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