camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [1/2] camel git commit: CAMEL-7672- use of HeaderFilterStrategy to send message headers as stomp frames
Date Thu, 11 May 2017 11:31:59 GMT
Repository: camel
Updated Branches:
  refs/heads/master 153cfd142 -> 98b3d7eae


CAMEL-7672- use of HeaderFilterStrategy to send message headers as stomp frames


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

Branch: refs/heads/master
Commit: 978df307adc929c8451aca165bb0e731050cffee
Parents: 153cfd1
Author: onders86 <ondersezgin@gmail.com>
Authored: Tue May 9 15:02:36 2017 +0300
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Thu May 11 13:31:03 2017 +0200

----------------------------------------------------------------------
 .../src/main/docs/stomp-component.adoc          |  6 ++-
 .../camel/component/stomp/StompComponent.java   | 17 +++++++-
 .../camel/component/stomp/StompEndpoint.java    | 41 +++++++++++++++++++-
 .../springboot/StompComponentConfiguration.java | 16 ++++++++
 4 files changed, 75 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/978df307/components/camel-stomp/src/main/docs/stomp-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-stomp/src/main/docs/stomp-component.adoc b/components/camel-stomp/src/main/docs/stomp-component.adoc
index d1e735a..ec60fc5 100644
--- a/components/camel-stomp/src/main/docs/stomp-component.adoc
+++ b/components/camel-stomp/src/main/docs/stomp-component.adoc
@@ -34,7 +34,7 @@ Where *destination* is the name of the queue.
 
 
 // component options: START
-The Stomp component supports 7 options which are listed below.
+The Stomp component supports 8 options which are listed below.
 
 
 
@@ -47,6 +47,7 @@ The Stomp component supports 7 options which are listed below.
 | **passcode** (security) | The password |  | String
 | **host** (common) | The virtual host |  | String
 | **useGlobalSslContext Parameters** (security) | Enable usage of global SSL context parameters.
| false | boolean
+| **headerFilterStrategy** (filter) | To use a custom org.apache.camel.spi.HeaderFilterStrategy
to filter header to and from Camel message. |  | HeaderFilterStrategy
 | **resolveProperty Placeholders** (advanced) | Whether the component should resolve property
placeholders on itself when starting. Only properties which are of String type can use property
placeholders. | true | boolean
 |=======================================================================
 // component options: END
@@ -70,7 +71,7 @@ with the following path and query parameters:
 | **destination** | *Required* Name of the queue |  | String
 |=======================================================================
 
-#### Query Parameters (9 parameters):
+#### Query Parameters (10 parameters):
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |=======================================================================
@@ -80,6 +81,7 @@ with the following path and query parameters:
 | **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
 | **exceptionHandler** (consumer) | To let the consumer use a custom ExceptionHandler. Notice
if the option bridgeErrorHandler is enabled then this options is not in use. By default the
consumer will deal with exceptions that will be logged at WARN or ERROR level and ignored.
|  | ExceptionHandler
 | **exchangePattern** (consumer) | Sets the exchange pattern when the consumer creates an
exchange. |  | ExchangePattern
+| **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
 | **login** (security) | The username |  | String
 | **passcode** (security) | The password |  | String

http://git-wip-us.apache.org/repos/asf/camel/blob/978df307/components/camel-stomp/src/main/java/org/apache/camel/component/stomp/StompComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-stomp/src/main/java/org/apache/camel/component/stomp/StompComponent.java
b/components/camel-stomp/src/main/java/org/apache/camel/component/stomp/StompComponent.java
index 6519e7d..10bb93b 100644
--- a/components/camel-stomp/src/main/java/org/apache/camel/component/stomp/StompComponent.java
+++ b/components/camel-stomp/src/main/java/org/apache/camel/component/stomp/StompComponent.java
@@ -20,10 +20,11 @@ import java.util.Map;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.SSLContextParametersAware;
-import org.apache.camel.impl.UriEndpointComponent;
+import org.apache.camel.impl.DefaultHeaderFilterStrategy;
+import org.apache.camel.impl.HeaderFilterStrategyComponent;
 import org.apache.camel.spi.Metadata;
 
