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