<div dir="ltr">Hi,<div><br></div><div>Connections can be re-used if the responses of the previous request is consumed. That&#39;s how ApacheHttpClient works for SimpleConnectionManager. By default, rest easy is using SingleClientConnectionManager[1] as explained in rest-easy docs[2]. Now this[1] class is depricated and they suggest using BasicClientConnectionManager[3]. Technically, they[1][3] means the same thing such that </div>
<div><br></div><div>Quoted</div><div>&quot;<code class="" style="color:rgb(0,0,0);text-align:justify">BasicHttpClientConnectionManager</code><span style="color:rgb(0,0,0);font-family:Verdana,Arial,sans-serif;font-size:14px;text-align:justify"> is a simple connection manager that maintains only one connection at a time. Even though this class is thread-safe it ought to be used by one execution thread only. </span><code class="" style="color:rgb(0,0,0);text-align:justify">BasicHttpClientConnectionManager</code><span style="color:rgb(0,0,0);font-family:Verdana,Arial,sans-serif;font-size:14px;text-align:justify"> will make an effort to reuse the connection for subsequent requests with the same route. It will, however, close the existing connection and re-open it for the given route, if the route of the persistent connection does not match that of the connection request. If the connection has been already been allocated, then </span><code class="" style="color:rgb(0,0,0);text-align:justify">java.lang.IllegalStateException</code><span style="color:rgb(0,0,0);font-family:Verdana,Arial,sans-serif;font-size:14px;text-align:justify"> is thrown.</span>&quot;</div>
<div><br></div><div>A connection remains allocated if the response is not consumed.</div><div><br></div><div>[1] <a href="http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/conn/SingleClientConnManager.html">http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/conn/SingleClientConnManager.html</a></div>
<div>[2] <a href="http://docs.jboss.org/resteasy/docs/3.0.5.Final/userguide/html_single/index.html#transport_layer">http://docs.jboss.org/resteasy/docs/3.0.5.Final/userguide/html_single/index.html#transport_layer</a></div>
<div>[3] <a href="http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/conn/BasicClientConnectionManager.html">http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/conn/BasicClientConnectionManager.html</a></div>
<div>[4] <a href="http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d5e361">http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d5e361</a></div><div><br></div><div>-Nibin</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Nov 10, 2013 at 11:05 AM, Arun Gupta <span dir="ltr">&lt;<a href="mailto:arun.gupta@gmail.com" target="_blank">arun.gupta@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Nibin,<br>
<br>
After changing<br>
<br>
    @BeforeClass<br>
    public void setUp() {<br>
        client = ClientBuilder.newClient();<br>
        target =<br>
client.target(&quot;<a href="http://localhost:8080/jaxrs-client/webresources/persons" target="_blank">http://localhost:8080/jaxrs-client/webresources/persons</a>&quot;);<br>
    }<br>
<br>
<br>
to<br>
<br>
    @Before<br>
    public void setUp() {<br>
        client = ClientBuilder.newClient();<br>
        target =<br>
client.target(&quot;<a href="http://localhost:8080/jaxrs-client/webresources/persons" target="_blank">http://localhost:8080/jaxrs-client/webresources/persons</a>&quot;);<br>
    }<br>
<br>
this test is working fine on beta2 snapshot.<br>
<br>
Are you suggesting that the connections cannot be reused even within<br>
each test ? And it should not work ?<br>
<span class="HOEnZb"><font color="#888888"><br>
Arun<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
On Sun, Nov 10, 2013 at 6:24 AM, Nibin Varghese &lt;<a href="mailto:nibin.gv@gmail.com">nibin.gv@gmail.com</a>&gt; wrote:<br>
&gt; Hi,<br>
&gt;<br>
&gt; This is becuase AppacheHTTPClient will not allow to use the same connection<br>
&gt; if the previous request is not yet consumed. For eg, as mentioned in the<br>
&gt; Test (quoted below)<br>
&gt;<br>
&gt;  @Test<br>
&gt;     public void test1PostAndGet() {<br>
&gt;         MultivaluedHashMap&lt;String, String&gt; map = new MultivaluedHashMap&lt;&gt;();<br>
&gt;         map.add(&quot;name&quot;, &quot;Penny&quot;);<br>
&gt;         map.add(&quot;age&quot;, &quot;1&quot;);<br>
&gt;         target.request().post(Entity.form(map));<br>
&gt;<br>
&gt;<br>
&gt;         map.clear();<br>
&gt;         map.add(&quot;name&quot;, &quot;Leonard&quot;);<br>
&gt;         map.add(&quot;age&quot;, &quot;2&quot;);<br>
&gt;         target.request().post(Entity.form(map)); // &lt;--- Reference [1]<br>
&gt;<br>
&gt;<br>
&gt;         map.clear();<br>
&gt;         map.add(&quot;name&quot;, &quot;Sheldon&quot;);<br>
&gt;         map.add(&quot;age&quot;, &quot;3&quot;);<br>
&gt;         target.request().post(Entity.form(map));  &lt;--- Reference [2]<br>
&gt;<br>
&gt;<br>
&gt;         Person[] list = target.request().get(Person[].class);<br>
&gt;         assertEquals(3, list.length);<br>
&gt;<br>
&gt;<br>
&gt;         assertEquals(&quot;Penny&quot;, list[0].getName());<br>
&gt;         assertEquals(1, list[0].getAge());<br>
&gt;<br>
&gt;<br>
&gt;         assertEquals(&quot;Leonard&quot;, list[1].getName());<br>
&gt;         assertEquals(2, list[1].getAge());<br>
&gt;<br>
&gt;<br>
&gt;         assertEquals(&quot;Sheldon&quot;, list[2].getName());<br>
&gt;         assertEquals(3, list[2].getAge());<br>
&gt;     }<br>
&gt;<br>
&gt; As you can see in Reference[1], the request is made and its response is not<br>
&gt; consumed. So the connection is still in active state. You should consume the<br>
&gt; response or call connection.close() before making the second request as<br>
&gt; mentioned in Reference[2]. This is because the &quot;target&quot; object uses the same<br>
&gt; ApacheHttpClient connection manager which internally uses &quot;<br>
&gt;<br>
&gt; SingleClientConnManager&quot; as discussed in the documentation[3].<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; [3]<br>
&gt;<br>
&gt; <a href="http://docs.jboss.org/resteasy/docs/3.0.5.Final/userguide/html_single/index.html#RESTEasy_Client_Framework" target="_blank">http://docs.jboss.org/resteasy/docs/3.0.5.Final/userguide/html_single/index.html#RESTEasy_Client_Framework</a><br>

&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; -Nibin<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Fri, Nov 8, 2013 at 5:31 AM, Arun Gupta &lt;<a href="mailto:arun.gupta@gmail.com">arun.gupta@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Tests for JAX-RS Client API sample at:<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; <a href="https://github.com/arun-gupta/javaee7-samples/tree/master/jaxrs/jaxrs-client" target="_blank">https://github.com/arun-gupta/javaee7-samples/tree/master/jaxrs/jaxrs-client</a><br>
&gt;&gt;<br>
&gt;&gt; is failing with:<br>
&gt;&gt;<br>
&gt;&gt; Caused by: java.lang.IllegalStateException: Invalid use of<br>
&gt;&gt; BasicClientConnManager: connection still allocated.<br>
&gt;&gt; Make sure to release the connection before allocating another one.<br>
&gt;&gt;     at<br>
&gt;&gt; org.apache.http.impl.conn.BasicClientConnectionManager.getConnection(BasicClientConnectionManager.java:161)<br>
&gt;&gt;     at<br>
&gt;&gt; org.apache.http.impl.conn.BasicClientConnectionManager$1.getConnection(BasicClientConnectionManager.java:138)<br>
&gt;&gt;     at<br>
&gt;&gt; org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:455)<br>
&gt;&gt;     at<br>
&gt;&gt; org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)<br>
&gt;&gt;     at<br>
&gt;&gt; org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)<br>
&gt;&gt;     at<br>
&gt;&gt; org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:245)<br>
&gt;&gt;     ... 33 more<br>
&gt;&gt;<br>
&gt;&gt; The instructions to run the test are described at:<br>
&gt;&gt;<br>
&gt;&gt; <a href="https://github.com/arun-gupta/javaee7-samples" target="_blank">https://github.com/arun-gupta/javaee7-samples</a><br>
&gt;&gt;<br>
&gt;&gt; Any suggestions ?<br>
&gt;&gt;<br>
&gt;&gt; Arun<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; <a href="http://blog.arungupta.me" target="_blank">http://blog.arungupta.me</a><br>
&gt;&gt; <a href="http://twitter.com/arungupta" target="_blank">http://twitter.com/arungupta</a><br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; wildfly-dev mailing list<br>
&gt;&gt; <a href="mailto:wildfly-dev@lists.jboss.org">wildfly-dev@lists.jboss.org</a><br>
&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/wildfly-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/wildfly-dev</a><br>
&gt;<br>
&gt;<br>
<br>
<br>
<br>
--<br>
<a href="http://blog.arungupta.me" target="_blank">http://blog.arungupta.me</a><br>
<a href="http://twitter.com/arungupta" target="_blank">http://twitter.com/arungupta</a><br>
</div></div></blockquote></div><br></div>