import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
return NanoHTTPD.newFixedLengthResponse(Status.SERVICE_UNAVAILABLE,
NanoHTTPD.MIME_PLAINTEXT, "Server is already exiting...");
}
-
+
exiting = true;
Instance.getInstance().getTraceHandler().trace("Exiting");
doStop();
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ Thread.sleep(1500);
+ } catch (InterruptedException e) {
+ }
+
+ Instance.getInstance().getTraceHandler()
+ .trace("Exit timeout: force-quit");
+ System.exit(0);
+ }
+ }, "Exit program after timeout of 1500 ms").start();
+
return NanoHTTPD.newFixedLengthResponse(Status.OK,
NanoHTTPD.MIME_PLAINTEXT, "Exited");
}
jsons.add(JsonIO.toJson(meta));
}
- return newInputStreamResponse("application/json",
- new ByteArrayInputStream(
- new JSONArray(jsons).toString().getBytes()));
+ return NanoHTTPD.newFixedLengthResponse(Status.OK,
+ "application/json", new JSONArray(jsons).toString());
}
return NanoHTTPD.newFixedLengthResponse(Status.BAD_REQUEST,
return NanoHTTPD.newFixedLengthResponse(Status.FORBIDDEN,
NanoHTTPD.MIME_PLAINTEXT, "SET story part not allowed");
}
-
+
if (exiting) {
return NanoHTTPD.newFixedLengthResponse(Status.SERVICE_UNAVAILABLE,
NanoHTTPD.MIME_PLAINTEXT, "Server is exiting...");
}
String type = uriParts[off + 0];
- String id = uriParts[off + 1];
+ String id = URLDecoder.decode(uriParts[off + 1], "UTF-8");
InputStream in = null;
return NanoHTTPD.newFixedLengthResponse(Status.FORBIDDEN,
NanoHTTPD.MIME_PLAINTEXT, "Cover request not allowed");
}
-
+
if (exiting) {
return NanoHTTPD.newFixedLengthResponse(Status.SERVICE_UNAVAILABLE,
NanoHTTPD.MIME_PLAINTEXT, "Server is exiting...");
}
String type = uriParts[off + 0];
- String id = uriParts[off + 1];
+ String id = URLDecoder.decode(uriParts[off + 1], "UTF-8");
if ("source".equals(type)) {
sourceCover(id, login, luid);
return NanoHTTPD.newFixedLengthResponse(Status.FORBIDDEN,
NanoHTTPD.MIME_PLAINTEXT, "Import not allowed");
}
-
+
if (exiting) {
return NanoHTTPD.newFixedLengthResponse(Status.SERVICE_UNAVAILABLE,
NanoHTTPD.MIME_PLAINTEXT, "Server is exiting...");
return NanoHTTPD.newFixedLengthResponse(Status.FORBIDDEN,
NanoHTTPD.MIME_PLAINTEXT, "Delete not allowed");
}
-
+
if (exiting) {
return NanoHTTPD.newFixedLengthResponse(Status.SERVICE_UNAVAILABLE,
NanoHTTPD.MIME_PLAINTEXT, "Server is exiting...");