[KARAF-6002] Add cfg file for the websocket servlet appender
authorJean-Baptiste Onofré <jbonofre@apache.org>
Wed, 14 Nov 2018 09:47:58 +0000 (10:47 +0100)
committerJean-Baptiste Onofré <jbonofre@apache.org>
Wed, 14 Nov 2018 09:48:05 +0000 (10:48 +0100)
appender/websocket-servlet/pom.xml
appender/websocket-servlet/src/main/cfg/org.apache.karaf.decanter.appender.websocket.servlet.cfg [new file with mode: 0644]
appender/websocket-servlet/src/main/java/org/apache/karaf/decanter/appender/websocket/DecanterWebSocketAppender.java
manual/src/main/asciidoc/user-guide/appenders.adoc

index 319daf8..cf05680 100644 (file)
                         </Private-Package>
                     </instructions>
                 </configuration>
-            </plugin>
+            </plugin>            <plugin>
+            <groupId>org.codehaus.mojo</groupId>
+            <artifactId>build-helper-maven-plugin</artifactId>
+            <executions>
+                <execution>
+                    <phase>package</phase>
+                    <goals>
+                        <goal>attach-artifact</goal>
+                    </goals>
+                    <configuration>
+                        <artifacts>
+                            <artifact>
+                                <file>src/main/cfg/org.apache.karaf.decanter.appender.websocket.servlet.cfg</file>
+                                <type>cfg</type>
+                            </artifact>
+                        </artifacts>
+                    </configuration>
+                </execution>
+            </executions>
+        </plugin>
         </plugins>
     </build>
 
diff --git a/appender/websocket-servlet/src/main/cfg/org.apache.karaf.decanter.appender.websocket.servlet.cfg b/appender/websocket-servlet/src/main/cfg/org.apache.karaf.decanter.appender.websocket.servlet.cfg
new file mode 100644 (file)
index 0000000..d93367f
--- /dev/null
@@ -0,0 +1,28 @@
+################################################################################
+#
+#    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.
+#
+################################################################################
+
+#######################################
+# Decanter WebSocket Servlet Appender Configuration
+#######################################
+
+# Servlet alias where the websocket is registered
+servlet.alias=/decanter-websocket
+
+# Marshaller to use (json is recommended)
+marshaller.target=(dataFormat=json)
\ No newline at end of file
index d2c16b6..195ed83 100644 (file)
@@ -49,6 +49,7 @@ public class DecanterWebSocketAppender implements EventHandler {
     private static final Logger LOG = LoggerFactory.getLogger(DecanterWebSocketAppender.class);
 
     private static final Set<Session> sessions = Collections.synchronizedSet(new HashSet<Session>());
+    private String alias;
 
     @Reference
     private Marshaller marshaller;
@@ -69,12 +70,16 @@ public class DecanterWebSocketAppender implements EventHandler {
 
     @Activate
     public void activate(ComponentContext componentContext) throws Exception {
-        httpService.registerServlet("/decanter-websocket", new DecanterWebSocketServlet(), null, null);
+        alias = (String) componentContext.getProperties().get("servlet.alias");
+        if (alias == null) {
+            alias = "/decanter-websocket";
+        }
+        httpService.registerServlet(alias, new DecanterWebSocketServlet(), null, null);
     }
 
     @Deactivate
     public void deactivate() throws Exception {
-        httpService.unregister("/decanter-websocket");
+        httpService.unregister(alias);
     }
 
     @Override
index 1df18b7..b2eb136 100644 (file)
@@ -1440,6 +1440,8 @@ ID │ Servlet                  │ Servlet-Name   │ State       │ Alias
 55 │ DecanterWebSocketServlet │ ServletModel-2 │ Deployed    │ /decanter-websocket │ [/decanter-websocket/*]
 ```
 
+The alias can be configured via the `etc/org.apache.karaf.decanter.appender.websocket.servlet.cfg` configuration file installed by the feature.
+
 You can now register your websocket client on this URL. You can use `curl` as client to test:
 
 ```