You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2009/11/13 20:25:42 UTC

svn commit: r835959 - in /servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel: ./ src/main/java/org/apache/servicemix/camel/ src/main/java/org/apache/servicemix/camel/converter/ src/main/java/org/apache/servicemix/camel/...

Author: gertv
Date: Fri Nov 13 19:25:41 2009
New Revision: 835959

URL: http://svn.apache.org/viewvc?rev=835959&view=rev
Log:
SMXCOMP-638: Add options for better handling of non-serializable properties and exceptions

Added:
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/util/
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/util/BasicSerializationHeaderFilterStrategy.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/util/HeaderFilterStrategies.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/util/StrictSerializationHeaderFilterStrategy.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiCamelExceptionsTest.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiConvertExceptionsTest.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiInOutCamelJMSFlowExceptionTest.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiStrictSerializationTest.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/test/
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/test/InvalidSerializableObject.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/util/
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/util/BasicSerializationHeaderFilterStrategyTest.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/util/HeaderFilterStrategiesTest.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/util/StrictSerializationHeaderFilterStrategyTest.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/resources/org/apache/servicemix/camel/simple.xsd
Modified:
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/   (props changed)
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiBinding.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiComponent.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/converter/JbiConverter.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiBindingTest.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/converter/JbiConverterTest.java

Propchange: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Nov 13 19:25:41 2009
@@ -5,3 +5,4 @@
 .ruleset
 .checkstyle
 .pmd
+*.i??

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java?rev=835959&r1=835958&r2=835959&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java Fri Nov 13 19:25:41 2009
@@ -117,7 +117,9 @@
         String camelUri = uri.getSchemeSpecificPart();
         Endpoint camelEndpoint = jbiComponent.getCamelContext().getEndpoint(camelUri);
         Processor processor = jbiComponent.createCamelProcessor(camelEndpoint);
-        CamelProviderEndpoint endpoint = new CamelProviderEndpoint(getServiceUnit(), camelEndpoint, jbiComponent.getBinding(), processor);
+        CamelProviderEndpoint endpoint =
+            new CamelProviderEndpoint(getServiceUnit(), camelEndpoint,
+                                      jbiComponent.createBinding(camelEndpoint), processor);
 
         IntrospectionSupport.setProperties(endpoint, map);
 

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java?rev=835959&r1=835958&r2=835959&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java Fri Nov 13 19:25:41 2009
@@ -120,16 +120,7 @@
      */
     private void handleFailure(MessageExchange exchange, Exchange camelExchange) throws MessagingException {
         if (camelExchange.getFault(false) == null || camelExchange.getFault(false).getBody() == null) {
-            Throwable t = camelExchange.getException();
-            Exception e;
-            if (t == null) {
-                e = new Exception("Unknown error");
-            } else if (t instanceof Exception) {
-                e = (Exception) t;
-            } else {
-                e = new Exception(t);
-            }
-            fail(exchange, e);
+            fail(exchange, binding.extractException(camelExchange));
         } else {
             Fault fault = exchange.createFault();
             fault.setContent(camelExchange.getFault().getBody(Source.class));

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiBinding.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiBinding.java?rev=835959&r1=835958&r2=835959&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiBinding.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiBinding.java Fri Nov 13 19:25:41 2009
@@ -16,11 +16,8 @@
  */
 package org.apache.servicemix.camel;
 
-import java.io.Serializable;
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.util.Collection;
-import java.util.Map;
 
 import javax.jbi.messaging.InOptionalOut;
 import javax.jbi.messaging.InOut;
@@ -38,8 +35,13 @@
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.Message;
 import org.apache.camel.NoTypeConversionAvailableException;
+import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.camel.util.BasicSerializationHeaderFilterStrategy;
+import org.apache.servicemix.camel.util.HeaderFilterStrategies;
+import org.apache.servicemix.camel.util.StrictSerializationHeaderFilterStrategy;
+import org.apache.servicemix.jbi.FaultException;
 
 /**
  * The binding of how Camel messages get mapped to JBI and back again
@@ -58,10 +60,34 @@
     private static final Log LOG = LogFactory.getLog(JbiBinding.class);
 
     private final CamelContext context;
-    
+
+    private HeaderFilterStrategies strategies = new HeaderFilterStrategies();
+    private boolean convertExceptions;
+
+    /**
+     * Create the binding instance for a given CamelContext
+     *
+     * @param context the CamelContext
+     */
     public JbiBinding(CamelContext context) {
-        super();
+        this(context, false);    
+    }
+
+    public JbiBinding(CamelContext context, boolean strictSerialization) {
         this.context = context;
+        if (strictSerialization) {
+            strategies.add(new StrictSerializationHeaderFilterStrategy());
+        } else {
+            strategies.add(new BasicSerializationHeaderFilterStrategy());
+        }
+    }
+
+    public void addHeaderFilterStrategy(HeaderFilterStrategy strategy) {
+        strategies.add(strategy);
+    }
+
+    public void setConvertExceptions(boolean convertExceptions) {
+        this.convertExceptions = convertExceptions;
     }
 
     public MessageExchange makeJbiMessageExchange(Exchange camelExchange,
@@ -182,7 +208,7 @@
         
         for (String key : message.getHeaders().keySet()) {
             Object value = message.getHeader(key);
-            if (isSerializable(value)) {
+            if (!strategies.applyFilterToCamelHeaders(key, value)) {
                 normalizedMessage.setProperty(key, value);
             }
         }
@@ -212,10 +238,29 @@
         }
     }
 
+
+    /**
+     * Extract an Exception from the exchange.  This method will always return a
+     *
+     * @param exchange the Camel exchange
+     * @return an exception
+     */
+    public Exception extractException(Exchange exchange) {
+        Throwable e  = exchange.getException();
+        if (!(e instanceof Exception) || convertExceptions) {
+            e = context.getTypeConverter().convertTo(FaultException.class, exchange);
+        }
+        return (Exception) e;
+    }
+
     private boolean isOutCapable(MessageExchange exchange) {
         return exchange instanceof InOut || exchange instanceof InOptionalOut;
     }
 
+    /**
+     * Access the JBI MessageExchange that has been stored on the Camel Exchange
+     * @return the JBI MessageExchange
+     */
     public static MessageExchange getMessageExchange(Exchange exchange) {
         return exchange.getProperty(MESSAGE_EXCHANGE, MessageExchange.class);
     }
@@ -240,9 +285,4 @@
         }
         return null;
     }
