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:org.schedoscope.metascope.service.MetascopeURLService.java

public String removeFromFilterURL(HttpServletRequest request, String key) {
    String queryParams = "";
    for (Entry<String, String[]> e : request.getParameterMap().entrySet()) {
        if (!e.getKey().equals(key)) {
            if (!queryParams.isEmpty()) {
                queryParams += URL_PARAMS_AND;
            }// w w w. j a v a2s. com
            queryParams += e.getKey() + URL_PARAMS_EQUALS + cleanseValue(e.getValue()[0]);
        }
    }
    return request.getRequestURL() + URL_PARAMS_DIVIDER + queryParams;
}

From source file:uk.ac.ebi.phenotype.web.proxy.ExternalUrlConfiguratbleProxyServlet.java

private String rewriteUrlFromResponse(HttpServletRequest servletRequest, String theUrl) {
    // TODO document example paths
    if (theUrl.startsWith(this.targetUri.toString())) {
        String curUrl = servletRequest.getRequestURL().toString();// no
        // query/*from  w  ww .j av  a2s  .c o  m*/
        String pathInfo = servletRequest.getPathInfo();
        if (pathInfo != null) {
            assert curUrl.endsWith(pathInfo);
            curUrl = curUrl.substring(0, curUrl.length() - pathInfo.length());// take pathInfo
            // off
        }
        theUrl = curUrl + theUrl.substring(this.targetUri.toString().length());
    }
    return theUrl;
}

From source file:de.hybris.platform.chinesepspalipaymockaddon.controllers.pages.AlipayMockController.java

@SuppressWarnings("boxing")
@RequestMapping(value = "", method = RequestMethod.GET)
public String doGetGateWay(final Model model, final HttpServletRequest request) {
    final Map<String, String[]> requestParamMap = request.getParameterMap();
    if (requestParamMap == null) {
        return AlipayMockControllerConstants.Pages.AlipayMockPage;
    }/*from   w  w  w .  j  a v  a  2s .c om*/
    final String baseGateWay = request.getRequestURL().toString();
    model.addAttribute("baseGateWay", baseGateWay);

    final Map<String, String> clearParams = removeUselessValue(requestParamMap);
    this.setCSRFToken(clearParams, request);

    final String service = request.getParameter("service");
    if (service == null) {
        return AlipayMockControllerConstants.Pages.AlipayMockPage;
    }
    XSSFilterUtil.filter(service);
    final boolean signIsValid = isSignValid(clearParams);
    model.addAttribute("signIsValid", Boolean.valueOf(signIsValid));
    model.addAttribute("params", clearParams);
    model.addAttribute("out_trade_no", clearParams.get("out_trade_no"));
    model.addAttribute("total_fee", clearParams.get("total_fee"));
    model.addAttribute("storefront", (StringUtils.substringBetween(request.getContextPath(), "/")));

    if ("refund_fastpay_by_platform_pwd".equals(service)) {
        return AlipayMockControllerConstants.Pages.AlipayRefundPage;
    }

    return AlipayMockControllerConstants.Pages.AlipayMockPage;
}

From source file:com.pedra.storefront.filters.cms.CMSSiteFilter.java

/**
 * Processing normal request (i.e. when user goes directly to that application - not from cmscockpit)
 * <p/>//from  ww  w. j  a  v  a  2s  . c o  m
 * <b>Note:</b> <br/>
 * We preparing application by setting correct:
 * <ul>
 * <li>Current Site</li>
 * <li>Current Catalog Versions</li>
 * <li>Enabled language fallback</li>
 * </ul>
 * 
 * @see ContextInformationLoader#initializeSiteFromRequest(String)
 * @see ContextInformationLoader#setCatalogVersions()
 * @param httpRequest
 *           current request
 * @param httpResponse
 *           the http response
 * @throws java.io.IOException
 */
