1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.mock;
14
15 import java.io.IOException;
16 import java.io.OutputStream;
17 import java.util.Enumeration;
18
19 import javax.servlet.http.HttpServletResponse;
20
21 import org.mortbay.jetty.HttpFields;
22
23 import com.eviware.soapui.impl.wsdl.panels.mockoperation.WsdlMockResultMessageExchange;
24 import com.eviware.soapui.impl.wsdl.teststeps.actions.ShowMessageExchangeAction;
25 import com.eviware.soapui.model.mock.MockResult;
26 import com.eviware.soapui.support.action.ActionList;
27 import com.eviware.soapui.support.action.DefaultActionList;
28 import com.eviware.soapui.support.types.StringToStringMap;
29
30 public class WsdlMockResult implements MockResult
31 {
32 private WsdlMockResponse mockResponse;
33 private String responseContent;
34 private long timeTaken;
35 private long timestamp;
36 private DefaultActionList actions;
37 private StringToStringMap responseHeaders = new StringToStringMap();
38 private WsdlMockRequest mockRequest;
39 private HttpServletResponse response;
40
41 public WsdlMockResult( WsdlMockRequest request, HttpServletResponse response ) throws Exception
42 {
43 this.response = response;
44 timestamp = System.currentTimeMillis();
45 mockRequest = request;
46 }
47
48 public WsdlMockRequest getMockRequest()
49 {
50 return mockRequest;
51 }
52
53 public ActionList getActions()
54 {
55 if( actions == null )
56 {
57 actions = new DefaultActionList( "MockResult" );
58 actions.setDefaultAction( new ShowMessageExchangeAction( new WsdlMockResultMessageExchange( this ), "MockResult") );
59 }
60
61 return actions;
62 }
63
64 public WsdlMockResponse getMockResponse()
65 {
66 return mockResponse;
67 }
68
69 public String getResponseContent()
70 {
71 return responseContent;
72 }
73
74 public long getTimeTaken()
75 {
76 return timeTaken;
77 }
78
79 public long getTimestamp()
80 {
81 return timestamp;
82 }
83
84 public void setTimestamp( long timestamp )
85 {
86 this.timestamp = timestamp;
87 }
88
89 public void setTimeTaken( long timeTaken )
90 {
91 this.timeTaken = timeTaken;
92 }
93
94 public StringToStringMap getResponseHeaders()
95 {
96 return responseHeaders;
97 }
98
99 public void setMockResponse( WsdlMockResponse mockResponse )
100 {
101 this.mockResponse = mockResponse;
102 }
103
104 public void setReponseContent( String responseContent )
105 {
106 this.responseContent = responseContent;
107 }
108
109 public void finish()
110 {
111 HttpFields httpFields = ((org.mortbay.jetty.Response)response).getHttpFields();
112
113 Enumeration<String> e = httpFields.getFieldNames();
114 while( e.hasMoreElements() )
115 {
116 String nextElement = e.nextElement();
117 responseHeaders.put( nextElement, httpFields.getStringField( nextElement ) );
118 }
119
120 response = null;
121 }
122
123 public void addHeader( String name, String value )
124 {
125 if( response != null )
126 response.addHeader( name, value );
127 else
128 responseHeaders.put( name, value );
129 }
130
131 public boolean isCommitted()
132 {
133 return response.isCommitted();
134 }
135
136 public void setContentType( String string )
137 {
138 response.setContentType( string );
139 }
140
141 public OutputStream getOutputStream() throws IOException
142 {
143 return response.getOutputStream();
144 }
145
146 public void initResponse()
147 {
148 response.setStatus( HttpServletResponse.SC_OK );
149 }
150
151 public boolean isDiscarded()
152 {
153 return false;
154 }
155 }