hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Boris J. Bonfils" <...@bording.dk>
Subject null response stream when posting using https
Date Fri, 23 May 2003 14:04:50 GMT
Hi!

I'm trying to get your cool httpclient to work against a tomcat v. 4.06. 
When using PostMethod and GetMethod on an unsecure URL 
everything works fine. 
However I only get a correct response under https for the GetMethod.
The PostMethod reaches the server allright and the client seems to start
reading the response header but then I get a null pointer exception 
when accessing the response body or stream. I include the code snippet
and a wire trace.

Really hope you guys have a suggestion to what may be wrong here..

Best Regards,
Boris Jan Bonfils

==== BEGIN CODE SNIPPET =============
	HttpMethod method;
	HttpClient client = new HttpClient();
	URI uri = new
URI("https://127.0.0.1:8443/servlet/dk.bording.axt.test.TestServlet");

	boolean post=true;
	if(post) {
		method = new PostMethod(uri.toString());
		((PostMethod) method).setRequestBody("" + 100 + "\nPlease
return 100 bytes\n");
	} else {
		method = new GetMethod(uri.toString());
	}

	// Execute the method.
	int statusCode = -1;
	int attempt = 0;
	// We will retry up to 3 times.
	while (statusCode == -1 && attempt < 3) {
	  try {
		// execute the method.
		statusCode = client.executeMethod(method);
		Header []hders = method.getResponseHeaders();
		for(int x=0; x<hders.length; x++) {
			System.err.println(hders[x].toString());
		}
	  } catch (HttpRecoverableException e) {
		System.err.println(
		  "A recoverable exception occurred, retrying." + 
		  e.getMessage());
	  } catch (IOException e) {
		System.err.println("Failed to download file.");
		e.printStackTrace();
		System.exit(-1);
	  }
	}
	// Check that we didn't run out of retries.
	if (statusCode == -1) {
	  System.err.println("Failed to recover from exception.");
	  System.exit(-2);
	}

	// THIS ONE FAILS WITH AN EXCEPTION !!!!!!!
	// Read the response body.
	byte[] responseBody = method.getResponseBody();
==== END CODE SNIPPET

==== DEBUG TRACE AND EXCEPTION ====
0 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - enter
getContentCharSet( Header contentheader )
0 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - Default charset
used: ISO-8859-1
531 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - enter
HttpMethodBase.execute(HttpState, HttpConnection)
571 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - Execute loop
try 1
571 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - enter
HttpMethodBase.processRequest(HttpState, HttpConnection)
571 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - Attempt number
1 to write request
571 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - enter
HttpMethodBase.writeRequest(HttpState, HttpConnection)
571 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - enter
HttpMethodBase.writeRequestLine(HttpState, HttpConnection)
571 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - enter
HttpMethodBase.generateRequestLine(HttpConnection, String, String, String,
String)
581 [main] DEBUG httpclient.wire  - >> "POST
/servlet/dk.bording.axt.test.TestServlet HTTP/1.1
" [\r\n]
751 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - enter
HttpMethodBase.writeRequestHeaders(HttpState,HttpConnection)
751 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - enter
HttpMethodBase.addRequestHeaders(HttpState, HttpConnection)
751 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - enter
HttpMethodBase.addUserAgentRequestHeaders(HttpState, HttpConnection)
751 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - enter
HttpMethodBase.addHostRequestHeader(HttpState, HttpConnection)
751 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - Adding Host
request header
751 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - enter
HttpMethodBase.addCookieRequestHeader(HttpState, HttpConnection)
841 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - enter
HttpMethodBase.addAuthorizationRequestHeader(HttpState, HttpConnection)
841 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - enter
HttpMethodBase.addProxyAuthorizationRequestHeader(HttpState, HttpConnection)
841 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - enter
HttpMethodBase.addContentLengthRequestHeader(HttpState, HttpConnection)
841 [main] DEBUG httpclient.wire  - >> "User-Agent: Jakarta
Commons-HttpClient/2.0alpha3
" [\r\n]
841 [main] DEBUG httpclient.wire  - >> "Host: 127.0.0.1:8443
" [\r\n]
851 [main] DEBUG httpclient.wire  - >> "Content-Length: 17
" [\r\n]
851 [main] DEBUG httpclient.wire  - >> "Expect: 100-continue
" [\r\n]
851 [main] DEBUG httpclient.wire  - >> [\r\n]
3866 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - Response not
available. Send the request body
3866 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - enter
writeRemainingRequestBody(HttpState, HttpConnection)
3886 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - enter
HttpMethodBase.readResponse(HttpState, HttpConnection)
3896 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - enter
HttpMethodBase.readStatusLine(HttpState, HttpConnection)
3896 [main] DEBUG httpclient.wire  - << "HTTP/1.1 100 Continue
" [\r\n]
3906 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - enter
HttpMethodBase.readResponseHeaders(HttpState,HttpConnection)
3906 [main] DEBUG httpclient.wire  - << "
" [\r\n]
3916 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - enter
HttpMethodBase.processResponseHeaders(HttpState, HttpConnection)
3916 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - enter
HttpMethodBase.readResponseBody(HttpState, HttpConnection)
3916 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - enter
HttpMethodBase.readResponseBody(HttpState, HttpConnection)
3916 [main] DEBUG org.apache.commons.httpclient.HttpMethod  - enter
HttpMethodBase.canResponseHaveBody(int)
java.lang.NullPointerException
	at
org.apache.commons.httpclient.HttpMethodBase.getResponseBody(HttpMethodBase.
java:670)
	at
org.apache.commons.httpclient.methods.GetMethod.getResponseBody(GetMethod.ja
va:293)
	at
dk.bording.axt.test.HTTPSBenchmark.apacheExample(HTTPSBenchmark.java:678)
	at dk.bording.axt.test.HTTPSBenchmark.main(HTTPSBenchmark.java:716)
Exception in thread "main" 



Mime
View raw message