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.mock;
014:
015: import java.io.IOException;
016: import java.io.OutputStream;
017: import java.util.Enumeration;
018:
019: import javax.servlet.http.HttpServletResponse;
020:
021: import org.mortbay.jetty.HttpFields;
022:
023: import com.eviware.soapui.impl.wsdl.panels.mockoperation.WsdlMockResultMessageExchange;
024: import com.eviware.soapui.impl.wsdl.teststeps.actions.ShowMessageExchangeAction;
025: import com.eviware.soapui.model.mock.MockResult;
026: import com.eviware.soapui.support.action.swing.ActionList;
027: import com.eviware.soapui.support.action.swing.DefaultActionList;
028: import com.eviware.soapui.support.types.StringToStringMap;
029:
030: /**
031: * The result of a handled WsdlMockRequest
032: *
033: * @author ole.matzura
034: */
035:
036: public class WsdlMockResult implements MockResult {
037: private WsdlMockResponse mockResponse;
038: private String responseContent;
039: private long timeTaken;
040: private long timestamp;
041: private DefaultActionList actions;
042: private StringToStringMap responseHeaders = new StringToStringMap();
043: private WsdlMockRequest mockRequest;
044: private HttpServletResponse response;
045:
046: public WsdlMockResult(WsdlMockRequest request,
047: HttpServletResponse response) throws Exception {
048: this .response = response;
049: timestamp = System.currentTimeMillis();
050: mockRequest = request;
051: }
052:
053: public WsdlMockRequest getMockRequest() {
054: return mockRequest;
055: }
056:
057: public ActionList getActions() {
058: if (actions == null) {
059: actions = new DefaultActionList("MockResult");
060: actions.setDefaultAction(new ShowMessageExchangeAction(
061: new WsdlMockResultMessageExchange(this ),
062: "MockResult"));
063: }
064:
065: return actions;
066: }
067:
068: public WsdlMockResponse getMockResponse() {
069: return mockResponse;
070: }
071:
072: public String getResponseContent() {
073: return responseContent;
074: }
075:
076: public long getTimeTaken() {
077: return timeTaken;
078: }
079:
080: public long getTimestamp() {
081: return timestamp;
082: }
083:
084: public void setTimestamp(long timestamp) {
085: this .timestamp = timestamp;
086: }
087:
088: public void setTimeTaken(long timeTaken) {
089: this .timeTaken = timeTaken;
090: }
091:
092: public StringToStringMap getResponseHeaders() {
093: return responseHeaders;
094: }
095:
096: public void setMockResponse(WsdlMockResponse mockResponse) {
097: this .mockResponse = mockResponse;
098: }
099:
100: /**
101: * @deprecated
102: */
103:
104: public void setReponseContent(String responseContent) {
105: this .responseContent = responseContent;
106: }
107:
108: public void setResponseContent(String responseContent) {
109: this .responseContent = responseContent;
110: }
111:
112: @SuppressWarnings("unchecked")
113: public void finish() {
114: HttpFields httpFields = ((org.mortbay.jetty.Response) response)
115: .getHttpFields();
116:
117: Enumeration<String> e = httpFields.getFieldNames();
118: while (e.hasMoreElements()) {
119: String nextElement = e.nextElement();
120: responseHeaders.put(nextElement, httpFields
121: .getStringField(nextElement));
122: }
123:
124: response = null;
125: }
126:
127: public void addHeader(String name, String value) {
128: if (response != null)
129: response.addHeader(name, value);
130: else
131: responseHeaders.put(name, value);
132: }
133:
134: public boolean isCommitted() {
135: return response.isCommitted();
136: }
137:
138: public void setContentType(String string) {
139: response.setContentType(string);
140: }
141:
142: public OutputStream getOutputStream() throws IOException {
143: return response.getOutputStream();
144: }
145:
146: public void initResponse() {
147: response.setStatus(HttpServletResponse.SC_OK);
148: }
149:
150: public boolean isDiscarded() {
151: return false;
152: }
153: }
|