我们想使用 arquillian 测试我们的 REST API。
我们使用 glassfish 进行生产和 arquillian。
我们已经对我们公开的一些 JMS 队列进行了 arquillian 测试,而且效果很好,所以我们至少有一些基础知识是正确的。当我们开始使用该设置进行 REST 测试时,在我们在 REST URL 上发送的第一个 HTTP GET 时,我们得到了异常:
com.sun.jersey.api.container.ContainerException: No WebApplication provider is present.
这是我们的 ShrinkWrap 设置:
public static WebArchive createTestArchive() {
return ShrinkWrap.create(WebArchive.class, "test.war") // Create jar
.addPackages(true, "<our packages, plus some dependencies>") //, "com.ocpsoft.pretty")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") // b
.setWebXML("WEB-INF/web.xml")
.addAsWebInfResource("WEB-INF/faces-config.xml")
//.addAsWebInfResource(new StringAsset("<faces-config version=\"2.0\"/>"), "faces-config.xml")
.addAsResource("META-INF/test-persistence.xml", "META-INF/persistence.xml");
}
我认为我们的 web.xml 是相关的:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<!-- Pretty faces config -->
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
<dispatcher>ASYNC</dispatcher>
</filter-mapping>
<!-- disable annotation scanning by the PrettyFaces module -->
<context-param>
<param-name>com.ocpsoft.pretty.BASE_PACKAGES</param-name>
<param-value>none</param-value>
</context-param>
</web-app>
编辑:由于这个问题,我现在已更改为 glassfish-embedded 3.1.1,并根据新的错误消息更新了问题。我们使用 glassfish 3.1.2 进行主要操作。
另请注意,我们首先收到警告:
WARNING: Could not instantiate service class org.glassfish.osgicdi.impl.OSGiServiceExtension
java.lang.NoClassDefFoundError: org/osgi/framework/ServiceException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
[..]
Caused by: java.lang.ClassNotFoundException: org.osgi.framework.ServiceException
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)
(但似乎忽略该警告是安全的,请参阅此及其链接到的错误:http://www.java.net/forum/topic/glassfish/glassfish/could-not-instantiate-service-class-orgglassfishosgicdiimplosgiserviceextension?力=217 )
然后是错误:
SEVERE: WebModule[/test]StandardWrapper.Throwable
com.sun.jersey.api.container.ContainerException: No WebApplication provider is present
at com.sun.jersey.spi.container.WebApplicationFactory.createWebApplication(WebApplicationFactory.java:69)
at com.sun.jersey.spi.container.servlet.ServletContainer.create(ServletContainer.java:391)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.create(ServletContainer.java:306)