Author: tv Date: Sun Sep 25 16:39:10 2016 New Revision: 1762225 URL: http://svn.apache.org/viewvc?rev=1762225&view=rev Log: Clean up
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/AbstractHttpClient.java commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/AbstractHttpClient.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/AbstractHttpClient.java?rev=1762225&r1=1762224&r2=1762225&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/AbstractHttpClient.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/AbstractHttpClient.java Sun Sep 25 16:39:10 2016 @@ -1,5 +1,7 @@ package org.apache.commons.jcs.auxiliary.remote.http.client; +import java.io.IOException; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -28,12 +30,10 @@ import org.apache.commons.httpclient.coo import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import java.io.IOException; - /** * This class simply configures the http multithreaded connection manager. * <p> - * This is abstract because it can't do anything. Child classes can overwrite whatever they want. + * This is abstract because it can do anything. Child classes can overwrite whatever they want. */ public abstract class AbstractHttpClient { @@ -57,13 +57,9 @@ public abstract class AbstractHttpClient */ public AbstractHttpClient( RemoteHttpCacheAttributes remoteHttpCacheAttributes ) { - setRemoteHttpCacheAttributes( remoteHttpCacheAttributes ); - setConnectionManager( new MultiThreadedHttpConnectionManager() ); - - // THIS IS NOT THREAD SAFE: - // setHttpClient( new HttpClient() ); - // THIS IS: - setHttpClient( new HttpClient( getConnectionManager() ) ); + this.remoteHttpCacheAttributes = remoteHttpCacheAttributes; + this.connectionManager = new MultiThreadedHttpConnectionManager(); + this.httpClient = new HttpClient(this.connectionManager); configureClient(); } @@ -71,27 +67,28 @@ public abstract class AbstractHttpClient /** * Configures the http client. */ - public void configureClient() + protected void configureClient() { if ( getRemoteHttpCacheAttributes().getMaxConnectionsPerHost() > 0 ) { - getConnectionManager().getParams().setMaxTotalConnections( - getRemoteHttpCacheAttributes() - .getMaxConnectionsPerHost() ); + this.connectionManager.getParams() + .setMaxTotalConnections(getRemoteHttpCacheAttributes().getMaxConnectionsPerHost()); + this.connectionManager.getParams() + .setDefaultMaxConnectionsPerHost(getRemoteHttpCacheAttributes().getMaxConnectionsPerHost()); } - getConnectionManager().getParams().setSoTimeout( getRemoteHttpCacheAttributes().getSocketTimeoutMillis() ); + this.connectionManager.getParams().setSoTimeout( getRemoteHttpCacheAttributes().getSocketTimeoutMillis() ); String httpVersion = getRemoteHttpCacheAttributes().getHttpVersion(); if ( httpVersion != null ) { if ( "1.1".equals( httpVersion ) ) { - getHttpClient().getParams().setParameter( "http.protocol.version", HttpVersion.HTTP_1_1 ); + this.httpClient.getParams().setParameter( "http.protocol.version", HttpVersion.HTTP_1_1 ); } else if ( "1.0".equals( httpVersion ) ) { - getHttpClient().getParams().setParameter( "http.protocol.version", HttpVersion.HTTP_1_0 ); + this.httpClient.getParams().setParameter( "http.protocol.version", HttpVersion.HTTP_1_0 ); } else { @@ -99,13 +96,11 @@ public abstract class AbstractHttpClient } } - getConnectionManager().getParams().setConnectionTimeout( - getRemoteHttpCacheAttributes() - .getConnectionTimeoutMillis() ); + this.connectionManager.getParams() + .setConnectionTimeout(getRemoteHttpCacheAttributes().getConnectionTimeoutMillis()); // By default we instruct HttpClient to ignore cookies. - String cookiePolicy = CookiePolicy.IGNORE_COOKIES; - getHttpClient().getParams().setCookiePolicy( cookiePolicy ); + this.httpClient.getParams().setCookiePolicy( CookiePolicy.IGNORE_COOKIES ); } /** @@ -119,7 +114,7 @@ public abstract class AbstractHttpClient throws IOException { HttpState httpState = preProcessWebserviceCall( post ); - getHttpClient().executeMethod( null, post, httpState ); + this.httpClient.executeMethod( null, post, httpState ); postProcessWebserviceCall( post, httpState ); } @@ -130,7 +125,7 @@ public abstract class AbstractHttpClient * @return HttpState * @throws IOException */ - public abstract HttpState preProcessWebserviceCall( HttpMethod post ) + protected abstract HttpState preProcessWebserviceCall( HttpMethod post ) throws IOException; /** @@ -140,53 +135,13 @@ public abstract class AbstractHttpClient * @param httpState state * @throws IOException */ - public abstract void postProcessWebserviceCall( HttpMethod post, HttpState httpState ) + protected abstract void postProcessWebserviceCall( HttpMethod post, HttpState httpState ) throws IOException; /** - * @return Returns the httpClient. - */ - private HttpClient getHttpClient() - { - return httpClient; - } - - /** - * @param httpClient The httpClient to set. - */ - private void setHttpClient( HttpClient httpClient ) - { - this.httpClient = httpClient; - } - - /** - * @return Returns the connectionManager. - */ - public MultiThreadedHttpConnectionManager getConnectionManager() - { - return connectionManager; - } - - /** - * @param connectionManager The connectionManager to set. - */ - public void setConnectionManager( MultiThreadedHttpConnectionManager connectionManager ) - { - this.connectionManager = connectionManager; - } - - /** - * @param remoteHttpCacheAttributes the remoteHttpCacheAttributes to set - */ - public void setRemoteHttpCacheAttributes( RemoteHttpCacheAttributes remoteHttpCacheAttributes ) - { - this.remoteHttpCacheAttributes = remoteHttpCacheAttributes; - } - - /** * @return the remoteHttpCacheAttributes */ - public RemoteHttpCacheAttributes getRemoteHttpCacheAttributes() + protected RemoteHttpCacheAttributes getRemoteHttpCacheAttributes() { return remoteHttpCacheAttributes; } Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java?rev=1762225&r1=1762224&r2=1762225&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java Sun Sep 25 16:39:10 2016 @@ -41,6 +41,9 @@ public class RemoteHttpCacheDispatcher extends AbstractHttpClient implements IRemoteCacheDispatcher { + /** Parameter encoding */ + private static final String DEFAULT_ENCODING = "UTF-8"; + /** Named of the parameter */ private static final String PARAMETER_REQUEST_TYPE = "RequestType"; @@ -99,8 +102,7 @@ public class RemoteHttpCacheDispatcher } catch ( Exception e ) { - log.error( "Problem dispatching request.", e ); - throw new IOException( e.getMessage() ); + throw new IOException("Problem dispatching request.", e); } } @@ -147,7 +149,7 @@ public class RemoteHttpCacheDispatcher if ( remoteCacheRequest.getCacheName() != null ) { url.append( PARAMETER_CACHE_NAME + "=" - + URLEncoder.encode( remoteCacheRequest.getCacheName(), "UTF-8" ) ); + + URLEncoder.encode( remoteCacheRequest.getCacheName(), DEFAULT_ENCODING ) ); } } if ( getRemoteHttpCacheAttributes().isIncludeKeysAndPatternsAsParameter() ) @@ -172,7 +174,7 @@ public class RemoteHttpCacheDispatcher default: break; } - String encodedKeyValue = URLEncoder.encode( keyValue, "UTF-8" ); + String encodedKeyValue = URLEncoder.encode( keyValue, DEFAULT_ENCODING ); url.append( "&" + PARAMETER_KEY + "=" + encodedKeyValue ); } if ( getRemoteHttpCacheAttributes().isIncludeRequestTypeasAsParameter() ) @@ -180,7 +182,7 @@ public class RemoteHttpCacheDispatcher url.append( "&" + PARAMETER_REQUEST_TYPE + "=" - + URLEncoder.encode( remoteCacheRequest.getRequestType().toString(), "UTF-8" ) ); + + URLEncoder.encode( remoteCacheRequest.getRequestType().toString(), DEFAULT_ENCODING ) ); } } catch ( UnsupportedEncodingException e ) @@ -204,7 +206,7 @@ public class RemoteHttpCacheDispatcher * @throws IOException */ @Override - public HttpState preProcessWebserviceCall( HttpMethod post ) + protected HttpState preProcessWebserviceCall( HttpMethod post ) throws IOException { // do nothing. Child can override. @@ -219,7 +221,7 @@ public class RemoteHttpCacheDispatcher * @throws IOException */ @Override - public void postProcessWebserviceCall( HttpMethod post, HttpState httpState ) + protected void postProcessWebserviceCall( HttpMethod post, HttpState httpState ) throws IOException { // do nothing. Child can override.