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 topicDurableSubsriber = 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  
51  			Topic topicSubscribe = jmsConnectionHolderTopic.getTopic( jmsConnectionHolderTopic.getJmsEndpoint().getReceive() );
52  			topicDurableSubsriber = createDurableSubscription( submitContext, topicSession, jmsConnectionHolderTopic ); 
53  
54  			Message textMessageSend = messageSend( submitContext, request, queueSession, jmsConnectionHolderQueue.getHermes(),
55  					queueSend, topicSubscribe );
56  
57  			return makeResponse( submitContext, request, timeStarted, textMessageSend, topicDurableSubsriber );
58  		}
59  		catch( JMSException jmse )
60  		{
61  			return errorResponse( submitContext, request, timeStarted, jmse );
62  		}
63  		catch( Throwable t )
64  		{
65  			SoapUI.logError( t );
66  		}
67  		finally
68  		{
69  			if( topicDurableSubsriber != null )
70  				topicDurableSubsriber.close();
71  			jmsConnectionHolderQueue.closeAll();
72  			jmsConnectionHolderQueue.closeAll();
73  			closeSessionAndConnection( jmsConnectionHolderQueue != null ? jmsConnectionHolderQueue.getConnection() : null,queueSession );
74  			closeSessionAndConnection( jmsConnectionHolderTopic != null ? jmsConnectionHolderTopic.getConnection() : null,topicSession );
75  		}
76  		return null;
77  	}
78  }