users@jersey.java.net

Re: [Jersey] Servlet Filter + Jersey + JAXB issues

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 14 Aug 2008 10:15:55 +0200

Hi Danny,

I don't think the problem is specifically to do with JAXB. It appears
that your servlet filter is consuming the body of the request, notice
the following in the stack trace:

   org.xml.sax.SAXParseException: Premature end of file.

This indicates that there is nothing for the SAX XML parser, that JAXB
uses, to read. But, without seeing the code i cannot tell what exactly
is wrong.

Jersey has server side filters and there is a filter that will support
what you require. See here [1] for details.

Paul.

[1]
http://markmail.org/search/?q=list%3Anet.java.dev.jersey.users+filter#query:list%3Anet.java.dev.jersey.users%20filter+page:1+mid:p7yxygz4wpakqno5+state:results

Danny Lin wrote:
> Hello,
>
>
>
> I’m trying to implement a servlet layer filter to fake a PUT or a DELETE
> based on values passed in through the POST request. This is to deal with
> clients that can’t handle PUTs or DELETEs like a FLEX client. When I add
> the filter to the web.xml, my create account POST request throws a
> Jersey exception complaining about parsing the request body. When I
> remove that filter, account creation works just fine. The response shows
> a IOException. I’m actually not performing any operations in the
> doFilter right now, I just wanted to hook up a dummy filter and see if
> my code still worked. Does anyone have any idea why the JAXB marshalling
> is failing in Jersey when there’s a filter?
>
>
>
> nbsp;</th><td class="sublevel1-odd"><pre>javax.servlet.ServletException:
> com.sun.jersey.api.container.ContainerException: Exception injecting
> parameters to Web resource method
>
>
> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:293)
>
> javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>
> com.trionworld.rest.RestFilter.doFilter(RestFilter.java:32)
>
> </pre></td></tr><tr><th class="sublevel1-even">root cause:&nbsp;</th><td
> class="sublevel1-even"><pre>com.sun.jersey.api.container.ContainerException:
> Exception injecting parameters to Web resource method
>
> com.sun.jersey.impl.model.method.dispatch.EntityParamDispatchProvider$EntityParamInInvoker.getParams(EntityParamDispatchProvider.java:103)
>
> com.sun.jersey.impl.model.method.dispatch.EntityParamDispatchProvider$ResponseOutInvoker._dispatch(EntityParamDispatchProvider.java:148)
>
> com.sun.jersey.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:81)
>
>
> com.sun.jersey.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:133)
>
>
> com.sun.jersey.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:71)
>
>
> com.sun.jersey.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:111)
>
>
> com.sun.jersey.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:64)
>
>
> com.sun.jersey.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:669)
>
>
> com.sun.jersey.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:631)
>
>
> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:291)
>
> javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>
> com.trionworld.rest.RestFilter.doFilter(RestFilter.java:32)
>
> </pre></td></tr><tr><th class="sublevel1-odd">root cause:&nbsp;</th><td
> class="sublevel1-odd"><pre>java.lang.IllegalArgumentException:
> java.io.IOException: Error marshalling out JAXB object of type
> &quot;class com.trionworld.dto.account.AccountDTO&quot;.
>
>
> com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:239)
>
> com.sun.jersey.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:79)
>
> com.sun.jersey.impl.model.method.dispatch.EntityParamDispatchProvider$EntityParamInInvoker.getParams(EntityParamDispatchProvider.java:97)
>
> com.sun.jersey.impl.model.method.dispatch.EntityParamDispatchProvider$ResponseOutInvoker._dispatch(EntityParamDispatchProvider.java:148)
>
> com.sun.jersey.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:81)
>
>
> com.sun.jersey.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:133)
>
>
> com.sun.jersey.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:71)
>
>
> com.sun.jersey.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:111)
>
>
> com.sun.jersey.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:64)
>
>
> com.sun.jersey.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:669)
>
>
> com.sun.jersey.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:631)
>
>
> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:291)
>
> javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>
> com.trionworld.rest.RestFilter.doFilter(RestFilter.java:32)
>
> </pre></td></tr><tr><th class="sublevel1-even">root cause:&nbsp;</th><td
> class="sublevel1-even"><pre>java.io.IOException: Error marshalling out
> JAXB object of type &quot;class com.trionworld.dto.account.AccountDTO&quot;.
>
>
> com.sun.jersey.impl.provider.entity.XMLRootElementProvider.readFrom(XMLRootElementProvider.java:80)
>
>
> com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:237)
>
> com.sun.jersey.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:79)
>
> com.sun.jersey.impl.model.method.dispatch.EntityParamDispatchProvider$EntityParamInInvoker.getParams(EntityParamDispatchProvider.java:97)
>
> com.sun.jersey.impl.model.method.dispatch.EntityParamDispatchProvider$ResponseOutInvoker._dispatch(EntityParamDispatchProvider.java:148)
>
> com.sun.jersey.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:81)
>
>
> com.sun.jersey.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:133)
>
>
> com.sun.jersey.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:71)
>
>
> com.sun.jersey.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:111)
>
>
> com.sun.jersey.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:64)
>
>
> com.sun.jersey.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:669)
>
>
> com.sun.jersey.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:631)
>
>
> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:291)
>
> javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>
> com.trionworld.rest.RestFilter.doFilter(RestFilter.java:32)
>
> </pre></td></tr><tr><th class="sublevel1-odd">root cause:&nbsp;</th><td
> class="sublevel1-odd"><pre>javax.xml.bind.UnmarshalException
>
> - with linked exception:
>
> [org.xml.sax.SAXParseException: Premature end of file.]
>
>
> javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(Unknown
> Source)
>
>
> com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(Unknown
> Source)
>
>
> com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(Unknown
> Source)
>
>
> com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(Unknown
> Source)
>
>
> javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(Unknown Source)
>
>
> javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(Unknown Source)
>
>
> com.sun.jersey.impl.provider.entity.XMLRootElementProvider.readFrom(XMLRootElementProvider.java:78)
>
>
> com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:237)
>
> com.sun.jersey.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:79)
>
> com.sun.jersey.impl.model.method.dispatch.EntityParamDispatchProvider$EntityParamInInvoker.getParams(EntityParamDispatchProvider.java:97)
>
> com.sun.jersey.impl.model.method.dispatch.EntityParamDispatchProvider$ResponseOutInvoker._dispatch(EntityParamDispatchProvider.java:148)
>
> com.sun.jersey.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:81)
>
>
> com.sun.jersey.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:133)
>
>
> com.sun.jersey.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:71)
>
>
> com.sun.jersey.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:111)
>
>
> com.sun.jersey.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:64)
>
>
> com.sun.jersey.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:669)
>
>
> com.sun.jersey.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:631)
>
>
> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:291)
>
> javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>
> com.trionworld.rest.RestFilter.doFilter(RestFilter.java:32)
>
> </pre></td></tr><tr><th class="sublevel1-even">root cause:&nbsp;</th><td
> class="sublevel1-even"><pre>org.xml.sax.SAXParseException: Premature end
> of file.
>
>
> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown
> Source)
>
>
> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown
> Source)
>
>
> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown
> Source)
>
>
> com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown
> Source)
>
>
> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown
> Source)
>
>
> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown
> Source)
>
>
> com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown
> Source)
>
>
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
> Source)
>
>
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
> Source)
>
>
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
> Source)
>
>
> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
>
>
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown
> Source)
>
>
> com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown
> Source)
>
>
> com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(Unknown
> Source)
>
>
> com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(Unknown
> Source)
>
>
> javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(Unknown Source)
>
>
> javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(Unknown Source)
>
>
> com.sun.jersey.impl.provider.entity.XMLRootElementProvider.readFrom(XMLRootElementProvider.java:78)
>
>
> com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:237)
>
> com.sun.jersey.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:79)
>
> com.sun.jersey.impl.model.method.dispatch.EntityParamDispatchProvider$EntityParamInInvoker.getParams(EntityParamDispatchProvider.java:97)
>
> com.sun.jersey.impl.model.method.dispatch.EntityParamDispatchProvider$ResponseOutInvoker._dispatch(EntityParamDispatchProvider.java:148)
>
> com.sun.jersey.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:81)
>
>
> com.sun.jersey.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:133)
>
>
> com.sun.jersey.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:71)
>
>
> com.sun.jersey.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:111)
>
>
> com.sun.jersey.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:64)
>
>
> com.sun.jersey.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:669)
>
>
> com.sun.jersey.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:631)
>
>
> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:291)
>
> javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>
> com.trionworld.rest.RestFilter.doFilter(RestFilter.java:32)
>
>
>
> Danny Hao-Yei Lin
>
> Software Engineer
>
> Trion World Network, Inc.
>
>
>

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109