You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2018/09/27 02:22:58 UTC

[cxf] branch 3.2.x-fixes updated: CXF-7844: Change Zipkin/Brave XML to use brave-spring-beans. Extracting reporter to separate bean (since it is generic type, adding the converter).

This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch 3.2.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/3.2.x-fixes by this push:
     new f62feb0  CXF-7844: Change Zipkin/Brave XML to use brave-spring-beans. Extracting reporter to separate bean (since it is generic type, adding the converter).
f62feb0 is described below

commit f62feb0421deb73557ad8a0115364092afc607b8
Author: reta <dr...@gmail.com>
AuthorDate: Wed Sep 26 22:22:25 2018 -0400

    CXF-7844: Change Zipkin/Brave XML to use brave-spring-beans. Extracting reporter to separate bean (since it is generic type, adding the converter).
---
 .../samples/jax_rs/tracing_brave_osgi/pom.xml      |  5 +++
 .../tracing/server/AsyncReporterConverter.java     | 49 ++++++++++++++++++++++
 .../tracing/server/CatalogTracingFactory.java      |  5 +--
 .../main/resources/OSGI-INF/blueprint/context.xml  | 14 +++++--
 .../samples/jaxws_tracing_brave_osgi/pom.xml       |  5 +++
 .../tracing/server/AsyncReporterConverter.java     | 49 ++++++++++++++++++++++
 .../tracing/server/CatalogTracingFactory.java      |  5 +--
 .../main/resources/OSGI-INF/blueprint/context.xml  | 12 +++++-
 8 files changed, 133 insertions(+), 11 deletions(-)

diff --git a/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/pom.xml b/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/pom.xml
index 14be322..dfddd7b 100644
--- a/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/pom.xml
+++ b/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/pom.xml
@@ -65,6 +65,11 @@
             <version>3.2.7-SNAPSHOT</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.aries.blueprint</groupId>
+            <artifactId>org.apache.aries.blueprint.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>javax.json</groupId>
             <artifactId>javax.json-api</artifactId>
         </dependency>
