List of usage examples for javax.servlet.http HttpServletResponse getOutputStream
public ServletOutputStream getOutputStream() throws IOException;
From source file:org.reallysqs.server.views.ReceivedMessagesResponseView.java
@SuppressWarnings("unchecked") @Override//from w w w . jav a 2 s .c o m protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("text/xml"); List<Message> messages = (List<Message>) model.get("messages"); ServletOutputStream outputStream = response.getOutputStream(); outputStream.print(prelude); if (messages != null) { for (Message message : messages) { outputStream.print("<Message><MessageId>"); outputStream.print(message.getUuid()); outputStream.print("</MessageId><MessageBody>"); outputStream.print(message.getContent()); outputStream.print("</MessageBody></Message>"); } } outputStream.print(epilogue); }
From source file:com.twitter.common.net.http.handlers.AssetHandler.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { OutputStream responseBody = resp.getOutputStream(); if (checksumMatches(req)) { resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED); } else {/*from w ww. j a v a 2s . c om*/ setPayloadHeaders(resp); boolean gzip = supportsGzip(req); if (gzip) { resp.setHeader("Content-Encoding", GZIP_ENCODING); } InputStream in = new ByteArrayInputStream(gzip ? staticAsset.getGzipData() : staticAsset.getRawData()); ByteStreams.copy(in, responseBody); } Closeables.close(responseBody, /* swallowIOException */ true); }
From source file:UTF8.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { try {//www . ja v a2s . c om BufferedReader reader = req.getReader(); res.setContentType("text/html; charset=UTF-8"); PrintWriter out = new PrintWriter(new OutputStreamWriter(res.getOutputStream(), "UTF8"), true); // Read and write 4K chars at a time // (Far more efficient than reading and writing a line at a time) char[] buf = new char[4 * 1024]; // 4Kchar buffer int len; while ((len = reader.read(buf, 0, buf.length)) != -1) { out.write(buf, 0, len); } out.flush(); } catch (Exception e) { getServletContext().log(e, "Problem filtering page to UTF-8"); } }
From source file:edu.mayo.cts2.framework.plugin.service.lexevs.bulk.AbstractBulkDownloadController.java
protected void writeException(HttpServletResponse response, String message, int errorCode) { response.setContentType("text/plain; charset=utf-8"); response.setStatus(errorCode);// w w w .j a va 2 s . co m try { IOUtils.write(message, response.getOutputStream()); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:simplestorage.hashtable.JsonView.java
@Override protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("text/plain"); response.setHeader("Cache-Control", "no-cache"); String json = model.get("responseJson").toString(); ServletOutputStream out = response.getOutputStream(); out.print(json);//w ww . j a v a 2 s. c o m out.close(); }
From source file:org.openmrs.module.clinicalsummary.web.controller.watcher.DownloadUploadWatcherController.java
@RequestMapping(method = RequestMethod.GET) public void watch(final HttpServletResponse response) throws IOException { response.setContentType(MimeType.APPLICATION_JSON); JsonFactory factory = new JsonFactory(); JsonGenerator generator = factory.createJsonGenerator(response.getOutputStream(), JsonEncoding.UTF8); generator.useDefaultPrettyPrinter(); generator.writeStartObject();//from w w w. j a v a2 s . c o m SummariesTaskInstance instance = SummariesTaskInstance.getInstance(); generator.writeBooleanField("running", instance.isRunning()); generator.writeStringField("filename", instance.getCurrentFilename()); generator.writeStringField("task", instance.getCurrentTask()); String summariesFilename = instance.getSummariesFilename(); if (!instance.isRunning() && StringUtils.isNotEmpty(summariesFilename)) { generator.writeStringField("file", summariesFilename); SummariesTaskInstance.removeInstance(); } generator.writeEndObject(); generator.close(); }
From source file:com.stratelia.webactiv.servlets.OnlineFileServer.java
private void displayWarningHtmlCode(HttpServletResponse res) throws IOException { StringReader message = null;// w w w . j a v a2s .c o m OutputStream output = res.getOutputStream(); ResourceLocator resourceLocator = new ResourceLocator( "com.stratelia.webactiv.util.peasUtil.multiLang.fileServerBundle", ""); message = new StringReader(resourceLocator.getString("warning")); try { IOUtils.copy(message, output); } catch (Exception e) { SilverTrace.warn("peasUtil", "OnlineFileServer.displayWarningHtmlCode", "root.EX_CANT_READ_FILE", "warning properties"); } finally { IOUtils.closeQuietly(output); IOUtils.closeQuietly(message); } }
From source file:net.mindengine.oculus.frontend.web.controllers.test.AjaxParameterSearchController.java
@Override public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { OutputStream os = response.getOutputStream(); response.setContentType("text/xml"); String rId = request.getParameter("id"); OutputStreamWriter w = new OutputStreamWriter(os); String rootId = rId;//w w w . jav a 2 s .c o m w.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); w.write("<tree id=\"" + rootId + "\" >"); List<Project> projects = null; List<TestGroup> groups = null; List<Test> tests = null; List<TestParameter> parameters = null; if (rId.equals("0")) { // Fetching a list of projects projects = projectDAO.getRootProjects(); } else if (rId.startsWith("p")) { Long projectId = Long.parseLong(rId.substring(1)); projects = projectDAO.getSubprojects(projectId); tests = testDAO.getTestsByProjectId(projectId, 0L); groups = testDAO.getProjectTestGroups(projectId); } else if (rId.startsWith("g")) { // g123_456 where 123 - id of a group and 456 - id of a project int dash = rId.indexOf("_"); Long groupId = Long.parseLong(rId.substring(1, dash)); Long projectId = Long.parseLong(rId.substring(dash + 1)); tests = testDAO.getTestsByProjectId(projectId, groupId); } else if (rId.startsWith("t")) { Long testId = Long.parseLong(rId.substring(1)); parameters = testDAO.getTestInputParameters(testId); parameters.addAll(testDAO.getTestOutputParameters(testId)); } if (projects != null) { for (Project project : projects) { w.write("<item text=\"" + XmlUtils.escapeXml(project.getName()) + "\" " + "id=\"p" + project.getId() + "\" im0=\"tombs.gif\" im1=\"tombs_open.gif\" im2=\"tombs.gif\" child=\"1\" " + " nocheckbox=\"1\" >"); w.write("</item>"); } } if (groups != null) { for (TestGroup group : groups) { w.write("<item "); w.write("text=\"" + XmlUtils.escapeXml(group.getName()) + "\" "); w.write("id=\"g" + group.getId() + "_" + group.getProjectId() + "\" "); w.write("im0=\"folderClosed.gif\" im1=\"folderOpen.gif\" im2=\"folderClosed.gif\" "); w.write("child=\"1\" nocheckbox=\"1\" >"); w.write("</item>"); } } if (tests != null) { for (Test test : tests) { w.write("<item "); w.write("text=\"" + XmlUtils.escapeXml(test.getName()) + "\" "); w.write("id=\"t" + test.getId() + "\" "); w.write("im0=\"iconTest.png\" im1=\"iconTest.png\" im2=\"iconTest.png\" "); w.write("child=\"1\" nocheckbox=\"1\" >"); w.write("</item>"); } } if (parameters != null) { for (TestParameter parameter : parameters) { w.write("<item "); w.write("text=\"" + XmlUtils.escapeXml(parameter.getName()) + "\" "); w.write("id=\"tp" + parameter.getId() + "\" "); if (parameter.getType().equals(TestParameter.TYPE_INPUT)) { w.write("im0=\"iconParameterInput.png\" im1=\"iconParameterInput.png\" im2=\"iconParameterInput.png\" "); } else w.write("im0=\"iconParameterOutput.png\" im1=\"iconParameterOutput.png\" im2=\"iconParameterOutput.png\" "); w.write(" >"); w.write("</item>"); } } w.write("</tree>"); w.flush(); os.flush(); os.close(); return null; }
From source file:codes.thischwa.c5c.requestcycle.response.GenericResponse.java
/** * Write the response to the {@link HttpServletResponse} (The character encoding of the {@link HttpServletResponse} will * be used. Inherited object could overwrite this to write * special content or headers.//from w ww .j av a 2 s . c o m * * @param resp * the resp * @throws IOException * Signals that an I/O exception has occurred. */ @JsonIgnore public void write(HttpServletResponse resp) throws IOException { if (mode != null && mode.getContentType() != null) resp.setContentType(mode.getContentType()); OutputStream out = resp.getOutputStream(); String json = toString(); IOUtils.write(json, out, resp.getCharacterEncoding()); IOUtils.closeQuietly(out); }
From source file:com.hp.autonomy.frontend.find.core.view.ViewController.java
@RequestMapping(value = VIEW_STATIC_CONTENT_PROMOTION_PATH, method = RequestMethod.GET) public void viewStaticContentPromotion(@RequestParam(REFERENCE_PARAM) final String reference, final HttpServletResponse response) throws IOException, E { response.setContentType(MediaType.TEXT_HTML_VALUE); ViewContentSecurityPolicy.addContentSecurityPolicy(response); viewServerService.viewStaticContentPromotion(reference, response.getOutputStream()); }