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