[wildfly-dev] Invalid use of BasicClientConnManager for JAX-RS Client API
Nibin Varghese
nibin.gv at gmail.com
Sat Nov 9 23:24:14 EST 2013
Hi,
This is becuase AppacheHTTPClient will not allow to use the same connection
if the previous request is not yet consumed. For eg, as mentioned in the
Test (quoted below)
@Test
public void test1PostAndGet() {
MultivaluedHashMap<String, String> map = new MultivaluedHashMap<>();
map.add("name", "Penny");
map.add("age", "1");
target.request().post(Entity.form(map));
map.clear();
map.add("name", "Leonard");
map.add("age", "2");
target.request().post(Entity.form(map)); // <--- Reference [1]
map.clear();
map.add("name", "Sheldon");
map.add("age", "3");
target.request().post(Entity.form(map)); <--- Reference [2]
Person[] list = target.request().get(Person[].class);
assertEquals(3, list.length);
assertEquals("Penny", list[0].getName());
assertEquals(1, list[0].getAge());
assertEquals("Leonard", list[1].getName());
assertEquals(2, list[1].getAge());
assertEquals("Sheldon", list[2].getName());
assertEquals(3, list[2].getAge());
}
As you can see in *Reference[1]*, the request is made and its response
is not consumed. So the connection is still in active state. You
should consume the response or call connection.close() before making
the second request as mentioned in *Reference[2]*. This is because the
"target" object uses the same ApacheHttpClient connection manager
which internally uses "
SingleClientConnManager" as discussed in the documentation[3].
[3]
http://docs.jboss.org/resteasy/docs/3.0.5.Final/userguide/html_single/index.html#RESTEasy_Client_Framework
-Nibin
On Fri, Nov 8, 2013 at 5:31 AM, Arun Gupta <arun.gupta at gmail.com> wrote:
> Tests for JAX-RS Client API sample at:
>
>
> https://github.com/arun-gupta/javaee7-samples/tree/master/jaxrs/jaxrs-client
>
> is failing with:
>
> Caused by: java.lang.IllegalStateException: Invalid use of
> BasicClientConnManager: connection still allocated.
> Make sure to release the connection before allocating another one.
> at
> org.apache.http.impl.conn.BasicClientConnectionManager.getConnection(BasicClientConnectionManager.java:161)
> at
> org.apache.http.impl.conn.BasicClientConnectionManager$1.getConnection(BasicClientConnectionManager.java:138)
> at
> org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:455)
> at
> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
> at
> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
> at
> org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:245)
> ... 33 more
>
> The instructions to run the test are described at:
>
> https://github.com/arun-gupta/javaee7-samples
>
> Any suggestions ?
>
> Arun
>
> --
> http://blog.arungupta.me
> http://twitter.com/arungupta
> _______________________________________________
> wildfly-dev mailing list
> wildfly-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/wildfly-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/wildfly-dev/attachments/20131110/e8caf6c0/attachment.html
More information about the wildfly-dev
mailing list