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 /*
14 * soapUI, copyright (C) 2004-2008 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 com.eviware.soapui.impl.rest.RestRequest;
28
29 import javax.activation.DataSource;
30 import java.io.ByteArrayInputStream;
31 import java.io.IOException;
32 import java.io.InputStream;
33 import java.io.OutputStream;
34
35 /***
36 * DataSource for an existing WsdlRequest
37 *
38 * @author ole.matzura
39 */
40
41 public class RestRequestDataSource implements DataSource
42 {
43 private final RestRequest restRequest;
44 private final String requestContent;
45
46 public RestRequestDataSource(RestRequest restRequest, String requestContent)
47 {
48 this.restRequest = restRequest;
49 this.requestContent = requestContent;
50 }
51
52 public String getContentType()
53 {
54 return restRequest.getMediaType();
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 restRequest.getName();
66 }
67
68 public OutputStream getOutputStream() throws IOException
69 {
70 return null;
71 }
72 }