List of usage examples for javax.servlet.http HttpServletResponse setHeader
public void setHeader(String name, String value);
From source file:net.sf.j2ep.responsehandlers.OptionsResponseHandler.java
/** * Will check if we are to handle this request, if so * the http methods allowed by this proxy is returned in the * Allow header./*w ww .java 2s .c o m*/ * If it is a request meant for the backing server its * allowed method will be returned. * * @see net.sf.j2ep.model.ResponseHandler#process(javax.servlet.http.HttpServletResponse) */ public void process(HttpServletResponse response) { if (useOwnAllow) { response.setStatus(HttpServletResponse.SC_OK); response.setHeader("allow", AllowedMethodHandler.getAllowHeader()); response.setHeader("Connection", "close"); response.setHeader("content-length", "0"); } else { setHeaders(response); response.setStatus(getStatusCode()); String allow = method.getResponseHeader("allow").getValue(); response.setHeader("allow", AllowedMethodHandler.processAllowHeader(allow)); Header contentLength = method.getResponseHeader("Content-Length"); if (contentLength == null || contentLength.getValue().equals("0")) { response.setHeader("Content-Length", "0"); } else { try { sendStreamToClient(response); } catch (IOException e) { log.error("Problem with writing response stream, solving by setting Content-Length=0", e); response.setHeader("Content-Length", "0"); } } } }
From source file:net.bafeimao.umbrella.web.controller.CaptchaController.java
@RequestMapping("") public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { response.setDateHeader("Expires", 0); // Set standard HTTP/1.1 no-cache headers. response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); // Set IE extended HTTP/1.1 no-cache headers (use addHeader). response.addHeader("Cache-Control", "post-check=0, pre-check=0"); // Set standard HTTP/1.0 no-cache header. response.setHeader("Pragma", "no-cache"); // return a jpeg response.setContentType("image/jpeg"); // create the text for the image String capText = captchaProducer.createText(); // store the text in the session request.getSession().setAttribute(Constants.KAPTCHA_SESSION_KEY, capText); // create the image with the text BufferedImage bi = captchaProducer.createImage(capText); ServletOutputStream out = response.getOutputStream(); // write the data out ImageIO.write(bi, "jpg", out); try {/*from ww w.j a va 2s . co m*/ out.flush(); } finally { out.close(); } return null; }
From source file:com.google.code.pathlet.web.json.JsonResponseProcessor.java
public boolean processResult(Path requestPath, Object returnResult, HttpServletResponse response) throws JsonResourceIOException { response.setContentType("text/plain"); response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache, must-revalidate"); try {//from w w w. j a v a 2 s.c o m if (returnResult != null) { if (String.class.isAssignableFrom(returnResult.getClass())) { //If returnResult is String, it will not convert into JSON, but directly write into response writer. response.getWriter().write((String) returnResult); } else { writeResult(response.getWriter(), returnResult); } } response.flushBuffer(); } catch (Exception e) { throw new JsonResourceIOException(e); } return false; }
From source file:com.controlj.green.istat.web.BookmarkServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //System.out.println("Area Servlet called at:"+new Date()); resp.setHeader("Expires", "Wed, 01 Jan 2003 12:00:00 GMT"); resp.setHeader("Cache-Control", "no-cache"); ServletOutputStream out = resp.getOutputStream(); try {//from ww w . j a v a 2 s . co m writeLocations(out, req.getParameterValues("bookmarks"), req); } catch (Exception e) { Logging.LOGGER.println("Unexpected exception:"); e.printStackTrace(Logging.LOGGER); throw new ServletException(e); } /* out.println("["); out.println("{ display:'Main Conf Room', id:'mainconf'},"); out.println("{ display:'Board Room', id:'boardroom'},"); out.println("{ display:'Room 235', id:'room235'}"); out.println("]"); */ }
From source file:info.toegepaste.www.service.PdfServiceImpl.java
@Override public void exportPdf(File temp) throws FileNotFoundException, IOException { FacesContext fc = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse(); response.setHeader("Content-Disposition", "attachment; filename=rapport.pdf"); response.setContentLength((int) temp.length()); ServletOutputStream out = null;/*from w w w . j a v a2 s . c om*/ FileInputStream input = new FileInputStream(temp); byte[] buffer = new byte[1024]; out = response.getOutputStream(); int i = 0; while ((i = input.read(buffer)) != -1) { out.write(buffer); out.flush(); } fc.responseComplete(); }
From source file:org.openmrs.module.clinicalsummary.web.controller.printer.PrintSummariesController.java
/** * Attach the file to the servlet response body * * @param response// ww w . j a v a 2s. c om * the response * @param file * the file * * @throws Exception */ private void attachAndPurgeFile(HttpServletResponse response, File file) throws Exception { response.setHeader("Content-Disposition", "attachment; filename=" + file.getName()); response.setContentType(MimeConstants.MIME_PDF); response.setContentLength((int) file.length()); FileCopyUtils.copy(new FileInputStream(file), response.getOutputStream()); if (!file.delete()) { log.info("Deleting temporary file failed!"); } }
From source file:net.webpasswordsafe.server.report.JasperReportServlet.java
private void setNoCache(HttpServletResponse res) { res.setHeader("Pragma", "no-cache"); res.setHeader("Cache-Control", "no-cache,no-store"); res.setDateHeader("Expires", 0); }
From source file:controllers.FeatureController.java
@RequestMapping("/getXls") public void getXls(Map<String, Object> model, HttpServletResponse response) throws Exception { response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment; filename=Feature.xls"); featureService.getXls().write(response.getOutputStream()); }
From source file:io.onedecision.engine.decisions.impl.LocationHeaderInterceptor.java
@Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { System.out.println("---Request Completed---"); if (response.getStatus() == HttpStatus.CREATED.value()) { response.setHeader("Location", String.format("%1$s", request.getRequestURL())); }//w w w. ja v a2 s .co m }
From source file:APIRequest.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //2. Merchant server makes an api request to the snap backend to get the SNAP_TOKEN //initialize settings. response.setHeader("Accept", "application/json"); response.setContentType("application/json"); response.setHeader("Authorization", Base64.getEncoder().encodeToString((serverKey + ":").getBytes())); String orderID = request.getParameterValues("gross_amount")[0]; int grossAmount = Integer.parseInt(request.getParameterValues("gross_amount")[0]); //dummy data/*from w ww . ja v a 2 s . c o m*/ orderID = "Testing Order-01"; grossAmount = 150000; //JSON object JSONObject jso = new JSONObject(); JSONObject transactionDetails = new JSONObject(); try { transactionDetails.put("order_id", orderID); transactionDetails.put("gross_amount", grossAmount); jso.put("transaction_details", transactionDetails); } catch (JSONException ex) { Logger.getLogger(APIRequest.class.getName()).log(Level.SEVERE, null, ex); } // send the jso to the server. response.getWriter().write(jso.toString()); //3. Snap backend responds to the api call with the SNAP_TOKEN }