protected boolean processNormalRequest(final HttpServletRequest httpRequest,
        final HttpServletResponse httpResponse) throws IOException {
    final String queryString = httpRequest.getQueryString();
    final String currentRequestURL = httpRequest.getRequestURL().toString();

    //set current site
    CMSSiteModel cmsSiteModel = getCurrentCmsSite();
    if (cmsSiteModel == null || StringUtils.contains(queryString, CLEAR_CMSSITE_PARAM)) {
        final String absoluteURL = StringUtils.removeEnd(currentRequestURL, "/")
                + (StringUtils.isBlank(queryString) ? "" : "?" + queryString);

        cmsSiteModel = getContextInformationLoader().initializeSiteFromRequest(absoluteURL);
    }

    if (cmsSiteModel == null) {
        // Failed to lookup CMS site
        httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, MISSING_CMS_SITE_ERROR_MESSAGE);
        return false;
    } else if (!SiteChannel.B2C.equals(cmsSiteModel.getChannel())) // Restrict to B2C channel
    {
        // CMS site that we looked up was for an unsupported channel
        httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, INCORRECT_CMS_SITE_CHANNEL_ERROR_MESSAGE);
        return false;
    }

    if (isNotActiveSite(cmsSiteModel)) {
        throw new IllegalStateException(
                "Site is not active. Active flag behaviour must be implement for this project.");
    }

    getContextInformationLoader().setCatalogVersions();
    //set fall back language enabled
    setFallbackLanguage(httpRequest, Boolean.TRUE);

    return true;
}

From source file:com.acc.storefront.filters.cms.CMSSiteFilter.java

/**
 * Processing normal request (i.e. when user goes directly to that application - not from cmscockpit)
 * <p/>/*  www. j  a  v a2s . co m*/
 * <b>Note:</b> <br/>
 * We preparing application by setting correct:
 * <ul>
 * <li>Current Site</li>
 * <li>Current Catalog Versions</li>
 * <li>Enabled language fallback</li>
 * </ul>
 * 
 * @see ContextInformationLoader#initializeSiteFromRequest(String)
 * @see ContextInformationLoader#setCatalogVersions()
 * @param httpRequest
 *           current request
 * @param httpResponse
 *           the http response
 * @throws java.io.IOException
 */
protected boolean processNormalRequest(final HttpServletRequest httpRequest,
        final HttpServletResponse httpResponse) throws IOException {
    final String queryString = httpRequest.getQueryString();
    final String currentRequestURL = httpRequest.getRequestURL().toString();

    //set current site
    CMSSiteModel cmsSiteModel = getCurrentCmsSite();
    if (cmsSiteModel == null || StringUtils.contains(queryString, CLEAR_CMSSITE_PARAM)) {
        final String absoluteURL = StringUtils.removeEnd(currentRequestURL, "/")
                + (StringUtils.isBlank(queryString) ? "" : "?" + queryString);

        cmsSiteModel = getContextInformationLoader().initializeSiteFromRequest(absoluteURL);
    }

    if (cmsSiteModel == null) {
        // Failed to lookup CMS site
        httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, MISSING_CMS_SITE_ERROR_MESSAGE);
        return false;
    } else if (!SiteChannel.B2C.equals(cmsSiteModel.getChannel())) // Restrict to B2C channel
    {
        // CMS site that we looked up was for an unsupported channel
        httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, INCORRECT_CMS_SITE_CHANNEL_ERROR_MESSAGE);
        return false;
    }

    if (!isActiveSite(cmsSiteModel)) {
        throw new IllegalStateException(
                "Site is not active. Active flag behaviour must be implement for this project.");
    }

    getContextInformationLoader().setCatalogVersions();
    //set fall back language enabled
    setFallbackLanguage(httpRequest, Boolean.TRUE);

    return true;
}

From source file:com.ctc.storefront.filters.cms.CMSSiteFilter.java

