Forum Discussion

mahesh_avinash1's avatar
mahesh_avinash1
Occasional Contributor
8 years ago

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

  • nmrao's avatar
    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.