Example usage for javax.servlet.http HttpServletRequest getAttributeNames

List of usage examples for javax.servlet.http HttpServletRequest getAttributeNames

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getAttributeNames.

Prototype

public Enumeration<String> getAttributeNames();

Source Link

Document

Returns an Enumeration containing the names of the attributes available to this request.

Usage

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) {// w w  w  .  j  a  va2 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();

    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.cws.us.pws.controllers.CommonController.java

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

    if (DEBUG) {// w  w  w.ja v  a  2s.  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("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.CommonController.java

@RequestMapping(value = "/contact", method = RequestMethod.POST)
public final ModelAndView sendMessage(@ModelAttribute("message") final EmailMessage message,
        final BindingResult bindResult) {
    final String methodName = CommonController.CNAME
            + "#sendMessage(@ModelAttribute(\"message\") final EmailMessage message, final BindingResult bindResult)";

    if (DEBUG) {//from  w w w .j a  v a 2s. co m
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("EmailMessage: {}", message);
        DEBUGGER.debug("BindingResult: {}", bindResult);
    }

    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);
        }
    }

    // validate
    this.appConfig.getEmailValidator().validate(message, bindResult);

    if (bindResult.hasErrors()) {
        // errors occurred during validation
        ERROR_RECORDER.error("Form failed field validation");

        mView.addObject(Constants.ERROR_MESSAGE, this.appConfig.getMessageValidationFailed());
        mView.addObject("command", new EmailMessage());
        mView.setViewName(this.appConfig.getContactPage());

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

        return mView;
    }

    this.appConfig.getMessageValidator().validate(message, bindResult);

    if (bindResult.hasErrors()) {
        // errors occurred during validation
        ERROR_RECORDER.error("Form failed field validation");

        mView = new ModelAndView();
        mView.addObject(Constants.ERROR_MESSAGE, this.appConfig.getMessageValidationFailed());
        mView.addObject("command", new EmailMessage());
        mView.setViewName(this.appConfig.getContactPage());

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

        return mView;
    }

    try {
        EmailUtils.sendEmailMessage(message, true);

        EmailMessage autoResponse = new EmailMessage();
        autoResponse.setIsAlert(false);
        autoResponse.setMessageSubject(this.contactResponseEmail.getSubject());
        autoResponse.setMessageTo(new ArrayList<>(Arrays
                .asList(String.format(this.contactResponseEmail.getTo()[0], message.getEmailAddr().get(0)))));
        autoResponse.setEmailAddr(
                new ArrayList<>(Arrays.asList(String.format(this.contactResponseEmail.getFrom()))));
        autoResponse.setMessageBody(String.format(this.contactResponseEmail.getText(), message.getEmailAddr(),
                message.getMessageBody()));

        if (DEBUG) {
            DEBUGGER.debug("EmailMessage: {}", autoResponse);
        }

        EmailUtils.sendEmailMessage(autoResponse, true);

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

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

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

    return mView;
}

From source file:com.cws.esolutions.security.filters.SessionAuthenticationFilter.java