-
-    @SuppressWarnings("unchecked")
-    protected boolean isSerializable(Object object) {
-        return (object instanceof Serializable) && !(object instanceof Map) && !(object instanceof Collection);
-    }
 }

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiComponent.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiComponent.java?rev=835959&r1=835958&r2=835959&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiComponent.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiComponent.java Fri Nov 13 19:25:41 2009
@@ -29,7 +29,7 @@
 
 public class JbiComponent implements Component<Exchange> {
     private CamelJbiComponent camelJbiComponent;
-    private JbiBinding binding;
+
     private CamelContext camelContext;
     private IdGenerator idGenerator;
     private String suName;
@@ -59,24 +59,6 @@
         return suName;
     }
 
-    /**
-     * @return the binding
-     */
-    public JbiBinding getBinding() {
-        if (binding == null) {
-            binding = new JbiBinding(camelContext);
-        }
-        return binding;
-    }
-
-    /**
-     * @param binding
-     *            the binding to set
-     */
-    public void setBinding(JbiBinding binding) {
-        this.binding = binding;
-    }
-
     // Resolve Camel Endpoints
     // -------------------------------------------------------------------------
     public Endpoint<Exchange> createEndpoint(String uri) {
@@ -133,14 +115,25 @@
                     + endpointUri);
             }
             jbiEndpoint = new CamelProviderEndpoint(getCamelJbiComponent().getServiceUnit(), service,
-                                                    endpoint, getBinding(), processor);
+                                                    endpoint, createBinding(camelEndpoint), processor);
         } else {
             jbiEndpoint = new CamelProviderEndpoint(getCamelJbiComponent().getServiceUnit(), camelEndpoint,
-                                                    getBinding(), processor);
+                                                    createBinding(camelEndpoint), processor);
         }
         return jbiEndpoint;
     }
 
