0

我创建了一个与消息队列连接并向其发送 JMS 消息的 SoapUI 项目。为了与 MQ 连接,我使用了 SoapUI 提供的 HERMES 工具。目前我正在使用 Hermes v1.14。

我已经在 Hermes 端创建了所需的会话和适当的队列,并按照此处所示的步骤发送了 JMS 消息:https : //www.soapui.org/documentation/jms/config.html,https:// www.soapui.org/jms/working-with-jms-messages.html

这一切都很好。

现在我正在尝试将这个 SOAPUI 项目合并到一个 Java 项目中,我将在其中提供项目 XML 并运行所有必需的测试用例。我无法通过 Java 代码创建 HERMES 会话和队列等。以下是该课程的一些代码片段。我在正确的道路上吗?寻找一些帮助来配置它。

TestRunner runner = null;
SoapUI.setSoapUICore(new StandaloneSoapUICore(true));
WsdlProject project = new WsdlProject("C:\\My Directory\\CustomerTest-soapui-project.xml");
List<TestSuite> suiteList = project.getTestSuiteList();

String defaultHermesJMSPath= HermesUtils.defaultHermesJMSPath();
System.out.println("defaultHermesJMSPath- "+defaultHermesJMSPath);

String soapUiHome = System.getProperty("soapui.home");
System.out.println("soapUiHome - "+soapUiHome);

//System.setProperty("soapui.home", "C:\\Program Files\\SmartBear\\SoapUI-5.2.1\\bin");

TestRunner runner = project.getTestSuiteByName("Private Individual").getTestCaseByName(
"TEST CASE CONTAINING GROOVY SCRIPT TEST STEPTHAT CONNECTS TO HERMES").run
(new PropertiesMap(), false);

输出:

defaultHermesJMSPath - null
soapuiHome - null

PS我为此包含了一些JAR,它们是:

在此处输入图像描述

任何帮助,将不胜感激。

4

2 回答 2

0

很简单,唯一的事情是您应该创建临时队列以获取响应

    import javax.jms.*;
    import java.util.Enumeration;

    public class JMSExample5 {

protected static final String SERVICE_QUEUE = "QUEUE_NAME_THAT_IS_CREDTED_IN_SERVER_FOR_ACCEPTING";
static String serverUrl = "tcp://10.xxx.xxx.xxx:xxxxx";
static String userName = "UR_UserID";
static String password = "UR_Pass";

public static void sendTopicMessage(String topicName, String messageStr) {

    Connection connection = null;
    Session session = null;
    MessageProducer msgProducer = null;
    Destination destination = null;

    try {
        TextMessage msg;
        System.out.println("Publishing to destination '" + topicName
                + "'\n");
        ConnectionFactory factory = new com.tibco.tibjms.TibjmsConnectionFactory(serverUrl);
        connection = factory.createConnection(userName, password);
        connection.start();
        session = connection
                .createSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);
        TemporaryQueue tempQueue = session.createTemporaryQueue();

        TextMessage message_t = session.createTextMessage(messageStr);
        //This step is compulsory to get the reply from JMS server
        message_t.setJMSReplyTo(tempQueue);
        MessageProducer producer = session.createProducer(session.createQueue(SERVICE_QUEUE));
        producer.send(message_t);

        System.out.println("INFO::  The producer has sent the message"+message_t);
        Destination dest = tempQueue;

        MessageConsumer consumer = session.createConsumer(dest);
        Message replyMsg = consumer.receive();
        TextMessage tm = (TextMessage) replyMsg;
        System.out.println("INFO The response is "+ replyMsg);
        consumer.close();
        producer.close();
        session.close();
        connection.close();

    } catch (JMSException e) {
         System.out.println("Error :: there was exception"+e);
        e.printStackTrace();
    }
}

/*-----------------------------------------------------------------------
 * main
 *----------------------------------------------------------------------*/
public static void main(String[] args) {
    JMSExample5.sendTopicMessage(SERVICE_QUEUE,
            "<?xml version = \"1.0\" encoding = \"UTF-8\"?>\n" +
                    "<MYServices>\n" +
                    " <header>\n" +
                    "  <Version>1.0</Version>\n" +
                    "  <SrvType>OML</SrvType>\n" +
                    "  <SrvName>REQ_BALANCE_ENQUIRY</SrvName>\n" +
                    "  <SrcApp>BNK</SrcApp>\n" +
                    "  <OrgId>BLA</OrgId>\n" +
                    " </header>\n" +
                    " <body>\n" +
                    "  <srv_req>\n" +
                    "   <req_credit_card_balance_enquiry>\n" +
                    "    <card_no>12345678</card_no>\n" +
                    "   </req_credit_card_balance_enquiry>\n" +
                    "  </srv_req>\n" +
                    " </body>\n" +
                    "</MYServices>\n");
}

}

于 2020-06-01T06:27:28.540 回答
0

这个问题的主要关注点是制作一个最终独立于 HERMES GUI的 SOAP 项目,以便配置会话、队列等。我最后所做的是为 MQQueueConnectionFactory、QueueConnection、QueueSession、MQQueue、我的 GROOVY 测试步骤中的 MQQueueSender、JMSTextMessage 并将 JMS 消息发送到队列。因此无需打开 Hermes UI 并在那里进行配置。以下是可以遵循的示例代码。

  def stringBuilder=context.expand('${CustomerXmlsAndCdbs#MasterXmlPrivateIndividual}');
  MQQueueConnectionFactory cf = new MQQueueConnectionFactory()
  cf.setHostName(context.expand('${#Project#HostName}'));
  cf.setPort(Integer.parseInt(context.expand('${#Project#Port}')))
  cf.setQueueManager(context.expand('${#Project#QueueManager}'))
  cf.setTransportType(Integer.parseInt(context.expand('${#Project#TransportType}')))
  QueueConnection queueConn = cf.createQueueConnection("retapp","retapp")
  QueueSession queueSession = queueConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE)

  MQQueue queue = (MQQueue) queueSession.createQueue(context.expand('${#Project#QueueName}').toString())

  MQQueueSender sender = (MQQueueSender) queueSession.createSender(queue)
  JMSTextMessage message = (JMSTextMessage) queueSession.createTextMessage(stringBuilder.toString())
  sender.send(message)
  sender.close()
  queueSession.close()
  queueConn.close()

SoapUI Lib ( \SoapUI-5.2.1\lib ) 和Hermes Lib 文件夹( \SoapUI-5.2.1\hermesJMS\lib )中必须已经存在以下依赖项:

com.ibm.dhbcore.jar、com.ibm.mq.jar、com.ibm.mq.pcf.jar、com.ibm.mqjms.jar、connector.jar、javax.transaction.jar

于 2016-09-07T04:48:55.403 回答