You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Bryce Fischer <br...@berzerker-soft.com> on 2005/12/09 17:41:11 UTC
[HTTPClient] Getting Protocol Exception
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
Re: [HTTPClient] Getting Protocol Exception
Posted by Bryce Fischer <br...@berzerker-soft.com>.
On 12/9/05, Bryce Fischer <br...@berzerker-soft.com> wrote:
> [...]
> DEBUG [httpclient.wire.header] << "<data removed>[\r][\n]"
> DEBUG [httpclient.wire.header] << "null[\r][\n]"
Well, stepping through the source code, I noticed this:
File: org.apache.commons.httpclient.HttpMethodBase
Line: 1846
Method: protected void readStatusLine(HttpState state, HttpConnection conn)
} else if (s == null || count >= maxGarbageLines) {
// Giving up
throw new ProtocolException("The server " + conn.getHost() +
" failed to respond with a valid HTTP response");
}
I also noticed that the last line the server sends is a null... So I
guess I have my answer. Doesn't look like much I can do.
> 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).
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [HTTPClient] Getting Protocol Exception
Posted by Bryce Fischer <br...@berzerker-soft.com>.
On 12/9/05, sebb <se...@gmail.com> wrote:
> On 09/12/05, Bryce Fischer <br...@berzerker-soft.com> wrote:
> [...]
> > config.getParams().setParameter("http.protocol.strict-transfer-encoding",
> > new Boolean(false));
>
> Boolean.FALSE would be cheaper.
>
> Sorry, could not resist...
No appologies needed. Its something I threw together quickly just to
test the behaviour.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [HTTPClient] Getting Protocol Exception
Posted by sebb <se...@gmail.com>.
On 09/12/05, Bryce Fischer <br...@berzerker-soft.com> wrote:
[...]
> config.getParams().setParameter("http.protocol.strict-transfer-encoding",
> new Boolean(false));
Boolean.FALSE would be cheaper.
Sorry, could not resist...
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [HTTPClient] Getting Protocol Exception
Posted by Bryce Fischer <br...@berzerker-soft.com>.
On 12/9/05, Oleg Kalnichevski <ol...@apache.org> wrote:
> On Fri, 2005-12-09 at 11:41 -0500, Bryce Fischer wrote:
>
> > 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]"
> >
> Bryce,
>
> What server is sending back is not a valid HTTP response. HttpClient is
> absolutely correct in throwing a protocol exception
>
> Oleg
Yea, you are correct. Its a server that a coworker wrote, and
unfortunately, I'm having difficulty getting him to fix it (he claims
its worked for 5 years now, why it needs to change now). I was just
hoping there was a way around it, but going through the code, doesn't
look like there is.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [HTTPClient] Getting Protocol Exception
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2005-12-09 at 11:41 -0500, Bryce Fischer wrote:
> 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]"
>
Bryce,
What server is sending back is not a valid HTTP response. HttpClient is
absolutely correct in throwing a protocol exception
Oleg
> 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
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org