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