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.impl.wsdl.mock.WsdlMockResponse;
16 import com.eviware.soapui.impl.wsdl.support.soap.SoapVersion;
17
18 import javax.activation.DataSource;
19 import java.io.ByteArrayInputStream;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.io.OutputStream;
23
24 /***
25 * DataSource for an existing WsdlMockResponse
26 *
27 * @author ole.matzura
28 */
29
30 public class MockResponseDataSource implements DataSource
31 {
32 private final String responseContent;
33 private final boolean isXOP;
34 private final WsdlMockResponse mockResponse;
35
36 public MockResponseDataSource(WsdlMockResponse mockResponse, String responseContent, boolean isXOP)
37 {
38 this.mockResponse = mockResponse;
39 this.responseContent = responseContent;
40 this.isXOP = isXOP;
41 }
42
43 public String getContentType()
44 {
45 SoapVersion soapVersion = mockResponse.getSoapVersion();
46
47 if( isXOP )
48 {
49 return AttachmentUtils.buildRootPartContentType( mockResponse.getMockOperation().getOperation().getName(),
50 soapVersion);
51 }
52 else
53 return soapVersion.getContentType() + "; charset=UTF-8";
54 }
55
56 public InputStream getInputStream() throws IOException
57 {
58 byte[] bytes = responseContent.getBytes( "UTF-8");
59 return new ByteArrayInputStream( bytes);
60 }
61
62 public String getName()
63 {
64 return mockResponse.getName();
65 }
66
67 public OutputStream getOutputStream() throws IOException
68 {
69 return null;
70 }
71 }