Example usage for org.springframework.web.context.request.async WebAsyncUtils WEB_ASYNC_MANAGER_ATTRIBUTE

List of usage examples for org.springframework.web.context.request.async WebAsyncUtils WEB_ASYNC_MANAGER_ATTRIBUTE

Introduction

In this page you can find the example usage for org.springframework.web.context.request.async WebAsyncUtils WEB_ASYNC_MANAGER_ATTRIBUTE.

Prototype

String WEB_ASYNC_MANAGER_ATTRIBUTE

To view the source code for org.springframework.web.context.request.async WebAsyncUtils WEB_ASYNC_MANAGER_ATTRIBUTE.

Click Source Link

Document

The name attribute containing the WebAsyncManager .

Usage

From source file:org.jasig.ssp.security.uportal.KeepSessionAliveFilter.java

@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
        throws IOException, ServletException {
    boolean overrideInterval = isIntervalOverridden(request);
    if (!(overrideInterval) && interval < 0) {
        chain.doFilter(request, response);
        return;/*from   w ww  . jav  a 2  s.  co m*/
    }

    final HttpServletRequest httpServletRequest = (HttpServletRequest) request;
    final HttpServletResponse httpServletResponse = (HttpServletResponse) response;
    final HttpSession session = httpServletRequest.getSession(false);
    if (session == null) {
        chain.doFilter(request, response);
        return;
    }

    Long lastUpdate = (Long) session.getAttribute(SESSION_KEEP_ALIVE_ATTRIBUTE_KEY);
    if (overrideInterval || lastUpdate != null) {
        if (overrideInterval || ((System.currentTimeMillis() - lastUpdate.longValue()) >= interval)) {
            final CrossContextRestApiInvoker rest = new SimpleCrossContextRestApiInvoker();
            //ensures request is GET going into REST Invoker
            HttpServletGetRequestWrapper wrap = new HttpServletGetRequestWrapper(httpServletRequest);
            final Object origWebAsyncManager = wrap.getAttribute(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE);
            request.removeAttribute(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE);
            try {
                final Map<String, String[]> params = new HashMap<String, String[]>();
                final RestResponse rr = rest.invoke(wrap, httpServletResponse, "/ssp-platform/api/session.json",
                        params);
                session.setAttribute(SESSION_KEEP_ALIVE_ATTRIBUTE_KEY, System.currentTimeMillis());
            } finally {
                request.setAttribute(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE, origWebAsyncManager);
            }
        }
    } else {
        session.setAttribute(SESSION_KEEP_ALIVE_ATTRIBUTE_KEY, System.currentTimeMillis());

    }

    chain.doFilter(request, response);
}

From source file:org.jasig.ssp.service.impl.UPortalPersonAttributesService.java

@SuppressWarnings("unchecked")
@Override//from  ww w  .j ava2s . c o  m
public PersonAttributesResult getAttributes(final String username) throws ObjectNotFoundException {

    LOGGER.debug("Fetching attributes for user '{}'", username);

    final Map<String, String[]> params = new HashMap<String, String[]>();
    params.put(PARAM_USERNAME, new String[] { username });

    final CrossContextRestApiInvoker rest = new PatchedSimpleCrossContextRestApiInvoker();
    final HttpServletRequest req = requestForCrossContextGet();
    final HttpServletResponse res = responseForCrossContextGet();
    final Object origWebAsyncManager = req.getAttribute(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE);
    req.removeAttribute(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE);

    RestResponse rr;
    try {
        rr = rest.invoke(req, res, REST_URI_PERSON, params);
    } finally {
        req.setAttribute(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE, origWebAsyncManager);
    }

    final ObjectMapper mapper = new ObjectMapper();
    Map<String, Map<String, Map<String, List<String>>>> value = null;
    try {
        value = mapper.readValue(rr.getWriterOutput(), Map.class);
    } catch (final Exception e) {
        final String msg = "Failed to access attributes for the specified person:  " + username;
        throw new UPortalSecurityException(msg, e);
    }

    final Map<String, Map<String, List<String>>> person = value.get(PERSON_KEY);
    if (person == null) {
        // No match...
        throw new ObjectNotFoundException("The specified person is unrecognized", username);
    }
    final Map<String, List<String>> rslt = person.get(ATTRIBUTES_KEY);
    if (rslt == null) {
        throw new ObjectNotFoundException("No attributes are available for the specified person", username);
    }

    LOGGER.debug("Retrieved the following attributes for user {}:  {}", username, rslt.toString());

    return convertAttributes(rslt);
}

