From 50b659fed3cd429cd2701793313820a581a318a2 Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno <emmanuel.bruno@univ-tln.fr> Date: Wed, 1 Dec 2021 08:58:18 +0100 Subject: [PATCH] adds ws reverse proxy. --- README.md | 5 ++++- docker/nginx/Dockerfile | 4 ++-- docker/nginx/nginx.conf | 7 +++++++ .../java/fr/univtln/bruno/samples/jee91/ws/WSServer.java | 7 ++++--- wsApp/src/main/resources/META-INF/beans.xml | 6 ++++++ wsApp/src/main/webapp/WEB-INF/beans.xml | 6 ++++++ .../fr/univtln/bruno/samples/jee91/wsclient/WsClient.java | 6 ++++-- 7 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 wsApp/src/main/resources/META-INF/beans.xml create mode 100644 wsApp/src/main/webapp/WEB-INF/beans.xml diff --git a/README.md b/README.md index a4d5fe3..c29f796 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,13 @@ curl --cacert localhost.pem \ Avec un reverse proxy : ``` echo quit | openssl s_client -showcerts \ - -servername localhost -connect localhost:8888 >! nginx.pem + -servername localhost -connect localhost:8888 >! localhost.pem curl --cacert localhost.pem \ https://localhost:8181/restApp-1.0-SNAPSHOT/resources/sample/persons/843c8236-6c6b-450e-9aa3-211a9b897403 + +keytool -noprompt -storepass storepass -import \ + -trustcacerts -alias mycert -file localhost.pem -keystore mycert-pub.jks ``` diff --git a/docker/nginx/Dockerfile b/docker/nginx/Dockerfile index ad968fb..656ee95 100644 --- a/docker/nginx/Dockerfile +++ b/docker/nginx/Dockerfile @@ -2,8 +2,8 @@ FROM nginx:1.20.2-alpine RUN apk add openssl RUN openssl req -x509 -nodes \ -days 365 \ - -subj "/C=CA/ST=QC/O=Company, Inc./CN=mydomain.com" \ - -addext "subjectAltName=DNS:mydomain.com" \ + -subj "/C=CA/ST=QC/O=Company, Inc./CN=localhost" \ + -addext "subjectAltName=DNS:localhost" \ -newkey rsa:2048 \ -keyout /etc/ssl/private/nginx-selfsigned.key \ -out /etc/ssl/certs/nginx-selfsigned.crt; \ No newline at end of file diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf index d4626c1..c54e654 100644 --- a/docker/nginx/nginx.conf +++ b/docker/nginx/nginx.conf @@ -10,6 +10,13 @@ http { ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt; ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key; + location /wsapp/ { + proxy_pass http://jakartaEE:8686; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + } + location / { proxy_pass http://jakartaEE:8080; } diff --git a/wsApp/src/main/java/fr/univtln/bruno/samples/jee91/ws/WSServer.java b/wsApp/src/main/java/fr/univtln/bruno/samples/jee91/ws/WSServer.java index eacbdf6..bea8ec0 100644 --- a/wsApp/src/main/java/fr/univtln/bruno/samples/jee91/ws/WSServer.java +++ b/wsApp/src/main/java/fr/univtln/bruno/samples/jee91/ws/WSServer.java @@ -20,10 +20,11 @@ import java.io.IOException; @Log public class WSServer { - @Inject + @Inject @SpokenLanguage(SpokenLanguage.Language.ENGLISH) Hello hello; + @Inject MainDAO dao1; @@ -36,8 +37,8 @@ public class WSServer { } @OnMessage - public void onMessage(Session session, - String message) throws IOException { + public void onMessage(String message, Session session + ) throws IOException { session.getBasicRemote().sendText("Echo :" + message); } } diff --git a/wsApp/src/main/resources/META-INF/beans.xml b/wsApp/src/main/resources/META-INF/beans.xml new file mode 100644 index 0000000..f8e2542 --- /dev/null +++ b/wsApp/src/main/resources/META-INF/beans.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd" + bean-discovery-mode="all"> +</beans> \ No newline at end of file diff --git a/wsApp/src/main/webapp/WEB-INF/beans.xml b/wsApp/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000..f8e2542 --- /dev/null +++ b/wsApp/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd" + bean-discovery-mode="all"> +</beans> \ No newline at end of file diff --git a/wsClient/src/main/java/fr/univtln/bruno/samples/jee91/wsclient/WsClient.java b/wsClient/src/main/java/fr/univtln/bruno/samples/jee91/wsclient/WsClient.java index 9711a21..71ab020 100644 --- a/wsClient/src/main/java/fr/univtln/bruno/samples/jee91/wsclient/WsClient.java +++ b/wsClient/src/main/java/fr/univtln/bruno/samples/jee91/wsclient/WsClient.java @@ -41,8 +41,10 @@ public class WsClient { public static void main(String[] args) { try { - - final WsClient clientEndPoint = new WsClient(new URI("wss://localhost:8686/wsApp-1.0-SNAPSHOT/hellows")); + URI uri = new URI("ws://localhost:8686/wsApp-1.0-SNAPSHOT/hellows"); + //URI uri = new URI("wss://localhost:8888/wsapp/wsApp-1.0-SNAPSHOT/hellows"); + log.info("Connecting to "+uri); + final WsClient clientEndPoint = new WsClient(uri); clientEndPoint.sendMessage("Hello 1 !"); Thread.sleep(5000); clientEndPoint.sendMessage("Hello 2 !"); -- GitLab