View Javadoc

1   /*
2    * soapUI, copyright (C) 2004-2010 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  /*
14   *  soapUI, copyright (C) 2004-2010 eviware.com 
15   *
16   *  soapUI is free software; you can redistribute it and/or modify it under the 
17   *  terms of version 2.1 of the GNU Lesser General Public License as published by 
18   *  the Free Software Foundation.
19   *
20   *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
21   *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
22   *  See the GNU Lesser General Public License for more details at gnu.org.
23   */
24  
25  package com.eviware.soapui.impl.wsdl.submit.transports.http.support.attachments;
26  
27  import java.io.ByteArrayInputStream;
28  import java.io.IOException;
29  import java.io.InputStream;
30  import java.io.OutputStream;
31  
32  import javax.activation.DataSource;
33  
34  import com.eviware.soapui.impl.support.http.HttpRequestInterface;
35  
36  /***
37   * DataSource for an existing WsdlRequest
38   * 
39   * @author ole.matzura
40   */
41  
42  public class HttpRequestDataSource implements DataSource
43  {
44  	private final HttpRequestInterface<?> restRequest;
45  	private final String requestContent;
46  
47  	public HttpRequestDataSource( HttpRequestInterface<?> restRequest, String requestContent )
48  	{
49  		this.restRequest = restRequest;
50  		this.requestContent = requestContent;
51  	}
52  
53  	public String getContentType()
54  	{
55  		return restRequest.getMediaType();
56  	}
57  
58  	public InputStream getInputStream() throws IOException
59  	{
60  		byte[] bytes = requestContent.getBytes( "UTF-8" );
61  		return new ByteArrayInputStream( bytes );
62  	}
63  
64  	public String getName()
65  	{
66  		return restRequest.getName();
67  	}
68  
69  	public OutputStream getOutputStream() throws IOException
70  	{
71  		return null;
72  	}
73  }