@Override
protected void doFilterInternal(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse,
        final FilterChain filterChain) throws ServletException, IOException {
    final String requestURL = httpRequest.getRequestURL().toString();

    final CmsPageRequestContextData cmsPageRequestContextData = getCmsPageContextService()
            .initialiseCmsPageContextForRequest(httpRequest);

    // check whether exits valid preview data
    if (cmsPageRequestContextData.getPreviewData() == null) {
        // process normal request (i.e. normal browser non-cmscockpit request)
        if (processNormalRequest(httpRequest, httpResponse)) {
            // proceed filters
            filterChain.doFilter(httpRequest, httpResponse);
        }//from www  .jav a2 s .co m
    } else if (StringUtils.contains(requestURL, PREVIEW_TOKEN)) {
        final String redirectURL = processPreviewRequest(httpRequest, cmsPageRequestContextData);

        // redirect to computed URL
        if (redirectURL.charAt(0) == '/') {
            final String contextPath = httpRequest.getContextPath();
            final String encodedRedirectUrl = httpResponse.encodeRedirectURL(contextPath + redirectURL);
            httpResponse.sendRedirect(encodedRedirectUrl);
        } else {
            final String encodedRedirectUrl = httpResponse.encodeRedirectURL(redirectURL);
            httpResponse.sendRedirect(encodedRedirectUrl);
        }

        // next filter in chain won't be invoked!!!
    } else {
        if (httpRequest.getSession().isNew()) {
            processPreviewData(httpRequest, cmsPageRequestContextData.getPreviewData());
        }
        // proceed filters
        filterChain.doFilter(httpRequest, httpResponse);
    }
}

From source file:dk.itst.oiosaml.sp.configuration.ConfigurationHandler.java

protected String getBaseUrl(HttpServletRequest request) {
    String url = request.getRequestURL().toString();
    log.info("url (old method): " + url);
    // might only be necessary because of my crazy pagekite setup --pdurbin
    //      url = request.getScheme()
    url = "https" + "://" + request.getServerName() + ":" + request.getServerPort() + request.getRequestURI();
    log.info("url (new method): " + url);
    int idx = url.lastIndexOf(request.getServletPath());

    return url.substring(0, idx + request.getServletPath().length());
}

From source file:com.exxonmobile.ace.hybris.storefront.filters.cms.CMSSiteFilter.java

/**
 * Processing normal request (i.e. when user goes directly to that application - not from cmscockpit)
 * <p/>/*w ww. j  a va  2 s  .  co  m*/
 * <b>Note:</b> <br/>
 * We preparing application by setting correct:
 * <ul>
 * <li>Current Site</li>
 * <li>Current Catalog Versions</li>
 * <li>Enabled language fallback</li>
 * </ul>
 * 
 * @see ContextInformationLoader#initializeSiteFromRequest(String)
 * @see ContextInformationLoader#setCatalogVersions()
 * @param httpRequest
 *            current request
 * @param httpResponse
 *            the http response
 * @throws java.io.IOException
 */
protected boolean processNormalRequest(final HttpServletRequest httpRequest,
        final HttpServletResponse httpResponse) throws IOException {
    final String queryString = httpRequest.getQueryString();
    final String currentRequestURL = httpRequest.getRequestURL().toString();

    // set current site
    CMSSiteModel cmsSiteModel = getCurrentCmsSite();
    if (cmsSiteModel == null || StringUtils.contains(queryString, CLEAR_CMSSITE_PARAM)) {
        final String absoluteURL = StringUtils.removeEnd(currentRequestURL, "/")
                + (StringUtils.isBlank(queryString) ? "" : "?" + queryString);

        cmsSiteModel = getContextInformationLoader().initializeSiteFromRequest(absoluteURL);
    }

    if (cmsSiteModel == null) {
        // Failed to lookup CMS site
        httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, MISSING_CMS_SITE_ERROR_MESSAGE);
        return false;
    } else if (!SiteChannel.B2B.equals(cmsSiteModel.getChannel())) // Restrict to B2B channel
    {
        // CMS site that we looked up was for an unsupported channel
        httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, INCORRECT_CMS_SITE_CHANNEL_ERROR_MESSAGE);
        return false;
    }

    if (!isActiveSite(cmsSiteModel)) {
        throw new IllegalStateException(
                "Site is not active. Active flag behaviour must be implement for this project.");
    }

    getContextInformationLoader().setCatalogVersions();
    // set fall back language enabled
    setFallbackLanguage(httpRequest, Boolean.TRUE);

    return true;
}

