Example usage for org.springframework.web.context.request RequestContextHolder currentRequestAttributes

List of usage examples for org.springframework.web.context.request RequestContextHolder currentRequestAttributes

Introduction

In this page you can find the example usage for org.springframework.web.context.request RequestContextHolder currentRequestAttributes.

Prototype

public static RequestAttributes currentRequestAttributes() throws IllegalStateException 

Source Link

Document

Return the RequestAttributes currently bound to the thread.

Usage

From source file:com.cws.us.pws.controllers.AboutController.java

@RequestMapping(value = "/careers/career/{reqId}", method = RequestMethod.GET)
public final ModelAndView showCareer(@PathVariable("reqId") final String reqId) {
    final String methodName = AboutController.CNAME
            + "#showCareer(@PathVariable(\"reqId\") final String reqId)";

    if (DEBUG) {//  ww  w  .  jav a2  s  .com
        DEBUGGER.debug(methodName);
    }

    ModelAndView mView = new ModelAndView();

    final ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
            .currentRequestAttributes();
    final HttpServletRequest hRequest = requestAttributes.getRequest();
    final HttpSession hSession = hRequest.getSession();

    if (DEBUG) {
        DEBUGGER.debug("ServletRequestAttributes: {}", requestAttributes);
        DEBUGGER.debug("HttpServletRequest: {}", hRequest);
        DEBUGGER.debug("HttpSession: {}", hSession);

        DEBUGGER.debug("Dumping session content:");
        @SuppressWarnings("unchecked")
        Enumeration<String> sessionEnumeration = hSession.getAttributeNames();

        while (sessionEnumeration.hasMoreElements()) {
            String sessionElement = sessionEnumeration.nextElement();
            Object sessionValue = hSession.getAttribute(sessionElement);

            DEBUGGER.debug("Attribute: " + sessionElement + "; Value: " + sessionValue);
        }

        DEBUGGER.debug("Dumping request content:");
        @SuppressWarnings("unchecked")
        Enumeration<String> requestEnumeration = hRequest.getAttributeNames();

        while (requestEnumeration.hasMoreElements()) {
            String requestElement = requestEnumeration.nextElement();
            Object requestValue = hRequest.getAttribute(requestElement);

            DEBUGGER.debug("Attribute: " + requestElement + "; Value: " + requestValue);
        }

        DEBUGGER.debug("Dumping request parameters:");
        @SuppressWarnings("unchecked")
        Enumeration<String> paramsEnumeration = hRequest.getParameterNames();

        while (paramsEnumeration.hasMoreElements()) {
            String requestElement = paramsEnumeration.nextElement();
            Object requestValue = hRequest.getParameter(requestElement);

            DEBUGGER.debug("Parameter: " + requestElement + "; Value: " + requestValue);
        }
    }

    try {
        Career career = new Career();
        career.setJobReqId(reqId);

        if (DEBUG) {
            DEBUGGER.debug("Career: {}", career);
        }

        CareerRequest request = new CareerRequest();
        request.setCareer(career);
        request.setLang(
                (StringUtils.isBlank(hRequest.getParameter("lang"))) ? "en" : hRequest.getParameter("lang"));

        if (DEBUG) {
            DEBUGGER.debug("CareerRequest: {}", request);
        }

        CareerResponse response = this.careerRefSvc.getCareerData(request);

        if (DEBUG) {
            DEBUGGER.debug("CareerResponse: {}", response);
        }

        if (response.getRequestStatus() == CoreServicesStatus.SUCCESS) {
            mView.addObject("career", response.getCareer());
        } else {
            mView.addObject(Constants.ERROR_MESSAGE, this.messageNoCareerLocated);
        }
    } catch (CareerRequestException crx) {
        ERROR_RECORDER.error(crx.getMessage(), crx);

        mView = new ModelAndView(new RedirectView());
        mView.setViewName(this.appConfig.getErrorResponsePage());
    }

    mView.setViewName(this.careersPage);

    if (DEBUG) {
        DEBUGGER.debug("ModelAndView: {}", mView);
    }

    return mView;
}

From source file:edu.dfci.cccb.mev.dataset.rest.controllers.WorkspaceController.java

@RequestMapping(method = GET, value = "/session/close")
@ResponseStatus(OK)// w  w  w. ja v  a2  s .  com
public void closeSession() {
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
            .currentRequestAttributes();
    HttpSession session = attributes.getRequest().getSession(true);
    session.invalidate();
}

From source file:org.kmnet.com.fw.web.token.transaction.HttpSessionTransactionTokenStore.java

/**
 * Returns {@link HttpServletRequest} from request context<br>
 * @return http request in this context/*from w w w.  j av a  2s.  c  om*/
 */
