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.bradmcevoy.http.ServletRequest.java

public ServletRequest(HttpServletRequest r, ServletContext servletContext) {
    this.request = r;
    this.servletContext = servletContext;
    String sMethod = r.getMethod();
    method = Request.Method.valueOf(sMethod);
    String s = r.getRequestURL().toString(); //MiltonUtils.stripContext(r);
    url = s;/*w  ww  .  j av  a  2 s. c o m*/
    tlRequest.set(r);
    tlServletContext.set(servletContext);
}

From source file:org.intalio.tempo.web.controller.SecuredController.java

@Override
protected final ModelAndView processFormSubmission(HttpServletRequest request, HttpServletResponse response,
        Object command, BindException errors) throws Exception {
    ApplicationState state = getApplicationState(request);
    User currentUser = state.getCurrentUser();
    if (currentUser != null) {
        return super.processFormSubmission(request, response, command, errors);
    }//w ww .  j a  v  a  2s  .c o m
    // save request position 
    state.setPreviousAction(request.getRequestURL().toString());
    // redirect to login page
    return Constants.REDIRECTION_TO_LOGIN;
}

From source file:com.all.backend.web.controller.LoginServerController.java

@RequestMapping(method = POST, value = "/password")
@ResponseBody//from  w  w w  .  j a  v a2  s .c o m
public String resetRequest(@RequestBody String mail, HttpServletRequest request) {
    log.info("\nACTION:ForgotPasswordRequest");
    StringBuffer requestURL = request.getRequestURL();
    String url = requestURL.substring(0, requestURL.lastIndexOf("/") + 1) + "reset/";
    String forgotPasswordResult = userService.createPasswordResetRequest(mail, url);

    log.debug("forgotPasswordResult: " + forgotPasswordResult);
    String result = "";
    String[] resultAsarray = forgotPasswordResult.split(";");
    if (resultAsarray.length == 2) {
        result = resultAsarray[0];
        url = resultAsarray[1];
        PendingEmail pendingEmail = createPasswordPendingEmail(url, mail);
        BackendServiceHelper.queue(emailService, BackendConstants.SEND_RESET_PASSWORD_EMAIL_REQUEST_TYPE,
                pendingEmail);
    } else {
        result = forgotPasswordResult;
    }
    return result;
}

From source file:com.github.achatain.catalog.servlet.CollectionServlet.java

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {
    final String userId = getUserId(req);
    LOG.info(format("List all collections for user [%s]", userId) + req.getRequestURI());
    final List<CollectionDto> collections = collectionService.listCollections(userId);
    collections.forEach(col -> {/* w  w w . j a  v  a  2s. c o m*/
        final String href = format("%s%s", appendIfMissing(req.getRequestURL().toString(), "/"), col.getId());
        col.addLink(Link.create().withRel("self").withMethod(Link.Method.GET).withHref(href).build());
    });
    sendResponse(resp, collections);
}

From source file:eu.semlibproject.annotationserver.servlets.OpenIDAuthentication.java

private void authRequest(String identifier, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    try {//  w w  w  .j a  v  a  2s.c  o m
        String openIDReturnedURL = request.getRequestURL() + "?" + SemlibConstants.OPENID_RETURNED + "=1";

        // perform discovery on the user-supplied identifier
        List discoveries = consumerManager.discover(identifier);

        // attempt to associate with the OpenID provider
        // and retrieve one service endpoint for authentication
        DiscoveryInformation discovered = consumerManager.associate(discoveries);

        // store the discovery information in the user's session
        request.getSession().setAttribute(SemlibConstants.OPENID_DISC, discovered);

        // obtain a AuthRequest message to be sent to the OpenID provider
        AuthRequest authReq = consumerManager.authenticate(discovered, openIDReturnedURL);

        // Add attribute exchange to the requests
        addAttributesExchangeToRequest(authReq);

        // This is necessary send a request to an OpenID providers which
        // support popup mode (like Google, etc.).
        String url = authReq.getDestinationUrl(true);
        url = url + "&openid.ns.ui=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fui%2F1.0&openid.ui.mode=popup";

        response.sendRedirect(url);

    } catch (OpenIDException ex) {
        request.setAttribute(SemlibConstants.OPENID_AUTH_ERROR, "1");
        request.setAttribute(SemlibConstants.OPENID_ERROR_MESSAGE, ex.toString());
        logger.log(Level.SEVERE, null, ex);
        getServletContext().getRequestDispatcher(returnPath).forward(request, response);
    }
}

From source file:org.guanxi.sp.engine.service.saml2.DiscoveryProfileService.java