From source file:de.hybris.platform.ytelcoacceleratorstorefront.filters.cms.CMSSiteFilter.java

/**
 * Processing normal request (i.e. when user goes directly to that application - not from cmscockpit)
 * <p/>// w  ww  . j av  a2s  .  c om
 * <b>Note:</b> <br/>
 * We preparing application by setting correct:
 * <ul>
 * <li>Current Site</li>
 * <li>Current Catalog Versions</li>
 * <li>Enabled language fallback</li>
 * </ul>
 * 
 * @see ContextInformationLoader#initializeSiteFromRequest(String)
 * @see ContextInformationLoader#setCatalogVersions()
 * @param httpRequest
 *           current request
 * @param httpResponse
 *           the http response
 * @throws java.io.IOException
 */
protected boolean processNormalRequest(final HttpServletRequest httpRequest,
        final HttpServletResponse httpResponse) throws IOException {
    final String queryString = httpRequest.getQueryString();
    final String currentRequestURL = httpRequest.getRequestURL().toString();

    //set current site
    CMSSiteModel cmsSiteModel = getCurrentCmsSite();
    if (cmsSiteModel == null || StringUtils.contains(queryString, CLEAR_CMSSITE_PARAM)) {
        final String absoluteURL = StringUtils.removeEnd(currentRequestURL, "/")
                + (StringUtils.isBlank(queryString) ? "" : "?" + queryString);

        cmsSiteModel = getContextInformationLoader().initializeSiteFromRequest(absoluteURL);
    }

    if (cmsSiteModel == null) {
        // Failed to lookup CMS site
        httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, MISSING_CMS_SITE_ERROR_MESSAGE);
        return false;
    } else if (!SiteChannel.B2C.equals(cmsSiteModel.getChannel())
            && !SiteChannel.TELCO.equals(cmsSiteModel.getChannel())) // Restrict to B2C and Telco channel
    {
        // CMS site that we looked up was for an unsupported channel
        httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, INCORRECT_CMS_SITE_CHANNEL_ERROR_MESSAGE);
        return false;
    }

    if (!isActiveSite(cmsSiteModel)) {
        throw new IllegalStateException(
                "Site is not active. Active flag behaviour must be implement for this project.");
    }

    getContextInformationLoader().setCatalogVersions();
    //set fall back language enabled
    setFallbackLanguage(httpRequest, Boolean.TRUE);

    return true;
}

From source file:org.osiam.addons.selfadministration.registration.RegistrationService.java

public void sendRegistrationEmail(User user, HttpServletRequest request) {
    Optional<Email> email = SCIMHelper.getPrimaryOrFirstEmail(user);
    if (!email.isPresent()) {
        String message = "Could not register user. No email of user " + user.getUserName() + " found!";
        throw new InvalidAttributeException(message, "registration.exception.noEmail");
    }//www  .  j a  v  a 2 s  .c o  m

    StringBuffer requestURL = request.getRequestURL().append("/activation");

    String activationToken = user.getExtension(internalScimExtensionUrn).getFieldAsString(activationTokenField);

    String registrationLink = RegistrationHelper.createLinkForEmail(requestURL.toString(), user.getId(),
            "activationToken", activationToken);

    Map<String, Object> mailVariables = new HashMap<>();
    mailVariables.put("registrationLink", registrationLink);
    mailVariables.put("user", user);

    Locale locale = RegistrationHelper.getLocale(user.getLocale());

    renderAndSendEmailService.renderAndSendEmail("registration", fromAddress, email.get().getValue(), locale,
            mailVariables);
}