View Javadoc

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  package com.eviware.soapui.impl.wsdl.submit.transports.http.support.methods;
14  
15  import com.eviware.soapui.impl.support.AbstractHttpRequest;
16  import com.eviware.soapui.impl.wsdl.submit.transports.http.ExtendedHttpMethod;
17  import com.eviware.soapui.impl.wsdl.submit.transports.http.HttpMethodSupport;
18  import com.eviware.soapui.impl.wsdl.submit.transports.http.SSLInfo;
19  import org.apache.commons.httpclient.Header;
20  import org.apache.commons.httpclient.HttpConnection;
21  import org.apache.commons.httpclient.HttpException;
22  import org.apache.commons.httpclient.HttpState;
23  import org.apache.commons.httpclient.methods.PostMethod;
24  
25  import java.io.IOException;
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  
38     public ExtendedPostMethod()
39     {
40        httpMethodSupport = new HttpMethodSupport( this );
41     }
42  
43     public String getDumpFile()
44     {
45        return httpMethodSupport.getDumpFile();
46     }
47  
48     public void setDumpFile( String dumpFile )
49     {
50        httpMethodSupport.setDumpFile( dumpFile );
51     }
52  
53     protected void readResponse( HttpState arg0, HttpConnection arg1 )
54             throws IOException, HttpException
55     {
56        super.readResponse( arg0, arg1 );
57        httpMethodSupport.afterReadResponse( arg0, arg1 );
58     }
59  
60     @Override
61     public String getResponseCharSet()
62     {
63        Header contentEncodingHeader = getResponseHeader( "Content-Encoding" );
64        if( contentEncodingHeader != null )
65           return contentEncodingHeader.getValue();
66  
67        return super.getResponseCharSet();
68     }
69  
70     public long getMaxSize()
71     {
72        return httpMethodSupport.getMaxSize();
73     }
74  
75     public void setMaxSize( long maxSize )
76     {
77        httpMethodSupport.setMaxSize( maxSize );
78     }
79  
80     public long getResponseReadTime()
81     {
82        return httpMethodSupport.getResponseReadTime();
83     }
84  
85     protected void writeRequest( HttpState arg0, HttpConnection arg1 )
86             throws IOException, HttpException
87     {
88        super.writeRequest( arg0, arg1 );
89        httpMethodSupport.afterWriteRequest( arg0, arg1 );
90     }
91  
92     public void initStartTime()
93     {
94        httpMethodSupport.initStartTime();
95     }
96  
97     public long getTimeTaken()
98     {
99        return httpMethodSupport.getTimeTaken();
100    }
101 
102    public long getStartTime()
103    {
104       return httpMethodSupport.getStartTime();
105    }
106 
107    public byte[] getResponseBody() throws IOException
108    {
109       return httpMethodSupport.getResponseBody();
110    }
111 
112    public SSLInfo getSSLInfo()
113    {
114       return httpMethodSupport.getSSLInfo();
115    }
116 
117    public String getResponseContentType()
118    {
119       return httpMethodSupport.getResponseContentType();
120    }
121 
122    public AbstractHttpRequest.RequestMethod getMethod()
123    {
124       return AbstractHttpRequest.RequestMethod.POST;
125    }
126 
127 }