HttpServletRequest getRequest() {
    return ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
}

From source file:com.cws.us.pws.controllers.CommonController.java

@RequestMapping(value = "/contact", method = RequestMethod.GET)
public final ModelAndView showMessagingPage() {
    final String methodName = CommonController.CNAME + "#showMessagingPage()";

    if (DEBUG) {/*from ww  w .ja  v  a 2s. c  om*/
        DEBUGGER.debug(methodName);
    }

    ModelAndView mView = new ModelAndView();

    final ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
            .currentRequestAttributes();
    final HttpServletRequest hRequest = requestAttributes.getRequest();
    final HttpSession hSession = hRequest.getSession();

    if (DEBUG) {
        DEBUGGER.debug("ServletRequestAttributes: {}", requestAttributes);
        DEBUGGER.debug("HttpServletRequest: {}", hRequest);
        DEBUGGER.debug("HttpSession: {}", hSession);
        DEBUGGER.debug("Session ID: {}", hSession.getId());

        DEBUGGER.debug("Dumping session content:");
        @SuppressWarnings("unchecked")
        Enumeration<String> sessionEnumeration = hSession.getAttributeNames();

        while (sessionEnumeration.hasMoreElements()) {
            String sessionElement = sessionEnumeration.nextElement();
            Object sessionValue = hSession.getAttribute(sessionElement);

            DEBUGGER.debug("Attribute: " + sessionElement + "; Value: " + sessionValue);
        }

        DEBUGGER.debug("Dumping request content:");
        @SuppressWarnings("unchecked")
        Enumeration<String> requestEnumeration = hRequest.getAttributeNames();

        while (requestEnumeration.hasMoreElements()) {
            String requestElement = requestEnumeration.nextElement();
            Object requestValue = hRequest.getAttribute(requestElement);

            DEBUGGER.debug("Attribute: " + requestElement + "; Value: " + requestValue);
        }

        DEBUGGER.debug("Dumping request parameters:");
        @SuppressWarnings("unchecked")
        Enumeration<String> paramsEnumeration = hRequest.getParameterNames();

        while (paramsEnumeration.hasMoreElements()) {
            String requestElement = paramsEnumeration.nextElement();
            Object requestValue = hRequest.getParameter(requestElement);

            DEBUGGER.debug("Parameter: " + requestElement + "; Value: " + requestValue);
        }
    }

    mView.addObject("svcAddress", this.appConfig.getServiceEmail());
    mView.addObject("command", new EmailMessage());
    mView.setViewName(this.appConfig.getContactPage());

    if (DEBUG) {
        DEBUGGER.debug("ModelAndView: {}", mView);
    }

    return mView;
}

From source file:com.cws.us.pws.controllers.ProductController.java

@RequestMapping(value = "/search", method = RequestMethod.POST)
public final ModelAndView searchProducts(@ModelAttribute("request") final Product request,
        final BindingResult binding) {
    final String methodName = ProductController.CNAME
            + "#searchProducts(@ModelAttribute(\"request\") final Product request, final BindingResult binding)";

    if (DEBUG) {// w w w  .  ja  v  a2  s .  co m
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Product: {}", request);
    }

    // String viewName = null;
    ProductResponse productResponse = null;
    ModelAndView mView = new ModelAndView();

    final ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
            .currentRequestAttributes();
    final HttpServletRequest hRequest = requestAttributes.getRequest();
    final HttpSession hSession = hRequest.getSession();
    final String lang = hRequest.getParameter(Constants.PARAMETER_LANG);

    if (DEBUG) {
        DEBUGGER.debug("ServletRequestAttributes: {}", requestAttributes);
        DEBUGGER.debug("HttpServletRequest: {}", hRequest);
        DEBUGGER.debug("HttpSession: {}", hSession);
        DEBUGGER.debug("lang: {}", lang);

        DEBUGGER.debug("Dumping session content:");
        @SuppressWarnings("unchecked")
        Enumeration<String> sessionEnumeration = hSession.getAttributeNames();

        while (sessionEnumeration.hasMoreElements()) {
            String sessionElement = sessionEnumeration.nextElement();
            Object sessionValue = hSession.getAttribute(sessionElement);

            DEBUGGER.debug("Attribute: " + sessionElement + "; Value: " + sessionValue);
        }

        DEBUGGER.debug("Dumping request content:");
        @SuppressWarnings("unchecked")
        Enumeration<String> requestEnumeration = hRequest.getAttributeNames();

        while (requestEnumeration.hasMoreElements()) {
            String requestElement = requestEnumeration.nextElement();
            Object requestValue = hRequest.getAttribute(requestElement);

            DEBUGGER.debug("Attribute: " + requestElement + "; Value: " + requestValue);
        }

        DEBUGGER.debug("Dumping request parameters:");
        @SuppressWarnings("unchecked")
        Enumeration<String> paramsEnumeration = hRequest.getParameterNames();

        while (paramsEnumeration.hasMoreElements()) {
            String requestElement = paramsEnumeration.nextElement();
            Object requestValue = hRequest.getParameter(requestElement);

            DEBUGGER.debug("Parameter: " + requestElement + "; Value: " + requestValue);
        }
    }

    try {
        ProductRequest productRequest = new ProductRequest();
        productRequest.setProduct(request);
        productRequest.setLang((StringUtils.isBlank(lang)) ? "en" : lang);

        if (DEBUG) {
            DEBUGGER.debug("ProductRequest: {}", productRequest);
        }

        productResponse = this.productRefSvc.getProductData(productRequest);

        if (DEBUG) {
            DEBUGGER.debug("ProductResponse: {}", productResponse);
        }

        if (productResponse.getRequestStatus() == CoreServicesStatus.FAILURE) {
            mView.setViewName(this.appConfig.getErrorResponsePage());
        }
    } catch (ProductRequestException prx) {
        ERROR_RECORDER.error(prx.getMessage(), prx);

        mView.setViewName(this.appConfig.getErrorResponsePage());
    }

    if (DEBUG) {
        DEBUGGER.debug("ModelAndView: {}", mView);
    }

    return mView;
}

