@Override public void handle(RestxRequestMatch match, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException { resp.setStatus(HttpStatus.FORBIDDEN); } };
@Override public void handle(RestxRequestMatch match, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException { resp.setStatus(HttpStatus.FORBIDDEN); } };
public RestxResponse setStatus(HttpStatus i) { restxResponse.setStatus(i); return this; }
public RestxResponse setStatus(HttpStatus i) { restxResponse.setStatus(i); return this; }
@Override public void handle(RestxRequestMatch match, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException { String path = match.getPathParam("path"); File file = root.resolve(path).toFile(); if (!file.exists()) { // nothing to do, send NO_CONTENT to be idempotent resp.setStatus(HttpStatus.NO_CONTENT); return; } if (file.isDirectory()) { if (file.list().length > 0) { throw new WebException(HttpStatus.UNAUTHORIZED, "can't delete non empty directory"); } } java.nio.file.Files.delete(file.toPath()); resp.setStatus(HttpStatus.NO_CONTENT); }
@Override public void handle(RestxRequestMatch match, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException { String path = match.getPathParam("path"); File file = root.resolve(path).toFile(); if (!file.exists()) { // nothing to do, send NO_CONTENT to be idempotent resp.setStatus(HttpStatus.NO_CONTENT); return; } if (file.isDirectory()) { if (file.list().length > 0) { throw new WebException(HttpStatus.UNAUTHORIZED, "can't delete non empty directory"); } } java.nio.file.Files.delete(file.toPath()); resp.setStatus(HttpStatus.NO_CONTENT); }
protected void notFound(RestxResponse resp, String relativePath) throws IOException { resp.setStatus(HttpStatus.NOT_FOUND); resp.setContentType("text/plain"); resp.getWriter().println("Resource route matched '" + this + "', but resource " + relativePath + " not found in " + baseResourcePath + "."); }
protected void notFound(RestxResponse resp, String relativePath) throws IOException { resp.setStatus(HttpStatus.NOT_FOUND); resp.setContentType("text/plain"); resp.getWriter().println("Resource route matched '" + this + "', but resource " + relativePath + " not found in " + baseResourcePath + "."); }
protected void notFound(RestxRequestMatch match, RestxResponse resp) throws IOException { resp.setStatus(HttpStatus.NOT_FOUND); resp.setContentType("text/plain"); resp.getWriter().println("Route matched, but resource " + match.getPath() + " not found."); resp.getWriter().println("Matched route: " + this); } }
protected void notFound(RestxRequestMatch match, RestxResponse resp) throws IOException { resp.setStatus(HttpStatus.NOT_FOUND); resp.setContentType("text/plain"); resp.getWriter().println("Route matched, but resource " + match.getPath() + " not found."); resp.getWriter().println("Matched route: " + this); } }
protected void serveResource(RestxResponse resp, URL resource, String contentType, Map<String, String> headers) throws IOException { resp.setLogLevel(RestxLogLevel.QUIET); resp.setStatus(HttpStatus.OK); for(Map.Entry<String,String> headerEntry: headers.entrySet()) { resp.setHeader(headerEntry.getKey(), headerEntry.getValue()); } resp.setContentType(contentType); Resources.asByteSource(resource).copyTo(resp.getOutputStream()); }
protected void serveResource(RestxResponse resp, URL resource, String contentType, Map<String, String> headers) throws IOException { resp.setLogLevel(RestxLogLevel.QUIET); resp.setStatus(HttpStatus.OK); for(Map.Entry<String,String> headerEntry: headers.entrySet()) { resp.setHeader(headerEntry.getKey(), headerEntry.getValue()); } resp.setContentType(contentType); Resources.asByteSource(resource).copyTo(resp.getOutputStream()); }
@Override public void handle(RestxRequestMatch match, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException { Iterable<Entry<String, String>> entries = messages.entries(currentLocaleResolver.guessLocale(req)); handleETagFor(req, resp, entries); resp.setStatus(HttpStatus.OK); resp.setContentType("application/javascript"); PrintWriter writer = resp.getWriter(); writer.print(labelsJsBefore); writeLabelsJson(writer, entries); writer.print(labelsJsAfter); } }
/** * Writes this web exception in a RestxResponse. * * This implementation uses the status, contentType and content found on the exception. * Override it to provide custom response. * Note that the implementation is also responsible for logging the exception. * * * @param restxRequest * @param restxResponse the response to write to * @throws IOException in case of IO error. */ public void writeTo(RestxRequest restxRequest, RestxResponse restxResponse) throws IOException { // by default log stack trace at debug level only if (logger.isDebugEnabled()) { logger.debug("request raised WebException - " + restxRequest, this); } restxResponse.setStatus(getStatus()); restxResponse.setContentType(getContentType()); restxResponse.getWriter().print(getContent()); } }
@Override public void handle(RestxRequestMatch match, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException { Iterable<Entry<String, String>> entries = messages.entries(currentLocaleResolver.guessLocale(req)); handleETagFor(req, resp, entries); resp.setStatus(HttpStatus.OK); resp.setContentType("application/json"); PrintWriter writer = resp.getWriter(); writeLabelsJson(writer, entries); }
@Override public void handle(RestxRequestMatch match, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException { resp.setStatus(HttpStatus.havingCode(whenHttpRequest.getThen().getExpectedCode())); if (whenHttpRequest.getThen().getExpectedCode() == HttpStatus.OK.getCode()) { resp.setContentType("application/json"); } resp.getWriter().print(whenHttpRequest.getThen().getExpected()); } }
@Override public void sendResponse(HttpStatus status, T value, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException { resp.setStatus(status); resp.setContentType(contentType); writeHeaders(value, req, resp, ctx); ctx.getLifecycleListener().onBeforeWriteContent(req, resp); write(value, req, resp, ctx); ctx.getLifecycleListener().onAfterWriteContent(req, resp); }
@Override public void handle(RestxRequestMatch match, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException { resp.setStatus(HttpStatus.havingCode(whenHttpRequest.getThen().getExpectedCode())); if (whenHttpRequest.getThen().getExpectedCode() == HttpStatus.OK.getCode()) { resp.setContentType("application/json"); } resp.getWriter().print(whenHttpRequest.getThen().getExpected()); } }
@Override public void sendResponse(HttpStatus status, T value, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException { resp.setStatus(status); resp.setContentType(contentType); writeHeaders(value, req, resp, ctx); ctx.getLifecycleListener().onBeforeWriteContent(req, resp); write(value, req, resp, ctx); ctx.getLifecycleListener().onAfterWriteContent(req, resp); }