Example usage for javax.servlet.http HttpServletRequest getProtocol

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

Introduction

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

Prototype

public String getProtocol();

Source Link

Document

Returns the name and version of the protocol the request uses in the form <i>protocol/majorVersion.minorVersion</i>, for example, HTTP/1.1.

Usage

From source file:com.matel.pg.components.OAuthController.java

/**
 *
 * @param request/*from   w  w w  . ja  v a 2  s .c o  m*/
 * @return
 */
public static String getProtocolHostnameAndPort(final HttpServletRequest request) {
    String protocol = request.getProtocol().split("/")[0].toLowerCase();
    String hostname = request.getServerName();
    int port = request.getServerPort();

    StringBuilder result = new StringBuilder(protocol + "://" + hostname);
    if (port != 80) {
        result.append(":").append(port);
    }

    return result.toString();
}

From source file:nl.dtls.fairdatapoint.api.controller.utils.LoggerUtils.java

/**
 * Log the request./*  w  ww . j  ava  2  s.co m*/
 * 
 * Log message pattern [Time\t IP\t requestMethod\t requestedURL]
 * @param logger    Class logger
 * @param request   Client request
 * @param response  Server response
 */
public static void logRequest(Logger logger, HttpServletRequest request, HttpServletResponse response) {
    ThreadContext.put("requestMethod", request.getMethod());
    ThreadContext.put("requestURI", request.getRequestURI());
    ThreadContext.put("requestProtocol", request.getProtocol());
    ThreadContext.put("responseStatus", String.valueOf(response.getStatus()));
    String contentLength = response.getHeader(HttpHeaders.CONTENT_LENGTH);
    ThreadContext.put("contentSize", contentLength);
    logger.log(Level.getLevel("API-REQUEST"), "");
}

From source file:it.greenvulcano.gvesb.adapter.http.utils.DumpUtils.java

public static void dump(HttpServletRequest request, StringBuffer log) throws IOException {
    String hN;//w ww.  j a  v a 2  s. com

    log.append("-- DUMP HttpServletRequest START").append("\n");
    log.append("Method             : ").append(request.getMethod()).append("\n");
    log.append("RequestedSessionId : ").append(request.getRequestedSessionId()).append("\n");
    log.append("Scheme             : ").append(request.getScheme()).append("\n");
    log.append("IsSecure           : ").append(request.isSecure()).append("\n");
    log.append("Protocol           : ").append(request.getProtocol()).append("\n");
    log.append("ContextPath        : ").append(request.getContextPath()).append("\n");
    log.append("PathInfo           : ").append(request.getPathInfo()).append("\n");
    log.append("QueryString        : ").append(request.getQueryString()).append("\n");
    log.append("RequestURI         : ").append(request.getRequestURI()).append("\n");
    log.append("RequestURL         : ").append(request.getRequestURL()).append("\n");
    log.append("ContentType        : ").append(request.getContentType()).append("\n");
    log.append("ContentLength      : ").append(request.getContentLength()).append("\n");
    log.append("CharacterEncoding  : ").append(request.getCharacterEncoding()).append("\n");

    log.append("---- Headers START\n");
    Enumeration<String> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        hN = headerNames.nextElement();
        log.append("[" + hN + "]=");
        Enumeration<String> headers = request.getHeaders(hN);
        while (headers.hasMoreElements()) {
            log.append("[" + headers.nextElement() + "]");
        }
        log.append("\n");
    }
    log.append("---- Headers END\n");

    log.append("---- Body START\n");
    log.append(IOUtils.toString(request.getInputStream())).append("\n");
    log.append("---- Body END\n");

    log.append("-- DUMP HttpServletRequest END \n");
}

From source file:fr.paris.lutece.util.http.SecurityUtil.java

/**
 * Write request variables into the dump stringbuffer
 * @param sb The dump stringbuffer/*from   w w w  .j ava 2  s.  c  om*/
 * @param request The HTTP request
 */
private static void dumpVariables(StringBuffer sb, HttpServletRequest request) {
    dumpVariable(sb, "AUTH_TYPE", request.getAuthType());
    dumpVariable(sb, "REQUEST_METHOD", request.getMethod());
    dumpVariable(sb, "PATH_INFO", request.getPathInfo());
    dumpVariable(sb, "PATH_TRANSLATED", request.getPathTranslated());
    dumpVariable(sb, "QUERY_STRING", request.getQueryString());
    dumpVariable(sb, "REQUEST_URI", request.getRequestURI());
    dumpVariable(sb, "SCRIPT_NAME", request.getServletPath());
    dumpVariable(sb, "LOCAL_ADDR", request.getLocalAddr());
    dumpVariable(sb, "SERVER_PROTOCOL", request.getProtocol());
    dumpVariable(sb, "REMOTE_ADDR", request.getRemoteAddr());
    dumpVariable(sb, "REMOTE_HOST", request.getRemoteHost());
    dumpVariable(sb, "HTTPS", request.getScheme());
    dumpVariable(sb, "SERVER_NAME", request.getServerName());
    dumpVariable(sb, "SERVER_PORT", String.valueOf(request.getServerPort()));
}

From source file:com.flexive.faces.FxJsfUtils.java

