View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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.methods;
14  
15  import java.io.IOException;
16  
17  import org.apache.commons.httpclient.HttpConnection;
18  import org.apache.commons.httpclient.HttpException;
19  import org.apache.commons.httpclient.HttpState;
20  import org.apache.commons.httpclient.methods.PostMethod;
21  
22  import com.eviware.soapui.impl.rest.RestRequestInterface;
23  import com.eviware.soapui.impl.wsdl.submit.transports.http.ExtendedHttpMethod;
24  import com.eviware.soapui.impl.wsdl.submit.transports.http.HttpMethodSupport;
25  import com.eviware.soapui.impl.wsdl.submit.transports.http.SSLInfo;
26  
27  /***
28   * Extended PostMethod that supports limiting of response size and detailed
29   * timestamps
30   * 
31   * @author Ole.Matzura
32   */
33  
34  public final class ExtendedPostMethod extends PostMethod implements ExtendedHttpMethod
35  {
36  	private HttpMethodSupport httpMethodSupport;
37  	private IAfterRequestInjection afterRequestInjection;
38  
39  	public ExtendedPostMethod()
40  	{
41  		httpMethodSupport = new HttpMethodSupport( this );
42  	}
43  
44  	public String getDumpFile()
45  	{
46  		return httpMethodSupport.getDumpFile();
47  	}
48  
49  	public void setDumpFile( String dumpFile )
50  	{
51  		httpMethodSupport.setDumpFile( dumpFile );
52  	}
53  
54  	public boolean hasResponse()
55  	{
56  		return httpMethodSupport.hasResponse();
57  	}
58  
59  	protected void readResponse( HttpState arg0, HttpConnection arg1 ) throws IOException, HttpException
60  	{
61  		super.readResponse( arg0, arg1 );
62  		httpMethodSupport.afterReadResponse( arg0, arg1 );
63  	}
64  
65  	@Override
66  	public String getResponseCharSet()
67  	{
68  		return httpMethodSupport.getResponseCharset();
69  	}
70  
71  	public long getMaxSize()
72  	{
73  		return httpMethodSupport.getMaxSize();
74  	}
75  
76  	public void setMaxSize( long maxSize )
77  	{
78  		httpMethodSupport.setMaxSize( maxSize );
79  	}
80  
81  	public long getResponseReadTime()
82  	{
83  		return httpMethodSupport.getResponseReadTime();
84  	}
85  
86  	protected void writeRequest( HttpState arg0, HttpConnection arg1 ) throws IOException, HttpException
87  	{
88  		super.writeRequest( arg0, arg1 );
89  		httpMethodSupport.afterWriteRequest( arg0, arg1 );
90  		if( afterRequestInjection != null )
91  			afterRequestInjection.executeAfterRequest();
92  	}
93  
94  	public void initStartTime()
95  	{
96  		httpMethodSupport.initStartTime();
97  	}
98  
99  	public long getTimeTaken()
100 	{
101 		return httpMethodSupport.getTimeTaken();
102 	}
103 
104 	public long getStartTime()
105 	{
106 		return httpMethodSupport.getStartTime();
107 	}
108 
109 	public byte[] getResponseBody() throws IOException
110 	{
111 		return httpMethodSupport.getResponseBody();
112 	}
113 
114 	public SSLInfo getSSLInfo()
115 	{
116 		return httpMethodSupport.getSSLInfo();
117 	}
118 
119 	public String getResponseContentType()
120 	{
121 		return httpMethodSupport.getResponseContentType();
122 	}
123 
124 	public RestRequestInterface.RequestMethod getMethod()
125 	{
126 		return RestRequestInterface.RequestMethod.POST;
127 	}
128 
129 	public void setAfterRequestInjection( IAfterRequestInjection injection )
130 	{
131 		afterRequestInjection = injection;
132 	}
133 	
134 	public Throwable getFailureCause()
135 	{
136 		return httpMethodSupport.getFailureCause();
137 	}
138 
139 	public boolean isFailed()
140 	{
141 		return httpMethodSupport.isFailed();
142 	}
143 
144 	public void setFailed( Throwable t )
145 	{
146 		httpMethodSupport.setFailed( t );
147 	}
148 }