Example usage for javax.servlet.http HttpServletRequest getPathInfo

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

Introduction

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

Prototype

public String getPathInfo();

Source Link

Document

Returns any extra path information associated with the URL the client sent when it made this request.

Usage

From source file:com.runwaysdk.controller.ServletDispatcher.java

/**
 * This method strips the context path from the request URI and returns it. Use this method to handle URI's in a context path agnostic manner.
 * /*  ww  w . j av a2s. co m*/
 * @param request
 * @return
 */
private static final String getServletPath(HttpServletRequest request) {
    String servletPath = request.getServletPath();

    if (!"".equals(servletPath)) {
        return servletPath;
    }

    String requestUri = request.getRequestURI();
    int startIndex = request.getContextPath().equals("") ? 0 : request.getContextPath().length();
    int endIndex = request.getPathInfo() == null ? requestUri.length()
            : requestUri.indexOf(request.getPathInfo());

    return requestUri.substring(startIndex, endIndex);
}

From source file:net.siegmar.japtproxy.JaptProxy.java

public static String getURL(HttpServletRequest req, boolean serverOnly, Configuration configuration) {

    String scheme = req.getScheme(); // http
    String serverName = req.getServerName(); // hostname.com

    // do we have a remap for this serverName??
    String remap = configuration.getRemap(serverName);
    if (remap != null) {
        serverName = remap;//w ww  .j  av  a  2  s  .  c  o m
    }

    int serverPort = req.getServerPort(); // 80
    String contextPath = req.getContextPath(); // /mywebapp
    String servletPath = req.getServletPath(); // /servlet/MyServlet
    String pathInfo = req.getPathInfo(); // /a/b;c=123
    String queryString = req.getQueryString(); // d=789

    // Reconstruct original requesting URL
    StringBuilder url = new StringBuilder();
    url.append(scheme).append("://").append(serverName);

    if (serverPort != 80 && serverPort != 443) {
        url.append(":").append(serverPort);
    }

    if (serverOnly)
        return url.toString();

    url.append(contextPath).append(servletPath);

    if (pathInfo != null) {
        url.append(pathInfo);
    }
    if (queryString != null) {
        url.append("?").append(queryString);
    }
    return url.toString();
}

From source file:com.jpeterson.littles3.S3ObjectRequest.java

/**
 * Create an <code>S3Object</code> based on the request supporting virtual
 * hosting of buckets.//from  w w  w  . j  a  v a2s .  co  m
 * 
 * @param req
 *            The original request.
 * @param baseHost
 *            The <code>baseHost</code> is the HTTP Host header that is
 *            "expected". This is used to help determine how the bucket name
 *            will be interpreted. This is used to implement the "Virtual
 *            Hosting of Buckets".
 * @param authenticator
 *            The authenticator to use to authenticate this request.
 * @return An object initialized from the request.
 * @throws IllegalArgumentException
 *             Invalid request.
 */
