You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ni...@apache.org on 2013/02/06 13:42:42 UTC

svn commit: r1442936 - in /servicemix/components/trunk/engines/servicemix-camel/src: main/java/org/apache/servicemix/camel/ main/java/org/apache/servicemix/camel/util/ test/java/org/apache/servicemix/camel/util/

Author: ningjiang
Date: Wed Feb  6 12:42:42 2013
New Revision: 1442936

URL: http://svn.apache.org/viewvc?rev=1442936&view=rev
Log:
SMXCOMP-964 Added DefaultJBIHeaderFilterStrategy to avoid copy the javax.jbi headers between Camel exchange and JBI exchange.

Added:
    servicemix/components/trunk/engines/servicemix-camel/src/main/java/org/apache/servicemix/camel/util/DefaultJBIHeaderFilterStrategy.java
    servicemix/components/trunk/engines/servicemix-camel/src/test/java/org/apache/servicemix/camel/util/DefaultJBIHeaderFilterStrategyTest.java
Modified:
    servicemix/components/trunk/engines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiBinding.java

Modified: servicemix/components/trunk/engines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiBinding.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/engines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiBinding.java?rev=1442936&r1=1442935&r2=1442936&view=diff
==============================================================================
--- servicemix/components/trunk/engines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiBinding.java (original)
+++ servicemix/components/trunk/engines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiBinding.java Wed Feb  6 12:42:42 2013
@@ -39,6 +39,7 @@ import org.apache.camel.Message;
 import org.apache.camel.impl.DefaultExchange;
 import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.servicemix.camel.util.BasicSerializationHeaderFilterStrategy;
+import org.apache.servicemix.camel.util.DefaultJBIHeaderFilterStrategy;
 import org.apache.servicemix.camel.util.HeaderFilterStrategies;
 import org.apache.servicemix.camel.util.HeaderFilterStrategyConstants;
 import org.apache.servicemix.camel.util.NoCheckSerializationHeaderFilterStrategy;
@@ -47,6 +48,7 @@ import org.apache.servicemix.jbi.excepti
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+
 /**
  * The binding of how Camel messages get mapped to JBI and back again
  *
@@ -87,6 +89,9 @@ public class JbiBinding {
                 strategies.add(new BasicSerializationHeaderFilterStrategy());
             }
         }
+        // Added the DefaultJBIHeaderFilter by default
+        strategies.add(new DefaultJBIHeaderFilterStrategy());
+
     }
 
     public void addHeaderFilterStrategy(HeaderFilterStrategy strategy) {

Added: servicemix/components/trunk/engines/servicemix-camel/src/main/java/org/apache/servicemix/camel/util/DefaultJBIHeaderFilterStrategy.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/engines/servicemix-camel/src/main/java/org/apache/servicemix/camel/util/DefaultJBIHeaderFilterStrategy.java?rev=1442936&view=auto
==============================================================================
--- servicemix/components/trunk/engines/servicemix-camel/src/main/java/org/apache/servicemix/camel/util/DefaultJBIHeaderFilterStrategy.java (added)
+++ servicemix/components/trunk/engines/servicemix-camel/src/main/java/org/apache/servicemix/camel/util/DefaultJBIHeaderFilterStrategy.java Wed Feb  6 12:42:42 2013
@@ -0,0 +1,40 @@
+/*
+ * 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.servicemix.camel.util;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.HeaderFilterStrategy;
+
+public class DefaultJBIHeaderFilterStrategy implements HeaderFilterStrategy {
+
+    public boolean applyFilterToCamelHeaders(String s, Object o, Exchange exchange) {
+        return doApplyFilter(s);
+    }
+
+    public boolean applyFilterToExternalHeaders(String s, Object o, Exchange exchange) {
+        return doApplyFilter(s);
+    }
+
+    // Here we should filter the jbi message headers which should be not be exposed to Camel
+    private boolean doApplyFilter(String header) {
+        if (header.startsWith("javax.jbi.")) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+}

Added: servicemix/components/trunk/engines/servicemix-camel/src/test/java/org/apache/servicemix/camel/util/DefaultJBIHeaderFilterStrategyTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/engines/servicemix-camel/src/test/java/org/apache/servicemix/camel/util/DefaultJBIHeaderFilterStrategyTest.java?rev=1442936&view=auto
==============================================================================
--- servicemix/components/trunk/engines/servicemix-camel/src/test/java/org/apache/servicemix/camel/util/DefaultJBIHeaderFilterStrategyTest.java (added)
+++ servicemix/components/trunk/engines/servicemix-camel/src/test/java/org/apache/servicemix/camel/util/DefaultJBIHeaderFilterStrategyTest.java Wed Feb  6 12:42:42 2013
@@ -0,0 +1,33 @@
+/*
+ * 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.servicemix.camel.util;
+
+import junit.framework.TestCase;
+import org.apache.camel.spi.HeaderFilterStrategy;
+
+import java.util.HashMap;
+
+public class DefaultJBIHeaderFilterStrategyTest extends TestCase {
+
+    private HeaderFilterStrategy strategy = new DefaultJBIHeaderFilterStrategy();
+
+    public void testApplyFilterToCamelHeaders() {
+        assertTrue("This header is a jbi header.", strategy.applyFilterToCamelHeaders("javax.jbi.ServiceName", "test", null));
+        assertFalse("This header should not be filtered", strategy.applyFilterToCamelHeaders("javax.jbitest", "test1", null));
+        assertTrue("This header is a jbi header.", strategy.applyFilterToCamelHeaders("javax.jbi.Endpoint", new HashMap(), null));
+    }
+}