/**
 * Get the server URL like "http://www.flexive.org" without the context path
 *
 * @return server URL//from   w w w  .j a va2  s.  c  o  m
 */
public static String getServerURL() {
    final FxRequest req = FxJsfUtils.getRequest();
    try {
        return req.getRequestURL().substring(0, req.getRequestURL().indexOf(req.getContextPath()));
    } catch (Exception e) {
        final HttpServletRequest r = req.getRequest();
        return r.getProtocol() + "://" + r.getRemoteHost()
                + (r.getProtocol().startsWith("http") ? "" : ":" + r.getRemotePort());
    }
}

From source file:com.google.ie.web.controller.ImageController.java

/**
 * Construct the url for the default image
 * //from   www. j av  a2s .c  o m
 * @param req the {@link HttpServletRequest} object
 * @return the url of the default image
 */
protected String constructDefaultImageURL(HttpServletRequest req) {
    String baseURL = req.getProtocol() + "://" + req.getServerName() + PATH_TO_DEFAULT_IMAGE;
    return baseURL;
}

From source file:org.addsimplicity.anicetus.web.TelemetryServletFilter.java

@SuppressWarnings("unchecked")
private void setRequestOnSession(TelemetryHttpSession session, HttpServletRequest request) {
    session.setMethod(request.getMethod());
    session.setProtocol(request.getProtocol());
    if (request.getContentType() != null) {
        session.setContentType(request.getContentType(), HeaderType.Request);
    }/*from  ww w  . j  a  va2  s. c o m*/
    session.setRequestURL(request.getRequestURI());

    Enumeration<String> pnames = request.getParameterNames();
    while (pnames.hasMoreElements()) {
        String name = pnames.nextElement();
        session.setParameter(name, request.getParameter(name));
    }

    Enumeration<String> hnames = request.getHeaderNames();
    while (hnames.hasMoreElements()) {
        String name = hnames.nextElement();
        String value = request.getHeader(name);
        if (value != null) {
            session.setHeader(name, request.getHeader(name), HeaderType.Request);
        }
    }

    String parent = request.getHeader(s_PARENT_NAME);
    if (parent == null) {
        parent = request.getParameter(s_PARENT_NAME);
    }

    if (parent != null) {
        try {
            UUID parentId = UUID.fromString(parent);
            session.setParentId(parentId);
        } catch (IllegalArgumentException iae) {
            // TODO - Exception handler
        }

    }
}

From source file:org.esigate.servlet.MockHttpServletRequestBuilder.java

/**
 * Build the request as defined in the current builder.
 * /*w  ww.j  a  v  a2  s. com*/
 * @return the request
 */
public HttpServletRequest build() {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);

    Mockito.when(request.getMethod()).thenReturn(this.method);
    Mockito.when(request.getProtocol()).thenReturn(this.protocolVersion);
    Mockito.when(request.getRequestURI()).thenReturn(this.uriString);

    Mockito.when(request.getHeaderNames()).thenReturn(Collections.enumeration(headers));
    for (Header h : headers) {
        List<String> hresult = new ArrayList<String>();
        hresult.add(h.getValue());
        Mockito.when(request.getHeaders(h.getName())).thenReturn(Collections.enumeration(hresult));
        Mockito.when(request.getHeader(h.getName())).thenReturn(h.getValue());
    }

    if (session == null) {
        Mockito.when(request.getSession()).thenReturn(null);
    } else {
        HttpSession sessionMock = Mockito.mock(HttpSession.class);
        Mockito.when(request.getSession()).thenReturn(sessionMock);
    }
    return request;
}

From source file:seava.j4e.web.controller.ui.extjs.UiExtjsFrameController.java

/**
 * Helper method to create , configure and return an DependencyLoader
 * instance/*from   w w w .  j a va 2 s  . c  o  m*/
 * 
 * @return
 */
private DependencyLoader getDependencyLoader(HttpServletRequest request) {
    String protocol = "http";
    if (request.getProtocol().startsWith("HTTPS")) {
        protocol = "https";
    }
    String host = protocol + "://" + request.getServerName();
    if (request.getServerPort() != 80) {
        host += ":" + request.getServerPort();
    }
    host += "/";
    if (logger.isDebugEnabled()) {
        logger.debug("Get dependency loader for host: " + host + ", modules url: "
                + getUiExtjsSettings().getUrlModules());
    }
    DependencyLoader loader = new DependencyLoader(host);
    loader.setUrlUiExtjsModules(getUiExtjsSettings().getUrlModules());
    loader.setModuleUseBundle(getUiExtjsSettings().isModuleUseBundle());
    loader.setUrlUiExtjsModuleSubpath(getUiExtjsSettings().getModuleSubpath());
    return loader;
}

From source file:com.netflix.spinnaker.gate.interceptors.RequestLoggingInterceptor.java

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) throws Exception {
    // 127.0.0.1 "GET /limecat.jpg HTTP/1.0" 200 2326
    log.debug(String.format("%s \"%s %s %s\" %d %d", sourceIpAddress(request), request.getMethod(),
            getRequestEndpoint(request), request.getProtocol(), response.getStatus(),
            getResponseSize(response)));
}