01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: * See the GNU Lesser General Public License for more details at gnu.org.
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:
25: /**
26: * DataSource for an existing WsdlMockResponse
27: *
28: * @author ole.matzura
29: */
30:
31: public class MockResponseDataSource implements DataSource {
32: private final String responseContent;
33: private final boolean isXOP;
34: private final WsdlMockResponse mockResponse;
35:
36: public MockResponseDataSource(WsdlMockResponse mockResponse,
37: String responseContent, boolean isXOP) {
38: this .mockResponse = mockResponse;
39: this .responseContent = responseContent;
40: this .isXOP = isXOP;
41: }
42:
43: public String getContentType() {
44: if (isXOP) {
45: return AttachmentUtils.buildRootPartContentType(
46: mockResponse.getMockOperation().getOperation()
47: .getName(), ((WsdlInterface) mockResponse
48: .getMockOperation().getOperation()
49: .getInterface()).getSoapVersion());
50: } else
51: return "text/xml; charset=UTF-8";
52: }
53:
54: public InputStream getInputStream() throws IOException {
55: byte[] bytes = responseContent.getBytes("UTF-8");
56: return new ByteArrayInputStream(bytes);
57: }
58:
59: public String getName() {
60: return mockResponse.getName();
61: }
62:
63: public OutputStream getOutputStream() throws IOException {
64: return null;
65: }
66: }
|