Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routing 3 #4236

Merged
merged 3 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
<artifactId>helidon-webserver</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver-http2</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver-jersey</artifactId>
Expand Down Expand Up @@ -70,7 +75,7 @@
</dependency>
<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver-tyrus</artifactId>
<artifactId>helidon-webserver-websocket</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion examples/messaging/jms-websocket-se/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</dependency>
<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver-tyrus</artifactId>
<artifactId>helidon-webserver-websocket</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/*
* Copyright (c) 2020, 2021 Oracle and/or its affiliates.
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,10 +22,9 @@
import java.util.logging.LogManager;

import io.helidon.config.Config;
import io.helidon.webserver.Routing;
import io.helidon.webserver.WebServer;
import io.helidon.webserver.staticcontent.StaticContentSupport;
import io.helidon.webserver.tyrus.TyrusSupport;
import io.helidon.webserver.websocket.WebSocketRouting;

import jakarta.websocket.server.ServerEndpointConfig;

Expand Down Expand Up @@ -65,7 +64,20 @@ static WebServer startServer() throws IOException {

SendingService sendingService = new SendingService(config);

WebServer server = WebServer.builder(createRouting(sendingService))
WebServer server = WebServer.builder()
.routing(r -> r
// register static content support (on "/")
.register(StaticContentSupport.builder("/WEB")
.welcomeFileName("index.html")
.build())
// register rest endpoint for sending to Jms
.register("/rest/messages", sendingService))
.addRouting(WebSocketRouting.builder()
danielkec marked this conversation as resolved.
Show resolved Hide resolved
// register WebSocket endpoint to push messages coming from Jms to client
.endpoint("/ws", ServerEndpointConfig.Builder.create(
WebSocketEndpoint.class, "/messages")
.build())
.build())
.config(config.get("server"))
.build();

Expand All @@ -90,28 +102,6 @@ static WebServer startServer() throws IOException {
return server;
}

/**
* Creates new {@link Routing}.
*
* @param sendingService the service
*/
private static Routing createRouting(SendingService sendingService) {

return Routing.builder()
// register static content support (on "/")
.register(StaticContentSupport.builder("/WEB").welcomeFileName("index.html"))
// register rest endpoint for sending to Jms
.register("/rest/messages", sendingService)
// register WebSocket endpoint to push messages coming from Jms to client
.register("/ws",
TyrusSupport.builder().register(
ServerEndpointConfig.Builder.create(
WebSocketEndpoint.class, "/messages")
.build())
.build())
.build();
}

/**
* Configure logging from logging.properties file.
*/
Expand Down
2 changes: 1 addition & 1 deletion examples/messaging/kafka-websocket-se/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</dependency>
<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver-tyrus</artifactId>
<artifactId>helidon-webserver-websocket</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021 Oracle and/or its affiliates.
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,10 +18,9 @@

import io.helidon.common.LogConfig;
import io.helidon.config.Config;
import io.helidon.webserver.Routing;
import io.helidon.webserver.WebServer;
import io.helidon.webserver.staticcontent.StaticContentSupport;
import io.helidon.webserver.tyrus.TyrusSupport;
import io.helidon.webserver.websocket.WebSocketRouting;

import jakarta.websocket.server.ServerEndpointConfig;

Expand Down Expand Up @@ -59,7 +58,21 @@ static WebServer startServer() {

SendingService sendingService = new SendingService(config);

WebServer server = WebServer.builder(createRouting(sendingService))
WebServer server = WebServer.builder()
.routing(r -> r
// register static content support (on "/")
.register(StaticContentSupport.builder("/WEB")
.welcomeFileName("index.html")
.build())
// register rest endpoint for sending to Kafka
.register("/rest/messages", sendingService)
)
// register WebSocket endpoint to push messages coming from Kafka to client
.addRouting(WebSocketRouting.builder()
.endpoint("/ws", ServerEndpointConfig.Builder.create(
WebSocketEndpoint.class, "/messages")
.build())
.build())
.config(config.get("server"))
.build();

Expand All @@ -83,27 +96,4 @@ static WebServer startServer() {
// Server threads are not daemon. No need to block. Just react.
return server;
}

/**
* Creates new {@link Routing}.
*
* @param sendingService service to configure
* @return routing configured with JSON support, a health check, and a service
*/
private static Routing createRouting(SendingService sendingService) {

return Routing.builder()
// register static content support (on "/")
.register(StaticContentSupport.builder("/WEB").welcomeFileName("index.html"))
// register rest endpoint for sending to Kafka
.register("/rest/messages", sendingService)
// register WebSocket endpoint to push messages coming from Kafka to client
.register("/ws",
TyrusSupport.builder().register(
ServerEndpointConfig.Builder.create(
WebSocketEndpoint.class, "/messages")
.build())
.build())
.build();
}
}
2 changes: 1 addition & 1 deletion examples/webserver/websocket/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</dependency>
<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver-tyrus</artifactId>
<artifactId>helidon-webserver-websocket</artifactId>
</dependency>
<dependency>
<groupId>jakarta.inject</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021 Oracle and/or its affiliates.
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,10 +19,9 @@
import java.util.Collections;
import java.util.List;