public void doFilter(final ServletRequest sRequest, final ServletResponse sResponse,
        final FilterChain filterChain) throws IOException, ServletException {
    final String methodName = SessionAuthenticationFilter.CNAME
            + "#doFilter(final ServletRequest sRequest, final ServletResponse sResponse, final FilterChain filterChain) throws IOException, ServletException";

    if (DEBUG) {/*from   w w  w  . java 2s  . c  o m*/
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("ServletRequest: {}", sRequest);
        DEBUGGER.debug("ServletResponse: {}", sResponse);
    }

    final HttpServletRequest hRequest = (HttpServletRequest) sRequest;
    final HttpServletResponse hResponse = (HttpServletResponse) sResponse;
    final HttpSession hSession = hRequest.getSession(false);
    final String requestURI = hRequest.getRequestURI();
    final String passwdPage = hRequest.getContextPath() + this.passwordURI;
    final StringBuilder redirectPath = new StringBuilder().append(hRequest.getContextPath() + this.loginURI)
            .append("?vpath=" + requestURI);

    if (DEBUG) {
        DEBUGGER.debug("HttpServletRequest: {}", hRequest);
        DEBUGGER.debug("HttpServletResponse: {}", hResponse);
        DEBUGGER.debug("HttpSession: {}", hSession);
        DEBUGGER.debug("RequestURI: {}", requestURI);
        DEBUGGER.debug("passwdPage: {}", passwdPage);
        DEBUGGER.debug("redirectPath: {}", redirectPath);

        DEBUGGER.debug("Dumping session content:");
        Enumeration<?> sessionEnumeration = hSession.getAttributeNames();

        while (sessionEnumeration.hasMoreElements()) {
            String element = (String) sessionEnumeration.nextElement();
            Object value = hSession.getAttribute(element);

            DEBUGGER.debug("Attribute: {}; Value: {}", element, value);
        }

        DEBUGGER.debug("Dumping request content:");
        Enumeration<?> requestEnumeration = hRequest.getAttributeNames();

        while (requestEnumeration.hasMoreElements()) {
            String element = (String) requestEnumeration.nextElement();
            Object value = hRequest.getAttribute(element);

            DEBUGGER.debug("Attribute: {}; Value: {}", element, value);
        }

        DEBUGGER.debug("Dumping request parameters:");
        Enumeration<?> paramsEnumeration = hRequest.getParameterNames();

        while (paramsEnumeration.hasMoreElements()) {
            String element = (String) paramsEnumeration.nextElement();
            Object value = hRequest.getParameter(element);

            DEBUGGER.debug("Parameter: {}; Value: {}", element, value);
        }
    }

    if (StringUtils.equals(this.loginURI, requestURI)) {
        if (DEBUG) {
            DEBUGGER.debug("Request authenticated. No action taken !");
        }

        filterChain.doFilter(sRequest, sResponse);

        return;
    }

    if ((this.ignoreURIs != null) && (this.ignoreURIs.length != 0)) {
        if (Arrays.asList(this.ignoreURIs).contains("ALL")) {
            if (DEBUG) {
                DEBUGGER.debug("ALL URIs are ignored. Breaking ...");
            }

            filterChain.doFilter(sRequest, sResponse);

            return;
        }

        // hostname isnt in ignore list
        for (String uri : this.ignoreURIs) {
            uri = hRequest.getContextPath().trim() + uri.trim();

            if (DEBUG) {
                DEBUGGER.debug(uri);
                DEBUGGER.debug(requestURI);
            }

            if (StringUtils.contains(requestURI, uri)) {
                // ignore
                if (DEBUG) {
                    DEBUGGER.debug("URI matched to ignore list - breaking out");
                }

                filterChain.doFilter(sRequest, sResponse);

                return;
            }
        }
    }

    if (hRequest.isRequestedSessionIdFromURL()) {
        ERROR_RECORDER.error("Session found is from URL. Redirecting request to " + hRequest.getContextPath()
                + this.loginURI);

        // invalidate the session
        hRequest.getSession(false).invalidate();
        hSession.removeAttribute(SessionAuthenticationFilter.USER_ACCOUNT);
        hSession.invalidate();

        hResponse.sendRedirect(hRequest.getContextPath() + this.loginURI);

        return;
    }

    Enumeration<?> sessionAttributes = hSession.getAttributeNames();

    if (DEBUG) {
        DEBUGGER.debug("Enumeration<String>: {}", sessionAttributes);
    }

    while (sessionAttributes.hasMoreElements()) {
        String element = (String) sessionAttributes.nextElement();

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

        Object value = hSession.getAttribute(element);

        if (DEBUG) {
            DEBUGGER.debug("sessionValue: {}", value);
        }

        if (value instanceof UserAccount) {
            UserAccount userAccount = (UserAccount) value;

            if (DEBUG) {
                DEBUGGER.debug("UserAccount: {}", userAccount);
            }

            if (userAccount.getStatus() != null) {
                switch (userAccount.getStatus()) {
                case EXPIRED:
                    if ((!(StringUtils.equals(requestURI, passwdPage)))) {
                        ERROR_RECORDER.error(
                                "Account is expired and this request is not for the password page. Redirecting !");

                        hResponse.sendRedirect(hRequest.getContextPath() + this.passwordURI);

                        return;
                    }

                    filterChain.doFilter(sRequest, sResponse);

                    return;
                case RESET:
                    if ((!(StringUtils.equals(requestURI, passwdPage)))) {
                        ERROR_RECORDER.error(
                                "Account has status RESET and this request is not for the password page. Redirecting !");

                        hResponse.sendRedirect(hRequest.getContextPath() + this.passwordURI);

                        return;
                    }

                    filterChain.doFilter(sRequest, sResponse);

                    return;
                case SUCCESS:
                    filterChain.doFilter(sRequest, sResponse);

                    return;
                default:
                    break;
                }
            }
        }
    }

    // no user account in the session
    ERROR_RECORDER.error("Session contains no existing user account. Redirecting request to "
            + hRequest.getContextPath() + this.loginURI);

    // invalidate the session
    hSession.removeAttribute(SessionAuthenticationFilter.USER_ACCOUNT);
    hSession.invalidate();

    if (StringUtils.isNotEmpty(hRequest.getQueryString())) {
        redirectPath.append("?" + hRequest.getQueryString());
    }

    if (DEBUG) {
        DEBUGGER.debug("redirectPath: {}", redirectPath.toString());
    }

    hResponse.sendRedirect(URLEncoder.encode(redirectPath.toString(), systemConfig.getEncoding()));

    return;
}

From source file:org.dihedron.strutlets.ActionContext.java

/**
 * Returns the list of all HTTP request attribute names.
 * //from   ww  w. j ava 2s .c om
 * @return
 *   the list of all HTTP request attribute names.
 */
