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

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 7ed4426  CAMEL-15576: camel-tracing fixed HTTP verb which is enum 
based in span report for http components.
7ed4426 is described below

commit 7ed44265775511a528b8ca8b97db488be5f4f85f
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Fri Oct 9 07:23:05 2020 +0200

    CAMEL-15576: camel-tracing fixed HTTP verb which is enum based in span 
report for http components.
---
 .../decorators/AbstractHttpSpanDecorator.java      |  4 ++++
 .../decorators/AbstractHttpSpanDecoratorTest.java  | 11 +++++++++
 .../camel/tracing/decorators/HttpMethods.java      | 26 ++++++++++++++++++++++
 3 files changed, 41 insertions(+)

diff --git 
a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/AbstractHttpSpanDecorator.java
 
b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/AbstractHttpSpanDecorator.java
index cbdc67b..c491927 100644
--- 
a/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/AbstractHttpSpanDecorator.java
+++ 
b/components/camel-tracing/src/main/java/org/apache/camel/tracing/decorators/AbstractHttpSpanDecorator.java
@@ -32,6 +32,10 @@ public abstract class AbstractHttpSpanDecorator extends 
AbstractSpanDecorator {
         Object method = exchange.getIn().getHeader(Exchange.HTTP_METHOD);
         if (method instanceof String) {
             return (String) method;
+        } else if (method instanceof Enum) {
+            return ((Enum<?>) method).name();
+        } else if (method != null) {
+            return 
exchange.getContext().getTypeConverter().tryConvertTo(String.class, exchange, 
method);
         }
 
         // 2. GET if query string is provided in header.
diff --git 
a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/AbstractHttpSpanDecoratorTest.java
 
b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/AbstractHttpSpanDecoratorTest.java
index 56825db..3cacc99 100644
--- 
a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/AbstractHttpSpanDecoratorTest.java
+++ 
b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/AbstractHttpSpanDecoratorTest.java
@@ -67,6 +67,17 @@ public class AbstractHttpSpanDecoratorTest {
     }
 
     @Test
+    public void testGetMethodFromMethodHeaderEnum() {
+        Exchange exchange = Mockito.mock(Exchange.class);
+        Message message = Mockito.mock(Message.class);
+
+        Mockito.when(exchange.getIn()).thenReturn(message);
+        
Mockito.when(message.getHeader(Exchange.HTTP_METHOD)).thenReturn(HttpMethods.GET);
+
+        assertEquals("GET", AbstractHttpSpanDecorator.getHttpMethod(exchange, 
null));
+    }
+
+    @Test
     public void testGetMethodQueryStringHeader() {
         Exchange exchange = Mockito.mock(Exchange.class);
         Message message = Mockito.mock(Message.class);
diff --git 
a/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/HttpMethods.java
 
b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/HttpMethods.java
new file mode 100644
index 0000000..ad692c9
--- /dev/null
+++ 
b/components/camel-tracing/src/test/java/org/apache/camel/tracing/decorators/HttpMethods.java
@@ -0,0 +1,26 @@
+/*
+ * 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.camel.tracing.decorators;
+
+public enum HttpMethods {
+
+    DELETE,
+    GET,
+    PATCH,
+    POST,
+    PUT
+}

Reply via email to