Reputation: 12637
This is really weird. I have a function that look pretty much the same but doesn't throw the exception. Here is problematic code:
public Header[] generateHeaders() {
Header[] headers = new Header[2];
headers[0] = new BasicHeader("Client", "android");
headers[1] = new BasicHeader("Accept", "application/json; charset=UTF-8");
return headers;
}
public HttpPost getHttpRequestPost() throws URISyntaxException {
HttpPost request = new HttpPost(new URI(generateQueryUrl()));
request.setHeaders(generateHeaders());
setTimeout(request);
return request;
}
protected Query buildQuery() {
Query query = null;
query = new Query(new Config(), getContext());
query.addOrderedParam(FUNCTION_NAME);
return query;
}
Code below causes ClientProtocolException
, precisely this: Caused by: org.apache.http.ProtocolException: Invalid header: :
public HttpResponse execute() throws URISyntaxException, ClientProtocolException,
IOException {
HttpClient client = new DefaultHttpClient();
HttpResponse response = response = client.execute(buildQuery().getHttpRequestPost());
return response;
}
It doesn't point to any of 2 headers but like some empty header. What is going on here?
Exception occurs inside client.execute(...), obviously I can't debug in there...
Those might be response headers... however I can't see anything wrong in fiddler. Here is request and response body:
Request
GET http://myapp.api.pl/api/bankName?accountNumber=32195000012006548541990002 HTTP/1.1
User-Agent: Fiddler
Accept: application/json
Client: android
Host: myapp.api.pl
Response
HTTP/1.1 404 Not Found
Date: Tue, 12 Nov 2013 08:35:01 GMT
Server: Apache
X-Powered-By: PleskLin
Content-Length: 0
Connection: close
Content-Type: application/json; charset=UTF-8
Ok I lied a bit, not everything is allright in fiddler. If the parameter accountNumber specifies wrong number, function is supposed to return 404. It does, but also there is error popup in fiddler:
EDIT: Pasting requested stack trace:
11-08 13:09:30.691: W/System.err(20729): org.apache.http.client.ClientProtocolException
11-08 13:09:30.701: W/System.err(20729): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:557)
11-08 13:09:30.711: W/System.err(20729): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
11-08 13:09:30.711: W/System.err(20729): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
11-08 13:09:30.721: W/System.err(20729): at pl.test.helloapp.communication.requests.BaseRequest.execute(BaseRequest.java:75)
11-08 13:09:30.721: W/System.err(20729): at pl.test.helloapp.async.LoginAsyncTask.doInBackground(LoginAsyncTask.java:51)
11-08 13:09:30.721: W/System.err(20729): at pl.test.helloapp.async.LoginAsyncTask.doInBackground(LoginAsyncTask.java:1)
11-08 13:09:30.721: W/System.err(20729): at android.os.AsyncTask$2.call(AsyncTask.java:287)
11-08 13:09:30.731: W/System.err(20729): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
11-08 13:09:30.731: W/System.err(20729): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
11-08 13:09:30.731: W/System.err(20729): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
11-08 13:09:30.731: W/System.err(20729): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
11-08 13:09:30.731: W/System.err(20729): at java.lang.Thread.run(Thread.java:841)
11-08 13:09:30.731: W/System.err(20729): Caused by: org.apache.http.ProtocolException: Invalid header: :
11-08 13:09:30.731: W/System.err(20729): at org.apache.http.impl.io.AbstractMessageParser.parseHeaders(AbstractMessageParser.java:162)
11-08 13:09:30.731: W/System.err(20729): at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:178)
11-08 13:09:30.741: W/System.err(20729): at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:180)
11-08 13:09:30.741: W/System.err(20729): at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:235)
11-08 13:09:30.741: W/System.err(20729): at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:259)
11-08 13:09:30.741: W/System.err(20729): at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:279)
11-08 13:09:30.741: W/System.err(20729): at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:121)
11-08 13:09:30.741: W/System.err(20729): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:428)
11-08 13:09:30.751: W/System.err(20729): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
11-08 13:09:30.751: W/System.err(20729): ... 11 more
Upvotes: 3
Views: 3677
Reputation: 12637
I wasn't able to fix the problem using this code. I swaped communication framework with another one. Apache HTTPClient had problem with those responses, but for HttpURLConnection everything was just fine, so I dropped the Apache usage.
Upvotes: 0
Reputation: 1103
Server seems response invalid http headers.
I guess the exception was raised from 'org.apache.http.message.BufferedHeader':
if (buffer == null) {
throw new IllegalArgumentException
("Char array buffer may not be null");
}
int colon = buffer.indexOf(':');
if (colon == -1) {
throw new ParseException
("Invalid header: " + buffer.toString());
}
String s = buffer.substringTrimmed(0, colon);
if (s.length() == 0) {
throw new ParseException
("Invalid header: " + buffer.toString());
}
this.buffer = buffer;
this.name = s;
this.valuePos = colon + 1;
can yout dump total http body by tcp dump, or enumerate by curl?
Upvotes: 6