From 017868b81c4d691ede984313e10b3e1614afc616 Mon Sep 17 00:00:00 2001 From: "A.Lepe" Date: Tue, 9 Aug 2022 10:59:48 +0900 Subject: [PATCH] Added WebSocketSecureExample --- .../examples/hello/HelloSecureWorld.java | 3 +- .../websocket/WebSocketSecureExample.java | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 src/test/java/spark/examples/websocket/WebSocketSecureExample.java diff --git a/src/test/java/spark/examples/hello/HelloSecureWorld.java b/src/test/java/spark/examples/hello/HelloSecureWorld.java index 4b6d871935..1d73e9c522 100644 --- a/src/test/java/spark/examples/hello/HelloSecureWorld.java +++ b/src/test/java/spark/examples/hello/HelloSecureWorld.java @@ -14,8 +14,7 @@ public class HelloSecureWorld { public static void main(String[] args) { if(args.length == 0) { - secure("/home/lepe/Projects/git/spark/keystore.jks", "yourpasswordhere", null, null); - //secure(SparkTestUtil.getKeyStoreLocation(), SparkTestUtil.getKeystorePassword(), null, null); + secure(SparkTestUtil.getKeyStoreLocation(), SparkTestUtil.getKeystorePassword(), null, null); } else { secure(args[0], args[1], null, null); } diff --git a/src/test/java/spark/examples/websocket/WebSocketSecureExample.java b/src/test/java/spark/examples/websocket/WebSocketSecureExample.java new file mode 100644 index 0000000000..cfc02bd079 --- /dev/null +++ b/src/test/java/spark/examples/websocket/WebSocketSecureExample.java @@ -0,0 +1,38 @@ +/* + * Copyright 2011- Per Wendel + * + * 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 spark.examples.websocket; + +import spark.util.SparkTestUtil; + +import static spark.Spark.init; +import static spark.Spark.secure; +import static spark.Spark.staticFiles; +import static spark.Spark.webSocket; + +public class WebSocketSecureExample { + + public static void main(String[] args) { + // Will serve all static file are under "/public" in classpath if the route isn't consumed by others routes. + staticFiles.location("/public"); + + secure(SparkTestUtil.getKeyStoreLocation(), SparkTestUtil.getKeystorePassword(), null, null); + + webSocket("/echo", EchoWebSocket.class); + webSocket("/ping", PingWebSocket.class); + init(); + } +}