9 Replies Latest reply on Apr 16, 2011 1:12 PM by henk53

    [jboss-metadata] Validation on completely merged view

    alrubinger

      @see https://jira.jboss.org/jira/browse/JBMETA-117

      The defining issue is to prohibit an invalid construct:

      @Stateless
      @RemoteBinding(jndiBinding="Something")
      @Local(SomeLocalBusinessInterface.class)
      class MyBean implements SomeLocalBusinessInterface{...}


      Here I've defined an explicit remote binding on a SLSB w/ no remote view.

      Makes sense to put this in the RemoteBindingProcessor:

      public void process(JBossSessionBeanMetaData metaData, Class<?> type, RemoteBinding annotation)
       {
       /*
       * JBMETA-117
       *
       * No @RemoteBindings are allowed if there are no business remote interfaces
       */
      
       BusinessRemotesMetaData businessRemotes = metaData.getBusinessRemotes();
       if (businessRemotes == null || businessRemotes.size() == 0)
       {
       throw new RuntimeException("A @" + RemoteBinding.class.getName() + " was defined on EJB " + metaData.getName()
       + ", but this bean has no remote business interfaces defined. [" + ErrorCodes.ERROR_CODE_JBMETA117 + "]");
       }


      ...but if the @Remote annotation is on the business interface type, not on the implementation class, this will provide for false errors as the fully merged metadata of the EJB is not available until after this processor is called.

      Is there a mechanism to validate metadata after all the processing/merging is completed? I'm envisioning something in the form of a chain of validators run by by JBoss50Creator.create() after everything is merged.

      S,
      ALR

        • 1. Re: [jboss-metadata] Validation on completely merged view
          emuckenhuber

           

          "ALRubinger" wrote:

          Is there a mechanism to validate metadata after all the processing/merging is completed? I'm envisioning something in the form of a chain of validators run by by JBoss50Creator.create() after everything is merged.


          Hmm, no there is not such a validation mechanism - we were thinking of adding smth like that, but this is actually not planned for the next future.

          Maybe you can add this check to merging?
          There you also have the xml data, if someone added the remote interface in the xml.
          But not really sure if that makes sense to add all to merging!?

          • 2. Re: [jboss-metadata] Validation on completely merged view
            alrubinger

             

            "emuckenhuber" wrote:
            Hmm, no there is not such a validation mechanism - we were thinking of adding smth like that, but this is actually not planned for the next future.


            Any objections to my adding a validator chain to be run at the end of Creator.create() please speak now or forever hold your piece.

            "emuckenhuber" wrote:
            But not really sure if that makes sense to add all to merging!?


            Merge merges, validators validate. :)

            Then we can even make the validation configurable/pluggable in the future if we want.

            S,
            ALR


            • 3. Re: [jboss-metadata] Validation on completely merged view
              alrubinger

              This is tracked in https://jira.jboss.org/jira/browse/JBMETA-118 and has been committed in r79433.

              The only place I've triggered the ValidatorChain to run is from JBoss50Creator. Can we think of other instances in which we'd need to validate a fully-merged metadata?

              S,
              ALR

              • 4. Re: [jboss-metadata] Validation on completely merged view
                alrubinger

                I'm also giving the ValidatorChain the ability to report all Validation failures at once, instead of fail-fast (should make things easier for bean providers)

                org.jboss.metadata.validation.ValidationException: An @RemoteBinding was defined on EJB MyStatelessBean, but this bean has no remote business interfaces defined. [JBMETA-117]


                ...becomes:

                org.jboss.metadata.validation.chain.ValidatorChainException: Validation has failed due to the following ValidationException(s) raised:
                An @RemoteBinding was defined on EJB MyStatelessBean, but this bean has no remote business interfaces defined. [JBMETA-117]


                S,
                ALR

                • 5. [jboss-metadata] Validation on completely merged view
                  henk53

                  Shouldn't this maybe be updated for EJB 3.1 and no-interface views?

                   

                  I have an EJB 3.1 bean without an interface, for which I would like to specify a local binding, but JBoss AS 6 doesn't let me because there is no (business) interface specified.

                  • 6. [jboss-metadata] Validation on completely merged view
                    jaikiran

                    We did not plan to support overriding of JBoss specifc JNDI names for no-interface views, since EJB3.1 introduced a portable JNDI name scheme. You are encouraged to use the EJB3.1 jndi names instead of JBoss specific ones. @LocalBinding isn't taken into account for no-interface views.

                    • 7. Re: [jboss-metadata] Validation on completely merged view
                      henk53

                      jaikiran pai wrote:

                       

                      We did not plan to support overriding of JBoss specifc JNDI names for no-interface views, since EJB3.1 introduced a portable JNDI name scheme. You are encouraged to use the EJB3.1 jndi names instead of JBoss specific ones.

                       

                      Yes, that does make sense.

                       

                      I noticed though that internally JBoss sometimes uses the non-portable names, like in e.g. JBossEnterpriseBeanMetaData. I also have spotted code like this on a couple of occasions:

                       

                       

                       private static String getLocalJndiName(JBossEnterpriseBeanMetaData ejb, Class<?> ejbClass)
                         {
                            // See if local binding is explicitly-defined
                            LocalBinding localBinding = ejbClass.getAnnotation(LocalBinding.class);
                      
                            // If none specified
                            if (localBinding == null || (localBinding.jndiBinding() != null && localBinding.jndiBinding().trim().length() == 0))
                            {
                               String name = ejb.getLocalJndiName();
                               return name;
                            }
                            // Local Binding was explicitly-specified, use it
                            else
                            {
                               return localBinding.jndiBinding();
                            }
                         }
                      
                      

                       

                      (this is from ResteasyEjbDeployer)

                       

                      Code such as this never works with no-interface views, so the only way out for the user (except for patching the code) would be if the LocalBinding annotation was allowed on EJB beans without an interface.

                      • 8. Re: [jboss-metadata] Validation on completely merged view
                        jaikiran

                        Yeah, that's buggy for no-interface views.  If this is causing you issues in AS6, then can you please open a JBAS JIRA with the relevant details?

                        • 9. Re: [jboss-metadata] Validation on completely merged view
                          henk53

                          jaikiran pai wrote:

                           

                          Yeah, that's buggy for no-interface views.  If this is causing you issues in AS6, then can you please open a JBAS JIRA with the relevant details?

                           

                          Okay, I already created a RestEasy JIRA here: https://issues.jboss.org/browse/RESTEASY-531

                           

                          The JBAS one, should that best be a request to add a no-interface property to JBossEnterpriseBeanMetaData or to support LocalBinding anyway on no-interface views?