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:com.centeractive.ws.server.endpoint.GenericContextDomEndpoint.java

private RequestResponder getRequestResponderBySessionRequestContextPath() {
    HttpServletRequest htpServletRequest = getHttpServletRequest();
    return getRequestResponderByRequestContextPath(htpServletRequest.getRequestURI());
}

From source file:de.adorsys.oauth.authdispatcher.FixedServletUtils.java

/**
 * Reconstructs the request URL string for the specified servlet
 * request. The host part is always the local IP address. The query
 * string and fragment is always omitted.
 *
 * @param request The servlet request. Must not be {@code null}.
 *
 * @return The reconstructed request URL string.
 *//*from  w  ww .  ja  v a2s .c  o m*/
private static String reconstructRequestURLString(final HttpServletRequest request) {

    StringBuilder sb = new StringBuilder("http");

    if (request.isSecure())
        sb.append('s');

    sb.append("://");

    String localAddress = request.getLocalAddr();

    if (localAddress.contains(".")) {
        // IPv3 address
        sb.append(localAddress);
    } else if (localAddress.contains(":")) {
        // IPv6 address, see RFC 2732
        sb.append('[');
        sb.append(localAddress);
        sb.append(']');
    } else {
        // Don't know what to do
    }

    if (!request.isSecure() && request.getLocalPort() != 80) {
        // HTTP plain at port other than 80
        sb.append(':');
        sb.append(request.getLocalPort());
    }

    if (request.isSecure() && request.getLocalPort() != 443) {
        // HTTPS at port other than 443 (default TLS)
        sb.append(':');
        sb.append(request.getLocalPort());
    }

    String path = request.getRequestURI();

    if (path != null)
        sb.append(path);

    return sb.toString();
}

From source file:com.lohika.alp.reporter.fe.controller.LogController.java

@RequestMapping(method = RequestMethod.GET, value = "/results/test-method/{testMethodId}/log/{name}")
void getLogBinary(HttpServletRequest request, HttpServletResponse response,
        @PathVariable("testMethodId") long id) throws IOException {

    String uri = request.getRequestURI();

    String[] parts = uri.split("/");
    String name = parts[parts.length - 1];

    InputStream is = logStorage.getLog(id, name);

    OutputStream os = response.getOutputStream();

    int c;//from   w w  w.jav  a  2s. c o m
    while ((c = is.read()) != -1)
        os.write(c);
}

From source file:org.intalio.tempo.web.LoginFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    if (request instanceof HttpServletRequest) {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;

        if (req.getRequestURI().endsWith("/login.htm") || req.getRequestURI().endsWith("/login")) {
            // don't protect login page
            chain.doFilter(request, response);
            return;
        }//from   ww w. ja  v  a2s . c  om

        String secureSession = LoginController.getSecureRandomSession(req);
        String secureCookie = LoginController.getSecureRandomCookie(req);
        if (secureSession != null) {
            if (secureSession.equals(secureCookie)) {
                // already authenticated
                chain.doFilter(request, response);
                return;
            }
        }

        WebApplicationContext context = WebApplicationContextUtils
                .getRequiredWebApplicationContext(req.getSession().getServletContext());
        LoginController login = (LoginController) context.getBean("loginController");
        if (login == null)
            throw new IllegalStateException("Missing 'loginController' object in Spring webapp context");

        User user = login.getCurrentUser(req);
        if (user == null) {
            // authentication failed or not available
            LOG.info("User not logged in, redirecting to login page: " + login.getLoginPageURL());
            LoginController.setRedirectAfterLoginCookie(resp, req.getRequestURI());
            resp.sendRedirect(login.getLoginPageURL());
        } else {
            // authenticated: synchronize secure random
            if (secureCookie != null) {
                LoginController.setSecureRandomSession(req, secureCookie);
            } else {
                LoginController.generateSecureRandom(req, resp);
            }
            ApplicationState state = login.getApplicationState(req);
            if (state != null) {
                state.setCurrentUser(user);
            }
            chain.doFilter(request, response);
        }
    } else {
        LOG.warn("ServletRequest was not HttpServletRequest; ignoring request.");
    }
}

From source file:com.dreambox.web.logger.LoggingFilter.java

@Override
protected void logRequest(HttpServletRequest request) {
    String uri = request.getRequestURI();
    if (isIgnoreUri(uri)) {
        return;// w w w. j  av  a 2 s  .c  o m
    }
    request.setAttribute(REQUEST_START_TIME, System.currentTimeMillis());
    HttpSession session = request.getSession(false);
    String id = "";
    if (session != null) {
        id = session.getId();
    } else {
        id = UUID.randomUUID().toString();
    }
    request.setAttribute(REQUEST_ID_ATTR, id);
    String method = request.getMethod();
    String queryStr = request.getQueryString();
    String parameter = getRequestParams(request);
    String ip = IPUtil.getClientIP(request);
    Map<String, String> commonPara = new HashMap<String, String>();
    commonPara.put("ip", ip);
    commonPara.put("method", method);
    commonPara.put("queryStr", queryStr);
    commonPara.put("parameter", parameter);
    threadLocalMap.set(commonPara);
    // log all request
    l4jlogger.info(String.format(REQUEST_LOG_FORMAT, now(), id, ip, method, uri, queryStr, parameter));
}

