Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create MockHttpSession with servlet 2.x [SPR-11049] #15676

Closed
spring-projects-issues opened this issue Oct 31, 2013 · 8 comments
Closed
Assignees
Labels
in: test Issues in the test module status: declined A suggestion or change that we don't feel we should currently apply

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Oct 31, 2013

Dave Syer opened SPR-11049 and commented

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)

Affects: 4.0 RC1

Issue Links:

Referenced from: commits 2e6c998

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

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

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

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

Update Javadoc for mocks regarding Servlet 3.0

Commit deba32c 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.

@spring-projects-issues
Copy link
Collaborator Author

Franz Neumann commented

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?

@spring-projects-issues
Copy link
Collaborator Author

Dave Syer commented

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

@spring-projects-issues
Copy link
Collaborator Author

Franz Neumann commented

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


@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

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.

@spring-projects-issues
Copy link
Collaborator Author

Franz Neumann commented

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>

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

Great!

Glad you found a solution, Franz. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

2 participants