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:fr.paris.lutece.util.http.SecurityUtil.java

/**
 * Write request variables into the dump stringbuffer
 * @param sb The dump stringbuffer/*from w ww.ja  v  a 2s.  c o m*/
 * @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:eu.webtoolkit.jwt.servlet.WebRequest.java

private static String getPathInfo(HttpServletRequest request, String scriptName) {
    String pathInfo = request.getPathInfo();

    // Jetty will report "/" as an internal path. Which totally makes no sense but is according
    // to the spec
    if (request.getServletPath().length() == 0)
        if (pathInfo != null && pathInfo.equals("/"))
            pathInfo = "";

    if (pathInfo == null || pathInfo.length() == 0) {
        // Work around (jetty) bug where path info is not interpreted correctly for a URL
        // like /bla/hello;jsessionid=q0f2lqgeivq9uipxwk12gj6s/wt-resources/webkit-transitions.css

        String uri = request.getRequestURI();
        if (uri.startsWith(scriptName + ";")) {
            int pathInfoStart = uri.indexOf('/', scriptName.length() + 1);
            if (pathInfoStart != -1)
                pathInfo = uri.substring(pathInfoStart);
        }/*from   ww w  .j a v a 2 s  . c o  m*/
    }

    if (pathInfo == null)
        pathInfo = "";
    return pathInfo;
}

From source file:by.stub.yaml.stubs.StubRequest.java

public static StubRequest createFromHttpServletRequest(final HttpServletRequest request) throws IOException {
    final StubRequest assertionRequest = StubRequest.newStubRequest(request.getPathInfo(),
            HandlerUtils.extractPostRequestBody(request, "stubs"));
    assertionRequest.addMethod(request.getMethod());

    final Enumeration<String> headerNamesEnumeration = request.getHeaderNames();
    final List<String> headerNames = ObjectUtils.isNotNull(headerNamesEnumeration)
            ? Collections.list(request.getHeaderNames())
            : new LinkedList<String>();
    for (final String headerName : headerNames) {
        final String headerValue = request.getHeader(headerName);
        assertionRequest.getHeaders().put(StringUtils.toLower(headerName), headerValue);
    }//from   w  w  w.  j  a va2  s. c o m

    assertionRequest.getQuery().putAll(CollectionUtils.constructParamMap(request.getQueryString()));
    ConsoleUtils.logAssertingRequest(assertionRequest);

    return assertionRequest;
}

From source file:jeeves.server.sources.ServiceRequestFactory.java

/** Builds the request with data supplied by tomcat.
  * A request is in the form: srv/<language>/<service>[!]<parameters>
  *///from  w w w  . j  av  a  2s.  c o  m

public static ServiceRequest create(HttpServletRequest req, HttpServletResponse res, String uploadDir,
        int maxUploadSize) throws Exception {
    String url = req.getPathInfo();

    // FIXME: if request character encoding is undefined set it to UTF-8

    String encoding = req.getCharacterEncoding();
    try {
        // verify that encoding is valid
        Charset.forName(encoding);
    } catch (Exception e) {
        encoding = null;
    }

    if (encoding == null) {
        try {
            req.setCharacterEncoding(Jeeves.ENCODING);
        } catch (UnsupportedEncodingException ex) {
            ex.printStackTrace();
        }
    }

    //--- extract basic info

    HttpServiceRequest srvReq = new HttpServiceRequest(res);

    srvReq.setDebug(extractDebug(url));
    srvReq.setLanguage(extractLanguage(url));
    srvReq.setService(extractService(url));
    srvReq.setJSONOutput(extractJSONFlag(url));
    String ip = req.getRemoteAddr();
    String forwardedFor = req.getHeader("x-forwarded-for");
    if (forwardedFor != null)
        ip = forwardedFor;
    srvReq.setAddress(ip);
    srvReq.setOutputStream(res.getOutputStream());

    //--- discover the input/output methods

    String accept = req.getHeader("Accept");

    if (accept != null) {
        int soapNDX = accept.indexOf("application/soap+xml");
        int xmlNDX = accept.indexOf("application/xml");
        int htmlNDX = accept.indexOf("html");

        if (soapNDX != -1)
            srvReq.setOutputMethod(OutputMethod.SOAP);

        else if (xmlNDX != -1 && htmlNDX == -1)
            srvReq.setOutputMethod(OutputMethod.XML);
    }

    if ("POST".equals(req.getMethod())) {
        srvReq.setInputMethod(InputMethod.POST);

        String contType = req.getContentType();

        if (contType != null) {
            if (contType.indexOf("application/soap+xml") != -1) {
                srvReq.setInputMethod(InputMethod.SOAP);
                srvReq.setOutputMethod(OutputMethod.SOAP);
            }

            else if (contType.indexOf("application/xml") != -1 || contType.indexOf("text/xml") != -1)
                srvReq.setInputMethod(InputMethod.XML);
        }
    }

    //--- retrieve input parameters

    InputMethod input = srvReq.getInputMethod();

    if ((input == InputMethod.XML) || (input == InputMethod.SOAP)) {
        if (req.getMethod().equals("GET"))
            srvReq.setParams(extractParameters(req, uploadDir, maxUploadSize));
        else
            srvReq.setParams(extractXmlParameters(req));
    } else {
        //--- GET or POST
        srvReq.setParams(extractParameters(req, uploadDir, maxUploadSize));
    }

    srvReq.setHeaders(extractHeaders(req));

    return srvReq;
}

