@Override protected void write(T value, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException { writer.writeValue(resp.getWriter(), value); } }
@Override protected void write(T value, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException { writer.writeValue(resp.getWriter(), value); } }
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 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 + "."); }
@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()); } }
@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> nodesCode = Lists.newArrayList(); List<String> linksCode = Lists.newArrayList(); for (Name<?> name : warehouse.listNames()) { nodesCode.add(String.format("{ \"id\": \"%s\", \"name\": \"%s\", \"type\": \"%s\" }", name.asId(), name.getSimpleName(), getType(name))); Iterable<Name<?>> deps = warehouse.listDependencies(name); for (Name<?> dep : deps) { linksCode.add(String.format("{ \"origin\": \"%s\", \"target\": \"%s\" }", name.asId(), dep.asId())); } } PrintWriter writer = resp.getWriter(); writer.println("{"); writer.println("\"nodes\": ["); Joiner.on(",\n").appendTo(writer, nodesCode); writer.println("\n],"); writer.println("\"links\": ["); Joiner.on(",\n").appendTo(writer, linksCode); writer.println("\n]"); writer.println("}"); }
@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]"); } },
/** * 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/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 { 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 { 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 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 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); } }
@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); } }