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 java.io.ByteArrayInputStream;
16 import java.io.IOException;
17 import java.io.InputStream;
18 import java.io.OutputStream;
19
20 import javax.activation.DataSource;
21
22 import com.eviware.soapui.SoapUI;
23 import com.eviware.soapui.impl.wsdl.submit.transports.http.ExtendedHttpMethod;
24 import com.eviware.soapui.impl.wsdl.support.CompressionSupport;
25 import com.eviware.soapui.impl.wsdl.support.http.HttpClientSupport;
26 import com.eviware.soapui.settings.HttpSettings;
27
28 /***
29 * DataSource for a standard POST response
30 *
31 * @author ole.matzura
32 */
33
34 public class PostResponseDataSource implements DataSource
35 {
36 private final ExtendedHttpMethod postMethod;
37 private byte[] data;
38
39 public PostResponseDataSource( ExtendedHttpMethod postMethod )
40 {
41 this.postMethod = postMethod;
42
43 try
44 {
45 data = postMethod.getResponseBody();
46
47
48
49 if( !SoapUI.getSettings().getBoolean( HttpSettings.DISABLE_RESPONSE_DECOMPRESSION ) )
50 {
51 String compressionAlg = HttpClientSupport.getResponseCompressionType( postMethod );
52 if( compressionAlg != null )
53 data = CompressionSupport.decompress( compressionAlg, data );
54 }
55 }
56 catch( Exception e )
57 {
58 SoapUI.logError( e );
59 }
60 }
61
62 public long getDataSize()
63 {
64 return data == null ? -1 : data.length;
65 }
66
67 public String getContentType()
68 {
69 return postMethod.getResponseHeader( "Content-Type" ).getValue();
70 }
71
72 public InputStream getInputStream() throws IOException
73 {
74 return new ByteArrayInputStream( data );
75 }
76
77 public String getName()
78 {
79 return postMethod.getName() + " response for " + postMethod.getPath().toString();
80 }
81
82 public OutputStream getOutputStream() throws IOException
83 {
84 return null;
85 }
86
87 public byte[] getData()
88 {
89 return data;
90 }
91 }