@SuppressWarnings("unchecked")
public static S3ObjectRequest create(HttpServletRequest req, String baseHost, Authenticator authenticator)
        throws IllegalArgumentException, AuthenticatorException {
    S3ObjectRequest o = new S3ObjectRequest();
    String pathInfo = req.getPathInfo();
    String contextPath = req.getContextPath();
    String requestURI = req.getRequestURI();
    String undecodedPathPart = null;
    int pathInfoLength;
    String requestURL;
    String serviceEndpoint;
    String bucket = null;
    String key = null;
    String host;
    String value;
    String timestamp;

    baseHost = baseHost.toLowerCase();

    host = req.getHeader("Host");
    if (host != null) {
        host = host.toLowerCase();
    }

    try {
        requestURL = URLDecoder.decode(req.getRequestURL().toString(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        // should never happen
        e.printStackTrace();
        IllegalArgumentException t = new IllegalArgumentException("Unsupport encoding: UTF-8");
        t.initCause(e);
        throw t;
    }

    if (!requestURL.endsWith(pathInfo)) {
        String m = "requestURL [" + requestURL + "] does not end with pathInfo [" + pathInfo + "]";
        throw new IllegalArgumentException(m);
    }

    pathInfoLength = pathInfo.length();

    serviceEndpoint = requestURL.substring(0, requestURL.length() - pathInfoLength);

    if (debug) {
        System.out.println("---------------");
        System.out.println("requestURI: " + requestURI);
        System.out.println("serviceEndpoint: " + serviceEndpoint);
        System.out.println("---------------");
    }

    if ((host == null) || // http 1.0 form
            (host.equals(baseHost))) { // ordinary method
        // http 1.0 form
        // bucket first part of path info
        // key second part of path info
        if (pathInfoLength > 1) {
            int index = pathInfo.indexOf('/', 1);
            if (index > -1) {
                bucket = pathInfo.substring(1, index);

                if (pathInfoLength > (index + 1)) {
                    key = pathInfo.substring(index + 1);
                    undecodedPathPart = requestURI.substring(contextPath.length() + 1 + bucket.length(),
                            requestURI.length());
                }
            } else {
                bucket = pathInfo.substring(1);
            }
        }
    } else if (host.endsWith("." + baseHost)) {
        // bucket prefix of host
        // key is path info
        bucket = host.substring(0, host.length() - 1 - baseHost.length());
        if (pathInfoLength > 1) {
            key = pathInfo.substring(1);
            undecodedPathPart = requestURI.substring(contextPath.length(), requestURI.length());
        }
    } else {
        // bucket is host
        // key is path info
        bucket = host;
        if (pathInfoLength > 1) {
            key = pathInfo.substring(1);
            undecodedPathPart = requestURI.substring(contextPath.length(), requestURI.length());
        }
    }

    // timestamp
    timestamp = req.getHeader("Date");

    // CanonicalizedResource
    StringBuffer canonicalizedResource = new StringBuffer();

    canonicalizedResource.append('/');
    if (bucket != null) {
        canonicalizedResource.append(bucket);
    }
    if (undecodedPathPart != null) {
        canonicalizedResource.append(undecodedPathPart);
    }
    if (req.getParameter(PARAMETER_ACL) != null) {
        canonicalizedResource.append("?").append(PARAMETER_ACL);
    }

    // CanonicalizedAmzHeaders
    StringBuffer canonicalizedAmzHeaders = new StringBuffer();
    Map<String, String> headers = new TreeMap<String, String>();
    String headerName;
    String headerValue;

    for (Enumeration headerNames = req.getHeaderNames(); headerNames.hasMoreElements();) {
        headerName = ((String) headerNames.nextElement()).toLowerCase();

        if (headerName.startsWith("x-amz-")) {
            for (Enumeration headerValues = req.getHeaders(headerName); headerValues.hasMoreElements();) {
                headerValue = (String) headerValues.nextElement();
                String currentValue = headers.get(headerValue);

                if (currentValue != null) {
                    // combine header fields with the same name
                    headers.put(headerName, currentValue + "," + headerValue);
                } else {
                    headers.put(headerName, headerValue);
                }

                if (headerName.equals("x-amz-date")) {
                    timestamp = headerValue;
                }
            }
        }
    }

    for (Iterator<String> iter = headers.keySet().iterator(); iter.hasNext();) {
        headerName = iter.next();
        headerValue = headers.get(headerName);
        canonicalizedAmzHeaders.append(headerName).append(":").append(headerValue).append("\n");
    }

    StringBuffer stringToSign = new StringBuffer();

    stringToSign.append(req.getMethod()).append("\n");
    value = req.getHeader("Content-MD5");
    if (value != null) {
        stringToSign.append(value);
    }
    stringToSign.append("\n");
    value = req.getHeader("Content-Type");
    if (value != null) {
        stringToSign.append(value);
    }
    stringToSign.append("\n");
    value = req.getHeader("Date");
    if (value != null) {
        stringToSign.append(value);
    }
    stringToSign.append("\n");
    stringToSign.append(canonicalizedAmzHeaders);
    stringToSign.append(canonicalizedResource);

    if (debug) {
        System.out.println(":v:v:v:v:");
        System.out.println("undecodedPathPart: " + undecodedPathPart);
        System.out.println("canonicalizedAmzHeaders: " + canonicalizedAmzHeaders);
        System.out.println("canonicalizedResource: " + canonicalizedResource);
        System.out.println("stringToSign: " + stringToSign);
        System.out.println(":^:^:^:^:");
    }

    o.setServiceEndpoint(serviceEndpoint);
    o.setBucket(bucket);
    o.setKey(key);
    try {
        if (timestamp == null) {
            o.setTimestamp(null);
        } else {
            o.setTimestamp(DateUtil.parseDate(timestamp));
        }
    } catch (DateParseException e) {
        o.setTimestamp(null);
    }
    o.setStringToSign(stringToSign.toString());
    o.setRequestor(authenticate(req, o));

    return o;
}

From source file:lucee.runtime.net.rpc.server.RPCServer.java

/**
 * getRequestPath a returns request path for web service padded with
 * request.getPathInfo for web services served from /services directory.
 * This is a required to support serving .jws web services from /services
 * URL. See AXIS-843 for more information.
 *
 * @param request HttpServletRequest//from  w w  w. j  av  a 2s . com
 * @return String
 */
private static String getRequestPath(HttpServletRequest request) {
    return request.getServletPath() + ((request.getPathInfo() != null) ? request.getPathInfo() : "");
}

From source file:com.softwarementors.extjs.djn.servlet.DirectJNgineServlet.java

private static RequestType getFromRequestContentType(HttpServletRequest request) {
    assert request != null;

    String contentType = request.getContentType();
    String pathInfo = request.getPathInfo();

    if (!StringUtils.isEmpty(pathInfo) && pathInfo.startsWith(PollRequestProcessor.PATHINFO_POLL_PREFIX)) {
        return RequestType.POLL;
    } else if (StringUtils.startsWithCaseInsensitive(contentType, "application/json")) {
        return RequestType.JSON;
    } else if (StringUtils.startsWithCaseInsensitive(contentType, "application/x-www-form-urlencoded")
            && request.getMethod().equalsIgnoreCase("post")) {
        return RequestType.FORM_SIMPLE_POST;
    } else if (ServletFileUpload.isMultipartContent(request)) {
        return RequestType.FORM_UPLOAD_POST;
    } else if (RequestRouter.isSourceRequest(pathInfo)) {
        return RequestType.SOURCE;
    } else {/*from   w w w .  jav a2 s  .c om*/
        String requestInfo = ServletUtils.getDetailedRequestInformation(request);
        RequestException ex = RequestException.forRequestFormatNotRecognized();
        logger.error("Error during file uploader: " + ex.getMessage() + "\nAdditional request information: "
                + requestInfo, ex);
        throw ex;
    }
}

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  . ja va 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:com.extjs.djn.ioc.servlet.BaseDirectJNgineServlet.java

private static RequestType getFromRequestContentType(HttpServletRequest request) {
    assert request != null;

    String contentType = request.getContentType();
    String contentTypeLowercase = "";
    if (contentType != null) {
        contentTypeLowercase = contentType.toLowerCase();
    }//  ww w. j  av  a2  s.co  m

    String pathInfo = request.getPathInfo();

    if (!StringUtils.isEmpty(pathInfo) && pathInfo.startsWith(PollRequestProcessor.PATHINFO_POLL_PREFIX)) {
        return RequestType.POLL;
    } else if (contentTypeLowercase.startsWith("application/json")) {
        return RequestType.JSON;
    } else if (contentTypeLowercase.startsWith("application/x-www-form-urlencoded")
            && request.getMethod().toLowerCase().equals("post")) {
        return RequestType.FORM_SIMPLE_POST;
    } else if (ServletFileUpload.isMultipartContent(request)) {
        return RequestType.FORM_UPLOAD_POST;
    } else {
        String requestInfo = ServletUtils.getDetailedRequestInformation(request);
        RequestException ex = RequestException.forRequestFormatNotRecognized();
        logger.error("Error during file uploader: " + ex.getMessage() + "\nAdditional request information: "
                + requestInfo, ex);
        throw ex;
    }
}

From source file:com.tc.utils.XSPUtils.java

public static String getURL() {

    HttpServletRequest req = XSPUtils.getRequest();
    String scheme = req.getScheme(); // http
    String serverName = req.getServerName(); // hostname.com
    int serverPort = req.getServerPort(); // 80
    String contextPath = req.getContextPath(); // /mywebapp
    String servletPath = req.getServletPath(); // /servlet/MyServlet
    String pathInfo = req.getPathInfo(); // /a/b;c=123
    String queryString = req.getQueryString(); // d=789

    // Reconstruct original requesting URL
    StringBuffer url = new StringBuffer();
    url.append(scheme).append("://").append(serverName);

    if ((serverPort != 80) && (serverPort != 443)) {
        url.append(":").append(serverPort);
    }//from   w  w w.  j  a  v  a 2s  .  c  om

    url.append(contextPath).append(servletPath);

    if (pathInfo != null) {
        url.append(pathInfo);
    }
    if (queryString != null) {
        url.append("?").append(queryString);
    }
    return url.toString();
}

From source file:info.magnolia.module.servletsanity.support.ServletAssert.java

public static void printRequestInfo(HttpServletRequest request, HttpServletResponse response, String location)
        throws IOException {
    append("");/*from w w  w .ja v a  2s  . c om*/
    append("");
    append("###################################");
    append("##");
    append("## " + location);
    append("##");
    append("##############");
    append("");

    appendRequestChain(request);

    appendResponseChain(response);

    append("Path elements:");
    append("&nbsp;&nbsp;&nbsp;&nbsp;RequestUri  = " + request.getRequestURI());
    append("&nbsp;&nbsp;&nbsp;&nbsp;ContextPath = " + request.getContextPath());
    append("&nbsp;&nbsp;&nbsp;&nbsp;ServletPath = " + request.getServletPath());
    append("&nbsp;&nbsp;&nbsp;&nbsp;PathInfo    = " + request.getPathInfo());
    append("&nbsp;&nbsp;&nbsp;&nbsp;QueryString = " + request.getQueryString());
    String x = request.getContextPath() + request.getServletPath()
            + StringUtils.defaultString(request.getPathInfo());
    if (!request.getRequestURI().equals(x)) {
        append("ERROR RequestURI is [" + request.getRequestURI() + "] according to spec it should be [" + x
                + "]");
    } else {
        append("&nbsp;&nbsp;&nbsp;&nbsp;Request path elements are in sync (requestURI = contextPath + servletPath + pathInfo) (SRV 3.4)");
    }
    append("");

    append("Forward attributes:");
    printAttribute(request, "javax.servlet.forward.request_uri");
    printAttribute(request, "javax.servlet.forward.context_path");
    printAttribute(request, "javax.servlet.forward.servlet_path");
    printAttribute(request, "javax.servlet.forward.path_info");
    printAttribute(request, "javax.servlet.forward.query_string");
    append("");

    append("Include attributes:");
    printAttribute(request, "javax.servlet.include.request_uri");
    printAttribute(request, "javax.servlet.include.context_path");
    printAttribute(request, "javax.servlet.include.servlet_path");
    printAttribute(request, "javax.servlet.include.path_info");
    printAttribute(request, "javax.servlet.include.query_string");
    append("");
}

From source file:uk.ac.ox.oucs.vle.mvc.CourseSignupUrlViewController.java

@Override
protected String getViewNameForRequest(HttpServletRequest request) {
    return request.getPathInfo();
}