Project Report: fawkez

Packagesummary org.jcoderz.commons.connector.http.transport

org.jcoderz.commons.connector.http.transport.HttpClientConnectionImpl

LineHitsNoteSource
1  /*
2   * $Id: HttpClientConnectionImpl.java 1011 2008-06-16 17:57:36Z amandel $
3   *
4   * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5   *
6   * Redistribution and use in source and binary forms, with or without
7   * modification, are permitted provided that the following conditions are
8   * met:
9   *
10   *    * Redistributions of source code must retain the above copyright
11   *      notice, this list of conditions and the following disclaimer.
12   *    * Redistributions in binary form must reproduce the above
13   *      copyright notice, this list of conditions and the following
14   *      disclaimer in the documentation and/or other materials
15   *      provided with the distribution.
16   *    * Neither the name of the jCoderZ.org Project nor the names of
17   *      its contributors may be used to endorse or promote products
18   *      derived from this software without specific prior written
19   *      permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   */
33  package org.jcoderz.commons.connector.http.transport;
34  
35  import java.io.IOException;
36  import java.io.InputStream;
37  import java.net.ConnectException;
38  import java.security.KeyStore;
39  import java.util.HashMap;
40  import java.util.Iterator;
41  import java.util.Map;
42  import java.util.logging.Level;
43  import java.util.logging.Logger;
44  
45  import org.apache.commons.httpclient.Header;
46  import org.apache.commons.httpclient.HostConfiguration;
47  import org.apache.commons.httpclient.HttpClient;
48  import org.apache.commons.httpclient.HttpConnection;
49  import org.apache.commons.httpclient.HttpConnectionManager;
50  import org.apache.commons.httpclient.HttpException;
51  import org.apache.commons.httpclient.SimpleHttpConnectionManager;
52  import org.apache.commons.httpclient.URI;
53  import org.apache.commons.httpclient.URIException;
54  import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
55  import org.apache.commons.httpclient.methods.PostMethod;
56  import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
57  import org.apache.commons.httpclient.protocol.Protocol;
58  import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
59  import org.jcoderz.commons.ArgumentMalformedException;
60  import org.jcoderz.commons.util.Assert;
61  import org.jcoderz.commons.util.Constants;
62  import org.jcoderz.commons.util.HexUtil;
63  import org.jcoderz.commons.util.StringUtil;
64  
65  
66  
67  /**
68   * This class implements the HttpConnectionInterface using the Jakarta
69   * commons-httpclient library.
70   *
71   */
72100(1)public class HttpClientConnectionImpl
73        implements HttpClientConnection
74  {
75     /** The class name used for logging */
7675    private static final String CLASSNAME
77           = HttpClientConnectionImpl.class.getName();
78     /** The logger in use */
79100    private static final Logger logger
80           = Logger.getLogger(CLASSNAME);
81     /** The default port used for SSL connections */
82     private static final int DEFAULT_SSL_PORT = 443;
83     /** Constant for line feed. */
84     private static final String LINE_FEED = "\n";
85     /** Constant for the HTTP result code 200 */
86     private static final int HTTP_RESULT_OK = 200;
87     /** Contant for the HTTP result code 300 */
88     private static final int HTTP_REDIRECT = 300;
89     /** Constant for the HTTP result code 400 */
90     private static final int HTTP_BAD_REQUEST = 400;
91     /** Constant for the HTTP result code 500 */
92     private static final int HTTP_INTERNAL_SERVER_ERROR = 500;
93     /** The HttpClient defined in the 3rd party library. */
94     private HttpClient mHttpClient;
95     /** The HostConfiguration defined in the 3rd party library. */
96     private HostConfiguration mHostConfiguration;
97     /** The PostMethod defined in the 3rd party library. */
98     private PostMethod mPostMethod;
99     /** The state identifying the current step of the HTTP send/receive
100        process. */
101     /** Input stream for the request message used for the httpclient */
102100    private InputStream mRequestBodyInputStream = null;
103     /** Content length of the request message */
104100    private int mRequestContentLength = 0;
105     /** Flag indicating if the content length has been set via interface method.
106         If false the content length will be calculated by the httpclient. */
107100    private boolean mIsRequestContentLengthSet = false;
108     /** Content type of the request message */
109100    private String mRequestContentType = null;
110     /** Current state of the httpclient. Used to check the correct usage of the
111         interface methods defined within HttpClientConnection interface. */
112100    private HttpConnectionState mState
113           = HttpConnectionState.CONNECTION_NOT_ESTABLISHED;
114     /** Keystore filename used for SSL connections. Used to load the keystore
115         from the filesystem if not given within interface method. */
116100    private String mKeyStoreFilename = null;
117     /** Keystore password used for SSL connection. */
118100    private String mKeyStorePassword = null;
119     /** Truststore filename used for SSL connections. Used to load the truststore
120         from the filesystem if not given within interface method. */
121100    private String mTrustStoreFilename = null;
122     /** Truststore password used for SSL connection. */
123100    private String mTrustStorePassword = null;
124     /** Keystore used for SSL connections obtained via interface method. */
125100    private KeyStore mKeyStore = null;
126100    private KeyStore mTrustStore = null;
127     /** Key alias of the sending system used for SSL connections. */
128100    private String mKeyAlias = null;
129     /** Key password of the used key. */
130100    private String mKeyAliasPassword = null;
131     /** Path used to load the keystore from file system if not given within
132         interface method calls. */
133100    private String mPath = null;
134  
135100    private HttpConnectorEventListener mHttpEventListener = null;
136100    private ConnectorContext mConnectorContext = null;
137100    private HttpRequestResponseHeader mRequestResponseHeader = null;
138  
139     /** {@inheritDoc} */
140     public void establishConnection (
141        String uriAsString,
142        int connectTimeout,
143        int readTimeout)
144     {
145100       Assert.notNull(uriAsString, "uriAsString");
146100       mHostConfiguration = new HostConfiguration();
147100       mPostMethod = new PostMethod();
148  
149        URI uri;
150        try
151        {
152100          uri = new URI(uriAsString, false);
153100          mPath = uri.getPathQuery();
154100          mPostMethod.setPath(mPath);
155  
156100          final String scheme = uri.getScheme();
157100(2)         if (scheme != null && scheme.toLowerCase(Constants.SYSTEM_LOCALE).
158                 equals("https"))
159           {
1600             SslSocketFactory sslFactory = null;
1610             if (mKeyStore != null && mTrustStore != null)
162              {
163                 // using the keystore given from signature service
1640                sslFactory = new SslSocketFactory(
165                       mKeyStore, mTrustStore, mKeyAlias, mKeyAliasPassword);
166              }
167              else
168              {
169                 // using a keystore loading from file system
1700                sslFactory = new SslSocketFactory(
171                       mKeyStoreFilename, mKeyStorePassword,
172                       mTrustStoreFilename, mTrustStorePassword,
173                       mKeyAlias, mKeyAliasPassword);
174              }
1750             final Protocol https
176                    = new Protocol(
177                          "https",
178                          (ProtocolSocketFactory) sslFactory,
179                          DEFAULT_SSL_PORT);
1800             int port = uri.getPort();
1810             if (port == -1)
182              {
1830                port = DEFAULT_SSL_PORT;
184              }
1850             final String host = uri.getHost();
1860             mHostConfiguration.setHost(host, port, https);
1870          }
188           else
189           {
190100             mHostConfiguration.setHost(uri);
191           }
192        }
1930       catch (URIException ue)
194        {
1950          final ArgumentMalformedException ame = new ArgumentMalformedException(
196              "uriAsString", uriAsString, ue.getMessage(), ue);
1970          throw ame;
198        }
199100       catch (IllegalArgumentException iae)
200        {
201100          final ArgumentMalformedException ame = new ArgumentMalformedException(
202              "uriAsString", uriAsString, iae.getMessage(), iae);
203100          throw ame;
204100       }
205100       mHttpClient = new HttpClient();
206  
207100       final SimpleHttpConnectionManager connectionManager
208              = new SimpleHttpConnectionManager();
209100       final HttpConnectionManagerParams httpParams
210              = new HttpConnectionManagerParams();
211100       httpParams.setConnectionTimeout(connectTimeout);
212100       httpParams.setSoTimeout(readTimeout);
213100       connectionManager.setParams(httpParams);
214100       mHttpClient.setHttpConnectionManager(connectionManager);
215100       mState = HttpConnectionState.CONNECTION_ESTABLISHED;
216100    }
217  
218     /** {@inheritDoc} */
219     public void releaseConnection ()
220     {
221100       if (mState == HttpConnectionState.CONNECTION_RELEASED)
222        {
223100          return;
224        }
225100       if (mState != HttpConnectionState.CONNECTION_ESTABLISHED
226              && mState != HttpConnectionState.CONNECTION_EXECUTED)
227        {
228100          final IllegalStateException ile = new IllegalStateException(
229                 "Connection must be established before");
230100          throw ile;
231        }
232100       mPostMethod.releaseConnection();
233  
234        // depcrecated and will be removed in future releases
235100(3)      mPostMethod.recycle();
236100       mState = HttpConnectionState.CONNECTION_RELEASED;
237100    }
238  
239     /** {@inheritDoc} */
240     public void closeConnection ()
241     {
242100       if (mState != HttpConnectionState.CONNECTION_ESTABLISHED
243              && mState != HttpConnectionState.CONNECTION_EXECUTED
244              && mState != HttpConnectionState.CONNECTION_RELEASED)
245        {
246100          final IllegalStateException ile = new IllegalStateException(
247                 "Connection must be established before");
248100          throw ile;
249        }
250100       final HttpConnectionManager connManager
251           = mHttpClient.getHttpConnectionManager();
252100       final HttpConnection connection
253           = connManager.getConnection(mHostConfiguration);
254100       connection.close();
255100       mState = HttpConnectionState.CONNECTION_CLOSED;
256100    }
257  
258     /** {@inheritDoc} */
259     public void execute ()
260           throws HttpConnectionException
261     {
262100       assertStateForExecute();
263100       setRequestHeader();
264100       mPostMethod.setRequestEntity(getRequestEntity());
265  
266        // reassign the path to the previously released post method
267100       if (mState == HttpConnectionState.CONNECTION_RELEASED)
268        {
269100          mPostMethod.setPath(mPath);
270        }
271        // dump request
272100       if (logger.isLoggable(Level.FINEST))
273        {
274100          dumpRequestHeader();
275        }
276100       int resultCode = 0;
277        try
278        {
279100          doCallbackRequestSend();
280100          resultCode = mHttpClient.executeMethod(
281                 mHostConfiguration, mPostMethod);
282100          doCallbackResponseReceived(resultCode, getResponseBody());
283        }
2840       catch (HttpException he)
285        {
2860          final HttpConnectionException hce = new HttpConnectionException(
287                 he.getMessage(), he);
2880          throw hce;
289        }
290100       catch (ConnectException ce)
291        {
292100          final HttpConnectConnectionException hce
293                 = new HttpConnectConnectionException(ce.getMessage(), ce);
294100          throw hce;
295        }
2960       catch (IOException ioe)
297        {
2980          handleIOExceptionWhilstExecute(ioe);
299100       }
300        // dump response
301100       if (logger.isLoggable(Level.FINEST))
302        {
303100          dumpResponse();
304        }
305  
306100       assertResultCode(resultCode);
307100       assertResponseHeader();
308100       mState = HttpConnectionState.CONNECTION_EXECUTED;
309100    }
310  
311     private void assertStateForExecute ()
312     {
313100       if (mState != HttpConnectionState.CONNECTION_ESTABLISHED
314              && mState != HttpConnectionState.CONNECTION_RELEASED)
315        {
316100          final IllegalStateException ile = new IllegalStateException(
317                 "Connection must be established before or released");
318100          throw ile;
319        }
320100    }
321  
322     private void handleIOExceptionWhilstExecute (
323           IOException ioe)
324           throws HttpConnectionException
325     {
326100       final String message = ioe.getMessage().toLowerCase(
327              Constants.SYSTEM_LOCALE);
328        HttpConnectionException hce;
329100(4)(5)      if (message.equals("read timed out"))
330        {
331100          hce = new HttpTimeoutConnectionException(ioe.getMessage(), ioe);
332        }
333        else
334        {
335100          hce = new HttpConnectionException(ioe.getMessage(), ioe);
336        }
337100       throw hce;
338     }
339  
340     /** {@inheritDoc} */
341     public void setRequestBody (InputStream in)
342     {
343100       mRequestBodyInputStream = in;
344100    }
345  
346     /** {@inheritDoc} */
347     public byte[] getResponseBody ()
348           throws HttpEmptyResponseException
349     {
350        final byte[] result;
351        try
352        {
353100          result = mPostMethod.getResponseBody();
354        }
3550       catch (IOException ioe)
356        {
3570          final HttpEmptyResponseException ere
358                 = new HttpEmptyResponseException(
359                       "IOException while obtaining response body", ioe);
3600          throw ere;
361100       }
362  
363100       if (result == null || result.length == 0)
364        {
365100          final HttpEmptyResponseException ere
366              = new HttpEmptyResponseException(
367                 "Received empty http body in response");
368100          throw ere;
369        }
370100       return result;
371     }
372  
373     /** {@inheritDoc} */
374     public String getResponseHeader (String key)
375     {
376100       String result = null;
377100       final Header header = mPostMethod.getResponseHeader(key);
378  
379100       if (header != null)
380        {
381100(6)         result = (header.getElements())[0].getName();
382        }
383100       return result;
384     }
385  
386     /** {@inheritDoc} */
387     public void initSsl (
388           String keyAlias,
389           String keyAliasPassword)
390     {
391100       Assert.notNull(keyAlias, "keyAlias");
392100       Assert.notNull(keyAliasPassword, "keyAliasPassword");
393100       mKeyStoreFilename = System.getProperty(
394              "javax.net.ssl.keyStore");
395100       mKeyStorePassword = System.getProperty(
396              "javax.net.ssl.keyStorePassword");
397100       mTrustStoreFilename = System.getProperty(
398              "javax.net.ssl.trustStore");
399100       mTrustStorePassword = System.getProperty(
400              "javax.net.ssl.trustStorePassword");
401100       mKeyStore = null;
402100       mTrustStore = null;
403100       mKeyAlias = keyAlias;
404100       mKeyAliasPassword = keyAliasPassword;
405100    }
406  
407     /** {@inheritDoc} */
408     public void initSsl (
409           KeyStore keyStore,
410           KeyStore trustStore,
411           String keyAlias,
412           String keyAliasPassword)
413     {
4140       Assert.notNull(keyStore, "keyStore");
4150       Assert.notNull(trustStore, "trustStore");
4160       Assert.notNull(keyAlias, "keyAlias");
4170       Assert.notNull(keyAliasPassword, "keyAliasPassword");
4180       mKeyStore = keyStore;
4190       mTrustStore = trustStore;
4200       mKeyAlias = keyAlias;
4210       mKeyAliasPassword = keyAliasPassword;
4220    }
423  
424     /** {@inheritDoc} */
425     public void setEventListener (HttpConnectorEventListener listener,
426           ConnectorContext context)
427     {
4280       mHttpEventListener = listener;
4290       mConnectorContext = context;
4300    }
431  
432     /** {@inheritDoc} */
433     public void setRequestResponseHeader (HttpRequestResponseHeader header)
434     {
435100       mRequestResponseHeader = header;
436100    }
437  
438     /**
439      * Prepares the InputStream including the http request for the
440      * httpclient.
441      *
442      * @return InputStreamRequestEntity the InputStream used by httpclient
443      */
444     private InputStreamRequestEntity getRequestEntity ()
445     {
446100       InputStreamRequestEntity entity = null;
44750       if (mIsRequestContentLengthSet && mRequestContentType != null)
448        {
4490          entity = new InputStreamRequestEntity(mRequestBodyInputStream,
450              mRequestContentLength, mRequestContentType);
451        }
452100       else if (mIsRequestContentLengthSet)
453        {
4540          entity = new InputStreamRequestEntity(mRequestBodyInputStream,
455                 mRequestContentLength);
456        }
457100       else if (mRequestContentType != null)
458        {
459100          entity = new InputStreamRequestEntity(mRequestBodyInputStream,
460                 mRequestContentType);
461        }
462        else
463        {
4640          entity = new InputStreamRequestEntity(mRequestBodyInputStream);
465        }
466100       return entity;
467     }
468  
469     /**
470      * Sets the request header included in the HttpRequestResponseHeader object.
471      */
472     private void setRequestHeader ()
473     {
474100       if (mRequestResponseHeader != null)
475        {
476100          final Map header
477                 = new HashMap(mRequestResponseHeader.getRequestHeader());
478100          if (!header.containsKey("Content-Type"))
479           {
480              // default Content-Type
4810             header.put("Content-Type", "text/xml; charset=ISO-8859-1");
482           }
483100          for (final Iterator it = header.keySet().iterator(); it.hasNext();)
484           {
485100             final String key = (String) it.next();
486100(7)            final String value = (String) header.get(key);
487100             mPostMethod.setRequestHeader(key, value);
488  
489100(8)(9)            if (key.equals("Content-Length"))
490              {
4910                setRequestContentLength(Integer.parseInt(value));
492              }
493100(10)(11)            else if (key.equals("Content-Type"))
494              {
495100                mRequestContentType = value;
496              }
497100          }
498        }
499100    }
500  
501     /**
502      * Sets the content lenght of the request.
503      * @param contentLength the length to set
504      */
505     private void setRequestContentLength (int contentLength)
506     {
5070       mRequestContentLength = contentLength;
5080       mIsRequestContentLengthSet = true;
5090    }
510  
511     /**
512      * Checks the http status code in the response message.
513      * Throws appropriate HttpConnectionException if result code is
514      * not 200 (OK).
515      *
516      * @param resultCode the http result code received in response
517      * @throws HttpConnectionException to indicate failure on http level
518      */
519     private void assertResultCode (int resultCode)
520           throws HttpConnectionException
521     {
522100       if (resultCode != HTTP_RESULT_OK)
523        {
524           HttpConnectionException hce;
5250          if (resultCode >= HTTP_BAD_REQUEST
526                 && resultCode < HTTP_INTERNAL_SERVER_ERROR)
527           { // HTTP 4xx
5280             hce = new HttpClientConnectionException(
529                       "HTTP Result Code of range 4xx in response",
530                       null);
531           }
5320          else if (resultCode >= HTTP_INTERNAL_SERVER_ERROR)
533           { // HTTP 5xx
5340             hce = new HttpServerConnectionException(
535                       "HTTP Result Code of range 5xx in response",
536                       null);
537           }
5380          else if (resultCode >= HTTP_REDIRECT
539                 && resultCode < HTTP_BAD_REQUEST)
540           { // HTTP 3xx
5410             hce = new HttpServerConnectionException(
542                       "HTTP redirect not supported",
543                       null);
544           }
545           else
546           {
5470             hce = new HttpServerConnectionException(
548                       "Unsupported HTTP Result Code in response",
549                       null);
550           }
5510          hce.setStatusCode(resultCode);
5520          hce.setHttpMessage(StringUtil.asciiToString(getResponseBody()));
553  
5540          throw hce;
555        }
556100    }
557  
558     /**
559      * Checks if the received http header in response match the
560      * response header defined in the given HttpRequestResponseHeader object.
561      *
562      * @throws HttpInvalidResponseHeaderException if one or more header
563      *          values are not like expected
564      */
565     private void assertResponseHeader ()
566           throws HttpInvalidResponseHeaderException
567     {
568100       if (mRequestResponseHeader != null)
569        {
570100          logger.finest(mRequestResponseHeader.toString());
571100          final Map expectedResponseHeader
572                 = mRequestResponseHeader.getResponseHeader();
573100          final StringBuffer message = new StringBuffer();
574100          final Map invalidHeaders = new HashMap();
575100          for (final Iterator it = expectedResponseHeader.keySet().iterator();
576100                it.hasNext();)
577           {
578100             final String key = (String) it.next();
579100(12)            final String value = (String) expectedResponseHeader.get(key);
580100             final String responseValue = getResponseHeader(key);
581100             if (responseValue == null)
582              {
583100                if (message.length() == 0)
584                 {
5850(13)                  message.append("One or more invalid header");
5860                   message.append(" values detected in response:\n");
587                 }
588100                message.append("Expected response header <");
589100                message.append(key);
590100                message.append("> not received\n");
591100                invalidHeaders.put(key, null);
592              }
593100             else if (!responseValue.equalsIgnoreCase(value))
594              {
595100                if (message.length() == 0)
596                 {
597100(14)                  message.append("One or more invalid header");
598100                   message.append(" values detected in response:\n");
599                 }
600100                message.append("Value for <");
601100                message.append(key);
602100                message.append("> is '");
603100                message.append(responseValue);
604100                message.append("' expected was '");
605100                message.append(value);
606100                message.append("'\n");
607100                invalidHeaders.put(key, responseValue);
608              }
609100          } // end for
610  
611100          if (message.length() != 0)
612           {
613100             final HttpInvalidResponseHeaderException ihe
614                    = new HttpInvalidResponseHeaderException(
615                          message.toString(), invalidHeaders);
616  
617              try
618              {
619100                ihe.setHttpMessage(HexUtil.dump(mPostMethod.getResponseBody()));
620              }
6210             catch (IOException ignore)
622              {
623                 // ignore
624100             }
625100             throw ihe;
626           }
627100       }
628        else
629        {
6300          logger.finest("No response header for validating set");
631        }
632100    }
633  
634     private void doCallbackRequestSend ()
635     {
636100       if (mHttpEventListener != null)
637        {
6380          mHttpEventListener.requestSend(mConnectorContext);
639        }
640100    }
641  
642     private void doCallbackResponseReceived (int resultCode, byte[] responseData)
643     {
644100       if (mHttpEventListener != null)
645        {
6460          mHttpEventListener.responseReceived(
647                 resultCode, responseData, mConnectorContext);
648        }
649100    }
650  
651     /**
652      * Dumps the request message.
653      */
654     private void dumpRequestHeader ()
655     {
656100(15)      final StringBuffer dumpBuffer = new StringBuffer();
657100(16)      dumpBuffer.append("\n-------------------------DUMP REQUEST HEADER---\n");
658100       dumpBuffer.append("Host: ");
659100       dumpBuffer.append(mHostConfiguration.getHost());
660100       dumpBuffer.append(LINE_FEED);
661100       dumpBuffer.append("Port: ");
662100       dumpBuffer.append(mHostConfiguration.getPort());
663100       dumpBuffer.append(LINE_FEED);
664100       dumpBuffer.append("Path: ");
665100       dumpBuffer.append(mPostMethod.getPath());
666100       dumpBuffer.append(LINE_FEED);
667100       dumpBuffer.append(LINE_FEED);
668100       dumpBuffer.append("Header:\n");
669100       final Header[] headers = mPostMethod.getRequestHeaders();
670100       for (int i = 0; i < headers.length; i++)
671        {
672100          final String header = headers[i].toString();
673100          dumpBuffer.append(header);
674        }
675100       dumpBuffer.append(LINE_FEED);
676100       dumpBuffer.append("-----------------------------------------");
677100       logger.finest(dumpBuffer.toString());
678100    }
679  
680     /**
681      * Dumps the response message.
682      */
683     private void dumpResponse ()
684     {
685100(17)      final StringBuffer dumpBuffer = new StringBuffer();
686100(18)      dumpBuffer.append("\n-------------------------DUMP RESPONSE---\n");
687100       dumpBuffer.append("StatusLine: ");
688100       dumpBuffer.append(mPostMethod.getStatusLine().toString());
689100       dumpBuffer.append(LINE_FEED);
690100       dumpBuffer.append(LINE_FEED);
691100       dumpBuffer.append("Header:\n");
692100       final Header[] headers = mPostMethod.getResponseHeaders();
693100       for (int i = 0; i < headers.length; i++)
694        {
695100          final String header = headers[i].toString();
696100          dumpBuffer.append(header);
697        }
698100       dumpBuffer.append(LINE_FEED);
699100       dumpBuffer.append("Body: \n");
700100       byte[] response = null;
701        try
702        {
703100          response = mPostMethod.getResponseBody();
704        }
7050       catch (IOException ignore)
706        {
707           // ignore
708100       }
709100       if (response != null)
710        {
711100          dumpBuffer.append(HexUtil.dump(response));
712        }
713        else
714        {
7150          dumpBuffer.append("no response body available");
716        }
717100       dumpBuffer.append(LINE_FEED);
718100       dumpBuffer.append("-----------------------------------------");
719100       logger.finest(dumpBuffer.toString());
720100    }
721  }

