<div dir="ltr">Hi,<div><br></div><div>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)</div><div><br></div>
<div><pre style="margin-top:0px;margin-bottom:0px;color:rgb(51,51,51);line-height:18px"><div class="" id="LC40" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px"> <span class="">@Test</span></div>
<div class="" id="LC41" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">    <span class="" style="font-weight:bold">public</span> <span class="" style="color:rgb(68,85,136);font-weight:bold">void</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">test1PostAndGet</span><span class="" style="font-weight:bold">()</span> <span class="" style="font-weight:bold">{</span></div>
<div class="" id="LC42" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">        <span class="">MultivaluedHashMap</span><span class="" style="font-weight:bold">&lt;</span><span class="">String</span><span class="" style="font-weight:bold">,</span> <span class="">String</span><span class="" style="font-weight:bold">&gt;</span> <span class="">map</span> <span class="" style="font-weight:bold">=</span> <span class="" style="font-weight:bold">new</span> <span class="">MultivaluedHashMap</span><span class="" style="font-weight:bold">&lt;&gt;();</span></div>
<div class="" id="LC43" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">        <span class="">map</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">add</span><span class="" style="font-weight:bold">(</span><span class="" style="color:rgb(221,17,68)">&quot;name&quot;</span><span class="" style="font-weight:bold">,</span> <span class="" style="color:rgb(221,17,68)">&quot;Penny&quot;</span><span class="" style="font-weight:bold">);</span></div>
<div class="" id="LC44" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">        <span class="">map</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">add</span><span class="" style="font-weight:bold">(</span><span class="" style="color:rgb(221,17,68)">&quot;age&quot;</span><span class="" style="font-weight:bold">,</span> <span class="" style="color:rgb(221,17,68)">&quot;1&quot;</span><span class="" style="font-weight:bold">);</span></div>
<div class="" id="LC45" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">        <span class="">target</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">request</span><span class="" style="font-weight:bold">().</span><span class="" style="color:rgb(0,128,128)">post</span><span class="" style="font-weight:bold">(</span><span class="">Entity</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">form</span><span class="" style="font-weight:bold">(</span><span class="">map</span><span class="" style="font-weight:bold">));</span></div>
<div class="" id="LC46" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px"><br></div><div class="" id="LC47" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">
        <span class="">map</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">clear</span><span class="" style="font-weight:bold">();</span></div><div class="" id="LC48" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">
        <span class="">map</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">add</span><span class="" style="font-weight:bold">(</span><span class="" style="color:rgb(221,17,68)">&quot;name&quot;</span><span class="" style="font-weight:bold">,</span> <span class="" style="color:rgb(221,17,68)">&quot;Leonard&quot;</span><span class="" style="font-weight:bold">);</span></div>
<div class="" id="LC49" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">        <span class="">map</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">add</span><span class="" style="font-weight:bold">(</span><span class="" style="color:rgb(221,17,68)">&quot;age&quot;</span><span class="" style="font-weight:bold">,</span> <span class="" style="color:rgb(221,17,68)">&quot;2&quot;</span><span class="" style="font-weight:bold">);</span></div>
<div class="" id="LC50" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">        <span class="">target</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">request</span><span class="" style="font-weight:bold">().</span><span class="" style="color:rgb(0,128,128)">post</span><span class="" style="font-weight:bold">(</span><span class="">Entity</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">form</span><span class="" style="font-weight:bold">(</span><span class="">map</span><span class="" style="font-weight:bold">)); // &lt;--- Reference [1]</span></div>
<div class="" id="LC51" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px"><br></div><div class="" id="LC52" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">
        <span class="">map</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">clear</span><span class="" style="font-weight:bold">();</span></div><div class="" id="LC53" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">
        <span class="">map</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">add</span><span class="" style="font-weight:bold">(</span><span class="" style="color:rgb(221,17,68)">&quot;name&quot;</span><span class="" style="font-weight:bold">,</span> <span class="" style="color:rgb(221,17,68)">&quot;Sheldon&quot;</span><span class="" style="font-weight:bold">);</span></div>
<div class="" id="LC54" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">        <span class="">map</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">add</span><span class="" style="font-weight:bold">(</span><span class="" style="color:rgb(221,17,68)">&quot;age&quot;</span><span class="" style="font-weight:bold">,</span> <span class="" style="color:rgb(221,17,68)">&quot;3&quot;</span><span class="" style="font-weight:bold">);</span></div>
<div class="" id="LC55" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">        <span class="">target</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">request</span><span class="" style="font-weight:bold">().</span><span class="" style="color:rgb(0,128,128)">post</span><span class="" style="font-weight:bold">(</span><span class="">Entity</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">form</span><span class="" style="font-weight:bold">(</span><span class="">map</span><span class="" style="font-weight:bold">)); </span><span style="font-weight:bold"> &lt;--- Reference [2]</span></div>
<div class="" id="LC56" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px"><br></div><div class="" id="LC57" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">
        <span class="">Person</span><span class="" style="font-weight:bold">[]</span> <span class="">list</span> <span class="" style="font-weight:bold">=</span> <span class="">target</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">request</span><span class="" style="font-weight:bold">().</span><span class="" style="color:rgb(0,128,128)">get</span><span class="" style="font-weight:bold">(</span><span class="">Person</span><span class="" style="font-weight:bold">[].</span><span class="" style="color:rgb(0,128,128)">class</span><span class="" style="font-weight:bold">);</span></div>
<div class="" id="LC58" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">        <span class="">assertEquals</span><span class="" style="font-weight:bold">(</span><span class="" style="color:rgb(0,153,153)">3</span><span class="" style="font-weight:bold">,</span> <span class="">list</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">length</span><span class="" style="font-weight:bold">);</span></div>
<div class="" id="LC59" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px"><br></div><div class="" id="LC60" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">
        <span class="">assertEquals</span><span class="" style="font-weight:bold">(</span><span class="" style="color:rgb(221,17,68)">&quot;Penny&quot;</span><span class="" style="font-weight:bold">,</span> <span class="">list</span><span class="" style="font-weight:bold">[</span><span class="" style="color:rgb(0,153,153)">0</span><span class="" style="font-weight:bold">].</span><span class="" style="color:rgb(0,128,128)">getName</span><span class="" style="font-weight:bold">());</span></div>
<div class="" id="LC61" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">        <span class="">assertEquals</span><span class="" style="font-weight:bold">(</span><span class="" style="color:rgb(0,153,153)">1</span><span class="" style="font-weight:bold">,</span> <span class="">list</span><span class="" style="font-weight:bold">[</span><span class="" style="color:rgb(0,153,153)">0</span><span class="" style="font-weight:bold">].</span><span class="" style="color:rgb(0,128,128)">getAge</span><span class="" style="font-weight:bold">());</span></div>
<div class="" id="LC62" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px"><br></div><div class="" id="LC63" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">
        <span class="">assertEquals</span><span class="" style="font-weight:bold">(</span><span class="" style="color:rgb(221,17,68)">&quot;Leonard&quot;</span><span class="" style="font-weight:bold">,</span> <span class="">list</span><span class="" style="font-weight:bold">[</span><span class="" style="color:rgb(0,153,153)">1</span><span class="" style="font-weight:bold">].</span><span class="" style="color:rgb(0,128,128)">getName</span><span class="" style="font-weight:bold">());</span></div>
<div class="" id="LC64" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">        <span class="">assertEquals</span><span class="" style="font-weight:bold">(</span><span class="" style="color:rgb(0,153,153)">2</span><span class="" style="font-weight:bold">,</span> <span class="">list</span><span class="" style="font-weight:bold">[</span><span class="" style="color:rgb(0,153,153)">1</span><span class="" style="font-weight:bold">].</span><span class="" style="color:rgb(0,128,128)">getAge</span><span class="" style="font-weight:bold">());</span></div>
<div class="" id="LC65" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px"><br></div><div class="" id="LC66" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">
        <span class="">assertEquals</span><span class="" style="font-weight:bold">(</span><span class="" style="color:rgb(221,17,68)">&quot;Sheldon&quot;</span><span class="" style="font-weight:bold">,</span> <span class="">list</span><span class="" style="font-weight:bold">[</span><span class="" style="color:rgb(0,153,153)">2</span><span class="" style="font-weight:bold">].</span><span class="" style="color:rgb(0,128,128)">getName</span><span class="" style="font-weight:bold">());</span></div>
<div class="" id="LC67" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">        <span class="">assertEquals</span><span class="" style="font-weight:bold">(</span><span class="" style="color:rgb(0,153,153)">3</span><span class="" style="font-weight:bold">,</span> <span class="">list</span><span class="" style="font-weight:bold">[</span><span class="" style="color:rgb(0,153,153)">2</span><span class="" style="font-weight:bold">].</span><span class="" style="color:rgb(0,128,128)">getAge</span><span class="" style="font-weight:bold">());</span></div>
<div class="" id="LC68" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">    <span class="" style="font-weight:bold">}</span></div><div class="" id="LC68" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">
<span class="" style="font-weight:bold"><br></span></div><div class="" id="LC68" style="padding-left:10px"><font face="Consolas, Liberation Mono, Courier, monospace">As you can see in </font><b style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px">Reference[1]</b><font face="Consolas, Liberation Mono, Courier, monospace">, 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 </font><b style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px">Reference[2]</b><font face="Consolas, Liberation Mono, Courier, monospace">. This is because the &quot;target&quot; object uses the same ApacheHttpClient connection manager which internally uses &quot;</font><a id="transport_layer" style="color:rgb(51,51,51);text-align:justify"><p style="display:inline!important">
<code class="" style="font-family:courrier,monospace;font-size:0.9em;white-space:nowrap">SingleClientConnManager&quot; </code><code class=""><font face="Consolas, Liberation Mono, Courier, monospace">as discussed in the documentation[3].</font></code></p>
</a></div><div class="" id="LC68" style="padding-left:10px"><a style="font-family:&#39;Lucida Grande&#39;,Geneva,Verdana,Arial,sans-serif;font-size:12px;color:rgb(51,51,51);text-align:justify;white-space:normal"><p style="display:inline!important">
<code class="" style="font-size:0.9em;font-family:courrier,monospace;white-space:nowrap"><br></code></p></a></div><div class="" id="LC68" style="padding-left:10px"><a style="font-family:&#39;Lucida Grande&#39;,Geneva,Verdana,Arial,sans-serif;font-size:12px;color:rgb(51,51,51);text-align:justify;white-space:normal"><p style="display:inline!important">
<code class="" style="font-size:0.9em;font-family:courrier,monospace;white-space:nowrap">[3] </code></p></a><a href="http://docs.jboss.org/resteasy/docs/3.0.5.Final/userguide/html_single/index.html#RESTEasy_Client_Framework" style="font-family:arial">http://docs.jboss.org/resteasy/docs/3.0.5.Final/userguide/html_single/index.html#RESTEasy_Client_Framework</a><a style="color:rgb(51,51,51);font-size:12px;font-family:&#39;Lucida Grande&#39;,Geneva,Verdana,Arial,sans-serif;text-align:justify;white-space:normal"><p style="display:inline!important">
<code class="" style="font-size:0.9em;font-family:courrier,monospace;white-space:nowrap"> </code></p></a></div><div class="" id="LC68" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">
<br></div><div class="" id="LC68" style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;padding-left:10px">-Nibin</div></pre></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Fri, Nov 8, 2013 at 5:31 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">
Tests for JAX-RS Client API sample at:<br>
<br>
<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>
<br>
is failing with:<br>
<br>
Caused by: java.lang.IllegalStateException: Invalid use of<br>
BasicClientConnManager: connection still allocated.<br>
Make sure to release the connection before allocating another one.<br>
    at org.apache.http.impl.conn.BasicClientConnectionManager.getConnection(BasicClientConnectionManager.java:161)<br>
    at org.apache.http.impl.conn.BasicClientConnectionManager$1.getConnection(BasicClientConnectionManager.java:138)<br>
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:455)<br>
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)<br>
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)<br>
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:245)<br>
    ... 33 more<br>
<br>
The instructions to run the test are described at:<br>
<br>
<a href="https://github.com/arun-gupta/javaee7-samples" target="_blank">https://github.com/arun-gupta/javaee7-samples</a><br>
<br>
Any suggestions ?<br>
<span class="HOEnZb"><font color="#888888"><br>
Arun<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>
_______________________________________________<br>
wildfly-dev mailing list<br>
<a href="mailto:wildfly-dev@lists.jboss.org">wildfly-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/wildfly-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/wildfly-dev</a><br>
</font></span></blockquote></div><br></div>