From source file:com.doculibre.constellio.filters.LocalRequestFilter.java

private boolean isIgnoredRequest(ServletRequest request) {
    boolean ignoredRequest = false;
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    String contextPath = httpRequest.getContextPath();
    String requestURI = httpRequest.getRequestURI();
    String contextRelativePath = requestURI.substring(contextPath.length());
    for (String ignoredPrefix : ignoredPrefixes) {
        ignoredRequest = contextRelativePath.startsWith(ignoredPrefix);
        if (ignoredRequest) {
            break;
        }/*from w  ww .ja v  a 2 s .  c  o  m*/
    }
    return ignoredRequest;
}

From source file:com.tce.oauth2.spring.client.filters.SessionDataFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse resp = (HttpServletResponse) response;

    // Todo Controller is not authorized for anonymous user
    if (req.getRequestURI().indexOf("/todos") != -1) {
        if (req.getSession().getAttribute("username") == null) {
            resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
        } else {/*from w  ww.  j a va  2s.  co m*/
            filterChain.doFilter(request, response);
        }
    } else {
        filterChain.doFilter(request, response);
    }
}

From source file:gridgrid.Web.java

@RequestMapping(value = "/*", produces = MediaType.TEXT_HTML_VALUE)
public String get(Model model, HttpServletRequest request) throws IOException {
    File file = new File("./hogan.xlsx");
    load(file);/*  ww  w  .ja  va 2 s .c o m*/
    CodeView codeView = map.get(request.getRequestURI());
    try {
        codeView.runCode();
        return codeView.getView();
    } catch (ScriptException e) {
        return e.getMessage();
    }
}

From source file:com.googlesource.gerrit.plugins.github.wizard.VelocityControllerServlet.java

private void redirectToNextStep(HttpServletRequest req, HttpServletResponse resp)
        throws IOException, ServletException {
    String sourceUri = req.getRequestURI();
    int pathPos = sourceUri.lastIndexOf('/') + 1;
    String sourcePage = sourceUri.substring(pathPos);
    String sourcePath = sourceUri.substring(0, pathPos);
    int queryStringStart = sourcePage.indexOf('?');
    if (queryStringStart > 0) {
        sourcePage = sourcePage.substring(0, queryStringStart);
    }//w ww . jav  a  2  s  . co m
    NextPage nextPage = githubConfig.getNextPage(sourcePage);
    if (nextPage != null) {
        if (nextPage.redirect) {
            resp.sendRedirect(nextPageURL(sourcePath, nextPage));
        } else {
            RequestDispatcher requestDispatcher = req.getRequestDispatcher(nextPageURL(sourcePath, nextPage));
            req.setAttribute("destUrl", nextPage);
            requestDispatcher.forward(req, resp);
        }
    }
}

From source file:org.venice.beachfront.bfapi.services.GeoServerProxyService.java

public ResponseEntity<byte[]> proxyRequest(HttpServletRequest request)
        throws MalformedURLException, IOException, URISyntaxException, UserException {
    String requestPath = request.getRequestURI();
    // Form the complete URI by piecing together the GeoServer URL with the API proxy request parameters
    URI requestUri = new URI(geoserverUrl.getProtocol(), null, geoserverUrl.getHost(), geoserverUrl.getPort(),
            requestPath, request.getQueryString(), null);
    // Double encoding takes place here. First, in the REST Request delivered to API by the client. Second, in the
    // translation to the URI object. Decode both of these steps to get the real, completely decoded request to
    // GeoServer.
    String decodedUrl = URLDecoder.decode(requestUri.toString(), "UTF-8");
    decodedUrl = URLDecoder.decode(decodedUrl.toString(), "UTF-8");
    piazzaLogger.log(String.format("Proxying request to GET GeoServer at URI %s", decodedUrl),
            Severity.INFORMATIONAL);
    try {//w  w w. j ava2  s.  c  o  m
        ResponseEntity<byte[]> response = restTemplate.exchange(decodedUrl, HttpMethod.GET, requestHeaders,
                byte[].class);
        return response;
    } catch (HttpClientErrorException | HttpServerErrorException exception) {
        piazzaLogger.log(String.format("Received GeoServer error response, code=%d, length=%d, for URI %s",
                exception.getStatusCode().value(), exception.getResponseBodyAsString().length(), decodedUrl),
                Severity.ERROR);
        if (exception.getStatusCode().equals(HttpStatus.UNAUTHORIZED)
                || exception.getStatusCode().equals(HttpStatus.FORBIDDEN)) {
            throw new UserException("Bad Authentication with GeoServer", exception,
                    exception.getResponseBodyAsString(), HttpStatus.BAD_REQUEST);
        }
        throw new UserException("Upstream GeoServer error", exception, exception.getResponseBodyAsString(),
                exception.getStatusCode());
    }
}