关于 glassfish:使用 Arquillian 测试 Web 服务部署:上下文根为空

Testing web service deployment with Arquillian: context root is null

我想使用 Arquillian 将具有 Web 服务外观的企业应用程序部署到 glassfish。我对这个主题不是很有经验。

我发送带有注释的 WebService 和接口代码。

WebService 实现:

1
2
3
4
5
6
@Stateless
@WebService(endpointInterface ="ena.access.ticketsservices.facade.ITicketsRoleMappingsFacade")
@DeclareRoles({"User","Guest","ProjectAdmin","Admin" })
public class TicketsRoleMappingsFacade implements ITicketsRoleMappingsFacade {
 ...
}

接口:

1
2
3
4
5
6
7
@WebService(name ="TicketsRoleMappingsFacade")
public interface ITicketsRoleMappingsFacade {

  @WebMethod
  @WebResult(name ="createProjectResult")
  public Project createProject(@WebParam(name ="createproject") Project project);          
}

而下面的xml文件是glassfish的配置文件。

应用程序.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?xml version="1.0" encoding="UTF-8"?>
<application
    version="6"
    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/application_6.xsd">

    <display-name>j2ee-ear</display-name>

    <module>
        <ejb>j2ee-ejb.jar</ejb>
    </module>

    <security-role>
        <role-name>User</role-name>        
    </security-role>
    <security-role>
        <role-name>Guest</role-name>        
    </security-role>
    <security-role>
        <role-name>ProjectAdmin</role-name>        
    </security-role>
    <security-role>
        <role-name>Admin</role-name>        
    </security-role>

    <library-directory>lib</library-directory>

</application>

glassfish-application.xml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-application PUBLIC -//GlassFish.org//DTD GlassFish Application Server 3.1 Java EE Application 6.0//EN http://glassfish.org/dtds/glassfish-application_6_0-1.dtd>
<glassfish-application>

    <security-role-mapping>
        <role-name>User</role-name>
        <group-name>User</group-name>
    </security-role-mapping>
    <security-role-mapping>
        <role-name>Guest</role-name>
        <group-name>Guest</group-name>
    </security-role-mapping>
    <security-role-mapping>
        <role-name>ProjectAdmin</role-name>
        <group-name>ProjectAdmin</group-name>
    </security-role-mapping>
    <security-role-mapping>
        <role-name>Admin</role-name>
        <group-name>Admin</group-name>
    </security-role-mapping>
    <realm>someRealm</realm>
</glassfish-application>

glassfish-ejb-jar.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-ejb-jar PUBLIC -//GlassFish.org//DTD GlassFish Application Server 3.1 EJB 3.1//EN http://glassfish.org/dtds/glassfish-ejb-jar_3_1-1.dtd>
<glassfish-ejb-jar>

    <security-role-mapping>
        <role-name>User</role-name>
        <group-name>User</group-name>
    </security-role-mapping>
    <security-role-mapping>
        <role-name>Guest</role-name>
        <group-name>Guest</group-name>
    </security-role-mapping>
    <security-role-mapping>
        <role-name>ProjectAdmin</role-name>
        <group-name>ProjectAdmin</group-name>
    </security-role-mapping>
    <security-role-mapping>
        <role-name>Admin</role-name>
        <group-name>Admin</group-name>
    </security-role-mapping>
    <enterprise-beans>
        <ejb>
            <ejb-name>TicketsRoleMappingsFacade</ejb-name>
            <webservice-endpoint>
                <port-component-name>TicketsRoleMappingsFacade</port-component-name>
                <port-component-uri>/TicketsRoleMappingsFacade</port-component-uri>
            </webservice-endpoint>
        </ejb>
    </enterprise-beans>

</glassfish-ejb-jar>

当我使用 ShrinkWrap 构建 ear 文件并部署时,在日志服务器日志中获取以下行,所以我认为部分部署是成功的:

1
[#|2013-08-03T17:23:57.322+0200|INFO|glassfish3.1.1|javax.enterprise.webservices.org.glassfish.webservices|_ThreadID=17;_ThreadName=Thread-2;|WS00019: EJB Endpoint deployed j2ee-ear  listening at address at http://localhost:9999/TicketsRoleMappingsFacadeService/TicketsRoleMappingsFacade|#]

但我在 Arquillian 中也遇到以下异常:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
java.lang.IllegalArgumentException: contextRoot must not be null
    at org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet.<init>(Servlet.java:48)
    at org.jboss.arquillian.container.glassfish.clientutils.GlassFishClientService.resolveWebModuleSubComponents(GlassFishClientService.java:357)
    at org.jboss.arquillian.container.glassfish.clientutils.GlassFishClientService.doDeploy(GlassFishClientService.java:227)
    at org.jboss.arquillian.container.glassfish.CommonGlassFishManager.deploy(CommonGlassFishManager.java:101)
    at org.jboss.arquillian.container.glassfish.remote_3_1.GlassFishRestDeployableContainer.deploy(GlassFishRestDeployableContainer.java:71)
    at org.jboss.arquillian.container.impl.client.container.ContainerDeployController$3.call(ContainerDeployController.java:161)
    at org.jboss.arquillian.container.impl.client.container.ContainerDeployController$3.call(ContainerDeployController.java:128)
    at org.jboss.arquillian.container.impl.client.container.ContainerDeployController.executeOperation(ContainerDeployController.java:271)
    at org.jboss.arquillian.container.impl.client.container.ContainerDeployController.deploy(ContainerDeployController.java:127)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
    at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
    at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
    at
....

我没有用于此测试设置的任何 .war 文件如何为我的 Web 服务指定 contextRoot?


8年后,很高兴想起我的硕士论文的问题......
据我记得上面的代码没有问题,但是旧的 Arquillian 版本有一个错误。

几周后,我的主管从假期回来,刚刚更新了父项目中的 Arquillian 版本,测试开始按预期工作。


如果您没有 WAR(Web 应用程序),理论上您不需要 application.xml。我的建议,尝试删除它。

应用程序在 glassfish 中的成功部署并不意味着它可以在 Arquillian 中运行。 Arquillian 在文件名和上下文根方面存在一些问题(我在 WAR 文件中遇到了这个问题)

根据 JavaEE 6 文档,EAR 通常用于绑定 WAR 和 EJB。因此,理论上,如果您没有 WAR,那么您并不完全需要 EAR。您可以直接部署 EJB。