List of usage examples for javax.servlet.http HttpServletRequest getHeaderNames
public Enumeration<String> getHeaderNames();
From source file:org.eclipse.swordfish.p2.internal.deploy.server.ProvisioningServlet.java
final String[] getIUList(HttpServletRequest request) throws ServletException { List<String> iuList = new ArrayList<String>(); for (Enumeration<String> en = request.getHeaderNames(); en.hasMoreElements();) { String pName = en.nextElement(); String value = request.getHeader(pName); if (pName.startsWith(PARAM_IU_ID) && !isEmpty(value)) { iuList.add(value);// w w w . jav a 2 s. co m } if (LOG.isDebugEnabled()) { LOG.debug("Header: " + pName + " = " + value); LOG.debug("List is now: " + list2String(iuList.toArray(new String[] {}))); } } if (iuList.size() == 0) { throw new ServletException("No IU entry (" + PARAM_IU_ID + "*) given."); } return iuList.toArray(new String[] {}); }
From source file:com.amazon.dtasdk.v2.signature.Request.java
/** * Creates a Request from an HttpServletRequest. Useful for verifying the signature of a request. * //w w w . j ava2 s . c o m * NOTE: This consumes the body of the request which can cause issues when you try and read it again. * * @param httpServletRequest * the HttpServletRequest to copy * @throws IOException * on invalid url or body copying */ public Request(HttpServletRequest httpServletRequest) throws IOException { url = getFullURL(httpServletRequest); method = Method.valueOf(httpServletRequest.getMethod()); Enumeration<String> headerNames = httpServletRequest.getHeaderNames(); while (headerNames.hasMoreElements()) { String name = headerNames.nextElement(); headers.put(name, httpServletRequest.getHeader(name)); } headers.put(CONTENT_TYPE_HEADER, httpServletRequest.getContentType()); body = IOUtils.toString(httpServletRequest.getInputStream()); }
From source file:org.nuxeo.ecm.platform.ui.web.auth.cleartrust.ClearTrustAuthenticator.java
protected void displayRequestInformation(HttpServletRequest request) { log.debug(">>>>>>>>>>>>> Here is the request: "); for (Enumeration headerNames = request.getHeaderNames(); headerNames.hasMoreElements();) { String headerName = (String) headerNames.nextElement(); log.debug("header " + headerName + " : [" + request.getHeader(headerName) + "]"); }/* www.j ava2 s .co m*/ for (Enumeration attributeNames = request.getAttributeNames(); attributeNames.hasMoreElements();) { String attributeName = (String) attributeNames.nextElement(); log.debug("attribute " + attributeName + " : [" + request.getAttribute(attributeName) + "]"); } for (Enumeration parameterNames = request.getParameterNames(); parameterNames.hasMoreElements();) { String parameterName = (String) parameterNames.nextElement(); log.debug("parameter " + parameterName + " : [" + request.getParameter(parameterName) + "]"); } }
From source file:edu.cornell.mannlib.vitro.webapp.controller.authenticate.LoginExternalAuthReturn.java
/** * <pre>//from w w w . j a v a 2s . c o m * Returning from the external authorization server. If we were successful, * the header will contain the name of the user who just logged in. * * Deal with these possibilities: * - The header name was not configured in runtime.properties. Complain. * - No username: the login failed. Complain * - User corresponds to a User acocunt. Record the login. * - User corresponds to an Individual (self-editor). * - User is not recognized. * * On entry, we expect to find: * - A LoginProcessBean, which will give us the afterLoginUrl if the login * succeeds. * - A referrer URL, to which we will redirect if the login fails. * TODO: is this equal to LoginProcessBean.getLoginPageUrl()? * These are removed on exit. * </pre> */ @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (log.isDebugEnabled()) { @SuppressWarnings("unchecked") Enumeration<String> names = req.getHeaderNames(); log.debug("------------request:" + req.getRequestURL()); while (names.hasMoreElements()) { String name = names.nextElement(); log.debug(name + "=" + req.getHeader(name)); } } String externalAuthId = ExternalAuthHelper.getHelper(req).getExternalAuthId(req); log.debug("externalAuthID='" + externalAuthId + "'"); if (externalAuthId == null) { complainAndReturnToReferrer(req, resp, ATTRIBUTE_REFERRER, messageLoginFailed(req)); return; } String afterLoginUrl = LoginProcessBean.getBean(req).getAfterLoginUrl(); removeLoginProcessArtifacts(req); UserAccount userAccount = getAuthenticator(req).getAccountForExternalAuth(externalAuthId); if (!getAuthenticator(req).isUserPermittedToLogin(userAccount)) { log.debug("Logins disabled for " + userAccount); complainAndReturnToReferrer(req, resp, ATTRIBUTE_REFERRER, messageLoginDisabled(req)); return; } if (userAccount == null) { log.debug("Creating new account for " + externalAuthId + ", return to '" + afterLoginUrl + "'"); UserAccountsFirstTimeExternalPage.setExternalLoginInfo(req, externalAuthId, afterLoginUrl); resp.sendRedirect(UrlBuilder.getUrl("/accounts/firstTimeExternal")); return; } try { log.debug("Logging in as " + userAccount.getUri()); getAuthenticator(req).recordLoginAgainstUserAccount(userAccount, AuthenticationSource.EXTERNAL); new LoginRedirector(req, afterLoginUrl).redirectLoggedInUser(resp); return; } catch (LoginNotPermitted e) { // should have been caught by isUserPermittedToLogin() log.debug("Logins disabled for " + userAccount); complainAndReturnToReferrer(req, resp, ATTRIBUTE_REFERRER, messageLoginDisabled(req)); return; } }
From source file:org.mule.transport.servlet.ServletMuleMessageFactory.java
protected void copyHeaders(HttpServletRequest request, Map<String, Object> messageProperties) { for (Enumeration<?> e = request.getHeaderNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); String realKey = key;//from w ww .jav a2s. c om if (key.startsWith(HttpConstants.X_PROPERTY_PREFIX)) { realKey = key.substring(2); } // Workaround for containers that strip the port from the Host header. // This is needed so Mule components can figure out what port they're on. if (HttpConstants.HEADER_HOST.equalsIgnoreCase(key)) { realKey = HttpConstants.HEADER_HOST; String value = request.getHeader(key); int port = request.getLocalPort(); if (!value.contains(":") && port != 80 && port != 443) { value = value + ":" + port; } messageProperties.put(realKey, value); } else { Enumeration<?> valueEnum = request.getHeaders(key); List<?> values = EnumerationUtils.toList(valueEnum); if (values.size() > 1) { messageProperties.put(realKey, values.toArray()); } else { messageProperties.put(realKey, values.get(0)); } } } }
From source file:org.kuali.coeus.sys.framework.controller.interceptor.RequestLoggingFilter.java
/** * Constructs a log message that displays HTTP header information belonging to the given * {@link HttpServletRequest} instance. This method uses two nested loops to iterate headers * and then iterate through header values because a header may have one or more values. *//*from w w w. ja v a 2 s . co m*/ private String getRequestHeadersMessage(HttpServletRequest request) { StringBuilder retval = new StringBuilder(); for (Enumeration<String> headerNames = request.getHeaderNames(); headerNames.hasMoreElements();) { String headerName = headerNames.nextElement(); retval.append(headerName).append(": {"); for (Enumeration<String> headerValues = request.getHeaders(headerName); headerValues .hasMoreElements();) { String headerValue = headerValues.nextElement(); retval.append(headerValue); if (headerValues.hasMoreElements()) { retval.append(","); } } retval.append("}\n"); } return retval.toString(); }
From source file:gov.loc.ndmso.proxyfilter.RequestProxy.java
private static HttpMethod setupProxyRequest(final HttpServletRequest hsRequest, final URL targetUrl) throws IOException { final String methodName = hsRequest.getMethod(); final HttpMethod method; if ("POST".equalsIgnoreCase(methodName)) { PostMethod postMethod = new PostMethod(); InputStreamRequestEntity inputStreamRequestEntity = new InputStreamRequestEntity( hsRequest.getInputStream()); postMethod.setRequestEntity(inputStreamRequestEntity); method = postMethod;/* w ww. ja v a 2s. c o m*/ } else if ("GET".equalsIgnoreCase(methodName)) { method = new GetMethod(); } else { // log.warn("Unsupported HTTP method requested: " + hsRequest.getMethod()); return null; } method.setFollowRedirects(false); method.setPath(targetUrl.getPath()); method.setQueryString(targetUrl.getQuery()); @SuppressWarnings("unchecked") Enumeration<String> e = hsRequest.getHeaderNames(); if (e != null) { while (e.hasMoreElements()) { String headerName = e.nextElement(); if ("host".equalsIgnoreCase(headerName)) { //the host value is set by the http client continue; } else if ("content-length".equalsIgnoreCase(headerName)) { //the content-length is managed by the http client continue; } else if ("accept-encoding".equalsIgnoreCase(headerName)) { //the accepted encoding should only be those accepted by the http client. //The response stream should (afaik) be deflated. If our http client does not support //gzip then the response can not be unzipped and is delivered wrong. continue; } else if (headerName.toLowerCase().startsWith("cookie")) { //fixme : don't set any cookies in the proxied request, this needs a cleaner solution continue; } @SuppressWarnings("unchecked") Enumeration<String> values = hsRequest.getHeaders(headerName); while (values.hasMoreElements()) { String headerValue = values.nextElement(); // log.info("setting proxy request parameter:" + headerName + ", value: " + headerValue); method.addRequestHeader(headerName, headerValue); } } } // add rs5/tomcat5 request header for ML method.addRequestHeader("X-Via", "tomcat5"); // log.info("proxy query string " + method.getQueryString()); return method; }
From source file:org.owasp.benchmark.testcode.BenchmarkTest00260.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); String param = ""; boolean flag = true; java.util.Enumeration<String> names = request.getHeaderNames(); while (names.hasMoreElements() && flag) { String name = (String) names.nextElement(); java.util.Enumeration<String> values = request.getHeaders(name); if (values != null) { while (values.hasMoreElements() && flag) { String value = (String) values.nextElement(); if (value.equals("vector")) { param = name;/*from w w w. j a va2 s . c o m*/ flag = false; } } } } String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); byte[] input = new byte[1000]; String str = "?"; Object inputParam = param; if (inputParam instanceof String) str = ((String) inputParam); if (inputParam instanceof java.io.InputStream) { int i = ((java.io.InputStream) inputParam).read(input); if (i == -1) { response.getWriter().println( "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); return; } str = new String(input, 0, i); } javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); cookie.setSecure(false); response.addCookie(cookie); response.getWriter().println("Created cookie: 'SomeCookie': with value: '" + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + "' and secure flag set to: false"); }
From source file:com.woonoz.proxy.servlet.HttpRequestHandler.java
protected void copyHeaders(final HttpServletRequest from, final HttpRequestBase to, ClientHeadersHandler clientHeadersHandler) throws URISyntaxException, MalformedURLException { Enumeration<?> enumerationOfHeaderNames = from.getHeaderNames(); while (enumerationOfHeaderNames.hasMoreElements()) { final String headerName = (String) enumerationOfHeaderNames.nextElement(); Enumeration<?> enumerationOfHeaderValues = from.getHeaders(headerName); while (enumerationOfHeaderValues.hasMoreElements()) { final String headerValue = (String) enumerationOfHeaderValues.nextElement(); final String modifiedValue = clientHeadersHandler.handleHeader(headerName, headerValue); if (modifiedValue != null) { to.addHeader(headerName, modifiedValue); }/*from w w w .j ava 2 s. com*/ } } }