List of usage examples for javax.servlet.http HttpServletResponse getOutputStream
public ServletOutputStream getOutputStream() throws IOException;
From source file:edu.usu.sdl.opencatalog.web.action.BaseAction.java
protected Resolution streamResults(final JsonResponse jsonResponse) { return new StreamingResolution(MediaType.APPLICATION_JSON) { @Override//from www . ja v a 2 s . co m protected void stream(HttpServletResponse response) throws Exception { objectMapper.writeValue(response.getOutputStream(), jsonResponse); } }; }
From source file:jahspotify.web.api.HistoryController.java
public void serializeHistoryCursor(Collection<TrackHistory> historyCursor, HttpServletResponse httpServletResponse) { try {/* w ww.ja v a 2s .com*/ final ServletOutputStream httpOutputStream = httpServletResponse.getOutputStream(); final BufferedWriter outputStream = new BufferedWriter(new OutputStreamWriter(httpOutputStream)); outputStream.write("{"); outputStream.write("\"count\":"); outputStream.write("" + historyCursor.size()); if (historyCursor.size() > 0) { Gson gson = new Gson(); outputStream.write(","); outputStream.write("\"tracks\":["); for (Iterator<TrackHistory> iterator = historyCursor.iterator(); iterator.hasNext();) { TrackHistory next = iterator.next(); outputStream.write(gson.toJson(toWebTrack(next))); if (iterator.hasNext()) { outputStream.write(","); } outputStream.flush(); } /* while (historyCursor.hasNext()) { outputStream.write(gson.toJson(toWebTrack(historyCursor.next()))); if (historyCursor.hasNext()) { outputStream.write(","); } outputStream.flush(); } */ outputStream.write("]"); } outputStream.write("}"); outputStream.flush(); outputStream.close(); httpOutputStream.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:byps.http.HIncomingStreamAsync.java
@Override public void close() throws IOException { if (log.isDebugEnabled()) log.debug("close(targetId=" + targetId); boolean alreadyClosed = closed.getAndSet(true); if (log.isDebugEnabled()) log.debug("alreadyClosed=" + alreadyClosed); if (!alreadyClosed) { if (log.isDebugEnabled()) log.debug("complete AsyncContext of targetId=" + targetId + " with status=" + HttpServletResponse.SC_OK); // The stream data must be completely read. // Otherwise the data remains in the socket and // disturbs the next request. while (is.read() != -1) { //if (log.isDebugEnabled()) log.debug("read before close, " + (char)c); }// w w w . j a v a2 s . com is.close(); HttpServletResponse response = (HttpServletResponse) rctxt.getResponse(); response.getOutputStream().close(); response.setStatus(HttpServletResponse.SC_OK); rctxt.complete(); super.close(); } if (log.isDebugEnabled()) log.debug(")close"); }
From source file:com.eviware.soapui.impl.wsdl.mock.WsdlMockOperationTest.java
private WsdlMockRequest makeWsdlMockRequest() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); Enumeration enumeration = mock(Enumeration.class); when(request.getHeaderNames()).thenReturn(enumeration); HttpServletResponse response = mock(HttpServletResponse.class); ServletOutputStream os = mock(ServletOutputStream.class); when(response.getOutputStream()).thenReturn(os); WsdlMockRunContext context = mock(WsdlMockRunContext.class); return new WsdlMockRequest(request, response, context); }
From source file:eu.europa.ejusticeportal.dss.controller.action.DownloadSignedPdf.java
/** * @param sf//from w w w . j av a 2 s . c o m * @param response * @throws IOException */ private void writeZip(SignedForm sf, HttpServletResponse response, String fileName) throws IOException { ZipOutputStream zos = new ZipOutputStream(response.getOutputStream()); ZipEntry ze = new ZipEntry(fileName); zos.putNextEntry(ze); zos.write(sf.getDocument()); ze = new ZipEntry(fileName + ".xml"); zos.putNextEntry(ze); zos.write(sf.getDetachedSignature()); zos.closeEntry(); zos.close(); }
From source file:net.mindengine.oculus.frontend.web.controllers.trm.tasks.AjaxSuiteSearchController.java
@Override public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { verifyPermissions(request);//from w w w . j a va 2 s .com OutputStream os = response.getOutputStream(); response.setContentType("text/xml"); String rId = request.getParameter("id"); OutputStreamWriter w = new OutputStreamWriter(os); String rootId = rId; if (rId.equals("mytasks0")) rootId = "0"; w.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); w.write("<tree id=\"" + rootId + "\" >"); User user = getUser(request); List<TrmSuite> suites = null; if (rId.startsWith("mytasks")) { Long projectId = null; String strProjectId = request.getParameter("projectId"); if (strProjectId != null) { projectId = Long.parseLong(strProjectId); } // Displaying a list of all user tasks List<TrmTask> tasks = trmDAO.getUserTasks(user.getId(), projectId); for (TrmTask task : tasks) { w.write("<item text=\"" + XmlUtils.escapeXml(task.getName()) + "\" " + "id=\"t" + task.getId() + "\" " + "im0=\"iconTask.png\" im1=\"iconTask.png\" im2=\"iconTask.png\" child=\"1\" " + " nocheckbox=\"1\" >"); w.write("</item>"); } } else if (rId.startsWith("t")) { Long taskId = Long.parseLong(rId.substring(1)); suites = trmDAO.getTaskSuites(taskId); } if (suites != null) { for (TrmSuite suite : suites) { w.write("<item "); w.write("text=\"" + XmlUtils.escapeXml(suite.getName()) + "\" "); w.write("id=\"suite" + suite.getId() + "\" "); w.write("im0=\"workflow-icon-suite.png\" im1=\"workflow-icon-suite.png\" im2=\"workflow-icon-suite.png\" "); w.write(">"); w.write("</item>"); } } w.write("</tree>"); w.flush(); os.flush(); os.close(); return null; }
From source file:edu.usu.sdl.opencatalog.web.action.BaseAction.java
private Resolution handleErrorResponse(final JsonResponse jsonResponse, boolean upload) { String contentType = MediaType.APPLICATION_JSON; if (upload) { contentType = MediaType.TEXT_HTML; }// ww w. j av a2s. c o m return new StreamingResolution(contentType) { @Override protected void stream(HttpServletResponse response) throws Exception { objectMapper.writeValue(response.getOutputStream(), jsonResponse); } }; }
From source file:it.biztech.btable.api.OlapApi.java
@GET @Path("/getCubes") @Produces("text/javascript") public void getCubes(@QueryParam(MethodParams.CATALOG) String catalog, @Context HttpServletRequest request, @Context HttpServletResponse response) throws IOException, JSONException { OlapUtils olapUtils = new OlapUtils(); JSONObject result = olapUtils.getOlapCubes(); Utils.buildJsonResult(response.getOutputStream(), result != null, result); }
From source file:com.thoughtworks.go.spark.SparkPreFilter.java
private void render404(HttpServletResponse response) throws IOException { response.setStatus(404);/* w w w . j av a 2 s . c o m*/ response.setCharacterEncoding("utf-8"); response.setContentType("text/plain"); response.getOutputStream().println("The url you are trying to reach appears to be incorrect."); }
From source file:de.iew.raspimotion.controllers.MotionJpegController.java
public void sendImageAsJpeg(FileDescriptor file, HttpServletResponse response) throws Exception { sendImageAsJpeg(response.getOutputStream(), file); response.flushBuffer();/*from w ww .ja v a2 s. c o m*/ }