@Override public Response type(final String type) { rsp.type(type); return this; }
@Override public Response type(final MediaType type) { rsp.type(type); return this; }
@Override public Optional<MediaType> type() { return rsp.type(); }
@Override public void setResponseContentType(final String content) { rsp.type(content); }
@Override public void setResponseContentType(String content) { rsp.type(content); }
/** * Set the response media type and set the <code>Content-Type</code> header. * * @param type A media type. * @return This response. */ @Nonnull default Response type(final String type) { return type(MediaType.valueOf(type)); }
@Override public void handle(final Request req, final Response rsp) throws Throwable { String CRLF = "\r\n"; StringBuilder buffer = new StringBuilder("TRACE ").append(req.path()) .append(" ").append(req.protocol()); for (Entry<String, Mutant> entry : req.headers().entrySet()) { buffer.append(CRLF).append(entry.getKey()).append(": ") .append(entry.getValue().toList(String.class).stream().collect(Collectors.joining(", "))); } buffer.append(CRLF); rsp.type(MediaType.valueOf("message/http")); rsp.length(buffer.length()); rsp.send(buffer.toString()); }
/** * Responsible of writing the given body into the HTTP response. * * @param result The HTTP body. * @throws Exception If the response write fails. */ default void send(final @Nullable Object result) throws Throwable { if (result instanceof Result) { send((Result) result); } else if (result != null) { // wrap body Result b = Results.with(result); status().ifPresent(b::status); type().ifPresent(b::type); send(b); } else { throw new NullPointerException("Response required."); } }
@Override public void handle(final Request req, final Response rsp) throws Throwable { if (compilationDone.get()) { if (req.param("assets.sync").isSet()) { onChange(StandardWatchEventKinds.ENTRY_MODIFY, basedir); } if (errors.size() > 0) { throw errors.values().iterator().next(); } } else { rsp.type(MediaType.html) .send("<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"UTF-8\">\n" + "<meta http-equiv=\"refresh\" content=\"2\">\n" + "<title>Compiling assets</title>\n" + "</head>\n" + "<body>\n" + "Compiling assets, please wait...\n" + "</body>\n" + "</html>"); } }
@Override public void handle(final Request req, final Response rsp) throws Throwable { rsp.status(Status.OK) .type(MediaType.plain) .header("Cache-Control", "must-revalidate,no-cache,no-store") .send("pong"); ; }
@Override public void handle(final Request req, final Response rsp) throws Throwable { Object data; Status status; if (threadDump == null) { data = "Sorry your runtime environment does not allow to dump threads."; status = Status.NOT_IMPLEMENTED; } else { final ByteArrayOutputStream output = new ByteArrayOutputStream(); threadDump.dump(output); data = output.toByteArray(); status = Status.OK; } rsp.type(MediaType.plain) .status(status) .header("Cache-Control", "must-revalidate,no-cache,no-store") .send(data); }
@Override public void handle(final Request req, final Response rsp, final Chain chain) throws Throwable { String error = req.param("error").toOptional().orElse(""); String username = req.param("username").toOptional().orElse(""); req.set("username", username); req.set("error", error); if (loginUrl.equals(req.path())) { // default login form rsp.type(MediaType.html).send(String.format(FORM, error, callback, username)); } else { super.handle(req, rsp, chain); } }
@Override public void handle(Request req, Response rsp) throws Throwable { PrometheusMeterRegistry registry = req.require(PrometheusMeterRegistry.class); String response = registry.scrape(); rsp.type(MediaType.plain) .send(Results.ok(response)); } }
@Override public void handle(final Request req, final Response rsp) throws Throwable { String error = req.param("error").value(""); String username = req.param("username").value(""); req.set("username", username); req.set("error", error); // default login form rsp.type(MediaType.html).send(String.format(FORM, error, callback, username)); }
rsp.type(MediaType.html).send(writer.toString());
@Override protected void send(final Request req, final Response rsp, final Asset asset) throws Throwable { Env env = req.require(Env.class); CharSequence text = process(env, text(asset.stream())); rsp.type(asset.type()) .send(text); }
@Override public Response type(final String type) { rsp.type(type); return this; }
@Override public Response type(final MediaType type) { rsp.type(type); return this; }
/** * Set the response media type and set the <code>Content-Type</code> header. * * @param type A media type. * @return This response. */ @Nonnull default Response type(final String type) { return type(MediaType.valueOf(type)); }
@Override protected void send(final Request req, final Response rsp, final Asset asset) throws Throwable { Env env = req.require(Env.class); CharSequence text = process(env, text(asset.stream())); rsp.type(asset.type()) .send(text); }