Example usage for javax.servlet.http HttpServletRequest getRequestURL

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

Introduction

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

Prototype

public StringBuffer getRequestURL();

Source Link

Document

Reconstructs the URL the client used to make the request.

Usage

From source file:io.kamax.mxisd.controller.identity.v1.SessionRestController.java

@RequestMapping(value = "/3pid/bind")
String bind(HttpServletRequest request, HttpServletResponse response, @RequestParam String sid,
        @RequestParam("client_secret") String secret, @RequestParam String mxid) {
    log.info("Requested: {}", request.getRequestURL(), request.getQueryString());
    try {//from  w ww. j a v  a2 s  .co m
        mgr.bind(sid, secret, mxid);
        return "{}";
    } catch (BadRequestException e) {
        log.info("requested session was not validated");

        JsonObject obj = new JsonObject();
        obj.addProperty("errcode", "M_SESSION_NOT_VALIDATED");
        obj.addProperty("error", e.getMessage());
        response.setStatus(HttpStatus.SC_BAD_REQUEST);
        return gson.toJson(obj);
    } finally {
        // If a user registers, there is no standard login event. Instead, this is the only way to trigger
        // resolution at an appropriate time. Meh at synapse/Riot!
        invMgr.lookupMappingsForInvites();
    }
}

From source file:com.wavemaker.commons.web.filter.EtagFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    //Disabling etag for ie browser as it is not honouring etag header.
    boolean requestedFromIeBrowser = isRequestFromIeBrowser(request);

    if (request.getRequestURL().indexOf("/services") != -1) {
        logger.debug("Etag Request for url {}, IE browser {}, user-agent {}, servlet Path {} ",
                request.getRequestURL(), requestedFromIeBrowser, request.getHeader("User-Agent"),
                request.getServletPath());
    }//  w  ww  .  ja  v  a 2 s .c  om

    //Setting no cache for ie as etag is disabled for it.
    if (requestedFromIeBrowser && (request.getServletPath().startsWith("/services")
            || request.getServletPath().startsWith("/app") || request.getServletPath().startsWith("/pages")
            || request.getServletPath().startsWith("/prefabs") || request.getServletPath().endsWith(".json"))) {
        response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1
        response.setHeader("Pragma", "no-cache"); // HTTP 1.0
        response.setDateHeader("Expires", 0); // Proxies.
    }
    if (HttpMethod.GET.name().equals(request.getMethod()) && !requestedFromIeBrowser) {
        response.setHeader("Cache-Control", "max-age=0"); // HTTP 1.1
        super.doFilterInternal(request, response, filterChain);
    } else {
        filterChain.doFilter(request, response);
    }

}

From source file:com.scooterframework.web.controller.ScooterRequestFilter.java

protected boolean isLocalRequest(HttpServletRequest request) {
    String requestURL = request.getRequestURL().toString();
    String remoteAddr = request.getRemoteAddr();
    String remoteHost = request.getRemoteHost();
    if (requestURL.startsWith(Constants.LOCAL_HOST_URL_PREFIX_1)
            || requestURL.startsWith(Constants.LOCAL_HOST_URL_PREFIX_2)
            || requestURL.startsWith(Constants.LOCAL_HOST_URL_PREFIX_3)
            || requestURL.startsWith(Constants.LOCAL_HOST_URL_PREFIX_4)
            || remoteAddr.equals(Constants.LOCAL_HOST_REMOTE_ADDRESS)
            || remoteHost.equals(Constants.LOCAL_HOST_REMOTE_HOST_1)
            || remoteHost.equals(Constants.LOCAL_HOST_REMOTE_HOST_2)) {
        return true;
    }//from www  .  ja v  a2  s.c o  m
    return false;
}

From source file:com.jayway.jaxrs.hateoas.web.RequestContextFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    final HttpServletRequest servletRequest = (HttpServletRequest) request;

    String requestURI = servletRequest.getRequestURI();
    requestURI = StringUtils.removeStart(requestURI,
            servletRequest.getContextPath() + servletRequest.getServletPath());
    String baseURL = StringUtils.removeEnd(servletRequest.getRequestURL().toString(), requestURI);
    UriBuilder uriBuilder = UriBuilder.fromUri(baseURL);

    RequestContext ctx = new RequestContext(uriBuilder,
            servletRequest.getHeader(RequestContext.HATEOAS_OPTIONS_HEADER));

    RequestContext.setRequestContext(ctx);
    try {//from  w w  w. j  a v  a2 s.  c o  m
        chain.doFilter(request, response);
    } finally {
        RequestContext.clearRequestContext();
    }
}

