View Javadoc

1   /*
2    *  soapUI, copyright (C) 2006 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
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.teststeps.support;
14  
15  import java.io.PrintWriter;
16  import java.lang.ref.SoftReference;
17  
18  import com.eviware.soapui.impl.wsdl.submit.WsdlMessageExchange;
19  import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep;
20  import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStepResult;
21  import com.eviware.soapui.impl.wsdl.teststeps.actions.ShowMessageExchangeAction;
22  import com.eviware.soapui.support.types.StringToStringMap;
23  import com.eviware.soapui.support.xml.XmlUtils;
24  
25  public class WsdlMessageExchangeStepResult extends WsdlTestStepResult
26  {
27  	private SoftReference<WsdlMessageExchange> messageExchange;
28  	private SoftReference<StringToStringMap> properties;
29  	
30  	public WsdlMessageExchangeStepResult(WsdlTestStep step )
31  	{
32  		super( step );
33  	}
34  	
35  	public void setMessageExchange( WsdlMessageExchange messageExchange )
36  	{
37  		this.messageExchange = new SoftReference<WsdlMessageExchange>( messageExchange );
38  		addAction( new ShowMessageExchangeAction( messageExchange, "StepResult" ), true );
39  	}
40  
41  	public String getRequestContent()
42  	{
43  		if( isDiscarded() )
44  			return "<discarded>";
45  		
46  		if( messageExchange != null && messageExchange.get() == null ) 
47  			return "<garbage-collected>";
48  		
49  		return messageExchange == null ? null : messageExchange.get().getRequestContent();
50  	}
51  
52  	public void addProperty( String name, String value )
53  	{
54  		if( isDiscarded() )
55  			return;
56  		
57  		if( properties == null )
58  			properties = new SoftReference<StringToStringMap>( new StringToStringMap() );
59  		
60  		properties.get().put( name, value );
61  	}
62  	
63  	public void discard()
64  	{
65  		super.discard();
66  		
67  		messageExchange = null;
68  		properties = null;
69  	}
70  
71  	public void writeTo(PrintWriter writer)
72  	{
73  		super.writeTo( writer );
74  		
75  		if( isDiscarded() )
76  			return;
77  		
78  		writer.println( "---------------- Properties ------------------------" );
79  		StringToStringMap map = properties == null ? null : properties.get();
80  		if( map == null || map.isEmpty() )
81  		{
82  			writer.println( "Missing Properties" );
83  		}
84  		else
85  		{
86  			for( String name : map.keySet() )
87  				writer.println( name + ": " + map.get( name ) );
88  		}
89  
90  		writer.println( "---------------- Message Exchange ------------------" );
91  		WsdlMessageExchange me = messageExchange == null ? null : messageExchange.get();
92  		if( me == null )
93  		{
94  			writer.println( "Missing MessageExchange" );
95  		}
96  		else
97  		{
98  			writer.println( "--- Request" );
99  			if( me.getRequestHeaders() != null )
100 				writer.println( "Request Headers: " + me.getRequestHeaders().toString() );
101 			
102 			writer.println( XmlUtils.prettyPrintXml( me.getRequestContent() ) );
103 
104 			writer.println( "--- Response" );
105 			if( me.getResponseHeaders() != null )
106 				writer.println( "Response Headers: " + me.getResponseHeaders().toString() );
107 			
108 			writer.println( XmlUtils.prettyPrintXml( me.getResponseContent() ) );
109 		}
110 	}
111 
112 	public StringToStringMap getProperties()
113 	{
114 		return properties == null ? null : properties.get();
115 	}
116 }