0

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.

chepaiytrath
  • 678
  • 1
  • 9
  • 20
  • `I am unable to configure the HERMES session manually via Java code` - confusing. Manually or automatic? – Rao Aug 25 '16 at 05:38
  • Hey Rao. Let me edit the description. By Manually, I meant creating the Hermes session and queues and all via Java code. I want to run the SOAP project independent of SOAPUI using JAVA. So I won't use HERMES UI to create the sessions, etc. – chepaiytrath Aug 25 '16 at 08:30
  • Do you have already configured `hermes-config.xml` with you? If so, then you really no need bother. It should be able execute the tests automatically. – Rao Aug 25 '16 at 16:58
  • @Rao I read about 'hermes-config.xml' somewhere on the web. Well, I am unable to find the file in any of my installation folders or in m2 or anywhere. Kindly share the exact address where I can find it. Also , once I do find it where do I need to place it and how do I need to configure it so that my project is able to read the properties. Note that I am creating a mere Java project and not a maven project in which I can configure pom.xml and insert new dependencies, etc. I just have a simple main class with which I plan to run my SOAP project. – chepaiytrath Aug 26 '16 at 03:29
  • Here is the path, SOAPUI_HOME/hermesJMS/cfg. But you need to configure it using SOAPUI, test it by sending a soap message. – Rao Aug 26 '16 at 03:54
  • @Rao Fortunately, I found the hermes-config.xml after reinstalling SOAPUI. Turns out there was some issue with the previous installation and it was missing the xml file. Now, how do I use it in my java project and when you say 'configure it using SOAPUI, test it by sending a soap message', what exactly do u mean? It is after all just a simple xml file with configurations of sessions and classpathgroups mentioned inside of it. – chepaiytrath Aug 26 '16 at 09:11
  • Check this http://ewaldertl.blogspot.in/2013/08/how-to-connect-to-websphere-mq-server.html – Rao Aug 26 '16 at 10:11
  • @Rao, I went through the above link. As I mentioned in the description, all the steps mentioned there have already been followed by me when I configured the sessions, queues, etc. through HermesGUI. But now I want to do all this in a Java project. i.e. I want to create a Hermes session using Java code with the properties like hostName, port, transportType, etc. – chepaiytrath Aug 26 '16 at 12:13

2 Answers2

0

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

chepaiytrath
  • 678
  • 1
  • 9
  • 20
0

It is simple only thing is you should create temporary queues to get the response

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

}

Shaheaz
  • 23
  • 5