protected void sendResource(URL resourceUrl, RouteContext routeContext) throws IOException { String filename = resourceUrl.getFile(); String mimeType = routeContext.getApplication().getMimeTypes().getContentType(filename); if (!StringUtils.isNullOrEmpty(mimeType)) { // stream the resource log.debug("Streaming as resource '{}'", resourceUrl); routeContext.getResponse().contentType(mimeType); routeContext.getResponse().ok().resource(resourceUrl.openStream()); } else { // stream the file log.debug("Streaming as file '{}'", resourceUrl); routeContext.getResponse().ok().file(filename, resourceUrl.openStream()); } }
private void finalizeResponse() { // add headers for (Map.Entry<String, String> header : getHeaderMap().entrySet()) { httpServletResponse.setHeader(header.getKey(), header.getValue()); } // add cookies for (Cookie cookie : getCookies()) { httpServletResponse.addCookie(cookie); } // set status to OK if it's not set if (getStatus() == 0 || getStatus() == Integer.MAX_VALUE) { ok(); } // call finalize listeners if ((finalizeListeners != null) && !finalizeListeners.isEmpty()) { finalizeListeners.onFinalize(this); } }
protected void sendResource(URL resourceUrl, RouteContext routeContext) throws IOException { String filename = resourceUrl.getFile(); String mimeType = routeContext.getApplication().getMimeTypes().getContentType(filename); if (!StringUtils.isNullOrEmpty(mimeType)) { // stream the resource log.debug("Streaming as resource '{}'", resourceUrl); routeContext.getResponse().ok().chunked(chunked).resource(resourceUrl.openStream()); } else { // stream the file log.debug("Streaming as file '{}'", resourceUrl); routeContext.getResponse().ok().chunked(chunked).file(filename, resourceUrl.openStream()); } }
@Override public void handle(RouteContext routeContext) { Response response = routeContext.getResponse().noCache().text(); SortedMap<String, HealthCheck.Result> healthChecks = healthCheckRegistry.runHealthChecks(); if (healthChecks.isEmpty()) { response.notImplemented().send("The health checks are empty"); } else { boolean notHealthy = healthChecks.values().stream().anyMatch(hc -> !hc.isHealthy()); if (notHealthy) { response.internalError().send("The health is bad"); } else { response.ok().send("The health is good"); } } }
@Override protected void sendResource(URL resourceUrl, RouteContext routeContext) throws IOException { try { // compile sass to css log.trace("Send css for '{}'", resourceUrl); ScssContext.UrlMode urlMode = ScssContext.UrlMode.ABSOLUTE; String identifier = resourceUrl.getFile(); ScssStylesheet scssStylesheet = ScssStylesheet.get(identifier); if (scssStylesheet == null) { throw new Exception("ScssStylesheet is null for '" + identifier + "'"); } String content = scssStylesheet.toString(); String result = sourceMap.get(content); if (result == null) { scssStylesheet.compile(urlMode); Writer writer = new StringWriter(); scssStylesheet.write(writer, minify); result = writer.toString(); if (routeContext.getApplication().getPippoSettings().isProd()) { sourceMap.put(content, result); } } // send css routeContext.getResponse().contentType("text/css"); routeContext.getResponse().ok().send(result); } catch (Exception e) { throw new PippoRuntimeException(e); } }
@Override protected void sendResource(URL resourceUrl, RouteContext routeContext) throws IOException { try { // compile less to css log.trace("Send css for '{}'", resourceUrl); LessSource.URLSource source = new LessSource.URLSource(resourceUrl); String content = source.getContent(); String result = sourceMap.get(content); if (result == null) { ThreadUnsafeLessCompiler compiler = new ThreadUnsafeLessCompiler(); LessCompiler.Configuration configuration = new LessCompiler.Configuration(); configuration.setCompressing(minify); LessCompiler.CompilationResult compilationResult = compiler.compile(resourceUrl, configuration); for (LessCompiler.Problem warning : compilationResult.getWarnings()) { log.warn("Line: {}, Character: {}, Message: {} ", warning.getLine(), warning.getCharacter(), warning.getMessage()); } result = compilationResult.getCss(); if (routeContext.getApplication().getPippoSettings().isProd()) { sourceMap.put(content, result); } } // send css routeContext.getResponse().contentType("text/css"); routeContext.getResponse().ok().send(result); } catch (Exception e) { throw new PippoRuntimeException(e); } }
@Override public void handle(RouteContext routeContext) { Response response = routeContext.getResponse().noCache().text(); SortedMap<String, HealthCheck.Result> healthChecks = healthCheckRegistry.runHealthChecks(); if (healthChecks.isEmpty()) { response.notImplemented().send("The health checks are empty"); } else { boolean notHealthy = healthChecks.values().stream().anyMatch(hc -> !hc.isHealthy()); if (notHealthy) { response.internalError().send("The health is bad"); } else { response.ok().send("The health is good"); } } }
protected void serveSpecification(RouteContext ctx, String specificationName) { String extension = Files.getFileExtension(specificationName); if (extension.isEmpty()) { // default to json specificationName += ".json"; } final String finalDocumentName = specificationName; final String finalExtension = Files.getFileExtension(finalDocumentName); String document = specifications.get(finalDocumentName.toLowerCase()); if (document == null) { ctx.getResponse().notFound(); } else { ctx.getResponse().ok(); httpCacheToolkit.addEtag(ctx, startTime); if ("json".equals(finalExtension)) { ctx.json(); } else if ("yaml".equals(finalExtension)) { ctx.yaml(); } else { ctx.text(); } if (HttpMethod.GET.equals(ctx.getRequestMethod())) { ctx.getResponse().send(document); } } }
@Override protected void sendResource(URL resourceUrl, RouteContext routeContext) throws IOException { try { // compile sass to css log.trace("Send css for '{}'", resourceUrl); ScssContext.UrlMode urlMode = ScssContext.UrlMode.ABSOLUTE; String identifier = resourceUrl.getFile(); ScssStylesheet scssStylesheet = ScssStylesheet.get(identifier); if (scssStylesheet == null) { throw new Exception("ScssStylesheet is null for '" + identifier + "'"); } String content = scssStylesheet.toString(); String result = sourceMap.get(content); if (result == null) { scssStylesheet.compile(urlMode); Writer writer = new StringWriter(); scssStylesheet.write(writer, minify); result = writer.toString(); if (routeContext.getApplication().getPippoSettings().isProd()) { sourceMap.put(content, result); } } // send css routeContext.getResponse().contentType("text/css"); routeContext.getResponse().ok().send(result); } catch (Exception e) { throw new PippoRuntimeException(e); } }
protected void serveSpecification(RouteContext ctx, String specificationName) { String extension = Files.getFileExtension(specificationName); if (extension.isEmpty()) { // default to json specificationName += ".json"; } final String finalDocumentName = specificationName; final String finalExtension = Files.getFileExtension(finalDocumentName); String document = specifications.get(finalDocumentName.toLowerCase()); if (document == null) { ctx.getResponse().notFound(); } else { ctx.getResponse().ok(); httpCacheToolkit.addEtag(ctx, startTime); if ("json".equals(finalExtension)) { ctx.json(); } else if ("yaml".equals(finalExtension)) { ctx.yaml(); } else { ctx.text(); } if (HttpMethod.GET.equals(ctx.getRequestMethod())) { ctx.getResponse().send(document); } } }
@POST @ApiSummary("Add a new pet to the store") @RequirePermission("add:pet") @Return(code = 405, description = "Invalid input", onResult = ValidationException.class) public void addPet(@Desc("Pet object that needs to be added to the store") @Body Pet pet) { getResponse().ok(); }
context.getResponse().ok().contentType(TEXT_XML).contentLength(result.length); try (OutputStream output = context.getResponse().getOutputStream()) { output.write(result);
context.getResponse().ok().contentType(TEXT_XML).contentLength(result.length); try (OutputStream output = context.getResponse().getOutputStream()) { output.write(result);
@Override protected void sendResource(URL resourceUrl, RouteContext routeContext) throws IOException { try { // compile less to css log.trace("Send css for '{}'", resourceUrl); LessSource.URLSource source = new LessSource.URLSource(resourceUrl); String content = source.getContent(); String result = sourceMap.get(content); if (result == null) { ThreadUnsafeLessCompiler compiler = new ThreadUnsafeLessCompiler(); LessCompiler.Configuration configuration = new LessCompiler.Configuration(); configuration.setCompressing(minify); LessCompiler.CompilationResult compilationResult = compiler.compile(resourceUrl, configuration); for (LessCompiler.Problem warning : compilationResult.getWarnings()) { log.warn("Line: {}, Character: {}, Message: {} ", warning.getLine(), warning.getCharacter(), warning.getMessage()); } result = compilationResult.getCss(); if (routeContext.getApplication().getPippoSettings().isProd()) { sourceMap.put(content, result); } } // send css routeContext.getResponse().contentType("text/css"); routeContext.getResponse().ok().send(result); } catch (Exception e) { throw new PippoRuntimeException(e); } }
@POST("/{petId}/uploadImage") @ApiSummary("uploads an image") @RequirePermission("update:pet") @Produces(Produces.JSON) @Return(code = 200, description = "Successful operation") public void uploadFile( @Desc("ID of pet to update") long petId, @Desc("Additional data to pass to server") @Form String additionalMetadata, @Desc("file to upload") @Form FileItem file) { getResponse().ok(); }