forked from github/cordova-android
Return error conditions from CallbackServer instead of just closing connection.
This commit is contained in:
parent
be5cac6d0b
commit
80c15de606
@ -578,8 +578,8 @@ PhoneGap.run_command = function() {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
PhoneGap.JSCallbackPort = CallbackServer.getPort();
|
PhoneGap.JSCallbackPort = null;
|
||||||
PhoneGap.JSCallbackToken = CallbackServer.getToken();
|
PhoneGap.JSCallbackToken = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is only for Android.
|
* This is only for Android.
|
||||||
@ -605,7 +605,7 @@ PhoneGap.JSCallback = function() {
|
|||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
// If we're getting an error here, seeing the message will help in debugging
|
// If we're getting an error here, seeing the message will help in debugging
|
||||||
console.log("Message from Server: " + msg);
|
console.log("JSCallback: Message from Server: " + msg);
|
||||||
console.log("JSCallback Error: "+e);
|
console.log("JSCallback Error: "+e);
|
||||||
}
|
}
|
||||||
}, 1);
|
}, 1);
|
||||||
@ -617,15 +617,38 @@ PhoneGap.JSCallback = function() {
|
|||||||
setTimeout(PhoneGap.JSCallback, 10);
|
setTimeout(PhoneGap.JSCallback, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If security error
|
||||||
|
else if (xmlhttp.status == 403) {
|
||||||
|
console.log("JSCallback Error: Invalid token. Stopping callbacks.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// If server is stopping
|
||||||
|
else if (xmlhttp.status == 503) {
|
||||||
|
console.log("JSCallback Error: Service unavailable. Stopping callbacks.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// If request wasn't GET
|
||||||
|
else if (xmlhttp.status == 400) {
|
||||||
|
console.log("JSCallback Error: Bad request. Stopping callbacks.");
|
||||||
|
}
|
||||||
|
|
||||||
// If error, restart callback server
|
// If error, restart callback server
|
||||||
else {
|
else {
|
||||||
console.log("JSCallback Error: Request failed.");
|
console.log("JSCallback Error: Request failed.");
|
||||||
CallbackServer.restartServer();
|
CallbackServer.restartServer();
|
||||||
|
PhoneGap.JSCallbackPort = null;
|
||||||
|
PhoneGap.JSCallbackToken = null;
|
||||||
setTimeout(PhoneGap.JSCallback, 100);
|
setTimeout(PhoneGap.JSCallback, 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (PhoneGap.JSCallbackPort == null) {
|
||||||
|
PhoneGap.JSCallbackPort = CallbackServer.getPort();
|
||||||
|
}
|
||||||
|
if (PhoneGap.JSCallbackToken == null) {
|
||||||
|
PhoneGap.JSCallbackToken = CallbackServer.getToken();
|
||||||
|
}
|
||||||
xmlhttp.open("GET", "http://127.0.0.1:"+PhoneGap.JSCallbackPort+"/"+PhoneGap.JSCallbackToken , true);
|
xmlhttp.open("GET", "http://127.0.0.1:"+PhoneGap.JSCallbackPort+"/"+PhoneGap.JSCallbackToken , true);
|
||||||
xmlhttp.send();
|
xmlhttp.send();
|
||||||
};
|
};
|
||||||
@ -651,6 +674,7 @@ PhoneGap.JSCallbackPolling = function() {
|
|||||||
var t = eval(""+msg);
|
var t = eval(""+msg);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
console.log("JSCallbackPolling: Message from Server: " + msg);
|
||||||
console.log("JSCallbackPolling Error: "+e);
|
console.log("JSCallbackPolling Error: "+e);
|
||||||
}
|
}
|
||||||
}, 1);
|
}, 1);
|
||||||
|
@ -168,6 +168,7 @@ public class CallbackServer implements Runnable {
|
|||||||
BufferedReader xhrReader = new BufferedReader(new InputStreamReader(connection.getInputStream()),40);
|
BufferedReader xhrReader = new BufferedReader(new InputStreamReader(connection.getInputStream()),40);
|
||||||
DataOutputStream output = new DataOutputStream(connection.getOutputStream());
|
DataOutputStream output = new DataOutputStream(connection.getOutputStream());
|
||||||
request = xhrReader.readLine();
|
request = xhrReader.readLine();
|
||||||
|
String response = "";
|
||||||
//System.out.println("Request="+request);
|
//System.out.println("Request="+request);
|
||||||
if (request.contains("GET")) {
|
if (request.contains("GET")) {
|
||||||
|
|
||||||
@ -194,16 +195,27 @@ public class CallbackServer implements Runnable {
|
|||||||
// If no data, then send 404 back to client before it times out
|
// If no data, then send 404 back to client before it times out
|
||||||
if (this.empty) {
|
if (this.empty) {
|
||||||
//System.out.println(" -- sending data 0");
|
//System.out.println(" -- sending data 0");
|
||||||
output.writeBytes("HTTP/1.1 404 NO DATA\r\n\r\n");
|
response = "HTTP/1.1 404 NO DATA\r\n\r\n";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//System.out.println(" -- sending item");
|
//System.out.println(" -- sending item");
|
||||||
output.writeBytes("HTTP/1.1 200 OK\r\n\r\n"+this.getJavascript());
|
response = "HTTP/1.1 200 OK\r\n\r\n"+this.getJavascript();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
response = "HTTP/1.1 503 Service Unavailable\r\n\r\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
response = "HTTP/1.1 403 Forbidden\r\n\r\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
response = "HTTP/1.1 400 Bad Request\r\n\r\n";
|
||||||
|
}
|
||||||
|
//System.out.println("CallbackServer: response="+response);
|
||||||
//System.out.println("CallbackServer: closing output");
|
//System.out.println("CallbackServer: closing output");
|
||||||
|
output.writeBytes(response);
|
||||||
output.close();
|
output.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user