Spring and cross context: WebAsyncManager cannot be passed to WebAsyncManager

I want to use the cross context function in a Spring application so that I can import some webapp1 JSP into webapp2 JSP. I am using Eclipse STS with Tomcat 7.0.42 (vFabric TC Server) enabled and Spring Framework 3.2.8.

I configured Tomcat conf / context.xml to have: `

<Context crossContext="true">...</Context>`. 

In webapp2 JSP I use `

<c:import context="/webapp1" url="/myurl" />`.

When I call webapp2 JSP, I have this error:

HTTP Status 500 - javax.servlet.ServletException: javax.servlet.jsp.JspException: `java.lang.ClassCastException:` `org.springframework.web.context.request.async.WebAsyncManager cannot be cast to` org.springframework.web.context.request.async.WebAsyncManager`

Has anyone else come across this?

+4
source share
4 answers

It seems that Spring is not ready to handle the context context request (at least not without hacking).

FrameworkServlet WebAsyncManager . , , ( ).

:

  • include JSP, , Spring ( , , org.springframework) .
  • Spring JAR (, , ).
+3

Atlassian, , , :

https://docs.atlassian.com/atlassian-confluence/latest/com/atlassian/confluence/internal/web/filter/spring/IgnoreWebAsyncManagerFilter.html

:

, , SpringMVC. Spring OnePerRequestFilter WebAsyncUtils.getAsyncManager(ServletRequest), WebAsyncManager , . getAsyncManager WebAsyncManager, ServletRequest.

- Spring ClassLoaders, WebAsyncManager ClassCastExceptions , SpringMVC.

, , Spring WebAsyncManager , . getAsyncManager (ServletRequest , . , - ClassLoader OSGi ClassLoader.

, . , , . , , -.

+1

@Sylvain Lecoy , , Atlasian javadoc. , WebAsyncUtils.getAsyncManager(ServletRequest), , / .

public class IgnoreWebAsyncManagerFilter implements Filter {

static class IgnoreWebAsyncManagerCacheServletRequest extends HttpServletRequestWrapper {

    /**
     * Creates a ServletRequest adaptor wrapping the given request object.
     *
     * @param request the {@link ServletRequest} to wrap.
     * @throws IllegalArgumentException if the request is null
     */
    IgnoreWebAsyncManagerCacheServletRequest(HttpServletRequest request) {
        super(request);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setAttribute(String name, Object o) {
        if (!name.equals(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE)) {
            super.setAttribute(name, o);
        }
    }
}


/**
 * {@inheritDoc}
 */
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}

/**
 * {@inheritDoc}
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    chain.doFilter(new IgnoreWebAsyncManagerCacheServletRequest((HttpServletRequest) request), response);
}

/**
 * {@inheritDoc}
 */
@Override
public void destroy() {
}

. , HttpServletRequest, , .

0

We fought this exception in our hybrid applications (development: Spring Boot app / production: Liferay portlet, an exception occurred on our Liferay servers) for several days.

In our case, disabling all (unnecessary) servlet filters helped:

0
source

Source: https://habr.com/ru/post/1529655/


All Articles