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