List of usage examples for javax.servlet.http HttpServletResponse setBufferSize
public void setBufferSize(int size);
From source file:cz.zcu.kiv.eegdatabase.logic.controller.semantic.SemanticMultiController.java
/** * Generates an ontology document from POJO objects. * This method transforms the Jena's output using Owl-Api. * * @param request/*from w w w . jav a 2 s . com*/ * @param response * @return * @throws Exception */ public ModelAndView getOntologyOwlApi(HttpServletRequest request, HttpServletResponse response) throws Exception { log.debug("Controller for transforming POJO object to resources of semantic web"); String syntax; OutputStream out = null; InputStream is = null; int headerBufferSize = 8096; syntax = request.getParameter("type"); response.setHeader("Content-Type", "application/rdf+xml"); response.setContentType("application/rdf+xml"); response.setHeader("Content-Disposition", "attachment;filename=eegdatabase.owl"); log.debug("Creating output stream"); response.setStatus(HttpServletResponse.SC_OK); response.setBufferSize(headerBufferSize); out = response.getOutputStream(); log.debug("Generating OWL"); is = semanticFactory.getOntologyOwlApi(syntax); copy(is, out); out.flush(); out.close(); return null; }
From source file:alpha.portal.webapp.controller.CardFormController.java
/** * Gets the payload.//ww w.j a v a 2 s . com * * @param jspCard * the jsp card * @param response * the response * @return the payload * @throws IOException * Signals that an I/O exception has occurred. */ @RequestMapping(method = RequestMethod.POST, params = { "payloadGet" }) public String getPayload(final AlphaCard jspCard, final HttpServletResponse response) throws IOException { final AlphaCard alphaCard = this.alphaCardManager.get(jspCard.getAlphaCardIdentifier()); final Payload payload = alphaCard.getPayload(); if (payload != null) { final BufferedInputStream in = new BufferedInputStream(new ByteArrayInputStream(payload.getContent())); response.setBufferSize(payload.getContent().length); response.setContentType(payload.getMimeType()); response.setHeader("Content-Disposition", "attachment; filename=\"" + payload.getFilename() + "\""); response.setContentLength(payload.getContent().length); FileCopyUtils.copy(in, response.getOutputStream()); in.close(); response.getOutputStream().flush(); response.getOutputStream().close(); } final AlphaCardIdentifier identifier = alphaCard.getAlphaCardIdentifier(); return "redirect:/caseform?caseId=" + identifier.getCaseId() + "&activeCardId=" + identifier.getCardId(); }
From source file:it.govpay.web.console.pagamenti.gde.exporter.EventiExporter.java
private void processRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try {/*from w w w .j a v a 2 s . c o m*/ // ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); // service = (IEventiService)context.getBean("eventiService"); // EventiSearchForm sfInSession = (EventiSearchForm)context.getBean("searchFormEventi"); // EventiSearchForm searchForm = (EventiSearchForm)sfInSession.clone(); // service.setForm(searchForm); // Then we have to get the Response where to write our file HttpServletResponse response = resp; String isAllString = req.getParameter("isAll"); Boolean isAll = Boolean.parseBoolean(isAllString); String idtransazioni = req.getParameter("ids"); String[] ids = StringUtils.split(idtransazioni, ","); String formato = req.getParameter("formato"); String fileName = "Eventi.zip"; response.setContentType("x-download"); response.setHeader("Content-Disposition", "attachment; filename=" + fileName); response.addHeader("Cache-Control", "no-cache"); response.setStatus(200); response.setBufferSize(1024); // committing status and headers response.flushBuffer(); ExporterProperties prop = new ExporterProperties(); prop.setEnableHeaderInfo(EventiExporter.enableHeaderInfo); prop.setFormatoExport(formato); prop.setMimeThrowExceptionIfNotFound(EventiExporter.mimeThrowExceptionIfNotFound); SingleFileExporter sfe = new SingleFileExporter(response.getOutputStream(), prop, service); if (isAll) { //transazioni = service.findAll(start, limit); sfe.export(); } else { List<String> idEvento = new ArrayList<String>(); for (int j = 0; j < ids.length; j++) { idEvento.add(ids[j]); } sfe.export(idEvento); } } catch (IOException se) { this.log.error(se, se); throw se; } catch (Exception e) { this.log.error(e, e); throw new ServletException(e); } }
From source file:org.granite.grails.web.GrailsGAEWebSWFServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setAttribute(GrailsApplicationAttributes.REQUEST_SCOPE_ID, grailsAttributes); // Get the name of the Groovy script (intern the name so that we can lock on it) String pageName = "/swf" + request.getServletPath(); Resource requestedFile = getResourceForUri(pageName); File swfFile = requestedFile.getFile(); if (swfFile == null || !swfFile.exists()) { response.sendError(404, "\"" + pageName + "\" not found."); return;//from ww w . j a v a 2 s. c om } response.setContentType("application/x-shockwave-flash"); response.setContentLength((int) swfFile.length()); response.setBufferSize((int) swfFile.length()); response.setDateHeader("Expires", 0); byte[] buf = new byte[1000000]; FileInputStream is = null; try { is = new FileInputStream(swfFile); OutputStream os = response.getOutputStream(); int read = is.read(buf, 0, 1000000); while (read > 0) { os.write(buf, 0, read); read = is.read(buf, 0, 1000000); } } finally { if (is != null) { IOUtils.closeQuietly(is); } } }
From source file:de.unirostock.sems.caroweb.Converter.java
private void checkout(HttpServletRequest request, HttpServletResponse response, Path storage, String req) throws ServletException, IOException { Path target = storage.resolve(req).toAbsolutePath().normalize(); if (!target.startsWith(storage) || !Files.exists(target)) { error(request, response, "you're not allowed to download that file."); return;/*from w w w . j a v a2s. co m*/ } try { String mime = target.toString().endsWith("omex") ? "application/zip" : "application/vnd.wf4ever.robundle+zip"; response.reset(); response.setBufferSize(CaRoWebutils.DEFAULT_BUFFER_SIZE); response.setContentType(mime); response.setHeader("Content-Length", String.valueOf(target.toFile().length())); response.setHeader("Content-Disposition", "attachment; filename=\"" + req + "\""); response.setHeader("Expires", CaRoWebutils.downloadDateFormater .format(new Date(System.currentTimeMillis() + CaRoWebutils.CACHE_TIME * 1000))); response.setHeader("Cache-Control", "max-age=" + CaRoWebutils.CACHE_TIME); response.setHeader("Last-Modified", CaRoWebutils.downloadDateFormater .format(new Date(Files.getLastModifiedTime(target).toMillis()))); response.setHeader("ETag", GeneralTools.hash(target + "-" + Files.getLastModifiedTime(target))); BufferedInputStream input = new BufferedInputStream(new FileInputStream(target.toFile()), CaRoWebutils.DEFAULT_BUFFER_SIZE); BufferedOutputStream output = new BufferedOutputStream(response.getOutputStream(), CaRoWebutils.DEFAULT_BUFFER_SIZE); // pass the stream to client byte[] buffer = new byte[CaRoWebutils.DEFAULT_BUFFER_SIZE]; int length; while ((length = input.read(buffer)) > 0) { output.write(buffer, 0, length); } input.close(); output.close(); return; } catch (IOException e) { // whoops, that's our fault. shouldn't happen. hopefully. LOGGER.error("unable to dump file " + target + " (at least not in an expected form)"); } error(request, response, "couldn't dump file"); }
From source file:org.granite.grails.web.GrailsWebSWFServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setAttribute(GrailsApplicationAttributes.REQUEST_SCOPE_ID, grailsAttributes); // Get the name of the Groovy script (intern the name so that we can lock on it) String pageName = "/swf" + request.getServletPath(); Resource requestedFile = getResourceForUri(pageName); File swfFile = requestedFile.getFile(); if (swfFile == null || !swfFile.exists()) { response.sendError(404, "\"" + pageName + "\" not found."); return;//from w ww .j a va2s . c o m } response.setContentType("application/x-shockwave-flash"); response.setContentLength((int) swfFile.length()); response.setBufferSize((int) swfFile.length()); response.setDateHeader("Expires", 0); FileInputStream is = null; FileChannel inChan = null; try { is = new FileInputStream(swfFile); OutputStream os = response.getOutputStream(); inChan = is.getChannel(); long fSize = inChan.size(); MappedByteBuffer mBuf = inChan.map(FileChannel.MapMode.READ_ONLY, 0, fSize); byte[] buf = new byte[(int) fSize]; mBuf.get(buf); os.write(buf); } finally { if (is != null) { IOUtils.closeQuietly(is); } if (inChan != null) { try { inChan.close(); } catch (IOException ignored) { } } } }
From source file:com.nabla.dc.server.ImageService.java
private boolean exportImage(final String imageId, final HttpServletResponse response) throws IOException, SQLException, InternalErrorException { final Connection conn = db.getConnection(); try {/*from ww w . ja va2 s. c o m*/ final PreparedStatement stmt = StatementFormat.prepare(conn, "SELECT * FROM image WHERE id=?;", imageId); try { final ResultSet rs = stmt.executeQuery(); try { if (!rs.next()) { if (log.isDebugEnabled()) log.debug("failed to find report ID= " + imageId); return false; } if (log.isTraceEnabled()) log.trace("exporting image " + imageId); response.reset(); response.setBufferSize(DEFAULT_BUFFER_SIZE); response.setContentType(rs.getString("content_type")); response.setHeader("Content-Length", String.valueOf(rs.getInt("length"))); response.setHeader("Content-Disposition", MessageFormat.format("inline; filename=\"{0}\"", rs.getString("name"))); // to prevent images to be downloaded every time user hovers one image final Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.add(Calendar.MONTH, 2); response.setDateHeader("Expires", cal.getTime().getTime()); final BufferedInputStream input = new BufferedInputStream(rs.getBinaryStream("content"), DEFAULT_BUFFER_SIZE); try { final BufferedOutputStream output = new BufferedOutputStream(response.getOutputStream(), DEFAULT_BUFFER_SIZE); try { final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; int length; while ((length = input.read(buffer)) > 0) output.write(buffer, 0, length); } finally { output.close(); } } finally { input.close(); } } finally { rs.close(); } } finally { stmt.close(); } } finally { conn.close(); } return true; }
From source file:org.apache.axis2.transport.http.AxisServlet.java
/** * Implementaion of POST interface/* w ww.j a v a 2s . c om*/ * * @param request * @param response * @throws ServletException * @throws IOException */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //set the initial buffer for a larger value response.setBufferSize(BUFFER_SIZE); preprocessRequest(request); MessageContext msgContext; OutputStream out = response.getOutputStream(); String contentType = request.getContentType(); if (!HTTPTransportUtils.isRESTRequest(contentType)) { msgContext = createMessageContext(request, response); msgContext.setProperty(Constants.Configuration.CONTENT_TYPE, contentType); try { // adding ServletContext into msgContext; String url = request.getRequestURL().toString(); OutputStream bufferedOut = new BufferedOutputStream(out); InvocationResponse pi = HTTPTransportUtils.processHTTPPostRequest(msgContext, new BufferedInputStream(request.getInputStream()), bufferedOut, contentType, request.getHeader(HTTPConstants.HEADER_SOAP_ACTION), url); Boolean holdResponse = (Boolean) msgContext.getProperty(RequestResponseTransport.HOLD_RESPONSE); if (pi.equals(InvocationResponse.SUSPEND) || (holdResponse != null && Boolean.TRUE.equals(holdResponse))) { ((RequestResponseTransport) msgContext.getProperty(RequestResponseTransport.TRANSPORT_CONTROL)) .awaitResponse(); } // if data has not been sent back and this is not a signal response if (!TransportUtils.isResponseWritten(msgContext) && (((RequestResponseTransport) msgContext .getProperty(RequestResponseTransport.TRANSPORT_CONTROL)) .getStatus() != RequestResponseTransport.RequestResponseTransportStatus.SIGNALLED)) { response.setStatus(HttpServletResponse.SC_ACCEPTED); // only set contentType in this scenario, not if response already set log.debug("Response not written. Setting response contentType to text/xml; " + "charset=" + msgContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING)); response.setContentType("text/xml; charset=" + msgContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING)); } // Make sure that no data remains in the BufferedOutputStream even if the message // formatter doesn't call flush bufferedOut.flush(); } catch (AxisFault e) { setResponseState(msgContext, response); log.debug(e); if (msgContext != null) { processAxisFault(msgContext, response, out, e); } else { throw new ServletException(e); } } catch (Throwable t) { log.error(t.getMessage(), t); try { // If the fault is not going along the back channel we should be 202ing if (AddressingHelper.isFaultRedirected(msgContext)) { response.setStatus(HttpServletResponse.SC_ACCEPTED); } else { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); AxisBindingOperation axisBindingOperation = (AxisBindingOperation) msgContext .getProperty(Constants.AXIS_BINDING_OPERATION); if (axisBindingOperation != null) { AxisBindingMessage axisBindingMessage = axisBindingOperation .getFault((String) msgContext.getProperty(Constants.FAULT_NAME)); if (axisBindingMessage != null) { Integer code = (Integer) axisBindingMessage .getProperty(WSDL2Constants.ATTR_WHTTP_CODE); if (code != null) { response.setStatus(code.intValue()); } } } } handleFault(msgContext, out, new AxisFault(t.toString(), t)); } catch (AxisFault e2) { log.info(e2); throw new ServletException(e2); } } finally { closeStaxBuilder(msgContext); TransportUtils.deleteAttachments(msgContext); } } else { if (!disableREST) { new RestRequestProcessor(Constants.Configuration.HTTP_METHOD_POST, request, response) .processXMLRequest(); } else { showRestDisabledErrorMessage(response); } } }
From source file:org.nema.medical.mint.server.controller.StudySummaryController.java
@RequestMapping("/studies/{uuid}/{type}/summary") public void studiesSummary(@PathVariable("uuid") final String uuid, @PathVariable("type") final String type, final HttpServletResponse res) throws IOException { final Utils.StudyStatus studyStatus = Utils.validateStudyStatus(studiesRoot, uuid, res, studyDAO); if (studyStatus != Utils.StudyStatus.OK) { return;// w w w . j av a 2s. c o m } final File studyDir = new File(studiesRoot, uuid); final File typeDir = new File(studyDir, type); if (!typeDir.exists() || !typeDir.canRead()) { LOG.error("Unable to locate directory for study: " + studyDir); res.sendError(HttpServletResponse.SC_NOT_FOUND, "Invalid study requested: Not found"); return; } try { final File file = new File(typeDir, "/summary.xml"); if (!file.exists()) { StudyMetadata study = StudyIO.loadStudy(typeDir); StudyIO.writeSummaryToXML(study, file); } res.setContentType("text/xml"); res.setContentLength(Long.valueOf(file.length()).intValue()); res.setBufferSize(fileResponseBufferSize); Utils.streamFile(file, res.getOutputStream(), fileStreamBufferSize); } catch (final IOException e) { if (!res.isCommitted()) { res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to provide study summary. See server logs."); return; } } }