1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.submit.transports.http;
14
15 import com.eviware.soapui.SoapUI;
16 import com.eviware.soapui.impl.support.AbstractHttpRequest;
17 import com.eviware.soapui.impl.wsdl.WsdlRequest;
18 import com.eviware.soapui.model.propertyexpansion.PropertyExpansionContext;
19 import com.eviware.soapui.settings.WsdlSettings;
20 import com.eviware.soapui.support.StringUtils;
21 import com.eviware.soapui.support.xml.XmlUtils;
22
23 /***
24 * Simple response to a request
25 *
26 * @author ole.matzura
27 */
28
29 public class SinglePartHttpResponse extends BaseHttpResponse
30 {
31 private String responseContent;
32 private final String requestContent;
33 private boolean prettyPrint;
34 private long responseSize;
35
36
37
38 public SinglePartHttpResponse(AbstractHttpRequest<?> httpRequest, ExtendedHttpMethod httpMethod, String requestContent, PropertyExpansionContext context )
39 {
40 super( httpMethod, httpRequest );
41 this.requestContent = requestContent;
42
43 try
44 {
45 byte[] responseBody = httpMethod.getResponseBody();
46 int contentOffset = 0;
47 if( responseBody == null )
48 responseBody = new byte[0];
49
50 responseSize = responseBody.length;
51
52 String contentType = httpMethod.getResponseContentType();
53 String charset = httpMethod.getResponseCharSet();
54
55 if( contentType != null && contentType.toLowerCase().endsWith("xml"))
56 {
57 if( responseSize > 3 && responseBody[0] == (byte)239 && responseBody[1] == (byte)187 && responseBody[2] == (byte)191 )
58 {
59 charset = "UTF-8";
60 contentOffset = 3;
61 }
62 }
63
64 if( charset == null )
65 charset = httpRequest.getEncoding();
66
67 charset = StringUtils.unquote( charset );
68
69 responseContent = responseBody.length == 0 ? null : charset == null ? new String(responseBody) :
70 new String( responseBody, contentOffset, (int)(responseSize-contentOffset), charset );
71
72 prettyPrint = httpRequest.getSettings().getBoolean( WsdlSettings.PRETTY_PRINT_RESPONSE_MESSAGES );
73
74
75
76
77
78
79
80
81
82
83
84
85 }
86 catch( Exception e )
87 {
88 SoapUI.logError( e );
89 }
90 }
91
92 public String getContentAsString()
93 {
94 if( prettyPrint )
95 {
96 responseContent = XmlUtils.prettyPrintXml( responseContent );
97 prettyPrint = false;
98 }
99
100 return responseContent;
101 }
102
103 public long getContentLength()
104 {
105 return responseSize;
106 }
107
108 public String getRequestContent()
109 {
110 return requestContent;
111 }
112
113 public void setResponseContent(String responseContent)
114 {
115 String oldContent = this.responseContent;
116 this.responseContent = responseContent;
117
118 getRequest().notifyPropertyChanged( WsdlRequest.RESPONSE_CONTENT_PROPERTY, oldContent, responseContent );
119 }
120
121
122
123
124
125
126
127
128
129
130
131
132 }