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 Glenn Holmer <gh...@weycogroup.com> on 2006/10/02 16:07:04 UTC
ProtocolException question
I'm writing code to connect to an SSL server. Although I can see the
responses I'm expecting in the wire trace, the program still fails on a
ProtocolException (when I call client.executeMethod() with a
PostMethod). I've tried several adjustments:
client = new HttpClient();
client.getParams().setParameter(
"http.protocol.version",
HttpVersion.HTTP_1_0);
client.getParams().setParameter(
"http.protocol.content-charset",
"UTF-8");
client.getParams().setParameter(
"http.protocol.unambiguous-statusline",
false);
client.getParams().setParameter(
"http.protocol.strict-transfer-encoding",
false);
client.getParams().setParameter(
"http.protocol.status-line-garbage-limit",
Integer.MAX_VALUE);
Is there anything obvious I might have missed? This is the stack trace:
org.apache.commons.httpclient.ProtocolException: The server
xxxxxxxx.xxxxxxxx.com 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:397)
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:324)
--
____________________________________________________________
Glenn Holmer gholmer@weycogroup.com
Software Engineer phone: 414-908-1809
Weyco Group, Inc. fax: 414-908-1601
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
Re: ProtocolException question
Posted by Glenn Holmer <gh...@weycogroup.com>.
On Monday 02 October 2006 10:10, Roland Weber wrote:
> as Julius suspected, the server doesn't respond with an HTTP status
> line.
Thanks, it was my fault. The server has a couple of URI's you can talk
to, and I chose the one that doesn't send headers...
--
____________________________________________________________
Glenn Holmer gholmer@weycogroup.com
Software Engineer phone: 414-908-1809
Weyco Group, Inc. fax: 414-908-1601
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
Re: ProtocolException question
Posted by Roland Weber <ht...@dubioso.net>.
Hi Glenn,
as Julius suspected, the server doesn't respond with an HTTP status line.
> 2006-10-02 09:33:40 DEBUG header wire:69 >> "POST /xxxxxxx/xxxxxxx.cgi
> HTTP/1.1[\r][\n]"
> [...]
> 2006-10-02 09:33:40 DEBUG content wire:83 >> *** DATA REMOVED ***
> 2006-10-02 09:33:40 DEBUG EntityEnclosingMethod writeRequestBody:504
> Request body sent
So far, so good. Now we're waiting for "HTTP/1.1 200 OK" or some such:
> 2006-10-02 09:33:40 DEBUG HttpMethodBase readStatusLine:1823 enter
> HttpMethodBase.readStatusLine(HttpState, HttpConnection)
> 2006-10-02 09:33:41 DEBUG header wire:69 << "XXXXXXXXXXXXXXXXXXX=XX[\r]
> [\n]"
and this is what we get instead! It's not a status line, it's not
a header line. Either the server is generating garbage, or you have
a problem with thread synchronization. If multiple threads are using
the same connection (which shouldn't be possible with the
MultiThreadedHttpConnectionManager), then this could be explained
as the response body for some other request.
cheers,
Roland
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
Re: ProtocolException question
Posted by Glenn Holmer <gh...@weycogroup.com>.
On Monday 02 October 2006 09:29, Roland Weber wrote:
> please send a context/wire log of the failing request.
> Since you get some requests through without problems,
> it doesn't seem to be one of the usual mistakes.
I've had to redact some of this because of an NDA. Where it says "DATA
REMOVED" are the params I'm sending, in the form "0=xxx,1=xxx,...".
2006-10-02 09:33:39 DEBUG PostMethod setRequestBody:402 enter
PostMethod.setRequestBody(NameValuePair[])
2006-10-02 09:33:39 DEBUG PostMethod clearRequestBody:151 enter
PostMethod.clearRequestBody()
2006-10-02 09:33:39 DEBUG EntityEnclosingMethod clearRequestBody:149
enter EntityEnclosingMethod.clearRequestBody()
2006-10-02 09:33:39 DEBUG PostMethod addParameters:303 enter
PostMethod.addParameters(NameValuePair[])
2006-10-02 09:33:39 DEBUG EntityEnclosingMethod clearRequestBody:149
enter EntityEnclosingMethod.clearRequestBody()
2006-10-02 09:33:39 DEBUG HttpClient executeMethod:322 enter
HttpClient.executeMethod(HttpMethod)
2006-10-02 09:33:39 DEBUG HttpClient executeMethod:373 enter
HttpClient.executeMethod(HostConfiguration,HttpMethod,HttpState)
2006-10-02 09:33:39 DEBUG HttpMethodDirector executeWithRetry:378
Attempt number 1 to process request
2006-10-02 09:33:39 DEBUG HttpConnection open:684 enter
HttpConnection.open()
2006-10-02 09:33:39 DEBUG HttpConnection open:691 Open connection to
xxxxxxxx.xxxxxxxx.com:443
2006-10-02 09:33:40 DEBUG HttpMethodBase execute:976 enter
HttpMethodBase.execute(HttpState, HttpConnection)
2006-10-02 09:33:40 DEBUG HttpMethodBase writeRequest:1916 enter
HttpMethodBase.writeRequest(HttpState, HttpConnection)
2006-10-02 09:33:40 DEBUG HttpMethodBase writeRequestLine:2071 enter
HttpMethodBase.writeRequestLine(HttpState, HttpConnection)
2006-10-02 09:33:40 DEBUG HttpMethodBase generateRequestLine:1379 enter
HttpMethodBase.generateRequestLine(HttpConnection, String, String,
String, String)
2006-10-02 09:33:40 DEBUG header wire:69 >> "POST /xxxxxxx/xxxxxxx.cgi
HTTP/1.1[\r][\n]"
2006-10-02 09:33:40 DEBUG HttpConnection print:1031 enter
HttpConnection.print(String)
2006-10-02 09:33:40 DEBUG HttpConnection write:941 enter
HttpConnection.write(byte[])
2006-10-02 09:33:40 DEBUG HttpConnection write:962 enter
HttpConnection.write(byte[], int, int)
2006-10-02 09:33:40 DEBUG HttpMethodBase writeRequestHeaders:2034 enter
HttpMethodBase.writeRequestHeaders(HttpState,HttpConnection)
2006-10-02 09:33:40 DEBUG EntityEnclosingMethod addRequestHeaders:366
enter EntityEnclosingMethod.addRequestHeaders(HttpState,
HttpConnection)
2006-10-02 09:33:40 DEBUG ExpectContinueMethod addRequestHeaders:182
enter ExpectContinueMethod.addRequestHeaders(HttpState, HttpConnection)
2006-10-02 09:33:40 DEBUG HttpMethodBase addRequestHeaders:1300 enter
HttpMethodBase.addRequestHeaders(HttpState, HttpConnection)
2006-10-02 09:33:40 DEBUG HttpMethodBase addUserAgentRequestHeader:1325
enter HttpMethodBase.addUserAgentRequestHeaders(HttpState,
HttpConnection)
2006-10-02 09:33:40 DEBUG HttpMethodBase addHostRequestHeader:1211 enter
HttpMethodBase.addHostRequestHeader(HttpState, HttpConnection)
2006-10-02 09:33:40 DEBUG HttpMethodBase addHostRequestHeader:1235
Adding Host request header
2006-10-02 09:33:40 DEBUG HttpMethodBase addCookieRequestHeader:1163
enter HttpMethodBase.addCookieRequestHeader(HttpState, HttpConnection)
2006-10-02 09:33:40 DEBUG HttpState getCookies:172 enter
HttpState.getCookies()
2006-10-02 09:33:40 DEBUG CookieSpec match:548 enter
CookieSpecBase.match(String, int, String, boolean, Cookie[])
2006-10-02 09:33:40 DEBUG HttpMethodBase addProxyConnectionHeader:1262
enter HttpMethodBase.addProxyConnectionHeader(HttpState,
HttpConnection)
2006-10-02 09:33:40 DEBUG EntityEnclosingMethod
addContentLengthRequestHeader:397 enter
EntityEnclosingMethod.addContentLengthRequestHeader(HttpState,
HttpConnection)
2006-10-02 09:33:40 DEBUG EntityEnclosingMethod
getRequestContentLength:321 enter
EntityEnclosingMethod.getRequestContentLength()
2006-10-02 09:33:40 DEBUG PostMethod hasRequestContent:134 enter
PostMethod.hasRequestContent()
2006-10-02 09:33:40 DEBUG PostMethod getParameters:239 enter
PostMethod.getParameters()
2006-10-02 09:33:40 DEBUG HttpMethodBase getContentCharSet:2183 enter
getContentCharSet( Header contentheader )
2006-10-02 09:33:40 DEBUG HttpMethodBase getContentCharSet:2201 Default
charset used: UTF-8
2006-10-02 09:33:40 DEBUG HttpMethodBase addRequestHeader:382
HttpMethodBase.addRequestHeader(Header)
2006-10-02 09:33:40 DEBUG PostMethod getParameters:239 enter
PostMethod.getParameters()
2006-10-02 09:33:40 DEBUG HttpMethodBase getContentCharSet:2183 enter
getContentCharSet( Header contentheader )
2006-10-02 09:33:40 DEBUG HeaderElement parseElements:237 enter
HeaderElement.parseElements(String)
2006-10-02 09:33:40 DEBUG HeaderElement parseElements:193 enter
HeaderElement.parseElements(char[])
2006-10-02 09:33:40 DEBUG HeaderElement getParameterByName:278 enter
HeaderElement.getParameterByName(String)
2006-10-02 09:33:40 DEBUG HttpMethodBase getContentCharSet:2201 Default
charset used: UTF-8
2006-10-02 09:33:40 DEBUG header wire:69 >> "User-Agent: Jakarta
Commons-HttpClient/3.0.1[\r][\n]"
2006-10-02 09:33:40 DEBUG HttpConnection print:1031 enter
HttpConnection.print(String)
2006-10-02 09:33:40 DEBUG HttpConnection write:941 enter
HttpConnection.write(byte[])
2006-10-02 09:33:40 DEBUG HttpConnection write:962 enter
HttpConnection.write(byte[], int, int)
2006-10-02 09:33:40 DEBUG header wire:69 >> "Host:
xxxxxxxx.xxxxxxxx.com[\r][\n]"
2006-10-02 09:33:40 DEBUG HttpConnection print:1031 enter
HttpConnection.print(String)
2006-10-02 09:33:40 DEBUG HttpConnection write:941 enter
HttpConnection.write(byte[])
2006-10-02 09:33:40 DEBUG HttpConnection write:962 enter
HttpConnection.write(byte[], int, int)
2006-10-02 09:33:40 DEBUG header wire:69 >> "Content-Length: 597[\r]
[\n]"
2006-10-02 09:33:40 DEBUG HttpConnection print:1031 enter
HttpConnection.print(String)
2006-10-02 09:33:40 DEBUG HttpConnection write:941 enter
HttpConnection.write(byte[])
2006-10-02 09:33:40 DEBUG HttpConnection write:962 enter
HttpConnection.write(byte[], int, int)
2006-10-02 09:33:40 DEBUG header wire:69 >> "Content-Type:
application/x-www-form-urlencoded[\r][\n]"
2006-10-02 09:33:40 DEBUG HttpConnection print:1031 enter
HttpConnection.print(String)
2006-10-02 09:33:40 DEBUG HttpConnection write:941 enter
HttpConnection.write(byte[])
2006-10-02 09:33:40 DEBUG HttpConnection write:962 enter
HttpConnection.write(byte[], int, int)
2006-10-02 09:33:40 DEBUG HttpConnection writeLine:1000 enter
HttpConnection.writeLine()
2006-10-02 09:33:40 DEBUG HttpConnection write:941 enter
HttpConnection.write(byte[])
2006-10-02 09:33:40 DEBUG HttpConnection write:962 enter
HttpConnection.write(byte[], int, int)
2006-10-02 09:33:40 DEBUG header wire:69 >> "[\r][\n]"
2006-10-02 09:33:40 DEBUG EntityEnclosingMethod writeRequestBody:465
enter EntityEnclosingMethod.writeRequestBody(HttpState, HttpConnection)
2006-10-02 09:33:40 DEBUG PostMethod hasRequestContent:134 enter
PostMethod.hasRequestContent()
2006-10-02 09:33:40 DEBUG EntityEnclosingMethod
getRequestContentLength:321 enter
EntityEnclosingMethod.getRequestContentLength()
2006-10-02 09:33:40 DEBUG PostMethod hasRequestContent:134 enter
PostMethod.hasRequestContent()
2006-10-02 09:33:40 DEBUG HttpConnection getRequestOutputStream:839
enter HttpConnection.getRequestOutputStream()
2006-10-02 09:33:40 DEBUG content wire:83 >> *** DATA REMOVED ***
2006-10-02 09:33:40 DEBUG EntityEnclosingMethod writeRequestBody:504
Request body sent
2006-10-02 09:33:40 DEBUG HttpConnection flushRequestOutputStream:825
enter HttpConnection.flushRequestOutputStream()
2006-10-02 09:33:40 DEBUG HttpMethodBase readResponse:1585 enter
HttpMethodBase.readResponse(HttpState, HttpConnection)
2006-10-02 09:33:40 DEBUG HttpMethodBase readStatusLine:1823 enter
HttpMethodBase.readStatusLine(HttpState, HttpConnection)
2006-10-02 09:33:40 DEBUG HttpConnection readLine:1112 enter
HttpConnection.readLine()
2006-10-02 09:33:41 DEBUG HttpParser readLine:104 enter
HttpParser.readLine(InputStream, String)
2006-10-02 09:33:41 DEBUG HttpParser readRawLine:73 enter
HttpParser.readRawLine()
2006-10-02 09:33:41 DEBUG header wire:69 << "XXXXXXXXXXXXXXXXXXX=XX[\r]
[\n]"
2006-10-02 09:33:41 DEBUG HttpConnection readLine:1112 enter
HttpConnection.readLine()
2006-10-02 09:33:41 DEBUG HttpParser readLine:104 enter
HttpParser.readLine(InputStream, String)
2006-10-02 09:33:41 DEBUG HttpParser readRawLine:73 enter
HttpParser.readRawLine()
2006-10-02 09:33:41 DEBUG header wire:69 << "XXXXXXXXXXXXXXXXX=X[\r]
[\n]"
(several more similar responses)
2006-10-02 09:33:41 DEBUG HttpConnection readLine:1112 enter
HttpConnection.readLine()
2006-10-02 09:33:41 DEBUG HttpParser readLine:104 enter
HttpParser.readLine(InputStream, String)
2006-10-02 09:33:41 DEBUG HttpParser readRawLine:73 enter
HttpParser.readRawLine()
2006-10-02 09:33:41 DEBUG header wire:69 << "null[\r][\n]"
2006-10-02 09:33:41 DEBUG HttpMethodDirector executeWithRetry:449
Closing the connection.
2006-10-02 09:33:41 DEBUG HttpConnection close:1147 enter
HttpConnection.close()
org.apache.commons.httpclient.ProtocolException: The server
xxxxxxxx.xxxxxxxx.com failed to respond with a valid HTTP response
at
org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1846)
--
____________________________________________________________
Glenn Holmer gholmer@weycogroup.com
Software Engineer phone: 414-908-1809
Weyco Group, Inc. fax: 414-908-1601
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
Re: ProtocolException question
Posted by Roland Weber <ht...@dubioso.net>.
Hello Glenn,
please send a context/wire log of the failing request.
Since you get some requests through without problems,
it doesn't seem to be one of the usual mistakes.
cheers,
Roland
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
Re: ProtocolException question
Posted by Julius Davies <ju...@cucbc.com>.
Hi,
Is your server responding with the very important HTTP status line? It
looks like this:
HTTP/1.1 200 OK
Try telnetting in and performing the same HTTP request. If you're
connecting to an SSL server you'll probably need to use openssl's
"s_client" command.
openssl s_client -connect www.cucbc.com:443
After all the certificate and SSL information flies by on the screen,
type in something like this:
HEAD / HTTP/1.0[enter]
[enter]
Replace "www.cucbc.com" with whatever server you are connecting to.
Replace "/" with the path of the resource you are requesting. You
should hopefully see a response like this:
HTTP/1.1 200 OK
Date: Mon, 02 Oct 2006 14:22:02 GMT
Server: Apache/2.0.46 (Red Hat)
Accept-Ranges: bytes
Connection: close
Content-Type: text/html; charset=UTF-8
If you are on Windows you can download OpenSSL starting from this link:
http://www.openssl.org/related/binaries.html
Instead of the openssl "s_client" command, you could try this pure-java
"commons-ssl" Ping utility I'm working on instead, but it only does
"HEAD /" - it doesn't try any other URL's. You'd need to hack it up a
bit to get different URLs.
http://juliusdavies.ca/commons-ssl/
Download "commons-ssl.jar" or "commons-ssl.zip", and once you have a jar
file, try this:
java -jar commons-ssl.jar
Hopefully that will show whether your server is correctly responding
with a status line!
yours,
Julius
On Mon, 2006-02-10 at 09:07 -0500, Glenn Holmer wrote:
> I'm writing code to connect to an SSL server. Although I can see the
> responses I'm expecting in the wire trace, the program still fails on a
> ProtocolException (when I call client.executeMethod() with a
> PostMethod). I've tried several adjustments:
>
> client = new HttpClient();
> client.getParams().setParameter(
> "http.protocol.version",
> HttpVersion.HTTP_1_0);
> client.getParams().setParameter(
> "http.protocol.content-charset",
> "UTF-8");
> client.getParams().setParameter(
> "http.protocol.unambiguous-statusline",
> false);
> client.getParams().setParameter(
> "http.protocol.strict-transfer-encoding",
> false);
> client.getParams().setParameter(
> "http.protocol.status-line-garbage-limit",
> Integer.MAX_VALUE);
>
> Is there anything obvious I might have missed? This is the stack trace:
>
> org.apache.commons.httpclient.ProtocolException: The server
> xxxxxxxx.xxxxxxxx.com 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:397)
> 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:324)
>
--
Julius Davies
Senior Application Developer, Technology Services
Credit Union Central of British Columbia
http://www.cucbc.com/
Tel: 416-652-0183
Cel: 647-232-7571
1441 Creekside Drive
Vancouver, BC
Canada
V6J 4S7
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org