users@jersey.java.net

Re: [Jersey] URLDecoder: Incomplete trailing escape (%) pattern

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 05 Jan 2009 13:07:38 +0100

Hi John,

Can you send the client code and resource class you are using to
receive and process the requests?

I suspect that the problem is with the '=' characters that base64
encoding puts at the end for padding *some* of the time, depending on
the length of the data being encoded. java.net.URLDecoder throws an
exception when an illegal character occurs e.g. an '=' character that
should be percent encoded.

My guess is the client side is not correctly encoding the form
parameter i.e. for binary data two layers of encoding are required,
base 64 encoding then form parameter encoding.

Paul.

On Jan 2, 2009, at 9:18 PM, John Gant wrote:

> Hello all,
>
> I've run into an issue in using Jersey that I can't seem to
> obviously resolve. To start I read in a jpeg (using FileInputStream
> and byte arrays), base64 encode the image chunks (using commons-
> codec 1.2) and send a POST request (via httpclient 3.1) to a Jersey
> web service. When sending the image data, *some* of the requests
> throw the following exception:
>
> [#|2009-01-02T15:01:05.470-0500|SEVERE|sun-appserver9.1|
> javax.enterprise.system.container.web|
> _ThreadID
> =
> 16
> ;_ThreadName
> =httpSSLWorkerThread-8080-0;_RequestID=201f0f75-4f67-49f2-
> aecc-8649c55daf3c;|StandardWrapperValve[Jersey Web Application]:
> PWC1406: Servlet.service() for servlet Jersey Web Application threw
> exception
> java.lang.IllegalArgumentException: URLDecoder: Incomplete trailing
> escape (%) pattern
> at java.net.URLDecoder.decode(URLDecoder.java:168)
> at
> com
> .sun
> .jersey.impl.provider.entity.FormProvider.readFrom(FormProvider.java:
> 86)
> at
> com
> .sun
> .jersey.impl.provider.entity.FormProvider.readFrom(FormProvider.java:
> 62)
> at
> com
> .sun
> .jersey
> .spi.container.ContainerRequest.getEntity(ContainerRequest.java:348)
> at
> com
> .sun
> .jersey
> .spi.container.ContainerRequest.getEntity(ContainerRequest.java:355)
> at
> com
> .sun
> .jersey
> .impl
> .model
> .method
> .dispatch.FormDispatchProvider.processForm(FormDispatchProvider.java:
> 73)
> at com.sun.jersey.impl.model.method.dispatch.FormDispatchProvider
> $FormParamInInvoker.getParams(FormDispatchProvider.java:87)
> at com.sun.jersey.impl.model.method.dispatch.FormDispatchProvider
> $TypeOutInvoker._dispatch(FormDispatchProvider.java:128)
> at
> com
> .sun
> .jersey
> .impl
> .model
> .method
> .dispatch
> .ResourceJavaMethodDispatcher
> .dispatch(ResourceJavaMethodDispatcher.java:85)
> at
> com
> .sun.jersey.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:
> 123)
> at
> com
> .sun
> .jersey
> .impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:71)
> at
> com
> .sun
> .jersey
> .impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:111)
> at
> com
> .sun
> .jersey
> .impl
> .uri
> .rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:63)
> at
> com
> .sun
> .jersey
> .impl
> .application
> .WebApplicationImpl.handleRequest(WebApplicationImpl.java:722)
> at
> com
> .sun
> .jersey
> .impl
> .application
> .WebApplicationImpl.handleRequest(WebApplicationImpl.java:692)
> at
> com
> .sun
> .jersey
> .spi
> .container.servlet.ServletContainer.service(ServletContainer.java:344)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
> at
> org
> .apache
> .catalina
> .core
> .ApplicationFilterChain.servletService(ApplicationFilterChain.java:
> 411)
> at
> org
> .apache
> .catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
> 290)
> at
> org
> .apache
> .catalina
> .core.StandardContextValve.invokeInternal(StandardContextValve.java:
> 271)
> at
> org
> .apache
> .catalina.core.StandardContextValve.invoke(StandardContextValve.java:
> 202)
> at
> org
> .apache
> .catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
> at
> org
> .apache
> .catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
> at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
> at
> org
> .apache
> .catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
> at
> org
> .apache
> .catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
> at
> org
> .apache
> .catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
> at
> org
> .apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:
> 571)
> at
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
> at
> org
> .apache
> .catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:
> 150)
> at
> org
> .apache
> .catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
> at
> org
> .apache
> .catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
> at
> org
> .apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:
> 571)
> at
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
> at
> org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:
> 272)
> at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter
> (DefaultProcessorTask.java:637)
> at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess
> (DefaultProcessorTask.java:568)
> at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process
> (DefaultProcessorTask.java:813)
> at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask
> (DefaultReadTask.java:341)
> at
> com
> .sun
> .enterprise
> .web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:
> 263)
> at
> com
> .sun
> .enterprise
> .web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:
> 214)
> at com.sun.enterprise.web.portunif.PortUnificationPipeline
> $PUTask.doTask(PortUnificationPipeline.java:380)
> at
> com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:
> 265)
> at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run
> (SSLWorkerThread.java:106)
>
> Below is an example of encoded data on which jersey threw an
> exception:
>
> 2009-01-02 15:15:05,784 [AWT-EventQueue-0] INFO
> edu.louisville.cecs.WebServiceClient - base64Data:
> [hjBMjlVYMqE4BIXgsWb5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Yz5lCOIo4ek1ToYaly8zjTpUI01KDSvJzUpzs3KTauf6lH7DP/BUT9kL9vTRYX+CfxGhtvHFpptnqPiD4VeMlGifEPRYruCC5kL6PcOV1ixga4WL+2NAn1LSnbaBco4aFP0jS4iIADAkBd2CCBkHHORwcNg4wdp9DX+QD47uPHf7OfxF8B+LfB3ibWfD2p+AvEWlv4V8YeGtV1HRNavfBGtwv4hs9HfUtO1GPULeHT7CbUdFhMVzDLeadKskiPK5eT9ufgF/wXX/4KMeDvD8PhXwn4li+NN/peg==]
>
> To me this screams invalid encoding of the data and I haven't ruled
> that out, but have used commons-codec before (in a similar
> application) and things worked. This is deployed on glassfish (Sun
> Java System Application Server 9.1_02 (build b04-fcs)). Any help
> would be appreciated!
>
> Thanks,
> John