Spring Framework
  1. Spring Framework
  2. SPR-11049

Cannot create MockHttpSession with servlet 2.x

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Works as Designed
    • Affects Version/s: 4.0 RC1
    • Fix Version/s: None
    • Component/s: Test
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      This shows up in the Spring OAuth build with Spring 4.0:

      java.lang.NoClassDefFoundError: javax/servlet/SessionCookieConfig
      	at org.springframework.mock.web.MockHttpSession.<init>(MockHttpSession.java:99)
      	at org.springframework.mock.web.MockHttpSession.<init>(MockHttpSession.java:89)
      	at org.springframework.mock.web.MockHttpSession.<init>(MockHttpSession.java:80)
      

        Issue Links

          Activity

          Hide
          Sam Brannen added a comment -

          The Servlet API mocks in Spring Framework 4.0 support Servlet 3.0 and higher, as can be seen in GitHub commit deba32cad9.

          The reason why MockHttpSession can not be instantiated when running against Servlet 2.x is that the MockHttpSession constructor instantiates a MockServletContext which has a dependency on SessionCookieConfig from Servlet 3.0.

          Unfortunately, the Javadoc for MockHttpSession did not get updated with the corresponding GitHub commit.

          So I'll update the Javadoc and resolve this issue as Works as Designed.

          Regards,

          Sam

          Show
          Sam Brannen added a comment - The Servlet API mocks in Spring Framework 4.0 support Servlet 3.0 and higher, as can be seen in GitHub commit deba32cad9 . The reason why MockHttpSession can not be instantiated when running against Servlet 2.x is that the MockHttpSession constructor instantiates a MockServletContext which has a dependency on SessionCookieConfig from Servlet 3.0. Unfortunately, the Javadoc for MockHttpSession did not get updated with the corresponding GitHub commit. So I'll update the Javadoc and resolve this issue as Works as Designed . Regards, Sam
          Hide
          Sam Brannen added a comment -

          Outstanding documentation issues have been addressed as described in the comments for GitHub commit 2e6c998168:

          Update Javadoc for mocks regarding Servlet 3.0

          Commit deba32cad9 upgraded the Servlet API mocks to Servlet 3.0;
          however, not all of the Javadoc was updated accordingly.

          This commit updates the remaining Javadoc with regard to Servlet 3.0 as
          the baseline for mocks in the spring-test module.

          In addition, this commit syncs up the mocks used for internal testing in
          the spring-web module with the most current versions in spring-test.

          Show
          Sam Brannen added a comment - Outstanding documentation issues have been addressed as described in the comments for GitHub commit 2e6c998168 : Update Javadoc for mocks regarding Servlet 3.0 Commit deba32cad9 upgraded the Servlet API mocks to Servlet 3.0; however, not all of the Javadoc was updated accordingly. This commit updates the remaining Javadoc with regard to Servlet 3.0 as the baseline for mocks in the spring-test module. In addition, this commit syncs up the mocks used for internal testing in the spring-web module with the most current versions in spring-test.
          Hide
          Franz Neumann added a comment -

          What about those guys, who can't use Servlet 3.x i.e in Google Appengine it's defined on server as 2.5. Does it mean, that we can't use spring 4 before we changed to Servlet 3?

          Show
          Franz Neumann added a comment - What about those guys, who can't use Servlet 3.x i.e in Google Appengine it's defined on server as 2.5. Does it mean, that we can't use spring 4 before we changed to Servlet 3?
          Hide
          Dave Syer added a comment -

          No, it means you can't use Servlet 2.5 jars for testing. Your app will still run in Appengine.

          Show
          Dave Syer added a comment - No, it means you can't use Servlet 2.5 jars for testing. Your app will still run in Appengine.
          Hide
          Franz Neumann added a comment - - edited

          Ok, Ive got it later. But, I actually tried to run my integration (unit) tests with Spring 4, but I got the same exception java.lang.NoClassDefFoundError: javax/servlet/SessionCookieConfig. I think it's because, I use also appengine test-libs for testing and there are also some incompatibilities

          java.lang.NoClassDefFoundError: javax/servlet/SessionCookieConfig
          	at org.springframework.test.context.web.AbstractGenericWebContextLoader.configureWebResources(AbstractGenericWebContextLoader.java:182)
          	at org.springframework.test.context.web.AbstractGenericWebContextLoader.loadContext(AbstractGenericWebContextLoader.java:123)
          	at org.springframework.test.context.web.AbstractGenericWebContextLoader.loadContext(AbstractGenericWebContextLoader.java:60)
          	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
          	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:250)
          	at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
          	at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
          	at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:101)
          	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
          	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
          	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:326)
          	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:212)
          	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
          	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
          	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
          	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:232)
          	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
          	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
          	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
          	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
          	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
          	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
          	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
          	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
          	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
          	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:175)
          	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
          	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
          	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
          	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
          	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
          	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
          Caused by: java.lang.ClassNotFoundException: javax.servlet.SessionCookieConfig
          	at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
          	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
          	at java.security.AccessController.doPrivileged(Native Method)
          	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
          	at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
          	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
          	at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
          	... 32 more
           
          
          

          Show
          Franz Neumann added a comment - - edited Ok, Ive got it later. But, I actually tried to run my integration (unit) tests with Spring 4, but I got the same exception java.lang.NoClassDefFoundError: javax/servlet/SessionCookieConfig. I think it's because, I use also appengine test-libs for testing and there are also some incompatibilities java.lang.NoClassDefFoundError: javax/servlet/SessionCookieConfig at org.springframework.test.context.web.AbstractGenericWebContextLoader.configureWebResources(AbstractGenericWebContextLoader.java:182) at org.springframework.test.context.web.AbstractGenericWebContextLoader.loadContext(AbstractGenericWebContextLoader.java:123) at org.springframework.test.context.web.AbstractGenericWebContextLoader.loadContext(AbstractGenericWebContextLoader.java:60) at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100) at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:250) at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64) at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91) at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:101) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:326) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:212) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:232) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:175) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: java.lang.ClassNotFoundException: javax.servlet.SessionCookieConfig at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:423) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) ... 32 more  
          Hide
          Sam Brannen added a comment -

          As mentioned in the Spring Framework 4.0 Reference Manual...

          Deployment to Servlet 2.5 servers remains an option, but Spring Framework 4.0 is now focused primarily on Servlet 3.0+ environments. If you are using the Spring MVC Test Framework you will need to ensure that a Servlet 3.0 compatible JAR is in your test classpath.

          Show
          Sam Brannen added a comment - As mentioned in the Spring Framework 4.0 Reference Manual ... Deployment to Servlet 2.5 servers remains an option, but Spring Framework 4.0 is now focused primarily on Servlet 3.0+ environments. If you are using the Spring MVC Test Framework you will need to ensure that a Servlet 3.0 compatible JAR is in your test classpath.
          Hide
          Franz Neumann added a comment -

          so i found a solution for my problem
          just add in pom.xml dependency for Servlet 3.0 with scope test and it shold work
          i.e.

          	<dependency>
          			<groupId>org.apache.geronimo.specs</groupId>
          			<artifactId>geronimo-servlet_3.0_spec</artifactId>
          			<version>1.0</version>
          			<scope>test</scope>
          		</dependency>

          Show
          Franz Neumann added a comment - so i found a solution for my problem just add in pom.xml dependency for Servlet 3.0 with scope test and it shold work i.e. <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-servlet_3.0_spec</artifactId> <version>1.0</version> <scope>test</scope> </dependency>
          Hide
          Sam Brannen added a comment -

          Great!

          Glad you found a solution, Franz.

          Show
          Sam Brannen added a comment - Great! Glad you found a solution, Franz.

            People

            • Assignee:
              Sam Brannen
              Reporter:
              Dave Syer
              Last updater:
              Sam Brannen
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                1 year, 10 weeks, 5 days ago