users@jersey.java.net

Re: [Jersey] Use of Form causing org.apache.commons.httpclient.ProtocolException: Unbuffered entity enclosing request can not be repeated.

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 08 Apr 2009 12:54:13 +0200

Hi Steve,

Are you using 1.0.2? If so you hit a bug that i have fixed in 1.0.3-
SNAPSHOT (btw i am going to send an email soon about when we will
release 1.0.3).

In 1.0.3-SNAPSHOT the Apache client support will by default buffer the
request entity. If you set the property
ApacheHttpClientConfig.PROPERTY_CHUNKED_ENCODING_SIZE to a non-null
value then chunked encoding will be enabled and no buffering will occur.

Could you try 1.0.3-SNAPSHOT ?

I am curious to know why the Apache client is repeating the request.
Perhaps you could do a curl, for example:

   curl -v -X PUT -d "param1=param1" http://locahost:8080/path?request_id=1

Paul.

On Apr 8, 2009, at 12:45 PM, Steve Sims wrote:

> Hello,
>
> The following exception is being thrown whilst using the Apache
> Jersey client. From what I've been able to find out, this is
> occurring because there's a communications error in the PUT to my
> resource and the client is automatically attempting to retry but
> can't because it doesn't think that it can re-read the entity. My
> questions are, given that the entity I'm trying to send is an
> instance of com.sun.jersey.api.representation.Form, why is it being
> treated as "unbuffered"? and what can I use instead?
>
> Caused by: com.sun.jersey.api.client.ClientHandlerException:
> org.apache.commons.httpclient.ProtocolException: Unbuffered entity
> enclosing request can not be repeated.
> at
> com
> .sun
> .jersey
> .client
> .apache.ApacheHttpClientHandler.handle(ApacheHttpClientHandler.java:
> 202)
> at com.sun.jersey.api.client.Client.handle(Client.java:365)
> at
> com.sun.jersey.api.client.WebResource.handle(WebResource.java:556)
> at com.sun.jersey.api.client.WebResource.access
> $300(WebResource.java:68)
> at com.sun.jersey.api.client.WebResource
> $Builder.put(WebResource.java:466)
> at com.myapp.services.MyMainBean.ejbTimeout(MyMainBean.java:
> 225)
> at sun.reflect.GeneratedMethodAccessor253.invoke(Unknown
> Source)
> at
> sun
> .reflect
> .DelegatingMethodAccessorImpl
> .invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:616)
> at
> com
> .sun
> .enterprise
> .security
> .application.EJBSecurityManager.runMethod(EJBSecurityManager.java:
> 1067)
> at
> com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:176)
> at
> com
> .sun
> .ejb
> .containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:
> 2895)
> at
> com
> .sun.ejb.containers.BaseContainer.callEJBTimeout(BaseContainer.java:
> 2824)
> ... 6 more
> Caused by: org.apache.commons.httpclient.ProtocolException:
> Unbuffered entity enclosing request can not be repeated.
> at
> org
> .apache
> .commons
> .httpclient
> .methods
> .EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:
> 487)
> at
> org
> .apache
> .commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:
> 2114)
> at
> org
> .apache
> .commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
> at
> org
> .apache
> .commons
> .httpclient
> .HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
> at
> org
> .apache
> .commons
> .httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:
> 171)
> at
> org
> .apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:
> 397)
> at
> com
> .sun
> .jersey
> .client
> .apache.ApacheHttpClientHandler.handle(ApacheHttpClientHandler.java:
> 197)
> ... 18 more
>
> I'm PUTing the resource using this code:
>
> MultivaluedMap<String, String> formParams = new Form();
> formParams.add("param1", param1);
> WebResource resource =
> restClient.resource(resourceUri).queryParam("request_id", requestId);
> ClientResponse resp =
> resource
> .entity
> (formParams
> ).type
> (MediaType
> .APPLICATION_FORM_URLENCODED_TYPE).put(ClientResponse.class);
>
> Many thanks,
>
> Steve
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>