#5 Fix for IllegalStateException after server error

Unstable_(example)
closed-accepted
nobody
None
5
2013-04-04
2011-05-10
No

My JWBF-based bot first encountered an internal server error when attempting to save an article to a MediaWiki site:

invalid status: HTTP/1.0 500 Internal Server Error; for /xxxwiki/api.php?action=edit&title=Name+of+article

This, I believe, is a site-specific issue. Other article saves work fine, so I don't see that the problem is anything in JWBF. No big deal here.

After this, however, my bot attempts to get the text of another article---and then BOOM:

Exception in thread "main" 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:199)
at org.apache.http.impl.conn.SingleClientConnManager$1.getConnection(SingleClientConnManager.java:173)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:390)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554)
at net.sourceforge.jwbf.core.actions.HttpActionClient.execute(Unknown Source)
at net.sourceforge.jwbf.core.actions.HttpActionClient.get(Unknown Source)
at net.sourceforge.jwbf.core.actions.HttpActionClient.performAction(Unknown Source)
at net.sourceforge.jwbf.core.bots.HttpBot.performAction(Unknown Source)
at net.sourceforge.jwbf.mediawiki.bots.MediaWikiBot.performAction(Unknown Source)
at net.sourceforge.jwbf.mediawiki.bots.MediaWikiBot.readData(Unknown Source)
at net.sourceforge.jwbf.mediawiki.bots.MediaWikiBot.readData(Unknown Source)
at net.sourceforge.jwbf.core.contentRep.Article.getText(Unknown Source)
at Xxxpedia.updateCategoryMembers(Xxxpedia.java:373)

After doing some research on this, I found the following discussion...

http://stackoverflow.com/questions/4612573/exception-using-httprequest-execute-invalid-use-of-singleclientconnmanager-co

...which suggests that when you get an error response from HttpClient, you have to consume the body of the response so that the connection can be properly closed.

My patch adds this, and gets rid of the above runtime exception. NOTE: You need HttpCore 4.1 for this, as the EntityUtils class is a new addition.

Discussion

  • Patch against current JWBF SVN

     
    Attachments
  • Loki
    Loki
    2013-04-04

    • status: open --> closed-accepted
    • milestone: --> Unstable_(example)