+    /*
+    * Creates a binding for the given endpoint
+    */
+    protected JbiBinding createBinding(Endpoint camelEndpoint) {
+        if (camelEndpoint instanceof JbiEndpoint) {
+            return ((JbiEndpoint) camelEndpoint).createBinding();
+        } else {
+            return new JbiBinding(camelContext);
+        }
+    }
+
     protected String createEndpointName() {
         if (idGenerator == null) {
             idGenerator = new IdGenerator("camel");

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java?rev=835959&r1=835958&r2=835959&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java Fri Nov 13 19:25:41 2009
@@ -29,9 +29,12 @@
 import org.apache.camel.impl.DefaultConsumer;
 import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.spi.HeaderFilterStrategy;
+import org.apache.camel.spi.Registry;
 import org.apache.camel.util.URISupport;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.springframework.util.StringUtils;
 
 /**
  * Represents an {@link org.apache.camel.Endpoint} for interacting with JBI
@@ -40,6 +43,8 @@
  */
 public class JbiEndpoint extends DefaultEndpoint<Exchange> {
 
+    private static final String STRICT_SERIALIZATION = "strict";
+
     private String destinationUri;
 
     private String mep;
@@ -48,14 +53,33 @@
 
     private JbiProducer producer;
 
+    private boolean convertExceptions;
+
+    private boolean strictSerialization;
+
+    private HeaderFilterStrategy headerFilterStrategy;
+
     private final JbiComponent jbiComponent;
 
+    private final JbiBinding binding;
+
     public JbiEndpoint(JbiComponent jbiComponent, String uri) {
         super(uri, jbiComponent);
         this.jbiComponent = jbiComponent;
         parseUri(uri);
+
+        //now create the binding based on the information read from the URI
+        this.binding = createBinding();
+    }
+
+    public final JbiBinding createBinding() {
+        JbiBinding result = new JbiBinding(this.getCamelContext(), strictSerialization);
+        result.setConvertExceptions(convertExceptions);
+        result.addHeaderFilterStrategy(headerFilterStrategy);
+        return result;
     }
 
+
     public synchronized Producer<Exchange> createProducer() throws Exception {
         if (producer == null) {
             producer = new JbiProducer(this);
@@ -75,7 +99,7 @@
 
         @Override
         public void start() throws Exception {
-            consumer = new CamelConsumerEndpoint(jbiComponent.getBinding(), JbiEndpoint.this);
+            consumer = new CamelConsumerEndpoint(binding, JbiEndpoint.this);
             jbiComponent.getCamelJbiComponent().addEndpoint(consumer);
             super.start();
         }
@@ -107,6 +131,7 @@
         }
     }
 
+    @SuppressWarnings("unchecked")
     private void parseUri(String uri) {
         destinationUri = uri;
         try {
@@ -117,8 +142,36 @@
                 if (mep != null && !mep.startsWith("http://www.w3.org/ns/wsdl/")) {
                     mep = "http://www.w3.org/ns/wsdl/" + mep;
                 }
-                operation = (String) params.get("operation");
+                String oper = (String) params.get("operation");
+                if (StringUtils.hasLength(oper)) {
+                    operation = oper;
+                }
                 this.destinationUri = destinationUri.substring(0, idx);
+
+                String filter = (String) params.get("headerFilterStrategy");
+                if (StringUtils.hasLength(filter)) {
+                    Registry registry = jbiComponent.getCamelContext().getRegistry();
+                    if (filter.indexOf('#') != -1) {
+                        filter = filter.substring(1);
+                    }
+                    Object object = registry.lookup(filter);
+                    if (object instanceof HeaderFilterStrategy) {
+                        headerFilterStrategy = (HeaderFilterStrategy) object;
+                    }
+                    params.remove("headerFilterStrategy");
+                }
+                String convert = (String) params.get("convertExceptions");
+                if (StringUtils.hasLength(convert)) {
+                    convertExceptions = Boolean.valueOf(convert);
+                    params.remove("convertExceptions");
+                }
+                String serialization = (String) params.get("serialization");
+                if (StringUtils.hasLength(serialization)) {
+                    strictSerialization = STRICT_SERIALIZATION.equalsIgnoreCase(serialization);
+                    params.remove("serialization");
+                }
+                String endpointUri = this.destinationUri + URISupport.createQueryString(params);
+                this.setEndpointUri(endpointUri);
             }
         } catch (URISyntaxException e) {
             throw new JbiException(e);
@@ -170,11 +223,31 @@
         };
     }
 
-    public JbiBinding getBinding() {
-        return jbiComponent.getBinding();
-    }
-
     public boolean isSingleton() {
         return true;
     }
+         
+    public HeaderFilterStrategy getHeaderFilterStrategy() {
+        return headerFilterStrategy;
+    }
+
+    public void setHeaderFilterStrategy(HeaderFilterStrategy strategy) {
+        this.headerFilterStrategy = strategy;
+    }
+
+    public void setConvertExceptions(boolean convertExceptions) {
+        this.convertExceptions = convertExceptions;
+    }
+
+    public boolean isConvertExceptions() {
+        return convertExceptions;
+    }
+
+    public void setStrictSerialization(boolean strictSerialization) {
+        this.strictSerialization = strictSerialization;
+    }
+
+    public boolean isStrictSerialization() {
+        return strictSerialization;
+    }
 }

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/converter/JbiConverter.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/converter/JbiConverter.java?rev=835959&r1=835958&r2=835959&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/converter/JbiConverter.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/converter/JbiConverter.java Fri Nov 13 19:25:41 2009
@@ -19,6 +19,8 @@
 import javax.xml.transform.Source;
 
 import org.apache.camel.Converter;
+import org.apache.camel.Exchange;
+import org.apache.servicemix.camel.JbiBinding;
 import org.apache.servicemix.jbi.FaultException;
 
 /**
@@ -31,5 +33,17 @@
     public Source convertFaultExceptionToSource(FaultException e) {
         return e.getFault().getContent();
     }
+
+    @Converter
+    public FaultException convertExchangeToFaultException(Exchange exchange) {
+        Throwable exception = exchange.getException();
+        if (exception == null) {
+            return new FaultException("Unknown error", JbiBinding.getMessageExchange(exchange), null);
+        } else {
+            FaultException result = new FaultException(exception.getMessage(), JbiBinding.getMessageExchange(exchange), null);
+            result.setStackTrace(exception.getStackTrace());
+            return result;
+        }
+    }
    
 }

Added: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/util/BasicSerializationHeaderFilterStrategy.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/util/BasicSerializationHeaderFilterStrategy.java?rev=835959&view=auto
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/util/BasicSerializationHeaderFilterStrategy.java (added)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/util/BasicSerializationHeaderFilterStrategy.java Fri Nov 13 19:25:41 2009
@@ -0,0 +1,46 @@
+/*
+ * 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 java.io.Serializable;
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.camel.spi.HeaderFilterStrategy;
+
+/**
+ * {@link org.apache.camel.spi.HeaderFilterStrategy} that filters out non-serializable values:
+ * <ul>
+ * <li>classes that don't implement {@link java.io.Serializable}</li>
+ * <li>{@link java.util.Collection}s</li>
+ * <li>{@link java.util.Map}s</li>
+ * </ul>
+ */
+public class BasicSerializationHeaderFilterStrategy implements HeaderFilterStrategy {
+
+    public boolean applyFilterToCamelHeaders(String s, Object o) {
+        return doApplyFilter(o);
+    }
+
+    public boolean applyFilterToExternalHeaders(String s, Object o) {
+        return doApplyFilter(o);
+    }
+
+    private boolean doApplyFilter(Object o) {
+        return !(o instanceof Serializable) || (o instanceof Map) || (o instanceof Collection);
+    }
+}

Added: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/util/HeaderFilterStrategies.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/util/HeaderFilterStrategies.java?rev=835959&view=auto
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/util/HeaderFilterStrategies.java (added)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/util/HeaderFilterStrategies.java Fri Nov 13 19:25:41 2009
@@ -0,0 +1,60 @@
+/*
+ * 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 java.util.LinkedList;
+import java.util.List;
+
+import org.apache.camel.spi.HeaderFilterStrategy;
+
+/**
+ * {@link HeaderFilterStrategy} implementation that will evaluate a set of
+ * strategies
+ */
+public class HeaderFilterStrategies implements HeaderFilterStrategy {
+
+    private final List<HeaderFilterStrategy> strategies = new LinkedList<HeaderFilterStrategy>();
+
+    public boolean applyFilterToCamelHeaders(String s, Object o) {
+        for (HeaderFilterStrategy strategy : strategies) {
+            if (strategy.applyFilterToCamelHeaders(s, o)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public boolean applyFilterToExternalHeaders(String s, Object o) {
+        for (HeaderFilterStrategy strategy : strategies) {
+            if (strategy.applyFilterToExternalHeaders(s, o)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Add a strategy to the set of strategies
+     *
+     * @param strategy
+     */
+    public void add(HeaderFilterStrategy strategy) {
+        if (strategy != null) {
+            strategies.add(strategy);
+        }
+    }
+}

Added: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/util/StrictSerializationHeaderFilterStrategy.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/util/StrictSerializationHeaderFilterStrategy.java?rev=835959&view=auto
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/util/StrictSerializationHeaderFilterStrategy.java (added)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/util/StrictSerializationHeaderFilterStrategy.java Fri Nov 13 19:25:41 2009
@@ -0,0 +1,69 @@
+/*
+ * 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 java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+
+import org.apache.camel.spi.HeaderFilterStrategy;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * {@link org.apache.camel.spi.HeaderFilterStrategy} that filters out non-serializable values.
+ *
+ * It will try to write the object to a stream to make sure that an object that implements the
+ * {@link Serializable} interface can actually be serialized
+ */
+public class StrictSerializationHeaderFilterStrategy implements HeaderFilterStrategy {
+
+    private static final Log LOG = LogFactory.getLog(StrictSerializationHeaderFilterStrategy.class);
+
+    public boolean applyFilterToCamelHeaders(String s, Object o) {
+        return doApplyFilter(s, o);
+    }
+
+    public boolean applyFilterToExternalHeaders(String s, Object o) {
+        return doApplyFilter(s, o);
+    }
+
+    private boolean doApplyFilter(String s, Object o) {
+        if (o instanceof Serializable) {
+            ObjectOutputStream oos = null;
+            try {
+                oos = new ObjectOutputStream(new ByteArrayOutputStream());
+                oos.writeObject(o);
+            } catch (IOException e) {
+                LOG.debug(String.format("%s implements Serializable, but serialization throws IOException: filtering key %s",
+                                        o, s));
+                return true;
+            } finally {
+                if (oos != null) {
+                    try {
+                        oos.close();
+                    } catch (IOException e) {
+                        // ignoring exception on stream close
+                    }
+                }
+            }
+            return false;
+        }
+        return true;
+    }
+}

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiBindingTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiBindingTest.java?rev=835959&r1=835958&r2=835959&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiBindingTest.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiBindingTest.java Fri Nov 13 19:25:41 2009
@@ -16,7 +16,6 @@
  */
 package org.apache.servicemix.camel;
 
-import java.util.ArrayList;
 import java.util.HashMap;
 
 import javax.activation.DataHandler;
@@ -162,11 +161,4 @@
         assertSame("JBI SecuritySubject should have been set from the Camel Message header",
                    SUBJECT, to.getSecuritySubject());
     }
-    
-    public void testIsSerializable() throws Exception {
-        assertTrue("A String is serializable", binding.isSerializable("test"));
-        assertFalse("JbiBinding is not serializable", binding.isSerializable(binding));
-        assertFalse("Maps can contain non-serializable data", binding.isSerializable(new HashMap()));
-        assertFalse("Collections can contain non-serializable data", binding.isSerializable(new ArrayList()));
-    }
 }

Added: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiCamelExceptionsTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiCamelExceptionsTest.java?rev=835959&view=auto
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiCamelExceptionsTest.java (added)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiCamelExceptionsTest.java Fri Nov 13 19:25:41 2009
@@ -0,0 +1,93 @@
+/*
+ * 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;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.InOut;
+import javax.xml.namespace.QName;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.converter.jaxp.StringSource;
+import org.apache.servicemix.client.DefaultServiceMixClient;
+import org.apache.servicemix.client.ServiceMixClient;
+
+/**
+ * Tests on conveying a simple exception thrown by a bean in the camel route
+ */
+public class JbiCamelExceptionsTest extends JbiCamelErrorHandlingTestSupport {
+
+    public void testInOnlyConveysException() throws Exception {
+        ServiceMixClient client = new DefaultServiceMixClient(jbiContainer);
+        InOnly exchange = client.createInOnlyExchange();
+        exchange.setService(new QName("urn:test", "service"));
+        exchange.getInMessage().setContent(new StringSource("<request>I would like a NPE, please!</request>"));
+        client.sendSync(exchange);
+        assertEquals(ExchangeStatus.ERROR, exchange.getStatus());
+
+        assertTrue("A NullPointerException was expected", exchange.getError() instanceof NullPointerException);
+    }
+
+    public void testInOutHandlingBusinessException() throws Exception {
+        ServiceMixClient client = new DefaultServiceMixClient(jbiContainer);
+        InOut exchange = client.createInOutExchange();
+        exchange.setService(new QName("urn:test", "failsafe"));
+        exchange.getInMessage().setContent(new StringSource("<request>I would like to do business, please!</request>"));
+        client.sendSync(exchange);
+        assertEquals(ExchangeStatus.ACTIVE, exchange.getStatus());
+
+        client.done(exchange);
+
+        // let's wait a moment to make sure that the last DONE MessageExchange is handled
+        Thread.sleep(500);
+    }
+
+    @Override
+    protected RouteBuilder createRoutes() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {                
+                errorHandler(noErrorHandler());
+
+                from("jbi:endpoint:urn:test:failsafe:endpoint")
+                    .tryBlock()
+                        .to("jbi:endpoint:urn:test:service:endpoint")
+                    .handle(BusinessException.class)
+                        .setBody(constant("<response>We handled that pretty well, didn't we?</response>"));
+
+                from("jbi:endpoint:urn:test:service:endpoint").bean(new MyPojo());
+            }
+        };
+    }
+
+    public class MyPojo {
+
+        public void handle(String message) {
+            if (message.contains("NPE")) {
+                throw new NullPointerException("You asked for a NPE, you got it!");
+            } else {
+                throw new BusinessException("Something went wrong, but we can still recover, can't we?");
+            }
+        }
+    }
+
+    private class BusinessException extends RuntimeException {
+        public BusinessException(String message) {
+            super(message);
+        }
+    }
+}

Added: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiConvertExceptionsTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiConvertExceptionsTest.java?rev=835959&view=auto
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiConvertExceptionsTest.java (added)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiConvertExceptionsTest.java Fri Nov 13 19:25:41 2009
@@ -0,0 +1,68 @@
+/*
+ * 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;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOut;
+import javax.xml.namespace.QName;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.converter.jaxp.StringSource;
+import org.apache.servicemix.client.DefaultServiceMixClient;
+import org.apache.servicemix.client.ServiceMixClient;
+import org.apache.servicemix.jbi.FaultException;
+
+/**
+ * Test the convertExceptions=true flag (converts all exceptions to JBI FaultExceptions)
+ */
+public class JbiConvertExceptionsTest extends JbiCamelErrorHandlingTestSupport {
+
+    private static final String EXCEPTION = "This has completely gone wrong at runtime!";
+
+    public void testInOnlyConvertExceptions() throws Exception {
+        ServiceMixClient client = new DefaultServiceMixClient(jbiContainer);
+        InOut exchange = client.createInOutExchange();
+        exchange.setService(new QName("urn:test", "exceptions"));
+        exchange.getInMessage().setContent(new StringSource(MESSAGE));
+        client.sendSync(exchange);
+        assertEquals(ExchangeStatus.ERROR, exchange.getStatus());
+
+        assertTrue("Exception should have been converted into a JBI FaultException",
+                   exchange.getError() instanceof FaultException);
+        assertTrue("Original message should have been preserved",
+                   exchange.getError().getMessage().contains(EXCEPTION));
+    }
+
+    @Override
+    protected RouteBuilder createRoutes() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                errorHandler(noErrorHandler());
+                
+                from("jbi:endpoint:urn:test:exceptions:endpoint?convertExceptions=true")
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws Exception {
+                            throw new RuntimeException(EXCEPTION);
+                        }
+                    });
+            }
+        };
+    }
+}

