Example usage for org.springframework.web.util WebUtils FORWARD_QUERY_STRING_ATTRIBUTE

List of usage examples for org.springframework.web.util WebUtils FORWARD_QUERY_STRING_ATTRIBUTE

Introduction

In this page you can find the example usage for org.springframework.web.util WebUtils FORWARD_QUERY_STRING_ATTRIBUTE.

Prototype

String FORWARD_QUERY_STRING_ATTRIBUTE

To view the source code for org.springframework.web.util WebUtils FORWARD_QUERY_STRING_ATTRIBUTE.

Click Source Link

Document

Standard Servlet 2.4+ spec request attribute for forward query string.

Usage

From source file:com.asual.summer.core.util.RequestUtils.java

public static String getQueryString() {
    String requestURI = (String) getAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE);
    if (requestURI != null) {
        return (String) getAttribute(WebUtils.FORWARD_QUERY_STRING_ATTRIBUTE);
    }// www .j  ava  2s  .  c o  m
    return getRequest().getQueryString();
}

From source file:org.jahia.services.render.webflow.WebflowDispatcherScript.java

/**
 * Execute the script and return the result as a string
 *
 * @param resource resource to display/*from w  w  w.  j a v a2 s .  c om*/
 * @param context
 * @return the rendered resource
 * @throws org.jahia.services.render.RenderException
 *
 */
