View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2007 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
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  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  }