List of usage examples for javax.servlet.http HttpServletRequest getHeaderNames
public Enumeration<String> getHeaderNames();
From source file:com.mockey.model.RequestFromClient.java
@SuppressWarnings("unchecked") private void parseRequestHeaders(HttpServletRequest rawRequest) { // Put header information coming from client. Enumeration<String> e = rawRequest.getHeaderNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); // Let's ignore some headers if (this.shouldIncludeHeader(name)) { List<String> values = new ArrayList<String>(); Enumeration eValues = rawRequest.getHeaders(name); while (eValues.hasMoreElements()) { String value = (String) eValues.nextElement(); values.add(value);/*from ww w . j a v a 2 s. c o m*/ } headers.put(name, values); } } // Override header information to prevent CACHING // As of 4/29/2011, updated Apache HttpClient. Result was the // following: // Testing with MAMP (Apache 2.0.63), I was seeing // this parameter being sent by Browsers Firefox 4 and // and Chrome 9, but NOT Safari 5. // To prevent caching, removing this attribute. e = rawRequest.getHeaderNames(); List<String> p = new ArrayList<String>(); p.add("Fri, 13 May 2006 23:54:18 GMT"); while (e.hasMoreElements()) { String name = (String) e.nextElement(); if ("if-none-match".equalsIgnoreCase(name)) { headers.remove(name); } else if ("If-modified-Since".equalsIgnoreCase(name)) { headers.put(name, p); } } }
From source file:com.adito.vfs.webdav.DAVServlet.java
private void debugRequest(HttpServletRequest req) { if (SystemProperties.get("adito.webdav.debug", "false").equalsIgnoreCase("true")) { for (Enumeration e = req.getHeaderNames(); e.hasMoreElements();) { String header = (String) e.nextElement(); for (Enumeration e2 = req.getHeaders(header); e2.hasMoreElements();) { log.info(header + ": " + (String) e2.nextElement()); }/*from w w w. j av a 2s. c om*/ } } if (log.isDebugEnabled()) log.debug("Processing " + req.getMethod() + " " + req.getPathInfo()); }
From source file:com.sslexplorer.vfs.webdav.DAVServlet.java
private void debugRequest(HttpServletRequest req) { if (SystemProperties.get("sslexplorer.webdav.debug", "false").equalsIgnoreCase("true")) { for (Enumeration e = req.getHeaderNames(); e.hasMoreElements();) { String header = (String) e.nextElement(); for (Enumeration e2 = req.getHeaders(header); e2.hasMoreElements();) { log.info(header + ": " + (String) e2.nextElement()); }/* w w w .ja v a2 s .c om*/ } } if (log.isDebugEnabled()) log.debug("Processing " + req.getMethod() + " " + req.getPathInfo()); }
From source file:org.apache.servicemix.http.processors.ProviderProcessor.java
protected Map<String, String> getHeaders(HttpServletRequest request) { Map<String, String> headers = new HashMap<String, String>(); Enumeration<?> enumeration = request.getHeaderNames(); while (enumeration.hasMoreElements()) { String name = (String) enumeration.nextElement(); String value = request.getHeader(name); headers.put(name, value);/*from w w w . j a v a 2 s. com*/ } return headers; }
From source file:org.apache.maven.plugins.site.deploy.SimpleDavServerHandler.java
public SimpleDavServerHandler(final File targetPath) throws Exception { this.siteTargetPath = targetPath; Handler repoHandler = new AbstractHandler() { public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException { String targetPath = request.getPathInfo(); HttpRequest rq = new HttpRequest(); rq.method = request.getMethod(); rq.path = targetPath;/*from w ww . j a v a 2s. com*/ @SuppressWarnings("rawtypes") Enumeration headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String name = (String) headerNames.nextElement(); rq.headers.put(name, request.getHeader(name)); } httpRequests.add(rq); if (request.getMethod().equalsIgnoreCase("PUT")) { File targetFile = new File(siteTargetPath, targetPath); log.info("writing file " + targetFile.getPath()); FileUtils.writeByteArrayToFile(targetFile, IOUtils.toByteArray(request.getInputStream())); } //PrintWriter writer = response.getWriter(); response.setStatus(HttpServletResponse.SC_OK); ((Request) request).setHandled(true); } }; server = new Server(0); server.setHandler(repoHandler); server.start(); }
From source file:com.reachcall.pretty.http.ProxyServlet.java
@SuppressWarnings("unchecked") public void copyHeaders(HttpServletRequest req, HttpRequestBase method) { Enumeration names = req.getHeaderNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); if (name.equalsIgnoreCase(HEADER_CONTENT_LENTH)) { continue; }// ww w . jav a2 s .c o m Enumeration values = req.getHeaders(name); while (values.hasMoreElements()) { String value = (String) values.nextElement(); LOG.log(Level.FINER, "{0} : {1}", new Object[] { name, value }); if (name.equalsIgnoreCase(HEADER_HOST) || name.equalsIgnoreCase(HEADER_X_FORWARDED_FOR)) { continue; } else { method.addHeader(name, value); } } setVHost(req.getHeader("Host")); } method.addHeader(HEADER_REMOTE_HOST, req.getRemoteAddr()); String xff = req.getHeader(HEADER_X_FORWARDED_FOR); if (xff == null) { xff = ""; } else { xff = xff + ", "; } method.addHeader(HEADER_X_FORWARDED_FOR, xff + req.getRemoteHost()); if (req.getHeader(HEADER_X_ORIGINAL_REQUEST_URL) == null) { method.addHeader(HEADER_X_ORIGINAL_REQUEST_URL, req.getRequestURL().toString()); } }
From source file:fr.paris.lutece.plugins.mylutece.modules.openam.service.OpenamService.java
private Map<String, String> getUserInformationInHeaderRequest(HttpServletRequest request) { Map<String, String> userInformations = new HashMap<String, String>(); Enumeration headerNames = request.getHeaderNames(); String strKey;/*w w w . j av a 2 s. c o m*/ while (headerNames.hasMoreElements()) { strKey = (String) headerNames.nextElement(); if (ATTRIBUTE_USER_MAPPING.containsKey(strKey) || ATTRIBUTE_USER_KEY_NAME.equals(strKey)) { userInformations.put(strKey, request.getHeader(strKey)); } } if (OpenamAPI._bDebug) { headerNames = request.getHeaderNames(); OpenamAPI._logger.debug("Openam Headers Informations"); while (headerNames.hasMoreElements()) { strKey = (String) headerNames.nextElement(); OpenamAPI._logger.debug(strKey + "=" + request.getHeader(strKey)); } } return userInformations; }
From source file:mobi.jenkinsci.ci.client.JenkinsClient.java
private HashMap<String, String> getHeaders(final HttpServletRequest req) { final HashMap<String, String> propagatedHeader = new HashMap<String, String>(); if (req != null) { final Enumeration<String> headerNames = req.getHeaderNames(); while (headerNames.hasMoreElements()) { final String headerName = headerNames.nextElement(); if (PROPAGATED_HEADERS_WHITELIST.contains(headerName.toLowerCase())) { propagatedHeader.put(headerName, req.getHeader(headerName)); }//from ww w .j a v a 2 s. co m } } return propagatedHeader; }
From source file:org.jahia.bin.errors.ErrorLoggingFilter.java
/** * Returns the request information for logging purposes. * * @param request the http request object * @return the request information for logging purposes *///from w w w . jav a2 s. c o m private static String getRequestInfo(HttpServletRequest request) { StringBuilder info = new StringBuilder(512); if (request != null) { String uri = (String) request.getAttribute("javax.servlet.error.request_uri"); String queryString = (String) request.getAttribute("javax.servlet.forward.query_string"); if (StringUtils.isNotEmpty(queryString)) { uri = uri + "?" + queryString; } info.append("Request information:").append("\nURL: ").append(uri).append("\nMethod: ") .append(request.getMethod()).append("\nProtocol: ").append(request.getProtocol()) .append("\nRemote host: ").append(request.getRemoteHost()).append("\nRemote address: ") .append(request.getRemoteAddr()).append("\nRemote port: ").append(request.getRemotePort()) .append("\nRemote user: ").append(request.getRemoteUser()).append("\nSession ID: ") .append(request.getRequestedSessionId()).append("\nSession user: ").append(getUserInfo(request)) .append("\nRequest headers: "); @SuppressWarnings("unchecked") Iterator<String> headerNames = new EnumerationIterator(request.getHeaderNames()); while (headerNames.hasNext()) { String headerName = headerNames.next(); String headerValue = request.getHeader(headerName); info.append("\n ").append(headerName).append(": ").append(headerValue); } } return info.toString(); }
From source file:com.cloudbees.tomcat.valves.PrivateAppValveIntegratedTest.java
@Before @Override/*from w w w . j a v a 2 s . c om*/ public void setUp() throws Exception { super.setUp(); Tomcat tomcat = getTomcatInstance(); // Must have a real docBase - just use temp org.apache.catalina.Context context = tomcat.addContext("", System.getProperty("java.io.tmpdir")); Tomcat.addServlet(context, "hello-servlet", new HttpServlet() { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println(req.getRequestURL()); IoUtils2.flush(req.getInputStream(), System.out); Enumeration<String> headers = req.getHeaderNames(); while (headers.hasMoreElements()) { String header = headers.nextElement(); System.out.println(" " + header + ": " + req.getHeader(header)); } resp.addHeader("x-response", "hello"); resp.getWriter().println("Hello world!"); } }); context.addServletMapping("/*", "hello-servlet"); privateAppValve = new PrivateAppValve(); privateAppValve.setSecretKey(secretKey); context.getPipeline().addValve(privateAppValve); tomcat.start(); httpClient = new DefaultHttpClient(); httpHost = new HttpHost("localhost", getPort()); }