From 92700fd23b33121226318309077f9ce1def990ed Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Wed, 27 Aug 2014 07:44:54 +0000 Subject: [PATCH] Cookie spec provides to re-use the same thread-safe CookieSpec instance by default git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1620787 13f79535-47bb-0310-9956-ffa450edef68 --- .../http/impl/cookie/BestMatchSpecFactory.java | 13 ++++++------- .../impl/cookie/BrowserCompatSpecFactory.java | 11 ++++++----- .../impl/cookie/NetscapeDraftSpecFactory.java | 15 ++++++--------- .../http/impl/cookie/RFC2109SpecFactory.java | 13 ++++++------- .../http/impl/cookie/RFC2965SpecFactory.java | 13 ++++++------- 5 files changed, 30 insertions(+), 35 deletions(-) diff --git a/httpclient/src/main/java/org/apache/http/impl/cookie/BestMatchSpecFactory.java b/httpclient/src/main/java/org/apache/http/impl/cookie/BestMatchSpecFactory.java index 7bd3a467c..293739feb 100644 --- a/httpclient/src/main/java/org/apache/http/impl/cookie/BestMatchSpecFactory.java +++ b/httpclient/src/main/java/org/apache/http/impl/cookie/BestMatchSpecFactory.java @@ -38,8 +38,9 @@ import org.apache.http.params.HttpParams; import org.apache.http.protocol.HttpContext; /** - * {@link CookieSpecProvider} implementation that creates and initializes - * {@link BestMatchSpec} instances. + * {@link org.apache.http.cookie.CookieSpecProvider} implementation that provides an instance of + * {@link org.apache.http.impl.cookie.BestMatchSpec}. The instance returned by this factory can + * be shared by multiple threads. * * @since 4.0 */ @@ -47,13 +48,11 @@ import org.apache.http.protocol.HttpContext; @SuppressWarnings("deprecation") public class BestMatchSpecFactory implements CookieSpecFactory, CookieSpecProvider { - private final String[] datepatterns; - private final boolean oneHeader; + private final CookieSpec cookieSpec; public BestMatchSpecFactory(final String[] datepatterns, final boolean oneHeader) { super(); - this.datepatterns = datepatterns; - this.oneHeader = oneHeader; + this.cookieSpec = new BestMatchSpec(datepatterns, oneHeader);; } public BestMatchSpecFactory() { @@ -82,7 +81,7 @@ public class BestMatchSpecFactory implements CookieSpecFactory, CookieSpecProvid @Override public CookieSpec create(final HttpContext context) { - return new BestMatchSpec(this.datepatterns, this.oneHeader); + return this.cookieSpec; } } diff --git a/httpclient/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpecFactory.java b/httpclient/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpecFactory.java index 809dc5984..fb3e0fe7c 100644 --- a/httpclient/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpecFactory.java +++ b/httpclient/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpecFactory.java @@ -38,8 +38,9 @@ import org.apache.http.params.HttpParams; import org.apache.http.protocol.HttpContext; /** - * {@link CookieSpecProvider} implementation that creates and initializes - * {@link BrowserCompatSpec} instances. + * {@link org.apache.http.cookie.CookieSpecProvider} implementation that provides an instance of + * {@link org.apache.http.impl.cookie.BrowserCompatSpec}. The instance returned by this factory + * can be shared by multiple threads. * * @since 4.0 */ @@ -52,13 +53,13 @@ public class BrowserCompatSpecFactory implements CookieSpecFactory, CookieSpecPr SECURITYLEVEL_IE_MEDIUM } - private final String[] datepatterns; private final SecurityLevel securityLevel; + private final CookieSpec cookieSpec; public BrowserCompatSpecFactory(final String[] datepatterns, final SecurityLevel securityLevel) { super(); - this.datepatterns = datepatterns; this.securityLevel = securityLevel; + this.cookieSpec = new BrowserCompatSpec(datepatterns, securityLevel); } public BrowserCompatSpecFactory(final String[] datepatterns) { @@ -88,7 +89,7 @@ public class BrowserCompatSpecFactory implements CookieSpecFactory, CookieSpecPr @Override public CookieSpec create(final HttpContext context) { - return new BrowserCompatSpec(this.datepatterns); + return this.cookieSpec; } } diff --git a/httpclient/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpecFactory.java b/httpclient/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpecFactory.java index 4b516c594..a5f4a0c50 100644 --- a/httpclient/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpecFactory.java +++ b/httpclient/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpecFactory.java @@ -38,8 +38,9 @@ import org.apache.http.params.HttpParams; import org.apache.http.protocol.HttpContext; /** - * {@link CookieSpecProvider} implementation that creates and initializes - * {@link NetscapeDraftSpec} instances. + * {@link org.apache.http.cookie.CookieSpecProvider} implementation that provides an instance of + * {@link org.apache.http.impl.cookie.NetscapeDraftSpec}. The instance returned by this factory + * can be shared by multiple threads. * * @since 4.0 */ @@ -47,11 +48,11 @@ import org.apache.http.protocol.HttpContext; @SuppressWarnings("deprecation") public class NetscapeDraftSpecFactory implements CookieSpecFactory, CookieSpecProvider { - private final String[] datepatterns; + private final CookieSpec cookieSpec; public NetscapeDraftSpecFactory(final String[] datepatterns) { super(); - this.datepatterns = datepatterns; + this.cookieSpec = new NetscapeDraftSpec(datepatterns); } public NetscapeDraftSpecFactory() { @@ -77,11 +78,7 @@ public class NetscapeDraftSpecFactory implements CookieSpecFactory, CookieSpecPr @Override public CookieSpec create(final HttpContext context) { - - - - - return new NetscapeDraftSpec(this.datepatterns); + return this.cookieSpec; } } diff --git a/httpclient/src/main/java/org/apache/http/impl/cookie/RFC2109SpecFactory.java b/httpclient/src/main/java/org/apache/http/impl/cookie/RFC2109SpecFactory.java index 1198e11b3..511911cf6 100644 --- a/httpclient/src/main/java/org/apache/http/impl/cookie/RFC2109SpecFactory.java +++ b/httpclient/src/main/java/org/apache/http/impl/cookie/RFC2109SpecFactory.java @@ -38,8 +38,9 @@ import org.apache.http.params.HttpParams; import org.apache.http.protocol.HttpContext; /** - * {@link CookieSpecProvider} implementation that creates and initializes - * {@link RFC2109Spec} instances. + * {@link org.apache.http.cookie.CookieSpecProvider} implementation that provides an instance of + * {@link org.apache.http.impl.cookie.RFC2109Spec}. The instance returned by this factory + * can be shared by multiple threads. * * @since 4.0 */ @@ -47,13 +48,11 @@ import org.apache.http.protocol.HttpContext; @SuppressWarnings("deprecation") public class RFC2109SpecFactory implements CookieSpecFactory, CookieSpecProvider { - private final String[] datepatterns; - private final boolean oneHeader; + private final CookieSpec cookieSpec; public RFC2109SpecFactory(final String[] datepatterns, final boolean oneHeader) { super(); - this.datepatterns = datepatterns; - this.oneHeader = oneHeader; + this.cookieSpec = new RFC2109Spec(datepatterns, oneHeader); } public RFC2109SpecFactory() { @@ -82,7 +81,7 @@ public class RFC2109SpecFactory implements CookieSpecFactory, CookieSpecProvider @Override public CookieSpec create(final HttpContext context) { - return new RFC2109Spec(this.datepatterns, this.oneHeader); + return this.cookieSpec; } } diff --git a/httpclient/src/main/java/org/apache/http/impl/cookie/RFC2965SpecFactory.java b/httpclient/src/main/java/org/apache/http/impl/cookie/RFC2965SpecFactory.java index f3b93c952..80f85d121 100644 --- a/httpclient/src/main/java/org/apache/http/impl/cookie/RFC2965SpecFactory.java +++ b/httpclient/src/main/java/org/apache/http/impl/cookie/RFC2965SpecFactory.java @@ -38,8 +38,9 @@ import org.apache.http.params.HttpParams; import org.apache.http.protocol.HttpContext; /** - * {@link CookieSpecProvider} implementation that creates and initializes - * {@link RFC2965Spec} instances. + * {@link org.apache.http.cookie.CookieSpecProvider} implementation that provides an instance of + * {@link org.apache.http.impl.cookie.RFC2965Spec}. The instance returned by this factory can + * be shared by multiple threads. * * @since 4.0 */ @@ -47,13 +48,11 @@ import org.apache.http.protocol.HttpContext; @SuppressWarnings("deprecation") public class RFC2965SpecFactory implements CookieSpecFactory, CookieSpecProvider { - private final String[] datepatterns; - private final boolean oneHeader; + private final CookieSpec cookieSpec; public RFC2965SpecFactory(final String[] datepatterns, final boolean oneHeader) { super(); - this.datepatterns = datepatterns; - this.oneHeader = oneHeader; + this.cookieSpec = new RFC2965Spec(datepatterns, oneHeader); } public RFC2965SpecFactory() { @@ -82,7 +81,7 @@ public class RFC2965SpecFactory implements CookieSpecFactory, CookieSpecProvider @Override public CookieSpec create(final HttpContext context) { - return new RFC2965Spec(this.datepatterns, this.oneHeader); + return this.cookieSpec; } }