1
2
3
4
5
6
7
8
9
10
11
12 package com.eviware.soapui.impl.wsdl.submit.transports.jms;
13
14 import java.net.URL;
15 import java.util.ArrayList;
16 import java.util.Calendar;
17 import java.util.Enumeration;
18 import java.util.List;
19 import java.util.Vector;
20
21 import javax.jms.JMSException;
22 import javax.jms.Message;
23 import javax.jms.TextMessage;
24
25 import com.eviware.soapui.SoapUI;
26 import com.eviware.soapui.impl.rest.RestRequestInterface.RequestMethod;
27 import com.eviware.soapui.impl.wsdl.WsdlRequest;
28 import com.eviware.soapui.impl.wsdl.submit.transports.http.SSLInfo;
29 import com.eviware.soapui.impl.wsdl.submit.transports.http.WsdlResponse;
30 import com.eviware.soapui.model.iface.Attachment;
31 import com.eviware.soapui.model.iface.Request;
32 import com.eviware.soapui.support.types.StringToStringMap;
33
34 public class JMSResponse implements WsdlResponse
35 {
36
37 private String payload;
38 private Message messageReceive;
39 private Message messageSend;
40 private Attachment[] attachments = new Attachment[0];
41 private Request request;
42 private long requestStartedTime;
43 private String endpoint;
44
45 public JMSResponse(String payload, Message messageSend, Message messageReceive, Request request,
46 long requestStartedTime)
47 {
48 this.payload = payload;
49 this.messageReceive = messageReceive;
50 this.messageSend = messageSend;
51 this.request = request;
52 this.requestStartedTime = requestStartedTime;
53 this.endpoint=request.getEndpoint();
54 }
55
56 public Attachment[] getAttachments()
57 {
58 return attachments;
59 }
60
61 public void setAttachments(Attachment[] attachments)
62 {
63 this.attachments = attachments;
64 }
65
66 public Attachment[] getAttachmentsForPart(String partName)
67 {
68 return attachments;
69 }
70
71 public String getContentAsString()
72 {
73 return payload;
74 }
75
76 public long getContentLength()
77 {
78 return payload.length();
79 }
80
81 public String getContentType()
82 {
83 if (messageReceive != null)
84 try
85 {
86 return messageReceive.getJMSType();
87 }
88 catch (JMSException e)
89 {
90 SoapUI.logError(e);
91 }
92 return null;
93 }
94
95 public String getProperty(String name)
96 {
97 if (messageReceive != null)
98 try
99 {
100 return messageReceive.getStringProperty(name);
101 }
102 catch (JMSException e)
103 {
104 SoapUI.logError(e);
105 }
106 return null;
107 }
108
109 public String[] getPropertyNames()
110 {
111 List<String> propertyNames = new ArrayList<String>();
112 Enumeration<?> temp;
113 try
114 {
115 if (messageReceive != null)
116 {
117 temp = messageReceive.getPropertyNames();
118 while (temp.hasMoreElements())
119 {
120 propertyNames.add((String) temp.nextElement());
121 }
122 return propertyNames.toArray(new String[propertyNames.size()]);
123 }
124 else
125 {
126 return new String[0];
127 }
128 }
129 catch (JMSException e)
130 {
131 SoapUI.logError(e);
132 }
133 return null;
134 }
135
136 public byte[] getRawRequestData()
137 {
138 if (messageSend != null)
139 return messageSend.toString().getBytes();
140 else
141 return "".getBytes();
142 }
143
144 public byte[] getRawResponseData()
145 {
146 if (messageReceive != null)
147 return messageReceive.toString().getBytes();
148 else
149 return "".getBytes();
150 }
151
152 public String getRequestContent()
153 {
154 if (messageSend != null)
155 {
156 try
157 {
158 if (messageSend instanceof TextMessage)
159 {
160 return ((TextMessage) messageSend).getText();
161 }
162 }
163 catch (JMSException e)
164 {
165 SoapUI.logError(e);
166 }
167 return messageSend.toString();
168 }
169 return "";
170 }
171
172 public StringToStringMap getRequestHeaders()
173 {
174 if (messageSend != null)
175 {
176 return JMSHeader.getMessageHeadersAndProperties(messageSend);
177 }
178 else
179 return new StringToStringMap();
180
181 }
182
183 public StringToStringMap getResponseHeaders()
184 {
185 if (messageReceive != null)
186 {
187 return JMSHeader.getMessageHeadersAndProperties(messageReceive);
188 }
189 else
190 return new StringToStringMap();
191 }
192
193 public long getTimeTaken()
194 {
195 return Calendar.getInstance().getTimeInMillis() - requestStartedTime;
196 }
197
198 public long getTimestamp()
199 {
200 try
201 {
202 if (messageReceive != null)
203 return messageReceive.getJMSTimestamp();
204 else
205 return 0;
206 }
207 catch (JMSException e)
208 {
209 SoapUI.logError(e);
210 }
211 return 0;
212 }
213
214 public void setProperty(String name, String value)
215 {
216 try
217 {
218 messageReceive.setStringProperty(name, value);
219 }
220 catch (JMSException e)
221 {
222 SoapUI.logError(e);
223 }
224
225 }
226
227 public String getContentAsXml()
228 {
229 if (payload != null && !"".equals(payload))
230 return payload;
231 else
232 return "<xml/>";
233 }
234
235 public String getHttpVersion()
236 {
237 return null;
238 }
239
240 public RequestMethod getMethod()
241 {
242 return null;
243 }
244
245 public SSLInfo getSSLInfo()
246 {
247 return null;
248 }
249
250 public int getStatusCode()
251 {
252 return 0;
253 }
254
255 public URL getURL()
256 {
257 return null;
258 }
259
260 public void setResponseContent(String responseContent)
261 {
262 this.payload = responseContent;
263 }
264
265 public Vector<?> getWssResult()
266 {
267 return null;
268 }
269
270 public WsdlRequest getRequest()
271 {
272 return (WsdlRequest) request;
273 }
274
275 public Message getMessageReceive()
276 {
277 return messageReceive;
278 }
279
280 public Message getMessageSend()
281 {
282 return messageSend;
283 }
284
285 public String getEndpoint(){
286 return endpoint;
287 }
288
289 }