01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * 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: private final MimeMultipart multipart;
34:
35: public MultipartAttachmentDataSource(MimeMultipart multipart) {
36: this .multipart = multipart;
37: }
38:
39: public String getContentType() {
40: return multipart.getContentType();
41: }
42:
43: public InputStream getInputStream() throws IOException {
44: try {
45: ByteArrayOutputStream out = new ByteArrayOutputStream();
46: multipart.writeTo(out);
47: return new ByteArrayInputStream(out.toByteArray());
48: } catch (Exception e) {
49: SoapUI.logError(e);
50: return null;
51: }
52: }
53:
54: public String getName() {
55: return multipart.toString();
56: }
57:
58: public OutputStream getOutputStream() throws IOException {
59: return null;
60: }
61: }
|