如何在IBM WAS中以编程方式启动()/ stop()ear应用程序?

问题描述 投票:0回答:1

我将使用Arquillian框架在IBM WAS 8.5.5上测试我的耳朵应用程序。我设法部署,启动并向我的耳朵发送JMS消息,并且耳朵已经按计划处理了此消息。根据我们的业务逻辑,每个ear都为其内部EJB组件之一实现IBM自动启动行为(比如说它是无状态会话Bean),因此组件的ejb-jar.xml如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="3.1" 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/ejb-jar_3_1.xsd">
    <enterprise-beans>
        <session>
            <ejb-name>MyBusinessEjb</ejb-name>
            <home>com.ibm.websphere.startupservice.AppStartUpHome</home>
            <remote>com.ibm.websphere.startupservice.AppStartUp</remote>
        </session>
        ...

并且一些内部EJB的代码是:

@Stateless(name = "MyBusinessEjb")
@TransactionManagement(TransactionManagementType.CONTAINER)
public class MyBusinessEjbBean implements TimedObject {

    public boolean start() {
        ... init some resources here
        return true;
    }

    public void stop() {
        ... free resources here
    }

    ...

但是唉 - Arquillian不允许应用程序调用start()和stop()方法。当管理员从IBM Console运行应用程序时,它们会自动调用(不使用由IBM WAS调用的带注释或部署描述符的拦截器)。在我的测试EJB中(当我的ear应用程序已部署时,它由arquillian加载)我可以查找MyBusinessEjb:

public void tryToCallStart() throws NamingException {
    InitialContext ic = new InitialContext();
    Object beanObj = ic.lookup("java:global/ear-app-1.0.0/ejb-module/MyBusinessEjb");
    AppStartUpHome beanHome = (AppStartUpHome) PortableRemoteObject.narrow(beanObj, AppStartUpHome.class);

但是JNDI只返回AppStartUpHome存根,而不是我可以调用startup()的AppStartUp,以及以下内容:

beanHome.create().start();

ofcourse只是创建并启动另一个bean实例,而不是我的:(

那么在Arquillian测试运行之前或期间,如何在my-business-1.0.0内的MyBusinessEjb上调用start()方法?或者也许有人知道如何调用start() - 使用arquillian.xml或Maven pom.xml来执行我的测试?

unit-testing java-ee websphere jboss-arquillian
1个回答
0
投票

我知道在WebSphere中以编程方式启动或停止应用程序的唯一方法是使用wsadmin命令行界面中的AdminControl。您可以编写一些代码来执行wsadmin脚本,该脚本将为您执行启动/停止。

也许是这样的:(免责声明,未经测试)

// any ${var} pieces are variables you will have to fill in
ProcessBuilder pb = new ProcessBuilder("/path/to/wsadmin.sh/bat", 
  "-conntype SOAP}",  
  "-host ${HOST}",
  "-port ${SOAP_PORT}",
  "-user ${USER_ID}",
  "-password ${PASS}",
  "-c $AdminControl invoke " + 
     "[$AdminControl queryNames cell=${CELL},node=${NODE},type=ApplicationManager,process=${PROCESS},*]" + 
     " startApplication ${APPLICATION_NAME}");
Process p = pb.start();
© www.soinside.com 2019 - 2024. All rights reserved.