Java Code Examples for fi.iki.elonen.NanoHTTPD#IHTTPSession

The following examples show how to use fi.iki.elonen.NanoHTTPD#IHTTPSession . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElementController.java    From UIAutomatorWD with MIT License 6 votes vote down vote up
@Override
public NanoHTTPD.Response get(RouterNanoHTTPD.UriResource uriResource, Map<String, String> urlParams, NanoHTTPD.IHTTPSession session) {
    String sessionId = urlParams.get("sessionId");
    String elementId = urlParams.get("elementId");
    try {
        Element el = Elements.getGlobal().getElement(elementId);
        final Rect rect = el.element.getVisibleBounds();
        JSONObject res = new JSONObject();
        res.put("x", rect.left);
        res.put("y", rect.top);
        res.put("height", rect.height());
        res.put("width", rect.width());
        return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(res, sessionId).toString());
    } catch (final Exception e) {
        return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(Status.UnknownError, sessionId).toString());
    }
}
 
Example 2
Source File: AppRequestProcesser.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
@Override
public NanoHTTPD.Response doResponse(NanoHTTPD.IHTTPSession session, String fileName, Map<String, String> params, Map<String, String> files) {
        switch (fileName) {
            case "/apps":
                return RemoteServer.createJSONResponse(NanoHTTPD.Response.Status.OK,
                        AppPackagesHelper.getQueryAppInfoJsonString(this.context, "true".equals(params.get("system"))));
            case "/uninstall":
                if (params.get("packageName") != null) {
                    AppPackagesHelper.uninstallPackage(params.get("packageName"), this.context);
                }
                return RemoteServer.createPlainTextResponse(NanoHTTPD.Response.Status.OK,"ok");
            case "/run":
                if (params.get("packageName") != null) {
                    AppPackagesHelper.runPackage(params.get("packageName"), this.context);
                }
                return RemoteServer.createPlainTextResponse(NanoHTTPD.Response.Status.OK,"ok");
            case "/runSystem":
                if (params.get("packageName") != null) {
                    AppPackagesHelper.runSystemPackage(params.get("packageName"), this.context);
                }
                return RemoteServer.createPlainTextResponse(NanoHTTPD.Response.Status.OK,"ok");
            default:
                return RemoteServer.createPlainTextResponse(NanoHTTPD.Response.Status.NOT_FOUND, "Error 404, file not found.");
        }
}
 
Example 3
Source File: FileRequestProcesser.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean isRequest(NanoHTTPD.IHTTPSession session, String fileName) {
    if(session.getMethod() == NanoHTTPD.Method.GET){
        return fileName.startsWith("/file/dir/")
                || fileName.startsWith("/file/download/");
    }
    else if(session.getMethod() == NanoHTTPD.Method.POST){
        switch (fileName) {
            case "/file/copy":
            case "/file/cut":
            case "/file/delete":
            case "/file/upload":
                return true;
        }
    }
    return false;
}
 
Example 4
Source File: InputRequestProcesser.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
@Override
public NanoHTTPD.Response doResponse(NanoHTTPD.IHTTPSession session, String fileName, Map<String, String> params, Map<String, String> files) {
    RemoteServer.DataReceiver mDataReceiver = remoteServer.getDataReceiver();
    switch (fileName) {
        case "/text":
            if (params.get("text") != null && mDataReceiver != null) {
                mDataReceiver.onTextReceived(params.get("text"));
            }
            return RemoteServer.createPlainTextResponse(NanoHTTPD.Response.Status.OK,"ok");
        case "/key":
            if (params.get("code") != null && mDataReceiver != null) {
                mDataReceiver.onKeyEventReceived(params.get("code"), IMEService.KEY_ACTION_PRESSED);
            }
            return RemoteServer.createPlainTextResponse(NanoHTTPD.Response.Status.OK,"ok");
        case "/keyup":
            if (params.get("code") != null && mDataReceiver != null) {
                mDataReceiver.onKeyEventReceived(params.get("code"), IMEService.KEY_ACTION_UP);
            }
            return RemoteServer.createPlainTextResponse(NanoHTTPD.Response.Status.OK,"ok");
        case "/keydown":
            if (params.get("code") != null && mDataReceiver != null) {
                mDataReceiver.onKeyEventReceived(params.get("code"), IMEService.KEY_ACTION_DOWN);
            }
            return RemoteServer.createPlainTextResponse(NanoHTTPD.Response.Status.OK,"ok");
        default:
            return RemoteServer.createPlainTextResponse(NanoHTTPD.Response.Status.NOT_FOUND, "Error 404, file not found.");
    }
}
 
Example 5
Source File: AlertController.java    From UIAutomatorWD with MIT License 5 votes vote down vote up
@Override
public NanoHTTPD.Response get(RouterNanoHTTPD.UriResource uriResource, Map<String, String> urlParams, NanoHTTPD.IHTTPSession session) {
    String sessionId = urlParams.get("sessionId");
    JSONObject result = null;
    try {
        acceptAlert();
        return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(result, sessionId).toString());
    } catch (final Exception e) {
        return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(Status.UnknownError, sessionId).toString());
    }
}
 
Example 6
Source File: OtherPostRequestProcesser.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
@Override
public NanoHTTPD.Response doResponse(NanoHTTPD.IHTTPSession session, String fileName, Map<String, String> params, Map<String, String> files) {
    switch (fileName) {
        case "/clearCache":
            RemoteServerFileManager.clearAllFiles();
            return RemoteServer.createPlainTextResponse(NanoHTTPD.Response.Status.OK,"ok");
        default:
            return RemoteServer.createPlainTextResponse(NanoHTTPD.Response.Status.NOT_FOUND, "Error 404, file not found.");
    }
}
 
Example 7
Source File: WindowController.java    From UIAutomatorWD with MIT License 4 votes vote down vote up
@Override
public NanoHTTPD.Response get(RouterNanoHTTPD.UriResource uriResource, Map<String, String> urlParams, NanoHTTPD.IHTTPSession session) {
    String sessionId = urlParams.get("sessionId");
    return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(Status.NoSuchElement, sessionId).toString());
}
 
Example 8
Source File: DebugActivity.java    From android-robocar with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void onRequest(NanoHTTPD.IHTTPSession session) {
  LocalWebServer.logSession(session);
}
 
Example 9
Source File: ContextController.java    From UIAutomatorWD with MIT License 4 votes vote down vote up
@Override
public NanoHTTPD.Response get(RouterNanoHTTPD.UriResource uriResource, Map<String, String> urlParams, NanoHTTPD.IHTTPSession session) {
    String sessionId = urlParams.get("sessionId");
    return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(Status.NoSuchElement, sessionId).toString());
}
 
Example 10
Source File: WindowController.java    From UIAutomatorWD with MIT License 4 votes vote down vote up
@Override
public NanoHTTPD.Response get(RouterNanoHTTPD.UriResource uriResource, Map<String, String> urlParams, NanoHTTPD.IHTTPSession session) {
    String sessionId = urlParams.get("sessionId");
    return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(Status.NoSuchElement, sessionId).toString());
}
 
Example 11
Source File: TitleController.java    From UIAutomatorWD with MIT License 4 votes vote down vote up
@Override
public NanoHTTPD.Response get(RouterNanoHTTPD.UriResource uriResource, Map<String, String> urlParams, NanoHTTPD.IHTTPSession session) {
    String sessionId = urlParams.get("sessionId");
    return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(Status.NoSuchElement, sessionId).toString());
}
 
Example 12
Source File: Ws.java    From USBHIDTerminal with Apache License 2.0 4 votes vote down vote up
public Ws(NanoHTTPD.IHTTPSession handshakeRequest) {
    super(handshakeRequest);
    this.httpSession = handshakeRequest;
    eventBus.register(this);
}
 
Example 13
Source File: ScreenshotController.java    From UIAutomatorWD with MIT License 4 votes vote down vote up
@Override
public NanoHTTPD.Response get(RouterNanoHTTPD.UriResource uriResource, Map<String, String> urlParams, NanoHTTPD.IHTTPSession session) {
    String sessionId = urlParams.get("sessionId");
    return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(Status.NoSuchElement, sessionId).toString());
}
 
Example 14
Source File: UploadRequestProcesser.java    From TVRemoteIME with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isRequest(NanoHTTPD.IHTTPSession session, String fileName) {
    return session.getMethod() == NanoHTTPD.Method.POST && "/upload".equalsIgnoreCase(fileName);
}
 
Example 15
Source File: AlertController.java    From UIAutomatorWD with MIT License 4 votes vote down vote up
@Override
public NanoHTTPD.Response get(RouterNanoHTTPD.UriResource uriResource, Map<String, String> urlParams, NanoHTTPD.IHTTPSession session) {
    String sessionId = urlParams.get("sessionId");
    return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(Status.NoSuchElement, sessionId).toString());
}
 
Example 16
Source File: WindowController.java    From UIAutomatorWD with MIT License 4 votes vote down vote up
@Override
public NanoHTTPD.Response get(RouterNanoHTTPD.UriResource uriResource, Map<String, String> urlParams, NanoHTTPD.IHTTPSession session) {
    String sessionId = urlParams.get("sessionId");
    return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(new JSONObject(), sessionId).toString());
}
 
Example 17
Source File: UrlController.java    From UIAutomatorWD with MIT License 4 votes vote down vote up
@Override
public NanoHTTPD.Response get(RouterNanoHTTPD.UriResource uriResource, Map<String, String> urlParams, NanoHTTPD.IHTTPSession session) {
    String sessionId = urlParams.get("sessionId");
    return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(Status.NoSuchElement, sessionId).toString());
}
 
Example 18
Source File: HomeController.java    From UIAutomatorWD with MIT License 4 votes vote down vote up
@Override
public NanoHTTPD.Response get(RouterNanoHTTPD.UriResource uriResource, Map<String, String> urlParams, NanoHTTPD.IHTTPSession session) {
    String sessionId = urlParams.get("sessionId");

    return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(Status.NoSuchElement, sessionId).toString());
}
 
Example 19
Source File: HTTPRequestListener.java    From android-robocar with BSD 2-Clause "Simplified" License votes vote down vote up
void onRequest(NanoHTTPD.IHTTPSession session); 
Example 20
Source File: HttpServer.java    From wasp with Apache License 2.0 votes vote down vote up
public NanoHTTPD.Response get(NanoHTTPD.IHTTPSession session);