JBoss Community

Deploying ws with custom JAXBContext

reply from Artem Oboturov in JBoss Web Services - View the full discussion

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 (JAXBRIContext)Proxy.newProxyInstance(getClass().getClassLoader(),
            new Class[]{ JAXBRIContext.class },
            new JAXBContextInvocationHandler());
    }
}

 

 

public class JAXBContextInvocationHandler implements InvocationHandler

{

 

    @Override

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable

    {

        Object object = method.invoke(context, args);

        return object;

    }

 

}

Reply to this message by going to Community

Start a new discussion in JBoss Web Services at Community