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:com.razorfish.controllers.misc.StoreSessionController.java

protected String getReturnRedirectUrlForUrlEncoding(final HttpServletRequest request, final String old,
        final String current) {
    String referer = StringUtils.remove(request.getRequestURL().toString(), request.getServletPath());
    if (!StringUtils.endsWith(referer, "/")) {
        referer = referer + "/";
    }//from  ww  w .  j  av a 2  s  . co  m
    if (referer != null && !referer.isEmpty() && StringUtils.contains(referer, "/" + old + "/")) {
        return REDIRECT_PREFIX + StringUtils.replace(referer, "/" + old + "/", "/" + current + "/");
    }
    return REDIRECT_PREFIX + referer;
}

From source file:org.energyos.espi.common.utils.StringToLongFilter.java

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

    if (logger.isDebugEnabled()) {

        logger.debug("StringToLongFilter processing");

        HttpServletRequest httpRequest = (HttpServletRequest) request;
        HttpServletResponse httpResponse = (HttpServletResponse) response;

        logger.debug("Request is " + httpRequest.getClass());
        logger.debug("Request URL: " + httpRequest.getRequestURL());
        logger.debug("Request Method is '" + httpRequest.getMethod() + "'");
        logger.debug("Response is " + httpResponse.getClass());

    }/*from   w ww . j av a2 s.  c  o  m*/

    // TODO: Add Long to String conversion logic

    filterChain.doFilter(request, response);
}

From source file:flex.messaging.services.http.proxy.ProxyContextFilter.java

protected void setupInitialProperties(ProxyContext context) {
    HttpServletRequest clientRequest = FlexContext.getHttpRequest();
    if (clientRequest != null) {
        String reqURL = clientRequest.getRequestURL().toString();
        int idx = reqURL.indexOf(':');
        String reqProto = reqURL.substring(0, idx);
        context.setClientHttps(reqProto.equalsIgnoreCase("https"));

        // set up disableCaching variable since its used in sendException
        String userAgent = clientRequest.getHeader("User-Agent");
        context.setDisableCaching(/* w ww .  ja  va2 s. c o  m*/
                context.isClientHttps() && userAgent != null && userAgent.indexOf("MSIE") != -1);
    }
}

From source file:org.consultjr.mvc.core.components.ApplicationInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    String queryString = request.getQueryString();
    String uri = request.getRequestURI();
    StringBuffer url = request.getRequestURL();
    HttpSession session = this.getSession(request);
    Enumeration attributes = session.getAttributeNames();
    Map<String, Object> sessionAttributes = new HashMap<>();

    logger.debug("URL: {}", url);
    logger.debug("URI: {}", uri);
    logger.debug("QUERY STRING: {}", queryString);

    logger.debug("Handler Object: {}", handler);

    while (attributes.hasMoreElements()) {
        String name = (String) attributes.nextElement();

        sessionAttributes.put(name, session.getAttribute(name));
    }//ww w  . j  av  a  2s  .c  o m

    logger.debug("Session: {}", sessionAttributes);

    return true;
}

From source file:com.enonic.cms.web.main.UpgradeController.java

/**
 * Redirect to self.//from  ww  w.j a  va2s . c o m
 */
private void redirectToSelf(HttpServletRequest req, HttpServletResponse res) throws Exception {
    String url = req.getRequestURL().toString();
    int index = url.indexOf("?");

    if (index > -1) {
        url = url.substring(0, index);
    }

    // change '/upgrade_db [GET]' to '/upgrade [POST]'
    index = url.lastIndexOf("/");
    if (index > -1) {
        url = url.substring(0, index);
    }

    res.sendRedirect(url + "/upgrade");
}

From source file:com.sun.socialsite.web.filters.DebugFilter.java

/**
 * Inspect incoming urls and see if they should be routed.
 *//*from   ww w . j  a  va  2 s. c  o  m*/
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {

    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    log.info("--- entering");
    log.info(request.getMethod() + " " + request.getRequestURL().toString());
    log.info("st=" + request.getParameter("st"));

    // print out session details
    HttpSession session = request.getSession(false);
    if (session != null) {
        log.info("inbound session contains:");
        Enumeration foo = session.getAttributeNames();
        while (foo.hasMoreElements()) {
            String attr = (String) foo.nextElement();
            log.info("   " + attr + " = " + session.getAttribute("attr"));
        }
    }

    // keep going
    chain.doFilter(request, response);

    // print out session details
    session = request.getSession(false);
    if (session != null) {
        log.info("outbound session contains:");
        Enumeration bar = session.getAttributeNames();
        while (bar.hasMoreElements()) {
            String attr = (String) bar.nextElement();
            log.info("    " + attr + " = " + session.getAttribute("attr"));
        }
    }

    log.info("--- exiting");
}

From source file:net.oneandone.stool.overview.GoController.java

@RequestMapping(value = "/**", method = RequestMethod.GET)
public ModelAndView goToStage(HttpServletRequest httpServletRequest)
        throws IOException, SAXException, NamingException, UserNotFound, EnumerationFailed {
    String requestetStage = httpServletRequest.getServletPath().replace("/go/", "");
    String baseurl = httpServletRequest.getRequestURL().toString();
    baseurl = baseurl.substring(0, baseurl.indexOf('/', 8));

    if (!session.wrappers.join(requestetStage).exists()) {
        return new ModelAndView("redirect:" + baseurl + "/#!404:" + requestetStage);
    }/*w  w w .  j  av  a2 s  . c o m*/

    StageInfo stage = StageGatherer.get(requestetStage, session, users);

    switch (stage.getRunning()) {
    case "up":
        return new ModelAndView("redirect:" + stage.getUrls().values().toArray()[0]);
    default:
        return new ModelAndView("redirect:" + baseurl + "/#!500!" + stage.getName() + "!" + stage.getRunning());
    }
}

From source file:com.chessix.vas.web.RequestProcessingTimeInterceptor.java

@Override
public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response,
        final Object handler) throws Exception {
    if (log.isDebugEnabled()) {
        final long startTime = System.currentTimeMillis();
        log.debug("Request URL::{}:: Start", request.getRequestURL());
        request.setAttribute(START_TIME, startTime);
    }//from  w  w w .  j  a  v  a  2 s . c  o m
    return super.preHandle(request, response, handler);
}

From source file:com.work.petclinic.web.GeneralController.java

@ExceptionHandler(Exception.class)
public ModelAndView handleException(HttpServletRequest req, Exception e) {
    log.warn("In handleException", e);

    ModelAndView mav = new ModelAndView();
    mav.addObject("exception", e);
    mav.addObject("timestamp", new Date());
    mav.addObject("url", req.getRequestURL());
    mav.setViewName("exception");
    return mav;/*from w  w w  . java2  s.co m*/
}

From source file:fr.aliasource.webmail.server.LoginFilter.java

private String computeMyUrl(HttpServletRequest hreq, HttpServletResponse resp) {
    StringBuilder ret = new StringBuilder(hreq.getRequestURL().toString());
    if (hreq.getQueryString() != null) {
        ret.append("?");
        ret.append(hreq.getQueryString());
    }//  w  ww. j ava  2 s . c o m
    try {
        return URLEncoder.encode(resp.encodeRedirectURL(ret.toString()), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        return hreq.getRequestURL().toString();
    }
}