View Javadoc

1   /*
2    *  soapUI, copyright (C) 2006 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  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  public class MockResponseDataSource implements DataSource
26  {
27  	private final String responseContent;
28  	private final boolean isXOP;
29  	private final WsdlMockResponse mockResponse;
30  
31  	public MockResponseDataSource(WsdlMockResponse mockResponse, String responseContent, boolean isXOP)
32  	{
33  		this.mockResponse = mockResponse;
34  		this.responseContent = responseContent;
35  		this.isXOP = isXOP;
36  	}
37  
38  	public String getContentType()
39  	{
40  		if( isXOP )
41  		{
42  		   return AttachmentUtils.buildRootPartContentType( mockResponse.getMockOperation().getOperation().getName(),
43  		   			((WsdlInterface)mockResponse.getMockOperation().getOperation().getInterface()).getSoapVersion());	
44  		}
45  		else
46  			return "text/xml; charset=UTF-8";
47  	}
48  
49  	public InputStream getInputStream() throws IOException
50  	{
51  		byte[] bytes = responseContent.getBytes( "UTF-8");
52  		return new ByteArrayInputStream( bytes);
53  	}
54  
55  	public String getName()
56  	{
57  		return mockResponse.getName();
58  	}
59  
60  	public OutputStream getOutputStream() throws IOException
61  	{
62  		return null;
63  	}
64  }