Search code examples
javajmssoapuimessage-queuehermes-jms

How to create Hermes session manually in a java project when importing a SOAP project that connects to a JMS MQ


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 :

enter image description here

Any help would be appreciated.


Solution

  • 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