NanoHTTPD.Response process() { if (isPassed()) { return NanoHTTPD.newFixedLengthResponse(Status.OK, "text/plain; charset=utf-8", "OK!"); } else { return NanoHTTPD.newFixedLengthResponse(Status.SERVICE_UNAVAILABLE, "text/plain; charset=utf-8", "Bad!"); } }
@Override public NanoHTTPD.Response serve(NanoHTTPD.IHTTPSession session) { return NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_PLAINTEXT, "ok"); } }
@Override public NanoHTTPD.Response serve(NanoHTTPD.IHTTPSession session) { if (session.getMethod() != NanoHTTPD.Method.POST) { return newFixedLengthResponse(METHOD_NOT_ALLOWED, MIME_PLAINTEXT, null); } String levelStr = session.getParms().get(PARAM_LEVEL); if (levelStr == null || levelStr.isEmpty()) { return newFixedLengthResponse(BAD_REQUEST, MIME_PLAINTEXT, format("Parameter '%s' is missing", PARAM_LEVEL)); } try { LoggerLevel level = LoggerLevel.valueOf(levelStr); logging.changeLevel(level); return newFixedLengthResponse(OK, MIME_PLAINTEXT, null); } catch (IllegalArgumentException e) { Loggers.get(ChangeLogLevelHttpAction.class).debug("Value '{}' for parameter '" + PARAM_LEVEL + "' is invalid: {}", levelStr, e); return newFixedLengthResponse(BAD_REQUEST, MIME_PLAINTEXT, format("Value '%s' for parameter '%s' is invalid", levelStr, PARAM_LEVEL)); } } }
@Override public NanoHTTPD.Response serve(NanoHTTPD.IHTTPSession session) { if (session.getMethod() != NanoHTTPD.Method.GET) { return newFixedLengthResponse(METHOD_NOT_ALLOWED, MIME_PLAINTEXT, null); } ProtobufSystemInfo.SystemInfo.Builder infoBuilder = ProtobufSystemInfo.SystemInfo.newBuilder(); for (SystemInfoSection sectionProvider : sectionProviders) { ProtobufSystemInfo.Section section = sectionProvider.toProtobuf(); infoBuilder.addSections(section); } byte[] bytes = infoBuilder.build().toByteArray(); return newFixedLengthResponse(OK, PROTOBUF_MIME_TYPE, new ByteArrayInputStream(bytes), bytes.length); } }
/** * Create a text response with known length. */ public static Response newFixedLengthResponse(String msg) { return newFixedLengthResponse(Status.OK, NanoHTTPD.MIME_HTML, msg); }
public OrchidResponse(String content, String mimeType) { this.response = NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.OK, mimeType, content); }
private NanoHTTPD.Response newDefaultErrorResponse() { return newFixedLengthResponse("Sorry, endpoint not implemented :)"); } }
public OrchidResponse(String content) { this.response = NanoHTTPD.newFixedLengthResponse(content); }
public OrchidResponse(String content) { this.response = NanoHTTPD.newFixedLengthResponse(content); }
public OrchidResponse(String content, String mimeType) { this.response = NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.OK, content, mimeType); }
public OrchidResponse(JSONArray data) { this.response = NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.OK, data.toString(), "application/json"); }
public OrchidResponse(JSONObject data) { this.response = NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.OK, data.toString(), "application/json"); }
public NanoHTTPD.Response getResponse(File targetFile, String targetPath) { //TODO: attempt to use NanoHttpd facilities for guessing MIME type String mimeType = mimeTypes.getOrDefault(FilenameUtils.getExtension(targetFile.getName()), "text/plain"); Clog.i("Rendering File: #{$1}", targetPath); try { return NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.OK, mimeType, new FileInputStream(targetFile), targetFile.length()); } catch (Exception e) { return NanoHTTPD.newFixedLengthResponse("Something went wrong opening file: " + targetPath); } } }
public NanoHTTPD.Response getResponse(File targetFile, String targetPath) { //TODO: attempt to use NanoHttpd facilities for guessing MIME type String mimeType = mimeTypes.getOrDefault(FilenameUtils.getExtension(targetFile.getName()), "text/plain"); Clog.i("Rendering File: #{$1}", targetPath); try { return NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.OK, mimeType, new FileInputStream(targetFile), targetFile.length()); } catch (Exception e) { return NanoHTTPD.newFixedLengthResponse("Something went wrong opening file: " + targetPath); } } }
@Override public NanoHTTPD.Response serve(NanoHTTPD.IHTTPSession session) { if (session.getMethod() != NanoHTTPD.Method.POST) { return newFixedLengthResponse(METHOD_NOT_ALLOWED, MIME_PLAINTEXT, null); } enabledCeWorkerController.refresh(); return newFixedLengthResponse(OK, MIME_PLAINTEXT, null); } }
public static Response newFixedLengthResponse(IStatus status, String mimeType, String message) { Response response = NanoHTTPD.newFixedLengthResponse(status, mimeType, message); response.addHeader("Accept-Ranges", "bytes"); return response; }
@Override public NanoHTTPD.Response serve(NanoHTTPD.IHTTPSession session) { return newFixedLengthResponse(loadTextAsset(htmlPath)); } }
@Override public NanoHTTPD.Response serve(NanoHTTPD.IHTTPSession session) { if (session.getMethod() != NanoHTTPD.Method.GET) { return newFixedLengthResponse(METHOD_NOT_ALLOWED, MIME_PLAINTEXT, null); } ProtobufSystemInfo.SystemInfo.Builder infoBuilder = ProtobufSystemInfo.SystemInfo.newBuilder(); for (SystemInfoSection sectionProvider : sectionProviders) { ProtobufSystemInfo.Section section = sectionProvider.toProtobuf(); infoBuilder.addSections(section); } byte[] bytes = infoBuilder.build().toByteArray(); return newFixedLengthResponse(OK, PROTOBUF_MIME_TYPE, new ByteArrayInputStream(bytes), bytes.length); } }
public Response get(UriResource uriResource, Map<String, String> urlParams, IHTTPSession session) { return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), getText()); }
public Response render(ModelAndView model) { IStatus status; if (model.getStatus() != null) { status = model.getStatus(); } else { status = Status.OK; } return NanoHTTPD.newFixedLengthResponse(status, MimeType.JSON.getType(), model.getData()); }