Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 32 33 package org.apache.commons.httpclient; 34 35 import java.io.IOException ; 36 import java.io.InputStream ; 37 38 import org.apache.commons.httpclient.params.HttpConnectionManagerParams; 39 40 42 public class NoHostHttpConnectionManager implements HttpConnectionManager { 43 44 private HttpConnection connection; 45 46 private boolean connectionReleased = false; 47 48 private HttpConnectionManagerParams params = new HttpConnectionManagerParams(); 49 50 public NoHostHttpConnectionManager() { 51 super(); 52 } 53 54 57 public void closeIdleConnections(long idleTimeout) { 58 } 59 60 63 public boolean isConnectionReleased() { 64 return connectionReleased; 65 } 66 67 70 public void setConnection(HttpConnection connection) { 71 this.connection = connection; 72 connection.setHttpConnectionManager(this); 73 connection.getParams().setDefaults(this.params); 74 } 75 76 public HttpConnection getConnection(HostConfiguration hostConfiguration) { 77 78 if (!hostConfiguration.hostEquals(connection) 81 || !hostConfiguration.proxyEquals(connection)) { 82 83 if (connection.isOpen()) { 84 connection.close(); 85 } 86 87 connection.setHost(hostConfiguration.getHost()); 88 connection.setPort(hostConfiguration.getPort()); 89 connection.setProtocol(hostConfiguration.getProtocol()); 90 connection.setLocalAddress(hostConfiguration.getLocalAddress()); 91 92 connection.setProxyHost(hostConfiguration.getProxyHost()); 93 connection.setProxyPort(hostConfiguration.getProxyPort()); 94 } else { 95 finishLastResponse(connection); 96 } 97 98 connectionReleased = false; 99 return connection; 100 } 101 102 105 public HttpConnection getConnection(HostConfiguration hostConfiguration, long timeout) 106 throws HttpException { 107 return getConnection(hostConfiguration); 108 } 109 110 public HttpConnection getConnectionWithTimeout( 111 HostConfiguration hostConfiguration, 112 long timeout) 113 throws ConnectionPoolTimeoutException { 114 return getConnection(hostConfiguration); 115 } 116 117 public void releaseConnection(HttpConnection conn) { 118 if (conn != connection) { 119 throw new IllegalStateException ("Unexpected close on a different connection."); 120 } 121 122 connectionReleased = true; 123 finishLastResponse(connection); 124 } 125 126 132 static void finishLastResponse(HttpConnection conn) { 133 InputStream lastResponse = conn.getLastResponseInputStream(); 134 if (lastResponse != null) { 135 conn.setLastResponseInputStream(null); 136 try { 137 lastResponse.close(); 138 } catch (IOException ioe) { 139 conn.close(); 141 } 142 } 143 } 144 145 public HttpConnectionManagerParams getParams() { 146 return this.params; 147 } 148 149 public void setParams(final HttpConnectionManagerParams params) { 150 if (params == null) { 151 throw new IllegalArgumentException ("Parameters may not be null"); 152 } 153 this.params = params; 154 } 155 156 } 157
| Popular Tags
|