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.commercehub.dropwizard.BuildInfoServlet.java

private static String getRequestedKey(HttpServletRequest request) {
    return StringUtils.substring(request.getPathInfo(), 1);
}

From source file:com.cubeia.backoffice.report.RequestBean.java

public static RequestBean parse(HttpServletRequest req) {
    /*//from   w  ww . j  av  a2 s.  com
     * Trim the path (which becomes the report name)
     */
    String path = trim(req.getPathInfo());
    /*
     * check the format and do default if needed
     */
    String form = req.getParameter("format");
    if (form == null) {
        form = Format.CSV.name();
    }
    /*
     * Convert parameter map to a simple string-string map
     */
    @SuppressWarnings("rawtypes")
    Map params = req.getParameterMap();
    Map<String, String> tmp = new HashMap<String, String>(params.size());
    for (Object key : params.keySet()) {
        tmp.put(key.toString(), req.getParameter(key.toString()));
    }
    /*
     * Continue parsing
     */
    return parse(path, tmp, form);
}

From source file:architecture.ee.web.util.ServletUtils.java

public static String getServletPath(HttpServletRequest request) {
    String thisPath = request.getServletPath();
    if (thisPath == null) {
        String requestURI = request.getRequestURI();
        if (request.getPathInfo() != null)
            thisPath = requestURI.substring(0, requestURI.indexOf(request.getPathInfo()));
        else/*from w  ww.j a  va2s.  com*/
            thisPath = requestURI;
    } else if (thisPath.equals("") && request.getPathInfo() != null)
        thisPath = request.getPathInfo();
    return thisPath;
}

From source file:mojo.view.util.DebugUtils.java

public static void logRequestInfo(HttpServletRequest req) {
    logger.debug("session.id          : " + req.getSession().getId());
    logger.debug("request.method      : " + req.getMethod());
    logger.debug("request.pathInfo    : " + req.getPathInfo());
    logger.debug("request.requestURI  : " + req.getRequestURI());
    logger.debug("request.requestURL  : " + req.getRequestURL());
    logger.debug("request.queryString : " + req.getQueryString());
    logger.debug("");

    logRequestHeaders(req);// w  ww  .ja  v  a  2  s  .com
    logRequestParameters(req);
    logRequestAttributes(req);
}

From source file:edu.umich.ctools.sectionsUtilityTool.Utils.java

public static void openFile(HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
    M_log.debug("Stub method called");
    String pathInfo = request.getPathInfo();
    M_log.debug("Path Info: " + pathInfo);

    String url = request.getPathInfo();
    String queryString = request.getQueryString();

    if (queryString != null) {
        url = pathInfo + "?" + queryString;
    }/*  w  ww.j a v a 2 s.  co m*/

    FileReader fr = null;

    if (url.matches(SectionsUtilityToolServlet.appExtPropertiesFile.getProperty(CANVAS_API_TERMS))) {
        fr = retrieveTestFile(url, fr, "Courses call stub", "/stubs/canvas/termsSample.txt");
    }

    else if (pathInfo.equalsIgnoreCase("/api/v1/courses/2222/sections")) {
        fr = retrieveTestFile(url, fr, "Sections call for course 2222 stub",
                "/stubs/canvas/mySecondSections.txt");
    }

    else if (pathInfo.equalsIgnoreCase("/api/v1/courses/1111/sections")) {
        fr = retrieveTestFile(url, fr, "Sections call for course 1111 stub",
                "/stubs/canvas/myFirstSections.txt");
    }

    else if (pathInfo.equalsIgnoreCase("/api/v1/courses")) {
        fr = retrieveTestFile(url, fr, "Courses call stub", "/stubs/canvas/coursesSample.txt");
    }

    else if (url.matches(SectionsUtilityToolServlet.appExtPropertiesFile.getProperty(CANVAS_API_GET_COURSE))) {
        fr = retrieveTestFile(url, fr, "Specific courses call stub", "/stubs/canvas/myCoursesSample.txt");
    }

    else if (url.matches(SectionsUtilityToolServlet.appExtPropertiesFile
            .getProperty(CANVAS_API_GETALLSECTIONS_PER_COURSE))) {
        fr = retrieveTestFile(url, fr, "Sections call stub", "/stubs/canvas/sectionsSample.txt");
    }

    else if (pathInfo.equalsIgnoreCase(SectionsUtilityToolServlet.MPATHWAYS_PATH_INFO)) {
        fr = retrieveTestFile(url, fr, "MPathways call stub", "/stubs/esb/mpathwaysSample.txt");
    }

    else {
        M_log.debug("Unrecognized call: " + url);
    }

    try {
        BufferedReader rd = new BufferedReader(fr);
        ;
        String line = "";
        StringBuilder sb = new StringBuilder();
        while ((line = rd.readLine()) != null) {
            sb.append(line);
        }
        out.print(sb.toString());
        out.flush();
        M_log.debug("SUCCESS");
    } catch (Exception e) {
        M_log.error("FAILURE");
        e.printStackTrace();
    }
}

From source file:com.moss.appkeep.server.HttpPublisher.java

