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   *  soapUI, copyright (C) 2004-2010 eviware.com 
14   *
15   *  soapUI is free software; you can redistribute it and/or modify it under the 
16   *  terms of version 2.1 of the GNU Lesser General Public License as published by 
17   *  the Free Software Foundation.
18   *
19   *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
20   *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
21   *  See the GNU Lesser General Public License for more details at gnu.org.
22   */
23  
24  package com.eviware.soapui.impl.wsdl.submit.transports.jms;
25  
26  import javax.jms.JMSException;
27  import javax.jms.Session;
28  import javax.jms.TopicSubscriber;
29  
30  import com.eviware.soapui.SoapUI;
31  import com.eviware.soapui.model.iface.Request;
32  import com.eviware.soapui.model.iface.Response;
33  import com.eviware.soapui.model.iface.SubmitContext;
34  import com.eviware.soapui.support.StringUtils;
35  
36  public class HermesJmsRequestSubscribeTransport extends HermesJmsRequestTransport
37  {
38  
39  	public Response execute( SubmitContext submitContext, Request request, long timeStarted ) throws Exception
40  	{
41  		Session topicSession = null;
42  		TopicSubscriber topicDurableSubsriber = null;
43  		JMSConnectionHolder jmsConnectionHolder = null;
44  		try
45  		{
46  			init( submitContext, request );
47  			String clientIDString = StringUtils.hasContent( clientID ) ? clientID : jmsEndpoint.getSessionName() + "-"
48  					+ jmsEndpoint.getReceive();
49  			jmsConnectionHolder = new JMSConnectionHolder( jmsEndpoint, hermes,  true, clientIDString, username,
50  					password );
51  
52  			// session
53  			topicSession = jmsConnectionHolder.getSession();
54  			// destination
55  			topicDurableSubsriber = createDurableSubscription( submitContext, topicSession, jmsConnectionHolder );
56  
57  			return makeResponse( submitContext, request, timeStarted, null, 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  			jmsConnectionHolder.closeAll();
72  			closeSessionAndConnection( jmsConnectionHolder != null ? jmsConnectionHolder.getConnection() : null,topicSession );
73  		}
74  		return null;
75  	}
76  }