commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bryce Fischer <br...@berzerker-soft.com>
Subject [HTTPClient] Getting Protocol Exception
Date Fri, 09 Dec 2005 16:41:11 GMT
I am trying to use the HttpClient library to replace the Oreilly
HttpMessage class. The following worked for the Oreilly classes
(except not being able to easily set a timeout).
When executing the method, I get the following error message (full
Stack trace at the bottom):
org.apache.commons.httpclient.ProtocolException: The server
xxx.xxx.xxx.xxx failed to respond with a valid HTTP response
Here is the relevant code (implemented in a JUnit test case):


       HostConfiguration config = new HostConfiguration();

        config.getParams().setParameter("http.protocol.strict-transfer-encoding",
new Boolean(false));
        config.getParams().setParameter("http.protocol.unambiguous-statusline",
new Boolean(false));
        config.getParams().setParameter("http.protocol.reject-head-body",
new Boolean(false));

        PostMethod method = new PostMethod("http://xxx.xxx.xxx:81");
        NameValuePair[] data = {
                new NameValuePair("xml", xml)
        };

        method.setRequestBody(data); // HERE IS WHERE EXCEPTION OCCURS!

        int statusCode = httpClient.executeMethod(config, method);
        byte[] bytes = method.getResponseBody();


Here is the wire trace:

DEBUG [httpclient.wire.header] >> "POST / HTTP/1.1[\r][\n]"
DEBUG [httpclient.wire.header] >> "User-Agent: Jakarta
Commons-HttpClient/3.0-rc4[\r][\n]"
DEBUG [httpclient.wire.header] >> "Host: xxx.xxx.xxx.xxx:81[\r][\n]"
DEBUG [httpclient.wire.header] >> "Content-Length: 4462[\r][\n]"
DEBUG [httpclient.wire.header] >> "Content-Type:
application/x-www-form-urlencoded[\r][\n]"
DEBUG [httpclient.wire.header] >> "[\r][\n]"
DEBUG [httpclient.wire.content] >> "xml=<content removed>"
DEBUG [httpclient.wire.header] << "<xml data removed>"
DEBUG [httpclient.wire.header] << "  <more data removed>[\r][\n]"
DEBUG [httpclient.wire.header] << "  <more data removed[\r][\n]"
DEBUG [httpclient.wire.header] << "<more data removed[\r][\n]"
DEBUG [httpclient.wire.header] << "<data removed>[\r][\n]"
DEBUG [httpclient.wire.header] << "null[\r][\n]"

First thing I noticed was that the data was being returned with the
header. That is why I was trying to set the parameters in the code
above (it didn't work without the parameters either).

Any help would be appreciated.

Thanks
Bryce

Entire Stack Trace:
org.apache.commons.httpclient.ProtocolException: The server
xxx.xxx.xxx.xxx failed to respond with a valid HTTP response
	at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1846)
	at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1590)
	at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:995)
	at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:395)
	at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
	at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
	at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)
	at com.company.Test.testMakeRequest2(Test.java:81)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:31)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message