From source file:org.jasig.ssp.service.impl.UPortalPersonAttributesService.java

@SuppressWarnings("unchecked")
@Override/*from w  w w. ja v  a  2s  .c om*/
public List<Map<String, Object>> searchForUsers(final Map<String, String> query) {

    LOGGER.debug("Searching for users with query terms '{}'", query);

    // Assemble searchTerms[] in expected way
    final List<String> searchTerms = new ArrayList<String>();
    final Map<String, String[]> params = new HashMap<String, String[]>();
    for (final Map.Entry<String, String> y : query.entrySet()) {
        searchTerms.add(y.getKey());
        params.put(y.getKey(), new String[] { y.getValue() });
    }

    // Build the URL
    final StringBuilder bld = new StringBuilder(REST_URI_SEARCH_PREFIX);
    for (final String key : params.keySet()) {
        bld.append("&{").append(key).append("}");
    }
    final String url = bld.toString();

    LOGGER.debug("Invoking REST enpoint with URL '{}'", url);

    // Add serchTerms[] to the params
    params.put(PARAM_SEARCH_TERMS, searchTerms.toArray(new String[0]));

    final CrossContextRestApiInvoker rest = new PatchedSimpleCrossContextRestApiInvoker();
    final HttpServletRequest req = requestForCrossContextGet();
    final HttpServletResponse res = responseForCrossContextGet();
    final Object origWebAsyncManager = req.getAttribute(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE);
    req.removeAttribute(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE);

    RestResponse rr;
    try {
        rr = rest.invoke(req, res, url, params);
    } finally {
        req.setAttribute(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE, origWebAsyncManager);
    }

    final ObjectMapper mapper = new ObjectMapper();
    Map<String, List<Map<String, Object>>> value = null;
    try {
        value = mapper.readValue(rr.getWriterOutput(), Map.class);
    } catch (final Exception e) {
        final String msg = "Failed to search for users with the specified query:  " + query;
        throw new PersonAttributesSearchException(msg, e);
    }

    final List<Map<String, Object>> rslt = value.get(PEOPLE_KEY);
    if (rslt == null) {
        // Odd... should at least be an empty list
        final String msg = "Search for users returned no list for the specified query:  " + query;
        throw new PersonAttributesSearchException(msg);
    }

    LOGGER.debug("Retrieved the following people for query {}:  {}", query, rslt);

    return rslt;

}

From source file:org.springframework.web.context.request.async.WebAsyncManager.java

/**
 * Configure the {@link AsyncWebRequest} to use. This property may be set
 * more than once during a single request to accurately reflect the current
 * state of the request (e.g. following a forward, request/response
 * wrapping, etc). However, it should not be set while concurrent handling
 * is in progress, i.e. while {@link #isConcurrentHandlingStarted()} is
 * {@code true}./*from  w  ww.  j a v  a2 s .  c  o  m*/
 * @param asyncWebRequest the web request to use
 */
public void setAsyncWebRequest(final AsyncWebRequest asyncWebRequest) {
    Assert.notNull(asyncWebRequest, "AsyncWebRequest must not be null");
    this.asyncWebRequest = asyncWebRequest;
    this.asyncWebRequest.addCompletionHandler(() -> asyncWebRequest
            .removeAttribute(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST));
}