List of usage examples for javax.servlet.http HttpServletResponse addHeader
public void addHeader(String name, String value);
From source file:psiprobe.controllers.RememberVisibilityController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { String cookieName = ServletRequestUtils.getStringParameter(request, "cn"); String state = ServletRequestUtils.getStringParameter(request, "state"); if (cookieName != null && state != null) { cookieName = Functions.safeCookieName(cookieName); // expire the cookis at the current date + 10years (roughly, nevermind leap years) response.addHeader("Set-Cookie", cookieName + "=" + state + "; Expires=" + sdf.format(new Date(System.currentTimeMillis() + 315360000000L))); }/*from w w w. ja v a 2 s . com*/ return null; }
From source file:mx.gob.cfe.documentos.web.CircularController.java
private void generaReporte(String tipo, List<Documento> documentos, HttpServletResponse response) throws JRException, IOException { log.debug("Generando reporte {}", tipo); byte[] archivo = null; switch (tipo) { case "PDF": archivo = generaPdf(documentos); response.setContentType("application/pdf"); response.addHeader("Content-Disposition", "attachment; filename=circular.pdf"); break;//from w w w . j a v a 2 s . co m } if (archivo != null) { response.setContentLength(archivo.length); try (BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream())) { bos.write(archivo); bos.flush(); } } }
From source file:mx.gob.cfe.documentos.web.MemoController.java
private void generaReporte(String tipo, List<Documento> documentos, HttpServletResponse response) throws JRException, IOException { log.debug("Generando reporte {}", tipo); byte[] archivo = null; switch (tipo) { case "PDF": archivo = generaPdf(documentos); response.setContentType("application/pdf"); response.addHeader("Content-Disposition", "attachment; filename=memo.pdf"); break;/* w w w . jav a 2 s .co m*/ } if (archivo != null) { response.setContentLength(archivo.length); try (BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream())) { bos.write(archivo); bos.flush(); } } }
From source file:mx.gob.cfe.documentos.web.MemoInterController.java
private void generaReporte(String tipo, List<Documento> documentos, HttpServletResponse response) throws JRException, IOException { log.debug("Generando reporte {}", tipo); byte[] archivo = null; switch (tipo) { case "PDF": archivo = generaPdf(documentos); response.setContentType("application/pdf"); response.addHeader("Content-Disposition", "attachment; filename=memoInter.pdf"); break;/* w w w .j a v a 2 s. c o m*/ } if (archivo != null) { response.setContentLength(archivo.length); try (BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream())) { bos.write(archivo); bos.flush(); } } }
From source file:net.sourceforge.vulcan.web.ContentTypeFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { final String contentType = detectContentType(request); final HttpServletResponseContentTypeWrapper responseWrapper = new HttpServletResponseContentTypeWrapper( request, response, suppressContentTypes, contentType); response.addHeader("Cache-Control", "max-age=0"); chain.doFilter(request, responseWrapper); }
From source file:com.eviware.soapui.impl.wsdl.monitor.jettyproxy.TunnelServlet.java
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { monitor.fireOnRequest(request, response); if (response.isCommitted()) return;/*w ww. j a v a 2 s .com*/ ExtendedHttpMethod postMethod; // for this create ui server and port, properties. InetSocketAddress inetAddress = new InetSocketAddress(sslEndPoint, sslPort); HttpServletRequest httpRequest = (HttpServletRequest) request; if (httpRequest.getMethod().equals("GET")) postMethod = new ExtendedGetMethod(); else postMethod = new ExtendedPostMethod(); JProxyServletWsdlMonitorMessageExchange capturedData = new JProxyServletWsdlMonitorMessageExchange(project); capturedData.setRequestHost(httpRequest.getRemoteHost()); capturedData.setRequestHeader(httpRequest); capturedData.setTargetURL(this.prot + inetAddress.getHostName()); CaptureInputStream capture = new CaptureInputStream(httpRequest.getInputStream()); // copy headers Enumeration<?> headerNames = httpRequest.getHeaderNames(); while (headerNames.hasMoreElements()) { String hdr = (String) headerNames.nextElement(); String lhdr = hdr.toLowerCase(); if ("host".equals(lhdr)) { Enumeration<?> vals = httpRequest.getHeaders(hdr); while (vals.hasMoreElements()) { String val = (String) vals.nextElement(); if (val.startsWith("127.0.0.1")) { postMethod.addRequestHeader(hdr, sslEndPoint); } } continue; } Enumeration<?> vals = httpRequest.getHeaders(hdr); while (vals.hasMoreElements()) { String val = (String) vals.nextElement(); if (val != null) { postMethod.addRequestHeader(hdr, val); } } } if (postMethod instanceof ExtendedPostMethod) ((ExtendedPostMethod) postMethod) .setRequestEntity(new InputStreamRequestEntity(capture, request.getContentType())); HostConfiguration hostConfiguration = new HostConfiguration(); httpRequest.getProtocol(); hostConfiguration.getParams().setParameter(SoapUIHostConfiguration.SOAPUI_SSL_CONFIG, settings.getString(SecurityTabForm.SSLTUNNEL_KEYSTOREPATH, "") + " " + settings.getString(SecurityTabForm.SSLTUNNEL_KEYSTOREPASSWORD, "")); hostConfiguration.setHost(new URI(this.prot + sslEndPoint, true)); hostConfiguration = ProxyUtils.initProxySettings(settings, httpState, hostConfiguration, prot + sslEndPoint, new DefaultPropertyExpansionContext(project)); if (sslEndPoint.indexOf("/") < 0) postMethod.setPath("/"); else postMethod.setPath(sslEndPoint.substring(sslEndPoint.indexOf("/"), sslEndPoint.length())); monitor.fireBeforeProxy(request, response, postMethod, hostConfiguration); if (settings.getBoolean(LaunchForm.SSLTUNNEL_REUSESTATE)) { if (httpState == null) httpState = new HttpState(); HttpClientSupport.getHttpClient().executeMethod(hostConfiguration, postMethod, httpState); } else { HttpClientSupport.getHttpClient().executeMethod(hostConfiguration, postMethod); } capturedData.stopCapture(); capturedData.setRequest(capture.getCapturedData()); capturedData.setRawResponseBody(postMethod.getResponseBody()); capturedData.setResponseHeader(postMethod); capturedData.setRawRequestData(getRequestToBytes(request.toString(), postMethod, capture)); capturedData.setRawResponseData( getResponseToBytes(response.toString(), postMethod, capturedData.getRawResponseBody())); monitor.fireAfterProxy(request, response, postMethod, capturedData); StringToStringsMap responseHeaders = capturedData.getResponseHeaders(); // copy headers to response HttpServletResponse httpResponse = (HttpServletResponse) response; for (String name : responseHeaders.keySet()) { for (String header : responseHeaders.get(name)) httpResponse.addHeader(name, header); } IO.copy(new ByteArrayInputStream(capturedData.getRawResponseBody()), httpResponse.getOutputStream()); postMethod.releaseConnection(); synchronized (this) { monitor.addMessageExchange(capturedData); } capturedData = null; }
From source file:com.vmware.appfactory.common.base.AbstractController.java
/** * Set HTTP headers on an HTTP response to hopefully force browsers to * prevent the response being cached. Especially important for dynamic * content updates. We're talking to you, Internet Explorer. *///from w w w. j a v a2 s .c om protected void setNoCacheHeaders(HttpServletResponse response) { response.addHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); response.setDateHeader("Expires", 0); }
From source file:com.struts2ext.json.JSONUtil.java
public static void writeJSONToResponse(SerializationParams serializationParams) throws IOException { StringBuilder stringBuilder = new StringBuilder(); if (StringUtils.isNotBlank(serializationParams.getSerializedJSON())) stringBuilder.append(serializationParams.getSerializedJSON()); if (StringUtils.isNotBlank(serializationParams.getWrapPrefix())) stringBuilder.insert(0, serializationParams.getWrapPrefix()); else if (serializationParams.isWrapWithComments()) { stringBuilder.insert(0, "/* "); stringBuilder.append(" */"); } else if (serializationParams.isPrefix()) stringBuilder.insert(0, "{}&& "); if (StringUtils.isNotBlank(serializationParams.getWrapSuffix())) stringBuilder.append(serializationParams.getWrapSuffix()); String json = stringBuilder.toString(); if (LOG.isDebugEnabled()) { LOG.debug("[JSON]" + json); }/* w w w .j ava 2 s .c om*/ HttpServletResponse response = serializationParams.getResponse(); // status or error code if (serializationParams.getStatusCode() > 0) response.setStatus(serializationParams.getStatusCode()); else if (serializationParams.getErrorCode() > 0) response.sendError(serializationParams.getErrorCode()); // content type if (serializationParams.isSmd()) response.setContentType("application/json-rpc;charset=" + serializationParams.getEncoding()); else response.setContentType( serializationParams.getContentType() + ";charset=" + serializationParams.getEncoding()); if (serializationParams.isNoCache()) { response.setHeader("Cache-Control", "no-cache"); response.setHeader("Expires", "0"); response.setHeader("Pragma", "No-cache"); } if (serializationParams.isGzip()) { response.addHeader("Content-Encoding", "gzip"); GZIPOutputStream out = null; InputStream in = null; try { out = new GZIPOutputStream(response.getOutputStream()); in = new ByteArrayInputStream(json.getBytes(serializationParams.getEncoding())); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } finally { if (in != null) in.close(); if (out != null) { out.finish(); out.close(); } } } else { response.setContentLength(json.getBytes(serializationParams.getEncoding()).length); PrintWriter out = response.getWriter(); out.print(json); } }
From source file:ru.org.linux.auth.SecurityFilter.java
private void CSRFManipulation(HttpServletRequest request, HttpServletResponse response) { Properties cookies = LorHttpUtils.getCookies(request.getCookies()); if (cookies.get(CSRFProtectionService.CSRF_COOKIE) == null) { CSRFProtectionService.generateCSRFCookie(request, response); } else {// www . jav a 2 s .c o m request.setAttribute(CSRFProtectionService.CSRF_ATTRIBUTE, cookies.getProperty(CSRFProtectionService.CSRF_COOKIE).trim()); } response.addHeader("Cache-Control", "private"); }
From source file:server.UpgradeController.java
@RequestMapping("/getupgradefile") public String getUpgradeFile(@RequestParam(value = "licensekey") String licensekey, @RequestParam(value = "url") String url, @RequestParam(value = "version") String version, HttpServletResponse response) { try {/*w ww . j a v a 2 s .c o m*/ License license = new License(counter.incrementAndGet(), licensekey, url, version, new java.sql.Date(Calendar.getInstance().getTime().getTime())); if (license.isCurrent() && license.isValid()) { // get your file as InputStream InputStream is = new FileInputStream(new File("upgrades/latest.zip")); response.addHeader("Content-disposition", "attachment;filename=latest.zip"); response.setContentType("txt/plain"); IOUtils.copy(is, response.getOutputStream()); response.flushBuffer(); return "License successfully validated."; } else { return "License validation unsuccessful. Unable to download upgrade files"; } } catch (Exception e) { System.out.println(e); return "License validation unsuccessful. Unable to download upgrade files"; } }