From source file:de.kurashigegollub.dev.gcatest.Utils.java

/**
 * /*from   w  w  w.  ja  v a  2 s .  co m*/
 * Will return a String with the request URL. 
 * @param req The current HttpServletRequest.
 * @param includeServlet Will include the servlet name in the return value.
 * @param includePathInfo Will include the path and query parts in the return value (only added, if includeServlet is true as well).
 * @return 
 */
// http://hostname.com:80/appname/servlet/MyServlet/a/b;c=123?d=789
public static String reconstructURL(HttpServletRequest req, boolean includeServlet, boolean includePathInfo) {
    String scheme = req.getScheme(); // http
    String serverName = req.getServerName(); // hostname.com
    int serverPort = req.getServerPort(); // 80
    String contextPath = req.getContextPath(); // /appname
    String servletPath = req.getServletPath(); // /servlet/MyServlet
    String pathInfo = req.getPathInfo(); // /a/b;c=123
    String queryString = req.getQueryString(); // d=789

    // Reconstruct original requesting URL
    String url = scheme + "://" + serverName + ":" + serverPort + contextPath;

    if (includeServlet) {
        url += servletPath;
        if (includePathInfo) {
            if (pathInfo != null) {
                url += pathInfo;
            }
            if (queryString != null) {
                url += "?" + queryString;
            }
        }
    }
    return url;
}

From source file:com.attribyte.essem.util.Util.java

/**
 * Splits the path into an iterable.//from w  w  w.jav a 2 s . c  om
 * @param request The request.
 * @return The components, or empty iterable if none.
 */
public static final Iterable<String> splitPath(final HttpServletRequest request) {

    String pathInfo = request.getPathInfo();
    if (pathInfo == null || pathInfo.length() == 0 || pathInfo.equals("/")) {
        return Collections.emptyList();
    } else {
        return pathSplitter.split(pathInfo);
    }
}

From source file:de.micromata.genome.logging.LogRequestDumpAttribute.java

/**
 * Gen http request dump.//from w w  w.  j  av  a  2s. co  m
 *
 * @param req the req
 * @return the string
 */
@SuppressWarnings("unchecked")
public static String genHttpRequestDump(HttpServletRequest req) {
    StringBuilder sb = new StringBuilder();

    sb.append("method: ").append(req.getMethod()).append('\n')//
            .append("requestURL: ").append(req.getRequestURL()).append('\n')//
            .append("servletPath: ").append(req.getServletPath()).append('\n')//
            .append("requestURI: ").append(req.getRequestURI()).append('\n') //
            .append("queryString: ").append(req.getQueryString()).append('\n') //
            .append("pathInfo: ").append(req.getPathInfo()).append('\n')//
            .append("contextPath: ").append(req.getContextPath()).append('\n') //
            .append("characterEncoding: ").append(req.getCharacterEncoding()).append('\n') //
            .append("localName: ").append(req.getLocalName()).append('\n') //
            .append("contentLength: ").append(req.getContentLength()).append('\n') //
    ;
    sb.append("Header:\n");
    for (Enumeration<String> en = req.getHeaderNames(); en.hasMoreElements();) {
        String hn = en.nextElement();
        sb.append("  ").append(hn).append(": ").append(req.getHeader(hn)).append("\n");
    }
    sb.append("Attr: \n");
    Enumeration en = req.getAttributeNames();
    for (; en.hasMoreElements();) {
        String k = (String) en.nextElement();
        Object v = req.getAttribute(k);
        sb.append("  ").append(k).append(": ").append(Objects.toString(v, StringUtils.EMPTY)).append('\n');
    }

    return sb.toString();
}