public String execute(Resource resource, RenderContext context) throws RenderException {
    final View view = getView();
    if (view == null) {
        throw new RenderException("View not found for : " + resource);
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("View '" + view + "' resolved for resource: " + resource);
        }
    }

    String identifier;
    try {
        identifier = resource.getNode().getIdentifier();
    } catch (RepositoryException e) {
        throw new RenderException(e);
    }
    String identifierNoDashes = StringUtils.replace(identifier, "-", "_");
    if (!view.getKey().equals("default")) {
        identifierNoDashes += "__" + view.getKey();
    }

    HttpServletRequest request;
    HttpServletResponse response = context.getResponse();

    @SuppressWarnings("unchecked")
    final Map<String, List<String>> parameters = (Map<String, List<String>>) context.getRequest()
            .getAttribute("actionParameters");

    if (xssFilteringEnabled && parameters != null) {
        final Map<String, String[]> m = Maps.transformEntries(parameters,
                new Maps.EntryTransformer<String, List<String>, String[]>() {
                    @Override
                    public String[] transformEntry(@Nullable String key, @Nullable List<String> value) {
                        return value != null ? value.toArray(new String[value.size()]) : null;
                    }
                });
        request = new WebflowHttpServletRequestWrapper(context.getRequest(), m, identifierNoDashes);
    } else {
        request = new WebflowHttpServletRequestWrapper(context.getRequest(),
                new HashMap<>(context.getRequest().getParameterMap()), identifierNoDashes);
    }

    String s = (String) request.getSession().getAttribute("webflowResponse" + identifierNoDashes);
    if (s != null) {
        request.getSession().removeAttribute("webflowResponse" + identifierNoDashes);
        return s;
    }

    // skip aggregation for potentials fragments under the webflow
    boolean aggregationSkippedForWebflow = false;
    if (!AggregateFilter.skipAggregation(context.getRequest())) {
        aggregationSkippedForWebflow = true;
        context.getRequest().setAttribute(AggregateFilter.SKIP_AGGREGATION, true);
    }

    flowPath = MODULE_PREFIX_PATTERN.matcher(view.getPath()).replaceFirst("");

    RequestDispatcher rd = request.getRequestDispatcher("/flow/" + flowPath);

    Object oldModule = request.getAttribute("currentModule");
    request.setAttribute("currentModule", view.getModule());

    if (logger.isDebugEnabled()) {
        dumpRequestAttributes(request);
    }

    StringResponseWrapper responseWrapper = new StringResponseWrapper(response);

    try {
        FlowDefinitionRegistry reg = ((FlowDefinitionRegistry) view.getModule().getContext()
                .getBean("jahiaFlowRegistry"));
        final GenericApplicationContext applicationContext = (GenericApplicationContext) reg
                .getFlowDefinition(flowPath).getApplicationContext();
        applicationContext.setClassLoader(view.getModule().getClassLoader());
        applicationContext.setResourceLoader(new ResourceLoader() {
            @Override
            public org.springframework.core.io.Resource getResource(String location) {
                return applicationContext.getParent().getResource("/" + flowPath + "/" + location);
            }

            @Override
            public ClassLoader getClassLoader() {
                return view.getModule().getClassLoader();
            }
        });

        rd.include(request, responseWrapper);

        String redirect = responseWrapper.getRedirect();
        if (redirect != null && context.getRedirect() == null) {
            // if we have an absolute redirect, set it and move on
            if (redirect.startsWith("http:/") || redirect.startsWith("https://")) {
                context.setRedirect(responseWrapper.getRedirect());
            } else {
                while (redirect != null) {
                    final String qs = StringUtils.substringAfter(responseWrapper.getRedirect(), "?");
                    final Map<String, String[]> params = new HashMap<String, String[]>();
                    if (!StringUtils.isEmpty(qs)) {
                        params.put("webflowexecution" + identifierNoDashes, new String[] { StringUtils
                                .substringAfterLast(qs, "webflowexecution" + identifierNoDashes + "=") });
                    }
                    HttpServletRequestWrapper requestWrapper = new HttpServletRequestWrapper(request) {
                        @Override
                        public String getMethod() {
                            return "GET";
                        }

                        @SuppressWarnings("rawtypes")
                        @Override
                        public Map getParameterMap() {
                            return params;
                        }

                        @Override
                        public String getParameter(String name) {
                            return params.containsKey(name) ? params.get(name)[0] : null;
                        }

                        @Override
                        public Enumeration getParameterNames() {
                            return new Vector(params.keySet()).elements();
                        }

                        @Override
                        public String[] getParameterValues(String name) {
                            return params.get(name);
                        }

                        @Override
                        public Object getAttribute(String name) {
                            if (WebUtils.FORWARD_QUERY_STRING_ATTRIBUTE.equals(name)) {
                                return qs;
                            }
                            return super.getAttribute(name);
                        }

                        @Override
                        public String getQueryString() {
                            return qs;
                        }
                    };
                    rd = requestWrapper.getRequestDispatcher("/flow/" + flowPath + "?" + qs);
                    responseWrapper = new StringResponseWrapper(response);
                    rd.include(requestWrapper, responseWrapper);

                    String oldRedirect = redirect;
                    redirect = responseWrapper.getRedirect();
                    if (redirect != null) {
                        // if we have an absolute redirect, exit the loop
                        if (redirect.startsWith("http://") || redirect.startsWith("https://")) {
                            context.setRedirect(redirect);
                            break;
                        }
                    } else if (request.getMethod().equals("POST")) {
                        // set the redirect to the last non-null one
                        request.getSession().setAttribute("webflowResponse" + identifierNoDashes,
                                responseWrapper.getString());
                        context.setRedirect(oldRedirect);
                    }
                }
            }
        }
    } catch (ServletException e) {
        throw new RenderException(e.getRootCause() != null ? e.getRootCause() : e);
    } catch (IOException e) {
        throw new RenderException(e);
    } finally {
        request.setAttribute("currentModule", oldModule);
    }
    try {
        if (aggregationSkippedForWebflow) {
            request.removeAttribute(AggregateFilter.SKIP_AGGREGATION);
        }
        return responseWrapper.getString();
    } catch (IOException e) {
        throw new RenderException(e);
    }
}

From source file:org.springframework.web.util.UrlPathHelper.java

/**
 * Return the query string part of the given request's URL. If this is a forwarded request,
 * correctly resolves to the query string of the original request.
 * @param request current HTTP request// ww  w.j ava  2 s  .co  m
 * @return the query string
 */
public String getOriginatingQueryString(HttpServletRequest request) {
    if ((request.getAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE) != null)
            || (request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE) != null)) {
        return (String) request.getAttribute(WebUtils.FORWARD_QUERY_STRING_ATTRIBUTE);
    } else {
        return request.getQueryString();
    }
}