6 Replies Latest reply on Apr 14, 2011 9:21 AM by Alessio Soldano

    Deploying ws with custom JAXBContext

    J Rosenberger Newbie

      So I was looking at programmatic deployment of web services, and in my case the implementation class is missing the jaxws annotations.  So basically I've got the JAXBIntroductions use case, except that I'm not reading the JAXB metadata from an XML file, I have the info at runtime another way.  I have no trouble creating a custom AnnotationsReader and adding that to a new JAXBContext.  But how do I get JBoss to use it?

       

      JAXBIntroductions itself does this with a custom deployment aspect, attaching the annotation reader to local deployment objects that don't exist outside the deployment process.  If I did it this way I would have to crack open the standard jbossws bean xmls and add my own deploymentaspect class, which I guess I would then have to deploy to server/lib as part of my base server install.  I'd rather not, to be honest.  I found some old threads (from the jaxbintros development apparently) lamenting the fact that this was necessary.  As those threads are a couple years old, I'm hoping maybe something has changed in the APIs?  I've dug a bit through the code but haven't found anything as of yet.

       

      Summary, I'm trying to get JBoss to use a JAXBContext provided by me (or to modify theirs) for certain (not all!) WS deployments.

       

      I'm using AS 5.1 and JBossWS native 3.3.1.  (I'm also using JBossESB 4.8)

       

      Many thanks if you can help me figure this out.

       

      J

        • 1. Re: Deploying ws with custom JAXBContext
          Jim Ma Apprentice

          JBossWS retrieves the BindingCustomization from endpoint attachements: endpoint.getAttachement(BindingCustomization.class). One of the possible way might be get the endpoint from the EndpointRegistry and set your own BindingCustomization  after this service is deployed.  The getting endpoint and setting BindingCustomization code can be in a war or sar file depends this ws war file.

          • 2. Re: Deploying ws with custom JAXBContext
            J Rosenberger Newbie

            I believe the class you're referring to is org.jboss.wsf.spi.deployment.Endpoint.  This is what I was referring to when I said:

             

            "JAXBIntroductions itself does this with a custom deployment aspect,  attaching the annotation reader to local deployment objects that don't  exist outside the deployment process."

             

            JAXBIntros calls Endpoint.setAttachment.  See http://grepcode.com/file/repository.jboss.org/nexus/content/repositories/releases/org.jboss.ws/jbossws-framework/3.3.0.CR2/org/jboss/wsf/framework/deployment/JAXBIntroDeploymentAspect.java#JAXBIntroDeploymentAspect

             

            This class is not available to me before deployment, and I'm not sure how I can follow your suggestion to do it after deployment.  Deployment is impossible if JBoss does not recognize that my class is a web service.  Without the metadata (in annotations or some form), JBoss will try to deploy the class as a servlet, or it will fail.  It doesn't appear to deploy it as a "webservice waiting for its metadata."

             

            If you think there's a specific trick to convince JBoss to do a two-step deployment here I'm willing to look at it.

             

            Regarding your last sentence, remember there's no war for this ws, it's programmatic deployment (which is otherwise working ok).

             

            So it really seems like I need to be able to provide metadata to the  deployment process.  There is a standard way to do this using the  JAXBContext and related classes.  I just haven't yet found an interface  or factory for injecting this into the deployment without writing my own  deploymentaspect as the JAXBIntros people were forced to do back then.   (See this thread from 2007, especially the second page: http://community.jboss.org/message/284953 ).

             

            Maybe the JAXBContextFactory can somehow be used?  I haven't been successful at that.  And I don't want to affect all deployments, just the ones of this sort.

            • 3. Re: Deploying ws with custom JAXBContext
              Jim Ma Apprentice

              After jbossws webservice deployment , each endpoint will be  registered in EndpointRegistry .

              You can use jbossws SPI api to retrieve the EndpointRegistry ,  then get the endpoint you want to change and set your own BindingCustomization. After this setup ,  the soap request come in and the new BindingCustomization will be used to process the jaxb classes.  This is just my draft thought about this problem, not really sure if this can work for your case.

              • 4. Re: Deploying ws with custom JAXBContext
                Artem Oboturov Newbie

                Example below is based on http://weblogs.java.net/blog/jitu/archive/2008/08/control_of_jaxb.html.

                Specify custom JAXBContextFactory on top of your webserice. Create new JAXBRIContext and pass an annotation processor to it. BaseJAXBContextFactory is under your control.

                 

                At least jaxws-rt 2.1.5 must be used internally by jboss.

                 

                Hope this will help.

                 

                @WebService(....)

                @UsesJAXBContext(BaseJAXBContextFactory.class)
                public class YourWebServiceBean
                {
                ....
                }
                public class BaseJAXBContextFactory implements JAXBContextFactory
                {
                    @Override
                    public JAXBRIContext createJAXBContext(SEIModel seiModel, List<Class> classes, List<TypeReference> typeReferences) throws JAXBException
                    {
                        Class[] arg = classes.toArray(new Class[classes.size()]);
                        JAXBRIContext context = JAXBRIContext.newInstance(
                            arg,
                            typeReferences,
                            null,
                            seiModel.getTargetNamespace(),
                            false,
                            null            // TODO: annotation processor should be put there
                        );
                        return context;
                    }
                }
                • 5. Re: Deploying ws with custom JAXBContext
                  Jacek Dabrowski Newbie

                  I made it work with JBoss Web Services - Metro Server 3.3.1.GA in JBoss 6.0.0.20100911-M5 "Neo" but cannot with JBoss 6.0.0 Final (JBossWS is not supported anymore and default CXF and deployed Native seem to ignore the annotation).

                   

                  Does any of CXF or Native support the @UsesJAXBContext and I'm doing something wrong?

                   

                  Jacek

                  • 6. Re: Deploying ws with custom JAXBContext
                    Alessio Soldano Master

                    There's no jbws feature at the moment for setting a given annotation reader do be used by jaxb for an endpoint. The only supported customization is the JAXBIntros stuff. However, it should not be that hard to add an annotation similar to the Metro @UsesJAXBContext and a deployment processor that looks for that, properly populate a BindingCustomization object and attach it to the current deployment.

                    If someone is willing to work on this, please create and self-assign a JIRA, I can provide more detailed suggestions / directions if needed.