Example usage for org.springframework.web.context.request ServletRequestAttributes getRequest

List of usage examples for org.springframework.web.context.request ServletRequestAttributes getRequest

Introduction

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

Prototype

public final HttpServletRequest getRequest() 

Source Link

Document

Exposes the native HttpServletRequest that we're wrapping.

Usage

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.AboutController.java

@RequestMapping(value = "/default", method = RequestMethod.GET)
public final ModelAndView showDefaultPage() {
    final String methodName = AboutController.CNAME + "#showDefaultPage()";

    if (DEBUG) {//from   w  w  w  .j a v a2s  . c  o m
        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 {
        CareerRequest request = new CareerRequest();
        request.setLang(
                (StringUtils.isBlank(hRequest.getParameter("lang"))) ? "en" : hRequest.getParameter("lang"));

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

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

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

        if (response.getRequestStatus() == CoreServicesStatus.SUCCESS) {
            mView.addObject("doCareersExist", Boolean.TRUE);
        }
    } catch (CareerRequestException crx) {
        ERROR_RECORDER.error(crx.getMessage(), crx);
    }

    mView.setViewName(this.aboutUsPage);

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

    return mView;
}

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

@RequestMapping(value = "/careers", method = RequestMethod.GET)
public final ModelAndView showCareersPage() {
    final String methodName = AboutController.CNAME + "#showCareersPage()";

    if (DEBUG) {/* ww w. j av a 2 s  .  c o  m*/
        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 {
        CareerRequest request = new CareerRequest();
        request.setLang(
                (StringUtils.isBlank(hRequest.getParameter("lang"))) ? "en" : hRequest.getParameter("lang"));

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

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

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

        if (response.getRequestStatus() == CoreServicesStatus.SUCCESS) {
            mView.addObject("careerList", response.getCareerList());
        }
    } catch (CareerRequestException crx) {
        ERROR_RECORDER.error(crx.getMessage(), crx);
    }

    mView.setViewName(this.careersPage);

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

    return mView;
}

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) {//from w  w w .j  a va2 s.co m
        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: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) {/*from  w  w w. j  ava2 s.c om*/
        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:com.cws.us.pws.controllers.ProductController.java

@RequestMapping(value = "/default", method = RequestMethod.GET)
public final ModelAndView showDefaultPage() {
    final String methodName = ProductController.CNAME + "#showDefaultPage()";

    if (DEBUG) {/*ww  w .j ava 2  s . 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();
    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.setIsFeatured(true);
        productRequest.setLang((StringUtils.isBlank(lang)) ? "en" : lang);

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

        ProductResponse productResponse = this.productRefSvc.getFeaturedProducts(productRequest);

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

        if (productResponse.getRequestStatus() == CoreServicesStatus.SUCCESS) {
            List<Product> featuredProducts = productResponse.getProductList();

            if (DEBUG) {
                DEBUGGER.debug("List<Product>: {}", featuredProducts);
            }

            mView.addObject("featuredProducts", featuredProducts);
        }

        mView.addObject("command", new Product());
        mView.setViewName(this.defaultPage);
    } catch (ProductRequestException prx) {
        ERROR_RECORDER.error(prx.getMessage(), prx);

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

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

    return mView;
}

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

@RequestMapping(value = "/product/{product}", method = RequestMethod.GET)
public final ModelAndView getProductInfo(@PathVariable("product") final String product) {
    final String methodName = ProductController.CNAME
            + "#getProductInfo(@PathVariable(\"product\") final String product)";

    if (DEBUG) {/*w w w .j  a  v  a2  s  .  c om*/
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Product: {}", product);
    }

    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 {
        Product reqProduct = new Product();
        reqProduct.setProductId(product);

        if (DEBUG) {
            DEBUGGER.debug("Product: {}", reqProduct);
        }

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

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

        ProductResponse productResponse = this.productRefSvc.getProductData(productRequest);

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

        if (productResponse.getRequestStatus() == CoreServicesStatus.SUCCESS) {
            Product resProduct = productResponse.getProduct();

            if (DEBUG) {
                DEBUGGER.debug("Product: {}", resProduct);
            }

            mView.addObject("product", resProduct);
            mView.setViewName(this.showProduct);
        } else {
            mView = new ModelAndView(new RedirectView());
            mView.addObject(Constants.ERROR_MESSAGE, productResponse.getResponse());
            mView.setViewName(this.defaultPage);
        }
    } 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:com.haulmont.restapi.auth.ClientProxyTokenStore.java

/**
 * Tries to find the session associated with the given {@code authentication}. If the session id is in the store and
 * exists then it is set to the {@link SecurityContext}. If the session id is not in the store or the session with
 * the id doesn't exist in the middleware, then the trusted login attempt is performed.
 *///from w  w w.  ja v a 2  s.com
protected void processSession(OAuth2Authentication authentication, String tokenValue) {
    RestUserSessionInfo sessionInfo = serverTokenStore.getSessionInfoByTokenValue(tokenValue);
    UUID sessionId = sessionInfo != null ? sessionInfo.getId() : null;
    if (sessionId == null) {
        @SuppressWarnings("unchecked")
        Map<String, String> userAuthenticationDetails = (Map<String, String>) authentication
                .getUserAuthentication().getDetails();
        //sessionId parameter was put in the CubaUserAuthenticationProvider
        String sessionIdStr = userAuthenticationDetails.get("sessionId");
        if (!Strings.isNullOrEmpty(sessionIdStr)) {
            sessionId = UUID.fromString(sessionIdStr);
        }
    }

    UserSession session = null;
    if (sessionId != null) {
        try {
            session = trustedClientService.findSession(restApiConfig.getTrustedClientPassword(), sessionId);
        } catch (LoginException e) {
            throw new RuntimeException("Unable to login with trusted client password");
        }
    }

    if (session == null) {
        @SuppressWarnings("unchecked")
        Map<String, String> userAuthenticationDetails = (Map<String, String>) authentication
                .getUserAuthentication().getDetails();
        String username = userAuthenticationDetails.get("username");
        try {
            ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
                    .currentRequestAttributes();
            Locale locale = sessionInfo != null ? sessionInfo.getLocale() : null;
            TrustedClientCredentials credentials = new TrustedClientCredentials(username,
                    restApiConfig.getTrustedClientPassword(), locale);
            credentials.setClientType(ClientType.REST_API);
            if (attributes != null) {
                HttpServletRequest request = attributes.getRequest();
                credentials.setIpAddress(request.getRemoteAddr());
                credentials.setClientInfo(makeClientInfo(request.getHeader(HttpHeaders.USER_AGENT)));
            } else {
                credentials.setClientInfo(makeClientInfo(""));
            }

            //if locale was not determined then use the user locale
            if (locale == null) {
                credentials.setOverrideLocale(false);
            }

            session = authenticationService.login(credentials).getSession();
        } catch (LoginException e) {
            throw new OAuth2Exception("Cannot login to the middleware");
        }
    }

    if (session != null) {
        serverTokenStore.putSessionInfo(tokenValue, new RestUserSessionInfo(session));
        AppContext.setSecurityContext(new SecurityContext(session));
    }
}

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

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

    if (DEBUG) {/*  ww w  .j  ava  2 s  .c  o  m*/
        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);
        }
    }

    mView.setViewName(this.appConfig.getSiteMap());

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

    return mView;
}

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 ww .j a va 2  s .c o  m*/
        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;
}