Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-24809] Android: HTTPClient - "onload" not dispatched. #9139

Merged
merged 8 commits into from Jun 14, 2017

Conversation

ypbnv
Copy link
Contributor

@ypbnv ypbnv commented Jun 12, 2017

Clear parts and nvPairs before reusing the client.

JIRA: https://jira.appcelerator.org/browse/TIMOB-24809

Clear parts and pairs collections before reusing the client.
//Clear parts and nvPairs before sending new data
nvPairs.clear();
parts.clear();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to clear the values only after they have been used:

L1145

if (nvPairs.size() > 0) {
	try {
		form = new UrlEncodedFormEntity(nvPairs, "UTF-8");
	} catch (UnsupportedEncodingException e) {
		Log.e(TAG, "Unsupported encoding: ", e);
	}
	nvPairs.clear();
}

L1198

for(String name : parts.keySet()) {
	Log.d(TAG, "adding part " + name + ", part type: " + parts.get(name).getMimeType() + ", len: "
			+ parts.get(name).getContentLength(), Log.DEBUG_MODE);
	addFilePart(name, parts.get(name));
}
parts.clear();

@ypbnv
Copy link
Contributor Author

ypbnv commented Jun 12, 2017

@garymathews Updated.

@garymathews garymathews changed the title [TIMOB-24809] Android: HTTPClient - "onload" not dispatched. [6_1_X][TIMOB-24809] Android: HTTPClient - "onload" not dispatched. Jun 12, 2017
@garymathews garymathews changed the title [6_1_X][TIMOB-24809] Android: HTTPClient - "onload" not dispatched. [TIMOB-24809] Android: HTTPClient - "onload" not dispatched. Jun 12, 2017
@garymathews garymathews modified the milestones: 6.2.0, 6.1.1 Jun 12, 2017
Copy link
Contributor

@garymathews garymathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR: PASS
FT: PASS

Copy link
Contributor

@ssjsamir ssjsamir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FR Passed: Error is no longer shown when a request is finished.

Test Steps:

  • Downloaded the SDK Build form this PR
  • Created a new Titanium project
  • Copied the the test case from description
  • Ran the application
  • Pressed Get Photos
  • Saw the Response via alert box
  • Pressed the upload button
  • Error was not shown
  • Saw the Response via alert box

Test Environment
Appcelerator Command-Line Interface, version 6.2.2
Google Nexus 6P (7.1.1)
Operating System Name: Mac OS X El Capitan
Operating System Version: 10.11.6
Node.js Version: 6.10.1
Xcode: 8.2
Appcelerator Studio: 4.9.0.201705251638

@@ -730,6 +731,11 @@ public String getResponseHeader(String getHeaderName)

public void open(String method, String url)
{
if (requestPending) {
Log.w(TAG,"Open canceled. Connection is already opened and a request is pending.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log.w(TAG, "open cancelled, a request is already pending for response.");
  • space after comma

@@ -1009,6 +1015,13 @@ private Object titaniumFileAsPutData(Object value)

public void send(Object userData) throws UnsupportedEncodingException
{

if (requestPending) {
//Log.w(TAG,"Request currently in transmission!");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this commented line


if (requestPending) {
//Log.w(TAG,"Request currently in transmission!");
Log.w(TAG,"Send canceled. A request with the same TiHTTPClient is pending!");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log.w(TAG, "send cancelled, a request is already pending for response.");

Copy link
Contributor

@garymathews garymathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR: FAIL

@ypbnv
Copy link
Contributor Author

ypbnv commented Jun 14, 2017

@garymathews Updated warning messages.

Copy link
Contributor

@garymathews garymathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR: PASS

Copy link
Contributor

@ssjsamir ssjsamir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FR Passed following the earlier steps. However I did change the requestbin link as the link had expired.

var window = Ti.UI.createWindow();
var buttonUpload = Ti.UI.createButton({title:"Upload", top:50});
var buttonGetPhotos = Ti.UI.createButton({title:"Get Photos", top: 110});
var xhr = Titanium.Network.createHTTPClient({timeout:5000});
 
var tempF = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory,"simpleTest.png");
Ti.API.info(tempF);
 
buttonUpload.addEventListener('click', function (e) {
    xhr.open("POST","https://requestb.in/16ixvgy1");
 
    var data_to_send = {
        "file": tempF.read(),
    };
 
    xhr.onload = function () {(alert(this.responseText))};
    xhr.send(data_to_send);
});
 
buttonGetPhotos.addEventListener('click', function (e) {    
    xhr.open("POST","https://requestb.in/16ixvgy1");
 
    var params = {
            id:46
    };
 
    xhr.onload = function (e) {alert(this.responseText)};
    xhr.send(params);
});
 
window.add(buttonGetPhotos);
window.add(buttonUpload);
window.open();

Test Steps:

  • Downloaded the SDK Build form this PR
  • Created a new Titanium project
  • Copied the the test case from description
  • Ran the application
  • Pressed Get Photos
  • Saw the Response
  • Pressed the upload button
  • Error was not shown

Test Environment
Appcelerator Command-Line Interface, version 6.2.2
Google Nexus 6P (7.1.1)
Operating System Name: Mac OS X El Capitan
Operating System Version: 10.11.6
Node.js Version: 6.10.1
Xcode: 8.2
Appcelerator Studio: 4.9.0.201705251638

@ssjsamir ssjsamir merged commit 9ab1627 into tidev:master Jun 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants