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

ffang 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 6994565  [CAMEL-13637]be able to enable access log for camel-undertow 
consumer endpoint
6994565 is described below

commit 69945655c1fcd59b6d75e0469e92b6c80f1d9875
Author: Freeman Fang <freeman.f...@gmail.com>
AuthorDate: Wed Jun 12 12:02:10 2019 -0400

    [CAMEL-13637]be able to enable access log for camel-undertow consumer 
endpoint
---
 .../src/main/docs/undertow-component.adoc          |  4 ++-
 .../camel/component/undertow/UndertowConsumer.java | 18 +++++++++++++-
 .../camel/component/undertow/UndertowEndpoint.java | 29 ++++++++++++++++++++++
 .../src/test/resources/SpringTest.xml              |  4 ++-
 4 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/components/camel-undertow/src/main/docs/undertow-component.adoc 
b/components/camel-undertow/src/main/docs/undertow-component.adoc
index 80dca7c..ef66c97 100644
--- a/components/camel-undertow/src/main/docs/undertow-component.adoc
+++ b/components/camel-undertow/src/main/docs/undertow-component.adoc
@@ -79,12 +79,13 @@ with the following path and query parameters:
 |===
 
 
-==== Query Parameters (23 parameters):
+==== Query Parameters (25 parameters):
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
+| *accessLog* (consumer) | Whether or not the consumer should write access log 
| false | Boolean
 | *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the 
Camel routing Error Handler, which mean any exceptions occurred while the 
consumer is trying to pickup incoming messages, or the likes, will now be 
processed as a message and handled by the routing Error Handler. By default the 
consumer will use the org.apache.camel.spi.ExceptionHandler to deal with 
exceptions, that will be logged at WARN or ERROR level and ignored. | false | 
boolean
 | *httpMethodRestrict* (consumer) | Used to only allow consuming if the 
HttpMethod matches, such as GET/POST/PUT etc. Multiple methods can be specified 
separated by comma. |  | String
 | *matchOnUriPrefix* (consumer) | Whether or not the consumer should try to 
find a target consumer by matching the URI prefix if no exact match is found. | 
false | Boolean
@@ -99,6 +100,7 @@ with the following path and query parameters:
 | *tcpNoDelay* (producer) | Setting to improve TCP protocol performance | true 
| Boolean
 | *throwExceptionOnFailure* (producer) | Option to disable throwing the 
HttpOperationFailedException in case of failed responses from the remote 
server. This allows you to get all responses regardless of the HTTP status 
code. | true | Boolean
 | *transferException* (producer) | If enabled and an Exchange failed 
processing on the consumer side and if the caused Exception was send back 
serialized in the response as a application/x-java-serialized-object content 
type. On the producer side the exception will be deserialized and thrown as is 
instead of the HttpOperationFailedException. The caused exception is required 
to be serialized. This is by default turned off. If you enable this then be 
aware that Java will deserialize the in [...]
+| *accessLogReceiver* (advanced) | Which Undertow AccessLogReciever should be 
used Will use JBossLoggingAccessLogReceiver if not specifid |  | 
AccessLogReceiver
 | *basicPropertyBinding* (advanced) | Whether the endpoint should use basic 
property binding (Camel 2.x) or the newer property binding with additional 
capabilities | false | boolean
 | *headerFilterStrategy* (advanced) | To use a custom HeaderFilterStrategy to 
filter header to and from Camel message. |  | HeaderFilterStrategy
 | *synchronous* (advanced) | Sets whether synchronous processing should be 
strictly used, or Camel is allowed to use asynchronous processing (if 
supported). | false | boolean
diff --git 
a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
 
b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
index 11b41c5..d700bf1 100644
--- 
a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
+++ 
b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
@@ -24,6 +24,9 @@ import java.util.Collection;
 import io.undertow.Handlers;
 import io.undertow.server.HttpHandler;
 import io.undertow.server.HttpServerExchange;
+import io.undertow.server.handlers.accesslog.AccessLogHandler;
+import io.undertow.server.handlers.accesslog.AccessLogReceiver;
+import io.undertow.server.handlers.accesslog.JBossLoggingAccessLogReceiver;
 import io.undertow.server.handlers.form.EagerFormParsingHandler;
 import io.undertow.util.Headers;
 import io.undertow.util.HttpString;
@@ -71,9 +74,22 @@ public class UndertowConsumer extends DefaultConsumer 
implements HttpHandler {
             this.webSocketHandler.setConsumer(this);
         } else {
             // allow for HTTP 1.1 continue
+            HttpHandler httpHandler = new 
EagerFormParsingHandler().setNext(UndertowConsumer.this);
+            if (endpoint.getAccessLog()) {
+                AccessLogReceiver accessLogReciever = null;
+                if (endpoint.getAccessLogReceiver() != null) {
+                    accessLogReciever = endpoint.getAccessLogReceiver();
+                } else {
+                    accessLogReciever = new JBossLoggingAccessLogReceiver();
+                }
+                httpHandler = new AccessLogHandler(httpHandler,
+                                                   accessLogReciever,
+                                                   "common",
+                                                   
AccessLogHandler.class.getClassLoader());
+            }
             
endpoint.getComponent().registerEndpoint(endpoint.getHttpHandlerRegistrationInfo(),
 endpoint.getSslContext(), Handlers.httpContinueRead(
                     // wrap with EagerFormParsingHandler to enable undertow 
form parsers
-                    new 
EagerFormParsingHandler().setNext(UndertowConsumer.this)));
+                    httpHandler));
         }
     }
 
diff --git 
a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowEndpoint.java
 
b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowEndpoint.java
index 63f0799..d1ab5b1 100644
--- 
a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowEndpoint.java
+++ 
b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowEndpoint.java
@@ -22,6 +22,8 @@ import java.util.Map;
 import javax.net.ssl.SSLContext;
 
 import io.undertow.server.HttpServerExchange;
+import io.undertow.server.handlers.accesslog.AccessLogReceiver;
+
 import org.apache.camel.AsyncEndpoint;
 import org.apache.camel.Consumer;
 import org.apache.camel.Exchange;
@@ -67,6 +69,8 @@ public class UndertowEndpoint extends DefaultEndpoint 
implements AsyncEndpoint,
     @UriParam(label = "advanced")
     private UndertowHttpBinding undertowHttpBinding;
     @UriParam(label = "advanced")
+    private AccessLogReceiver accessLogReceiver;
+    @UriParam(label = "advanced")
     private HeaderFilterStrategy headerFilterStrategy = new 
UndertowHeaderFilterStrategy();
     @UriParam(label = "security")
     private SSLContextParameters sslContextParameters;
@@ -74,6 +78,8 @@ public class UndertowEndpoint extends DefaultEndpoint 
implements AsyncEndpoint,
     private String httpMethodRestrict;
     @UriParam(label = "consumer", defaultValue = "false")
     private Boolean matchOnUriPrefix = Boolean.FALSE;
+    @UriParam(label = "consumer", defaultValue = "false")
+    private Boolean accessLog = Boolean.FALSE;
     @UriParam(label = "producer", defaultValue = "true")
     private Boolean throwExceptionOnFailure = Boolean.TRUE;
     @UriParam(label = "producer", defaultValue = "false")
@@ -457,4 +463,27 @@ public class UndertowEndpoint extends DefaultEndpoint 
implements AsyncEndpoint,
         return webSocketHttpHandler;
     }
 
+    public Boolean getAccessLog() {
+        return accessLog;
+    }
+
+    /**
+     * Whether or not the consumer should write access log
+     */
+    public void setAccessLog(Boolean accessLog) {
+        this.accessLog = accessLog;
+    }
+
+    public AccessLogReceiver getAccessLogReceiver() {
+        return accessLogReceiver;
+    }
+
+    /**
+     * Which Undertow AccessLogReciever should be used
+     * Will use JBossLoggingAccessLogReceiver if not specifid
+     */
+    public void setAccessLogReceiver(AccessLogReceiver accessLogReceiver) {
+        this.accessLogReceiver = accessLogReceiver;
+    }
+
 }
diff --git a/components/camel-undertow/src/test/resources/SpringTest.xml 
b/components/camel-undertow/src/test/resources/SpringTest.xml
index c1becd7..32177f9 100644
--- a/components/camel-undertow/src/test/resources/SpringTest.xml
+++ b/components/camel-undertow/src/test/resources/SpringTest.xml
@@ -50,8 +50,10 @@
         </property>
     </bean>
 
+    <bean id="accessLogReceiver" 
class="io.undertow.server.handlers.accesslog.JBossLoggingAccessLogReceiver"/>
+
     <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring";>
-        <endpoint id="input" 
uri="undertow:https://localhost:#{dynaPort}/spring?sslContextParameters=#sslContextParameters"/>
+        <endpoint id="input" 
uri="undertow:https://localhost:#{dynaPort}/spring?sslContextParameters=#sslContextParameters&amp;accessLog=true&amp;accessLogReceiver=#accessLogReceiver"/>
 
         <route>
             <from uri="ref:input"/>

Reply via email to