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.Queue;
18  import javax.jms.Session;
19  import javax.jms.Topic;
20  import javax.jms.TopicSubscriber;
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  import com.eviware.soapui.support.StringUtils;
27  
28  public class HermesJmsRequestSendSubscribeTransport extends HermesJmsRequestTransport
29  {
30  
31  	public Response execute( SubmitContext submitContext, Request request, long timeStarted ) throws Exception
32  	{
33  		Session topicSession = null;
34  		Session queueSession = null;
35  		TopicSubscriber topicSubsriber = null;
36  		JMSConnectionHolder jmsConnectionHolderTopic = null;
37  		JMSConnectionHolder jmsConnectionHolderQueue = null;
38  		try
39  		{
40  			init( submitContext, request );
41  			String clientIDString = StringUtils.hasContent( clientID ) ? clientID : jmsEndpoint.getSessionName() + "-"
42  					+ jmsEndpoint.getReceive();
43  			jmsConnectionHolderTopic = new JMSConnectionHolder( jmsEndpoint, hermes, true, clientIDString, username, password );
44  			jmsConnectionHolderQueue = new JMSConnectionHolder( jmsEndpoint, hermes, false, null, username, password );
45  			// session
46  			topicSession = jmsConnectionHolderTopic.getSession();
47  			queueSession = jmsConnectionHolderQueue.getSession();
48  
49  			Queue queueSend = jmsConnectionHolderQueue.getQueue( jmsConnectionHolderQueue.getJmsEndpoint().getSend() );
50  			Topic topicReceive = jmsConnectionHolderTopic.getTopic( jmsConnectionHolderTopic.getJmsEndpoint().getReceive() );
51  
52  			topicSubsriber = topicSession.createDurableSubscriber( topicReceive, StringUtils
53  					.hasContent( durableSubscriptionName ) ? durableSubscriptionName : "durableSubscription"
54  					+ jmsConnectionHolderTopic.getJmsEndpoint().getReceive(), messageSelector, false );
55  
56  			Message textMessageSend = messageSend( submitContext, request, queueSession, jmsConnectionHolderQueue.getHermes(),
57  					queueSend );
58  
59  			return makeResponse( submitContext, request, timeStarted, textMessageSend, topicSubsriber );
60  		}
61  		catch( JMSException jmse )
62  		{
63  			return errorResponse( submitContext, request, timeStarted, jmse );
64  		}
65  		catch( Throwable t )
66  		{
67  			SoapUI.logError( t );
68  		}
69  		finally
70  		{
71  			if( topicSubsriber != null )
72  				topicSubsriber.close();
73  			closeSessionAndConnection( jmsConnectionHolderQueue != null ? jmsConnectionHolderQueue.getConnection() : null,queueSession );
74  			closeSessionAndConnection( jmsConnectionHolderTopic != null ? jmsConnectionHolderTopic.getConnection() : null,topicSession );
75  		}
76  		return null;
77  	}
78  }