diff --git a/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/src/main/java/demo/jaxrs/tracing/server/AsyncReporterConverter.java b/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/src/main/java/demo/jaxrs/tracing/server/AsyncReporterConverter.java
new file mode 100644
index 0000000..a553deb
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/src/main/java/demo/jaxrs/tracing/server/AsyncReporterConverter.java
@@ -0,0 +1,49 @@
+/**
+ * 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 demo.jaxrs.tracing.server;
+
+import org.osgi.service.blueprint.container.Converter;
+import org.osgi.service.blueprint.container.ReifiedType;
+
+import zipkin2.Span;
+import zipkin2.reporter.AsyncReporter;
+
+/**
+ * Converts generic AsyncReporter<?> to AsyncReporter<Span> (see please
+ * https://issues.apache.org/jira/browse/ARIES-1607, https://issues.apache.org/jira/browse/ARIES-960
+ * and https://issues.apache.org/jira/browse/ARIES-1500)
+ *  
+ */
+public class AsyncReporterConverter implements Converter {
+    @Override
+    public boolean canConvert(Object source, ReifiedType target) {
+        return (source instanceof AsyncReporter<?> && target.getRawClass() == AsyncReporter.class);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public Object convert(Object source, ReifiedType target) throws Exception {
+        if (source instanceof AsyncReporter<?>) {
+            return (AsyncReporter<Span>)source;
+        } else {
+            throw new RuntimeException("Unable to convert from " + source + " to " + target);
+        }
+    }
+}
diff --git a/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/src/main/java/demo/jaxrs/tracing/server/CatalogTracingFactory.java b/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/src/main/java/demo/jaxrs/tracing/server/CatalogTracingFactory.java
index bb7c498..f4b8042 100644
--- a/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/src/main/java/demo/jaxrs/tracing/server/CatalogTracingFactory.java
+++ b/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/src/main/java/demo/jaxrs/tracing/server/CatalogTracingFactory.java
@@ -22,10 +22,9 @@ package demo.jaxrs.tracing.server;
 import brave.Tracing;
 import brave.propagation.ThreadLocalCurrentTraceContext;
 import zipkin2.reporter.AsyncReporter;
-import zipkin2.reporter.Sender;
 
 public class CatalogTracingFactory {
-    public static Tracing create(final String serviceName, final Sender sender) {
+    public static Tracing create(final String serviceName, final AsyncReporter<zipkin2.Span> reporter) {
         return Tracing
             .newBuilder()
             .localServiceName(serviceName)
@@ -34,7 +33,7 @@ public class CatalogTracingFactory {
                     .newBuilder()
                     .build()
               )
-            .spanReporter(AsyncReporter.create(sender))
+            .spanReporter(reporter)
             .build();
     }
 }
diff --git a/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/src/main/resources/OSGI-INF/blueprint/context.xml b/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/src/main/resources/OSGI-INF/blueprint/context.xml
index c0979e5..a0b908c 100644
--- a/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/src/main/resources/OSGI-INF/blueprint/context.xml
+++ b/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/src/main/resources/OSGI-INF/blueprint/context.xml
@@ -24,16 +24,25 @@
        xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
 
        xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
+                           http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.6.0 https://aries.apache.org/schemas/blueprint-ext/blueprint-ext-1.6.xsd
                            http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
                            http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd">
 
+    <type-converters>
+        <bean class="demo.jaxrs.tracing.server.AsyncReporterConverter" />
+    </type-converters>
+    
     <bean id="sender" class="zipkin2.reporter.okhttp3.OkHttpSender" factory-method="create" destroy-method="close">
         <argument index="0" value="http://localhost:9411/api/v2/spans" />
     </bean>
-
+    
+    <bean id="reporter" class="zipkin2.reporter.AsyncReporter" factory-method="create" destroy-method="close">
+        <argument index="0" ref="sender" />
+    </bean>
+    
     <bean id="tracing" class="demo.jaxrs.tracing.server.CatalogTracingFactory" factory-method="create">
         <argument index="0" value="catalog-service" />
-        <argument index="1" ref="sender" />
+        <argument index="1" ref="reporter" />
     </bean>
   
     <!-- JAXRS providers -->
@@ -62,6 +71,5 @@
             <ref component-id="braveFeature" />
         </jaxrs:providers>
     </jaxrs:server>
-
 </blueprint>
 <!-- END SNIPPET: blueprint -->
diff --git a/distribution/src/main/release/samples/jaxws_tracing_brave_osgi/pom.xml b/distribution/src/main/release/samples/jaxws_tracing_brave_osgi/pom.xml
index 0ec1cc9..4491786 100644
--- a/distribution/src/main/release/samples/jaxws_tracing_brave_osgi/pom.xml
+++ b/distribution/src/main/release/samples/jaxws_tracing_brave_osgi/pom.xml
@@ -80,6 +80,11 @@
             <version>3.2.7-SNAPSHOT</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.aries.blueprint</groupId>
+            <artifactId>org.apache.aries.blueprint.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>javax.ws.rs</groupId>
             <artifactId>javax.ws.rs-api</artifactId>
         </dependency>
diff --git a/distribution/src/main/release/samples/jaxws_tracing_brave_osgi/src/main/java/demo/jaxws/tracing/server/AsyncReporterConverter.java b/distribution/src/main/release/samples/jaxws_tracing_brave_osgi/src/main/java/demo/jaxws/tracing/server/AsyncReporterConverter.java
new file mode 100644
index 0000000..6c4c335
--- /dev/null
+++ b/distribution/src/main/release/samples/jaxws_tracing_brave_osgi/src/main/java/demo/jaxws/tracing/server/AsyncReporterConverter.java
@@ -0,0 +1,49 @@
+/**
+ * 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 demo.jaxws.tracing.server;
+
+import org.osgi.service.blueprint.container.Converter;
+import org.osgi.service.blueprint.container.ReifiedType;
+
+import zipkin2.Span;
+import zipkin2.reporter.AsyncReporter;
+
+/**
+ * Converts generic AsyncReporter<?> to AsyncReporter<Span> (see please
+ * https://issues.apache.org/jira/browse/ARIES-1607, https://issues.apache.org/jira/browse/ARIES-960
+ * and https://issues.apache.org/jira/browse/ARIES-1500)
+ *  
+ */
+public class AsyncReporterConverter implements Converter {
+    @Override
+    public boolean canConvert(Object source, ReifiedType target) {
+        return (source instanceof AsyncReporter<?> && target.getRawClass() == AsyncReporter.class);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public Object convert(Object source, ReifiedType target) throws Exception {
+        if (source instanceof AsyncReporter<?>) {
+            return (AsyncReporter<Span>)source;
+        } else {
+            throw new RuntimeException("Unable to convert from " + source + " to " + target);
+        }
+    }
+}
diff --git a/distribution/src/main/release/samples/jaxws_tracing_brave_osgi/src/main/java/demo/jaxws/tracing/server/CatalogTracingFactory.java b/distribution/src/main/release/samples/jaxws_tracing_brave_osgi/src/main/java/demo/jaxws/tracing/server/CatalogTracingFactory.java
index 34b5434..0e8b337 100644
--- a/distribution/src/main/release/samples/jaxws_tracing_brave_osgi/src/main/java/demo/jaxws/tracing/server/CatalogTracingFactory.java
+++ b/distribution/src/main/release/samples/jaxws_tracing_brave_osgi/src/main/java/demo/jaxws/tracing/server/CatalogTracingFactory.java
@@ -22,10 +22,9 @@ package demo.jaxws.tracing.server;
 import brave.Tracing;
 import brave.propagation.ThreadLocalCurrentTraceContext;
 import zipkin2.reporter.AsyncReporter;
-import zipkin2.reporter.Sender;
 
 public class CatalogTracingFactory {
-    public static Tracing create(final String serviceName, final Sender sender) {
+    public static Tracing create(final String serviceName, final AsyncReporter<zipkin2.Span> reporter) {
         return Tracing
             .newBuilder()
             .localServiceName(serviceName)
@@ -34,7 +33,7 @@ public class CatalogTracingFactory {
                     .newBuilder()
                     .build()
               )
-            .spanReporter(AsyncReporter.create(sender))
+            .spanReporter(reporter)
             .build();
     }
 }
diff --git a/distribution/src/main/release/samples/jaxws_tracing_brave_osgi/src/main/resources/OSGI-INF/blueprint/context.xml b/distribution/src/main/release/samples/jaxws_tracing_brave_osgi/src/main/resources/OSGI-INF/blueprint/context.xml
index 79e8c31..0ae7559 100644
--- a/distribution/src/main/release/samples/jaxws_tracing_brave_osgi/src/main/resources/OSGI-INF/blueprint/context.xml
+++ b/distribution/src/main/release/samples/jaxws_tracing_brave_osgi/src/main/resources/OSGI-INF/blueprint/context.xml
@@ -27,11 +27,15 @@
                            http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
                            http://cxf.apache.org/blueprint/jaxws http://cxf.apache.org/schemas/blueprint/jaxws.xsd">
 
+    <type-converters>
+        <bean class="demo.jaxws.tracing.server.AsyncReporterConverter" />
+    </type-converters>
+
     <!-- CXF BraveFeature -->
     <bean id="braveFeature" class="org.apache.cxf.tracing.brave.BraveFeature">
         <argument index="0" ref="tracing" />
     </bean>
-    
+
     <cxf:bus>
         <cxf:features>
             <cxf:logging />
@@ -45,10 +49,14 @@
     <bean id="sender" class="zipkin2.reporter.okhttp3.OkHttpSender" factory-method="create" destroy-method="close">
         <argument index="0" value="http://localhost:9411/api/v2/spans" />
     </bean>
+    
+    <bean id="reporter" class="zipkin2.reporter.AsyncReporter" factory-method="create" destroy-method="close">
+        <argument index="0" ref="sender" />
+    </bean>
 
 	<bean id="tracing" class="demo.jaxws.tracing.server.CatalogTracingFactory" factory-method="create">
         <argument index="0" value="catalog-service" />
-        <argument index="1" ref="sender" />
+        <argument index="1" ref="reporter" />
     </bean>
 
     <jaxws:endpoint