-public class StompComponent extends UriEndpointComponent implements SSLContextParametersAware
{
+public class StompComponent extends HeaderFilterStrategyComponent implements SSLContextParametersAware
{
 
     @Metadata(label = "advanced")
     private StompConfiguration configuration = new StompConfiguration();
@@ -39,6 +40,17 @@ public class StompComponent extends UriEndpointComponent implements SSLContextPa
     public StompComponent() {
         super(StompEndpoint.class);
     }
+    
+    // Implementation methods
+    // -------------------------------------------------------------------------
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+        if (getHeaderFilterStrategy() == null) {
+            setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
+        }
+    }
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object>
parameters) throws Exception {
@@ -55,6 +67,7 @@ public class StompComponent extends UriEndpointComponent implements SSLContextPa
         if (config.getSslContextParameters() == null) {
             config.setSslContextParameters(retrieveGlobalSslContextParameters());
         }
+        endpoint.setHeaderFilterStrategy(getHeaderFilterStrategy());
 
         return endpoint;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/978df307/components/camel-stomp/src/main/java/org/apache/camel/component/stomp/StompEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-stomp/src/main/java/org/apache/camel/component/stomp/StompEndpoint.java
b/components/camel-stomp/src/main/java/org/apache/camel/component/stomp/StompEndpoint.java
index 44258e9..d0ee552 100644
--- a/components/camel-stomp/src/main/java/org/apache/camel/component/stomp/StompEndpoint.java
+++ b/components/camel-stomp/src/main/java/org/apache/camel/component/stomp/StompEndpoint.java
@@ -17,6 +17,8 @@
 package org.apache.camel.component.stomp;
 
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.apache.camel.AsyncCallback;
@@ -26,6 +28,9 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.impl.DefaultHeaderFilterStrategy;
+import org.apache.camel.spi.HeaderFilterStrategy;
+import org.apache.camel.spi.HeaderFilterStrategyAware;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
@@ -50,7 +55,7 @@ import static org.fusesource.stomp.client.Constants.UNSUBSCRIBE;
  * The stomp component is used for communicating with Stomp compliant message brokers.
  */
 @UriEndpoint(firstVersion = "2.12.0", scheme = "stomp", title = "Stomp", syntax = "stomp:destination",
consumerClass = StompConsumer.class, label = "messaging")
-public class StompEndpoint extends DefaultEndpoint implements AsyncEndpoint {
+public class StompEndpoint extends DefaultEndpoint implements AsyncEndpoint, HeaderFilterStrategyAware
{
 
     @UriPath(description = "Name of the queue") @Metadata(required = "true")
     private String destination;
@@ -58,6 +63,8 @@ public class StompEndpoint extends DefaultEndpoint implements AsyncEndpoint
{
     private StompConfiguration configuration;
     private CallbackConnection connection;
     private Stomp stomp;
+    @UriParam(label = "advanced", description = "To use a custom HeaderFilterStrategy to
filter header to and from Camel message.")
+    private HeaderFilterStrategy headerFilterStrategy;
 
     private final List<StompConsumer> consumers = new CopyOnWriteArrayList<StompConsumer>();
 
@@ -137,6 +144,10 @@ public class StompEndpoint extends DefaultEndpoint implements AsyncEndpoint
{
 
     protected void send(final Exchange exchange, final AsyncCallback callback) {
         final StompFrame frame = new StompFrame(SEND);
+        
+        // feature for CAMEL-7672
+        populateCamelMessageHeadersToStompFrames(exchange, frame);
+        
         frame.addHeader(DESTINATION, StompFrame.encodeHeader(destination));
         //Fix for CAMEL-9506 leveraging the camel converter to do the change
         frame.content(utf8(exchange.getIn().getBody(String.class)));
@@ -160,6 +171,20 @@ public class StompEndpoint extends DefaultEndpoint implements AsyncEndpoint
{
         });
     }
 
+    private void populateCamelMessageHeadersToStompFrames(final Exchange exchange, final
StompFrame frame) {
+        Set<Map.Entry<String, Object>> entries = exchange.getIn().getHeaders().entrySet();
       
+        for (Map.Entry<String, Object> entry : entries) {
+            String headerName = entry.getKey();
+            Object headerValue = entry.getValue();
+            if (!headerName.toLowerCase().startsWith("camel") 
+                && !headerFilterStrategy.applyFilterToCamelHeaders(headerName, headerValue,
exchange)) {
+                if (headerValue != null) {
+                    frame.addHeader(new AsciiBuffer(headerName), StompFrame.encodeHeader(headerValue.toString()));
+                }
+            }
+        }
+    }
+
     void addConsumer(final StompConsumer consumer) {
         connection.getDispatchQueue().execute(new Task() {
             @Override
@@ -189,4 +214,18 @@ public class StompEndpoint extends DefaultEndpoint implements AsyncEndpoint
{
     AsciiBuffer getNextId() {
         return connection.nextId();
     }
+    
+    public HeaderFilterStrategy getHeaderFilterStrategy() {
+        if (headerFilterStrategy == null) {
+            headerFilterStrategy = new DefaultHeaderFilterStrategy();
+        }
+        return headerFilterStrategy;
+    }
+
+    /**
+     * To use a custom HeaderFilterStrategy to filter header to and from Camel message.
+     */
+    public void setHeaderFilterStrategy(HeaderFilterStrategy strategy) {
+        this.headerFilterStrategy = strategy;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/978df307/platforms/spring-boot/components-starter/camel-stomp-starter/src/main/java/org/apache/camel/component/stomp/springboot/StompComponentConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-stomp-starter/src/main/java/org/apache/camel/component/stomp/springboot/StompComponentConfiguration.java
b/platforms/spring-boot/components-starter/camel-stomp-starter/src/main/java/org/apache/camel/component/stomp/springboot/StompComponentConfiguration.java
index 2671bd5..39f7c7a 100644
--- a/platforms/spring-boot/components-starter/camel-stomp-starter/src/main/java/org/apache/camel/component/stomp/springboot/StompComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-stomp-starter/src/main/java/org/apache/camel/component/stomp/springboot/StompComponentConfiguration.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.stomp.springboot;
 
 import javax.annotation.Generated;
+import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.camel.util.jsse.SSLContextParameters;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.boot.context.properties.NestedConfigurationProperty;
@@ -56,6 +57,12 @@ public class StompComponentConfiguration {
      */
     private Boolean useGlobalSslContextParameters = false;
     /**
+     * To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter
+     * header to and from Camel message.
+     */
+    @NestedConfigurationProperty
+    private HeaderFilterStrategy headerFilterStrategy;
+    /**
      * Whether the component should resolve property placeholders on itself when
      * starting. Only properties which are of String type can use property
      * placeholders.
@@ -112,6 +119,15 @@ public class StompComponentConfiguration {
         this.useGlobalSslContextParameters = useGlobalSslContextParameters;
     }
 
+    public HeaderFilterStrategy getHeaderFilterStrategy() {
+        return headerFilterStrategy;
+    }
+
+    public void setHeaderFilterStrategy(
+            HeaderFilterStrategy headerFilterStrategy) {
+        this.headerFilterStrategy = headerFilterStrategy;
+    }
+
     public Boolean getResolvePropertyPlaceholders() {
         return resolvePropertyPlaceholders;
     }


Mime
View raw message