public RestxResponse setContentType(String s) { restxResponse.setContentType(s); return this; }
public RestxResponse setContentType(String s) { restxResponse.setContentType(s); return this; }
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); } }
@Override public void handle(RestxRequestMatch match, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException { securityManager.check(req, match, permissionFactory.hasRole(AdminModule.RESTX_ADMIN_ROLE)); resp.setContentType("text/plain"); resp.getWriter().println(factory.dump()); } }
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); } }
@Override public void handle(RestxRequestMatch match, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException { securityManager.check(req, match, permissionFactory.hasRole(AdminModule.RESTX_ADMIN_ROLE)); resp.setContentType("application/json"); List<String> data = Lists.newArrayList(); for (RestxSpecRecorder.RecordedSpec spec : recordedSpecsRepository.getRecordedSpecs()) { data.add(String.format("{ \"id\": \"%03d\", \"method\": \"%s\", \"path\": \"%s\", \"recordTime\": \"%s\", \"duration\":" + " %d, " + "\"capturedItems\": %d, \"capturedRequestSize\": %d, \"capturedResponseSize\": %d }", spec.getId(), spec.getMethod(), spec.getPath(), spec.getRecordTime(), spec.getDuration().getMillis(), spec.getCapturedItems(), spec.getCapturedRequestSize(), spec.getCapturedResponseSize())); } resp.getWriter().print("[\n"); Joiner.on(",\n").appendTo(resp.getWriter(), data); resp.getWriter().print("\n]"); } },
@Override public void handle(RestxRequestMatch match, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException { securityManager.check(req, match, permissionFactory.hasRole(AdminModule.RESTX_ADMIN_ROLE)); resp.setContentType("application/json"); List<String> data = Lists.newArrayList(); for (RestxSpecRecorder.RecordedSpec spec : recordedSpecsRepository.getRecordedSpecs()) { data.add(String.format("{ \"id\": \"%03d\", \"method\": \"%s\", \"path\": \"%s\", \"recordTime\": \"%s\", \"duration\":" + " %d, " + "\"capturedItems\": %d, \"capturedRequestSize\": %d, \"capturedResponseSize\": %d }", spec.getId(), spec.getMethod(), spec.getPath(), spec.getRecordTime(), spec.getDuration().getMillis(), spec.getCapturedItems(), spec.getCapturedRequestSize(), spec.getCapturedResponseSize())); } resp.getWriter().print("[\n"); Joiner.on(",\n").appendTo(resp.getWriter(), data); resp.getWriter().print("\n]"); } },
@Override public void handle(RestxRequestMatch match, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException { securityManager.check(req, match, permissionFactory.hasRole(AdminModule.RESTX_ADMIN_ROLE)); int id = Integer.parseInt(match.getPathParam("id")); for (RestxSpecRecorder.RecordedSpec spec : recordedSpecsRepository.getRecordedSpecs()) { if (spec.getId() == id) { resp.setContentType("text/yaml"); resp.getWriter().println(spec.getSpec().toString()); return; } } notFound(match, resp); } },
@Override public void handle(RestxRequestMatch match, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException { securityManager.check(req, match, permissionFactory.hasRole(AdminModule.RESTX_ADMIN_ROLE)); int id = Integer.parseInt(match.getPathParam("id")); for (RestxSpecRecorder.RecordedSpec spec : recordedSpecsRepository.getRecordedSpecs()) { if (spec.getId() == id) { resp.setContentType("text/yaml"); resp.getWriter().println(spec.getSpec().toString()); return; } } notFound(match, resp); } },
@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); }
@Override public void handle(RestxRequestMatch match, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException { securityManager.check(req, match, permissionFactory.hasRole(AdminModule.RESTX_ADMIN_ROLE)); int id = Integer.parseInt(match.getPathParam("id")); for (RestxSpecRecorder.RecordedSpec spec : recordedSpecsRepository.getRecordedSpecs()) { if (spec.getId() == id) { Optional<String> path = req.getQueryParam("path"); Optional<String> title = req.getQueryParam("title"); RestxSpec.Storage storage = RestxSpec.Storage.with(storageSettings); File destFile = storage.store( spec.getSpec() .withTitle(title) .withPath(storage.buildPath(path, title.or(spec.getSpec().getTitle())))); resp.setContentType("text/plain"); resp.getWriter().println(destFile.getAbsolutePath()); return; } } notFound(match, resp); } }