private void writeBootstrapPage(VaadinResponse response, String html) throws IOException { response.setContentType( ApplicationConstants.CONTENT_TYPE_TEXT_HTML_UTF_8); try (BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(response.getOutputStream(), UTF_8))) { writer.append(html); } }
/** * Sends the upload response. * * @param request * @param response * @throws IOException */ protected void sendUploadResponse(VaadinRequest request, VaadinResponse response) throws IOException { response.setContentType( ApplicationConstants.CONTENT_TYPE_TEXT_HTML_UTF_8); try (OutputStream out = response.getOutputStream()) { final PrintWriter outWriter = new PrintWriter( new BufferedWriter(new OutputStreamWriter(out, UTF_8))); outWriter.print("<html><body>download handled</body></html>"); outWriter.flush(); } }
/** * Writes the given string as a response using the given content type. * * @param response * The response reference * @param contentType * The content type of the response * @param responseString * The actual response * @throws IOException * If an error occurred while writing the response */ public void writeStringResponse(VaadinResponse response, String contentType, String responseString) throws IOException { response.setContentType(contentType); final OutputStream out = response.getOutputStream(); try (PrintWriter outWriter = new PrintWriter( new BufferedWriter(new OutputStreamWriter(out, UTF_8)))) { outWriter.print(responseString); } }
/** * Commit the JSON response. We can't write immediately to the output stream * as we want to write only a critical notification if something goes wrong * during the response handling. * * @param request * The request that resulted in this response * @param response * The response to write to * @param json * The JSON to write * @return true if the JSON was written successfully, false otherwise * @throws IOException * If there was an exception while writing to the output */ static boolean commitJsonResponse(VaadinRequest request, VaadinResponse response, String json) throws IOException { // The response was produced without errors so write it to the client response.setContentType(JsonConstants.JSON_CONTENT_TYPE); // Response might contain sensitive information, so prevent all forms of // caching response.setNoCacheHeaders(); byte[] b = json.getBytes(UTF_8); response.setContentLength(b.length); OutputStream outputStream = response.getOutputStream(); outputStream.write(b); // NOTE GateIn requires the buffers to be flushed to work outputStream.flush(); return true; }
try { if (mimetype != null) { response.setContentType(mimetype);
try { response.setContentType(getContentType());
private static void writeBootstrapPage(VaadinResponse response, String html) throws IOException { response.setContentType("text/html"); BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(response.getOutputStream(), "UTF-8")); writer.append(html); writer.close(); }
/** * Writes the given string as a response using the given content type. * * @param response * The response reference * @param contentType * The content type of the response * @param reponseString * The actual response * @throws IOException * If an error occured while writing the response */ public void writeStringResponse(VaadinResponse response, String contentType, String reponseString) throws IOException { response.setContentType(contentType); final OutputStream out = response.getOutputStream(); final PrintWriter outWriter = new PrintWriter( new BufferedWriter(new OutputStreamWriter(out, "UTF-8"))); outWriter.print(reponseString); outWriter.close(); }
/** * Commit the JSON response. We can't write immediately to the output stream * as we want to write only a critical notification if something goes wrong * during the response handling. * * @param response * The response to write to * @param json * The JSON to write * @throws IOException * If there was an exception while writing to the output */ public static void commitJsonResponse(VaadinResponse response, String json) throws IOException { response.setContentType(JsonConstants.JSON_CONTENT_TYPE); // Ensure that the browser does not cache UIDL responses. // iOS 6 Safari requires this (#9732) response.setHeader("Cache-Control", "no-cache"); byte[] b = json.getBytes("UTF-8"); response.setContentLength(b.length); OutputStream outputStream = response.getOutputStream(); outputStream.write(b); // NOTE GateIn requires the buffers to be flushed to work outputStream.flush(); } }
response.setContentType(mimeType != null ? mimeType : FileTypesHelper.DEFAULT_MIME_TYPE);
ServletContext context = ((VaadinServletRequest) request) .getServletContext(); response.setContentType(streamResource.getContentTypeResolver() .apply(streamResource, context)); response.setCacheTime(streamResource.getCacheTime());