Example usage for javax.servlet.http HttpServletRequest getPathTranslated

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

Introduction

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

Prototype

public String getPathTranslated();

Source Link

Document

Returns any extra path information after the servlet name but before the query string, and translates it to a real path.

Usage

From source file:org.impalaframework.web.utils.WebPathUtils.java

public static void maybeLogRequest(HttpServletRequest request, Log logger) {

    if (logger.isDebugEnabled()) {
        logger.debug("Request context path: " + request.getContextPath());
        logger.debug("Request local address: " + request.getLocalAddr());
        logger.debug("Request local name: " + request.getLocalName());
        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());
    }/*from  w  ww.j  a v  a2  s .  c om*/
}

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. j av  a2  s  . co  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:org.impalaframework.extension.mvc.util.RequestModelHelper.java

/**
 * //from  w  w w  . j a  v a2s  .  c om
 * @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:org.opensingular.form.wicket.mapper.attachment.upload.AttachmentKeyFactory.java

public AttachmentKey makeFromRequestPathOrNull(HttpServletRequest req) {
    String rawKey = substringAfterLast(defaultString(req.getPathTranslated()), File.separator);
    if (!StringUtils.isBlank(rawKey)) {
        return new AttachmentKey(rawKey);
    }/*from   w  w  w. j  a  v  a  2  s  .c  om*/
    return null;
}

From source file:org.broadleafcommerce.admin.util.controllers.ListDirectoryController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    XmlDirectoryListing dirs = new XmlDirectoryListing();
    response.setContentType("text/xml");
    dirs.setDateFormat("MMM DD, yyyy");

    String basepath = request.getPathTranslated().substring(0, request.getPathTranslated().indexOf("ls"));
    dirs.generateXmlDirectoryListing(new File(basepath + rootDirectory), response.getOutputStream());

    return null;/*  w  w  w. ja  va 2  s.c om*/
}

From source file:MyServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();

    if (req.getPathInfo() != null) {
        out.println("The file \"" + req.getPathInfo() + "\"");
        out.println("Is stored at \"" + req.getPathTranslated() + "\"");
    } else {/*  w w  w.j  ava 2 s  .co m*/
        out.println("Path info is null, no file to lookup");
    }
}

From source file:nl.ordina.jtech.http2.java8.server.tomcat.SimpleImagePush.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    System.out.println("request path: " + req.getContextPath() + " >> " + req.getServletPath() + " >> "
            + req.getPathTranslated());

    if (req.getPathTranslated() != null && req.getPathTranslated().contains("dynamic-image")) {
        handleDynamicImage(req, resp);/*from w  w w.  ja va2s.c o m*/
    }

    final HttpSession session = req.getSession(true);
    System.out.println(" (possibly new) sessionid: " + session.getId() + ", requested sessionid: "
            + req.getRequestedSessionId() + ", from cookie: " + req.isRequestedSessionIdFromCookie()
            + ", valid: " + req.isRequestedSessionIdValid());

    /*
     * Result:
     * GET https://localhost:8443/http2-java8-example-1.0/return.gif?answer=42
     *  header: x-my-header=[bar]
     *  header: x-my-header-1=[foo]
     *  header: x-my-header-1=[zaphod]
     */
    // Tomcat impl: http://svn.apache.org/viewvc/tomcat/tc9.0.x/branches/gsoc-jaspic/java/org/apache/catalina/core/ApplicationPushBuilder.java?view=markup
    PushBuilder pb = req.getPushBuilder().path("return.gif") // path is the only required value

            // note: the browser does not show these headers - only the ones delivered in the pushed resource itself
            .setHeader("x-my-header", "overwritten by subsequent setHeader").setHeader("x-my-header", "bar")
            .addHeader("x-my-header-1", "foo").addHeader("x-my-header-1", "zaphod") // note: had expected this to be reported as x-my-header-1=[foo,zaphod] ?

            // GET is default
            // ?! "IllegalArgumentException - if the method set expects a request body (eg POST)"; does not happen; Tomcat does not enforce it!
            .method("POST")

            .queryString("answer=42")

            //.sessionId("some-session-id") // dropped?! "pushed request will include the session ID either as a Cookie or as a URI parameter"
            .sessionId(session.getId())

    ;
    final boolean pushResult;
    try {
        //pb.push(); // results in 'java.lang.NoSuchMethodError: javax.servlet.http.PushBuilder.push()V'
        // - Tomcat's Servlet 4.0 API version return type is boolean, not void!
        final Method push = pb.getClass().getMethod("push");
        pushResult = (boolean) push.invoke(pb);
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        if (e.getCause() instanceof UnsupportedOperationException) {
            respondWith(resp,
                    "<p>The following image was NOT provided via a push request! "
                            + "Cannot push over plain HTTP/1.x.</p>" + "<img src=\"" + req.getContextPath()
                            + "/return.gif\"/>");
            return;
        }
        respondWith(resp, e.getClass().getName() + ": " + e.getMessage() + ", cause: " + e.getCause());
        return;
    }

    simplePush(req, "Chrome Pony.png");
    simplePush(req, "second.html");

    respondWith(resp,
            "<p>The following static image was provided via a push request with result " + pushResult + "</p>"
                    + "<img src=\"" + req.getContextPath() + "/return.gif\"/><br/>"
                    + "<p>Dynamic push request: </p><img src=\"push/dynamic-image\"/><br/>"
                    + "<p><a href=\"second.html\">Link naar gepushte pagina</a></p>");
}

