List of usage examples for javax.servlet.http HttpServletResponse containsHeader
public boolean containsHeader(String name);
From source file:org.artifactory.webapp.servlet.ArtifactoryFilter.java
@Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { // Redirect or forward if need for (RedirectionHandler redirectionHandler : redirectionHandlers) { if (redirectionHandler.shouldRedirect(request)) { redirectionHandler.redirect(request, response); return; }//from www. j a v a 2 s .c o m } if (filterConfig.getServletContext().getAttribute(DelayedInit.APPLICATION_CONTEXT_LOCK_KEY) != null) { String requestURI = ((HttpServletRequest) request).getRequestURI(); if (requestURI.endsWith("artifactory-splash.gif")) { ((HttpServletResponse) response).setStatus(200); ServletOutputStream out = response.getOutputStream(); ResourceUtils.copyResource("/artifactory-splash.gif", out, null, getClass()); return; } response.setContentType("text/html"); ((HttpServletResponse) response).setStatus(HttpStatus.SC_SERVICE_UNAVAILABLE); ServletOutputStream out = response.getOutputStream(); ResourceUtils.copyResource("/startup.html", out, null, getClass()); return; } try { ServletContext servletContext = filterConfig.getServletContext(); ArtifactoryContext context = RequestUtils.getArtifactoryContext(servletContext); if (context == null) { respondFailedToInitialize(response); return; } bind(context); if (response instanceof HttpServletResponse) { HttpServletResponse httpResponse = (HttpServletResponse) response; if (!httpResponse.containsHeader("Server")) { //Add the server header (curl -I http://localhost:8080/artifactory/) httpResponse.setHeader("Server", HttpUtils.getArtifactoryUserAgent()); } // set the Artifactory instance id header String hostId = ContextHelper.get().beanForType(AddonsManager.class) .addonByType(HaCommonAddon.class).getHostId(); httpResponse.setHeader(ArtifactoryResponse.ARTIFACTORY_ID, hostId); String serverId = ContextHelper.get().getServerId(); if (StringUtils.isNotBlank(serverId) && !HaCommonAddon.ARTIFACTORY_PRO.equals(serverId)) { httpResponse.setHeader(HaCommonAddon.ARTIFACTORY_NODE_ID, serverId); } } chain.doFilter(request, response); } finally { unbind(); } }
From source file:org.springframework.security.web.header.writers.HstsHeaderWriter.java
public void writeHeaders(HttpServletRequest request, HttpServletResponse response) { if (this.requestMatcher.matches(request)) { if (!response.containsHeader(HSTS_HEADER_NAME)) { response.setHeader(HSTS_HEADER_NAME, this.hstsHeaderValue); }/*from w w w . j a va 2s .co m*/ } else if (this.logger.isDebugEnabled()) { this.logger.debug( "Not injecting HSTS header since it did not match the requestMatcher " + this.requestMatcher); } }
From source file:org.nuxeo.ecm.platform.ui.web.auth.cas2.SecurityExceptionHandler.java
@Override public void handleException(HttpServletRequest request, HttpServletResponse response, Throwable t) throws IOException, ServletException { Throwable unwrappedException = unwrapException(t); if (!ExceptionHelper.isSecurityError(unwrappedException) && !response.containsHeader(SSO_INITIAL_URL_REQUEST_KEY)) { super.handleException(request, response, t); return;/*from www . ja v a2 s . co m*/ } Principal principal = request.getUserPrincipal(); NuxeoPrincipal nuxeoPrincipal = null; if (principal instanceof NuxeoPrincipal) { nuxeoPrincipal = (NuxeoPrincipal) principal; // redirect to login than to requested page if (nuxeoPrincipal.isAnonymous()) { response.resetBuffer(); String urlToReach = getURLToReach(request); Cookie cookieUrlToReach = new Cookie(NXAuthConstants.SSO_INITIAL_URL_REQUEST_KEY, urlToReach); cookieUrlToReach.setPath("/"); cookieUrlToReach.setMaxAge(60); response.addCookie(cookieUrlToReach); if (!response.isCommitted()) { request.getRequestDispatcher(CAS_REDIRECTION_URL).forward(request, response); } FacesContext.getCurrentInstance().responseComplete(); } } // go back to default handler super.handleException(request, response, t); }
From source file:eu.eidas.node.AbstractSpecificServlet.java
/** * Sets HTTPOnly Header to prevent cookies from being accessed through * client-side script./*from w w w . j a v a 2 s . co m*/ */ protected final void setHTTPOnlyHeader(HttpServletRequest request, HttpServletResponse response) { if (request.getSession() == null || request.getSession(false) == null) { // If the session doesn't exist, then we must create it. request.getSession(); // We will set the value only if we didn't set it already. if (!response.containsHeader(EIDASValues.SETCOOKIE.toString())) { response.setHeader(EIDASValues.SETCOOKIE.toString(), createHttpOnlyCookie(request)); } } }
From source file:fr.univlille2.ecm.platform.ui.web.auth.cas2.SecurityExceptionHandler.java
@Override public void handleException(HttpServletRequest request, HttpServletResponse response, Throwable t) throws IOException, ServletException { @SuppressWarnings("deprecation") Throwable unwrappedException = unwrapException(t); log.debug("handleException#in"); if (!ExceptionHelper.isSecurityError(unwrappedException) && !response.containsHeader(SSO_INITIAL_URL_REQUEST_KEY)) { super.handleException(request, response, t); return;//w w w .ja v a2 s. c o m } Principal principal = request.getUserPrincipal(); NuxeoPrincipal nuxeoPrincipal = null; if (principal instanceof NuxeoPrincipal) { nuxeoPrincipal = (NuxeoPrincipal) principal; // redirect to login than to requested page if (nuxeoPrincipal.isAnonymous()) { response.resetBuffer(); String urlToReach = getURLToReach(request); log.debug(String.format("handleException#urlToReach#%s", urlToReach)); Cookie cookieUrlToReach = new Cookie(NXAuthConstants.SSO_INITIAL_URL_REQUEST_KEY, urlToReach); cookieUrlToReach.setPath("/"); cookieUrlToReach.setMaxAge(60); response.addCookie(cookieUrlToReach); log.debug(String.format("handleException#cookieUrlToReach#%s", cookieUrlToReach.getName())); if (!response.isCommitted()) { request.getRequestDispatcher(CAS_REDIRECTION_URL).forward(request, response); } FacesContext.getCurrentInstance().responseComplete(); } } // go back to default handler super.handleException(request, response, t); }
From source file:wicket.protocol.http.WicketFilter.java
/** * If the response has not already a 'lastModified' header set and if * 'lastModified' >= 0 than set the response header accordingly. * /*from w ww. j a v a 2s. co m*/ * @param resp * @param lastModified */ private void maybeSetLastModified(final HttpServletResponse resp, final long lastModified) { if (resp.containsHeader("Last-Modified")) { return; } if (lastModified >= 0) { resp.setDateHeader("Last-Modified", lastModified); } }
From source file:com.idega.core.cache.filter.Filter.java
/** * Adds the gzip HTTP header to the response. This is need when a gzipped body * is returned so that browsers can properly decompress it. * @throws ResponseHeadersNotModifiableException Either the response is committed or we were called using the include method * from a {@link javax.servlet.RequestDispatcher#include(javax.servlet.ServletRequest, javax.servlet.ServletResponse)} * method and the set set header is ignored. *//* ww w . j av a 2s. com*/ protected void addGzipHeader(final HttpServletResponse response) throws ResponseHeadersNotModifiableException { response.setHeader("Content-Encoding", "gzip"); boolean containsEncoding = response.containsHeader("Content-Encoding"); if (!containsEncoding) { throw new ResponseHeadersNotModifiableException( "Failure when attempting to set " + "Content-Encoding: gzip"); } }
From source file:org.ejbca.extra.ra.ScepRAServlet.java
/** Helper methods that removes no-cache headers from a response. No-cache headers * makes IE refuse to save a file that is sent (for example a certificate). * No-cache headers are also automatically added by Tomcat by default, so we better * make sure they are set to a harmless value. * /*from www. j av a2 s . c o m*/ * @param res HttpServletResponse parameter as taken from the doGet, doPost methods in a Servlet. */ private void removeCacheHeaders(HttpServletResponse res) { if (res.containsHeader("Pragma")) { log.debug("Removing Pragma header to avoid caching issues in IE"); res.setHeader("Pragma", "null"); } if (res.containsHeader("Cache-Control")) { log.debug("Removing Cache-Control header to avoid caching issues in IE"); res.setHeader("Cache-Control", "null"); } }
From source file:org.springframework.security.web.header.writers.HpkpHeaderWriter.java
public void writeHeaders(HttpServletRequest request, HttpServletResponse response) { if (requestMatcher.matches(request)) { if (!pins.isEmpty()) { String headerName = reportOnly ? HPKP_RO_HEADER_NAME : HPKP_HEADER_NAME; if (!response.containsHeader(headerName)) { response.setHeader(headerName, hpkpHeaderValue); }/* w w w . j a v a 2 s .co m*/ } if (logger.isDebugEnabled()) { logger.debug("Not injecting HPKP header since there aren't any pins"); } } else if (logger.isDebugEnabled()) { logger.debug("Not injecting HPKP header since it wasn't a secure connection"); } }
From source file:org.jahia.bin.errors.ErrorServlet.java
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { WebUtils.setNoCacheHeaders(response); // check if the Basic Authentication is required Integer errorCode = (Integer) request.getAttribute("javax.servlet.error.status_code"); if (errorCode == HttpServletResponse.SC_UNAUTHORIZED && getException(request) == null) { if (!response.containsHeader("WWW-Authenticate")) { response.setHeader("WWW-Authenticate", "BASIC realm=\"Secured Jahia tools\""); }//w w w . j a va 2s .c o m response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); } else { if (errorCode == HttpServletResponse.SC_SERVICE_UNAVAILABLE && StringUtils.equals( ErrorServlet.MAINTENANCE_MODE, (String) request.getAttribute("javax.servlet.error.message"))) { forwardToErrorPage("/errors/maintenance.jsp", request, response); } else if (errorCode == HttpServletResponse.SC_SERVICE_UNAVAILABLE && StringUtils.equals(ErrorServlet.LICENSE_TERMS_VIOLATION_MODE, (String) request.getAttribute("javax.servlet.error.message"))) { forwardToErrorPage("/errors/license.jsp", request, response); } else { // otherwise continue with processing of the error String method = request.getMethod(); if (method.equals("GET") || method.equals("POST")) { process(request, response); } else { response.sendError(errorCode != null ? errorCode.intValue() : HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } } }