You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Gerardo Corro <ro...@hotmail.com> on 2009/06/08 22:01:15 UTC

java.lang.IllegalStateException: Connection is not open

Hi HttpClient people,


I'm creating an Http filter, I have to replace the calls to java.net API methods with the Apache HTTP Client 3.1 API. This filter works properly for GET requests, however it does not work that great with POST requests, the thing is that the filter makes some business and redirection logic depending upon the headers of the request, however for POST requests it has to pass the content as it comes to the target destination.

The problem comes when it passes the content of the POST request, it takes forever to pass the content until a timeout error pops-up



            //THIS SNIPPET NEVER ENDS
                            if (httpRequest.getMethod().equals("POST")) {
                                //URL redirectUrl = new URL(resourcePath.toString());
                                //HttpURLConnection httpURLConn = (HttpURLConnection) redirectUrl.openConnection();
                                //httpURLConn.setDoOutput(true);
                                HttpConnection connection  = httpClient.getHttpConnectionManager().getConnection(hostConfiguration);
                                if(!connection.isOpen()) connection.open();

                                //BufferedOutputStream theServletBOSW = new BufferedOutputStream(httpURLConn.getOutputStream());
                                BufferedOutputStream newTheServletBOSW = new BufferedOutputStream(connection.getRequestOutputStream());
                                //ServletInputStream theSIS = httpRequest.getInputStream();
                                ServletInputStream newTheSIS = httpRequest.getInputStream();
                                //while ((read = theSIS.read(buffer)) > 0) {
                                    //theServletBOSW.write(buffer, 0, read);
                                //}

                                while ((newRead = newTheSIS.read(newBuffer)) > 0) {
                                    newTheServletBOSW.write(newBuffer, 0, newRead);
                                }

                                //theServletBOSW.flush();
                                //theServletBOSW.close();
                                //theSIS.close();

                                newTheServletBOSW.flush();
                                newTheServletBOSW.close();
                                newTheSIS.close();
                            }


                int responseCode = httpClient.executeMethod(hostConfiguration, httpMethod);






What's wrong?

Thank you!!!


_________________________________________________________________
Windows Live™: Keep your life in sync. Check it out!
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_012009

java.net.ConnectException: Connection timed out

Posted by Gerardo Corro <ro...@hotmail.com>.
Sorry, correcting the title of the problem, the description contained in the body is correct.


> 
> 
> Hi HttpClient people,
> 
> 
> I'm creating an Http filter, I have to replace the calls to java.net API methods with the Apache HTTP Client 3.1 API. This filter works properly for GET requests, however it does not work that great with POST requests, the thing is that the filter makes some business and redirection logic depending upon the headers of the request, however for POST requests it has to pass the content as it comes to the target destination.
> 
> The problem comes when it passes the content of the POST request, it takes forever to pass the content until a timeout error pops-up
> 
> 
> 
>             //THIS SNIPPET NEVER ENDS
>                             if (httpRequest.getMethod().equals("POST")) {
>                                 //URL redirectUrl = new URL(resourcePath.toString());
>                                 //HttpURLConnection httpURLConn = (HttpURLConnection) redirectUrl.openConnection();
>                                 //httpURLConn.setDoOutput(true);
>                                 HttpConnection connection  = httpClient.getHttpConnectionManager().getConnection(hostConfiguration);
>                                 if(!connection.isOpen()) connection.open();
> 
>                                 //BufferedOutputStream theServletBOSW = new BufferedOutputStream(httpURLConn.getOutputStream());
>                                 BufferedOutputStream newTheServletBOSW = new BufferedOutputStream(connection.getRequestOutputStream());
>                                 //ServletInputStream theSIS = httpRequest.getInputStream();
>                                 ServletInputStream newTheSIS = httpRequest.getInputStream();
>                                 //while ((read = theSIS.read(buffer)) > 0) {
>                                     //theServletBOSW.write(buffer, 0, read);
>                                 //}
> 
>                                 while ((newRead = newTheSIS.read(newBuffer)) > 0) {
>                                     newTheServletBOSW.write(newBuffer, 0, newRead);
>                                 }
> 
>                                 //theServletBOSW.flush();
>                                 //theServletBOSW.close();
>                                 //theSIS.close();
> 
>                                 newTheServletBOSW.flush();
>                                 newTheServletBOSW.close();
>                                 newTheSIS.close();
>                             }
> 
> 
>                 int responseCode = httpClient.executeMethod(hostConfiguration, httpMethod);
> 
> 
> 
> 
> 
> 
> What's wrong?
> 
> Thank you!!!
> 
> 
> _________________________________________________________________
> Windows Live™: Keep your life in sync. Check it out!
> http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_012009

_________________________________________________________________
Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.

http://www.microsoft.com/windows/windowslive/products/photos.aspx