From source file:de.zib.vold.userInterface.RESTController.java

MultiValueMap<String, String> getBody() throws IOException {
    ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
            .currentRequestAttributes();
    HttpServletRequest request = requestAttributes.getRequest();

    if (request.getContentLength() <= 0)
        return null;

    HttpInputMessage inputMessage = new ServletServerHttpRequest(request);

    return (MultiValueMap<String, String>) converter.read(LinkedMultiValueMap.class, inputMessage);
}

From source file:com.cws.us.pws.controllers.CommonController.java

@RequestMapping(value = "/search", method = RequestMethod.GET)
public final ModelAndView siteSearch() {
    final String methodName = CommonController.CNAME + "#siteSearch()";

    if (DEBUG) {//from  w w  w.  j  a va 2s  . c  om
        DEBUGGER.debug(methodName);
    }

    ModelAndView mView = new ModelAndView();

    final ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
            .currentRequestAttributes();
    final HttpServletRequest hRequest = requestAttributes.getRequest();
    final HttpSession hSession = hRequest.getSession();

    if (DEBUG) {
        DEBUGGER.debug("ServletRequestAttributes: {}", requestAttributes);
        DEBUGGER.debug("HttpServletRequest: {}", hRequest);
        DEBUGGER.debug("HttpSession: {}", hSession);
        DEBUGGER.debug("Session ID: {}", hSession.getId());

        DEBUGGER.debug("Dumping session content:");
        @SuppressWarnings("unchecked")
        Enumeration<String> sessionEnumeration = hSession.getAttributeNames();

        while (sessionEnumeration.hasMoreElements()) {
            String sessionElement = sessionEnumeration.nextElement();
            Object sessionValue = hSession.getAttribute(sessionElement);

            DEBUGGER.debug("Attribute: " + sessionElement + "; Value: " + sessionValue);
        }

        DEBUGGER.debug("Dumping request content:");
        @SuppressWarnings("unchecked")
        Enumeration<String> requestEnumeration = hRequest.getAttributeNames();

        while (requestEnumeration.hasMoreElements()) {
            String requestElement = requestEnumeration.nextElement();
            Object requestValue = hRequest.getAttribute(requestElement);

            DEBUGGER.debug("Attribute: " + requestElement + "; Value: " + requestValue);
        }

        DEBUGGER.debug("Dumping request parameters:");
        @SuppressWarnings("unchecked")
        Enumeration<String> paramsEnumeration = hRequest.getParameterNames();

        while (paramsEnumeration.hasMoreElements()) {
            String requestElement = paramsEnumeration.nextElement();
            Object requestValue = hRequest.getParameter(requestElement);

            DEBUGGER.debug("Parameter: " + requestElement + "; Value: " + requestValue);
        }
    }

    mView.addObject("command", new SearchRequest());
    mView.setViewName(this.appConfig.getSearchRequestPage());

    if (DEBUG) {
        DEBUGGER.debug("ModelAndView: {}", mView);
    }

    return mView;
}

From source file:com.jaspersoft.jasperserver.war.xmla.XmlaRepositoryImpl.java

