You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tv...@apache.org on 2017/09/24 19:04:47 UTC
svn commit: r1809537 - in /commons/proper/jcs/trunk: ./ commons-jcs-core/
commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/
commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/config/
commons-jcs-core/src/test/...
Author: tv
Date: Sun Sep 24 19:04:47 2017
New Revision: 1809537
URL: http://svn.apache.org/viewvc?rev=1809537&view=rev
Log:
JCS-181 Update dependency to httpclient 4.5.3
Removed:
commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcherUnitTest.java
Modified:
commons/proper/jcs/trunk/commons-jcs-core/pom.xml
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
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/config/PropertySetter.java
commons/proper/jcs/trunk/pom.xml
commons/proper/jcs/trunk/src/changes/changes.xml
Modified: commons/proper/jcs/trunk/commons-jcs-core/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/pom.xml?rev=1809537&r1=1809536&r2=1809537&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/pom.xml (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/pom.xml Sun Sep 24 19:04:47 2017
@@ -48,8 +48,8 @@
<!-- JDBC DISK CACHE -->
<dependency>
- <groupId>commons-dbcp</groupId>
- <artifactId>commons-dbcp</artifactId>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-dbcp2</artifactId>
<optional>true</optional>
</dependency>
@@ -94,14 +94,8 @@
</dependency -->
<dependency>
- <groupId>org.apache.velocity</groupId>
- <artifactId>velocity-tools</artifactId>
- <optional>true</optional>
- </dependency>
-
- <dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
<optional>true</optional>
</dependency>
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=1809537&r1=1809536&r2=1809537&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 24 19:04:47 2017
@@ -1,7 +1,5 @@
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
@@ -21,14 +19,18 @@ import java.io.IOException;
* under the License.
*/
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.HttpState;
-import org.apache.commons.httpclient.HttpVersion;
-import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
-import org.apache.commons.httpclient.cookie.CookiePolicy;
+import java.io.IOException;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpVersion;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.CookieSpecs;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.client.methods.RequestBuilder;
+import org.apache.http.impl.client.HttpClientBuilder;
/**
* This class simply configures the http multithreaded connection manager.
@@ -37,12 +39,12 @@ import org.apache.commons.logging.LogFac
*/
public abstract class AbstractHttpClient
{
- /** The connection manager. */
- private MultiThreadedHttpConnectionManager connectionManager;
-
/** The client */
private HttpClient httpClient;
+ /** The protocol version */
+ private HttpVersion httpVersion;
+
/** Configuration settings. */
private RemoteHttpCacheAttributes remoteHttpCacheAttributes;
@@ -58,84 +60,87 @@ public abstract class AbstractHttpClient
public AbstractHttpClient( RemoteHttpCacheAttributes remoteHttpCacheAttributes )
{
this.remoteHttpCacheAttributes = remoteHttpCacheAttributes;
- this.connectionManager = new MultiThreadedHttpConnectionManager();
- this.httpClient = new HttpClient(this.connectionManager);
- configureClient();
+ String httpVersion = getRemoteHttpCacheAttributes().getHttpVersion();
+ if ( "1.1".equals( httpVersion ) )
+ {
+ this.httpVersion = HttpVersion.HTTP_1_1;
+ }
+ else if ( "1.0".equals( httpVersion ) )
+ {
+ this.httpVersion = HttpVersion.HTTP_1_0;
+ }
+ else
+ {
+ log.warn( "Unrecognized value for 'httpVersion': [" + httpVersion + "], defaulting to 1.1" );
+ this.httpVersion = HttpVersion.HTTP_1_1;
+ }
+
+ HttpClientBuilder builder = HttpClientBuilder.create();
+ configureClient(builder);
+ this.httpClient = builder.build();
}
/**
* Configures the http client.
+ *
+ * @param builder client builder to configure
*/
- protected void configureClient()
+ protected void configureClient(HttpClientBuilder builder)
{
if ( getRemoteHttpCacheAttributes().getMaxConnectionsPerHost() > 0 )
{
- this.connectionManager.getParams()
- .setMaxTotalConnections(getRemoteHttpCacheAttributes().getMaxConnectionsPerHost());
- this.connectionManager.getParams()
- .setDefaultMaxConnectionsPerHost(getRemoteHttpCacheAttributes().getMaxConnectionsPerHost());
- }
-
- this.connectionManager.getParams().setSoTimeout( getRemoteHttpCacheAttributes().getSocketTimeoutMillis() );
-
- String httpVersion = getRemoteHttpCacheAttributes().getHttpVersion();
- if ( httpVersion != null )
- {
- if ( "1.1".equals( httpVersion ) )
- {
- this.httpClient.getParams().setParameter( "http.protocol.version", HttpVersion.HTTP_1_1 );
- }
- else if ( "1.0".equals( httpVersion ) )
- {
- this.httpClient.getParams().setParameter( "http.protocol.version", HttpVersion.HTTP_1_0 );
- }
- else
- {
- log.warn( "Unrecognized value for 'httpVersion': [" + httpVersion + "]" );
- }
+ builder.setMaxConnTotal(getRemoteHttpCacheAttributes().getMaxConnectionsPerHost());
+ builder.setMaxConnPerRoute(getRemoteHttpCacheAttributes().getMaxConnectionsPerHost());
}
- this.connectionManager.getParams()
- .setConnectionTimeout(getRemoteHttpCacheAttributes().getConnectionTimeoutMillis());
-
- // By default we instruct HttpClient to ignore cookies.
- this.httpClient.getParams().setCookiePolicy( CookiePolicy.IGNORE_COOKIES );
+ builder.setDefaultRequestConfig(RequestConfig.custom()
+ .setConnectTimeout(getRemoteHttpCacheAttributes().getConnectionTimeoutMillis())
+ .setSocketTimeout(getRemoteHttpCacheAttributes().getSocketTimeoutMillis())
+ // By default we instruct HttpClient to ignore cookies.
+ .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
+ .build());
}
/**
- * Extracted method that can be overwritten to do additional things to the post before the call
- * is made.
+ * Execute the web service call
* <p>
- * @param post the post that is about to get executed.
+ * @param builder builder for the post request
+ *
+ * @return the call response
+ *
* @throws IOException on i/o error
*/
- protected final void doWebserviceCall( HttpMethod post )
+ protected final HttpResponse doWebserviceCall( RequestBuilder builder )
throws IOException
{
- HttpState httpState = preProcessWebserviceCall( post );
- this.httpClient.executeMethod( null, post, httpState );
- postProcessWebserviceCall( post, httpState );
+ preProcessWebserviceCall( builder.setVersion(httpVersion) );
+ HttpUriRequest request = builder.build();
+ HttpResponse httpResponse = this.httpClient.execute( request );
+ postProcessWebserviceCall( request, httpResponse );
+
+ return httpResponse;
}
/**
- * Called before the executeMethod on the client.
+ * Called before the execute call on the client.
* <p>
- * @param post http method
- * @return HttpState
+ * @param requestBuilder http method request builder
+ *
* @throws IOException
*/
- protected abstract HttpState preProcessWebserviceCall( HttpMethod post )
+ protected abstract void preProcessWebserviceCall( RequestBuilder requestBuilder )
throws IOException;
/**
- * Called after the executeMethod on the client.
+ * Called after the execute call on the client.
* <p>
- * @param post http method
- * @param httpState state
+ * @param request http request
+ * @param httpState result of execution
+ *
* @throws IOException
*/
- protected abstract void postProcessWebserviceCall( HttpMethod post, HttpState httpState )
+ protected abstract void postProcessWebserviceCall( HttpUriRequest request, HttpResponse httpState )
throws IOException;
/**
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=1809537&r1=1809536&r2=1809537&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 24 19:04:47 2017
@@ -20,21 +20,20 @@ package org.apache.commons.jcs.auxiliary
*/
import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
+import java.nio.charset.Charset;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.HttpState;
-import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheDispatcher;
import org.apache.commons.jcs.auxiliary.remote.value.RemoteCacheRequest;
import org.apache.commons.jcs.auxiliary.remote.value.RemoteCacheResponse;
import org.apache.commons.jcs.utils.serialization.StandardSerializer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.http.HttpException;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.client.methods.RequestBuilder;
+import org.apache.http.entity.ByteArrayEntity;
+import org.apache.http.util.EntityUtils;
/** Calls the service. */
public class RemoteHttpCacheDispatcher
@@ -42,7 +41,7 @@ public class RemoteHttpCacheDispatcher
implements IRemoteCacheDispatcher
{
/** Parameter encoding */
- private static final String DEFAULT_ENCODING = "UTF-8";
+ private static final Charset DEFAULT_ENCODING = Charset.forName("UTF-8");
/** Named of the parameter */
private static final String PARAMETER_REQUEST_TYPE = "RequestType";
@@ -85,9 +84,9 @@ public class RemoteHttpCacheDispatcher
{
byte[] requestAsByteArray = serializer.serialize( remoteCacheRequest );
- String url = addParameters( remoteCacheRequest, getRemoteHttpCacheAttributes().getUrl() );
-
- byte[] responseAsByteArray = processRequest( requestAsByteArray, url );
+ byte[] responseAsByteArray = processRequest( requestAsByteArray,
+ remoteCacheRequest,
+ getRemoteHttpCacheAttributes().getUrl());
RemoteCacheResponse<T> remoteCacheResponse = null;
try
@@ -107,121 +106,88 @@ public class RemoteHttpCacheDispatcher
}
/**
- * @param requestAsByteArray
- * @param url
+ * Process single request
+ *
+ * @param requestAsByteArray request body
+ * @param remoteCacheRequest the cache request
+ * @param url target url
+ *
* @return byte[] - the response
+ *
* @throws IOException
* @throws HttpException
*/
- protected byte[] processRequest( byte[] requestAsByteArray, String url )
+ protected <K, V> byte[] processRequest( byte[] requestAsByteArray,
+ RemoteCacheRequest<K, V> remoteCacheRequest, String url )
throws IOException, HttpException
{
- PostMethod post = new PostMethod( url );
- RequestEntity requestEntity = new ByteArrayRequestEntity( requestAsByteArray );
- post.setRequestEntity( requestEntity );
- doWebserviceCall( post );
- byte[] response = post.getResponseBody();
- return response;
- }
-
- /**
- * @param remoteCacheRequest
- * @param baseUrl
- * @return String
- */
- protected <K, V> String addParameters( RemoteCacheRequest<K, V> remoteCacheRequest, String baseUrl )
- {
- StringBuilder url = new StringBuilder( baseUrl == null ? "" : baseUrl );
+ RequestBuilder builder = RequestBuilder.post( url ).setCharset( DEFAULT_ENCODING );
- try
+ if ( getRemoteHttpCacheAttributes().isIncludeCacheNameAsParameter()
+ && remoteCacheRequest.getCacheName() != null )
{
- if ( baseUrl != null && baseUrl.indexOf( "?" ) == -1 )
- {
- url.append( "?" );
- }
- else
- {
- url.append( "&" );
- }
-
- if ( getRemoteHttpCacheAttributes().isIncludeCacheNameAsParameter() )
- {
- if ( remoteCacheRequest.getCacheName() != null )
- {
- url.append( PARAMETER_CACHE_NAME + "="
- + URLEncoder.encode( remoteCacheRequest.getCacheName(), DEFAULT_ENCODING ) );
- }
- }
- if ( getRemoteHttpCacheAttributes().isIncludeKeysAndPatternsAsParameter() )
- {
- String keyValue = "";
- switch ( remoteCacheRequest.getRequestType() )
- {
- case GET:
- case REMOVE:
- case GET_KEYSET:
- keyValue = remoteCacheRequest.getKey() + "";
- break;
- case GET_MATCHING:
- keyValue = remoteCacheRequest.getPattern();
- break;
- case GET_MULTIPLE:
- keyValue = remoteCacheRequest.getKeySet() + "";
- break;
- case UPDATE:
- keyValue = remoteCacheRequest.getCacheElement().getKey() + "";
- break;
- default:
- break;
- }
- String encodedKeyValue = URLEncoder.encode( keyValue, DEFAULT_ENCODING );
- url.append( "&" + PARAMETER_KEY + "=" + encodedKeyValue );
- }
- if ( getRemoteHttpCacheAttributes().isIncludeRequestTypeasAsParameter() )
- {
- url.append( "&"
- + PARAMETER_REQUEST_TYPE
- + "="
- + URLEncoder.encode( remoteCacheRequest.getRequestType().toString(), DEFAULT_ENCODING ) );
- }
+ builder.addParameter( PARAMETER_CACHE_NAME, remoteCacheRequest.getCacheName() );
}
- catch ( UnsupportedEncodingException e )
+ if ( getRemoteHttpCacheAttributes().isIncludeKeysAndPatternsAsParameter() )
{
- log.error( "Couldn't encode URL.", e );
+ String keyValue = "";
+ switch ( remoteCacheRequest.getRequestType() )
+ {
+ case GET:
+ case REMOVE:
+ case GET_KEYSET:
+ keyValue = remoteCacheRequest.getKey().toString();
+ break;
+ case GET_MATCHING:
+ keyValue = remoteCacheRequest.getPattern();
+ break;
+ case GET_MULTIPLE:
+ keyValue = remoteCacheRequest.getKeySet().toString();
+ break;
+ case UPDATE:
+ keyValue = remoteCacheRequest.getCacheElement().getKey().toString();
+ break;
+ default:
+ break;
+ }
+ builder.addParameter( PARAMETER_KEY, keyValue );
}
-
- if ( log.isDebugEnabled() )
+ if ( getRemoteHttpCacheAttributes().isIncludeRequestTypeasAsParameter() )
{
- log.debug( "Url: " + url.toString() );
+ builder.addParameter( PARAMETER_REQUEST_TYPE,
+ remoteCacheRequest.getRequestType().toString() );
}
- return url.toString();
+ builder.setEntity(new ByteArrayEntity( requestAsByteArray ));
+ HttpResponse httpResponse = doWebserviceCall( builder );
+ byte[] response = EntityUtils.toByteArray( httpResponse.getEntity() );
+ return response;
}
/**
- * Called before the executeMethod on the client.
+ * Called before the execute call on the client.
* <p>
- * @param post http method
- * @return HttpState
+ * @param requestBuilder http method request builder
+ *
* @throws IOException
*/
@Override
- protected HttpState preProcessWebserviceCall( HttpMethod post )
+ protected void preProcessWebserviceCall( RequestBuilder requestBuilder )
throws IOException
{
// do nothing. Child can override.
- return null;
}
/**
- * Called after the executeMethod on the client.
+ * Called after the execute call on the client.
* <p>
- * @param post http method
- * @param httpState state
+ * @param request http request
+ * @param httpState result of execution
+ *
* @throws IOException
*/
@Override
- protected void postProcessWebserviceCall( HttpMethod post, HttpState httpState )
+ protected void postProcessWebserviceCall( HttpUriRequest request, HttpResponse httpState )
throws IOException
{
// do nothing. Child can override.
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/config/PropertySetter.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/config/PropertySetter.java?rev=1809537&r1=1809536&r2=1809537&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/config/PropertySetter.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/config/PropertySetter.java Sun Sep 24 19:04:47 2017
@@ -1,5 +1,14 @@
package org.apache.commons.jcs.utils.config;
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.Enumeration;
+import java.util.Properties;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -22,15 +31,6 @@ package org.apache.commons.jcs.utils.con
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.beans.BeanInfo;
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
-import java.beans.PropertyDescriptor;
-import java.io.File;
-import java.lang.reflect.Method;
-import java.util.Enumeration;
-import java.util.Properties;
-
/**
* This class is based on the log4j class org.apache.log4j.config.PropertySetter that was made by
* Anders Kristensen
@@ -265,7 +265,6 @@ public class PropertySetter
}
else if( type.isEnum() )
{
- @SuppressWarnings("unchecked") // type check in if()
Enum<?> en = Enum.valueOf(type.asSubclass(Enum.class), v );
return en;
}
Modified: commons/proper/jcs/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/pom.xml?rev=1809537&r1=1809536&r2=1809537&view=diff
==============================================================================
--- commons/proper/jcs/trunk/pom.xml (original)
+++ commons/proper/jcs/trunk/pom.xml Sun Sep 24 19:04:47 2017
@@ -306,17 +306,9 @@
<!-- JDBC DISK CACHE -->
<dependency>
- <groupId>commons-dbcp</groupId>
- <artifactId>commons-dbcp</artifactId>
- <version>1.4</version>
- <optional>true</optional>
- </dependency>
-
- <!-- JDBC DISK CACHE -->
- <dependency>
- <groupId>commons-pool</groupId>
- <artifactId>commons-pool</artifactId>
- <version>1.6</version>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-dbcp2</artifactId>
+ <version>2.1.1</version>
<optional>true</optional>
</dependency>
@@ -365,16 +357,9 @@
</dependency -->
<dependency>
- <groupId>org.apache.velocity</groupId>
- <artifactId>velocity-tools</artifactId>
- <version>2.0</version>
- <optional>true</optional>
- </dependency>
-
- <dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>3.1</version>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>4.5.3</version>
<optional>true</optional>
</dependency>
@@ -539,7 +524,7 @@
<jsr107.api.version>1.0.0</jsr107.api.version>
<commons.collections.version>4.1</commons.collections.version>
- <commons.lang.version>3.3.2</commons.lang.version>
+ <commons.lang.version>3.6</commons.lang.version>
<commons.clirr.version>2.8</commons.clirr.version>
<test.type>Unit</test.type>
Modified: commons/proper/jcs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/changes/changes.xml?rev=1809537&r1=1809536&r2=1809537&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/changes/changes.xml (original)
+++ commons/proper/jcs/trunk/src/changes/changes.xml Sun Sep 24 19:04:47 2017
@@ -20,6 +20,18 @@
</properties>
<body>
<release version="3.0" date="unreleased">
+ <action dev="tv" type="remove">
+ Remove dependency on velocity-tools
+ </action>
+ <action dev="tv" type="remove">
+ Remove deprecated code
+ </action>
+ <action issue="JCS-181" dev="tv" type="update">
+ Update dependency to httpclient 4.5.3
+ </action>
+ <action dev="tv" type="update">
+ Update dependency commons-dbcp2
+ </action>
<action dev="tv" type="update">
Finally require Java 8
</action>