2015-10-14 50 views
0

我想在我的Junit測試中模擬http請求。所以我用Jadler Project。當我運行我的測試,並把我的http請求,我有這樣的例外:Java Jadler:碼頭衝突

java.lang.SecurityException: class "javax.servlet.AsyncContext"'s signer information does not match signer information of other classes in the same package 
at java.lang.ClassLoader.checkCerts(ClassLoader.java:806) 
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:487) 
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:625) 
at java.lang.ClassLoader.defineClass(ClassLoader.java:615) 
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) 
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) 
at java.net.URLClassLoader.access$000(URLClassLoader.java:58) 
at java.net.URLClassLoader$1.run(URLClassLoader.java:197) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.net.URLClassLoader.findClass(URLClassLoader.java:190) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:306) 
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:247) 
at org.eclipse.jetty.server.AbstractHttpConnection.<init>(AbstractHttpConnection.java:162) 
at org.eclipse.jetty.server.AsyncHttpConnection.<init>(AsyncHttpConnection.java:50) 
at org.eclipse.jetty.server.nio.SelectChannelConnector.newConnection(SelectChannelConnector.java:285) 
at org.eclipse.jetty.server.nio.SelectChannelConnector$ConnectorSelectorManager.newConnection(SelectChannelConnector.java:325) 
at org.eclipse.jetty.server.nio.SelectChannelConnector.newEndPoint(SelectChannelConnector.java:272) 
at org.eclipse.jetty.server.nio.SelectChannelConnector$ConnectorSelectorManager.newEndPoint(SelectChannelConnector.java:331) 
at org.eclipse.jetty.io.nio.SelectorManager$SelectSet.createEndPoint(SelectorManager.java:842) 
at org.eclipse.jetty.io.nio.SelectorManager$SelectSet.doSelect(SelectorManager.java:496) 
at org.eclipse.jetty.io.nio.SelectorManager$1.run(SelectorManager.java:290) 
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) 
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) 
at java.lang.Thread.run(Thread.java:662) 

在開始的時候我的依賴性看起來,對於JAdler:

<dependency> 
    <groupId>net.jadler</groupId> 
    <artifactId>jadler-core</artifactId> 
    <version>1.1.2</version> 
    <scope>test</scope> 
</dependency> 

<dependency> 
    <groupId>net.jadler</groupId> 
    <artifactId>jadler-jetty</artifactId> 
    <version>1.1.2</version> 
    <scope>test</scope> 
</dependency> 

<dependency> 
    <groupId>net.jadler</groupId> 
    <artifactId>jadler-junit</artifactId> 
    <version>1.1.2</version> 
    <scope>test</scope> 
</dependency> 

serveral的搜索後,我明白了爲什麼我有這個例外。爲了解決這個問題,我不得不改變我的依賴這樣的:

<dependency> 
    <groupId>net.jadler</groupId> 
    <artifactId>jadler-core</artifactId> 
    <version>1.1.2</version> 
    <scope>test</scope> 
</dependency> 
<dependency> 
    <groupId>net.jadler</groupId> 
    <artifactId>jadler-jetty</artifactId> 
    <version>1.1.2</version> 
    <scope>test</scope> 
    <exclusions> 
    <exclusion> 
     <groupId>org.eclipse.jetty</groupId> 
     <artifactId>jetty-server</artifactId> 
    </exclusion> 
    <exclusion> 
     <groupId>org.eclipse.jetty.orbit</groupId> 
     <artifactId>javax.servlet</artifactId> 
    </exclusion> 
    </exclusions> 
</dependency> 
<dependency> 
    <groupId>org.eclipse.jetty</groupId> 
    <artifactId>jetty-server</artifactId> 
    <version>8.1.18.v20150929</version> 
    <scope>test</scope> 
    <exclusions> 
    <exclusion> 
     <groupId>org.eclipse.jetty.orbit</groupId> 
     <artifactId>javax.servlet</artifactId> 
    </exclusion> 
    </exclusions> 
</dependency> 
<dependency> 
    <groupId>javax.servlet</groupId> 
    <artifactId>javax.servlet-api</artifactId> 
    <version>3.0.1</version> 
    <scope>test</scope> 
</dependency> 
<dependency> 
    <groupId>net.jadler</groupId> 
    <artifactId>jadler-junit</artifactId> 
    <version>1.1.2</version> 
    <scope>test</scope> 
</dependency> 