Added: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiInOutCamelJMSFlowExceptionTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiInOutCamelJMSFlowExceptionTest.java?rev=835959&view=auto
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiInOutCamelJMSFlowExceptionTest.java (added)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiInOutCamelJMSFlowExceptionTest.java Fri Nov 13 19:25:41 2009
@@ -0,0 +1,103 @@
+/*
+ * 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;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOut;
+import javax.xml.namespace.QName;
+
+import org.apache.camel.CamelException;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.converter.jaxp.StringSource;
+import org.apache.servicemix.client.DefaultServiceMixClient;
+import org.apache.servicemix.client.ServiceMixClient;
+import org.apache.servicemix.jbi.FaultException;
+
+/**
+ * Test to ensure possibility of conveying exceptions over the JMS/JCA flow with convertException=true
+ */
+public class JbiInOutCamelJMSFlowExceptionTest extends JbiCamelErrorHandlingTestSupport {
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        // make sure all exchanges in the ESB are serializable (e.g. for use with JMS/JCA flow)
+        enableCheckForSerializableExchanges();
+    }
+    
+    public void testInOutWithConvertExceptionsEnabled() throws Exception {
+        MockEndpoint errors = getMockEndpoint("mock:errors");
+        errors.expectedMessageCount(1);
+
+        ServiceMixClient client = new DefaultServiceMixClient(jbiContainer);
+        InOut exchange = client.createInOutExchange();
+        exchange.setService(new QName("urn:test", "error-not-handled"));
+        exchange.getInMessage().setContent(new StringSource(MESSAGE));
+        client.sendSync(exchange);
+        assertEquals(ExchangeStatus.ERROR, exchange.getStatus());
+
+        assertTrue("Exception should have been converted to a JBI FaultException",
+                   exchange.getError() instanceof FaultException);
+        assertTrue("Original validation message should have been preserved",
+                   exchange.getError().getMessage().contains("Validation"));
+
+        errors.assertIsSatisfied();
+    }
+    
+    public void testInOutWithErrorHandledTrue() throws Exception {
+        MockEndpoint errors = getMockEndpoint("mock:errors");
+        errors.expectedMessageCount(1);
+
+        ServiceMixClient client = new DefaultServiceMixClient(jbiContainer);
+        InOut exchange = client.createInOutExchange();
+        exchange.setService(new QName("urn:test", "error-handled-true"));
+        exchange.getInMessage().setContent(new StringSource(MESSAGE));
+        client.sendSync(exchange);
+        assertEquals(ExchangeStatus.ACTIVE, exchange.getStatus());
+        client.done(exchange);
+       
+        errors.assertIsSatisfied();
+        
+        // let's wait a moment to make sure that the last DONE MessageExchange is handled
+        Thread.sleep(500);
+    }
+
+    @Override
+    protected RouteBuilder createRoutes() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                onException(org.apache.camel.processor.validation.SchemaValidationException.class).handled(false);
+                onException(org.apache.camel.CamelException.class).handled(true);
+                errorHandler(deadLetterChannel("mock:errors").maximumRedeliveries(1));
+                from("jbi:service:urn:test:error-not-handled?convertExceptions=true")
+                    .to("validator:org/apache/servicemix/camel/simple.xsd");
+                from("jbi:service:urn:test:error-handled-true")
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws Exception {
+                            throw new CamelException();
+                        }
+                    })
+                    .setBody(constant("<msg>Done</msg>"));
+            }
+        };
+    }
+}