public static List<String> getHttpAttributeNames() {
    List<String> names = new ArrayList<String>();
    if (getContext().portal != null) {
        HttpServletRequest servlet = getContext().portal.getHTTPServletRequest(getContext().request);
        @SuppressWarnings("unchecked")
        Enumeration<String> enumeration = (Enumeration<String>) servlet.getAttributeNames();
        while (enumeration.hasMoreElements()) {
            names.add(enumeration.nextElement());
        }
    }
    return names;
}

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

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

    if (DEBUG) {/*from   w ww.j a va  2s.  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();
    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);
        }
    } catch (ProductRequestException prx) {
        ERROR_RECORDER.error(prx.getMessage(), prx);

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

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

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

    return mView;
}

From source file:org.springframework.web.servlet.SimpleDispatcherServlet.java

/**
 * Exposes the DispatcherServlet-specific request attributes and delegates to {@link #doDispatch}
 * for the actual dispatching.// www .  j a v a 2  s  . c o m
 */
@Override
public void doService(HttpServletRequest request, HttpServletResponse response) throws Exception {
    if (logger.isDebugEnabled()) {
        String requestUri = new UrlPathHelper().getRequestUri(request);
        logger.debug("DispatcherServlet with name '" + getServletName() + "' processing " + request.getMethod()
                + " request for [" + requestUri + "]");
    }

    // Keep a snapshot of the request attributes in case of an include,
    // to be able to restore the original attributes after the include.
    Map<String, Object> attributesSnapshot = null;
    if (WebUtils.isIncludeRequest(request)) {
        logger.debug("Taking snapshot of request attributes before include");
        attributesSnapshot = new HashMap<String, Object>();
        Enumeration attrNames = request.getAttributeNames();
        while (attrNames.hasMoreElements()) {
            String attrName = (String) attrNames.nextElement();
            if (this.cleanupAfterInclude || attrName.startsWith("org.springframework.web.servlet")) {
                attributesSnapshot.put(attrName, request.getAttribute(attrName));
            }
        }
    }

    // Make framework objects available to handlers and view objects.
    request.setAttribute(WEB_APPLICATION_CONTEXT_ATTRIBUTE, getWebApplicationContext());
    request.setAttribute(LOCALE_RESOLVER_ATTRIBUTE, this.localeResolver);
    request.setAttribute(THEME_RESOLVER_ATTRIBUTE, this.themeResolver);
    request.setAttribute(THEME_SOURCE_ATTRIBUTE, getThemeSource());

    try {
        doDispatch(request, response);
    } finally {
        // Restore the original attribute snapshot, in case of an include.
        if (attributesSnapshot != null) {
            restoreAttributesAfterInclude(request, attributesSnapshot);
        }
    }
}

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  w w  w .j av  a  2  s.  com
        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:com.cws.us.pws.controllers.CommonController.java

@RequestMapping(value = "/search", method = RequestMethod.POST)
public final ModelAndView siteSearch(@ModelAttribute("request") final SearchRequest request,
        final BindingResult bindResult) {
    final String methodName = CommonController.CNAME
            + "#sendMessage(@ModelAttribute(\"request\") final SearchRequest request, final BindingResult bindResult)";

    if (DEBUG) {/*from   w  w  w.  ja  v  a  2s  .  co  m*/
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("SearchRequest: {}", request);
        DEBUGGER.debug("BindingResult: {}", bindResult);
    }

    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);
        }
    }

    // validate
    this.appConfig.getEmailValidator().validate(request, bindResult);

    if (bindResult.hasErrors()) {
        // errors occurred during validation
        ERROR_RECORDER.error("Form failed field validation");

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

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

        return mView;
    }

    try {
        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", 1);
            mView.addObject("searchTerms", request.getSearchTerms());
            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:com.jsmartframework.web.manager.BeanHandler.java

public void finalizeBeans(HttpServletRequest request, HttpServletResponse response) {
    List<String> names = Collections.list(request.getAttributeNames());
    for (String name : names) {
        Object bean = request.getAttribute(name);
        if (bean == null) {
            continue;
        }//w ww.j av a  2 s  . c om

        Field[] exposeVars = HELPER.getExposeVarFields(bean.getClass());
        for (int i = 0; i < exposeVars.length; i++) {
            try {
                Object value = exposeVars[i].get(bean);
                if (value != null) {
                    setExposeVarAttribute(request, exposeVars[i].getName(), value);
                }
            } catch (Exception ex) {
                LOGGER.log(Level.SEVERE, "Could not expose var [" + exposeVars[i] + "]", ex);
            }
        }

        if (bean.getClass().isAnnotationPresent(WebBean.class)) {
            finalizeWebBean(bean, request);

        } else if (bean.getClass().isAnnotationPresent(AuthBean.class)) {
            finalizeAuthBean(bean, request, response);

        } else if (bean.getClass().isAnnotationPresent(WebSecurity.class)) {
            finalizeWebSecurity(bean, request);
        }
    }
}