cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cxf git commit: CXF-6360: Integration with Apache HTrace. Added sample application skeleton. Fixed minor issue with new span creation.
Date Fri, 26 Jun 2015 00:58:30 GMT
Repository: cxf
Updated Branches:
  refs/heads/master e681dda5b -> da53162f3


CXF-6360: Integration with Apache HTrace. Added sample application skeleton. Fixed minor issue
with new span creation.


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/da53162f
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/da53162f
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/da53162f

Branch: refs/heads/master
Commit: da53162f385fa73957626446cbd63ea269c1ee26
Parents: e681dda
Author: reta <drreta@gmail.com>
Authored: Thu Jun 25 20:58:12 2015 -0400
Committer: reta <drreta@gmail.com>
Committed: Thu Jun 25 20:58:12 2015 -0400

----------------------------------------------------------------------
 .../samples/jax_rs/tracing_htrace/README.txt    |  39 ++++++
 .../samples/jax_rs/tracing_htrace/pom.xml       | 140 +++++++++++++++++++
 .../java/demo/jaxrs/tracing/client/Client.java  |  31 ++++
 .../java/demo/jaxrs/tracing/server/Catalog.java | 106 ++++++++++++++
 .../java/demo/jaxrs/tracing/server/Server.java  |  41 ++++++
 distribution/src/main/release/samples/pom.xml   |   1 +
 .../tracing/htrace/AbstractHTraceProvider.java  |   3 +-
 7 files changed, 359 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/da53162f/distribution/src/main/release/samples/jax_rs/tracing_htrace/README.txt
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/tracing_htrace/README.txt b/distribution/src/main/release/samples/jax_rs/tracing_htrace/README.txt
new file mode 100644
index 0000000..cbbea95
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/tracing_htrace/README.txt
@@ -0,0 +1,39 @@
+JAX-RS Search Demo 
+=================
+
+The demo shows a basic usage of HTrace distributed tracer with REST based 
+Web Services using  JAX-RS 2.0 (JSR-339). The REST server provides the 
+following services: 
+
+A RESTful catalog service is provided on URL http://localhost:9000/catalog 
+
+A HTTP GET request to URL http://localhost:9000/catalog generates following 
+traces:
+
+A HTTP POST request to URL http://localhost:9000/catalog generates following 
+traces:
+
+A HTTP GET request to URL http://localhost:9000/catalog/<id> generates following 
+traces:
+
+A HTTP DELETE request to URL http://localhost:9000/catalog/<id> generates following

+traces:
+
+Building and running the demo using Maven
+---------------------------------------
+
+From the base directory of this sample (i.e., where this README file is
+located), the Maven pom.xml file can be used to build and run the demo. 
+
+
+Using either UNIX or Windows:
+
+  mvn install
+  mvn -Pserver  (from one command line window)
+  mvn -Pclient  (from a second command line window)
+    
+
+To remove the target dir, run mvn clean".
+
+
+