import io.helidon.webserver.Routing;
import io.helidon.webserver.WebServer;
import io.helidon.webserver.staticcontent.StaticContentSupport;
import io.helidon.webserver.tyrus.TyrusSupport;
import io.helidon.webserver.websocket.WebSocketRouting;

import jakarta.websocket.Encoder;
import jakarta.websocket.server.ServerEndpointConfig;
Expand All @@ -37,34 +36,29 @@ public class Main {
private Main() {
}

/**
* Creates new {@link Routing}.
*
* @return the new instance
*/
static Routing createRouting() {
static WebServer startWebServer() {
List<Class<? extends Encoder>> encoders = Collections.singletonList(UppercaseEncoder.class);

return Routing.builder()
.register("/rest", new MessageQueueService())
.register("/websocket",
TyrusSupport.builder().register(
ServerEndpointConfig.Builder.create(MessageBoardEndpoint.class, "/board")
.encoders(encoders).build())
.build())
.register("/web", StaticContentSupport.builder("/WEB").build())
.build();
}

static WebServer startWebServer() {
// Wait for webserver to start before returning
WebServer server = WebServer.builder(createRouting())
WebServer server = WebServer.builder()
.port(8080)
.routing(r -> r
.register("/web", StaticContentSupport.builder("/WEB")
.welcomeFileName("index.html")
.build())
.register("/rest", new MessageQueueService())
)
.addRouting(WebSocketRouting.builder()
.endpoint("/websocket", ServerEndpointConfig.Builder.create(MessageBoardEndpoint.class, "/board")
.encoders(encoders)
.build())
.build()
)
.build()
.start()
.await();

System.out.println("WEB server is up! http://localhost:" + server.port());
System.out.println("WEB server is up! http://localhost:" + server.port() + "/web");

return server;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021 Oracle and/or its affiliates.
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,9 +44,7 @@ class GraphQlSupportTest {
void testHelloWorld() {
WebServer server = WebServer.builder()
.host("localhost")
.routing(Routing.builder()
.register(GraphQlSupport.create(buildSchema()))
.build())
.routing(r -> r.register(GraphQlSupport.create(buildSchema())))
.build()
.start()
.await(10, TimeUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ public class ContextTest {
static void beforeAll() {
server = WebServer.builder()
.host("localhost")
.routing(Routing.builder()
.put((req, res) -> res.send("I'm Frank!"))
.build())
.routing(r -> r.put((req, res) -> res.send("I'm Frank!")))
.build()
.start()
.await(TIME_OUT);
Expand Down
6 changes: 1 addition & 5 deletions lra/coordinator/server/src/test/java/CoordinatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ static void beforeAll() {
.addNamedRouting(COORDINATOR_ROUTING_NAME, Routing.builder()
.register("/lra-coordinator", coordinatorService)
.build())
.routing(Routing.builder()
.register(CONTEXT_PATH, rules -> rules.put((req, res) -> {
res.send();
}))
.build())
.routing(r -> r.register(CONTEXT_PATH, rules -> rules.put((req, res) -> res.send())))
.build();
server.start().await();
serverUrl = "http://localhost:" + server.port();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates.
* Copyright (c) 2021, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,7 +48,7 @@ void testEndpoint() throws ExecutionException, InterruptedException {
webServer = WebServer.builder()
.host("localhost")
.port(0)
.routing(routing)
.addRouting(routing)
.build()
.start()
.toCompletableFuture()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private void startServer(@Observes @Priority(PLATFORM_AFTER + 100) @Initialized(
registerJaxRsApplications(beanManager);

// start the webserver
serverBuilder.routing(routingBuilder.build());
serverBuilder.addRouting(routingBuilder.build());

namedRoutings.forEach(serverBuilder::addNamedRouting);
webserver = serverBuilder.build();
Expand Down
3 changes: 1 addition & 2 deletions microprofile/websocket/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</dependency>
<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver-tyrus</artifactId>
<artifactId>helidon-webserver-websocket</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.common</groupId>
Expand All @@ -64,7 +64,6 @@
<dependency>
<groupId>org.glassfish.tyrus</groupId>
<artifactId>tyrus-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.tyrus</groupId>
Expand Down

This file was deleted.

Loading