Example usage for javax.servlet.http HttpServletRequest getRequestURI

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

Introduction

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

Prototype

public String getRequestURI();

Source Link

Document

Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.

Usage

From source file:ar.com.zauber.commons.spring.web.controllers.InformationController.java

/**
 * @see AbstractController#handleRequest(HttpServletRequest,
 *      HttpServletResponse)/*from w w w  . j a  va2  s . c  o  m*/
 */
@Override
protected final ModelAndView handleRequestInternal(final HttpServletRequest request,
        final HttpServletResponse response) throws Exception {

    final String uri = request.getRequestURI().substring(request.getContextPath().length());

    if (uri.contains("..")) {
        throw new IllegalArgumentException("..");
    }
    final int i = uri.lastIndexOf('.');
    String view = (i == -1) ? uri : uri.substring(1, i);
    while (view.startsWith("/")) {
        view = view.substring(1);
    }
    while (view.endsWith("/")) {
        view = view.substring(0, view.length() - 1);
    }

    final Resource r = getApplicationContext()
            .getResource("/WEB-INF/templates/jsp/" + baseView + view + ".jsp");
    final ModelAndView ret;
    if (r.exists()) {
        ret = new ModelAndView(baseView + view);
    } else {
        response.sendError(404);
        ret = null;
    }
    return ret;
}

From source file:edu.usu.sdl.openstorefront.core.model.ErrorInfo.java

public ErrorInfo(Throwable error, HttpServletRequest request) {
    this.error = error;

    if (request != null) {
        requestUrl = request.getRequestURI();
        requestMethod = request.getMethod();
        clientIp = NetworkUtil.getClientIp(request);

        StringBuilder input = new StringBuilder();
        if (StringUtils.isNotBlank(request.getQueryString())) {
            input.append("Query: ").append(request.getQueryString()).append("\n");
        }/*  w w w.j  a  v  a  2 s.  co m*/

        inputData = input.toString();
    }
}

From source file:edu.usu.sdl.openstorefront.service.transfermodel.ErrorInfo.java

public ErrorInfo(Throwable error, HttpServletRequest request) {
    this.error = error;

    if (request != null) {
        requestUrl = request.getRequestURI();
        requestMethod = request.getMethod();
        clientIp = SecurityUtil.getClientIp(request);

        StringBuilder input = new StringBuilder();
        if (StringUtils.isNotBlank(request.getQueryString())) {
            input.append("Query: ").append(request.getQueryString()).append("\n");
        }//from  w ww.java  2  s .  co m

        inputData = input.toString();
    }
}

From source file:cn.sel.wetty.interceptor.AccessLogger.java

private void o(HttpServletRequest request, HttpServletResponse response) {
    String msg = String.format("%s\t[%s] -> %s \tStatus:%s\tHeaders:%s", request.getRequestURI(),
            request.getMethod(), request.getRemoteAddr(), response.getStatus(), getHeaders(response));
    LOGGER.info(msg);//from  ww w . j  ava 2  s . c  o m
}

From source file:com.alliander.osgp.shared.security.MellonTokenProcessingFilter.java

private boolean isLogoutRequest(final HttpServletRequest httpRequest) {
    return httpRequest.getRequestURI().equals(httpRequest.getServletContext().getContextPath() + "/logout");
}

From source file:com.jiwhiz.web.filter.StaticResourcesProductionFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    String contextPath = ((HttpServletRequest) request).getContextPath();
    String requestURI = httpRequest.getRequestURI();
    requestURI = StringUtils.substringAfter(requestURI, contextPath);
    if (StringUtils.equals("/", requestURI)) {
        requestURI = "/index.html";
    }/*  w w  w. j av  a  2  s  . c om*/
    String newURI = "/dist" + requestURI;
    request.getRequestDispatcher(newURI).forward(request, response);
}

From source file:com.kolich.curacao.util.helpers.UrlPathHelper.java

/**
 * Return the request URI for the given request, detecting an include request
 * URL if called within a RequestDispatcher include.
 * <p>As the value returned by {@code request.getRequestURI()} is <i>not</i>
 * decoded by the servlet container, this method will decode it.
 * <p>The URI that the web container resolves <i>should</i> be correct, but some
 * containers like JBoss/Jetty incorrectly include ";" strings like ";jsessionid"
 * in the URI. This method cuts off such incorrect appendices.
 * @param request current HTTP request//from  w  w  w.j av a 2 s  .  c  o  m
 * @return the request URI
 */
private final String getRequestUri(final HttpServletRequest request) {
    final String uri = request.getRequestURI();
    // <https://github.com/markkolich/curacao/issues/17>
    // Apparently it's possible for HttpServletRequest.getRequestURI() to
    // return null.  Looking at Jetty 9 source specifically, there is a case
    // in which the Servlet container could return null although the servlet
    // spec seems to imply that returning null is invalid/impossible.  I've
    // decided not to do anything about this and just ignore the fact that
    // the servlet container could be wrong and have bugs, and therefore,
    // it's not Curacao's job to work around those bugs by adding null
    // checks everywhere.
    return decodeAndCleanUriString(uri);
}

From source file:org.chos.transaction.passport.SessionInterceptor.java

/**
 * (Javadoc)/*from  w w w  .ja va2s  .c o m*/
 *
 * @see org.springframework.web.servlet.HandlerInterceptor#preHandle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
 */
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj)
        throws Exception {
    String requestUrl = request.getRequestURI().replace(request.getContextPath(), "");
    System.out.println(requestUrl);
    if (null != allowUrls && allowUrls.length >= 1) {
        for (String url : allowUrls) {
            if (requestUrl.contains(url)) {
                return true;
            }
        }
    }
    Session session = httpContextSessionManager.getSession(request);
    if (session != null) {
        return true; //true???postHandle(),  afterCompletion()
    }
    throw new SessionException();
}

From source file:info.magnolia.voting.voters.BasePatternVoter.java

protected String resolveURIFromValue(Object value) {
    String uri = null;/* w ww  .  j  a  v  a2s .  c  o m*/
    if (value instanceof String) {
        uri = (String) value;
    } else {
        if (MgnlContext.hasInstance()) {
            uri = MgnlContext.getAggregationState().getCurrentURI();
        } else {
            if (value instanceof HttpServletRequest) {
                HttpServletRequest request = (HttpServletRequest) value;
                uri = StringUtils.substringAfter(request.getRequestURI(), request.getContextPath());
            }
        }
    }
    return uri;
}

From source file:com.hypersocket.network.handlers.AbstractForwardingHandler.java

@Override
public boolean handlesRequest(HttpServletRequest request) {
    return request.getRequestURI().startsWith(server.resolvePath(path));
}