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
Conversation
Clear parts and pairs collections before reusing the client.
//Clear parts and nvPairs before sending new data | ||
nvPairs.clear(); | ||
parts.clear(); | ||
|
There was a problem hiding this comment.
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:
if (nvPairs.size() > 0) {
try {
form = new UrlEncodedFormEntity(nvPairs, "UTF-8");
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Unsupported encoding: ", e);
}
nvPairs.clear();
}
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();
@garymathews Updated. |
There was a problem hiding this 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
There was a problem hiding this 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."); |
There was a problem hiding this comment.
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!"); |
There was a problem hiding this comment.
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!"); |
There was a problem hiding this comment.
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.");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CR: FAIL
@garymathews Updated warning messages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CR: PASS
There was a problem hiding this 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
Clear parts and nvPairs before reusing the client.
JIRA: https://jira.appcelerator.org/browse/TIMOB-24809