Added: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiStrictSerializationTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiStrictSerializationTest.java?rev=835959&view=auto
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiStrictSerializationTest.java (added)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiStrictSerializationTest.java Fri Nov 13 19:25:41 2009
@@ -0,0 +1,87 @@
+/*
+ * 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;
+
+import java.io.ByteArrayOutputStream;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOut;
+import javax.xml.namespace.QName;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.converter.jaxp.StringSource;
+import org.apache.servicemix.camel.test.InvalidSerializableObject;
+import org.apache.servicemix.client.DefaultServiceMixClient;
+import org.apache.servicemix.client.ServiceMixClient;
+
+/**
+ * Testcase for strictSerialization=true (removes all non-serializable headers, even those that incorrectly
+ * implement the Serializable interface)
+ */
+public class JbiStrictSerializationTest extends JbiCamelErrorHandlingTestSupport {
+
+    private static final String SERIALIZABLE_KEY = "serializable";
+    private static final String INVALID_SERIALIZABLE_KEY = "invalid.serializable";
+    private static final String NON_SERIALIZABLE_KEY = "non.serializable";
+
+    public void testInOutWithStrictSerialization() throws Exception {
+        MockEndpoint errors = getMockEndpoint("mock:errors");
+        errors.expectedMessageCount(1);
+
+        ServiceMixClient client = new DefaultServiceMixClient(jbiContainer);
+        InOut exchange = client.createInOutExchange();
+        exchange.setService(new QName("urn:test", "strictserialization"));
+        exchange.getInMessage().setContent(new StringSource(MESSAGE));
+        client.sendSync(exchange);
+        assertEquals(ExchangeStatus.ACTIVE, exchange.getStatus());
+        client.done(exchange);
+       
+        errors.assertIsSatisfied();
+
+        assertTrue("Serializable values are still in the headers",
+                   exchange.getOutMessage().getPropertyNames().contains(SERIALIZABLE_KEY));
+        assertFalse("Non-serializable values are not in the headers",
+                   exchange.getOutMessage().getPropertyNames().contains(NON_SERIALIZABLE_KEY));
+        assertFalse("Non-serializable values are not in the headers",
+                    exchange.getOutMessage().getPropertyNames().contains(INVALID_SERIALIZABLE_KEY));
+
+        // let's wait a moment to make sure that the last DONE MessageExchange is handled
+        Thread.sleep(500);
+    }
+
+    @Override
+    protected RouteBuilder createRoutes() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("jbi:endpoint:urn:test:strictserialization:endpoint?serialization=strict")
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws Exception {
+                            Message message = exchange.getOut();
+                            message.copyFrom(exchange.getIn());
+                            message.setHeader(SERIALIZABLE_KEY, "A string is Serializable");
+                            message.setHeader(INVALID_SERIALIZABLE_KEY, new InvalidSerializableObject());
+                            message.setHeader(NON_SERIALIZABLE_KEY, new ByteArrayOutputStream());
+                        }
+                    }).to("mock:errors");
+            }
+        };
+    }
+}

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java?rev=835959&r1=835958&r2=835959&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java Fri Nov 13 19:25:41 2009
@@ -16,6 +16,10 @@
  */
 package org.apache.servicemix.camel;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.NotSerializableException;
