Forum Discussion

stephanusts's avatar
stephanusts
Occasional Contributor
7 years ago

how to groovy script with jms websphere

Hi there, do any of you guys have a groovy script that works with jms and Websphere MQ?   I'm struggling with the concept..   Regards SP
  • Nastya_Khovrina's avatar
    Nastya_Khovrina
    7 years ago

    Hi  Stephanus,

     

    Please see my comments:

    >> If I open JMS (Configure JMS) I press green arrow on the configs, I get no message so I think its working.

    You should have the message that the Connection successfully tested. 

     

     

    >> Do you have a groovy script that I can use with HermesJMS?

    The script from the Working With JMS From Groovy Scripts article works for the WebSphere provider too, you just need to change the jmsEndpoint value.

     

    import com.eviware.soapui.impl.wsdl.submit.transports.jms.JMSConnectionHolder
    import com.eviware.soapui.impl.wsdl.submit.transports.jms.util.HermesUtils
    import com.eviware.soapui.impl.wsdl.submit.transports.jms.JMSEndpoint
    import hermes.Hermes
    import javax.jms.*
    
    
    //Establishing the JMS connection
    def jmsEndpoint = new JMSEndpoint("jms://activeMQSession::queue_testQ1::queue_testQ1");
    def hermes = HermesUtils.getHermes( context.testCase.testSuite.project, jmsEndpoint.sessionName)
    def jmsConnectionHolder = new JMSConnectionHolder( jmsEndpoint, hermes, false, null, null, null);
    
    // Obtaining the session and queue
    Session queueSession = jmsConnectionHolder.getSession();
    Queue queueSend = jmsConnectionHolder.getQueue( jmsConnectionHolder.getJmsEndpoint().getSend() );
    Queue queueBrowse = jmsConnectionHolder.getQueue( jmsConnectionHolder.getJmsEndpoint().getReceive() );
    
    // Performing some actions
    MessageProducer messageProducer = queueSession.createProducer( queueSend );
    TextMessage textMessageSend = queueSession.createTextMessage();
    textMessageSend.setText( "A JMS message sent from ReadyAPI.");
    messageProducer.send( textMessageSend );
    textMessageSend.setText( "Another JMS message sent from ReadyAPI.");
    messageProducer.send( textMessageSend );
    
    // Logging elements
    QueueBrowser qb = queueSession.createBrowser(queueBrowse);
    Enumeration en = qb.getEnumeration();
    while(en.hasMoreElements())
    {
        TextMessage tm = (TextMessage)en.nextElement();
        log.info tm.getText()
    }
    jmsConnectionHolder.closeAll() // Make sure to close the session and connection

     

    >> If I want to as JMS Destination to project I 'm getting an error. Check the Error attached.
    This error occurs when the session isn't properly configured in HermesJMS.

     

    >> I also added the Hermes JMS screen to show that it works with the config file.

    Can you see the queues content in HermesJMS for the configured session: https://www.screencast.com/t/xuQK0QtFlDC

     

    You can also open a new support case here: https://support.smartbear.com/message/?prod=ReadyAPI