我明白,碼頭不使用org.eclipse.jetty.orbit的javax.servlet.AsyncContext:的javax.servlet但它使用的javax。 servlet:javax.servlet-api v3.0.1。

有人知道爲什麼嗎?解決方案更好

我的JDK版本是1.6.45。

如果您需要更多信息,例如我的測試資源告訴我。

編輯1:MVN依賴性:樹

+- commons-beanutils:commons-beanutils:jar:1.6:compile 
+- commons-collections:commons-collections:jar:3.2.1:compile 
+- commons-digester:commons-digester:jar:1.5:compile 
| \- xml-apis:xml-apis:jar:1.0.b2:compile 
+- commons-fileupload:commons-fileupload:jar:1.0:compile 
+- commons-lang:commons-lang:jar:2.6:compile 
+- commons-logging:commons-logging:jar:1.1.1:compile 
+- ant:ant-jakarta-oro:jar:1.6:compile 
+- log4j:log4j:jar:1.2.17:compile 
+- struts:struts:jar:1.2.9:compile 
|  +- commons-validator:commons-validator:jar:1.1.4:compile 
|  +- oro:oro:jar:2.0.7:compile 
| \- xalan:xalan:jar:2.5.1:compile 
+- oracle:orai18n:jar:14:compile 
+- oracle:ojdbc6:jar:11.1.0.7.0:provided 
+- oracle:xdb:jar:11.1.1.2.0:compile 
+- javax.servlet:servlet-api:jar:2.4:provided 
+- javax.servlet:jsp-api:jar:2.0:provided 
+- org.slf4j:slf4j-api:jar:1.7.5:compile 
+- org.slf4j:slf4j-log4j12:jar:1.7.12:test (scope not updated to compile) 
+- antlr:antlr:jar:2.7.6:compile 
+- com.fasterxml.jackson.core:jackson-databind:jar:2.6.0:compile 
|  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.0:compile 
| \- com.fasterxml.jackson.core:jackson-core:jar:2.6.0:compile 
+- net.sf.ehcache:ehcache:jar:2.10.0:compile 
+- org.springframework:spring-context:jar:3.2.14.RELEASE:compile 
|  +- org.springframework:spring-aop:jar:3.2.14.RELEASE:compile 
|  +- org.springframework:spring-beans:jar:3.2.14.RELEASE:compile 
|  +- org.springframework:spring-core:jar:3.2.14.RELEASE:compile 
| \- org.springframework:spring-expression:jar:3.2.14.RELEASE:compile 
+- org.springframework:spring-context-support:jar:3.2.14.RELEASE:compile 
+- junit:junit:jar:4.12:test 
| \- org.hamcrest:hamcrest-core:jar:1.3:test 
+- org.springframework:spring-test:jar:3.0.6.RELEASE:test 
+- net.jadler:jadler-core:jar:1.1.2:test 
|  +- org.hamcrest:hamcrest-library:jar:1.3:test 
| \- commons-io:commons-io:jar:2.4:test 
+- net.jadler:jadler-jetty:jar:1.1.2:test 
+- org.eclipse.jetty:jetty-server:jar:8.1.18.v20150929:test 
|  +- org.eclipse.jetty:jetty-continuation:jar:8.1.18.v20150929:test 
| \- org.eclipse.jetty:jetty-http:jar:8.1.18.v20150929:test 
|  \- org.eclipse.jetty:jetty-io:jar:8.1.18.v20150929:test 
|  \- org.eclipse.jetty:jetty-util:jar:8.1.18.v20150929:test 
+- javax.servlet:javax.servlet-api:jar:3.0.1:test 
    \- net.jadler:jadler-junit:jar:1.1.2:test 
+1