Findings in this File

i (19) HttpClientConnectionImpl.mHostConfiguration not initialized in constructor
i (20) HttpClientConnectionImpl.mHttpClient not initialized in constructor
i (21) HttpClientConnectionImpl.mPostMethod not initialized in constructor
c (1) 72 : 0 Type Javadoc comment is missing an @author tag.
i (2) 157 : 0 method org.jcoderz.commons.connector.http.transport.HttpClientConnectionImpl.establishConnection(String, int, int) makes literal string comparisons passing the literal as an argument
d (3) 235 : 18 [deprecation] recycle() in org.apache.commons.httpclient.methods.EntityEnclosingMethod has been deprecated
i (4) 329 : 0 method org.jcoderz.commons.connector.http.transport.HttpClientConnectionImpl.handleIOExceptionWhilstExecute(IOException) makes literal string comparisons passing the literal as an argument
c (5) 329 : 11 Position literals first in String comparisons
c (6) 381 : 20 This statement may have some unnecessary parentheses
w (7) 486 : 0 Method org.jcoderz.commons.connector.http.transport.HttpClientConnectionImpl.setRequestHeader() makes inefficient use of keySet iterator instead of entrySet iterator
i (8) 489 : 0 method org.jcoderz.commons.connector.http.transport.HttpClientConnectionImpl.setRequestHeader() makes literal string comparisons passing the literal as an argument
c (9) 489 : 17 Position literals first in String comparisons
i (10) 493 : 0 method org.jcoderz.commons.connector.http.transport.HttpClientConnectionImpl.setRequestHeader() makes literal string comparisons passing the literal as an argument
c (11) 493 : 22 Position literals first in String comparisons
w (12) 579 : 0 Method org.jcoderz.commons.connector.http.transport.HttpClientConnectionImpl.assertResponseHeader() makes inefficient use of keySet iterator instead of entrySet iterator
i (13) 585 : 33 StringBuffer.append is called 2 consecutive times with literal Strings. Use a single append with a single String.
i (14) 597 : 33 StringBuffer.append is called 2 consecutive times with literal Strings. Use a single append with a single String.
i (15) 656 : 26 StringBuffer constructor is initialized with size 16, but has at least 119 characters appended.
i (16) 657 : 24 StringBuffer.append is called 2 consecutive times with literal Strings. Use a single append with a single String.
i (17) 685 : 26 StringBuffer constructor is initialized with size 16, but has at least 141 characters appended.
i (18) 686 : 24 StringBuffer.append is called 2 consecutive times with literal Strings. Use a single append with a single String.