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 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.support.http.HttpClientSupport;
24 import com.eviware.soapui.support.Tools;
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 TimeablePostMethod postMethod;
35 private byte[] data;
36
37 public PostResponseDataSource(TimeablePostMethod postMethod)
38 {
39 this.postMethod = postMethod;
40
41 try
42 {
43 data = Tools.readAll( postMethod.getResponseBodyAsStream(), 0 ).toByteArray();
44
45 if( HttpClientSupport.isZippedResponse( postMethod ))
46 {
47 data = HttpClientSupport.decompress( data );
48 }
49 }
50 catch (Exception e)
51 {
52 SoapUI.logError( e );
53 }
54 }
55
56 public long getDataSize()
57 {
58 return data == null ? -1 : data.length;
59 }
60
61 public String getContentType()
62 {
63 return postMethod.getResponseHeader( "Content-Type" ).getValue();
64 }
65
66 public InputStream getInputStream() throws IOException
67 {
68 return new ByteArrayInputStream( data );
69 }
70
71 public String getName()
72 {
73 return postMethod.getName() + " response for " + postMethod.getPath().toString();
74 }
75
76 public OutputStream getOutputStream() throws IOException
77 {
78 return null;
79 }
80
81 public byte[] getData()
82 {
83 return data;
84 }
85 }