http://git-wip-us.apache.org/repos/asf/cxf/blob/da53162f/distribution/src/main/release/samples/jax_rs/tracing_htrace/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/tracing_htrace/pom.xml b/distribution/src/main/release/samples/jax_rs/tracing_htrace/pom.xml
new file mode 100644
index 0000000..c84bb96
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/tracing_htrace/pom.xml
@@ -0,0 +1,140 @@
+<?xml version="1.0"?>
+<!--
+  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/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>jax_rs_tracing_htrace</artifactId>
+    <name>JAX-RS Demo Using Distributed Tracing with Apache HTrace</name>
+    <description>JAX-RS Demo Using Distributed Tracing with Apache HTrace</description>
+    <parent>
+        <groupId>org.apache.cxf.samples</groupId>
+        <artifactId>cxf-samples</artifactId>
+        <version>3.1.2-SNAPSHOT</version>
+        <relativePath>../..</relativePath>
+    </parent>
+    <properties>
+        <cxf.version>${project.version}</cxf.version>
+        <httpclient.version>3.1</httpclient.version>
+    </properties>
+    <profiles>
+        <profile>
+            <id>server</id>
+            <build>
+                <defaultGoal>test</defaultGoal>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>exec-maven-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <phase>test</phase>
+                                <goals>
+                                    <goal>java</goal>
+                                </goals>
+                                <configuration>
+                                    <mainClass>demo.jaxrs.tracing.server.Server</mainClass>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+        <profile>
+            <id>client</id>
+            <build>
+                <defaultGoal>test</defaultGoal>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>exec-maven-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <phase>test</phase>
+                                <goals>
+                                    <goal>java</goal>
+                                </goals>
+                                <configuration>
+                                    <mainClass>demo.jaxrs.tracing.client.Client</mainClass>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-transports-http</artifactId>
+            <version>3.1.2-SNAPSHOT</version>
+        </dependency>
+        <!-- This dependency is needed if you're using the Jetty container -->
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-transports-http-jetty</artifactId>
+            <version>3.1.2-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+            <version>3.1.2-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-rs-client</artifactId>
+            <version>3.1.2-SNAPSHOT</version>
+        </dependency>	
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-integration-tracing-htrace</artifactId>
+            <version>3.1.2-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-rs-extension-providers</artifactId>
+            <version>3.1.2-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>javax.json</groupId>
+            <artifactId>javax.json-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.glassfish</groupId>
+            <artifactId>javax.json</artifactId>
+        </dependency>                    
+        <dependency>
+            <groupId>commons-lang</groupId>
+            <artifactId>commons-lang</artifactId>
+        </dependency>                        
+        <dependency>
+            <groupId>commons-httpclient</groupId>
+            <artifactId>commons-httpclient</artifactId>
+        </dependency>                
+        <dependency>
+            <groupId>javax.ws.rs</groupId>
+            <artifactId>javax.ws.rs-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-webapp</artifactId>
+        </dependency>		
+    </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/cxf/blob/da53162f/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/client/Client.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/client/Client.java
b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/client/Client.java
new file mode 100644
index 0000000..ee2ca0e
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/client/Client.java
@@ -0,0 +1,31 @@
+package demo.jaxrs.tracing.client;
+
+import java.util.Arrays;
+import java.util.HashMap;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.tracing.htrace.jaxrs.HTraceClientProvider;
+import org.apache.htrace.HTraceConfiguration;
+import org.apache.htrace.Trace;
+import org.apache.htrace.impl.AlwaysSampler;
+import org.apache.htrace.impl.StandardOutSpanReceiver;
+
+public class Client {
+    public static void main( final String[] args ) throws Exception {
+        final HashMap<String, String> properties = new HashMap<String, String>();
+        final HTraceConfiguration conf = HTraceConfiguration.fromMap(properties);
+        Trace.addReceiver(new StandardOutSpanReceiver(conf));
+        
+        final HTraceClientProvider provider = new HTraceClientProvider(new AlwaysSampler(conf));
+        final Response response = WebClient
+            .create("http://localhost:9000/catalog", Arrays.asList(provider))
+            .accept(MediaType.APPLICATION_JSON)
+            .get();
+        
+        System.out.println(response.readEntity(String.class));
+        response.close();
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/da53162f/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/Catalog.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/Catalog.java
b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/Catalog.java
new file mode 100644
index 0000000..7e7f52d
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/Catalog.java
@@ -0,0 +1,106 @@
+/**
+ * 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 java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonArrayBuilder;
+import javax.json.JsonObject;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.NotFoundException;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.container.AsyncResponse;
+import javax.ws.rs.container.Suspended;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+@Path("/catalog")
+public class Catalog {
+    private final ExecutorService executor = Executors.newFixedThreadPool(2);
+    private ConcurrentMap<String, String> books = new ConcurrentHashMap<>();
+    
+    @POST
+    @Produces(MediaType.APPLICATION_JSON)
+    public void addBook(@Suspended final AsyncResponse response, @Context final UriInfo uri,

+            @FormParam("title") final String title)  {
+        executor.submit(new Runnable() {
+            public void run() {
+            }
+        });
+    }
+    
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    public JsonArray getBooks() {
+        final JsonArrayBuilder builder = Json.createArrayBuilder();
+        
+        for (final Map.Entry<String, String> entry: books.entrySet()) {
+            builder.add(Json.createObjectBuilder()
+                .add("id", entry.getKey())
+                .add("title", entry.getValue())
+            );
+        }
+        
+        return builder.build();
+    }
+    
+    @GET
+    @Path("/{id}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public JsonObject getBook(@PathParam("id") final String id) {
+        final String title = books.get(id);
+        
+        if (title == null) {
+            throw new NotFoundException("Book with does not exists: " + id);
+        }
+        
+        return Json.createObjectBuilder()
+            .add("id", id)
+            .add("title", title)
+            .build();
+    }
+    
+    @DELETE
+    @Path("/{id}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response delete(@PathParam("id") final String id) {
+        if (books.remove(id) == null) {
+            throw new NotFoundException("Book with does not exists: " + id);
+        }
+        
+        return Response.ok().build();
+    }
+}
+
+

http://git-wip-us.apache.org/repos/asf/cxf/blob/da53162f/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/Server.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/Server.java
b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/Server.java
new file mode 100644
index 0000000..aff8c8b
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/Server.java
@@ -0,0 +1,41 @@
+package demo.jaxrs.tracing.server;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.cxf.jaxrs.provider.jsrjsonp.JsrJsonpProvider;
+import org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet;
+import org.apache.cxf.tracing.htrace.jaxrs.HTraceFeature;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+
+public class Server {
+    protected Server() throws Exception {
+        org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(9000);
+
+        // Register and map the dispatcher servlet
+        final ServletHolder servletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet());
+        final ServletContextHandler context = new ServletContextHandler();      
+        context.setContextPath("/");
+        context.addServlet(servletHolder, "/*");
+        
+        servletHolder.setInitParameter("jaxrs.serviceClasses", Catalog.class.getName());
+        servletHolder.setInitParameter("jaxrs.features", HTraceFeature.class.getName());
+        servletHolder.setInitParameter("jaxrs.providers", StringUtils.join(
+            new String[] { 
+                JsrJsonpProvider.class.getName()
+            }, ",") 
+        );                
+                
+        server.setHandler(context);
+        server.start();
+        server.join();
+    }
+
+    public static void main(String args[]) throws Exception {
+        new Server();
+        System.out.println("Server ready...");
+
+        Thread.sleep(5 * 6000 * 1000);
+        System.out.println("Server exiting");
+        System.exit(0);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/da53162f/distribution/src/main/release/samples/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/pom.xml b/distribution/src/main/release/samples/pom.xml
index f2354b7..8b5b413 100644
--- a/distribution/src/main/release/samples/pom.xml
+++ b/distribution/src/main/release/samples/pom.xml
@@ -104,6 +104,7 @@
         <module>ws_discovery</module>
         <module>ws_eventing</module>
         <module>throttling</module>
+        <module>jax_rs/tracing_htrace</module>
         
         <!--
          These are removed from the build as they currently don't inherit the parent from


http://git-wip-us.apache.org/repos/asf/cxf/blob/da53162f/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceProvider.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceProvider.java
b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceProvider.java
index 7d68417..dd9f3ed 100644
--- a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceProvider.java
+++ b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceProvider.java
@@ -55,8 +55,7 @@ public abstract class AbstractHTraceProvider extends AbstractTracingProvider
{
             Tracer.DONT_TRACE.spanId); 
         
         if (traceId == Tracer.DONT_TRACE.traceId || spanId == Tracer.DONT_TRACE.spanId) {
-            return Trace.startSpan(path, (Sampler< TraceInfo >)sampler, 
-                new TraceInfo(traceId, spanId));
+            return Trace.startSpan(path, (Sampler< TraceInfo >)sampler);
         } 
         
         return Trace.startSpan(path, new MilliSpan


Mime
View raw message