From source file:org.impalaframework.extension.mvc.util.RequestModelHelper.java

/**
 * /*from w ww  .j  ava  2s.  com*/
 * @param logger
 * @param request
 */
public static void maybeDebugRequest(Log logger, HttpServletRequest request) {

    if (logger.isDebugEnabled()) {

        logger.debug("#####################################################################################");
        logger.debug("---------------------------- Request details ---------------------------------------");
        logger.debug("Request context path: " + request.getContextPath());
        logger.debug("Request path info: " + request.getPathInfo());
        logger.debug("Request path translated: " + request.getPathTranslated());
        logger.debug("Request query string: " + request.getQueryString());
        logger.debug("Request servlet path: " + request.getServletPath());
        logger.debug("Request request URI: " + request.getRequestURI());
        logger.debug("Request request URL: " + request.getRequestURL());
        logger.debug("Request session ID: " + request.getRequestedSessionId());

        logger.debug("------------------------------------------------ ");
        logger.debug("Parameters ------------------------------------- ");
        final Enumeration<String> parameterNames = request.getParameterNames();

        Map<String, String> parameters = new TreeMap<String, String>();

        while (parameterNames.hasMoreElements()) {
            String name = parameterNames.nextElement();
            String value = request.getParameter(name);
            final String lowerCase = name.toLowerCase();
            if (lowerCase.contains("password") || lowerCase.contains("cardnumber")) {
                value = "HIDDEN";
            }
            parameters.put(name, value);
        }

        //now output            
        final Set<String> parameterKeys = parameters.keySet();
        for (String key : parameterKeys) {
            logger.debug(key + ": " + parameters.get(key));
        }

        logger.debug("------------------------------------------------ ");

        Map<String, Object> attributes = new TreeMap<String, Object>();

        logger.debug("Attributes ------------------------------------- ");
        final Enumeration<String> attributeNames = request.getAttributeNames();
        while (attributeNames.hasMoreElements()) {
            String name = attributeNames.nextElement();
            Object value = request.getAttribute(name);
            final String lowerCase = name.toLowerCase();
            if (lowerCase.contains("password") || lowerCase.contains("cardnumber")) {
                value = "HIDDEN";
            }
            attributes.put(name, value);
        }

        //now output
        final Set<String> keys = attributes.keySet();
        for (String name : keys) {
            Object value = attributes.get(name);
            logger.debug(name + ": " + (value != null ? value.toString() : value));
        }

        logger.debug("------------------------------------------------ ");
        logger.debug("#####################################################################################");
    } else {
        if (logger.isInfoEnabled()) {
            logger.info(
                    "#####################################################################################");
            logger.info("Request query string: " + request.getQueryString());
            logger.info("Request request URI: " + request.getRequestURI());
            logger.info(
                    "#####################################################################################");
        }
    }
}

From source file:net.oneandone.jasmin.main.Servlet.java

private static String pathInfo(HttpServletRequest request) {
    if (request == null) {
        return null;
    }/*from ww w .  ja  v a2s .  co m*/
    return request.getPathInfo();
}

From source file:br.gov.lexml.server.LexMLOAIHandler.java

public static String getResult(final HashMap attributes, final HttpServletRequest request,
        final HttpServletResponse response, final Transformer serverTransformer, final HashMap serverVerbs,
        final HashMap extensionVerbs, final String extensionPath) throws Throwable {
    try {//from  ww w  . j  a  va  2 s.  c o  m
        boolean isExtensionVerb = extensionPath.equals(request.getPathInfo());
        String verb = request.getParameter("verb");
        if (debug) {
            log.debug("OAIHandler.getResult: verb=>" + verb + "<");
        }
        String result;
        Class verbClass = null;
        if (isExtensionVerb) {
            verbClass = (Class) extensionVerbs.get(verb);
        } else {
            verbClass = (Class) serverVerbs.get(verb);
        }
        if (verbClass == null) {
            verbClass = (Class) attributes.get("OAIHandler.missingVerbClass");
        }
        Method construct = verbClass.getMethod("construct", new Class[] { HashMap.class,
                HttpServletRequest.class, HttpServletResponse.class, Transformer.class });
        try {
            result = (String) construct.invoke(null,
                    new Object[] { attributes, request, response, serverTransformer });
        } catch (InvocationTargetException e) {
            throw e.getTargetException();
        }
        if (debug) {
            log.debug(result);
        }
        return result;
    } catch (NoSuchMethodException e) {
        throw new OAIInternalServerError(e.getMessage());
    } catch (IllegalAccessException e) {
        throw new OAIInternalServerError(e.getMessage());
    }
}