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