Permalink
Browse files

Fixes for better errorhandling

  • Loading branch information...
1 parent e033528 commit 9acb38c54494ca60701e635bc585038d359a14ad @eoftedal committed Nov 7, 2012
Showing with 21 additions and 5 deletions.
  1. +15 −4 flex/malariaproxy.mxml
  2. +6 −1 proxy-backend/malaria/MalariaServer.java
@@ -54,6 +54,8 @@ xmlns="*" creationComplete="useHttpService()">
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, onComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
+ loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
+ //loader.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, onHttpResponseStatus);
loader.load(urlRequest);
ExternalInterface.call("log", "Sent");
}
@@ -68,18 +70,27 @@ xmlns="*" creationComplete="useHttpService()">
}
public function onComplete(event:Event):void {
- socket.writeUTFBytes(event.target.bytesTotal + ":");
+ socket.writeUTFBytes(event.target.data.length + ":");
socket.writeBytes(event.target.data);
socket.flush();
ExternalInterface.call("log", "Sending back data - length " + event.target.bytesTotal + " (" + event.target.data.length + ")");
}
+ public function onHttpResponseStatus(event:HTTPStatusEvent):void {
+ ExternalInterface.call("log", "HTTP status");
+ ExternalInterface.call("log", "HTTP status: " + event.status);
+ }
public function onIOError(event:IOErrorEvent):void {
- ExternalInterface.call("log", "Fault");
- var faultstring:String = event.text;
+ respondError(event.text);
+ }
+ public function onSecurityError(event:SecurityErrorEvent):void {
+ respondError(event.text);
+ }
+ public function respondError(eventText:String):void {
+ var faultstring:String = eventText;
ExternalInterface.call("log", "FAULT:" + faultstring);
- socket.writeUTFBytes("HTTP/1.1 502 Not accessible - " + event.text);
+ socket.writeUTFBytes("HTTP/1.1 502 Not accessible - " + eventText);
socket.flush();
ExternalInterface.call("log", "Sending back 502");
}
@@ -65,6 +65,7 @@ public void serveSocket(Socket client, ServerSocket proxySocket, String hostname
handleProxyRequests:
while (true) {
+ System.out.println("Incoming proxy request...");
Socket proxyClient = proxySocket.accept();
InputStreamReader proxyIn = new InputStreamReader(proxyClient.getInputStream());
OutputStream proxyOut = proxyClient.getOutputStream();
@@ -83,6 +84,10 @@ public void serveSocket(Socket client, ServerSocket proxySocket, String hostname
while (!done) {
byte[] buffer = new byte[4096];
int length = clientIn.read(buffer, 0, buffer.length);
+ if (length <= 0) {
+ if (read == 0) continue handleProxyRequests;
+ break;
+ }
if (new String(buffer, 0, length, "UTF8").startsWith("HTTP/1.1 502 Not accessible")) {
proxyOut.write(buffer, 0, length);
proxyOut.flush();
@@ -125,7 +130,7 @@ public void serveSocket(Socket client, ServerSocket proxySocket, String hostname
}
proxyOut.flush();
} else {
- System.out.println("No match");
+ System.out.println("No match: " + proxyMessage.substring(0, 20));
proxyOut.write("HTTP/1.1 500 OK\n".getBytes("UTF8"));
proxyOut.flush();
}

0 comments on commit 9acb38c

Please sign in to comment.