首先,也是最重要的:[Java 1.6在2013年是EOL(End of Life)](http://www.oracle.com/technetwork/java/eol-135779.html)和[碼頭8在2014年是EOL](https://dev.eclipse.org/mhonarc/lists/jetty-announce/msg00069.html)。其次,你可以爲你的項目做一個'mvn dependency:tree'並將它包含在你的問題中嗎? –

+0

是的,但我沒有選擇Java 1.6和JAdler使用Jetty 8 max。我在我的問題中添加了我的依賴關係樹。 –

+1

在問題中看不到'dependency:tree'。 –

回答

0
與我JDK的更新

最後爲servlet的API 3> 7 - (6 - > 7)和我的Tomcat(6 .x)錯誤已修復。感謝Joakim Erdelft。我認爲這是解決我的問題的servlet-api 3.x。

我的新的依賴:樹:

+- commons-beanutils:commons-beanutils:jar:1.6:compile 
+- commons-collections:commons-collections:jar:3.2.1:compile 
+- commons-digester:commons-digester:jar:1.5:compile 
| \- xml-apis:xml-apis:jar:1.0.b2:compile 
+- commons-fileupload:commons-fileupload:jar:1.0:compile 
+- commons-lang:commons-lang:jar:2.6:compile 
+- commons-logging:commons-logging:jar:1.1.1:compile 
+- ant:ant-jakarta-oro:jar:1.6:compile 
+- log4j:log4j:jar:1.2.17:compile 
+- struts:struts:jar:1.2.9:provided 
|  +- commons-validator:commons-validator:jar:1.1.4:provided 
|  +- oro:oro:jar:2.0.7:provided 
| \- xalan:xalan:jar:2.5.1:provided 
+- oracle:orai18n:jar:14:compile 
+- com.oracle:ojdbc6:jar:11.2.0.4:provided 
+- oracle:xdb:jar:11.2.0.3.0:compile 
+- javax.servlet:javax.servlet-api:jar:3.0.1:provided 
+- javax.servlet:jsp-api:jar:2.0:provided 
| \- javax.servlet:servlet-api:jar:2.4:provided 
+- org.slf4j:slf4j-api:jar:1.7.5:compile 
+- org.slf4j:slf4j-log4j12:jar:1.7.12:test (scope not updated to compile) 
+- antlr:antlr:jar:2.7.6:compile 
+- com.fasterxml.jackson.core:jackson-databind:jar:2.6.0:compile 
|  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.0:compile 
| \- com.fasterxml.jackson.core:jackson-core:jar:2.6.0:compile 
+- net.sf.ehcache:ehcache:jar:2.10.0:compile 
+- org.springframework:spring-context:jar:3.2.14.RELEASE:compile 
|  +- org.springframework:spring-aop:jar:3.2.14.RELEASE:compile 
|  +- org.springframework:spring-beans:jar:3.2.14.RELEASE:compile 
|  +- org.springframework:spring-core:jar:3.2.14.RELEASE:compile 
| \- org.springframework:spring-expression:jar:3.2.14.RELEASE:compile 
+- org.springframework:spring-context-support:jar:3.2.14.RELEASE:compile 
+- junit:junit:jar:4.12:test 
| \- org.hamcrest:hamcrest-core:jar:1.3:test 
+- org.springframework:spring-test:jar:3.2.14.RELEASE:test 
+- net.jadler:jadler-core:jar:1.1.2:test 
|  +- org.hamcrest:hamcrest-library:jar:1.3:test 
| \- commons-io:commons-io:jar:2.4:test 
+- net.jadler:jadler-jetty:jar:1.1.2:test 
|  +- org.eclipse.jetty:jetty-server:jar:8.1.11.v20130520:test 
|  |  +- org.eclipse.jetty:jetty-continuation:jar:8.1.11.v20130520:test 
|  | \- org.eclipse.jetty:jetty-http:jar:8.1.11.v20130520:test 
|  |  \- org.eclipse.jetty:jetty-io:jar:8.1.11.v20130520:test 
|  |  \- org.eclipse.jetty:jetty-util:jar:8.1.11.v20130520:test 
| \- org.eclipse.jetty.orbit:javax.servlet:jar:3.0.0.v201112011016:test 
    \- net.jadler:jadler-junit:jar:1.1.2:test 
1

您的依賴關係樹的servlet的API的兩倍。

+- javax.servlet:servlet-api:jar:2.4:provided 
+- javax.servlet:javax.servlet-api:jar:3.0.1:test 

刪除該javax.servlet:servlet-api:jar:2.4

然後標記javax.servlet:javax.servlet-api:jar:3.0.1作爲<scope>provided</scope>

+0

是的,我知道,但這不是問題。我的項目需要servlet-api 2.4,所以我把它們放在提供的位置。但是要使用jetty 8,我必須在範圍測試中添加servlet-api 3而不是org.eclipse.jetty.orbit:javax-servlet導致所使用的AsyncContext類在此庫中。在把servlet-api放在我的問題中之前,我把我的第一個jadler依賴關係放在了我的問題中。3. AsyncContext:https://tomcat.apache.org/tomcat-8.0-doc/servletapi/javax/servlet/AsyncContext.html –

+0

servlet jar是密封的並且包含signed/protected類,則不能同時在classpath中同時擁有這兩個類。這是行不通的。 –