8 Replies Latest reply on Jul 5, 2009 3:19 PM by wolfgangknauf

    EJBTHREE-1823 - handling of res-type in resource-ref

    wolfgangknauf

      In https://jira.jboss.org/jira/browse/EJBTHREE-1823 a warning message was introduced if a "resource-ref" in ejb-jar.xml lacks the element "res-type".

      19:56:41,171 WARN [ResourceHandler] EJBTHREE-1823 : <res-type> not specified for the <resource-ref> ... in bean ...Bean


      I think this warn message is a slight violation of the spec (chapter 16.7.1.3 of EJB3 spec and 5.6.2 of JavaEE5 spec):

      "The resource-ref element consists of ... the optional res-type .... The res-type element is optional if an injection target is specified for the
      resource; in this case, the res-type defaults to the type of the injection target."

      And:
      "The resource manager connection factory type must be compatible with the type declared in the res-type element"

      So I think that JBoss should warn only if no "injection-target" is specified (though it can handle this case, too).

      The content of the res-type element does not seem to be checked by JBoss. Even if I don't enter an injection target and have no or an invalid res-type value, a lookup works. That's quite gentle of JBoss. But according to the spec, I would at least expect an error if the type of the object bound to the mapped-name does not match the "res-type".

      By the way: the "resource-ref" element seems to be only valid for a "Resource Manager Connection Factory", but I could use it for injection of a javax.ejb.SessionContext from "java:comp/EJBContext". While digging through the spec for writing this post, I found that I should have used a "resource-env-ref" element....

      Any comments from the gurus on my crude theories ;-)?

      Wolfgang

        • 1. Re: EJBTHREE-1823 - handling of res-type in resource-ref
          wolfgangknauf

          By the way: the "resource-env-ref" element performs validation of the "resource-env-ref-type".

          • 2. Re: EJBTHREE-1823 - handling of res-type in resource-ref
            jaikiran

             

            So I think that JBoss should warn only if no "injection-target" is specified (though it can handle this case, too).


            Yes, we can do away with the WARN message if the injection-target is configured.

            And:
            "The resource manager connection factory type must be compatible with the type declared in the res-type element"


            That's part of the "Deployer's responsibility" section :) So the container provider may or may not validate the types, which effectively might mean runtime exceptions in the application code where the code does a JNDI lookup and casts it to an incorrect type.

            Even if I ...have an invalid res-type value, a lookup works.

            I did not get this. You mean, you have something like this (just an pseudo example):

            <resource-ref>
             <res-ref-name>MyDS</res-ref-name>
             <res-type>i.am.invalid.type</res-type>
             <mapped-name>java:/DefaultDS</mapped-name>
            </resource-ref>
            
            


            Context ctx = new InitialContext();
            // successful lookup and cast
            DataSource ds = (DataSource) ctx.lookup("java:comp/env/MyDS");


            • 3. Re: EJBTHREE-1823 - handling of res-type in resource-ref
              jaikiran

              And yes, thanks for all these comments and the other bug reports that you have been filing :)

              • 4. Re: EJBTHREE-1823 - handling of res-type in resource-ref
                wolfgangknauf

                Hi Jaikiran,

                yes, your "I did not get this" guess was correct: I used it to inject a SessionContext, and no matter what was entered for the "res-type", it did not complain, neither on injection nor on JNDI lookup. I can build a sample if you want.

                Shall I create any JIRA issues (about the unnecessary warning and about the type check)?

                Wolfgang

                • 5. Re: EJBTHREE-1823 - handling of res-type in resource-ref
                  jaikiran

                   

                  "Wolfgang Knauf" wrote:

                  Shall I create any JIRA issues (about the unnecessary warning and about the type check)?



                  Sure, please create one.

                  yes, your "I did not get this" guess was correct: I used it to inject a SessionContext, and no matter what was entered for the "res-type", it did not complain, neither on injection nor on JNDI lookup. I can build a sample if you want.


                  Although, the spec mentions this as a deployer's responsibility to correctly configure the res-type, i guess we could issue either a WARN or ERROR if the types don't match. Please create a separate JIRA for this too and attach your application.



                  • 6. Re: EJBTHREE-1823 - handling of res-type in resource-ref
                    wolfgangknauf

                    Done!

                    For the warn message: https://jira.jboss.org/jira/browse/EJBTHREE-1862

                    For the missing validation of "res-type": https://jira.jboss.org/jira/browse/EJBTHREE-1863

                    Is there any check that the object declared through the resource-env-ref/resource-ref element is actually of the correct type? It seems the error message for resource-env-ref is only coming if the declared class is not found at all by the classloader, but if it is just wrong, there is no error message. Is this worth one more JIRA ;-)?

                    Wolfgang

                    • 7. Re: EJBTHREE-1823 - handling of res-type in resource-ref
                      jaikiran

                       

                      "Wolfgang Knauf" wrote:

                      Is there any check that the object declared through the resource-env-ref/resource-ref element is actually of the correct type? It seems the error message for resource-env-ref is only coming if the declared class is not found at all by the classloader, but if it is just wrong, there is no error message. Is this worth one more JIRA ;-)?

                      Wolfgang


                      AFAIK, there isn't any check. Please add the comments to the existing JIRA for the missing validation and if possible attach the same application.

                      • 8. Re: EJBTHREE-1823 - handling of res-type in resource-ref
                        wolfgangknauf

                        I attached an updated sample to https://jira.jboss.org/jira/browse/EJBTHREE-1863 with two "resource-env-ref" declarations with invalid "resource-env-ref-type" class. I also added some comments about missing type checks.

                        Best regards

                        Wolfgang