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. Completed JAX-WS test case for HTrace tracing.
Date Thu, 24 Sep 2015 00:22:35 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 5c2d09810 -> 9df377971


CXF-6360: Integration with Apache HTrace. Completed JAX-WS test case for HTrace tracing.


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

Branch: refs/heads/master
Commit: 9df377971980a0224f9a03f605c48f075d720446
Parents: 5c2d098
Author: reta <drreta@gmail.com>
Authored: Wed Sep 23 20:22:07 2015 -0400
Committer: reta <drreta@gmail.com>
Committed: Wed Sep 23 20:22:07 2015 -0400

----------------------------------------------------------------------
 .../tracing/htrace/HTraceStopInterceptor.java   |  6 ++++
 .../jaxws/tracing/htrace/HTraceTracingTest.java | 33 +++++++++++++++++---
 2 files changed, 35 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/9df37797/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceStopInterceptor.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceStopInterceptor.java
b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceStopInterceptor.java
index e43b0ab..2bb1da6 100644
--- a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceStopInterceptor.java
+++ b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceStopInterceptor.java
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.tracing.htrace;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -36,6 +37,11 @@ public class HTraceStopInterceptor extends AbstractHTraceInterceptor {
     public void handleMessage(Message message) throws Fault {
         Map<String, List<Object>> responseHeaders = CastUtils.cast((Map<?,
?>)message.get(Message.PROTOCOL_HEADERS));
         
+        if (responseHeaders == null) {
+            responseHeaders = new HashMap<String, List<Object>>();
+            message.put(Message.PROTOCOL_HEADERS, responseHeaders);
+        }
+        
         boolean isRequestor = MessageUtils.isRequestor(message);
         Message requestMessage = isRequestor ? message.getExchange().getOutMessage() 
             : message.getExchange().getInMessage();

http://git-wip-us.apache.org/repos/asf/cxf/blob/9df37797/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/htrace/HTraceTracingTest.java
----------------------------------------------------------------------
diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/htrace/HTraceTracingTest.java
b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/htrace/HTraceTracingTest.java
index 0e6f297..684a4b4 100644
--- a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/htrace/HTraceTracingTest.java
+++ b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/htrace/HTraceTracingTest.java
@@ -26,6 +26,7 @@ import java.util.Map;
 
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.frontend.ClientProxy;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.LoggingInInterceptor;
 import org.apache.cxf.interceptor.LoggingOutInterceptor;
 import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
@@ -49,6 +50,8 @@ import org.junit.Ignore;
 import org.junit.Test;
 
 import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.hasItems;
+import static org.hamcrest.CoreMatchers.nullValue;
 
 public class HTraceTracingTest extends AbstractBusClientServerTestBase {
     public static final String PORT = allocatePort(HTraceTracingTest.class);
@@ -64,7 +67,7 @@ public class HTraceTracingTest extends AbstractBusClientServerTestBase {
             sf.setServiceClass(BookStore.class);
             sf.setAddress("http://localhost:" + PORT);
             sf.getInInterceptors().add(new HTraceStartInterceptor(Phase.PRE_INVOKE, new AlwaysSampler(conf)));
-            sf.getOutInterceptors().add(new HTraceStopInterceptor(Phase.POST_MARSHAL));
+            sf.getOutInterceptors().add(new HTraceStopInterceptor(Phase.PRE_MARSHAL));
             sf.create();
         }
     }
@@ -89,6 +92,10 @@ public class HTraceTracingTest extends AbstractBusClientServerTestBase
{
         assertThat(TestSpanReceiver.getAllSpans().size(), equalTo(2));
         assertThat(TestSpanReceiver.getAllSpans().get(0).getDescription(), equalTo("Get Books"));
         assertThat(TestSpanReceiver.getAllSpans().get(1).getDescription(), equalTo("POST
/BookStore"));
+        
+        final Map<String, List<String>> response = getResponseHeaders(service);
+        assertThat(response.get(TracerHeaders.DEFAULT_HEADER_TRACE_ID), nullValue());
+        assertThat(response.get(TracerHeaders.DEFAULT_HEADER_SPAN_ID), nullValue());
     }
     
     @Test
@@ -97,22 +104,40 @@ public class HTraceTracingTest extends AbstractBusClientServerTestBase
{
         final Client proxy = ClientProxy.getClient(service);
         
         final Map<String, List<String>> headers = new HashMap<String, List<String>>();
-        headers.put(TracerHeaders.DEFAULT_HEADER_TRACE_ID, Arrays.asList("10L"));
-        headers.put(TracerHeaders.DEFAULT_HEADER_SPAN_ID, Arrays.asList("20L"));        
+        headers.put(TracerHeaders.DEFAULT_HEADER_TRACE_ID, Arrays.asList("10"));
+        headers.put(TracerHeaders.DEFAULT_HEADER_SPAN_ID, Arrays.asList("20"));
         proxy.getRequestContext().put(Message.PROTOCOL_HEADERS, headers);
         assertThat(service.getBooks().size(), equalTo(2));
         
         assertThat(TestSpanReceiver.getAllSpans().size(), equalTo(2));
         assertThat(TestSpanReceiver.getAllSpans().get(0).getDescription(), equalTo("Get Books"));
         assertThat(TestSpanReceiver.getAllSpans().get(1).getDescription(), equalTo("POST
/BookStore"));
+        
+        final Map<String, List<String>> response = getResponseHeaders(service);
+        assertThat(response.get(TracerHeaders.DEFAULT_HEADER_TRACE_ID), hasItems("10"));
+        assertThat(response.get(TracerHeaders.DEFAULT_HEADER_SPAN_ID), hasItems("20"));
     }
     
-    protected BookStoreService createJaxWsService() throws MalformedURLException {
+    private BookStoreService createJaxWsService() throws MalformedURLException {
+        return createJaxWsService(new HashMap<String, List<String>>());
+    }
+    
+    private BookStoreService createJaxWsService(final Map<String, List<String>>
headers) throws MalformedURLException {
         JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
         factory.getOutInterceptors().add(new LoggingOutInterceptor());
         factory.getInInterceptors().add(new LoggingInInterceptor());
         factory.setServiceClass(BookStoreService.class);
         factory.setAddress("http://localhost:" + PORT + "/BookStore");
+        
+        final BookStoreService service = (BookStoreService) factory.create();
+        final Client proxy = ClientProxy.getClient(service);
+        proxy.getRequestContext().put(Message.PROTOCOL_HEADERS, headers);
+        
         return (BookStoreService) factory.create();
     }
+    
+    private Map<String, List<String>> getResponseHeaders(final BookStoreService
service) {
+        final Client proxy = ClientProxy.getClient(service);
+        return CastUtils.cast((Map<?, ?>)proxy.getResponseContext().get(Message.PROTOCOL_HEADERS));
+    }    
 }


Mime
View raw message