+import java.io.ObjectOutputStream;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
@@ -23,6 +27,7 @@
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.jbi.JBIException;
+import javax.jbi.messaging.MessageExchange;
 import javax.xml.namespace.QName;
 
 import org.apache.camel.AsyncCallback;
@@ -41,6 +46,8 @@
 import org.apache.servicemix.jbi.container.ActivationSpec;
 import org.apache.servicemix.jbi.container.JBIContainer;
 import org.apache.servicemix.jbi.container.SpringJBIContainer;
+import org.apache.servicemix.jbi.event.ExchangeEvent;
+import org.apache.servicemix.jbi.event.ExchangeListener;
 import org.apache.servicemix.tck.ExchangeCompletedListener;
 
 /**
@@ -67,7 +74,7 @@
     protected ProducerTemplate<Exchange> client;
 
     protected ServiceMixClient servicemixClient;
-
+    
     /**
      * Sends an exchange to the endpoint
      */
@@ -150,7 +157,7 @@
 
         camelContext.start();
     }
-
+    
     protected CamelContext createCamelContext() {
         return new DefaultCamelContext();
     }
@@ -197,6 +204,27 @@
     }
 
 
+    protected void enableCheckForSerializableExchanges() {
+        jbiContainer.addListener(new ExchangeListener() {
+
+            public void exchangeSent(ExchangeEvent exchangeEvent) {
+                MessageExchange exchange = exchangeEvent.getExchange();
+                try {
+                    ObjectOutputStream oos = new ObjectOutputStream(new ByteArrayOutputStream());
+                    oos.writeObject(exchange);
+                } catch (NotSerializableException e) {
+                    fail("Non-serializable MessageExchange found: " + exchange);
+                } catch (IOException e) {
+                    fail("Error while trying to serialize MessageExchange " + exchange + ":" + e.getMessage());
+                }
+            }
+
+            public void exchangeAccepted(ExchangeEvent exchangeEvent) {
+                // graciously do nothing
+            }
+        });
+    }
+
     protected abstract void appendJbiActivationSpecs(List<ActivationSpec> activationSpecList);
 
     protected abstract RouteBuilder createRoutes();

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/converter/JbiConverterTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/converter/JbiConverterTest.java?rev=835959&r1=835958&r2=835959&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/converter/JbiConverterTest.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/converter/JbiConverterTest.java Fri Nov 13 19:25:41 2009
@@ -17,11 +17,16 @@
 package org.apache.servicemix.camel.converter;
 
 import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.MessagingException;
 import javax.xml.transform.Source;
 
 import junit.framework.TestCase;
 
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.servicemix.camel.JbiBinding;
 import org.apache.servicemix.jbi.FaultException;
 import org.apache.servicemix.jbi.jaxp.StringSource;
 import org.apache.servicemix.tck.mock.MockMessageExchange;
