mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-07 23:03:11 +08:00
Guard against null request in Android 1.5/1.6
This commit is contained in:
parent
a7415bcfc9
commit
54eff557d9
@ -188,54 +188,57 @@ public class CallbackServer implements Runnable {
|
|||||||
request = xhrReader.readLine();
|
request = xhrReader.readLine();
|
||||||
String response = "";
|
String response = "";
|
||||||
//System.out.println("CallbackServerRequest="+request);
|
//System.out.println("CallbackServerRequest="+request);
|
||||||
if (request.contains("GET")) {
|
if (request != null) {
|
||||||
|
if (request.contains("GET")) {
|
||||||
|
|
||||||
// Must have security token
|
// Must have security token
|
||||||
if (request.substring(5,41).equals(this.token)) {
|
if (request.substring(5,41).equals(this.token)) {
|
||||||
//System.out.println("CallbackServer -- Processing GET request");
|
//System.out.println("CallbackServer -- Processing GET request");
|
||||||
|
|
||||||
// Wait until there is some data to send, or send empty data every 10 sec
|
// Wait until there is some data to send, or send empty data every 10 sec
|
||||||
// to prevent XHR timeout on the client
|
// to prevent XHR timeout on the client
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
while (this.empty) {
|
while (this.empty) {
|
||||||
try {
|
try {
|
||||||
this.wait(10000); // prevent timeout from happening
|
this.wait(10000); // prevent timeout from happening
|
||||||
//System.out.println("CallbackServer>>> break <<<");
|
//System.out.println("CallbackServer>>> break <<<");
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
catch (Exception e) { }
|
||||||
}
|
}
|
||||||
catch (Exception e) { }
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// If server is still running
|
// If server is still running
|
||||||
if (this.active) {
|
if (this.active) {
|
||||||
|
|
||||||
// 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("CallbackServer -- sending data 0");
|
//System.out.println("CallbackServer -- sending data 0");
|
||||||
response = "HTTP/1.1 404 NO DATA\r\n\r\n "; // need to send content otherwise some Android devices fail, so send space
|
response = "HTTP/1.1 404 NO DATA\r\n\r\n "; // need to send content otherwise some Android devices fail, so send space
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//System.out.println("CallbackServer -- sending item");
|
||||||
|
response = "HTTP/1.1 200 OK\r\n\r\n"+this.getJavascript();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//System.out.println("CallbackServer -- sending item");
|
response = "HTTP/1.1 503 Service Unavailable\r\n\r\n ";
|
||||||
response = "HTTP/1.1 200 OK\r\n\r\n"+this.getJavascript();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
response = "HTTP/1.1 503 Service Unavailable\r\n\r\n ";
|
response = "HTTP/1.1 403 Forbidden\r\n\r\n ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
response = "HTTP/1.1 403 Forbidden\r\n\r\n ";
|
response = "HTTP/1.1 400 Bad Request\r\n\r\n ";
|
||||||
}
|
}
|
||||||
}
|
//System.out.println("CallbackServer: response="+response);
|
||||||
else {
|
//System.out.println("CallbackServer: closing output");
|
||||||
response = "HTTP/1.1 400 Bad Request\r\n\r\n ";
|
output.writeBytes(response);
|
||||||
}
|
output.flush();
|
||||||
//System.out.println("CallbackServer: response="+response);
|
}
|
||||||
//System.out.println("CallbackServer: closing output");
|
|
||||||
output.writeBytes(response);
|
|
||||||
output.flush();
|
|
||||||
output.close();
|
output.close();
|
||||||
|
xhrReader.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
Loading…
Reference in New Issue
Block a user