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