mirror of
https://github.com/jlengrand/helidon.git
synced 2026-03-10 08:21:17 +00:00
Tyrus support for native-image (#2097)
Signed-off-by: Daniel Kec <daniel.kec@oracle.com>
This commit is contained in:
@@ -150,7 +150,8 @@ final class FeatureCatalog {
|
||||
.name("Websocket")
|
||||
.description("Jakarta Websocket implementation")
|
||||
.path("WebServer", "Websocket")
|
||||
.nativeSupported(false));
|
||||
.nativeSupported(true)
|
||||
.nativeDescription("Server only"));
|
||||
|
||||
/*
|
||||
* MP Modules
|
||||
|
||||
2
dependencies/pom.xml
vendored
2
dependencies/pom.xml
vendored
@@ -51,7 +51,7 @@
|
||||
<version.lib.failsafe>2.3.1</version.lib.failsafe>
|
||||
<version.lib.google-api-client>1.30.5</version.lib.google-api-client>
|
||||
<version.lib.google-error-prone>2.3.3</version.lib.google-error-prone>
|
||||
<version.lib.graalvm>20.0.0</version.lib.graalvm>
|
||||
<version.lib.graalvm>20.1.0</version.lib.graalvm>
|
||||
<version.lib.grpc>1.27.1</version.lib.grpc>
|
||||
<version.lib.guava>28.1-jre</version.lib.guava>
|
||||
<version.lib.h2>1.4.199</version.lib.h2>
|
||||
|
||||
@@ -102,7 +102,7 @@ for native image.
|
||||
|✅ |{nbsp} |JSON-P |{nbsp}
|
||||
|✅ |{nbsp} |Multi-part |{nbsp}
|
||||
|❓ |{nbsp} |Prometheus |Not yet tested.
|
||||
|❓ |{nbsp} |Websocket |Not yet tested.
|
||||
|✅ |{nbsp} |Websocket |Server only.
|
||||
|❓ |gRPC Server |gRPC Server |Not yet tested.
|
||||
|✅ |{nbsp} |Metrics |{nbsp}
|
||||
|❓ |gRPC Client |gRPC Client |Not yet tested.
|
||||
|
||||
@@ -794,9 +794,8 @@ public class HelidonReflectionFeature implements Feature {
|
||||
}
|
||||
|
||||
void addFields(boolean all) {
|
||||
Field[] fields = clazz.getFields();
|
||||
|
||||
try {
|
||||
Field[] fields = clazz.getFields();
|
||||
// add all public fields
|
||||
for (Field field : fields) {
|
||||
add(field);
|
||||
|
||||
@@ -40,4 +40,21 @@ curl -i -H "Accept: application/json" http://localhost:7076/metrics
|
||||
|
||||
# Should return ALL TESTS PASSED! after passing all webclient tests
|
||||
curl -i http://localhost:7076/wc/test
|
||||
|
||||
# Should return: Upgrade: websocket
|
||||
curl \
|
||||
--include \
|
||||
--no-buffer \
|
||||
--header "Connection: Upgrade" \
|
||||
--header "Upgrade: websocket" \
|
||||
--header "Host: localhost:7076" \
|
||||
--header "Origin: http://localhost:7076" \
|
||||
--header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
|
||||
--header "Sec-WebSocket-Version: 13" \
|
||||
http://localhost:7076/ws/messages
|
||||
|
||||
# Bi-directional test is possible with websocat tool
|
||||
# should return 'part1 part2'
|
||||
for msg in "part1" "part2" "SEND"; do echo $msg; done \
|
||||
| websocat ws://127.0.0.1:7076/ws/messages
|
||||
```
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
JSON-P
|
||||
Classpath static content
|
||||
File static content
|
||||
Tyrus(web sockets)
|
||||
Config (with change support)
|
||||
File watch
|
||||
Classpath
|
||||
@@ -64,6 +65,10 @@
|
||||
<groupId>io.helidon.webserver</groupId>
|
||||
<artifactId>helidon-webserver</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.helidon.webserver</groupId>
|
||||
<artifactId>helidon-webserver-tyrus</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.helidon.media</groupId>
|
||||
<artifactId>helidon-media-jsonp</artifactId>
|
||||
|
||||
@@ -32,9 +32,12 @@ import io.helidon.tracing.TracerBuilder;
|
||||
import io.helidon.webserver.Routing;
|
||||
import io.helidon.webserver.StaticContentSupport;
|
||||
import io.helidon.webserver.WebServer;
|
||||
import io.helidon.webserver.tyrus.TyrusSupport;
|
||||
|
||||
import org.eclipse.microprofile.health.HealthCheckResponse;
|
||||
|
||||
import javax.websocket.server.ServerEndpointConfig;
|
||||
|
||||
import static io.helidon.config.ConfigSources.classpath;
|
||||
import static io.helidon.config.ConfigSources.file;
|
||||
|
||||
@@ -42,7 +45,6 @@ import static io.helidon.config.ConfigSources.file;
|
||||
* Main class of this integration test.
|
||||
*/
|
||||
public final class Se1Main {
|
||||
|
||||
/**
|
||||
* Cannot be instantiated.
|
||||
*/
|
||||
@@ -143,6 +145,12 @@ public final class Se1Main {
|
||||
.register("/greet", greetService)
|
||||
.register("/wc", webClientService)
|
||||
.register("/zipkin", zipkinService)
|
||||
.register("/ws",
|
||||
TyrusSupport.builder().register(
|
||||
ServerEndpointConfig.Builder.create(
|
||||
WebSocketEndpoint.class, "/messages")
|
||||
.build())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.helidon.tests.integration.nativeimage.se1;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.websocket.Endpoint;
|
||||
import javax.websocket.EndpointConfig;
|
||||
import javax.websocket.MessageHandler;
|
||||
import javax.websocket.Session;
|
||||
|
||||
|
||||
public class WebSocketEndpoint extends Endpoint {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(WebSocketEndpoint.class.getName());
|
||||
|
||||
@Override
|
||||
public void onOpen(Session session, EndpointConfig endpointConfig) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
LOGGER.log(Level.INFO, "Session " + session.getId());
|
||||
session.addMessageHandler(new MessageHandler.Whole<String>() {
|
||||
@Override
|
||||
public void onMessage(String message) {
|
||||
LOGGER.log(Level.INFO, "WS Receiving " + message);
|
||||
if (message.contains("SEND")) {
|
||||
sendTextMessage(session, sb.toString());
|
||||
sb.setLength(0);
|
||||
} else {
|
||||
sb.append(message);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void sendTextMessage(Session session, String msg) {
|
||||
try {
|
||||
session.getBasicRemote().sendText(msg);
|
||||
} catch (IOException e) {
|
||||
LOGGER.log(Level.SEVERE, "Message sending failed", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"annotated": [],
|
||||
"class-hierarchy": [
|
||||
"javax.websocket.Endpoint",
|
||||
"javax.websocket.Encoder",
|
||||
"javax.websocket.Decoder",
|
||||
"org.glassfish.tyrus.spi.ClientContainer",
|
||||
"io.netty.channel.ChannelInboundHandlerAdapter",
|
||||
"io.netty.channel.ChannelHandlerAdapter",
|
||||
"io.netty.channel.ChannelInboundHandler",
|
||||
"io.netty.channel.ChannelOutboundHandler"
|
||||
],
|
||||
"classes": [
|
||||
"javax.websocket.CloseReason",
|
||||
"javax.naming.InitialContext"
|
||||
],
|
||||
"exclude": [
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user