Ask a Question

How to take file path from command line for sending jms file on queue.

mahesh_avinash1
Occasional Contributor

How to take file path from command line for sending jms file on queue.

Below is code for producing message. My requirement is to send file on JMS queue.

 

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.*
import javax.mail.internet.MimeBodyPart
import javax.activation.*;


Properties properties = new Properties()
//'C:/Users/mahekumar/Desktop/testProperty.properties'
def filePath=testRunner.testCase.testSuite.getPropertyValue( "config-filePath" )

File propertiesFile = new File(filePath)
propertiesFile.withInputStream {
properties.load(it)
}

def Queue1_jmsEndpoint = new JMSEndpoint(properties.Queue1);
def Queue1_hermes = HermesUtils.getHermes( context.testCase.testSuite.project, Queue1_jmsEndpoint.sessionName)
def Queue1_jmsConnectionHolder = new JMSConnectionHolder( Queue1_jmsEndpoint, Queue1_hermes, false, null ,null ,null);
Session Queue1_queueSession = Queue1_jmsConnectionHolder.getSession();
Queue Queue1_queueSend = Queue1_jmsConnectionHolder.getQueue(Queue1_jmsConnectionHolder.getJmsEndpoint().getSend() );
MessageProducer Queue1_messageProducer =Queue1_queueSession.createProducer(Queue1_queueSend );
TextMessage Queue1_textMessageSend = Queue1_queueSession.createTextMessage();


Queue1_textMessageSend.setStringProperty("Organization", properties.Queue1_organization);
Queue1_textMessageSend.setStringProperty("Hostname", properties.Queue1_host);
Queue1_textMessageSend.setStringProperty("User", properties.Queue1_user);
Queue1_textMessageSend.setText(properties.jmsMessage);

 

//Here, I need to implement file sending logic

 

 

 

Queue1_jmsConnectionHolder.closeAll()

2 REPLIES 2
MarcusJ
Moderator

Hi,

 

You would send the message with:

 

Queue1_messageProducer.send( Queue_textMessageSend );

Please look at the below link which provides a Groovy script related to sending and browsing JMS messages with SoapUI.

 

https://www.soapui.org/jms/working-with-jms-messages.html

 

Regards,

Marcus

SmartBear Support


Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
nmrao
Champion Level 3

I believe that you wanted to input a file name using command line and send the contents of that file as message. Is it so?

Then you can just use property expansion say ${#Project#MESSAGE_FILE} in your script to get the dynamic file name as input.

While running command line, pass -PMESSAGE_FILE=</absolute/file/path>

And hope you know how to get the file contents like:

def contents = new File(context.expand('${#Project#MESSAGE_FILE}')).text

Now 'content' variable has your file content.

Hope this helps.


Regards,
Rao.
cancel
Showing results for 
Search instead for 
Did you mean: