1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.submit.transports.http.support.attachments;
14
15 import java.io.ByteArrayInputStream;
16 import java.io.IOException;
17 import java.io.InputStream;
18 import java.io.OutputStream;
19
20 import javax.activation.DataSource;
21
22 import com.eviware.soapui.impl.wsdl.WsdlRequest;
23 import com.eviware.soapui.impl.wsdl.support.soap.SoapVersion;
24
25 /***
26 * DataSource for an existing WsdlRequest
27 *
28 * @author ole.matzura
29 */
30
31 public class WsdlRequestDataSource implements DataSource
32 {
33 private final WsdlRequest wsdlRequest;
34 private final String requestContent;
35 private final boolean isXOP;
36
37 public WsdlRequestDataSource( WsdlRequest wsdlRequest, String requestContent, boolean isXOP )
38 {
39 this.wsdlRequest = wsdlRequest;
40 this.requestContent = requestContent;
41 this.isXOP = isXOP;
42 }
43
44 public String getContentType()
45 {
46 SoapVersion soapVersion = wsdlRequest.getOperation().getInterface().getSoapVersion();
47
48 if( isXOP )
49 {
50 return AttachmentUtils.buildRootPartContentType( wsdlRequest.getOperation().getName(), soapVersion );
51 }
52 else
53 {
54 return soapVersion.getContentType() + "; charset=UTF-8";
55 }
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 wsdlRequest.getName();
67 }
68
69 public OutputStream getOutputStream() throws IOException
70 {
71 return null;
72 }
73 }