http-client-branch: CookieManager -> CookieHandler http-client-branch
authorchegar
Tue, 14 Nov 2017 15:14:51 +0000
branchhttp-client-branch
changeset 55812 0a3a307f3502
parent 55811 deecd5ea67cf
child 55813 1b61574881e8
http-client-branch: CookieManager -> CookieHandler
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/CookieFilter.java
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpClient.java
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpClientBuilderImpl.java
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpClientFacade.java
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpClientImpl.java
test/jdk/java/net/httpclient/HttpClientBuilderTest.java
test/jdk/java/net/httpclient/whitebox/jdk.incubator.httpclient/jdk/incubator/http/ConnectionPoolTest.java
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/CookieFilter.java	Tue Nov 14 14:58:39 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/CookieFilter.java	Tue Nov 14 15:14:51 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,7 @@
 package jdk.incubator.http;
 
 import java.io.IOException;
-import java.net.CookieManager;
+import java.net.CookieHandler;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
@@ -41,11 +41,11 @@
     @Override
     public void request(HttpRequestImpl r, MultiExchange<?,?> e) throws IOException {
         HttpClientImpl client = e.client();
-        Optional<CookieManager> cookieManOpt = client.cookieManager();
-        if (cookieManOpt.isPresent()) {
-            CookieManager cookieMan = cookieManOpt.get();
+        Optional<CookieHandler> cookieHandlerOpt = client.cookieHandler();
+        if (cookieHandlerOpt.isPresent()) {
+            CookieHandler cookieHandler = cookieHandlerOpt.get();
             Map<String,List<String>> userheaders = r.getUserHeaders().map();
-            Map<String,List<String>> cookies = cookieMan.get(r.uri(), userheaders);
+            Map<String,List<String>> cookies = cookieHandler.get(r.uri(), userheaders);
 
             // add the returned cookies
             HttpHeadersImpl systemHeaders = r.getSystemHeaders();
@@ -74,9 +74,9 @@
         HttpRequestImpl request = r.request();
         Exchange<?> e = r.exchange;
         Log.logTrace("Response: processing cookies for {0}", request.uri());
-        Optional<CookieManager> cookieManOpt = e.client().cookieManager();
-        if (cookieManOpt.isPresent()) {
-            CookieManager cookieMan = cookieManOpt.get();
+        Optional<CookieHandler> cookieHandlerOpt = e.client().cookieHandler();
+        if (cookieHandlerOpt.isPresent()) {
+            CookieHandler cookieMan = cookieHandlerOpt.get();
             Log.logTrace("Response: parsing cookies from {0}", hdrs.map());
             cookieMan.put(request.uri(), hdrs.map());
         } else {
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpClient.java	Tue Nov 14 14:58:39 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpClient.java	Tue Nov 14 15:14:51 2017 +0000
@@ -27,7 +27,7 @@
 
 import java.io.IOException;
 import java.net.Authenticator;
-import java.net.CookieManager;
+import java.net.CookieHandler;
 import java.net.InetSocketAddress;
 import java.net.ProxySelector;
 import java.net.URI;
@@ -103,12 +103,12 @@
         protected Builder() {}
 
         /**
-         * Sets a cookie manager.
+         * Sets a cookie handler.
          *
-         * @param cookieManager the cookie manager
+         * @param cookieHandler the cookie handler
          * @return this builder
          */
-        public abstract Builder cookieManager(CookieManager cookieManager);
+        public abstract Builder cookieHandler(CookieHandler cookieHandler);
 
         /**
          * Sets an {@code SSLContext}.
@@ -238,13 +238,13 @@
 
 
     /**
-     * Returns an {@code Optional} containing this client's {@link
-     * CookieManager}. If no {@code CookieManager} was set in this client's
+     * Returns an {@code Optional} containing this client's {@linkplain
+     * CookieHandler}. If no {@code CookieHandler} was set in this client's
      * builder, then the {@code Optional} is empty.
      *
-     * @return an {@code Optional} containing this client's {@code CookieManager}
+     * @return an {@code Optional} containing this client's {@code CookieHandler}
      */
-    public abstract Optional<CookieManager> cookieManager();
+    public abstract Optional<CookieHandler> cookieHandler();
 
     /**
      * Returns the follow redirects policy for this client. The default value
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpClientBuilderImpl.java	Tue Nov 14 14:58:39 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpClientBuilderImpl.java	Tue Nov 14 15:14:51 2017 +0000
@@ -26,7 +26,7 @@
 package jdk.incubator.http;
 
 import java.net.Authenticator;
-import java.net.CookieManager;
+import java.net.CookieHandler;
 import java.net.NetPermission;
 import java.net.ProxySelector;
 import java.util.concurrent.Executor;
@@ -37,7 +37,7 @@
 
 class HttpClientBuilderImpl extends HttpClient.Builder {
 
-    CookieManager cookieManager;
+    CookieHandler cookieHandler;
     HttpClient.Redirect followRedirects;
     ProxySelector proxy;
     Authenticator authenticator;
@@ -49,9 +49,9 @@
     int priority = -1;
 
     @Override
-    public HttpClientBuilderImpl cookieManager(CookieManager cookieManager) {
-        requireNonNull(cookieManager);
-        this.cookieManager = cookieManager;
+    public HttpClientBuilderImpl cookieHandler(CookieHandler cookieHandler) {
+        requireNonNull(cookieHandler);
+        this.cookieHandler = cookieHandler;
         return this;
     }
 
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpClientFacade.java	Tue Nov 14 14:58:39 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpClientFacade.java	Tue Nov 14 15:14:51 2017 +0000
@@ -28,7 +28,7 @@
 import java.io.IOException;
 import java.lang.ref.Reference;
 import java.net.Authenticator;
-import java.net.CookieManager;
+import java.net.CookieHandler;
 import java.net.ProxySelector;
 import java.net.URI;
 import java.util.Optional;
@@ -53,8 +53,8 @@
     }
 
     @Override
-    public Optional<CookieManager> cookieManager() {
-        return impl.cookieManager();
+    public Optional<CookieHandler> cookieHandler() {
+        return impl.cookieHandler();
     }
 
     @Override
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpClientImpl.java	Tue Nov 14 14:58:39 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpClientImpl.java	Tue Nov 14 15:14:51 2017 +0000
@@ -31,7 +31,7 @@
 import java.lang.System.Logger.Level;
 import java.lang.ref.WeakReference;
 import java.net.Authenticator;
-import java.net.CookieManager;
+import java.net.CookieHandler;
 import java.net.NetPermission;
 import java.net.ProxySelector;
 import java.net.URI;
@@ -111,7 +111,7 @@
         }
     }
 
-    private final CookieManager cookieManager;
+    private final CookieHandler cookieHandler;
     private final Redirect followRedirects;
     private final ProxySelector proxySelector;
     private final Authenticator authenticator;
@@ -227,7 +227,7 @@
         facadeRef = new WeakReference<>(facadeFactory.createFacade(this));
         client2 = new Http2ClientImpl(this);
         executor = ex;
-        cookieManager = builder.cookieManager;
+        cookieHandler = builder.cookieHandler;
         followRedirects = builder.followRedirects == null ?
                 Redirect.NEVER : builder.followRedirects;
         this.proxySelector = builder.proxy;
@@ -899,8 +899,8 @@
 
 
     @Override
-    public Optional<CookieManager> cookieManager() {
-        return Optional.ofNullable(cookieManager);
+    public Optional<CookieHandler> cookieHandler() {
+        return Optional.ofNullable(cookieHandler);
     }
 
     @Override
@@ -944,7 +944,7 @@
     private void initFilters() {
         addFilter(AuthenticationFilter.class);
         addFilter(RedirectFilter.class);
-        if (this.cookieManager != null) {
+        if (this.cookieHandler != null) {
             addFilter(CookieFilter.class);
         }
     }
--- a/test/jdk/java/net/httpclient/HttpClientBuilderTest.java	Tue Nov 14 14:58:39 2017 +0000
+++ b/test/jdk/java/net/httpclient/HttpClientBuilderTest.java	Tue Nov 14 15:14:51 2017 +0000
@@ -23,6 +23,7 @@
 
 import java.lang.reflect.Method;
 import java.net.Authenticator;
+import java.net.CookieHandler;
 import java.net.CookieManager;
 import java.net.InetSocketAddress;
 import java.net.ProxySelector;
@@ -55,7 +56,7 @@
         for (HttpClient client : clients) {
             // Empty optionals and defaults
             assertFalse(client.authenticator().isPresent());
-            assertFalse(client.cookieManager().isPresent());
+            assertFalse(client.cookieHandler().isPresent());
             assertFalse(client.executor().isPresent());
             assertFalse(client.proxy().isPresent());
             assertTrue(client.sslParameters() != null);
@@ -69,7 +70,7 @@
     public void testNull() throws Exception {
         HttpClient.Builder builder = HttpClient.newBuilder();
         assertThrows(NullPointerException.class, () -> builder.authenticator(null));
-        assertThrows(NullPointerException.class, () -> builder.cookieManager(null));
+        assertThrows(NullPointerException.class, () -> builder.cookieHandler(null));
         assertThrows(NullPointerException.class, () -> builder.executor(null));
         assertThrows(NullPointerException.class, () -> builder.proxy(null));
         assertThrows(NullPointerException.class, () -> builder.sslParameters(null));
@@ -96,18 +97,18 @@
     }
 
     @Test
-    public void testCookieManager() {
+    public void testCookieHandler() {
         HttpClient.Builder builder = HttpClient.newBuilder();
-        CookieManager a = new CookieManager();
-        builder.cookieManager(a);
-        assertTrue(builder.build().cookieManager().get() == a);
-        CookieManager b = new CookieManager();
-        builder.cookieManager(b);
-        assertTrue(builder.build().cookieManager().get() == b);
-        assertThrows(NullPointerException.class, () -> builder.cookieManager(null));
+        CookieHandler a = new CookieManager();
+        builder.cookieHandler(a);
+        assertTrue(builder.build().cookieHandler().get() == a);
+        CookieHandler b = new CookieManager();
+        builder.cookieHandler(b);
+        assertTrue(builder.build().cookieHandler().get() == b);
+        assertThrows(NullPointerException.class, () -> builder.cookieHandler(null));
         CookieManager c = new CookieManager();
-        builder.cookieManager(c);
-        assertTrue(builder.build().cookieManager().get() == c);
+        builder.cookieHandler(c);
+        assertTrue(builder.build().cookieHandler().get() == c);
     }
 
     static class TestExecutor implements Executor {
--- a/test/jdk/java/net/httpclient/whitebox/jdk.incubator.httpclient/jdk/incubator/http/ConnectionPoolTest.java	Tue Nov 14 14:58:39 2017 +0000
+++ b/test/jdk/java/net/httpclient/whitebox/jdk.incubator.httpclient/jdk/incubator/http/ConnectionPoolTest.java	Tue Nov 14 15:14:51 2017 +0000
@@ -26,7 +26,7 @@
 import java.io.IOException;
 import java.lang.management.ManagementFactory;
 import java.net.Authenticator;
-import java.net.CookieManager;
+import java.net.CookieHandler;
 import java.net.InetSocketAddress;
 import java.net.ProxySelector;
 import java.nio.ByteBuffer;
@@ -219,7 +219,7 @@
             this.pool = pool;
         }
         final ConnectionPool pool;
-        @Override public Optional<CookieManager> cookieManager() {return error();}
+        @Override public Optional<CookieHandler> cookieHandler() {return error();}
         @Override public HttpClient.Redirect followRedirects() {return error();}
         @Override public Optional<ProxySelector> proxy() {return error();}
         @Override public SSLContext sslContext() {return error();}