public void serve(ISourceLocation url, final IValue callback, final IEvaluatorContext ctx) {
URI uri = url.getURI();
int port = uri.getPort() != -1 ? uri.getPort() : 80;
String host = uri.getHost() != null ? uri.getHost() : "localhost";
final ICallableValue callee = (ICallableValue) callback;
NanoHTTPD server = new NanoHTTPD(host, port) {
@Override
public Response serve(String uri, Method method, Map<String, String> headers, Map<String, String> parms,
Map<String, String> files) {
IConstructor methodVal = makeMethod(method);
IMap headersVal = makeMap(headers);
IMap paramsVal= makeMap(parms);
IMap filesVal= makeMap(files);
ISourceLocation loc = vf.sourceLocation(URIUtil.assumeCorrect("request", "", uri));
try {
synchronized (callee.getEval()) {
callee.getEval().__setInterrupt(false);
Result<IValue> response = callee.call(argTypes, new IValue[] { loc, methodVal, headersVal, paramsVal, filesVal }, null);
return translateResponse(method, response.getValue());
}
}
catch (Throw rascalException) {
ctx.getStdErr().println(rascalException.getMessage());