You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by rm...@apache.org on 2021/04/22 15:10:52 UTC
[openwebbeans-meecrowave] branch master updated: [MEECROWAVE-284]
add meecrowave-websocket module
This is an automated email from the ASF dual-hosted git repository.
rmannibucau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwebbeans-meecrowave.git
The following commit(s) were added to refs/heads/master by this push:
new 0b0c83c [MEECROWAVE-284] add meecrowave-websocket module
0b0c83c is described below
commit 0b0c83ce357c8f4f7874985504ddaf60ca7b9d20
Author: Romain Manni-Bucau <rm...@gmail.com>
AuthorDate: Thu Apr 22 17:10:48 2021 +0200
[MEECROWAVE-284] add meecrowave-websocket module
---
meecrowave-doc/pom.xml | 4 +-
.../main/java/org/apache/meecrowave/doc/JBake.java | 4 +
.../src/main/jbake/assets/assets/css/styles.css | 64 ++++++++
.../src/main/jbake/assets/assets/js/main.js | 26 ++++
.../jbake/content/meecrowave-websocket/index.adoc | 27 ++++
meecrowave-websocket/pom.xml | 168 +++++++++++++++++++++
.../websocket/CDIServerConfigurator.java | 70 +++++++++
...socket.server.ServerEndpointConfig$Configurator | 1 +
pom.xml | 1 +
9 files changed, 364 insertions(+), 1 deletion(-)
diff --git a/meecrowave-doc/pom.xml b/meecrowave-doc/pom.xml
index 89ec459..0d3c100 100644
--- a/meecrowave-doc/pom.xml
+++ b/meecrowave-doc/pom.xml
@@ -164,7 +164,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
- <version>1.6.0</version>
+ <version>3.0.0</version>
<executions>
<execution>
<id>meecrowave-site</id>
@@ -175,6 +175,8 @@
</execution>
</executions>
<configuration>
+ <cleanupDaemonThreads>false</cleanupDaemonThreads>
+ <stopUnresponsiveDaemonThreads>false</stopUnresponsiveDaemonThreads>
<includeProjectDependencies>true</includeProjectDependencies>
<mainClass>org.apache.meecrowave.doc.JBake</mainClass>
<arguments>
diff --git a/meecrowave-doc/src/main/java/org/apache/meecrowave/doc/JBake.java b/meecrowave-doc/src/main/java/org/apache/meecrowave/doc/JBake.java
index 9746ef4..abf3a2d 100755
--- a/meecrowave-doc/src/main/java/org/apache/meecrowave/doc/JBake.java
+++ b/meecrowave-doc/src/main/java/org/apache/meecrowave/doc/JBake.java
@@ -54,6 +54,7 @@ import org.apache.meecrowave.doc.generator.LetsEncryptConfiguration;
import org.apache.meecrowave.doc.generator.MavenConfiguration;
import org.apache.meecrowave.doc.generator.OAuth2Configuration;
import org.apache.meecrowave.doc.generator.ProxyConfiguration;
+import org.apache.meecrowave.proxy.servlet.meecrowave.ProxyServletSetup;
import org.jbake.app.Oven;
import org.jbake.app.configuration.ConfigUtil;
import org.jbake.app.configuration.DefaultJBakeConfiguration;
@@ -123,6 +124,7 @@ public class JBake {
add("source-highlighter=highlightjs");
add("highlightjs-theme=idea");
add("context_rootpath=/meecrowave");
+ add("icons=font");
}});
}}));
config.addConfiguration(DefaultJBakeConfiguration.class.cast(
@@ -243,8 +245,10 @@ public class JBake {
try (final Meecrowave container = new Meecrowave(new Meecrowave.Builder() {{
setWebResourceCached(false);
+ property("proxy-skip", "true");
}}) {{
start();
+ getTomcat().getServer().setParentClassLoader(Thread.currentThread().getContextClassLoader());
deployWebapp("/meecrowave", destination);
}}) {
System.out.println("Started on http://localhost:" + container.getConfiguration().getHttpPort() + "/meecrowave");
diff --git a/meecrowave-doc/src/main/jbake/assets/assets/css/styles.css b/meecrowave-doc/src/main/jbake/assets/assets/css/styles.css
index edb6c74..d758f1b 100644
--- a/meecrowave-doc/src/main/jbake/assets/assets/css/styles.css
+++ b/meecrowave-doc/src/main/jbake/assets/assets/css/styles.css
@@ -1261,3 +1261,67 @@ select {
pre {
padding: 0;
}
+
+
+}
+.admonitionblock td.content > :first-child {
+ margin: 0;
+}
+.admonitionblock {
+ margin-bottom: 1rem;
+}
+.admonitionblock > table {
+ padding-top: 1rem;
+ padding-bottom: 1rem;
+ width: 100%;
+ height: 100%;
+ position: relative;
+ display: block;
+ /*border: 1px solid #c6c6c6;
+ border-radius: 5px;*/
+}
+.admonitionblock td.content > code {
+ background-color: unset !important;
+ color: unset !important;
+}
+.admonitionblock td.content {
+ display: block;
+ width: 100%;
+ padding: 0.5rem;
+}
+.admonitionblock .icon {
+ padding-right: 0.6rem;
+ padding-top: 0.5rem;
+}
+.admonitionblock .icon i {
+ display: inline-flex;
+ align-items: center;
+ height: 100%;
+}
+.admonitionblock .icon i::after {
+ content: attr(title);
+ hyphens: none;
+}
+.icon-important:before, .icon-note:before, .icon-tip:before, .icon-warning:before {
+ font-size: 1em;
+}
+.icon-important:before {
+ content: "\f06a";
+ font-family: "Font Awesome 5 Free";
+ color: #e96065;
+}
+.icon-note:before {
+ content: "\f05a";
+ font-family: "Font Awesome 5 Free";
+ color: #0675c1;
+}
+.icon-tip:before {
+ content: "\f059";
+ font-family: "Font Awesome 5 Free";
+ color: #6ec01e;
+}
+.icon-warning:before {
+ content: "\f071";
+ font-family: "Font Awesome 5 Free";
+ color: #ffc300;
+}
diff --git a/meecrowave-doc/src/main/jbake/assets/assets/js/main.js b/meecrowave-doc/src/main/jbake/assets/assets/js/main.js
index da07fe8..6dc2e61 100644
--- a/meecrowave-doc/src/main/jbake/assets/assets/js/main.js
+++ b/meecrowave-doc/src/main/jbake/assets/assets/js/main.js
@@ -46,4 +46,30 @@ $(document).ready(function() {
});
hljs.initHighlightingOnLoad();
+
+ // set admonitionblock custom theme
+ // drop titles from <i> to not pollute the ui with pointless text
+ function setAdmonitionStyle(item, color) {
+ var i = $(item);
+ i.css('border-left', '1.5px solid ' + color);
+ i.css('padding-left', '2rem');
+ i.css('background-color', color + '10');
+ i.css('color', color);
+ }
+ $('div.admonitionblock td.icon > i.fa').each(function (idx, item) {
+ item.title = '';
+
+ var jItem = $(item);
+ jItem.addClass('fa-lg');
+ var content = jItem.parent().parent().find('td.content');
+ if (jItem.hasClass('icon-important')) {
+ setAdmonitionStyle(content, '#e96065');
+ } else if (jItem.hasClass('icon-note')) {
+ setAdmonitionStyle(content, '#0675c1');
+ } else if (jItem.hasClass('icon-warning')) {
+ setAdmonitionStyle(content, '#ffc300');
+ } else {
+ setAdmonitionStyle(content, '#6ec01e');
+ }
+ });
});
\ No newline at end of file
diff --git a/meecrowave-doc/src/main/jbake/content/meecrowave-websocket/index.adoc b/meecrowave-doc/src/main/jbake/content/meecrowave-websocket/index.adoc
new file mode 100755
index 0000000..32b8253
--- /dev/null
+++ b/meecrowave-doc/src/main/jbake/content/meecrowave-websocket/index.adoc
@@ -0,0 +1,27 @@
+= Meecrowave WebSocket
+:jbake-date: 2021-04-22
+:jbake-type: page
+:jbake-status: published
+:jbake-meecrowavepdf:
+:jbake-meecrowavetitleicon: icon icon_chat
+:jbake-meecrowavecolor: body-red
+:icons: font
+
+WARNING: this module is available with Apache Meecrowave >= 1.2.11.
+
+Coordinates:
+
+[source,xml]
+----
+<dependency>
+ <groupId>org.apache.meecrowave</groupId>
+ <artifactId>meecrowave-websocket</artifactId>
+ <version>${meecrowave.version}</version>
+</dependency>
+----
+
+IMPORTANT: this module requires `org.apache.tomcat:tomcat-websocket-api` but replaces `org.apache.tomcat:tomcat-websocket` until Tomcat enables a better way to extend its default.
+
+Once this module added, you can implement a server websocket endpoint as a CDI bean, it will use `CDI.current().select(endpointType).get()` to resolve it.
+
+NOTE: you can still pass a custom `Configurator` to your endpoint to customize the lookup or runtime of the endpoint.
diff --git a/meecrowave-websocket/pom.xml b/meecrowave-websocket/pom.xml
new file mode 100644
index 0000000..71828d3
--- /dev/null
+++ b/meecrowave-websocket/pom.xml
@@ -0,0 +1,168 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>meecrowave</artifactId>
+ <groupId>org.apache.meecrowave</groupId>
+ <version>1.2.11-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>meecrowave-websocket</artifactId>
+ <name>Meecrowave :: WebSocket</name>
+
+ <properties>
+ <meecrowave.build.name>${project.groupId}.websocket</meecrowave.build.name>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>meecrowave-specs-api</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>tomcat-websocket</artifactId>
+ <version>${tomcat.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>embed-tomcat-websocket</id>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <createDependencyReducedPom>true</createDependencyReducedPom>
+ <dependencyReducedPomLocation>${project.build.directory}/reduced.pom</dependencyReducedPomLocation>
+ <artifactSet>
+ <includes>
+ <include>${project.groupId}:${project.artifactId}</include>
+ <include>org.apache.tomcat:tomcat-websocket</include>
+ </includes>
+ </artifactSet>
+ <filters>
+ <filter>
+ <artifact>org.apache.tomcat:tomcat-websocket</artifact>
+ <excludes>
+ META-INF/services/javax.websocket.server.ServerEndpointConfig$Configurator
+ </excludes>
+ </filter>
+ <filter>
+ <artifact>*:*</artifact>
+ <excludes>
+ <exclude>META-INF/*.SF</exclude>
+ <exclude>META-INF/*.DSA</exclude>
+ <exclude>META-INF/*.RSA</exclude>
+ </excludes>
+ </filter>
+ </filters>
+ </configuration>
+ </execution>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <transformers>
+ <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
+ </transformers>
+ <shadedArtifactAttached>true</shadedArtifactAttached>
+ <shadedClassifierName>jakarta</shadedClassifierName>
+ <createDependencyReducedPom>false</createDependencyReducedPom>
+ <artifactSet>
+ <includes>
+ <include>${project.groupId}:${project.artifactId}</include>
+ <include>org.apache.tomcat:tomcat-websocket</include>
+ </includes>
+ </artifactSet>
+ <filters>
+ <filter>
+ <artifact>org.apache.tomcat:tomcat-websocket</artifact>
+ <excludes>
+ META-INF/services/javax.websocket.server.ServerEndpointConfig$Configurator
+ </excludes>
+ </filter>
+ <filter>
+ <artifact>*:*</artifact>
+ <excludes>
+ <exclude>META-INF/*.SF</exclude>
+ <exclude>META-INF/*.DSA</exclude>
+ <exclude>META-INF/*.RSA</exclude>
+ </excludes>
+ </filter>
+ </filters>
+ <relocations>
+ <relocation>
+ <pattern>javax.activation</pattern>
+ <shadedPattern>jakarta.activation</shadedPattern>
+ </relocation>
+ <relocation>
+ <pattern>javax.annotation</pattern>
+ <shadedPattern>jakarta.annotation</shadedPattern>
+ </relocation>
+ <relocation>
+ <pattern>javax.el</pattern>
+ <shadedPattern>jakarta.el</shadedPattern>
+ </relocation>
+ <relocation>
+ <pattern>javax.enterprise</pattern>
+ <shadedPattern>jakarta.enterprise</shadedPattern>
+ </relocation>
+ <relocation>
+ <pattern>javax.decorator</pattern>
+ <shadedPattern>jakarta.decorator</shadedPattern>
+ </relocation>
+ <relocation>
+ <pattern>javax.inject</pattern>
+ <shadedPattern>jakarta.inject</shadedPattern>
+ </relocation>
+ <relocation>
+ <pattern>javax.interceptor</pattern>
+ <shadedPattern>jakarta.interceptor</shadedPattern>
+ </relocation>
+ <relocation>
+ <pattern>javax.servlet</pattern>
+ <shadedPattern>jakarta.servlet</shadedPattern>
+ </relocation>
+ <relocation>
+ <pattern>javax.websocket</pattern>
+ <shadedPattern>jakarta.websocket</shadedPattern>
+ </relocation>
+ </relocations>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
diff --git a/meecrowave-websocket/src/main/java/org/apache/meecrowave/websocket/CDIServerConfigurator.java b/meecrowave-websocket/src/main/java/org/apache/meecrowave/websocket/CDIServerConfigurator.java
new file mode 100644
index 0000000..cd25611
--- /dev/null
+++ b/meecrowave-websocket/src/main/java/org/apache/meecrowave/websocket/CDIServerConfigurator.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.meecrowave.websocket;
+
+import javax.enterprise.inject.spi.CDI;
+import javax.websocket.Extension;
+import javax.websocket.HandshakeResponse;
+import javax.websocket.server.HandshakeRequest;
+import javax.websocket.server.ServerEndpointConfig;
+import java.util.List;
+import java.util.Set;
+
+import static java.util.Collections.emptyList;
+import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toSet;
+
+public class CDIServerConfigurator extends ServerEndpointConfig.Configurator {
+ @Override
+ public <T> T getEndpointInstance(final Class<T> clazz) throws InstantiationException {
+ try {
+ return CDI.current().select(clazz).get();
+ } catch (final RuntimeException re) {
+ return super.getEndpointInstance(clazz);
+ }
+ }
+
+ @Override
+ public String getNegotiatedSubprotocol(final List<String> supported, final List<String> requested) {
+ return requested.stream().filter(supported::contains).findFirst().orElse("");
+ }
+
+
+ @Override
+ public List<Extension> getNegotiatedExtensions(final List<Extension> installed,
+ final List<Extension> requested) {
+ if (requested.isEmpty()) {
+ return emptyList();
+ }
+ final Set<String> names = installed.stream().map(Extension::getName).collect(toSet());
+ return requested.stream().filter(e -> names.contains(e.getName())).collect(toList());
+ }
+
+ @Override
+ public boolean checkOrigin(final String originHeaderValue) {
+ return true;
+ }
+
+ @Override
+ public void modifyHandshake(final ServerEndpointConfig sec,
+ final HandshakeRequest request,
+ final HandshakeResponse response) {
+ // no-op
+ }
+}
diff --git a/meecrowave-websocket/src/main/resources/META-INF/services/javax.websocket.server.ServerEndpointConfig$Configurator b/meecrowave-websocket/src/main/resources/META-INF/services/javax.websocket.server.ServerEndpointConfig$Configurator
new file mode 100644
index 0000000..269ba96
--- /dev/null
+++ b/meecrowave-websocket/src/main/resources/META-INF/services/javax.websocket.server.ServerEndpointConfig$Configurator
@@ -0,0 +1 @@
+org.apache.meecrowave.websocket.CDIServerConfigurator
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 2845f69..7fd2457 100644
--- a/pom.xml
+++ b/pom.xml
@@ -86,6 +86,7 @@
<module>meecrowave-oauth2</module>
<module>meecrowave-letsencrypt</module>
<module>meecrowave-proxy</module>
+ <module>meecrowave-websocket</module>
</modules>
<dependencyManagement>