/** @see org.guanxi.sp.engine.service.generic.ProfileService#doProfile(javax.servlet.http.HttpServletRequest, String, String, org.guanxi.xal.saml2.metadata.GuardRoleDescriptorExtensions, String, org.guanxi.common.entity.EntityFarm) */
public ModelAndView doProfile(HttpServletRequest request, String guardID, String guardSessionID,
        GuardRoleDescriptorExtensions guardNativeMetadata, String entityID, EntityFarm farm)
        throws GuanxiException {
    ModelAndView mAndV = new ModelAndView();
    mAndV.setViewName(viewName);//from   ww  w.j a  v  a  2  s  .  c  o  m

    try {
        String edsURL = edsBaseURL + "?entityID=" + URLEncoder.encode(guardID, "UTF-8");
        edsURL += "&return=" + URLEncoder.encode(request.getRequestURL() + "?" + Guanxi.WAYF_PARAM_GUARD_ID
                + "=" + guardID + "&" + Guanxi.WAYF_PARAM_SESSION_ID + "=" + guardSessionID, "UTF-8");
        edsURL += "&returnIDParam=" + URLEncoder.encode("edsEntityID", "UTF-8");

        mAndV.getModel().put("edsURL", edsURL);
    } catch (UnsupportedEncodingException use) {
        logger.error("Could not encode EDS URL", use);
        mAndV.getModel().put("edsError", use.getMessage());
    }

    return mAndV;
}

From source file:pt.ist.applications.admissions.ui.ApplicationsAdmissionsController.java

@RequestMapping(value = "/candidate/{candidate}/generateLink", method = RequestMethod.POST)
public String candidateGenerateLink(@PathVariable Candidate candidate, final Model model,
        HttpServletRequest request) {
    if (Contest.canManageContests()) {
        String path = request.getRequestURL().substring(0, request.getRequestURL().length()
                - request.getRequestURI().length() + request.getContextPath().length());
        candidate.generateHash(path, messageSource);
    }/* w  ww .  ja  va  2s . c  o  m*/
    return "redirect:/admissions/candidate/" + candidate.getExternalId();
}

From source file:com.hobba.hobaserver.services.security.ChallengeUtil.java

private String getHobaTBS(HttpServletRequest request) {
    String header = request.getHeader("Authorized");
    String[] headerParams = header.split("[.]");
    String kid = headerParams[0];
    kid = new String(Base64.encodeBase64(kid.getBytes()));
    String chalenge = headerParams[1];
    String nonce = headerParams[2];

    String alg = "1";
    String origin = request.getRequestURL().toString();
    origin = origin.split("/")[0] + "//" + origin.split("/")[2] + "/";
    String hobaTbs = nonce + " " + alg + " " + origin + " " + kid + " " + chalenge;
    return hobaTbs;
}

From source file:com.acc.storefront.controllers.misc.FavIconController.java

@RequestMapping(value = "/favicon.ico", method = RequestMethod.GET)
public String getFavIcon(final HttpServletRequest request) {
    final String themeName = themeResolver.resolveThemeName(request);
    String iconPath = themeSource.getTheme(themeName).getMessageSource().getMessage(FAVICON_THEME_CODE,
            new Object[] {}, i18nService.getCurrentLocale());
    final String originalContextPath = (String) request.getAttribute(ORIGINAL_CONTEXT);

    if (originalContextPath != null) {
        final String requestUrl = String.valueOf(request.getRequestURL());
        iconPath = requestUrl.substring(0,
                requestUrl.indexOf(originalContextPath) + originalContextPath.length()) + "/" + iconPath;
    }//  w  ww .  j av a  2 s  .c o  m

    return REDIRECT_PREFIX + iconPath;
}

From source file:com.microsoft.aad.adal4jsample.BasicFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    if (request instanceof HttpServletRequest) {
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        HttpServletResponse httpResponse = (HttpServletResponse) response;
        try {//from  ww  w  . j av  a2 s . c  o  m
            String currentUri = httpRequest.getRequestURL().toString();
            String queryStr = httpRequest.getQueryString();
            String fullUrl = currentUri + (queryStr != null ? "?" + queryStr : "");

            // check if user has a AuthData in the session
            if (!AuthHelper.isAuthenticated(httpRequest)) {
                if (AuthHelper.containsAuthenticationData(httpRequest)) {
                    processAuthenticationData(httpRequest, currentUri, fullUrl);
                } else {
                    // not authenticated
                    sendAuthRedirect(httpRequest, httpResponse);
                    return;
                }
            }
            if (isAuthDataExpired(httpRequest)) {
                updateAuthDataUsingRefreshToken(httpRequest);
            }
        } catch (AuthenticationException authException) {
            // something went wrong (like expiration or revocation of token)
            // we should invalidate AuthData stored in session and redirect to Authorization server
            removePrincipalFromSession(httpRequest);
            sendAuthRedirect(httpRequest, httpResponse);
            return;
        } catch (Throwable exc) {
            httpResponse.setStatus(500);
            request.setAttribute("error", exc.getMessage());
            request.getRequestDispatcher("/error.jsp").forward(request, response);
        }
    }
    chain.doFilter(request, response);
}