cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6360] Prototyping CXF HTrace interceptors
Date Fri, 05 Jun 2015 15:51:03 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 0ac5dde07 -> 884e8a2bf


[CXF-6360] Prototyping CXF HTrace interceptors


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

Branch: refs/heads/master
Commit: 884e8a2bf207a92719a770f138e9ae0edede896a
Parents: 0ac5dde
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Fri Jun 5 16:50:48 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Fri Jun 5 16:50:48 2015 +0100

----------------------------------------------------------------------
 .../htrace/AbstractHTraceInterceptor.java       | 59 ++++++++++++++++++++
 .../tracing/htrace/HTraceStartInterceptor.java  | 42 ++++++++++++++
 .../tracing/htrace/HTraceStopInterceptor.java   | 50 +++++++++++++++++
 3 files changed, 151 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/884e8a2b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceInterceptor.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceInterceptor.java
b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceInterceptor.java
new file mode 100644
index 0000000..7465585
--- /dev/null
+++ b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceInterceptor.java
@@ -0,0 +1,59 @@
+/**
+ * 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.cxf.tracing.htrace;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.PhaseInterceptor;
+import org.apache.htrace.Sampler;
+
+public abstract class AbstractHTraceInterceptor extends AbstractHTraceProvider implements
PhaseInterceptor<Message> {
+    private String phase;
+    protected AbstractHTraceInterceptor(final String phase, final Sampler< ? > sampler)
{
+        super(sampler);
+        this.phase = phase;
+    }
+    
+    public Collection<PhaseInterceptor<? extends Message>> getAdditionalInterceptors()
{
+        return null;
+    }
+
+    public Set<String> getAfter() {
+        return Collections.emptySet();
+    }
+
+    public Set<String> getBefore() {
+        return Collections.emptySet();
+    }
+
+    public String getId() {
+        return getClass().getName();
+    }
+
+    public String getPhase() {
+        return phase;
+    }
+    
+    public void handleFault(Message message) {
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/884e8a2b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceStartInterceptor.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceStartInterceptor.java
b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceStartInterceptor.java
new file mode 100644
index 0000000..cce392d
--- /dev/null
+++ b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceStartInterceptor.java
@@ -0,0 +1,42 @@
+/**
+ * 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.cxf.tracing.htrace;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.htrace.Sampler;
+import org.apache.htrace.TraceScope;
+
+public class HTraceStartInterceptor extends AbstractHTraceInterceptor {
+    public HTraceStartInterceptor(final String phase, final Sampler< ? > sampler) {
+        super(phase, sampler);
+    }
+
+    @Override
+    public void handleMessage(Message message) throws Fault {
+        Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));

+        TraceScope scope = super.startTraceSpan(headers, (String)message.get(Message.REQUEST_URI));
+        message.getExchange().put(TRACE_SPAN, scope);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/884e8a2b/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
new file mode 100644
index 0000000..e43b0ab
--- /dev/null
+++ b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceStopInterceptor.java
@@ -0,0 +1,50 @@
+/**
+ * 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.cxf.tracing.htrace;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageUtils;
+import org.apache.htrace.TraceScope;
+
+public class HTraceStopInterceptor extends AbstractHTraceInterceptor {
+    public HTraceStopInterceptor(final String phase) {
+        super(phase, null);
+    }
+
+    @Override
+    public void handleMessage(Message message) throws Fault {
+        Map<String, List<Object>> responseHeaders = CastUtils.cast((Map<?,
?>)message.get(Message.PROTOCOL_HEADERS));
+        
+        boolean isRequestor = MessageUtils.isRequestor(message);
+        Message requestMessage = isRequestor ? message.getExchange().getOutMessage() 
+            : message.getExchange().getInMessage();
+        Map<String, List<String>> requestHeaders =  
+            CastUtils.cast((Map<?, ?>)requestMessage.get(Message.PROTOCOL_HEADERS));
+        
+        TraceScope span = (TraceScope)message.getExchange().get(TRACE_SPAN);
+        
+        super.stopTraceSpan(requestHeaders, responseHeaders, span);
+    }
+    
+}


Mime
View raw message