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.GetMethod;
24  import org.apache.commons.httpclient.methods.RequestEntity;
25  
26  import java.io.IOException;
27  
28  /***
29   * Extended PostMethod that supports limiting of response size and detailed
30   * timestamps
31   *
32   * @author Ole.Matzura
33   */
34  
35  public final class ExtendedGetMethod extends GetMethod implements ExtendedHttpMethod
36  {
37     private HttpMethodSupport httpMethodSupport;
38  
39     public ExtendedGetMethod()
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     protected void readResponse( HttpState arg0, HttpConnection arg1 )
55             throws IOException, HttpException
56     {
57        super.readResponse( arg0, arg1 );
58        httpMethodSupport.afterReadResponse( arg0, arg1 );
59     }
60  
61     @Override
62     public String getResponseCharSet()
63     {
64        Header contentEncodingHeader = getResponseHeader( "Content-Encoding" );
65        if( contentEncodingHeader != null )
66           return contentEncodingHeader.getValue();
67  
68        return super.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 )
87             throws IOException, HttpException
88     {
89        super.writeRequest( arg0, arg1 );
90        httpMethodSupport.afterWriteRequest( arg0, arg1 );
91     }
92  
93     public void initStartTime()
94     {
95        httpMethodSupport.initStartTime();
96     }
97  
98     public long getTimeTaken()
99     {
100       return httpMethodSupport.getTimeTaken();
101    }
102 
103    public long getStartTime()
104    {
105       return httpMethodSupport.getStartTime();
106    }
107 
108    public byte[] getResponseBody() throws IOException
109    {
110       return httpMethodSupport.getResponseBody();
111    }
112 
113    public SSLInfo getSSLInfo()
114    {
115       return httpMethodSupport.getSSLInfo();
116    }
117 
118    public String getResponseContentType()
119    {
120       return httpMethodSupport.getResponseContentType();
121    }
122 
123    public RequestEntity getRequestEntity()
124    {
125       return null;
126    }
127 
128    public AbstractHttpRequest.RequestMethod getMethod()
129    {
130       return AbstractHttpRequest.RequestMethod.GET;
131    }
132 
133 }