From source file:unUtils.ActionError.java

@Override
public Object doAction(WikittyPublicationContext context) {
    error.printStackTrace();/*from w  w w . j  a  va 2s  .c  o m*/

    HttpServletRequest req = context.getRequest();
    String result = "<html><body>Error: " + "<br>context: " + context + "<br>" + "<br>getContextPath: "
            + req.getContextPath() + "<br>getMethod: " + req.getMethod() + "<br>getPathInfo: "
            + req.getPathInfo() + "<br>getPathTranslated: " + req.getPathTranslated() + "<br>getQueryString: "
            + req.getQueryString() + "<br>getRemoteUser: " + req.getRemoteUser() + "<br>getRequestURI: "
            + req.getRequestURI() + "<br>getRequestURI: " + req.getRequestURI() + "<br>getRequestedSessionId: "
            + req.getRequestedSessionId() + "<br>getServletPath: " + req.getServletPath()
            + "<br>getCharacterEncoding: " + req.getCharacterEncoding() + "<br>getContentType: "
            + req.getContentType() + "<br>getLocalAddr: " + req.getLocalAddr() + "<br>getLocalName: "
            + req.getLocalName() + "<br>getProtocol: " + req.getProtocol() + "<br>getRemoteAddr: "
            + req.getRemoteAddr() + "<br>getRemoteHost: " + req.getRemoteHost() + "<br>getScheme: "
            + req.getScheme() + "<br>getServerName: " + req.getServerName() + "<br>" + "<br>error:<pre>"
            + StringEscapeUtils.escapeHtml(ExceptionUtil.stackTrace(error)) + "</pre>" + "</body></html>";
    return result;
}

From source file:org.openehealth.ipf.platform.camel.lbs.http.process.HttpResourceHandler.java

private ResourceList extractFromSingle(String subUnit, HttpServletRequest request) throws Exception {
    ResourceList resources = new ResourceList();
    handleResource(subUnit, resources, request.getContentType(), request.getPathTranslated(), null,
            request.getInputStream());/*from w  w  w .  java  2 s .  c o  m*/
    return resources;
}

From source file:org.b3log.latke.servlet.HTTPRequestDispatcher.java

/**
 * Serves./*from   w  w  w .  j a  v a 2s .  com*/
 *
 * @param request the specified HTTP servlet request
 * @param response the specified HTTP servlet response
 * @throws ServletException servlet exception
 * @throws IOException io exception
 */
@Override
protected void service(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {
    final String resourcePath = request.getPathTranslated();
    final String requestURI = request.getRequestURI();

    LOGGER.log(Level.FINEST, "Request[contextPath={0}, pathTranslated={1}, requestURI={2}]",
            new Object[] { request.getContextPath(), resourcePath, requestURI });

    if (StaticResources.isStatic(request)) {
        final RequestDispatcher requestDispatcher = getServletContext().getNamedDispatcher(defaultServletName);

        if (null == requestDispatcher) {
            throw new IllegalStateException("A RequestDispatcher could not be located for the default servlet ["
                    + this.defaultServletName + "]");
        }

        requestDispatcher.forward(request, response);
        return;
    }

    final long startTimeMillis = System.currentTimeMillis();

    request.setAttribute(Keys.HttpRequest.START_TIME_MILLIS, startTimeMillis);

    if (Latkes.isPageCacheEnabled()) {
        final String queryString = request.getQueryString();
        String pageCacheKey = (String) request.getAttribute(Keys.PAGE_CACHE_KEY);

        if (Strings.isEmptyOrNull(pageCacheKey)) {
            pageCacheKey = PageCaches.getPageCacheKey(requestURI, queryString);
            request.setAttribute(Keys.PAGE_CACHE_KEY, pageCacheKey);
        }
    }

    // Encoding configuration to filter/EncodingFilter

    final HTTPRequestContext context = new HTTPRequestContext();

    context.setRequest(request);
    context.setResponse(response);

    dispatch(context);
}