Jetty ServletTester抛出SecurityException

时间:2014-12-05 16:52:49

标签: java jetty securityexception jar-signing

当我在我的类路径中放入以下依赖项(及其所有传递deps)时:

<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>test-jetty-servlet</artifactId>
    <version>8.1.14.v20131031</version>
</dependency>

运行此JUnit测试:

public class MySimpleTest {
    private ServletTester tester;

    @Before
    public void setUp() {
        tester = new ServletTester();
        tester.contextPath = "http://localhost:8080/myapp/location";
        tester.addServlet(MyAppMockEndpoint.class, "/address/*");
        tester.start();
    }

    @After
    public void tearDown() {
        tester.stop();
    }

    @Test
    public void test() {
        // Dummy assertion that is always true, just to prove its not
        // my code throwing the exception.
        Assert.assertTrue(System.currentTimeMillis() > 0L);
    }

    public class MyAppMockEndpoint extends HttpServlet {
        @Override
        public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.getWriter().println(provideJson())
            response.getWriter().flush()
        }

        public String provideJson() {
            return "{ \"id\": 5, \"fizz\": \"true\", \"buzz\": \"false\" }";
        }
    }
}

我明白了:

java.lang.SecurityException: class "javax.servlet.DispatcherType"'s signer information does not match signer information of other classes in the same package
    at java.lang.ClassLoader.checkCerts(ClassLoader.java:952)
    at java.lang.ClassLoader.preDefineClass(ClassLoader.java:666)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:794)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    <giant stack trace omitted for brevity>
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

为什么?有什么问题?如果其中一个传递依赖项已签名,我该如何判断哪一个?有没有办法指定所有传递deps的无符号版本?还有其他问题,还是更好的解决方案?

1 个答案:

答案 0 :(得分:0)

为了它的价值。我有一个类似的问题,通过删除我在我的路径中提供的冗余servlet-api(javax.servlet servlet-api 2.3提供)来摆脱它。

我能够从命令行运行测试(在我的情况下是sbt),但是当我从Intellij运行它们时,它们就崩溃了。