Merge pull request #19788 from ktoso/wip-connect-to-ktoso
-htp #19577 replace overloads of bind with HttpConnect
This commit is contained in:
commit
3c94805666
16 changed files with 190 additions and 206 deletions
|
|
@ -6,6 +6,8 @@ package docs.http.javadsl.server;
|
|||
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.dispatch.OnFailure;
|
||||
import akka.http.javadsl.ConnectHttp;
|
||||
import akka.http.javadsl.Http;
|
||||
import akka.http.javadsl.IncomingConnection;
|
||||
import akka.http.javadsl.ServerBinding;
|
||||
|
|
@ -38,7 +40,7 @@ public class HttpServerExampleDocTest {
|
|||
Materializer materializer = ActorMaterializer.create(system);
|
||||
|
||||
Source<IncomingConnection, CompletionStage<ServerBinding>> serverSource =
|
||||
Http.get(system).bind("localhost", 8080, materializer);
|
||||
Http.get(system).bind(ConnectHttp.toHost("localhost", 8080), materializer);
|
||||
|
||||
CompletionStage<ServerBinding> serverBindingFuture =
|
||||
serverSource.to(Sink.foreach(connection -> {
|
||||
|
|
@ -56,7 +58,7 @@ public class HttpServerExampleDocTest {
|
|||
Materializer materializer = ActorMaterializer.create(system);
|
||||
|
||||
Source<IncomingConnection, CompletionStage<ServerBinding>> serverSource =
|
||||
Http.get(system).bind("localhost", 80, materializer);
|
||||
Http.get(system).bind(ConnectHttp.toHost("localhost", 80), materializer);
|
||||
|
||||
CompletionStage<ServerBinding> serverBindingFuture =
|
||||
serverSource.to(Sink.foreach(connection -> {
|
||||
|
|
@ -78,7 +80,7 @@ public class HttpServerExampleDocTest {
|
|||
Materializer materializer = ActorMaterializer.create(system);
|
||||
|
||||
Source<IncomingConnection, CompletionStage<ServerBinding>> serverSource =
|
||||
Http.get(system).bind("localhost", 8080, materializer);
|
||||
Http.get(system).bind(ConnectHttp.toHost("localhost", 8080), materializer);
|
||||
|
||||
Flow<IncomingConnection, IncomingConnection, NotUsed> failureDetection =
|
||||
Flow.of(IncomingConnection.class).watchTermination((notUsed, termination) -> {
|
||||
|
|
@ -108,7 +110,7 @@ public class HttpServerExampleDocTest {
|
|||
Materializer materializer = ActorMaterializer.create(system);
|
||||
|
||||
Source<IncomingConnection, CompletionStage<ServerBinding>> serverSource =
|
||||
Http.get(system).bind("localhost", 8080, materializer);
|
||||
Http.get(system).bind(ConnectHttp.toHost("localhost", 8080), materializer);
|
||||
|
||||
Flow<HttpRequest, HttpRequest, NotUsed> failureDetection =
|
||||
Flow.of(HttpRequest.class)
|
||||
|
|
@ -151,7 +153,7 @@ public class HttpServerExampleDocTest {
|
|||
final Materializer materializer = ActorMaterializer.create(system);
|
||||
|
||||
Source<IncomingConnection, CompletionStage<ServerBinding>> serverSource =
|
||||
Http.get(system).bind("localhost", 8080, materializer);
|
||||
Http.get(system).bind(ConnectHttp.toHost("localhost", 8080), materializer);
|
||||
|
||||
//#request-handler
|
||||
final Function<HttpRequest, HttpResponse> requestHandler =
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import java.util.concurrent.CompletionStage;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.http.javadsl.ConnectHttp;
|
||||
import scala.concurrent.Await;
|
||||
import scala.concurrent.Future;
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
|
|
@ -57,7 +58,7 @@ public class WebSocketCoreExample {
|
|||
public HttpResponse apply(HttpRequest request) throws Exception {
|
||||
return handleRequest(request);
|
||||
}
|
||||
}, "localhost", 8080, materializer);
|
||||
}, ConnectHttp.toHost("localhost", 8080), materializer);
|
||||
|
||||
// will throw if binding fails
|
||||
serverBindingFuture.toCompletableFuture().get(1, TimeUnit.SECONDS);
|
||||
|
|
|
|||
|
|
@ -169,4 +169,23 @@ Previously we had a mix of methods and classes called ``websocket`` or ``Websock
|
|||
how the word is spelled in the spec and some other places of Akka HTTP.
|
||||
|
||||
Methods and classes using the word WebSocket now consistently use it as ``WebSocket``, so updating is as simple as
|
||||
find-and-replacing the lower-case ``s`` to an upper-case ``S`` wherever the word WebSocket appeared.
|
||||
find-and-replacing the lower-case ``s`` to an upper-case ``S`` wherever the word WebSocket appeared.
|
||||
|
||||
Java DSL for Http binding and connections changed
|
||||
-------------------------------------------------
|
||||
|
||||
In order to minimise the number of needed overloads for each method defined on the ``Http`` extension
|
||||
a new mini-DSL has been introduced for connecting to hosts given a hostname, port and optional ``ConnectionContext``.
|
||||
|
||||
The availability of the connection context (if it's set to ``HttpsConnectionContext``) makes the server be bound
|
||||
as an HTTPS server, and for outgoing connections those settings are used instead of the default ones if provided.
|
||||
|
||||
Was::
|
||||
|
||||
http.cachedHostConnectionPool(toHost("akka.io"), materializer());
|
||||
http.cachedHostConnectionPool("akka.io", 80, httpsConnectionContext, materializer()); // does not work anymore
|
||||
|
||||
Replace with::
|
||||
|
||||
http.cachedHostConnectionPool(toHostHttps("akka.io", 8081), materializer());
|
||||
http.cachedHostConnectionPool(toHostHttps("akka.io", 8081).withCustomHttpsContext(httpsContext), materializer());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue