Hello,
I'm using jersey in a WebService to produce XML object marshalled with JAXB.
I want to use my own JAXBContext so i create a Jersey provider to handle
the marshalling of my object.
My problem is that when i use the MIME type aplication/xml, my provider
is well used, but when i use the MIME type text/XML
jersey generate his own marshaller and so failed to create the
JAXBContext (because it is a little hard).
here is my provider (simplified) :
import**;
@Provider
public class CapabilitiesWriter<T extends Capabilities> implements
MessageBodyWriter<T> {
private static final MarshallerPool pool;
static {
MarshallerPool pool = // here i build a sort of marshaller
}
@Override
public boolean isWriteable(Class<?> type, Type type1, Annotation[]
antns, MediaType mt) {
return Capabilities.class.isAssignableFrom(type);
}
@Override
public long getSize(T t, Class<?> type, Type type1, Annotation[]
antns, MediaType mt) {
return -1;
}
@Override
public void writeTo(T t, Class<?> type, Type type1, Annotation[]
antns, MediaType mt, MultivaluedMap<String, Object> mm, OutputStream
out) throws IOException, WebApplicationException {
Marshaller m = // here i get my marshaller;
m.marshal(t, out);
}
}
and in my singleton I return a Response object like this :
@GET
public Response doGET() throws JAXBException {
String currentMIME_Type = "something"; // here i have some process
to choose the MIME type
Capabilities capa = something; // again i have
some process building the object
return Response.ok(capa, currentMIME_Type).build();
}
if "currentMIME_Type"=application/xml allright everything is fine, i
enter in the method writeTo of my provider CapabilitiesWriter.
if "currentMIME_Type"=text/xml i get a JAXB Exception at (I have 2
stack trace, don't know why) :
at
com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.writeTo(AbstractRootElementProvider.java:152)
at
com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:294)
at
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1140)
at
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1053)
at
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1043)
at
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:406)
at
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:477)
at
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:662)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:163)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:556)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:402)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:249)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:267)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:245)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:260)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
at
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:91)
at
com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:436)
at
com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:277)
at
com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1100)
at
com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:143)
at
com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:110)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:202)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:376)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
at
com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.getStoredJAXBContext(AbstractJAXBProvider.java:184)
at
com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.getJAXBContext(AbstractJAXBProvider.java:177)
at
com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.getMarshaller(AbstractJAXBProvider.java:155)
at
com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.getMarshaller(AbstractJAXBProvider.java:134)
at
com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.writeTo(AbstractRootElementProvider.java:145)
so my question is, why the MIME type change the way of using provider?
and how redirect all mime type to my provider?
Thanks,
Guilhem legal