View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 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.support.attachments;
14  
15  import com.eviware.soapui.impl.wsdl.WsdlRequest;
16  import com.eviware.soapui.impl.wsdl.support.soap.SoapVersion;
17  
18  import javax.activation.DataSource;
19  import java.io.ByteArrayInputStream;
20  import java.io.IOException;
21  import java.io.InputStream;
22  import java.io.OutputStream;
23  
24  /***
25   * DataSource for an existing WsdlRequest
26   * 
27   * @author ole.matzura
28   */
29  
30  public class WsdlRequestDataSource implements DataSource
31  {
32  	private final WsdlRequest wsdlRequest;
33  	private final String requestContent;
34  	private final boolean isXOP;
35  
36  	public WsdlRequestDataSource(WsdlRequest wsdlRequest, String requestContent, boolean isXOP)
37  	{
38  		this.wsdlRequest = wsdlRequest;
39  		this.requestContent = requestContent;
40  		this.isXOP = isXOP;
41  	}
42  
43  	public String getContentType()
44  	{
45  		SoapVersion soapVersion = wsdlRequest.getOperation().getInterface().getSoapVersion();
46  		
47  		if( isXOP )
48  		{
49  			return AttachmentUtils.buildRootPartContentType( wsdlRequest.getOperation().getName(),	soapVersion);	
50  		}
51  		else
52        {
53           return soapVersion.getContentType() + "; charset=UTF-8";
54        }
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  }