@@ -49,4 +54,50 @@
         assertEquals(FAULT_CONTENTS, converter.convertFaultExceptionToSource(exception));
     }
 
+    public void testConvertExchangeToFaultException() {
+        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
+        MessageExchange me = new MockMessageExchange();
+        exchange.setProperty(JbiBinding.MESSAGE_EXCHANGE, me);
+
+        FaultException exception = converter.convertExchangeToFaultException(exchange);
+        assertNotNull(exception);
+        assertEquals("Unknown error", exception.getMessage());       
+        assertSame(me, exception.getExchange());
+    }
+
+    public void testConvertExchangeToFaultExceptionWithExistingException() {
+        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
+        Exception original = new Exception("The original exception");
+        exchange.setException(original);
+        MessageExchange me = new MockMessageExchange();
+        exchange.setProperty(JbiBinding.MESSAGE_EXCHANGE, me);
+
+        FaultException exception = converter.convertExchangeToFaultException(exchange);
+        assertNotNull(exception);
+        assertEquals(original.getMessage(), exception.getMessage());
+        assertEqualStackTraces(original.getStackTrace(), exception.getStackTrace());
+        assertSame(me, exception.getExchange());
+    }
+
+    public void testConvertExchangeToFaultExceptionWithExistingThrowable() {
+        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
+        Throwable original = new Throwable("The original exception");
+        exchange.setException(original);
+        MessageExchange me = new MockMessageExchange();
+        exchange.setProperty(JbiBinding.MESSAGE_EXCHANGE, me);
+
+        FaultException exception = converter.convertExchangeToFaultException(exchange);
+        assertNotNull(exception);
+        assertEquals(original.getMessage(), exception.getMessage());
+        assertEqualStackTraces(original.getStackTrace(), exception.getStackTrace());
+        assertSame(me, exception.getExchange());
+    }
+
+
+    private void assertEqualStackTraces(StackTraceElement[] trace1, StackTraceElement[] trace2) {
+        assertEquals(trace1.length, trace2.length);
+        for (int i = 0; i < trace1.length; i++) {
+            assertEquals(trace1[i], trace2[i]);
+        }
+    }
 }

Added: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/test/InvalidSerializableObject.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/test/InvalidSerializableObject.java?rev=835959&view=auto
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/test/InvalidSerializableObject.java (added)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/test/InvalidSerializableObject.java Fri Nov 13 19:25:41 2009
@@ -0,0 +1,34 @@
+/*
+ * 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.test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+
+/**
+ * Invalid serializable object for testing purposes
+ */
+public class InvalidSerializableObject implements Serializable {
+    
+    private OutputStream stream = new ByteArrayOutputStream();
+
+    public OutputStream getStream() {
+        return stream;
+    }
+
+}

