List of usage examples for javax.servlet.http HttpServletRequest getHeaderNames
public Enumeration<String> getHeaderNames();
From source file:opendap.hai.BesControlApi.java
private void controlApi(HttpServletRequest request, HttpServletResponse response, boolean isPost) throws IOException { StringBuilder sb = new StringBuilder(); Enumeration headers = request.getHeaderNames(); while (headers.hasMoreElements()) { String headerName = (String) headers.nextElement(); String headerValue = request.getHeader(headerName); sb.append(" ").append(headerName).append(" = '").append(headerValue).append("'\n"); }/* w w w .j av a2 s. co m*/ log.debug("\nHTTP HEADERS:\n{}", sb); //log.debug("\nBODY:\n{}",getRequestBodyAsString(request)); HashMap<String, String> kvp = Util.processQuery(request); String status = null; try { status = processBesCommand(kvp, isPost); } catch (BesAdminFail baf) { status = baf.getMessage(); } PrintWriter output = response.getWriter(); //@todo work this out to not escape everything. //output.append(StringEscapeUtils.escapeHtml(status)); //String s = processStatus(status); output.append(status); output.flush(); }
From source file:uk.ac.ebi.phenotype.web.proxy.ExternalUrlConfiguratbleProxyServlet.java
/** Copy request headers from the servlet client to the proxy request. */ protected void copyRequestHeaders(HttpServletRequest servletRequest, HttpRequest proxyRequest) { // Get an Enumeration of all of the header names sent by the client Enumeration enumerationOfHeaderNames = servletRequest.getHeaderNames(); while (enumerationOfHeaderNames.hasMoreElements()) { String headerName = (String) enumerationOfHeaderNames.nextElement(); if (headerName.equalsIgnoreCase(HttpHeaders.CONTENT_LENGTH)) continue; // As per the Java Servlet API 2.5 documentation: // Some headers, such as Accept-Language can be sent by clients // as several headers each with a different value rather than // sending the header as a comma separated list. // Thus, we get an Enumeration of the header values sent by the // client Enumeration headers = servletRequest.getHeaders(headerName); while (headers.hasMoreElements()) { String headerValue = (String) headers.nextElement(); // In case the proxy host is running multiple virtual servers, // rewrite the Host header to ensure that we get content from // the correct virtual server if (headerName.equalsIgnoreCase(HttpHeaders.HOST)) { HttpHost host = URIUtils.extractHost(this.targetUri); headerValue = host.getHostName(); if (host.getPort() != -1) headerValue += ":" + host.getPort(); }/*from w w w . j ava 2 s. c o m*/ proxyRequest.addHeader(headerName, headerValue); } } }
From source file:org.alfresco.repo.web.scripts.servlet.jive.JiveToolkitAuthenticatorFactory.java
/** * Debugging method for obtaining the state of a request as a String. * // ww w. ja v a 2 s . c o m * @param request The request to retrieve the state from <i>(may be null)</i>. * @return The request state as a human-readable string value <i>(will not be null)</i>. */ private String requestToString(final HttpServletRequest request) { StringBuffer result = new StringBuffer(128); if (request != null) { result.append("\n\tMethod: "); result.append(request.getMethod()); result.append("\n\tURL: "); result.append(String.valueOf(request.getRequestURI())); result.append("\n\tHeaders: "); Enumeration<String> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String headerName = headerNames.nextElement(); String headerValue = request.getHeader(headerName); result.append("\n\t\t"); result.append(headerName); result.append(" : "); result.append(headerValue); } } else { result.append("(null)"); } return (result.toString()); }
From source file:org.ow2.petals.binding.restproxy.in.AbstractRESTService.java
/** * @param path/*from ww w. j a v a 2 s . c o m*/ * @param request * @return */ private Map<String, Object> createProperties(final String path, final HttpServletRequest request) { Map<String, Object> result = new HashMap<String, Object>(); result.put(org.ow2.petals.messaging.framework.message.Constants.HTTP_URL, path); Enumeration<?> headers = request.getHeaderNames(); if (headers != null) { while (headers.hasMoreElements()) { Object object = headers.nextElement(); String key = object.toString(); result.put(org.ow2.petals.messaging.framework.message.Constants.HEADER + "." + key, request.getHeader(key)); } } result.put(org.ow2.petals.messaging.framework.message.Constants.CONTENT_LENGTH, request.getContentLength()); String contentType = HTTPUtils.getContentType(request.getContentType()); result.put(org.ow2.petals.messaging.framework.message.Constants.CONTENT_TYPE, contentType); final String charsetEncoding = request.getCharacterEncoding(); result.put(org.ow2.petals.messaging.framework.message.Constants.CHARSET_ENCODING, charsetEncoding); result.put(org.ow2.petals.messaging.framework.message.Constants.HTTP_METHOD, request.getMethod()); // get form data which is not XML! Enumeration<?> e = request.getParameterNames(); while (e.hasMoreElements()) { String paramName = (String) e.nextElement(); String[] values = request.getParameterValues(paramName.toString()); int i = 0; for (String string : values) { result.put(org.ow2.petals.messaging.framework.message.Constants.PARAMETERS + "." + (i++) + "." + paramName, string); } } for (String key : result.keySet()) { this.logger.debug("From HTTPRequest : Property '" + key + "' = '" + result.get(key) + "'"); } return result; }
From source file:com.codeabovelab.dm.gateway.proxy.common.HttpProxy.java
/** * Copy request headers from the servlet client to the proxy request. */// ww w . j a v a 2s . co m private void copyRequestHeaders(HttpProxyContext proxyContext, HttpRequest proxyRequest) { HttpServletRequest servletRequest = proxyContext.getRequest(); // Get an Enumeration of all of the header names sent by the client Enumeration enumerationOfHeaderNames = servletRequest.getHeaderNames(); while (enumerationOfHeaderNames.hasMoreElements()) { String headerName = (String) enumerationOfHeaderNames.nextElement(); //Instead the content-length is effectively set via InputStreamEntity if (headerName.equalsIgnoreCase(HttpHeaders.CONTENT_LENGTH)) { continue; } if (hopByHopHeaders.containsHeader(headerName)) { continue; } Enumeration headers = servletRequest.getHeaders(headerName); while (headers.hasMoreElements()) {//sometimes more than one value String headerValue = (String) headers.nextElement(); // In case the proxy host is running multiple virtual servers, // rewrite the Host header to ensure that we get content from // the correct virtual server if (headerName.equalsIgnoreCase(HttpHeaders.HOST)) { HttpHost host = proxyContext.getTargetHost(); headerValue = host.getHostName(); if (host.getPort() != -1) { headerValue += ":" + host.getPort(); } } else if (headerName.equalsIgnoreCase(org.apache.http.cookie.SM.COOKIE)) { headerValue = getRealCookie(headerValue); } proxyRequest.addHeader(headerName, headerValue); } } }
From source file:org.realityforge.proxy_servlet.AbstractProxyServlet.java
/** * Copy request headers from the servlet client to the proxy request. */// ww w . j ava 2 s. com private void copyRequestHeaders(final HttpServletRequest servletRequest, final HttpRequest proxyRequest) { // Get an Enumeration of all of the header names sent by the client final Enumeration enumerationOfHeaderNames = servletRequest.getHeaderNames(); while (enumerationOfHeaderNames.hasMoreElements()) { final String headerName = (String) enumerationOfHeaderNames.nextElement(); //Instead the content-length is effectively set via InputStreamEntity if (headerName.equalsIgnoreCase(HttpHeaders.CONTENT_LENGTH)) { continue; } else if (HOP_BY_HOP_HEADERS.containsHeader(headerName)) { continue; } final Enumeration headers = servletRequest.getHeaders(headerName); while (headers.hasMoreElements()) { //sometimes more than one value String headerValue = (String) headers.nextElement(); // In case the proxy host is running multiple virtual servers, // rewrite the Host header to ensure that we get content from // the correct virtual server if (headerName.equalsIgnoreCase(HttpHeaders.HOST)) { final HttpHost host = URIUtils.extractHost(_targetUri); headerValue = host.getHostName(); if (-1 != host.getPort()) { headerValue += ":" + host.getPort(); } } proxyRequest.addHeader(headerName, headerValue); } } }
From source file:snoopware.api.ProxyServlet.java
/** * Copy request headers from the servlet client to the proxy request. */// ww w. j a va 2 s . c o m protected void copyRequestHeaders(HttpServletRequest servletRequest, HttpRequest proxyRequest) { // Get an Enumeration of all of the header names sent by the client Enumeration enumerationOfHeaderNames = servletRequest.getHeaderNames(); while (enumerationOfHeaderNames.hasMoreElements()) { String headerName = (String) enumerationOfHeaderNames.nextElement(); //Instead the content-length is effectively set via InputStreamEntity if (headerName.equalsIgnoreCase(HttpHeaders.CONTENT_LENGTH)) { continue; } if (hopByHopHeaders.containsHeader(headerName)) { continue; } Enumeration headers = servletRequest.getHeaders(headerName); while (headers.hasMoreElements()) {//sometimes more than one value String headerValue = (String) headers.nextElement(); // In case the proxy host is running multiple virtual servers, // rewrite the Host header to ensure that we get content from // the correct virtual server if (headerName.equalsIgnoreCase(HttpHeaders.HOST)) { HttpHost host = URIUtils.extractHost(this.targetUri); headerValue = host.getHostName(); if (host.getPort() != -1) { headerValue += ":" + host.getPort(); } } proxyRequest.addHeader(headerName, headerValue); } } }
From source file:org.finra.dm.app.security.HttpHeaderApplicationUserBuilder.java
/** * Creates a map of the HTTP headers contained within the servlet request. The session Id is also placed in the HTTP_HEADER_SESSION_ID key. * * @param request the HTTP servlet request. * * @return the map of headers.//from w w w .jav a 2 s . c om */ private Map<String, String> getHttpHeaders(HttpServletRequest request) { // Create a hash map to contain the headers. Map<String, String> headerMap = new HashMap<String, String>(); // Enumerate through each header and store it in the map. Enumeration<String> enumeration = request.getHeaderNames(); while (enumeration.hasMoreElements()) { String header = enumeration.nextElement(); headerMap.put(header.toLowerCase(), request.getHeader(header)); } // Place the session Id in a special key so it can retrieved later on when building the user. headerMap.put(HTTP_HEADER_SESSION_ID, request.getSession().getId()); // Return the header map. return headerMap; }
From source file:com.fujitsu.dc.engine.rs.StatusResource.java
/** * Service.// ww w .j a va2 s.com * @param path ?? * @param req Request * @param res Response * @param is * @return Response */ public final Response run(final String path, final HttpServletRequest req, final HttpServletResponse res, final InputStream is) { StringBuilder msg = new StringBuilder(); msg.append(">>> Request Started "); msg.append(" method:"); msg.append(req.getMethod()); msg.append(" method:"); msg.append(req.getRequestURL()); msg.append(" url:"); log.info(msg); // ? ???? Enumeration<String> multiheaders = req.getHeaderNames(); for (String headerName : Collections.list(multiheaders)) { Enumeration<String> headers = req.getHeaders(headerName); for (String header : Collections.list(headers)) { log.debug("RequestHeader['" + headerName + "'] = " + header); } } try { DcEngineConfig.reload(); } catch (Exception e) { log.warn(" unknown Exception(" + e.getMessage() + ")"); return errorResponse(new DcEngineException("500 Internal Server Error (Unknown Error)", DcEngineException.STATUSCODE_SERVER_ERROR)); } return Response.status(HttpStatus.SC_NO_CONTENT).build(); }
From source file:io.personium.engine.rs.StatusResource.java
/** * Service./*from w ww . j a v a 2 s.c o m*/ * @param path ?? * @param req Request * @param res Response * @param is * @return Response */ public final Response run(final String path, final HttpServletRequest req, final HttpServletResponse res, final InputStream is) { StringBuilder msg = new StringBuilder(); msg.append(">>> Request Started "); msg.append(" method:"); msg.append(req.getMethod()); msg.append(" method:"); msg.append(req.getRequestURL()); msg.append(" url:"); log.info(msg); // ? ???? Enumeration<String> multiheaders = req.getHeaderNames(); for (String headerName : Collections.list(multiheaders)) { Enumeration<String> headers = req.getHeaders(headerName); for (String header : Collections.list(headers)) { log.debug("RequestHeader['" + headerName + "'] = " + header); } } try { PersoniumEngineConfig.reload(); } catch (Exception e) { log.warn(" unknown Exception(" + e.getMessage() + ")"); return errorResponse(new PersoniumEngineException("500 Internal Server Error (Unknown Error)", PersoniumEngineException.STATUSCODE_SERVER_ERROR)); } return Response.status(HttpStatus.SC_NO_CONTENT).build(); }