You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2020/06/17 15:12:29 UTC
[karaf-decanter] branch master updated: [KARAF-5691] Add Pax Web
Jetty handler collector
This is an automated email from the ASF dual-hosted git repository.
jbonofre pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/karaf-decanter.git
The following commit(s) were added to refs/heads/master by this push:
new 782b359 [KARAF-5691] Add Pax Web Jetty handler collector
new 9172598 Merge pull request #187 from jbonofre/KARAF-5691
782b359 is described below
commit 782b35994168a77d618143b5e8db0469bebdbfdd
Author: jbonofre <jb...@apache.org>
AuthorDate: Wed Jun 17 10:25:17 2020 +0200
[KARAF-5691] Add Pax Web Jetty handler collector
---
assembly/src/main/feature/feature.xml | 6 +
collector/jetty/NOTICE | 57 +++++++
collector/jetty/pom.xml | 84 ++++++++++
.../jetty/DecanterCollectorJettyHandler.java | 179 +++++++++++++++++++++
collector/pom.xml | 1 +
.../src/main/asciidoc/user-guide/collectors.adoc | 12 ++
6 files changed, 339 insertions(+)
diff --git a/assembly/src/main/feature/feature.xml b/assembly/src/main/feature/feature.xml
index 867797a..37a4dbd 100644
--- a/assembly/src/main/feature/feature.xml
+++ b/assembly/src/main/feature/feature.xml
@@ -245,6 +245,12 @@ org.apache.felix.eventadmin.IgnoreTimeout=org.apache.karaf.decanter.
<feature>decanter-collector-elasticsearch-core</feature>
</feature>
+ <feature name="decanter-collector-jetty" version="${project.version}" description="Karaf Decanter Jetty Handler Collector">
+ <feature>decanter-common</feature>
+ <feature>pax-http-jetty</feature>
+ <bundle>mvn:org.apache.karaf.decanter.collector/org.apache.karaf.decanter.collector.jetty/${project.version}</bundle>
+ </feature>
+
<feature name="decanter-appender-log" version="${project.version}" description="Karaf Decanter Log Appender">
<feature>decanter-common</feature>
<configfile finalname="/etc/org.apache.karaf.decanter.appender.log.cfg">mvn:org.apache.karaf.decanter.appender/org.apache.karaf.decanter.appender.log/${project.version}/cfg</configfile>
diff --git a/collector/jetty/NOTICE b/collector/jetty/NOTICE
new file mode 100644
index 0000000..4e4af9e
--- /dev/null
+++ b/collector/jetty/NOTICE
@@ -0,0 +1,57 @@
+Apache Karaf Decanter
+Copyright 2015-2019 The Apache Software Foundation
+
+I. Included Software
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+This product includes software developed at
+Elastic (https://www.elastic.co/).
+Licensed under the Apache License 2.0.
+
+This product includes software developed at
+OrientDB (http://orientdb.com).
+Licensed under the Apache License 2.0.
+
+II. Used Software
+
+This product uses software developed at
+The OSGi Alliance (http://www.osgi.org/).
+Copyright (c) OSGi Alliance (2000, 2010).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+OPS4J (http://www.ops4j.org/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+SLF4J (http://www.slf4j.org/).
+Licensed under the MIT License.
+
+This product uses software developed at
+JUnit (http://www.junit.org/).
+Licensed under the Eclipse Public License 1.0.
+
+This product uses software developed at
+Redis (http://www.redis.io).
+Licensed under the BSD license.
+
+This product uses software developed at
+Dropwizard (http://www.dropwizard.io).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+searchbox.io (https://github.com/searchbox-io)
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+MongoDB (https://www.mongodb.com/)
+Licensed under the Apache License 2.0.
+
+III. License Summary
+- Apache License 2.0
+- MIT License
+- Eclipse Public License 1.0
+- BSD License
diff --git a/collector/jetty/pom.xml b/collector/jetty/pom.xml
new file mode 100644
index 0000000..6f24252
--- /dev/null
+++ b/collector/jetty/pom.xml
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+
+ <!--
+
+ 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.
+ -->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.karaf.decanter</groupId>
+ <artifactId>collector</artifactId>
+ <version>2.5.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.apache.karaf.decanter.collector</groupId>
+ <artifactId>org.apache.karaf.decanter.collector.jetty</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Karaf :: Decanter :: Collector :: Jetty Handler</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.karaf.decanter</groupId>
+ <artifactId>org.apache.karaf.decanter.api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.decanter.collector</groupId>
+ <artifactId>org.apache.karaf.decanter.collector.utils</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-server</artifactId>
+ <version>9.4.28.v20200408</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>3.1.0</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <inherited>true</inherited>
+ <extensions>true</extensions>
+ <configuration>
+ <obrRepository>NONE</obrRepository>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Export-Package>!*</Export-Package>
+ <Import-Package>
+ org.eclipse.jetty*;version="[8,11)",
+ *
+ </Import-Package>
+ <Private-Package>
+ org.apache.karaf.decanter.collector.jetty,
+ org.apache.karaf.decanter.collector.utils
+ </Private-Package>
+ <_dsannotations>*</_dsannotations>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
diff --git a/collector/jetty/src/main/java/org/apache/karaf/decanter/collector/jetty/DecanterCollectorJettyHandler.java b/collector/jetty/src/main/java/org/apache/karaf/decanter/collector/jetty/DecanterCollectorJettyHandler.java
new file mode 100644
index 0000000..ad9d1d7
--- /dev/null
+++ b/collector/jetty/src/main/java/org/apache/karaf/decanter/collector/jetty/DecanterCollectorJettyHandler.java
@@ -0,0 +1,179 @@
+/*
+ * 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.karaf.decanter.collector.jetty;
+
+import org.apache.karaf.decanter.collector.utils.PropertiesPreparator;
+import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.Server;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+@Component(
+ name = "org.apache.karaf.decanter.collector.jetty",
+ service = { Handler.class },
+ immediate = true
+)
+public class DecanterCollectorJettyHandler implements Handler {
+
+ @Reference
+ public EventAdmin dispatcher;
+
+ private Server server;
+
+ private boolean started = false;
+ private Dictionary<String, Object> properties;
+
+ @Activate
+ public void activate(ComponentContext componentContext) {
+ this.properties = componentContext.getProperties();
+ }
+
+ @Override
+ public void start() throws Exception {
+ started = true;
+ }
+
+ @Override
+ public void stop() throws Exception {
+ started = false;
+ }
+
+ @Override
+ public boolean isRunning() {
+ return started;
+ }
+
+ @Override
+ public boolean isStarted() {
+ return started;
+ }
+
+ @Override
+ public boolean isStarting() {
+ return false;
+ }
+
+ @Override
+ public boolean isStopping() {
+ return false;
+ }
+
+ @Override
+ public boolean isStopped() {
+ return !started;
+ }
+
+ @Override
+ public boolean isFailed() {
+ return false;
+ }
+
+ @Override
+ public void addLifeCycleListener(Listener listener) {
+ // nothing to do
+ }
+
+ @Override
+ public void removeLifeCycleListener(Listener listener) {
+ // nothing to do
+ }
+
+ @Override
+ public void handle(String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException {
+ Map<String, Object> data = new HashMap<>();
+ data.put("request.method", httpServletRequest.getMethod());
+ data.put("request.requestURI", httpServletRequest.getRequestURI());
+ try {
+ if (httpServletRequest.getSession() != null) {
+ data.put("request.session.id", httpServletRequest.getSession().getId());
+ }
+ } catch (Exception e) {
+ // nothing to do
+ }
+ data.put("request.contentType", httpServletRequest.getContentType());
+ data.put("request.authType", httpServletRequest.getAuthType());
+ data.put("request.contextPath", httpServletRequest.getContextPath());
+ data.put("request.pathInfo", httpServletRequest.getPathInfo());
+ data.put("request.pathTranslated", httpServletRequest.getPathTranslated());
+ data.put("request.queryString", httpServletRequest.getQueryString());
+ data.put("request.remoteUser", httpServletRequest.getRemoteUser());
+ data.put("request.requestedSessionId", httpServletRequest.getRequestedSessionId());
+ data.put("request.requestURL", httpServletRequest.getRequestURL());
+ data.put("request.servletPath", httpServletRequest.getServletPath());
+ data.put("request.localAddr", httpServletRequest.getLocalAddr());
+ Enumeration<String> attributeNames = httpServletRequest.getAttributeNames();
+ while (attributeNames.hasMoreElements()) {
+ String name = attributeNames.nextElement();
+ data.put("request.attribute." + name, httpServletRequest.getAttribute(name));
+ }
+ Enumeration<String> parameterNames = httpServletRequest.getParameterNames();
+ while (parameterNames.hasMoreElements()) {
+ String name = parameterNames.nextElement();
+ data.put("request.parameter." + name, httpServletRequest.getParameter(name));
+ }
+ Enumeration<String> requestHeaders = httpServletRequest.getHeaderNames();
+ while (requestHeaders.hasMoreElements()) {
+ String name = requestHeaders.nextElement();
+ data.put("request.header." + name, httpServletRequest.getHeader(name));
+ }
+ data.put("response.status", httpServletResponse.getStatus());
+ for (String headerName : httpServletResponse.getHeaderNames()) {
+ data.put("response.header." + headerName, httpServletResponse.getHeader(headerName));
+ }
+ data.put("response.contentType", httpServletResponse.getContentType());
+ data.put("response.characterEncoding", httpServletResponse.getCharacterEncoding());
+ try {
+ PropertiesPreparator.prepare(data, properties);
+ } catch (Exception e) {
+ // nothing to do
+ }
+ Event event = new Event("decanter/collect/jetty", data);
+ dispatcher.postEvent(event);
+ }
+
+ @Override
+ public void setServer(Server server) {
+ this.server = server;
+ }
+
+ @Override
+ public Server getServer() {
+ return server;
+ }
+
+ @Override
+ public void destroy() {
+ // nothing to do
+ }
+
+}
diff --git a/collector/pom.xml b/collector/pom.xml
index 13e918a..1d71c89 100644
--- a/collector/pom.xml
+++ b/collector/pom.xml
@@ -41,6 +41,7 @@
<module>elasticsearch</module>
<module>eventadmin</module>
<module>file</module>
+ <module>jetty</module>
<module>jms</module>
<module>jmx</module>
<module>kafka</module>
diff --git a/manual/src/main/asciidoc/user-guide/collectors.adoc b/manual/src/main/asciidoc/user-guide/collectors.adoc
index 882e2e1..f37dde3 100644
--- a/manual/src/main/asciidoc/user-guide/collectors.adoc
+++ b/manual/src/main/asciidoc/user-guide/collectors.adoc
@@ -1043,6 +1043,18 @@ addresses=http://localhost:9200
* `from` and `max` properties are used to "square" the query. They are `null` by default.
* `timeout` property limits the query execution. There's no timeout by default.
+==== Pax Web Jetty Handler
+
+Pax Web Jetty Handler collector "intercepts" all HTTP exchanges with the Pax Web Jetty container running in Apache Karaf.
+
+The `decanter-collector-jetty` feature installs the Pax Web Jetty container:
+
+```
+karaf@root()> feature:install decanter-collector-jetty
+```
+
+The collector automatically registers in the Pax Web Jetty container and then all HTTP requests/responses data will be sent to the appenders.
+
==== Customizing properties in collectors
You can add, rename or remove properties collected by the collectors before sending it to the dispatcher.