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