List of usage examples for javax.servlet.http HttpServletResponse getOutputStream
public ServletOutputStream getOutputStream() throws IOException;
From source file:com.kelveden.rastajax.servlet.DefaultHtmlServlet.java
private void writeRepresentationToResponse(Set<FlatResource> representation, HttpServletResponse httpResponse) throws IOException { httpResponse.setContentType("text/html; charset=utf8"); final OutputStream outputStream = httpResponse.getOutputStream(); final PrintStream printStream = new PrintStream(outputStream); printStream.println("<html>"); printStream.println("<body>"); printStream.println("<head>"); printStream.println("<style type=\"text/css\">"); printStream.println("* { font-size:10px; }"); printStream.println("table { border-width: 1px; border-collapse: collapse; margin-left: 10px; }"); printStream.println("table th { border: 1px solid; padding: 4px; background-color: #dedede; }"); printStream.println("table td { border: 1px solid; padding: 4px; }"); printStream.println("</style>"); printStream.println("</head>"); for (FlatResource resource : representation) { writeResource(resource, printStream); }//w w w .ja va 2 s . c o m printStream.println("</body>"); printStream.println("</html>"); printStream.flush(); }
From source file:com.sap.dirigible.runtime.registry.RepositoryServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String repositoryPath = null; final OutputStream out = response.getOutputStream(); try {//www . j av a 2 s.c o m repositoryPath = extractRepositoryPath(request); IEntity entity = getEntity(repositoryPath, request); byte[] data; if (entity == null) { ByteArrayOutputStream buff = new ByteArrayOutputStream(); IOUtils.copy(request.getInputStream(), buff); data = buff.toByteArray(); String contentType = request.getContentType(); if (contentType == null) { contentType = "text/plain"; //$NON-NLS-1$ } boolean isBinary = ContentTypeHelper.isBinary(contentType); getRepository(request).createResource(repositoryPath, data, isBinary, contentType); } else { if (entity instanceof IResource) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, THERE_IS_AN_EXISTING_RESOURCE_AT_THE_SAME_LOCATION_USE_PUT_METHOD_FOR_UPDATE); } else if (entity instanceof ICollection) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, THERE_IS_AN_EXISTING_COLLECTION_AT_THE_SAME_LOCATION); } } } catch (IllegalArgumentException ex) { logger.error(String.format(REQUEST_PROCESSING_FAILED_S, repositoryPath) + ex.getMessage()); response.sendError(HttpServletResponse.SC_BAD_REQUEST, ex.getMessage()); } catch (MissingResourceException ex) { logger.error(String.format(REQUEST_PROCESSING_FAILED_S, repositoryPath) + ex.getMessage()); response.sendError(HttpServletResponse.SC_NO_CONTENT, ex.getMessage()); } finally { out.flush(); out.close(); } }
From source file:com.seleniumtests.it.driver.support.server.PageServlet.java
/** * Allow downloading of files in upload folder *//*from w ww . j a va 2s . com*/ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { if (this.resourceFile.endsWith(".css")) { resp.addHeader("Content-Type", "text/css "); } IOUtils.copy(getClass().getResourceAsStream(this.resourceFile), resp.getOutputStream()); } catch (IOException e) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Error while handling request: " + e.getMessage()); } }
From source file:org.inbio.ait.web.ajax.controller.ExportCsvController.java
private ModelAndView writeReponse(HttpServletRequest request, HttpServletResponse response, List<Specimen> specimens) throws Exception { response.setCharacterEncoding("ISO-8859-1"); response.setContentType("text/html"); ServletOutputStream out = response.getOutputStream(); //String documento = ""; StringBuilder documento = new StringBuilder(); documento.append(//w w w . j a v a 2 s. co m "<table class=\"contacts\" cellspacing=\"0\"><tr><th class=\"species\">Nombre cientfico</th><th class=\"species\">Longitud</th><th class=\"species\">Latitud</th><th class=\"species\"># de catlogo</th><th class=\"species\">Institucin</th>"); for (Specimen s : specimens) { documento.append("<tr>"); documento.append("<td class=\"contact\">" + s.getScientificname() + "</td>"); documento.append("<td class=\"contact\">" + s.getDecimallongitude() + "</td>"); documento.append("<td class=\"contact\">" + s.getDecimallatitude() + "</td>"); documento.append("<td class=\"contact\">" + s.getCatalognumber() + "</td>"); documento.append("<td class=\"contact\">" + s.getInstitutioncode() + "</td>"); documento.append("<tr>"); } documento.append("</table>"); out.println(documento.toString()); out.flush(); out.close(); return null; }
From source file:org.inbio.ait.web.ajax.controller.SelectAllController.java
private ModelAndView writeReponse(HttpServletRequest request, HttpServletResponse response, List<Polygon> pList) throws Exception { response.setCharacterEncoding("ISO-8859-1"); response.setContentType("text/xml"); // Binary output ServletOutputStream out = response.getOutputStream(); if (pList != null) { StringBuilder result = new StringBuilder(); result.append("<?xml version='1.0' encoding='ISO-8859-1'?><response>"); for (Polygon p : pList) { result.append("<polygon><id>" + p.getId() + "</id>"); result.append("<name>" + p.getName() + "</name></polygon>"); }/*from w ww . j a v a 2 s .com*/ result.append("</response>"); out.println(result.toString()); } out.flush(); out.close(); return null; }
From source file:org.shredzone.cilla.plugin.sitemap.SitemapView.java
/** * Renders a sitemap of all pages./*from w w w . ja v a 2 s. c o m*/ */ @View(pattern = "/sitemap.xml.gz", name = "sitemap") public void sitemapView(HttpServletRequest req, HttpServletResponse resp) throws ViewException { try { resp.setContentType("text/xml"); resp.setHeader("Content-Encoding", "gzip"); try (GZIPOutputStream go = new GZIPOutputStream(resp.getOutputStream())) { SitemapWriter writer = new SitemapWriter(go); writer.writeHeader(); writeHome(writer); writePages(writer); writer.writeFooter(); writer.flush(); go.finish(); } } catch (IOException ex) { throw new ViewException(ex); } }
From source file:com.collective.celos.servlet.JSONWorkflowListServlet.java
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException { try {/*w ww . j a v a2s.c o m*/ Scheduler sch = getOrCreateCachedScheduler(); WorkflowConfiguration cfg = sch.getWorkflowConfiguration(); ObjectNode object = createJSONObject(cfg); writer.writeValue(res.getOutputStream(), object); } catch (Exception e) { throw new ServletException(e); } }
From source file:org.openqa.grid.internal.listener.CommandListenerTest.java
@Test public void canModifyResponseWithListener() throws IOException { Registry registry = Registry.newInstance(); registry.add(new MyRemoteProxy(req, registry)); RequestHandler req = GridHelper.createNewSessionHandler(registry, app1); req.process();/*from w w w . ja va2 s . c om*/ TestSession session = req.getSession(); // Mock the request so it seems like a new session SeleniumBasedRequest request = mock(SeleniumBasedRequest.class); when(request.getRequestURI()).thenReturn("session"); when(request.getServletPath()).thenReturn("session"); when(request.getContextPath()).thenReturn(""); when(request.getMethod()).thenReturn("GET"); Enumeration<String> strings = Collections.emptyEnumeration(); when(request.getHeaderNames()).thenReturn(strings); HttpServletResponse response = mock(HttpServletResponse.class); ServletOutputStream stream = mock(ServletOutputStream.class); when(response.getOutputStream()).thenReturn(stream); session.forward(request, response, true); // When the output stream is being written back to the remote, it should // only contain the bits we modified in // MyRemoteProxy's afterCommand method verify(stream).write(responseBytes); }
From source file:org.vbossica.springbox.metrics.MetricsController.java
@RequestMapping(value = "/metrics/metrics", method = RequestMethod.GET) public void process( @RequestParam(value = "pretty", required = false, defaultValue = "true") boolean prettyPrint, HttpServletResponse resp) throws IOException { resp.setContentType("application/json"); resp.setHeader("Cache-Control", "must-revalidate,no-cache,no-store"); resp.setStatus(HttpServletResponse.SC_OK); final OutputStream output = resp.getOutputStream(); try {/*from w w w.jav a2 s .co m*/ (prettyPrint ? mapper.writerWithDefaultPrettyPrinter() : mapper.writer()).writeValue(output, registry); } finally { output.close(); } }
From source file:org.opengeo.gsr.core.controller.ImageResourceController.java
protected void writeImageData(File imageFile, HttpServletResponse response) throws IOException { InputStream is = null;//from w w w . ja v a 2 s . c om OutputStream os = null; try { is = new FileInputStream(imageFile); os = response.getOutputStream(); IOUtils.copy(is, os); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(os); } }