如何在导入连接到JMS MQ的SOAP项目时在Java项目中手动创建Hermes会话(How to create Hermes session manually in a java project w

系统教程 行业动态 更新时间:2024-06-14 17:03:54
如何在导入连接到JMS MQ的SOAP项目时在Java项目中手动创建Hermes会话(How to create Hermes session manually in a java project when importing a SOAP project that connects to a JMS MQ)

我创建了一个SoapUI项目,它与消息队列连接并向其发送JMS消息。 为了与MQ连接,我使用了SoapUI提供的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,它们是:

任何帮助,将不胜感激。

I have created a SoapUI project that connects with a message queue and sends a JMS message onto it. In order to connect with the MQ, I have used the HERMES tool that SoapUI provides. Currently I am using Hermes v1.14.

I've created the required session and the appropriate queues at Hermes' end and sent the JMS message after following the steps as shown here : https://www.soapui.org/documentation/jms/config.html, https://www.soapui.org/jms/working-with-jms-messages.html

This all works fine.

Now I am trying to incorporate this SOAPUI project into a Java project in which I will provide the project XML and run all the required Test Cases. I am unable to create the HERMES session and queues, etc. via Java code. Below are some code snippets from the class. Am I on the right path? Looking for some help to configure this.

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);

Output:

defaultHermesJMSPath - null soapuiHome - null

P.S. I have included a number of JARs for this which are :

Any help would be appreciated.

最满意答案

这个问题的主要关注点是制作一个最终独立于HERMES GUI的SOAP项目,以便配置会话,队列等。我最终做的是我为MQQueueConnectionFactory,QueueConnection,QueueSession,MQQueue创建了对象, MQQueueSender,我的GROOVY测试步骤中的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

The main concern for this question was to make a SOAP Project that is ultimately independent of the HERMES GUI in order to configure session, queues, etc. What I did in the end was that I created objects for MQQueueConnectionFactory, QueueConnection, QueueSession, MQQueue, MQQueueSender, JMSTextMessage in my GROOVY test step and sent the JMS Message to the queue. There was thus no need to open Hermes UI and configure the same there. Below is the sample code that can be followed.

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()

The following dependencies must already exist in both the SoapUI Lib(\SoapUI-5.2.1\lib) & Hermes Lib folder (\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

更多推荐

本文发布于:2023-04-24 14:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/909b26e1da18c6550b4b9a1954b62dd7.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   连接到   如何在   SOAP   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!