View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.wsdl.submit.transports.jms;
14  
15  import javax.jms.JMSException;
16  import javax.jms.Message;
17  import javax.jms.MessageConsumer;
18  import javax.jms.Queue;
19  import javax.jms.Session;
20  import javax.jms.Topic;
21  
22  import com.eviware.soapui.SoapUI;
23  import com.eviware.soapui.model.iface.Request;
24  import com.eviware.soapui.model.iface.Response;
25  import com.eviware.soapui.model.iface.SubmitContext;
26  
27  public class HermesJmsRequestPublishReceiveTransport extends HermesJmsRequestTransport
28  {
29  
30  	public Response execute( SubmitContext submitContext, Request request, long timeStarted ) throws Exception
31  	{
32  		Session topicSession = null;
33  		Session queueSession = null;
34  		
35  		JMSConnectionHolder jmsConnectionHolderTopic = null;
36  		JMSConnectionHolder jmsConnectionHolderQueue = null;
37  		try
38  		{
39  			init( submitContext, request );
40  			jmsConnectionHolderTopic = new JMSConnectionHolder( jmsEndpoint, hermes, true, clientID, username, password );
41  			jmsConnectionHolderQueue = new JMSConnectionHolder( jmsEndpoint, hermes, false, null, username, password );
42  
43  			// session
44  			topicSession = jmsConnectionHolderTopic.getSession();
45  			queueSession = jmsConnectionHolderQueue.getSession();
46  
47  			// destination
48  			Topic topicPublish = jmsConnectionHolderTopic.getTopic( jmsConnectionHolderTopic.getJmsEndpoint().getSend() );
49  			Queue queueReceive = jmsConnectionHolderQueue.getQueue( jmsConnectionHolderQueue.getJmsEndpoint().getReceive() );
50  
51  			Message messagePublish = messagePublish( submitContext, request, topicSession,
52  					jmsConnectionHolderTopic.getHermes(), topicPublish );
53  
54  			MessageConsumer messageConsumer = queueSession.createConsumer( queueReceive, messageSelector );
55  
56  			return makeResponse( submitContext, request, timeStarted, messagePublish, messageConsumer );
57  		}
58  		catch( JMSException jmse )
59  		{
60  			return errorResponse( submitContext, request, timeStarted, jmse );
61  		}
62  		catch( Throwable t )
63  		{
64  			SoapUI.logError( t );
65  		}
66  		finally
67  		{
68  			closeSessionAndConnection( jmsConnectionHolderQueue != null ? jmsConnectionHolderQueue.getConnection() : null,queueSession );
69  			closeSessionAndConnection( jmsConnectionHolderTopic != null ? jmsConnectionHolderTopic.getConnection() : null,topicSession );
70  		
71  		}
72  		return null;
73  
74  	}
75  }