1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.submit.transports.http.support.attachments;
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.impl.wsdl.submit.transports.http.BaseHttpResponse;
19 import com.eviware.soapui.impl.wsdl.submit.transports.http.ExtendedHttpMethod;
20 import com.eviware.soapui.model.iface.Attachment;
21 import com.eviware.soapui.model.propertyexpansion.PropertyExpansionContext;
22 import com.eviware.soapui.settings.HttpSettings;
23 import org.apache.commons.httpclient.Header;
24 import org.apache.commons.httpclient.HeaderElement;
25 import org.apache.commons.httpclient.NameValuePair;
26
27 /***
28 * WsdlMockResponse for a MimeResponse
29 *
30 * @author ole.matzura
31 */
32
33 public class MimeMessageResponse extends BaseHttpResponse
34 {
35 private long timeTaken;
36 private long responseContentLength;
37 private final String requestContent;
38 private MultipartMessageSupport mmSupport;
39 private PostResponseDataSource postResponseDataSource;
40
41 public MimeMessageResponse(AbstractHttpRequest<?> httpRequest, ExtendedHttpMethod httpMethod, String requestContent, PropertyExpansionContext context)
42 {
43 super( httpMethod, httpRequest );
44
45 this.requestContent = requestContent;
46
47 try
48 {
49 postResponseDataSource = new PostResponseDataSource( httpMethod );
50 responseContentLength = postResponseDataSource.getDataSize();
51
52 Header h = httpMethod.getResponseHeader( "Content-Type" );
53 HeaderElement[] elements = h.getElements();
54
55 String rootPartId = null;
56
57 for( HeaderElement element : elements )
58 {
59 String name = element.getName().toUpperCase();
60 if( name.startsWith( "MULTIPART/" ))
61 {
62 NameValuePair parameter = element.getParameterByName("start");
63 if (parameter != null)
64 rootPartId = parameter.getValue();
65 }
66 }
67
68 mmSupport = new MultipartMessageSupport( postResponseDataSource, rootPartId, httpRequest.getOperation(), false,
69 httpRequest.isPrettyPrint());
70
71 if (httpRequest.getSettings().getBoolean(HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN))
72 this.timeTaken += httpMethod.getResponseReadTime();
73 }
74 catch ( Exception e)
75 {
76 SoapUI.logError( e );
77 }
78 }
79
80 protected MultipartMessageSupport getMmSupport()
81 {
82 return mmSupport;
83 }
84
85 public long getContentLength()
86 {
87 return responseContentLength;
88 }
89
90 public String getRequestContent()
91 {
92 return requestContent;
93 }
94
95 public void setResponseContent( String responseContent )
96 {
97 String oldContent = getContentAsString();
98 mmSupport.setResponseContent( responseContent );
99
100 getRequest().notifyPropertyChanged( WsdlRequest.RESPONSE_CONTENT_PROPERTY, oldContent, responseContent );
101 }
102
103 public Attachment[] getAttachments()
104 {
105 return mmSupport.getAttachments();
106 }
107
108 public Attachment[] getAttachmentsForPart( String partName )
109 {
110 return mmSupport.getAttachmentsForPart( partName );
111 }
112
113 public String getContentAsString()
114 {
115 return mmSupport.getContentAsString();
116 }
117
118
119
120
121
122
123
124
125
126
127 }