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

Tyrus server support for native-image in SE #2097

Merged
merged 1 commit into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion docs/se/aot/01_introduction.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,9 +663,8 @@ private void addConstructors() {
}

void addFields(boolean all) {
Field[] fields = clazz.getFields();

try {
Field[] fields = clazz.getFields();
// add all public fields
for (Field field : fields) {
add(field);
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/native-image/se-1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
5 changes: 5 additions & 0 deletions tests/integration/native-image/se-1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
JSON-P
Classpath static content
File static content
Tyrus(web sockets)
Config (with change support)
File watch
Classpath
Expand Down Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@
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;

/**
* Main class of this integration test.
*/
public final class Se1Main {

/**
* Cannot be instantiated.
*/
Expand Down Expand Up @@ -143,6 +145,12 @@ private static Routing createRouting(Config config) {
.register("/greet", greetService)
.register("/wc", webClientService)
.register("/zipkin", zipkinService)
.register("/ws",
TyrusSupport.builder().register(
ServerEndpointConfig.Builder.create(
WebSocketEndpoint.class, "/messages")
.build())
.build())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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": [
]
}