From source file:edu.duke.cabig.c3pr.utils.web.filter.GzipFilter.java

/**
 * Checks if the request uri is an include.
 * These cannot be gzipped.// w w  w . ja v a2 s.com
 */
private boolean isIncluded(final HttpServletRequest request) {
    final String uri = (String) request.getAttribute("javax.servlet.include.request_uri");
    final boolean includeRequest = !(uri == null);

    if (includeRequest && LOG.isDebugEnabled()) {
        LOG.debug(request.getRequestURL() + " resulted in an include request. This is unusable, because"
                + "the response will be assembled into the overall response. Not gzipping.");
    }
    return includeRequest;
}

From source file:io.kamax.mxisd.controller.identity.v1.SessionRestController.java

@RequestMapping(value = "/validate/{medium}/submitToken", method = POST)
public String validate(HttpServletRequest request, HttpServletResponse response, @RequestParam String sid,
        @RequestParam("client_secret") String secret, @RequestParam String token, Model model) {
    log.info("Requested: {}", request.getRequestURL());

    ValidationResult r = mgr.validate(sid, secret, token);
    log.info("Session {} was validated", sid);

    return gson.toJson(new SuccessStatusJson(true));
}

From source file:com.googlesource.gerrit.plugins.github.oauth.OAuthGitFilter.java

private URI getRequestUrlWithAlternatePath(HttpServletRequest httpRequest, String alternatePath)
        throws MalformedURLException {
    URL originalUrl = new URL(httpRequest.getRequestURL().toString());
    String contextPath = httpRequest.getContextPath();
    return URI.create(originalUrl.getProtocol() + "://" + originalUrl.getHost() + ":" + getPort(originalUrl)
            + contextPath + alternatePath);
}

From source file:gov.nih.nci.cabig.caaers.web.filters.GzipFilter.java

/**
 * Checks if the request uri is an include.
 * These cannot be gzipped.//w  ww.java2  s  .c o m
 */
private boolean isIncluded(final HttpServletRequest request) {
    final String uri = (String) request.getAttribute("javax.servlet.include.request_uri");
    final boolean includeRequest = !(uri == null);

    if (includeRequest && LOG.isDebugEnabled()) {
        LOG.debug(request.getRequestURL() + " resulted in an include request. This is unusable, because"
                + "the response will be assembled into the overrall response. Not gzipping.");
    }
    return includeRequest;
}

From source file:in.mycp.controller.LoginController.java

@RequestMapping(produces = "text/html")
public String main(HttpServletRequest req, HttpServletResponse resp) {
    logger.info("login " + req.getQueryString() + " {}{}{} " + req.getRequestURL() + " {}{}{} "
            + req.getRemoteAddr());/*from  www . j  av a  2s.c  o  m*/
    //HttpSession s = req.getSession(true);
    return "mycplogin";
}

From source file:com.fiveamsolutions.nci.commons.web.filter.SessionFixationProtectionFilter.java

/**
 * {@inheritDoc}/*w ww. j  a  v  a  2s  . c o m*/
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    HttpServletRequest hReq = (HttpServletRequest) request;
    HttpServletResponse hResp = (HttpServletResponse) response;
    if (hReq.isRequestedSessionIdFromURL()) {
        String requestUrl = hReq.getRequestURL().toString();
        String queryStr = hReq.getQueryString();
        StringBuilder url = new StringBuilder(JSESSIONID_REGEX.matcher(requestUrl).replaceAll(""));
        if (!StringUtils.isEmpty(queryStr)) {
            url.append("?").append(JSESSIONID_REGEX.matcher(queryStr).replaceAll(""));
        }
        hResp.setHeader("Location", url.toString());
        hResp.sendError(HttpServletResponse.SC_MOVED_PERMANENTLY);
        return;
    }

    SessionIdBlockingResponse wrapped = new SessionIdBlockingResponse((HttpServletResponse) response);
    chain.doFilter(request, wrapped);
}