1

I am trying to send a standard error response when the request is not fulfilled on the server due to any reason. For that, I implemented ErrorController interface and overridden getErrorPath method. It's working on my local machine but when I deploy that onto the OpenShift server with Tomcat 7.0.54. It does not work it show this exception instead of showing the json reponse :

    HTTP Status 500 - org.springframework.web.context.request.async.WebAsyncManager cannot be cast to org.springframework.web.context.request.async.WebAsyncManager

    type Exception report

    message org.springframework.web.context.request.async.WebAsyncManager cannot be cast to org.springframework.web.context.request.async.WebAsyncManager

    description The server encountered an internal error that prevented it from fulfilling this request.

    exception

    java.lang.ClassCastException: org.springframework.web.context.request.async.WebAsyncManager cannot be cast to org.springframework.web.context.request.async.WebAsyncManager
        org.springframework.web.context.request.async.WebAsyncUtils.getAsyncManager(WebAsyncUtils.java:47)
        org.springframework.web.filter.OncePerRequestFilter.isAsyncDispatch(OncePerRequestFilter.java:137)
        org.springframework.web.filter.OncePerRequestFilter.skipDispatch(OncePerRequestFilter.java:118)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:98)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
        org.springframework.boot.web.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:112)
        org.springframework.boot.web.support.ErrorPageFilter.forwardToErrorPage(ErrorPageFilter.java:187)
        org.springframework.boot.web.support.ErrorPageFilter.handleException(ErrorPageFilter.java:170)
        org.springframework.boot.web.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:134)
        org.springframework.boot.web.support.ErrorPageFilter.access$000(ErrorPageFilter.java:61)
        org.springframework.boot.web.support.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:94)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        org.springframework.boot.web.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:112)    

Here is what I did :

Application.java

    import org.apache.catalina.Context;
    import org.apache.catalina.deploy.ContextResource;
    import org.apache.catalina.startup.Tomcat;
    import org.apache.log4j.Logger;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration;
    import org.springframework.boot.builder.SpringApplicationBuilder;
    import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
    import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer;
    import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
    import org.springframework.boot.web.support.SpringBootServletInitializer;
    import org.springframework.context.annotation.Bean;
    import org.springframework.jndi.JndiObjectFactoryBean;

    @SpringBootApplication
    public class Application extends SpringBootServletInitializer{

        private static final Logger LOGGER = Logger.getLogger(Application.class);

        public static void main(String[] args) {
            LOGGER.info("Spring Boot Application Started");
            SpringApplication.run(Application.class, args);
            LOGGER.info("Spring Boot Application Ended");
        }

        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(Application.class);
        }

        @Bean
        public EmbeddedServletContainerFactory tomcatFactory() {
            return new TomcatEmbeddedServletContainerFactory() {

                @Override
                protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(Tomcat tomcat) {
                    tomcat.enableNaming();
                    return super.getTomcatEmbeddedServletContainer(tomcat);
                }
            };
        }
    }   

ErrorJson.java

import java.util.Map;

public class ErrorJson {

public Integer status;
public String error;
public String message;
public String timeStamp;

public ErrorJson(int status, Map<String, Object> errorAttributes) {
    this.status = status;
    this.error = (String) errorAttributes.get("error");
    this.message = "Please Contact the Administrator for more detail.";
    this.timeStamp = errorAttributes.get("timestamp").toString();
}
}

CustomErrorController.java

    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.boot.autoconfigure.web.ErrorAttributes;
    import org.springframework.boot.autoconfigure.web.ErrorController;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    import org.springframework.web.context.request.RequestAttributes;
    import org.springframework.web.context.request.ServletRequestAttributes;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.util.Map;

    @RestController
    public class CustomErrorController implements ErrorController {

        private static final String PATH = "/error";

        @Autowired
        private ErrorAttributes errorAttributes;

        @RequestMapping(value = PATH)
        ErrorJson error(HttpServletRequest request, HttpServletResponse response) {
            // Appropriate HTTP response code (e.g. 404 or 500) is automatically set by Spring. 
            // Here we just define response body.
            return new ErrorJson(response.getStatus(), getErrorAttributes(request));
        }

        @Override
        public String getErrorPath() {
            return PATH;
        }

        private Map<String, Object> getErrorAttributes(HttpServletRequest request) {
            RequestAttributes requestAttributes = new ServletRequestAttributes(request);
            return errorAttributes.getErrorAttributes(requestAttributes,true);
        }

    }

POM.xml

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>

        <artifactId>tomcat7</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>war</packaging>

        <name>newapp-tomcat7</name>

        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.4.1.RELEASE</version>
        </parent>

        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <java.version>1.7</java.version>
            <tomcat.version>7.0.54</tomcat.version>
            <json-simple.version>1.1.1</json-simple.version>
            <commons-codec.verison>1.10</commons-codec.verison>
            <log4j-core.version>2.4.1</log4j-core.version>
            <log4j-api.version>2.4.1</log4j-api.version>
        </properties>

        <dependencies>
            <dependency>
                <groupId>org.springframework.session</groupId>
                <artifactId>spring-session</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.session</groupId>
                <artifactId>spring-session-jdbc</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-freemarker</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-mail</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-jdbc</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-jersey</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-tomcat</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> 
                </dependency> -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
            <!-- http://mvnrepository.com/artifact/commons-codec/commons-codec -->
            <dependency>
                <groupId>commons-codec</groupId>
                <artifactId>commons-codec</artifactId>
            </dependency>
            <dependency>
                <groupId>com.googlecode.json-simple</groupId>
                <artifactId>json-simple</artifactId>
            </dependency>
            <dependency>
                <groupId>org.json</groupId>
                <artifactId>json</artifactId>
            </dependency>
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-core</artifactId>
            </dependency>
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-api</artifactId>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <scope>test</scope>
            </dependency>

            <!-- Dependencies added for WAS and Oracle -->
            <dependency>
                <groupId>com.oracle</groupId>
                <artifactId>classes12</artifactId>
                <version>10.2.0.5</version>
                <scope>provided</scope>
            </dependency>
            <!-- <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> 
                <version>11.2.0.3</version> <scope>provided</scope> </dependency> -->

            <dependency>
                <groupId>com.oracle</groupId>
                <artifactId>ojdbc14</artifactId>
                <version>10.2.0.5</version>
            </dependency>

            <!-- Dependencies WAS and Oracle ends -->

            <!-- Server Dependency -->
            <dependency>
                <groupId>org.apache.tomcat</groupId>
                <artifactId>tomcat-juli</artifactId>
                <version>${tomcat.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.tomcat</groupId>
                <artifactId>tomcat-dbcp</artifactId>
                <version>${tomcat.version}</version>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
            </dependency>
            <dependency>
                <groupId>org.apache.tomcat</groupId>
                <artifactId>tomcat-jdbc</artifactId>
            </dependency>
            <!-- Server Dependency ends -->

        </dependencies>

        <build>
            <finalName>cctgmap</finalName>
            <plugins>
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.2</version>
                    <configuration>
                        <server>TomcatServer</server>
                        <port>8008</port>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.4</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <appendAssemblyId>false</appendAssemblyId>
                        <descriptors>
                            <descriptor>assembly.xml</descriptor>
                        </descriptors>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.1.1</version>
                    <configuration>
                        <outputDirectory>${project.build.directory}/../package/dependencies/jbossews/webapps </outputDirectory>
                        <warName>ROOT</warName>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>

I found this when I was searching only for solution: https://jira.atlassian.com/browse/CWD-4770

But it does not make sense.

If I run mvn dependency:tree I get this:

    [INFO] +- org.springframework.session:spring-session:jar:1.2.2.RELEASE:compile
    [INFO] |  \- commons-logging:commons-logging:jar:1.2:compile
    [INFO] +- org.springframework.session:spring-session-jdbc:jar:1.2.2.RELEASE:compile
    [INFO] |  \- org.springframework:spring-jdbc:jar:4.3.3.RELEASE:compile
    [INFO] |     +- org.springframework:spring-beans:jar:4.3.3.RELEASE:compile
    [INFO] |     \- org.springframework:spring-tx:jar:4.3.3.RELEASE:compile
    [INFO] +- org.springframework.boot:spring-boot-starter-freemarker:jar:1.4.1.RELEASE:compile
    [INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.4.1.RELEASE:compile
    [INFO] |  |  +- org.springframework.boot:spring-boot:jar:1.4.1.RELEASE:compile
    [INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.4.1.RELEASE:compile
    [INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.4.1.RELEASE:compile
    [INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.1.7:compile
    [INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.1.7:compile
    [INFO] |  |  |  +- org.slf4j:jcl-over-slf4j:jar:1.7.21:compile
    [INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.21:compile
    [INFO] |  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.21:compile
    [INFO] |  |  \- org.yaml:snakeyaml:jar:1.17:runtime
    [INFO] |  +- org.freemarker:freemarker:jar:2.3.25-incubating:compile
    [INFO] |  \- org.springframework:spring-context-support:jar:4.3.3.RELEASE:compile
    [INFO] +- org.springframework.boot:spring-boot-starter-mail:jar:1.4.1.RELEASE:compile
    [INFO] |  +- org.springframework:spring-context:jar:4.3.3.RELEASE:compile
    [INFO] |  |  +- org.springframework:spring-aop:jar:4.3.3.RELEASE:compile
    [INFO] |  |  \- org.springframework:spring-expression:jar:4.3.3.RELEASE:compile
    [INFO] |  \- com.sun.mail:javax.mail:jar:1.5.6:compile
    [INFO] |     \- javax.activation:activation:jar:1.1:compile
    [INFO] +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.4.1.RELEASE:compile
    [INFO] +- org.springframework.boot:spring-boot-starter-jersey:jar:1.4.1.RELEASE:compile
    [INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.4.1.RELEASE:compile
    [INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:7.0.59:compile
    [INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:7.0.59:compile
    [INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:7.0.59:compile
    [INFO] |  +- org.springframework.boot:spring-boot-starter-validation:jar:1.4.1.RELEASE:compile
    [INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.3:compile
    [INFO] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.3:compile
    [INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.8.3:compile
    [INFO] |  +- org.springframework:spring-web:jar:4.3.3.RELEASE:compile
    [INFO] |  +- org.glassfish.jersey.core:jersey-server:jar:2.23.2:compile
    [INFO] |  |  +- org.glassfish.jersey.core:jersey-common:jar:2.23.2:compile
    [INFO] |  |  |  +- org.glassfish.jersey.bundles.repackaged:jersey-guava:jar:2.23.2:compile
    [INFO] |  |  |  \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.1:compile
    [INFO] |  |  +- org.glassfish.jersey.core:jersey-client:jar:2.23.2:compile
    [INFO] |  |  +- javax.ws.rs:javax.ws.rs-api:jar:2.0.1:compile
    [INFO] |  |  +- org.glassfish.jersey.media:jersey-media-jaxb:jar:2.23.2:compile
    [INFO] |  |  +- javax.annotation:javax.annotation-api:jar:1.2:compile
    [INFO] |  |  +- org.glassfish.hk2:hk2-api:jar:2.5.0-b05:compile
    [INFO] |  |  |  +- org.glassfish.hk2:hk2-utils:jar:2.5.0-b05:compile
    [INFO] |  |  |  \- org.glassfish.hk2.external:aopalliance-repackaged:jar:2.5.0-b05:compile
    [INFO] |  |  +- org.glassfish.hk2.external:javax.inject:jar:2.5.0-b05:compile
    [INFO] |  |  +- org.glassfish.hk2:hk2-locator:jar:2.5.0-b05:compile
    [INFO] |  |  |  \- org.javassist:javassist:jar:3.20.0-GA:compile
    [INFO] |  |  \- javax.validation:validation-api:jar:1.1.0.Final:compile
    [INFO] |  +- org.glassfish.jersey.containers:jersey-container-servlet-core:jar:2.23.2:compile
    [INFO] |  +- org.glassfish.jersey.containers:jersey-container-servlet:jar:2.23.2:compile
    [INFO] |  +- org.glassfish.jersey.ext:jersey-bean-validation:jar:2.23.2:compile
    [INFO] |  +- org.glassfish.jersey.ext:jersey-spring3:jar:2.23.2:compile
    [INFO] |  |  +- org.glassfish.hk2:hk2:jar:2.5.0-b05:compile
    [INFO] |  |  |  +- org.glassfish.hk2:config-types:jar:2.5.0-b05:compile
    [INFO] |  |  |  +- org.glassfish.hk2:hk2-core:jar:2.5.0-b05:compile
    [INFO] |  |  |  +- org.glassfish.hk2:hk2-config:jar:2.5.0-b05:compile
    [INFO] |  |  |  +- org.glassfish.hk2:hk2-runlevel:jar:2.5.0-b05:compile
    [INFO] |  |  |  \- org.glassfish.hk2:class-model:jar:2.5.0-b05:compile
    [INFO] |  |  |     \- org.glassfish.hk2.external:asm-all-repackaged:jar:2.5.0-b05:compile
    [INFO] |  |  \- org.glassfish.hk2:spring-bridge:jar:2.5.0-b05:compile
    [INFO] |  \- org.glassfish.jersey.media:jersey-media-json-jackson:jar:2.23.2:compile
    [INFO] |     +- org.glassfish.jersey.ext:jersey-entity-filtering:jar:2.23.2:compile
    [INFO] |     +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.8.3:compile
    [INFO] |     \- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.8.3:compile
    [INFO] |        \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.8.3:compile
    [INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:1.4.1.RELEASE:compile
    [INFO] |  \- org.springframework.boot:spring-boot-actuator:jar:1.4.1.RELEASE:compile
    [INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.4.1.RELEASE:compile
    [INFO] |  +- org.hibernate:hibernate-validator:jar:5.2.4.Final:compile
    [INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
    [INFO] |  |  \- com.fasterxml:classmate:jar:1.3.1:compile
    [INFO] |  \- org.springframework:spring-webmvc:jar:4.3.3.RELEASE:compile
    [INFO] +- org.springframework.boot:spring-boot-starter-test:jar:1.4.1.RELEASE:test
    [INFO] |  +- org.springframework.boot:spring-boot-test:jar:1.4.1.RELEASE:test
    [INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.4.1.RELEASE:test
    [INFO] |  +- com.jayway.jsonpath:json-path:jar:2.2.0:test
    [INFO] |  |  \- net.minidev:json-smart:jar:2.2.1:test
    [INFO] |  |     \- net.minidev:accessors-smart:jar:1.1:test
    [INFO] |  |        \- org.ow2.asm:asm:jar:5.0.3:test
    [INFO] |  +- org.assertj:assertj-core:jar:2.5.0:test
    [INFO] |  +- org.mockito:mockito-core:jar:1.10.19:test
    [INFO] |  |  \- org.objenesis:objenesis:jar:2.1:test
    [INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:test
    [INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
    [INFO] |  +- org.skyscreamer:jsonassert:jar:1.3.0:test
    [INFO] |  +- org.springframework:spring-core:jar:4.3.3.RELEASE:compile
    [INFO] |  \- org.springframework:spring-test:jar:4.3.3.RELEASE:test
    [INFO] +- commons-codec:commons-codec:jar:1.10:compile
    [INFO] +- com.googlecode.json-simple:json-simple:jar:1.1.1:compile
    [INFO] +- org.json:json:jar:20140107:compile
    [INFO] +- org.apache.logging.log4j:log4j-core:jar:2.6.2:compile
    [INFO] +- org.apache.logging.log4j:log4j-api:jar:2.6.2:compile
    [INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.21:compile
    [INFO] |  +- org.slf4j:slf4j-api:jar:1.7.21:compile
    [INFO] |  \- log4j:log4j:jar:1.2.17:compile
    [INFO] +- junit:junit:jar:4.12:test
    [INFO] +- com.oracle:classes12:jar:10.2.0.5:provided
    [INFO] +- com.oracle:ojdbc14:jar:10.2.0.5:compile
    [INFO] +- org.apache.tomcat:tomcat-juli:jar:7.0.59:compile
    [INFO] +- org.apache.tomcat:tomcat-dbcp:jar:7.0.59:compile
    [INFO] +- javax.servlet:javax.servlet-api:jar:3.1.0:compile
    [INFO] \- org.apache.tomcat:tomcat-jdbc:jar:7.0.59:compile

Added Filter

    import org.apache.log4j.Logger;
    import org.springframework.core.Ordered;  
    import org.springframework.core.annotation.Order;  
    import org.springframework.stereotype.Component;
    import org.springframework.web.context.request.async.WebAsyncUtils;

    import javax.servlet.*;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;  
    import java.io.IOException;  

    @Component  
    @Order(Ordered.HIGHEST_PRECEDENCE)  
    public class SecurityFilter implements Filter {  

        private static final Logger LOGGER = Logger.getLogger(SecurityFilter.class);

        @Override  
        public void init(FilterConfig filterConfig) throws ServletException {  

        }  

        @Override  
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {  
            if (request.getAttribute(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE) != null) {
             request.setAttribute(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE, null);
            }    
            LOGGER.info("Filter "+((HttpServletRequest) request).getRequestURL().toString());
            chain.doFilter(request,response);  
        }  

        @Override  
        public void destroy() {  

        }  
    } 

But still it not working its showing me this exception:

    Type Exception report

    message Request processing failed; nested exception is java.lang.ClassCastException: org.springframework.web.context.request.async.WebAsyncManager cannot be cast to org.springframework.web.context.request.async.WebAsyncManager

    description The server encountered an internal error that prevented it from fulfilling this request.

    exception

    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.ClassCastException: org.springframework.web.context.request.async.WebAsyncManager cannot be cast to org.springframework.web.context.request.async.WebAsyncManager
        org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
        org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
        org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
        org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:105)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:89)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        org.springframework.session.web.http.SessionRepositoryFilter.doFilterInternal(SessionRepositoryFilter.java:164)
        org.springframework.session.web.http.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:80)
        org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:107)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        com.cisco.eloqua.app.SecurityFilter.doFilter(SecurityFilter.java:31)
    root cause

    java.lang.ClassCastException: org.springframework.web.context.request.async.WebAsyncManager cannot be cast to org.springframework.web.context.request.async.WebAsyncManager
        org.springframework.web.context.request.async.WebAsyncUtils.getAsyncManager(WebAsyncUtils.java:47)
        org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:900)
        org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
        org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
        org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
        org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:105)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:89)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        org.springframework.session.web.http.SessionRepositoryFilter.doFilterInternal(SessionRepositoryFilter.java:164)
        org.springframework.session.web.http.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:80)
        org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:107)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        com.cisco.eloqua.app.SecurityFilter.doFilter(SecurityFilter.java:31)
    note The full stack trace of the root cause is available in the Apache Tomcat/7.0.54 logs.

    Apache Tomcat/7.0.54
mohitkira
  • 45
  • 12

1 Answers1

0

It looks like a classloading issue. Usually errors like that indicate that there are two versions of the same library loaded. The problem may occur 'randomly' depending on environment you run it in.

You could check if produced war file contains the class org.springframework.web.context.request.async.WebAsyncManager twice in the libs directory.

To check your pom.xml, you can use mvn dependency:tree, it will print out all included libraries: Maven: Resolving conflicts using the dependency tree

Bartosz Bierkowski
  • 2,782
  • 1
  • 19
  • 18
  • This is due to spring-mvc setting a request attribute with the WebAsyncManager in core (using Spring3), and spring request processing in the plugin trying to reuse it and cast it to the Spring4 version, which fails. But I am not able to find the workaround. Openshift environment has lots of problems. – mohitkira Feb 01 '17 at 00:43
  • Yes, I have seen the bug you linked to. Did you check if the class occurs twice in class path? If so, you could remove the dependency and have it only once. Or change library versions, so only one instance is present. Such issues are independent of OpenShift. It happens quite often on normal hosts or for example it works in test environment and stops working in prod. The goal would be to get rid of duplicate libraries if possible. – Bartosz Bierkowski Feb 01 '17 at 07:04
  • I mentioned about what i get after running mvn dependency:tree command.. @bibix – mohitkira Feb 01 '17 at 20:26
  • Actually have a look at: http://stackoverflow.com/questions/22128150/spring-and-cross-context-webasyncmanager-cannot-be-cast-to-webasyncmanager Exactly your issue with several possible solutions - using common lib dir of tomcat or additional filter from atlassian. – Bartosz Bierkowski Feb 01 '17 at 21:02
  • I added a filter class but no luck its still showing me same error. @bibix – mohitkira Feb 07 '17 at 00:41