[TIMOB-2676] Titanium Mobile Android HttpClient Unable to Handle 204 Error Code
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2017-07-26T03:12:21.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Android |
Labels | android, httpclient, response, xhr |
Reporter | philip.jarrell (at gmail) |
Assignee | Ashraf Abu |
Created | 2011-04-15T03:26:43.000+0000 |
Updated | 2017-07-26T03:12:21.000+0000 |
Description
The Android HttpClient module in 1.5.1 is unable to handle a missing entity. This is possible when encountering a 204 HTTP status code (no content).
The following is stated in the Apache HttpClient "http://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/HttpEntity.html" Java API doc:
"An entity that can be sent or received with an HTTP message. Entities can be found in some requests and in responses, where they are optional."
Currently lines 203 - 208 in TiHTTPClient.java assume that any status code less then 300 will have an entity. However this is not true. Other codes may not. This includes 204 (no content) and 201 (created).
Requests made that result in these response codes will currently result in null pointer exceptions when executing line 209:
entity = response.getEntity();
if (entity.getContentType() != null) {
contentType = entity.getContentType().getValue();
}
The iPhone version does not appear to suffer from the same issue.
Assigning to Don for triage.
Come on.. Why hasn't this been fixed yet? Reported over 4 years ago...
[~msamah] FYI
[~jalo@emtnordic.com] Could I help assist if you are facing this issue? If so, are there logs or code that you can provide to help speed up the progress of this ticket. Any information would be much appreciated in fixing the issue that you are facing.
For this particular ticket and that code, it has been fixed in this PR https://github.com/appcelerator/titanium_mobile/commit/cafb4fe6e7445043fea61bd846bdfdba8a533311
Tested with 5.0.2.GA with the following code and there is no problem To check there is indeed no entity, run this in terminal 'curl -D - https://httpbin.org/status/204'.
If there is no more updates related to the ticket, I'll close this as invalid as it is not reproducible.
* I use Ti.Network.createHTTPClient. * Then I call a service, which returns 204 and an empty body, which is a valid response. * This results in the following error and the "onerror" function on HTTPClient is called. [ERROR] TiHTTPClient: (TiHttpClient-21) [120368,593182] HTTP Error (java.lang.NullPointerException): Attempt to invoke virtual method 'java.lang.String[] java.lang.String.split(java.lang.String)' on a null object reference [ERROR] TiHTTPClient: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String[] java.lang.String.split(java.lang.String)' on a null object reference [ERROR] TiHTTPClient: at ti.modules.titanium.network.TiHTTPClient.handleResponse(TiHTTPClient.java:195) [ERROR] TiHTTPClient: at ti.modules.titanium.network.TiHTTPClient.access$1200(TiHTTPClient.java:84) [ERROR] TiHTTPClient: at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1194) [ERROR] TiHTTPClient: at java.lang.Thread.run(Thread.java:818) [ERROR] TiHTTPClient: (TiHttpClient-20) [1,593183] HTTP Error (java.lang.NullPointerException): Attempt to invoke virtual method 'java.lang.String[] java.lang.String.split(java.lang.String)' on a null object reference [ERROR] TiHTTPClient: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String[] java.lang.String.split(java.lang.String)' on a null object reference [ERROR] TiHTTPClient: at ti.modules.titanium.network.TiHTTPClient.handleResponse(TiHTTPClient.java:195) [ERROR] TiHTTPClient: at ti.modules.titanium.network.TiHTTPClient.access$1200(TiHTTPClient.java:84) [ERROR] TiHTTPClient: at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1194) [ERROR] TiHTTPClient: at java.lang.Thread.run(Thread.java:818)
My SDK info: Appcelerator Command-Line Interface, version 5.0.3 Copyright (c) 2014-2015, Appcelerator, Inc. All Rights Reserved. 10/27/2015, 8:01:17 AM Operating System Name = Mac OS X Version = 10.10.5 Architecture = 64bit # CPUs = 4 Memory = 12884901888 Node.js Node.js Version = 0.12.7 npm Version = 2.11.3 Titanium CLI CLI Version = 5.0.5 Titanium SDK SDK Version = 5.0.2.GA SDK Path = /Users/jalo/Library/Application Support/Titanium/mobilesdk/osx/5.0.2.GA Target Platform = android