Source Code Cross Referenced for DefaultHttpMethodRetryHandler.java in  » Net » Apache-common-HttpClient » org » apache » commons » httpclient » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Apache common HttpClient » org.apache.commons.httpclient 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/DefaultHttpMethodRetryHandler.java,v 1.3 2004/12/20 11:47:46 olegk Exp $
003:         * $Revision: 480424 $
004:         * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
005:         *
006:         * ====================================================================
007:         *
008:         *  Licensed to the Apache Software Foundation (ASF) under one or more
009:         *  contributor license agreements.  See the NOTICE file distributed with
010:         *  this work for additional information regarding copyright ownership.
011:         *  The ASF licenses this file to You under the Apache License, Version 2.0
012:         *  (the "License"); you may not use this file except in compliance with
013:         *  the License.  You may obtain a copy of the License at
014:         *
015:         *      http://www.apache.org/licenses/LICENSE-2.0
016:         *
017:         *  Unless required by applicable law or agreed to in writing, software
018:         *  distributed under the License is distributed on an "AS IS" BASIS,
019:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
020:         *  See the License for the specific language governing permissions and
021:         *  limitations under the License.
022:         * ====================================================================
023:         *
024:         * This software consists of voluntary contributions made by many
025:         * individuals on behalf of the Apache Software Foundation.  For more
026:         * information on the Apache Software Foundation, please see
027:         * <http://www.apache.org/>.
028:         *
029:         */
030:
031:        package org.apache.commons.httpclient;
032:
033:        import java.io.IOException;
034:        import java.io.InterruptedIOException;
035:        import java.net.NoRouteToHostException;
036:        import java.net.UnknownHostException;
037:
038:        /**
039:         * The default {@link HttpMethodRetryHandler} used by {@link HttpMethod}s.
040:         * 
041:         * @author Michael Becke
042:         * @author <a href="mailto:oleg -at- ural.ru">Oleg Kalnichevski</a>
043:         */
044:        public class DefaultHttpMethodRetryHandler implements 
045:                HttpMethodRetryHandler {
046:
047:            private static Class SSL_HANDSHAKE_EXCEPTION = null;
048:
049:            static {
050:                try {
051:                    SSL_HANDSHAKE_EXCEPTION = Class
052:                            .forName("javax.net.ssl.SSLHandshakeException");
053:                } catch (ClassNotFoundException ignore) {
054:                }
055:            }
056:            /** the number of times a method will be retried */
057:            private int retryCount;
058:
059:            /** Whether or not methods that have successfully sent their request will be retried */
060:            private boolean requestSentRetryEnabled;
061:
062:            /**
063:             * Creates a new DefaultHttpMethodRetryHandler.
064:             * @param retryCount the number of times a method will be retried
065:             * @param requestSentRetryEnabled if true, methods that have successfully sent their request will be retried
066:             */
067:            public DefaultHttpMethodRetryHandler(int retryCount,
068:                    boolean requestSentRetryEnabled) {
069:                super ();
070:                this .retryCount = retryCount;
071:                this .requestSentRetryEnabled = requestSentRetryEnabled;
072:            }
073:
074:            /**
075:             * Creates a new DefaultHttpMethodRetryHandler that retries up to 3 times
076:             * but does not retry methods that have successfully sent their requests.
077:             */
078:            public DefaultHttpMethodRetryHandler() {
079:                this (3, false);
080:            }
081:
082:            /** 
083:             * Used <code>retryCount</code> and <code>requestSentRetryEnabled</code> to determine
084:             * if the given method should be retried.
085:             * 
086:             * @see HttpMethodRetryHandler#retryMethod(HttpMethod, IOException, int)
087:             */
088:            public boolean retryMethod(final HttpMethod method,
089:                    final IOException exception, int executionCount) {
090:                if (method == null) {
091:                    throw new IllegalArgumentException(
092:                            "HTTP method may not be null");
093:                }
094:                if (exception == null) {
095:                    throw new IllegalArgumentException(
096:                            "Exception parameter may not be null");
097:                }
098:                // HttpMethod interface is the WORST thing ever done to HttpClient
099:                if (method instanceof  HttpMethodBase) {
100:                    if (((HttpMethodBase) method).isAborted()) {
101:                        return false;
102:                    }
103:                }
104:                if (executionCount > this .retryCount) {
105:                    // Do not retry if over max retry count
106:                    return false;
107:                }
108:                if (exception instanceof  NoHttpResponseException) {
109:                    // Retry if the server dropped connection on us
110:                    return true;
111:                }
112:                if (exception instanceof  InterruptedIOException) {
113:                    // Timeout
114:                    return false;
115:                }
116:                if (exception instanceof  UnknownHostException) {
117:                    // Unknown host
118:                    return false;
119:                }
120:                if (exception instanceof  NoRouteToHostException) {
121:                    // Host unreachable
122:                    return false;
123:                }
124:                if (SSL_HANDSHAKE_EXCEPTION != null
125:                        && SSL_HANDSHAKE_EXCEPTION.isInstance(exception)) {
126:                    // SSL handshake exception
127:                    return false;
128:                }
129:                if (!method.isRequestSent() || this .requestSentRetryEnabled) {
130:                    // Retry if the request has not been sent fully or
131:                    // if it's OK to retry methods that have been sent
132:                    return true;
133:                }
134:                // otherwise do not retry
135:                return false;
136:            }
137:
138:            /**
139:             * @return <code>true</code> if this handler will retry methods that have 
140:             * successfully sent their request, <code>false</code> otherwise
141:             */
142:            public boolean isRequestSentRetryEnabled() {
143:                return requestSentRetryEnabled;
144:            }
145:
146:            /**
147:             * @return the maximum number of times a method will be retried
148:             */
149:            public int getRetryCount() {
150:                return retryCount;
151:            }
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.