1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.teststeps;
14
15 import java.io.PrintWriter;
16
17 import com.eviware.soapui.impl.wsdl.submit.transports.http.WsdlResponse;
18 import com.eviware.soapui.impl.wsdl.teststeps.actions.ShowMessageExchangeAction;
19 import com.eviware.soapui.model.iface.Attachment;
20 import com.eviware.soapui.model.iface.MessageExchange;
21 import com.eviware.soapui.support.action.swing.ActionList;
22 import com.eviware.soapui.support.types.StringToStringMap;
23 import com.eviware.soapui.support.xml.XmlUtils;
24
25 /***
26 * TestStepResult for a WsdlTestRequestStep
27 *
28 * @author ole.matzura
29 */
30
31 public class WsdlTestRequestStepResult extends WsdlTestStepResult implements MessageExchange
32 {
33 private String requestContent;
34 private WsdlResponse response;
35 private String domain;
36 private String username;
37 private String endpoint;
38 private String encoding;
39 private String password;
40 private StringToStringMap properties;
41 private boolean addedAction;
42
43 public WsdlTestRequestStepResult(WsdlTestRequestStep step )
44 {
45 super( step );
46 }
47
48 public String getRequestContent()
49 {
50 if( isDiscarded() )
51 return "<discarded>";
52
53 return requestContent;
54 }
55
56 public void setRequestContent(String requestContent)
57 {
58 this.requestContent = requestContent;
59 }
60
61 public WsdlResponse getResponse()
62 {
63 return response;
64 }
65
66 @Override
67 public ActionList getActions()
68 {
69 if( !addedAction )
70 {
71 addAction( new ShowMessageExchangeAction( this, "TestStep" ), true );
72 addedAction = true;
73 }
74
75 return super.getActions();
76 }
77
78 public void setResponse(WsdlResponse response)
79 {
80 this.response = response;
81 }
82
83 public String getDomain()
84 {
85 return domain;
86 }
87
88 public void setDomain(String domain)
89 {
90 this.domain = domain;
91 addProperty( "domain", domain );
92 }
93
94 private void addProperty( String key, String value )
95 {
96 if( properties == null )
97 properties = new StringToStringMap();
98
99 properties.put( key, value );
100 }
101
102 public String getEncoding()
103 {
104 return encoding;
105 }
106
107 public void setEncoding(String encoding)
108 {
109 this.encoding = encoding;
110 addProperty( "encoding", encoding );
111 }
112
113 public String getEndpoint()
114 {
115 return endpoint;
116 }
117
118 public void setEndpoint(String endpoint)
119 {
120 this.endpoint = endpoint;
121 addProperty( "endpoint", endpoint );
122 }
123
124 public String getPassword()
125 {
126 return password;
127 }
128
129 public void setPassword(String password)
130 {
131 this.password = password;
132 addProperty( "password", password );
133 }
134
135 public String getUsername()
136 {
137 return username;
138 }
139
140 public void setUsername(String username)
141 {
142 this.username = username;
143 addProperty( "username", username );
144 }
145
146 public void discard()
147 {
148 super.discard();
149
150 requestContent = null;
151 response = null;
152 properties = null;
153 }
154
155 public void writeTo(PrintWriter writer)
156 {
157 super.writeTo( writer );
158
159 writer.println( "----------------------------------------------------" );
160 writer.println( "Encoding: " + getEncoding() );
161 writer.println( "Endpoint: " + getEndpoint() );
162 writer.println( "Username: " + getUsername() );
163 writer.println( "Password: " + getPassword() );
164 writer.println( "Domain: " + getDomain() );
165
166 writer.println( "---------------- Request ---------------------------" );
167 if( requestContent != null )
168 writer.println( XmlUtils.prettyPrintXml( requestContent ) );
169 else
170 writer.println( "- missing request / garbage collected -" );
171
172 if( response != null )
173 {
174 writer.println( "Request Headers: " + response.getRequestHeaders().toString() );
175 }
176
177 writer.println( "---------------- Response --------------------------" );
178 if( response != null )
179 {
180 String respContent = response.getContentAsString();
181 if( respContent != null )
182 writer.println( XmlUtils.prettyPrintXml( respContent ) );
183
184 writer.println( "Response Headers: " + response.getResponseHeaders().toString() );
185 }
186 else
187 writer.println( "- missing response / garbage collected -" );
188 }
189
190 public StringToStringMap getProperties()
191 {
192 return properties;
193 }
194
195 public Attachment[] getRequestAttachments()
196 {
197 if( response == null || response.getRequest() == null )
198 return new Attachment[0];
199
200 return response.getRequest().getAttachments();
201 }
202
203 public StringToStringMap getRequestHeaders()
204 {
205 if( response == null )
206 return null;
207
208 return response.getRequestHeaders();
209 }
210
211 public Attachment[] getResponseAttachments()
212 {
213 if( response == null )
214 return new Attachment[0];
215
216 return response.getAttachments();
217 }
218
219 public String getResponseContent()
220 {
221 if( isDiscarded() )
222 return "<discarded>";
223
224 if( response == null )
225 return "<missing response>";
226
227 return response.getContentAsString();
228 }
229
230 public StringToStringMap getResponseHeaders()
231 {
232 if( response == null )
233 return null;
234
235 return response.getResponseHeaders();
236 }
237
238 public long getTimestamp()
239 {
240 if( isDiscarded() || response == null )
241 return -1;
242
243 return response.getTimestamp();
244 }
245 }