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  package com.eviware.soapui.impl.wsdl.submit.transports.jms.util;
13  
14  import java.util.Enumeration;
15  
16  import javax.jms.JMSException;
17  import javax.jms.MapMessage;
18  
19  import com.eviware.soapui.SoapUI;
20  import com.eviware.soapui.impl.wsdl.submit.transports.jms.JMSEndpoint;
21  import com.eviware.soapui.impl.wsdl.support.MessageExchangeModelItem;
22  import com.eviware.soapui.model.ModelItem;
23  import com.eviware.soapui.model.iface.MessageExchange;
24  import com.eviware.soapui.model.iface.Request;
25  import com.eviware.soapui.support.types.StringToStringMap;
26  
27  public class JMSUtils
28  {
29  
30  	private static boolean checkIfJMS( Request request )
31  	{
32  		try
33  		{
34  			return request.getEndpoint().startsWith( JMSEndpoint.JMS_ENDPIONT_PREFIX );
35  		}
36  		catch( NullPointerException e )
37  		{
38  			SoapUI.logError( e );
39  		}
40  		return false;
41  	}
42  
43  	private static boolean checkIfJMS( MessageExchangeModelItem messageExchange )
44  	{
45  		try
46  		{
47  			MessageExchange me = ( ( MessageExchangeModelItem )messageExchange ).getMessageExchange();
48  			if( me != null )
49  			{
50  				StringToStringMap strmap = me.getProperties();
51  				if( strmap != null && strmap.containsKey( "Endpoint" ) )
52  				{
53  					String r = me.getProperty( "Endpoint" );
54  					return r != null && r.startsWith( JMSEndpoint.JMS_ENDPIONT_PREFIX );
55  				}else{
56  					return false;
57  				}
58  			}
59  			else
60  			{
61  				return false;
62  			}
63  		}
64  		catch( NullPointerException e )
65  		{
66  			SoapUI.logError( e );
67  		}
68  		return false;
69  	}
70  
71  	public static boolean checkIfJMS( ModelItem modelItem )
72  	{
73  		if( modelItem instanceof Request )
74  		{
75  			return checkIfJMS( ( Request )modelItem );
76  		}
77  		else
78  		{
79  			if( modelItem instanceof MessageExchangeModelItem )
80  			{
81  				return checkIfJMS( ( MessageExchangeModelItem )modelItem );
82  			}
83  		}
84  		return false;
85  	}
86  
87  	public static String extractMapMessagePayloadToString( MapMessage mapMessage ) throws JMSException
88  	{
89  		StringBuffer sb = new StringBuffer();
90  
91  		Enumeration<?> mapNames = mapMessage.getMapNames();
92  
93  		while( mapNames.hasMoreElements() )
94  		{
95  			String key = ( String )mapNames.nextElement();
96  			String value = mapMessage.getString( key );
97  			sb.append( key + ": " + value );
98  		}
99  
100 		return sb.toString();
101 	}
102 }