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.ByteArrayOutputStream;
17  import java.io.IOException;
18  import java.io.InputStream;
19  import java.io.OutputStream;
20  
21  import javax.activation.DataSource;
22  import javax.mail.internet.MimeMultipart;
23  
24  import com.eviware.soapui.SoapUI;
25  
26  /***
27   * DataSource for multipart attachments
28   * 
29   * @author ole.matzura
30   */
31  
32  class MultipartAttachmentDataSource implements DataSource
33  {
34  	private final MimeMultipart multipart;
35  
36  	public MultipartAttachmentDataSource(MimeMultipart multipart)
37  	{
38  		this.multipart = multipart;
39  	}
40  
41  	public String getContentType()
42  	{
43  		return multipart.getContentType();
44  	}
45  
46  	public InputStream getInputStream() throws IOException
47  	{
48  		try
49  		{
50  			ByteArrayOutputStream out = new ByteArrayOutputStream();
51  			multipart.writeTo(out);
52  			return new ByteArrayInputStream( out.toByteArray() );
53  		}
54  		catch (Exception e)
55  		{
56  			SoapUI.logError( e );
57  			return null;
58  		}		
59  	}
60  
61  	public String getName()
62  	{
63  		return multipart.toString();
64  	}
65  
66  	public OutputStream getOutputStream() throws IOException
67  	{
68  		return null;
69  	}}