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