public static ComponentRequest parse(HttpServletRequest request) {
    List<String> parts = splitWell(request.getPathInfo(), "/");

    RootType type = RootType.read(parts.get(0));

    if (type != RootType.BY_COMPONENT_ID) {
        return null;
    }//from  w ww .  j av a 2s.com

    ComponentId componentId;
    ComponentType componentType;
    {
        String fileName = parts.get(1);

        int pos = fileName.lastIndexOf('.');

        componentId = new ComponentId(fileName.substring(0, pos));
        componentType = ComponentType.valueOf(fileName.substring(pos + 1).toUpperCase());
    }

    //      System.out.println("Component ID: " + componentId);
    //      System.out.println("Component Type: " + componentType);

    List<String> endorsementStrings = splitWell(request.getParameter("with-endorsements"), ";");

    List<ComponentEndorsement> endorsements = new LinkedList<ComponentEndorsement>();

    for (String next : endorsementStrings) {
        int delimiterPos = next.indexOf(':');
        String typeString = next.substring(0, delimiterPos);
        String value = next.substring(delimiterPos + 1);
        //         System.out.println("Type " + typeString + ", value=" + value);

        EndorsementType endorsementType = EndorsementType.valueOf(typeString.toUpperCase());
        ComponentEndorsement e = endorsementType.parse(value);
        endorsements.add(e);
        //         System.out.println("Endorsement " + e);
    }

    return new ComponentRequest(endorsements, componentId, componentType);
}

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

public static void assertPathInfo(HttpServletRequest request, String expected) throws IOException {
    if (!StringUtils.equals(request.getPathInfo(), expected)) {
        append("ERROR PathInfo is [" + request.getPathInfo() + "] expected it to be [" + expected + "]");
    } else {/*w  ww  .  jav a2 s  .com*/
        append("PASSED PathInfo is correct");
    }
}

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

/**
 * Analyzes (validates) request url and extract required information.
 *
 * @param request the object to populate with extracted information.
 * @throws net.siegmar.japtproxy.exception.InvalidRequestException is thrown if requested url is invalid.
 *///  w ww.j av  a 2  s  .  c  o m
private static RequestedData buildRequestedData(final HttpServletRequest request,
        final Configuration configuration) throws InvalidRequestException {
    final String resource = request.getPathInfo();
    final RequestedData requestedData = new RequestedData();
    requestedData.setRequestedResource(resource);
    requestedData.setRequestModifiedSince(request.getDateHeader(HttpHeaderConstants.IF_MODIFIED_SINCE));

    requestedData.setUserAgent(request.getHeader(HttpHeaderConstants.USER_AGENT));
    requestedData.setUrl(getURL(request, configuration));
    requestedData.setHostUrl(getURL(request, true, configuration));
    requestedData.setScheme(request.getScheme());
    requestedData.setServerName(request.getServerName());
    requestedData.setServerPort(request.getServerPort());

    final String requestedResource = requestedData.getRequestedResource();

    // Reject if no requested resource is specified
    if (requestedResource == null) {
        throw new InvalidRequestException("Rejected request because it doesn't contain a resource request");
    }

    // Reject requests that contain /../ for security reason
    if (requestedResource.contains("/../")) {
        throw new InvalidRequestException(
                "Rejected request '" + requestedResource + "' because it contains /../");
    }

    // Reject requests that doesn't contain a backend
    final int endIdx = requestedResource.indexOf('/', 1);
    if (endIdx <= 1) {
        throw new InvalidRequestException(
                "Rejected request '" + requestedResource + "' because it doesn't specify a backend");
    }

    // Reject requests that doesn't contain a target resource
    if (requestedResource.length() == endIdx + 1) {
        throw new InvalidRequestException("Rejected request '" + requestedResource
                + "' because it doesn't specify a target " + "resource");
    }

    // Extract the backend and target resource parts of the request
    final String requestedBackend = requestedResource.substring(1, endIdx);
    final String requestedTarget = requestedResource.substring(endIdx);

    // Set requestedData
    requestedData.setRequestedTarget(requestedTarget);
    requestedData.setRequestedBackend(requestedBackend);

    return requestedData;
}

From source file:com.ecyrd.jspwiki.url.DefaultURLConstructor.java

/**
 *  Takes the name of the page from the request URI.
 *  The initial slash is also removed.  If there is no page,
 *  returns null./*from   w  ww  .  j a  v a2  s  . c o  m*/
 *  
 *  @param request The request to parse
 *  @param encoding The encoding to use
 *  
 *  @return a parsed page name, or null, if it cannot be found
 *  
 *  @throws UnsupportedEncodingException If the encoding is not recognized.
 */
public static String parsePageFromURL(HttpServletRequest request, String encoding)
        throws UnsupportedEncodingException {
    String name = request.getPathInfo();

    if (name == null || name.length() <= 1) {
        return null;
    } else if (name.charAt(0) == '/') {
        name = name.substring(1);
    }

    //
    //  This is required, because by default all URLs are handled
    //  as Latin1, even if they are really UTF-8.
    //

    // name = TextUtil.urlDecode( name, encoding );

    return name;
}

From source file:org.ow2.chameleon.everest.servlet.EverestServlet.java

public static DefaultRequest translate(HttpServletRequest request) {

    String debug = System.getProperty(DEBUG_SERVLET);
    if (debug != null && debug.equalsIgnoreCase("true")) {
        //Trace//  w  w  w  .  j a va 2 s  .c  o  m
        System.out.println("Path info : " + request.getPathInfo());
        //End Trace
    }

    Path path = Path.from(request.getPathInfo());

    Action action;
    if (isGet(request) || isHead(request)) {
        action = Action.READ;
    } else if (isPut(request)) {
        action = Action.CREATE;
    } else if (isPost(request)) {
        action = Action.UPDATE;
    } else if (isDelete(request)) {
        action = Action.DELETE;
    } else {
        return null; // Unsupported request.
    }

    Map<String, ?> params = flat(request.getParameterMap());

    return new DefaultRequest(action, path, params); // TODO Detect JSON.
}