You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2019/02/18 18:30:50 UTC

[httpcomponents-core] branch master updated: Fixed broken generics in server bootstrap classes

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 40cc287  Fixed broken generics in server bootstrap classes
     new a493112  Merge pull request #109 from ok2c/server-bootscrap-fixes
40cc287 is described below

commit 40cc2878f8c023fa600575ee1749f04b228441bc
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sat Feb 16 15:25:04 2019 +0100

    Fixed broken generics in server bootstrap classes
---
 .../impl/nio/bootstrap/H2ServerBootstrap.java      | 11 ++--
 .../testing/nio/Http1ServerAndRequesterTest.java   |  2 +-
 .../http/impl/bootstrap/AsyncServerBootstrap.java  | 11 ++--
 .../core5/http/impl/bootstrap/ServerBootstrap.java | 12 ++---
 .../TestAsyncServerBootstrapLookupRegistry.java    | 61 ----------------------
 5 files changed, 19 insertions(+), 78 deletions(-)

diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2ServerBootstrap.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2ServerBootstrap.java
index e446895..1a51590 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2ServerBootstrap.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2ServerBootstrap.java
@@ -84,7 +84,7 @@ public class H2ServerBootstrap {
     private final List<HandlerEntry<Supplier<AsyncServerExchangeHandler>>> handlerList;
     private final List<FilterEntry<AsyncFilterHandler>> filters;
     private String canonicalHostName;
-    private LookupRegistry<AsyncServerExchangeHandler> lookupRegistry;
+    private LookupRegistry<Supplier<AsyncServerExchangeHandler>> lookupRegistry;
     private IOReactorConfig ioReactorConfig;
     private HttpProcessor httpProcessor;
     private CharCodingConfig charCodingConfig;
@@ -216,7 +216,7 @@ public class H2ServerBootstrap {
      * @return this
      * @since 5.0
      */
-    public final H2ServerBootstrap setLookupRegistry(final LookupRegistry<AsyncServerExchangeHandler> lookupRegistry) {
+    public final H2ServerBootstrap setLookupRegistry(final LookupRegistry<Supplier<AsyncServerExchangeHandler>> lookupRegistry) {
         this.lookupRegistry = lookupRegistry;
         return this;
     }
@@ -350,11 +350,12 @@ public class H2ServerBootstrap {
     public HttpAsyncServer create() {
         final RequestHandlerRegistry<Supplier<AsyncServerExchangeHandler>> registry = new RequestHandlerRegistry<>(
                 canonicalHostName != null ? canonicalHostName : InetAddressUtils.getCanonicalLocalHostName(),
-                new Supplier() {
+                new Supplier<LookupRegistry<Supplier<AsyncServerExchangeHandler>>>() {
 
                     @Override
-                    public LookupRegistry get() {
-                        return lookupRegistry != null ? lookupRegistry : UriPatternType.newMatcher(UriPatternType.URI_PATTERN);
+                    public LookupRegistry<Supplier<AsyncServerExchangeHandler>> get() {
+                        return lookupRegistry != null ? lookupRegistry :
+                                UriPatternType.<Supplier<AsyncServerExchangeHandler>>newMatcher(UriPatternType.URI_PATTERN);
                     }
 
                 });
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1ServerAndRequesterTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1ServerAndRequesterTest.java
index 04c3496..98a9e87 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1ServerAndRequesterTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1ServerAndRequesterTest.java
@@ -114,7 +114,7 @@ public class Http1ServerAndRequesterTest {
         protected void before() throws Throwable {
             log.debug("Starting up test server");
             server = AsyncServerBootstrap.bootstrap()
-                    .setLookupRegistry(new UriPatternMatcher<AsyncServerExchangeHandler>()) // same as the default
+                    .setLookupRegistry(new UriPatternMatcher<Supplier<AsyncServerExchangeHandler>>())
                     .setIOReactorConfig(
                             IOReactorConfig.custom()
                                     .setSoTimeout(TIMEOUT)
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java
index 0115961..2efe675 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java
@@ -77,7 +77,7 @@ public class AsyncServerBootstrap {
     private final List<HandlerEntry<Supplier<AsyncServerExchangeHandler>>> handlerList;
     private final List<FilterEntry<AsyncFilterHandler>> filters;
     private String canonicalHostName;
-    private LookupRegistry<AsyncServerExchangeHandler> lookupRegistry;
+    private LookupRegistry<Supplier<AsyncServerExchangeHandler>> lookupRegistry;
     private IOReactorConfig ioReactorConfig;
     private H1Config h1Config;
     private CharCodingConfig charCodingConfig;
@@ -184,7 +184,7 @@ public class AsyncServerBootstrap {
      * @return this
      * @since 5.0
      */
-    public final AsyncServerBootstrap setLookupRegistry(final LookupRegistry<AsyncServerExchangeHandler> lookupRegistry) {
+    public final AsyncServerBootstrap setLookupRegistry(final LookupRegistry<Supplier<AsyncServerExchangeHandler>> lookupRegistry) {
         this.lookupRegistry = lookupRegistry;
         return this;
     }
@@ -328,11 +328,12 @@ public class AsyncServerBootstrap {
     public HttpAsyncServer create() {
         final RequestHandlerRegistry<Supplier<AsyncServerExchangeHandler>> registry = new RequestHandlerRegistry<>(
                 canonicalHostName != null ? canonicalHostName : InetAddressUtils.getCanonicalLocalHostName(),
-                new Supplier() {
+                new Supplier<LookupRegistry<Supplier<AsyncServerExchangeHandler>>>() {
 
                     @Override
-                    public LookupRegistry get() {
-                        return lookupRegistry != null ? lookupRegistry : UriPatternType.newMatcher(UriPatternType.URI_PATTERN);
+                    public LookupRegistry<Supplier<AsyncServerExchangeHandler>> get() {
+                        return lookupRegistry != null ? lookupRegistry :
+                                UriPatternType.<Supplier<AsyncServerExchangeHandler>>newMatcher(UriPatternType.URI_PATTERN);
                     }
 
                 });
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ServerBootstrap.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ServerBootstrap.java
index 2af402d..cbb8c54 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ServerBootstrap.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ServerBootstrap.java
@@ -61,7 +61,6 @@ import org.apache.hc.core5.http.io.support.HttpServerExpectationFilter;
 import org.apache.hc.core5.http.io.support.HttpServerFilterChainElement;
 import org.apache.hc.core5.http.io.support.HttpServerFilterChainRequestHandler;
 import org.apache.hc.core5.http.io.support.TerminalServerFilter;
-import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.http.protocol.LookupRegistry;
 import org.apache.hc.core5.http.protocol.RequestHandlerRegistry;
@@ -79,7 +78,7 @@ public class ServerBootstrap {
     private final List<HandlerEntry<HttpRequestHandler>> handlerList;
     private final List<FilterEntry<HttpFilterHandler>> filters;
     private String canonicalHostName;
-    private LookupRegistry<AsyncServerExchangeHandler> lookupRegistry;
+    private LookupRegistry<HttpRequestHandler> lookupRegistry;
     private int listenerPort;
     private InetAddress localAddress;
     private SocketConfig socketConfig;
@@ -184,7 +183,7 @@ public class ServerBootstrap {
      * @return this
      * @since 5.0
      */
-    public final ServerBootstrap setLookupRegistry(final LookupRegistry<AsyncServerExchangeHandler> lookupRegistry) {
+    public final ServerBootstrap setLookupRegistry(final LookupRegistry<HttpRequestHandler> lookupRegistry) {
         this.lookupRegistry = lookupRegistry;
         return this;
     }
@@ -326,11 +325,12 @@ public class ServerBootstrap {
     public HttpServer create() {
         final RequestHandlerRegistry<HttpRequestHandler> handlerRegistry = new RequestHandlerRegistry<>(
                 canonicalHostName != null ? canonicalHostName : InetAddressUtils.getCanonicalLocalHostName(),
-                new Supplier() {
+                new Supplier<LookupRegistry<HttpRequestHandler>>() {
 
                     @Override
-                    public LookupRegistry get() {
-                        return lookupRegistry != null ? lookupRegistry : UriPatternType.newMatcher(UriPatternType.URI_PATTERN);
+                    public LookupRegistry<HttpRequestHandler> get() {
+                        return lookupRegistry != null ? lookupRegistry :
+                                UriPatternType.<HttpRequestHandler>newMatcher(UriPatternType.URI_PATTERN);
                     }
 
                 });
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/bootstrap/TestAsyncServerBootstrapLookupRegistry.java b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/bootstrap/TestAsyncServerBootstrapLookupRegistry.java
deleted file mode 100644
index 96225df..0000000
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/bootstrap/TestAsyncServerBootstrapLookupRegistry.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation.  For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.hc.core5.http.impl.bootstrap;
-
-import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
-import org.apache.hc.core5.http.protocol.LookupRegistry;
-import org.junit.Test;
-
-public class TestAsyncServerBootstrapLookupRegistry {
-
-    @Test
-    public void testCreateNullLookupRegistry() {
-        AsyncServerBootstrap.bootstrap().setLookupRegistry(null).create();
-    }
-
-    @Test
-    public void testCreateCustomLookupRegistry() {
-        AsyncServerBootstrap.bootstrap().setLookupRegistry(new LookupRegistry<AsyncServerExchangeHandler>() {
-
-            @Override
-            public void register(final String pattern, final AsyncServerExchangeHandler obj) {
-                // noop
-            }
-
-            @Override
-            public AsyncServerExchangeHandler lookup(final String value) {
-                // noop
-                return null;
-            }
-
-            @Override
-            public void unregister(final String pattern) {
-                // noop
-            }
-        }).create();
-    }
-}