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 import javax.servlet.http.HttpServletRequest;
22
23 import com.eviware.soapui.SoapUI;
24 import com.eviware.soapui.support.Tools;
25
26 /***
27 * DataSource for a MockRequest
28 *
29 * @author ole.matzura
30 */
31
32 public class MockRequestDataSource implements DataSource
33 {
34 private byte[] data;
35 private String contentType;
36 private String name;
37
38 public MockRequestDataSource( HttpServletRequest request )
39 {
40 try
41 {
42 data = Tools.readAll( request.getInputStream(), 0 ).toByteArray();
43 contentType = request.getContentType();
44 name = "Request for " + request.getPathInfo();
45 }
46 catch( Exception e )
47 {
48 SoapUI.logError( e );
49 }
50 }
51
52 public String getContentType()
53 {
54 return contentType;
55 }
56
57 public InputStream getInputStream() throws IOException
58 {
59 return new ByteArrayInputStream( data );
60 }
61
62 public String getName()
63 {
64 return name;
65 }
66
67 public OutputStream getOutputStream() throws IOException
68 {
69 return null;
70 }
71
72 public byte[] getData()
73 {
74 return data;
75 }
76 }