I am doing some work with the sunhttpserver
.
Here is the java (extract) that starts the server and displays Hello World
.
java
@SimpleFunction
public void StartServer(String path, int port) throws IOException {
try {
server = HttpServer.create(new InetSocketAddress("0.0.0.0", port), 0);
server.createContext(path, new MyHandler());
server.setExecutor(null);
server.start();
} catch (IOException e){
Log.e("SUNServer", e.toString());
}
}
private class MyHandler implements HttpHandler {
public void handle(HttpExchange t) throws IOException {
InputStream is = t.getRequestBody();
is.read(); // .. read the request body
String response = "Hello World";
t.sendResponseHeaders(200, response.length());
OutputStream os = t.getResponseBody();
os.write(response.getBytes());
os.close();
}
I would like to be able to include some more parameters in the SimpleFunction that can get passed to the private class
(as you can see to input in the simplefunction (1) and pass through MyHandler()
to the private class (2)
For example to be able to change the message Hello World
. I may have other parameters as well that need to be changed in a more expansive version of the handler class. Looks like `handle() will accept parameters, but how to get them in there from the function ?
Any suggestions ?