Added: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/util/BasicSerializationHeaderFilterStrategyTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/util/BasicSerializationHeaderFilterStrategyTest.java?rev=835959&view=auto
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/util/BasicSerializationHeaderFilterStrategyTest.java (added)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/util/BasicSerializationHeaderFilterStrategyTest.java Fri Nov 13 19:25:41 2009
@@ -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 java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import junit.framework.TestCase;
+import org.apache.camel.spi.HeaderFilterStrategy;
+
+/**
+ * Test cases for {@link org.apache.servicemix.camel.util.BasicSerializationHeaderFilterStrategy}
+ */
+public class BasicSerializationHeaderFilterStrategyTest extends TestCase {
+
+    private HeaderFilterStrategy strategy = new BasicSerializationHeaderFilterStrategy();
+
+    public void testApplyFilterToCamelHeaders() {
+        assertFalse("A String is serializable", strategy.applyFilterToCamelHeaders("key", "test"));
+        assertTrue("An OutputStream is not serializable", strategy.applyFilterToCamelHeaders("key", new ByteArrayOutputStream()));
+        assertTrue("Maps can contain non-serializable data", strategy.applyFilterToCamelHeaders("key", new HashMap()));
+        assertTrue("Collections can contain non-serializable data", strategy.applyFilterToCamelHeaders("key", new ArrayList()));
+    }
+
+}

Added: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/util/HeaderFilterStrategiesTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/util/HeaderFilterStrategiesTest.java?rev=835959&view=auto
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/util/HeaderFilterStrategiesTest.java (added)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/util/HeaderFilterStrategiesTest.java Fri Nov 13 19:25:41 2009
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+/**
+ * Test cases for {@link org.apache.servicemix.camel.util.HeaderFilterStrategies}
+ */
+public class HeaderFilterStrategiesTest extends TestCase {
+
+    public void testStrategies() {
+        HeaderFilterStrategies strategies = new HeaderFilterStrategies();
+        strategies.add(new HeaderFilterStrategy() {
+
+            public boolean applyFilterToCamelHeaders(String s, Object o) {
+                return "A".equals(s);
+            }
+
+            public boolean applyFilterToExternalHeaders(String s, Object o) {
+                return "1".equals(s);
+            }
+        });
+        strategies.add(new HeaderFilterStrategy() {
+
+            public boolean applyFilterToCamelHeaders(String s, Object o) {
+                return "B".equals(s);
+            }
+
+            public boolean applyFilterToExternalHeaders(String s, Object o) {
+                return "2".equals(s);
+            }
+        });
+
+        assertTrue("A should have been filtered", strategies.applyFilterToCamelHeaders("A", null));
+        assertTrue("B should have been filtered", strategies.applyFilterToCamelHeaders("B", null));
+        assertFalse("C should not have been filtered", strategies.applyFilterToCamelHeaders("C", null));
+
+        assertTrue("1 should have been filtered", strategies.applyFilterToExternalHeaders("1", null));
+        assertTrue("2 should have been filtered", strategies.applyFilterToExternalHeaders("2", null));
+        assertFalse("3 should not have been filtered", strategies.applyFilterToExternalHeaders("3", null));
+    }
+
+    public void testIgnoreNullStrategies() {
+        HeaderFilterStrategies strategies = new HeaderFilterStrategies();
+        strategies.add(null);
+
+        assertFalse("XYZ should not have been filtered", strategies.applyFilterToCamelHeaders("XYZ", null));
+    }
+}

Added: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/util/StrictSerializationHeaderFilterStrategyTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/util/StrictSerializationHeaderFilterStrategyTest.java?rev=835959&view=auto
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/util/StrictSerializationHeaderFilterStrategyTest.java (added)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/util/StrictSerializationHeaderFilterStrategyTest.java Fri Nov 13 19:25:41 2009
@@ -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 java.io.ByteArrayOutputStream;
+
+import junit.framework.TestCase;
+import org.apache.camel.spi.HeaderFilterStrategy;
+import org.apache.servicemix.camel.test.InvalidSerializableObject;
+
+/**
+ * Test cases for {@link org.apache.servicemix.camel.util.StrictSerializationHeaderFilterStrategy}
+ */
+public class StrictSerializationHeaderFilterStrategyTest extends TestCase {
+
+    private HeaderFilterStrategy strategy = new StrictSerializationHeaderFilterStrategy();
+
+    public void testApplyFilterToCamelHeaders() {
+        assertTrue("Strategy should filter ByteArrayInputStream - is not Serializable",
+                   strategy.applyFilterToCamelHeaders("key", new ByteArrayOutputStream()));
+        assertTrue("Strategy should filter Serializable implementations that can not be serialized",
+                   strategy.applyFilterToCamelHeaders("key", new InvalidSerializableObject()));
+        assertFalse("Strategy should not filter String - is Serializable",
+                    strategy.applyFilterToCamelHeaders("key", "value"));
+    }
+}

Added: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/resources/org/apache/servicemix/camel/simple.xsd
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/resources/org/apache/servicemix/camel/simple.xsd?rev=835959&view=auto
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/resources/org/apache/servicemix/camel/simple.xsd (added)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/resources/org/apache/servicemix/camel/simple.xsd Fri Nov 13 19:25:41 2009
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+targetNamespace="http://www.w3schools.com"
+xmlns="http://www.w3schools.com"
+elementFormDefault="qualified">
+
+<xs:element name="note">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element name="to" type="xs:string"/>
+      <xs:element name="from" type="xs:string"/>
+      <xs:element name="heading" type="xs:string"/>
+      <xs:element name="body" type="xs:string"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+</xs:schema>