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.SoapUI;
16  
17  import javax.activation.DataSource;
18  import javax.mail.BodyPart;
19  import javax.mail.MessagingException;
20  import java.io.IOException;
21  import java.io.InputStream;
22  import java.io.OutputStream;
23  
24  /***
25   * DataSource for a BodyPart
26   * 
27   * @author ole.matzura
28   */
29  
30  public class BodyPartDataSource implements DataSource
31  {
32  	private final BodyPart bodyPart;
33  
34  	public BodyPartDataSource(BodyPart bodyPart)
35  	{
36  		this.bodyPart = bodyPart;
37  	}
38  
39  	public String getContentType()
40  	{
41  		try
42  		{
43  			return bodyPart.getContentType();
44  		}
45  		catch (MessagingException e)
46  		{
47  			SoapUI.logError( e );
48  			return null;
49  		}
50  	}
51  
52  	public InputStream getInputStream() throws IOException
53  	{
54  		try
55  		{
56  			return bodyPart.getInputStream();
57  		}
58  		catch (MessagingException e)
59  		{
60  			SoapUI.logError( e );
61  			return null;
62  		}
63  	}
64  
65  	public String getName()
66  	{
67  		try
68  		{
69  			return bodyPart.getHeader( "Content-ID" )[0];
70  		}
71  		catch (MessagingException e)
72  		{
73  			SoapUI.logError( e );
74  			return null;
75  		}
76  	}
77  
78  	public OutputStream getOutputStream() throws IOException
79  	{
80  		return null;
81  	}
82  
83  }