protected String getCurrentUserSessionId() {
    return RequestContextHolder.currentRequestAttributes().getSessionId();
}

From source file:com.cws.us.pws.controllers.CommonController.java

@RequestMapping(value = "/search/terms/{terms}page/{page}", method = RequestMethod.GET)
public final ModelAndView siteSearch(@PathVariable("terms") final String terms,
        @PathVariable("page") final int page) {
    final String methodName = CommonController.CNAME
            + "#siteSearch(@PathVariable(\"terms\") final String terms, @PathVariable(\"page\") final int page)";

    if (DEBUG) {//from  www .  j  av  a 2 s.  c o  m
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("terms: {}", terms);
        DEBUGGER.debug("page: {}", page);
    }

    ModelAndView mView = new ModelAndView();

    final ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
            .currentRequestAttributes();
    final HttpServletRequest hRequest = requestAttributes.getRequest();
    final HttpSession hSession = hRequest.getSession();
    final ISearchProcessor processor = new SearchProcessorImpl();

    if (DEBUG) {
        DEBUGGER.debug("ServletRequestAttributes: {}", requestAttributes);
        DEBUGGER.debug("HttpServletRequest: {}", hRequest);
        DEBUGGER.debug("HttpSession: {}", hSession);
        DEBUGGER.debug("Session ID: {}", hSession.getId());

        DEBUGGER.debug("Dumping session content:");
        @SuppressWarnings("unchecked")
        Enumeration<String> sessionEnumeration = hSession.getAttributeNames();

        while (sessionEnumeration.hasMoreElements()) {
            String sessionElement = sessionEnumeration.nextElement();
            Object sessionValue = hSession.getAttribute(sessionElement);

            DEBUGGER.debug("Attribute: " + sessionElement + "; Value: " + sessionValue);
        }

        DEBUGGER.debug("Dumping request content:");
        @SuppressWarnings("unchecked")
        Enumeration<String> requestEnumeration = hRequest.getAttributeNames();

        while (requestEnumeration.hasMoreElements()) {
            String requestElement = requestEnumeration.nextElement();
            Object requestValue = hRequest.getAttribute(requestElement);

            DEBUGGER.debug("Attribute: " + requestElement + "; Value: " + requestValue);
        }

        DEBUGGER.debug("Dumping request parameters:");
        @SuppressWarnings("unchecked")
        Enumeration<String> paramsEnumeration = hRequest.getParameterNames();

        while (paramsEnumeration.hasMoreElements()) {
            String requestElement = paramsEnumeration.nextElement();
            Object requestValue = hRequest.getParameter(requestElement);

            DEBUGGER.debug("Parameter: " + requestElement + "; Value: " + requestValue);
        }
    }

    try {
        SearchRequest request = new SearchRequest();
        request.setSearchType(SearchRequestType.SITE);
        request.setSearchTerms(terms);
        request.setStartRow(page);

        if (DEBUG) {
            DEBUGGER.debug("SearchRequest: {}", request);
        }

        SearchResponse response = processor.doSiteSearch(request);

        if (DEBUG) {
            DEBUGGER.debug("SearchResponse: {}", response);
        }

        if (response.getRequestStatus() == CoreServicesStatus.SUCCESS) {
            mView.addObject("pages", (int) Math.ceil(response.getEntryCount() * 1.0 / this.recordsPerPage));
            mView.addObject("page", page);
            mView.addObject("searchTerms", terms);
            mView.addObject("searchResults", response.getResults());
            mView.setViewName(this.appConfig.getSearchRequestPage());
        } else {
            mView.addObject(Constants.MESSAGE_RESPONSE, response.getResponse());
            mView.setViewName(this.appConfig.getSearchRequestPage());
        }

        mView = new ModelAndView(new RedirectView());
        mView.setViewName(this.appConfig.getRequestCompletePage());
    } catch (SearchRequestException srx) {
        ERROR_RECORDER.error(srx.getMessage(), srx);

        mView = new ModelAndView(new RedirectView());
        mView.setViewName(this.appConfig.getErrorResponsePage());
    }

    if (DEBUG) {
        DEBUGGER.debug("ModelAndView: {}", mView);
    }

    return mView;
}

From source file:de.hybris.platform.assistedservicestorefront.controllers.cms.AssistedServiceComponentController.java

protected void setSessionTimeout() {
    JaloSession.getCurrentSession().setTimeout(assistedServiceFacade.getAssistedServiceSessionTimeout());
    // since agent is logged in - change session timeout to the value from properties
    ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest().getSession()
            .setMaxInactiveInterval(assistedServiceFacade.getAssistedServiceSessionTimeout()); // in seconds
}