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.support.Tools;
23
24 public class PostResponseDataSource implements DataSource
25 {
26 private final TimeablePostMethod postMethod;
27 private byte[] data;
28
29 public PostResponseDataSource(TimeablePostMethod postMethod)
30 {
31 this.postMethod = postMethod;
32
33 try
34 {
35 data = Tools.readAll( postMethod.getResponseBodyAsStream(), 0 ).toByteArray();
36 }
37 catch (Exception e)
38 {
39 e.printStackTrace();
40 }
41 }
42
43 public long getDataSize()
44 {
45 return data == null ? -1 : data.length;
46 }
47
48 public String getContentType()
49 {
50 return postMethod.getResponseHeader( "Content-Type" ).getValue();
51 }
52
53 public InputStream getInputStream() throws IOException
54 {
55 return new ByteArrayInputStream( data );
56 }
57
58 public String getName()
59 {
60 return postMethod.getName() + " response for " + postMethod.getPath().toString();
61 }
62
63 public OutputStream getOutputStream() throws IOException
64 {
65 return null;
66 }
67
68 }