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.Session;
18  import javax.jms.Topic;
19  import javax.jms.TopicSubscriber;
20  
21  import com.eviware.soapui.SoapUI;
22  import com.eviware.soapui.model.iface.Request;
23  import com.eviware.soapui.model.iface.Response;
24  import com.eviware.soapui.model.iface.SubmitContext;
25  import com.eviware.soapui.support.StringUtils;
26  
27  public class HermesJmsRequestPublishSubscribeTransport extends HermesJmsRequestTransport
28  {
29  
30  	public Response execute( SubmitContext submitContext, Request request, long timeStarted ) throws Exception
31  	{
32  		Session topicSession = null;
33  		TopicSubscriber topicDurableSubsriber = null;
34  		JMSConnectionHolder jmsConnectionHolder = null;
35  		try
36  		{
37  			init( submitContext, request );
38  			String clientIDString = StringUtils.hasContent( clientID ) ? clientID : jmsEndpoint.getSessionName() + "-"
39  					+ jmsEndpoint.getReceive();
40  			jmsConnectionHolder = new JMSConnectionHolder( jmsEndpoint, hermes, true, clientIDString, username,
41  					password );
42  
43  			// session
44  			topicSession = jmsConnectionHolder.getSession();
45  
46  			// destination
47  			Topic topicPublish = jmsConnectionHolder.getTopic( jmsConnectionHolder.getJmsEndpoint().getSend() );
48  			Topic topicSubscribe = jmsConnectionHolder.getTopic( jmsConnectionHolder.getJmsEndpoint().getReceive() );
49  
50  			topicDurableSubsriber = topicSession.createDurableSubscriber( topicSubscribe, StringUtils
51  					.hasContent( durableSubscriptionName ) ? durableSubscriptionName : "durableSubscription"
52  					+ jmsConnectionHolder.getJmsEndpoint().getReceive(), messageSelector, false );
53  
54  			Message messagePublish = messagePublish( submitContext, request, topicSession,
55  					jmsConnectionHolder.getHermes(), topicPublish );
56  
57  			return makeResponse( submitContext, request, timeStarted, messagePublish, 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  			closeSessionAndConnection( jmsConnectionHolder != null ? jmsConnectionHolder.getConnection() : null,
72  					topicSession );
73  		}
74  		return null;
75  	}
76  }