dev@jersey.java.net

GET method that can produce multipart or XML

From: Adam Retter <adam.retter_at_googlemail.com>
Date: Wed, 20 Jan 2010 16:26:16 +0000

I have a GET Method using Jersey 1.1.4.1 which can return a mime
multipart response when successful, this all works fine :-)
But, I now want to extend it so that if there is a failure, it can
return an XML document detailing the problem.

Previously I was using the following on my method -

@GET
@Path("{rrn: [0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{4}}/pdfs")
@Produces("multipart/mixed")

So, I changed that to -

@GET
@Path("{rrn: [0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{4}}/pdfs")
@Produces({"multipart/mixed", "text/xml"})

It still works fine for returning a mime multipart response when the
request is successful, but when the request fails and I try and return
my XML Bean generated by JAXB -

@XmlRootElement(name = "response")
public class Response {
...
}

Then I get the following stack trace, which seems to imply to me that
the "text/xml" argument to @Produces is being ignored? -


20-Jan-2010 16:21:12 com.sun.jersey.spi.container.ContainerResponse write
SEVERE: A message body writer for Java type, class
uk.co.landmark.solutions.registers.rest.Response, and MIME media type,
multipart/mixed, was not found
20-Jan-2010 16:21:12
com.sun.jersey.server.impl.application.WebApplicationImpl onException
SEVERE: Internal server error
javax.ws.rs.WebApplicationException
        at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:253)
        at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:814)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:740)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:731)
        at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:372)
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:452)
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:633)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at uk.co.landmarkinfo.registers.common.filter.UrlSecurityFilter.handleTermsPage(UrlSecurityFilter.java:306)
        at uk.co.landmarkinfo.registers.common.filter.UrlSecurityFilter.doFilter(UrlSecurityFilter.java:194)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at uk.co.landmarkinfo.registers.common.filter.TextSizeFilter.doFilter(TextSizeFilter.java:73)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
        at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
        at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:283)
        at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
        at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
        at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
        at java.lang.Thread.run(Thread.java:619)


-- 
Adam Retter
skype :adam.retter
http://www.adamretter.org.uk