List of usage examples for javax.servlet.http HttpServletResponse addHeader
public void addHeader(String name, String value);
From source file:fr.univlille2.ecm.drive.BasicDriveAuthenticator.java
public Boolean handleLoginPrompt(HttpServletRequest httpRequest, HttpServletResponse httpResponse, String baseURL) {// ww w . j a v a 2 s.c o m logger.debug(BasicDriveAuthenticator.class.getSimpleName() + " : handleLoginPrompt"); try { String baHeader = "Basic realm=\"" + realmName + '\"'; httpResponse.addHeader(BA_HEADER_NAME, baHeader); httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED); return true; } catch (IOException e) { return false; } }
From source file:com.hyeb.back.controller.CommonController.java
/** * ??/* www. j a v a2s . c o m*/ */ @RequestMapping(value = "/captcha", method = RequestMethod.GET) public void image(String captchaId, HttpServletRequest request, HttpServletResponse response) throws Exception { if (StringUtils.isEmpty(captchaId)) { captchaId = request.getSession().getId(); } String pragma = new StringBuffer().append("PowderBy").toString(); String value = new StringBuffer().append("hyeb").toString(); response.addHeader(pragma, value); response.setHeader("Pragma", "no-cache");//HTTP1.0Pragma ??Pragmano-cache,??????? Pragma response.setHeader("Cache-Control", "no-cache");// HTTP1.1?Cache-Control ???,no-cache????? response.setHeader("Cache-Control", "no-store");//HTTP1.1?Cache-Control ???no-store???? response.setDateHeader("Expires", 0);//Expires?GMT???????? response.setContentType("image/jpeg"); ServletOutputStream servletOutputStream = null; try { servletOutputStream = response.getOutputStream(); BufferedImage bufferedImage = captchaService.buildImage(captchaId); ImageIO.write(bufferedImage, "jpg", servletOutputStream); servletOutputStream.flush(); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(servletOutputStream); } }
From source file:de.bermuda.arquillian.example.ContentTypeProxyServlet.java
private void migrateResponseHeader(HttpServletResponse resp, HttpMethod post) { for (Header header : post.getResponseHeaders()) { if (!(header.getName().equalsIgnoreCase("Content-Type")) && !(header.getName().equalsIgnoreCase("Transfer-Encoding"))) { resp.addHeader(header.getName(), header.getValue()); log.info("Copying response header: " + header.getName() + ": " + header.getValue()); }//from ww w . j a v a 2 s. c o m } resp.setContentType("application/soap+xml"); }
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 w ww. ja va 2 s . co m*/ out.flush(); } finally { out.close(); } return null; }
From source file:net.mindengine.oculus.frontend.web.controllers.api.ApiController.java
@Override public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, Object> model = new HashMap<String, Object>(); response.addHeader("Content-Type", "application/json"); if (userIsAuthorized(request)) { MatchedMethod matchedMethod = findMatchedMethod(request); Object[] arguments = createMethodArguments(matchedMethod, request, response); try {//w w w. jav a 2 s . c o m Object result = matchedMethod.getMethod().invoke(this, arguments); if (matchedMethod.getMethod().getReturnType().equals(Void.TYPE)) { return null; } else model.put("response", result); } catch (InvocationTargetException e) { response.setStatus(400); model.put("response", new ApiError( e.getTargetException().getClass().getName() + ": " + e.getTargetException().getMessage())); e.getTargetException().printStackTrace(); } } else { response.setStatus(401); model.put("response", new ApiError("You are not authorized for this request.")); } return new ModelAndView("jsonView", model); }
From source file:org.ihtsdo.otf.refset.interceptor.RequestProcessingTimeInterceptor.java
@Override public void postHandle(HttpServletRequest req, HttpServletResponse res, Object arg2, ModelAndView model) throws Exception { if (isEnabled) { String tTime = Long.toString((System.currentTimeMillis() - (Long) req.getAttribute(START_TIME)) / 1000); LOGGER.debug("Total time taken in this request is {}", tTime); res.addHeader(TOTAL_TIME, tTime); }//from w w w. j a v a 2s. c om }
From source file:io.neba.core.resourcemodels.metadata.ModelStatisticsConsolePlugin.java
private void setNoCacheHeaders(HttpServletResponse res) { res.setHeader("Expires", "Sat, 6 May 1970 12:00:00 GMT"); res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); res.addHeader("Cache-Control", "post-check=0, pre-check=0"); res.setHeader("Pragma", "no-cache"); }
From source file:com.cloudseal.spring.client.namespace.CloudSealLogoutImageFilter.java
protected void preventCaching(HttpServletResponse response) { Date now = new Date(); response.setHeader("Pragma", "no-cache"); response.setDateHeader("Date", now.getTime()); response.setDateHeader("Expires", now.getTime() - 86400000L); // one day old response.setHeader("Cache-Control", "no-cache"); response.addHeader("Cache-Control", "no-store"); response.addHeader("Cache-Control", "must-revalidate"); }
From source file:net.jadler.stubbing.server.jetty.StubHandler.java
private void setResponseHeaders(final MultiMap headers, final HttpServletResponse response) { for (@SuppressWarnings("unchecked") final Iterator<Entry<String, Collection<String>>> it = headers.entrySet().iterator(); it.hasNext();) { final Entry<String, Collection<String>> e = it.next(); for (final String value : e.getValue()) { response.addHeader(e.getKey(), value); }/*from ww w. j a v a2s. com*/ } }
From source file:net.sourceforge.fenixedu.presentationTier.Action.commons.student.ViewStudentApplicationDA.java
public ActionForward downloadDocument(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws IOException { final IndividualCandidacyDocumentFile document = getDomainObject(request, "documentOID"); if (document != null && isAuthorized(document)) { response.setContentType(document.getContentType()); response.addHeader("Content-Disposition", "attachment; filename=\"" + document.getFilename() + "\""); response.setContentLength(document.getSize().intValue()); final DataOutputStream dos = new DataOutputStream(response.getOutputStream()); dos.write(document.getContent()); dos.close();/* w ww .j av a 2s .c o m*/ } else { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().write(HttpStatus.getStatusText(HttpStatus.SC_BAD_REQUEST)); response.getWriter().close(); } return null; }