001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.impl.wsdl.teststeps;
014:
015: import java.io.PrintWriter;
016:
017: import com.eviware.soapui.impl.wsdl.submit.transports.http.WsdlResponse;
018: import com.eviware.soapui.impl.wsdl.teststeps.actions.ShowMessageExchangeAction;
019: import com.eviware.soapui.model.iface.Attachment;
020: import com.eviware.soapui.model.iface.MessageExchange;
021: import com.eviware.soapui.support.action.swing.ActionList;
022: import com.eviware.soapui.support.types.StringToStringMap;
023: import com.eviware.soapui.support.xml.XmlUtils;
024:
025: /**
026: * TestStepResult for a WsdlTestRequestStep
027: *
028: * @author ole.matzura
029: */
030:
031: public class WsdlTestRequestStepResult extends WsdlTestStepResult
032: implements MessageExchange {
033: private String requestContent;
034: private WsdlResponse response;
035: private String domain;
036: private String username;
037: private String endpoint;
038: private String encoding;
039: private String password;
040: private StringToStringMap properties;
041: private boolean addedAction;
042:
043: public WsdlTestRequestStepResult(WsdlTestRequestStep step) {
044: super (step);
045: }
046:
047: public String getRequestContent() {
048: if (isDiscarded())
049: return "<discarded>";
050:
051: return requestContent;
052: }
053:
054: public void setRequestContent(String requestContent) {
055: this .requestContent = requestContent;
056: }
057:
058: public WsdlResponse getResponse() {
059: return response;
060: }
061:
062: @Override
063: public ActionList getActions() {
064: if (!addedAction) {
065: addAction(new ShowMessageExchangeAction(this , "TestStep"),
066: true);
067: addedAction = true;
068: }
069:
070: return super .getActions();
071: }
072:
073: public void setResponse(WsdlResponse response) {
074: this .response = response;
075: }
076:
077: public String getDomain() {
078: return domain;
079: }
080:
081: public void setDomain(String domain) {
082: this .domain = domain;
083: addProperty("domain", domain);
084: }
085:
086: private void addProperty(String key, String value) {
087: if (properties == null)
088: properties = new StringToStringMap();
089:
090: properties.put(key, value);
091: }
092:
093: public String getEncoding() {
094: return encoding;
095: }
096:
097: public void setEncoding(String encoding) {
098: this .encoding = encoding;
099: addProperty("encoding", encoding);
100: }
101:
102: public String getEndpoint() {
103: return endpoint;
104: }
105:
106: public void setEndpoint(String endpoint) {
107: this .endpoint = endpoint;
108: addProperty("endpoint", endpoint);
109: }
110:
111: public String getPassword() {
112: return password;
113: }
114:
115: public void setPassword(String password) {
116: this .password = password;
117: addProperty("password", password);
118: }
119:
120: public String getUsername() {
121: return username;
122: }
123:
124: public void setUsername(String username) {
125: this .username = username;
126: addProperty("username", username);
127: }
128:
129: public void discard() {
130: super .discard();
131:
132: requestContent = null;
133: response = null;
134: properties = null;
135: }
136:
137: public void writeTo(PrintWriter writer) {
138: super .writeTo(writer);
139:
140: writer
141: .println("----------------------------------------------------");
142: writer.println("Encoding: " + getEncoding());
143: writer.println("Endpoint: " + getEndpoint());
144: writer.println("Username: " + getUsername());
145: writer.println("Password: " + getPassword());
146: writer.println("Domain: " + getDomain());
147:
148: writer
149: .println("---------------- Request ---------------------------");
150: if (requestContent != null)
151: writer.println(XmlUtils.prettyPrintXml(requestContent));
152: else
153: writer.println("- missing request / garbage collected -");
154:
155: if (response != null) {
156: writer.println("Request Headers: "
157: + response.getRequestHeaders().toString());
158: }
159:
160: writer
161: .println("---------------- Response --------------------------");
162: if (response != null) {
163: String respContent = response.getContentAsString();
164: if (respContent != null)
165: writer.println(XmlUtils.prettyPrintXml(respContent));
166:
167: writer.println("Response Headers: "
168: + response.getResponseHeaders().toString());
169: } else
170: writer.println("- missing response / garbage collected -");
171: }
172:
173: public StringToStringMap getProperties() {
174: return properties;
175: }
176:
177: public Attachment[] getRequestAttachments() {
178: if (response == null || response.getRequest() == null)
179: return new Attachment[0];
180:
181: return response.getRequest().getAttachments();
182: }
183:
184: public StringToStringMap getRequestHeaders() {
185: if (response == null)
186: return null;
187:
188: return response.getRequestHeaders();
189: }
190:
191: public Attachment[] getResponseAttachments() {
192: if (response == null)
193: return new Attachment[0];
194:
195: return response.getAttachments();
196: }
197:
198: public String getResponseContent() {
199: if (isDiscarded())
200: return "<discarded>";
201:
202: if (response == null)
203: return "<missing response>";
204:
205: return response.getContentAsString();
206: }
207:
208: public StringToStringMap getResponseHeaders() {
209: if (response == null)
210: return null;
211:
212: return response.getResponseHeaders();
213: }
214:
215: public long getTimestamp() {
216: if (isDiscarded() || response == null)
217: return -1;
218:
219: return response.getTimestamp();
220: }
221: }
|