List of usage examples for javax.servlet.http HttpServletResponse reset
public void reset();
From source file:fll.web.api.CheckAuthServlet.java
@Override protected final void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException { final ServletContext application = getServletContext(); final boolean authenticated = WebUtils.checkAuthenticated(request, application); final AuthResult result = new AuthResult(authenticated); final ObjectMapper jsonMapper = new ObjectMapper(); response.reset(); response.setContentType("application/json"); final PrintWriter writer = response.getWriter(); jsonMapper.writeValue(writer, result); }
From source file:com.fun.rrs.common.excel.ExportExcel.java
/** * //ww w. ja v a 2 s . com * @param fileName ?? */ public ExportExcel write(HttpServletResponse response, String fileName) throws IOException { response.reset(); response.setContentType("application/octet-stream; charset=utf-8"); response.setHeader("Content-Disposition", "attachment; filename=" + java.net.URLEncoder.encode(fileName, "UTF-8")); write(response.getOutputStream()); return this; }
From source file:org.apache.metron.rest.controller.PcapController.java
@ApiOperation(value = "Download Pcap Results for a page.") @ApiResponses(value = { @ApiResponse(message = "Returns Pcap as a file download.", code = 200), @ApiResponse(message = "Job or page is missing.", code = 404) }) @RequestMapping(value = "/{jobId}/raw", method = RequestMethod.GET) void raw(/* w ww.j a va 2s .co m*/ @ApiParam(name = "jobId", value = "Job ID of submitted job", required = true) @PathVariable String jobId, @ApiParam(name = "page", value = "Page number", required = true) @RequestParam Integer page, @RequestParam(defaultValue = "", required = false) String fileName, final HttpServletRequest request, final HttpServletResponse response) throws RestException { try (InputStream inputStream = pcapQueryService.getRawPcap(SecurityUtils.getCurrentUser(), jobId, page); OutputStream output = response.getOutputStream()) { response.reset(); if (inputStream == null) { response.setStatus(HttpStatus.NOT_FOUND.value()); } else { response.setContentType("application/octet-stream"); if (fileName.isEmpty()) { fileName = String.format(PCAP_FILENAME_FORMAT, jobId, page); } response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); int size = IOUtils.copy(inputStream, output); response.setContentLength(size); output.flush(); } } catch (IOException e) { throw new RestException(e); } }
From source file:com.baidu.upload.controller.ImageController.java
@RequestMapping("downloadImg") public void downloadImg(Integer id, HttpServletRequest request, HttpServletResponse response) { Image image = imageService.get(id); String imgname = image.getName(); ServletOutputStream out = null;//from ww w .j av a 2s. c om try { response.reset(); String userAgent = request.getHeader("User-Agent"); byte[] bytes = userAgent.contains("MSIE") ? imgname.getBytes() : imgname.getBytes("UTF-8"); // fileName.getBytes("UTF-8")?safari? String fileName = new String(bytes, "ISO-8859-1"); System.out.println(fileName); // ? response.setContentType("multipart/form-data"); response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(imgname, "UTF-8")); //?blob byte[] contents = image.getImgblob(); out = response.getOutputStream(); //? out.write(contents); out.flush(); } catch (IOException e) { e.printStackTrace(); } }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setBufferSize(8 * 1024); // 8K buffer res.setContentType("text/html"); PrintWriter out = res.getWriter(); int size = res.getBufferSize(); // returns 8096 or greater // Record the default size, in the log log("The default buffer size is " + size); out.println("The client won't see this"); res.reset(); out.println("And this won't be seen if sendError() is called"); if (req.getParameter("important_parameter") == null) { res.sendError(res.SC_BAD_REQUEST, "important_parameter needed"); }//w w w . java2 s .c o m }
From source file:me.utils.excel.ExportExcelme.java
/** * /* www . j av a2 s. c om*/ * @param fileName ?? */ public ExportExcelme write(HttpServletResponse response, String fileName) throws IOException { response.reset(); response.setContentType("application/octet-stream; charset=utf-8"); response.setHeader("Content-Disposition", "attachment; filename=" + Encodes.urlEncode(fileName)); write(response.getOutputStream()); return this; }
From source file:org.displaytag.filter.ExportDelegate.java
/** * Actually writes exported data. Extracts content from the Map stored in request with the * <code>TableTag.FILTER_CONTENT_OVERRIDE_BODY</code> key. * /* w ww . j av a 2s. c o m*/ * @param wrapper BufferedResponseWrapper implementation * @param response HttpServletResponse * @param request ServletRequest * @throws IOException exception thrown by response writer/outputStream */ protected static void writeExport(HttpServletResponse response, ServletRequest request, BufferedResponseWrapper wrapper) throws IOException { if (wrapper.isOutRequested()) { // data already written log.debug("Filter operating in unbuffered mode. Everything done, exiting"); return; } // if you reach this point the PARAMETER_EXPORTING has been found, but the special header has never been set in // response (this is the signal from table tag that it is going to write exported data) log.debug("Filter operating in buffered mode. "); Map bean = (Map) request.getAttribute(TableTag.FILTER_CONTENT_OVERRIDE_BODY); if (log.isDebugEnabled()) { log.debug(bean); } Object pageContent = bean.get(TableTagParameters.BEAN_BODY); if (pageContent == null) { if (log.isDebugEnabled()) { log.debug("Filter is enabled but exported content has not been found. Maybe an error occurred?"); } PrintWriter out = response.getWriter(); out.write(wrapper.getContentAsString()); out.flush(); return; } // clear headers if (!response.isCommitted()) { response.reset(); } String filename = (String) bean.get(TableTagParameters.BEAN_FILENAME); String contentType = "application/download"; String characterEncoding = wrapper.getCharacterEncoding(); String wrappedContentType = wrapper.getContentType(); if (wrappedContentType != null && wrappedContentType.indexOf("charset") > -1) { // charset is already specified (see #921811) characterEncoding = StringUtils.substringAfter(wrappedContentType, "charset="); } if (characterEncoding != null && contentType.indexOf("charset") == -1) //$NON-NLS-1$ { contentType += "; charset=" + characterEncoding; //$NON-NLS-1$ } ExibicaoDocumento exibicao = new ExibicaoDocumento(); exibicao.setTipoConteudo(contentType); exibicao.setNomeArquivo(filename); exibicao.setAsAttachment(true); if (((String) bean.get(TableTagParameters.BEAN_CONTENTTYPE)).indexOf("excel") > -1) { exibicao.setExtensaoArquivo(".xls"); } else if (((String) bean.get(TableTagParameters.BEAN_CONTENTTYPE)).indexOf("csv") > -1) { exibicao.setExtensaoArquivo(".csv"); } else if (((String) bean.get(TableTagParameters.BEAN_CONTENTTYPE)).indexOf("xml") > -1) { exibicao.setExtensaoArquivo(".xml"); } else if (((String) bean.get(TableTagParameters.BEAN_CONTENTTYPE)).indexOf("pdf") > -1) { exibicao.setExtensaoArquivo(".pdf"); } byte[] content; if (pageContent instanceof String) { content = ((String) pageContent).getBytes(characterEncoding); } else { content = (byte[]) pageContent; } try { exibicao.gerarExibicaoDocumento(response, content); } catch (CDException cde) { // TODO Tratar erro.... } }
From source file:org.massyframework.assembly.base.web.HttpResourceProcessorManagement.java
/** * ??//from ww w.j av a 2 s.co m * @param resp * @param sc * @throws IOException */ private void sendError(final HttpServletResponse resp, int sc) throws IOException { try { // we need to reset headers for 302 and 403 resp.reset(); resp.sendError(sc); } catch (IllegalStateException e) { // this could happen if the response has already been committed } }
From source file:org.sakaiproject.kernel.rest.count.RestCountProvider.java
/** * {@inheritDoc}//from w ww. ja v a 2 s .c om * * @see org.sakaiproject.kernel.api.rest.RestProvider#dispatch(java.lang.String[], * javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse) */ public void dispatch(String[] elements, HttpServletRequest request, HttpServletResponse response) { try { String path = request.getPathInfo().substring(KEY.length() + 1); Node n = jcrNodeFactoryService.getNode(path); if (n == null) { response.reset(); response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // String primaryNodeType = n.getPrimaryNodeType().getName(); if (n.hasProperty(JCRConstants.JCR_SMARTNODE)) { handleSmartNode(request, response, n); } else { // if (JCRConstants.NT_FOLDER.equals(primaryNodeType)) { doDefaultGet(request, response, n); } } catch (RepositoryException e) { throw new RestServiceFaultException(e.getLocalizedMessage(), e); } catch (JCRNodeFactoryServiceException e) { throw new RestServiceFaultException(e.getLocalizedMessage(), e); } catch (IOException e) { throw new RestServiceFaultException(e.getLocalizedMessage(), e); } }
From source file:org.jboss.dashboard.ui.controller.responses.SendStreamResponse.java
public boolean execute(CommandRequest cmdReq) throws Exception { if (log.isDebugEnabled()) log.debug("SendStreamResponse"); HttpServletResponse res = cmdReq.getResponseObject(); if (errorCode != 0) { res.sendError(errorCode);//from w w w. j av a2s. c o m return false; } if (resetHeaders) { //Remove everything, including headers. The stream is often a file that may be cached. res.reset(); } res.setHeader("Content-Encoding", HTTPSettings.lookup().getEncoding()); if (contentDisposition != null) { res.setHeader("Content-Disposition", contentDisposition); log.debug("Content-Disposition = " + contentDisposition); } if (contentType != null) { res.setContentType(contentType); } res.setHeader("Content-Transfer-Encoding", "binary"); if (contentLength < 0) contentLength = is.available(); if (contentLength > 0) { res.setContentLength(contentLength); log.debug("Content-Length = " + contentLength); } try { OutputStream os = new BufferedOutputStream(cmdReq.getResponseObject().getOutputStream()); IOUtils.copy(is, os); os.close(); is.close(); } catch (Exception e) { log.warn("Error sending Stream Response: " + e); //res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return false; } return true; }