1

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

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

网络服务实现:

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

界面:

@WebService(name = "TicketsRoleMappingsFacade")
public interface ITicketsRoleMappingsFacade {

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

并且以下 xml 文件是 glassfish 配置文件。

应用程序.xml

<?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:

<?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

<?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 文件并部署时,在日志服务器日志中获取以下行,所以我认为部署的一部分是成功的:

[#|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 中也遇到了以下异常:

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?

4

2 回答 2

0

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

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

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

于 2017-12-07T14:33:04.440 回答
0

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

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

于 2021-07-05T21:20:29.163 回答