Example usage for javax.servlet.http HttpServletRequest getHeaderNames

List of usage examples for javax.servlet.http HttpServletRequest getHeaderNames

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getHeaderNames.

Prototype

public Enumeration<String> getHeaderNames();

Source Link

Document

Returns an enumeration of all the header names this request contains.

Usage

From source file:net.sf.j2ep.requesthandlers.RequestHandlerBase.java

/**
 * Will write all request headers stored in the request to the method that
 * are not in the set of banned headers.
 * The Accept-Endocing header is also changed to allow compressed content
 * connection to the server even if the end client doesn't support that. 
 * A Via headers is created as well in compliance with the RFC.
 * /* w w  w.  j  av  a2 s .  c o  m*/
 * @param method The HttpMethod used for this connection
 * @param request The incoming request
 * @throws HttpException 
 */
protected void setHeaders(HttpMethod method, HttpServletRequest request) throws HttpException {
    Enumeration headers = request.getHeaderNames();
    String connectionToken = request.getHeader("connection");

    while (headers.hasMoreElements()) {
        String name = (String) headers.nextElement();
        boolean isToken = (connectionToken != null && name.equalsIgnoreCase(connectionToken));

        if (!isToken && !bannedHeaders.contains(name.toLowerCase())) {
            Enumeration value = request.getHeaders(name);
            while (value.hasMoreElements()) {
                method.addRequestHeader(name, (String) value.nextElement());
            }
        }
    }

    setProxySpecificHeaders(method, request);
}

From source file:com.thoughtworks.go.server.plugin.controller.PluginController.java

private void addRequestHeaders(HttpServletRequest request, DefaultGoPluginApiRequest apiRequest) {
    Enumeration headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String header = (String) headerNames.nextElement();
        String value = request.getHeader(header);
        apiRequest.addRequestHeader(header, value);
    }//from  w  ww.  j  av  a  2 s  .c o m
}

From source file:se.vgregion.portal.requestlogger.RequestLoggerController.java

private Map<String, String> getRequestHeader(PortletRequest request) {
    Map<String, String> result = new TreeMap<String, String>();

    HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(request);
    Enumeration<String> names = httpRequest.getHeaderNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        result.put(name, httpRequest.getHeader(name));
    }//w  w  w  .  j av  a  2s. c  om

    return result;
}

From source file:RequestHeaderView.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {

    //get an Enumeration of all the request header names
    Enumeration e = request.getHeaderNames();

    //display//from w w  w. j a v  a2  s .  co m
    response.setContentType("text/html");
    java.io.PrintWriter out = response.getWriter();
    out.println("<html><head><title>Request Header View</title></head><body>");
    out.println("<h2>Request Headers</h2>");
    String header = null;

    while (e.hasMoreElements()) {
        header = (String) e.nextElement();
        //getHeader returns null if a request header of that name does not
        // exist in the request
        out.println("<strong>" + header + "</strong>" + ": " + request.getHeader(header) + "<br>");
    }

    out.println("</body></html>");

}

From source file:com.eviware.soapui.impl.wsdl.mock.WsdlMockOperationTest.java

private WsdlMockRequest makeWsdlMockRequest() throws Exception {
    HttpServletRequest request = mock(HttpServletRequest.class);
    Enumeration enumeration = mock(Enumeration.class);
    when(request.getHeaderNames()).thenReturn(enumeration);

    HttpServletResponse response = mock(HttpServletResponse.class);
    ServletOutputStream os = mock(ServletOutputStream.class);
    when(response.getOutputStream()).thenReturn(os);

    WsdlMockRunContext context = mock(WsdlMockRunContext.class);

    return new WsdlMockRequest(request, response, context);
}

From source file:com.npower.dl.OMADownloadServlet.java

/**
 * @param request/* w  w w  .j a  v a2s .  com*/
 */
private void logRequest(HttpServletRequest request) {
    Enumeration<String> names = request.getHeaderNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        String value = request.getHeader(name);
        log.info("Http header: " + name + "=" + value);
    }
    names = request.getParameterNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        String value = request.getHeader(name);
        log.info("Http param: " + name + "=" + value);
    }
}

From source file:nz.net.catalyst.mobile.dds.RequestInfo.java

/**
 * creates a RequestInfo object based from the HttpServletRequest
 * //from  w  w  w . jav  a  2s . co m
 * use RequestInfo.getRequest when possible as it will cache the object
 * @param request
 */
private RequestInfo(HttpServletRequest request) {
    HashMap<String, String> headers = new HashMap<String, String>();

    for (Enumeration<?> h = request.getHeaderNames(); h.hasMoreElements();) {
        String headerName = (String) h.nextElement();
        String headerValue = request.getHeader(headerName);

        logger.debug("header: " + headerName + " = " + headerValue);

        headers.put(headerName.toLowerCase(), headerValue);
    }

    this.headers = Collections.unmodifiableMap(getNewMap(headers));
    validateHeaders();
}

From source file:org.eclipse.orion.server.servlets.OrionServlet.java

protected void printHeaders(HttpServletRequest req, StringBuffer out) {
    for (String header : Collections.<String>list(req.getHeaderNames()))
        out.append(header + ": " + req.getHeader(header) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
}

From source file:com.qualogy.qafe.web.upload.DatagridUploadServlet.java

@SuppressWarnings("unchecked")
private void writeUploadInfo(HttpServletRequest request) {
    writeLog("Document Upload!");

    Enumeration headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        Object name = headerNames.nextElement();
        if (name != null) {
            writeLog("Header - " + name + " : " + request.getHeader((String) name));
        }//from   w  ww. j  a va 2  s .  c  om
    }

    writeLog("ServletRemoteAddr: " + request.getRemoteAddr());
    writeLog("Remote Host: " + request.getRemoteHost());
    writeLog("Remote User: " + request.getRemoteUser());
    writeLog("Protocol: " + request.getProtocol());
    writeLog("Server Name: " + request.getServerName());
    writeLog("Server Port: " + request.getServerPort());
    writeLog("Request URL: " + request.getRequestURL());

}

From source file:com.ibm.util.merge.web.rest.servlet.RequestData.java

private Map<String, List<String>> readHeaderValues(HttpServletRequest request) {
    Enumeration<String> headerNames = request.getHeaderNames();
    Map<String, List<String>> headerValues = new HashMap<>();
    while (headerNames.hasMoreElements()) {
        String headerName = headerNames.nextElement();
        Enumeration<String> values = request.getHeaders(headerName);
        List<String> vals = new ArrayList<>();
        while (values.hasMoreElements()) {
            String val = values.nextElement();
            vals.add(val);
        }//from w ww  .ja v a 2s .c o  m
    }
    return headerValues;
}