View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 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 java.io.IOException;
16  import java.io.InputStream;
17  import java.io.OutputStream;
18  
19  import javax.activation.DataSource;
20  import javax.servlet.http.HttpServletRequest;
21  
22  import com.eviware.soapui.SoapUI;
23  import com.eviware.soapui.impl.wsdl.monitor.CaptureInputStream;
24  import com.eviware.soapui.settings.UISettings;
25  
26  /***
27   * DataSource for a MockRequest
28   * 
29   * @author ole.matzura
30   */
31  
32  public class MockRequestDataSource implements DataSource
33  {
34  	private String contentType;
35  	private String name;
36  	private final HttpServletRequest request;
37  	private CaptureInputStream capture = null;
38  
39  	public MockRequestDataSource( HttpServletRequest request )
40  	{
41  		this.request = request;
42  		try
43  		{
44  			contentType = request.getContentType();
45  			name = "Request for " + request.getPathInfo();
46  			capture = new CaptureInputStream( request.getInputStream(), SoapUI.getSettings().getLong(
47  					UISettings.RAW_REQUEST_MESSAGE_SIZE, 0 ) );
48  		}
49  		catch( Exception e )
50  		{
51  			SoapUI.logError( e );
52  		}
53  	}
54  
55  	public String getContentType()
56  	{
57  		return contentType;
58  	}
59  
60  	public InputStream getInputStream() throws IOException
61  	{
62  		return request.getInputStream();
63  	}
64  
65  	public String getName()
66  	{
67  		return name;
68  	}
69  
70  	public OutputStream getOutputStream() throws IOException
71  	{
72  		return null;
73  	}
74  
75  	public byte[] getData()
76  	{
77  		return capture.getCapturedData();
78  	}
79  }