Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19665] Android java error when making HTTP request to endpoint that returns 'true' or 'false'

GitHub Issuen/a
TypeImprovement
PriorityCritical
StatusClosed
ResolutionInvalid
Resolution Date2016-01-19T22:14:41.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterSeth Toda
AssigneeAshraf Abu
Created2015-10-03T00:31:28.000+0000
Updated2016-01-19T22:14:47.000+0000

Description

Steps to reproduce

Create xhr that pings an endpoint that returns 'true' or 'false

function doit() {
    var xhr = Ti.Network.createHTTPClient({
        onload: function onLoad(e) {
            alert("Received: Status = " + e.status + ", Value = " + e.responseText);
        },
        onerror: function onError(e) {
            alert("Error: Status = " + e.status + ", Value = " + e.responseText);
        }
    });

    xhr.open("GET", "https://13b6379a34068a7bb6c483d30f362f550675a41c.cloudapp-enterprise.appcelerator.com/t");
    xhr.send();
}

Error generated

[ERROR] TiHTTPClient: (TiHttpClient-1) [3054,3054] 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)

Endpoint

function t(req, res){
    res.end((((new Date()).getTime() & 1) == 1).toString());
}

Comments

  1. Ashraf Abu 2015-10-23

  2. Seth Toda 2015-10-23

    thanks [~msamah]
  3. Ashraf Abu 2015-10-29

    Resolving issue as Won't Fix Reason being the endpoint is not being detected as there is no header Content-Type. iOS and Android behaviour are the same. HTTP protocols docs https://tools.ietf.org/html/rfc7231#section-3.1.1.5 {quote} A sender that generates a message containing a payload body SHOULD generate a Content-Type header field in that message unless the intended media type of the enclosed representation is unknown to the sender. If a Content-Type header field is not present, the recipient MAY either assume a media type of "application/octet-stream" ([RFC2046], Section 4.5.1) or examine the data to determine its type. {quote} Thus the endpoint should set the header for iOS and Android client to get the proper payload.
  4. Ashraf Abu 2015-10-29

    Will look into this further.
  5. Ashraf Abu 2015-10-30

    Please run this code. This code will make it work.
       // this sets the background color of the master UIView (when there are no windows/tab groups on it)
       Titanium.UI.setBackgroundColor('#000');
        
       var win = Titanium.UI.createWindow({  
           title:'Tab 1',
           backgroundColor:'#fff'
       });
        
        
       var button = Titanium.UI.createButton({
       	title:'Press to click'
       });
        
       win.add(button);
        
       button.addEventListener('click', function(e) {
       	
       	var xhr = Ti.Network.createHTTPClient({
               onload: function(e) {
                   alert("Received: Status = " + this.status + ", Value = " + this.responseText);
                   Ti.API.info("Received: Status = " + this.status + ", Value = " + this.responseText);
               },
               onerror: function(e) {
                   alert("Error: Status = " + this.status + ", Value = " + this.responseText, " error:" + e.error);
               }
           });
        
        	var args = {
        		name: 'filename',
        		file: Ti.Filesystem.getFile("mytestfile.txt")
        	};
        
           xhr.open("GET", "https://13b6379a34068a7bb6c483d30f362f550675a41c.cloudapp-enterprise.appcelerator.com/t");
           xhr.send();
           
       
           
       });
        
       win.open();
        
           
    Resolving this as invalid as the code above will make it work.
  6. Ashraf Abu 2015-10-30

    Also, you can run appc ti sdk install -d -b 5_0_X to get the branch 5.0.3 which contains 5.0.2.GA with the fixes to the first error issue.

JSON Source