title: Exception---SingleClientConnManager: connection still allocated
body: <p>I have a code to read the response of a page. it looks like this.</p>
  
  <pre><code>public static void main(String[] args)
      {
          DefaultHttpClient httpclient = new DefaultHttpClient();
          HttpEntity entity  = null;
          try{
  
              String it= "https://www.aaa/login";
                  HttpPost httpost = new HttpPost(it);
  
                  List &lt;NameValuePair&gt; ln= new ArrayList &lt;NameValuePair&gt;();
                  ln.add(new BasicNameValuePair("un", "aaa"));
                  ln.add(new BasicNameValuePair("pwd", "bbb"));
                  httpost.setEntity(new UrlEncodedFormEntity(ln, HTTP.UTF_8));
  
                  HttpResponse  response = httpclient.execute(httpost);
                  entity  = response.getEntity();
                  GZIPInputStream gis= new GZIPInputStream(entity.getContent());
              StringBuffer st = new StringBuffer();
                  for (int c = gis.read(); c != -1; c = gis.read()) {
                      st.append((char)c);
                  }
  
                      CookieStore cookieStore = httpclient.getCookieStore();
                      HttpContext httpContext = new BasicHttpContext();
                      httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
                      HttpGet httpget = new HttpGet("http://aaa/index");
                      HttpResponse httpResponse = httpclient.execute(httpget, httpContext);
                      entity = httpResponse.getEntity();
  
                      if (entity != null) {
                          BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
                          String readLine;
                          while(((readLine = br.readLine()) != null)) {
                            System.err.println("br   :"+readLine);
                      }
  
  
                  }                
          }catch(Exception e){
              e.printStackTrace();
          }
          finally{
  
              EntityUtils.consume(entity);
              httpclient.getConnectionManager().shutdown();
          }
  </code></pre>
  
  <p>When I run this program i get the foll exception.</p>
  
  <pre><code>java.lang.IllegalStateException: Invalid use of SingleClientConnManager: connection still allocated.
  Make sure to release the connection before allocating another one.
      at org.apache.http.impl.conn.SingleClientConnManager.getConnection(SingleClientConnManager.java:216)
      at org.apache.http.impl.conn.SingleClientConnManager$1.getConnection(SingleClientConnManager.java:190)
      at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:401)
      at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
      at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
  </code></pre>
  
  <p>I have closed the connection in the finally block. As suggested in aonther thread I have consumed the response body before reusing the connection. what else would go wrong here?</p>