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:15:14 UTC
svn commit: r835955 [1/2] - in
/servicemix/components/engines/servicemix-camel/trunk/src:
main/java/org/apache/servicemix/camel/
main/java/org/apache/servicemix/camel/converter/
main/java/org/apache/servicemix/camel/util/ test/java/org/apache/servicemi...
Author: gertv
Date: Fri Nov 13 19:15:12 2009
New Revision: 835955
URL: http://svn.apache.org/viewvc?rev=835955&view=rev
Log:
SMXCOMP-638: Add options for better handling of non-serializable properties and exceptions
Added:
servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/
servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/BasicSerializationHeaderFilterStrategy.java
servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/HeaderFilterStrategies.java
servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/StrictSerializationHeaderFilterStrategy.java
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiCamelExceptionsTest.java
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiConvertExceptionsTest.java
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutCamelJMSFlowExceptionTest.java
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiStrictSerializationTest.java
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/test/
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/test/InvalidSerializableObject.java
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/util/
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/util/BasicSerializationHeaderFilterStrategyTest.java
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/util/HeaderFilterStrategiesTest.java
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/util/StrictSerializationHeaderFilterStrategyTest.java
servicemix/components/engines/servicemix-camel/trunk/src/test/resources/org/apache/servicemix/camel/simple.xsd
Modified:
servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java
servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java
servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiBinding.java
servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java
servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java
servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/converter/JbiConverter.java
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiBindingTest.java
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyToCamelObjectTest.java
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutFaultTest.java
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutFromCamelRoute.java
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutPipelineTest.java
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiToCamelCbrTest.java
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiToCamelStreamSourceTest.java
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/TwoServicemixCamelSusTest.java
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/converter/JbiConverterTest.java
Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java?rev=835955&r1=835954&r2=835955&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java Fri Nov 13 19:15:12 2009
@@ -116,9 +116,8 @@
Map map = URISupport.parseQuery(uri.getQuery());
String camelUri = uri.getSchemeSpecificPart();
Endpoint camelEndpoint = jbiComponent.getCamelContext().getEndpoint(camelUri);
- Processor processor = jbiComponent.createCamelProcessor(camelEndpoint);
- CamelProviderEndpoint endpoint = new CamelProviderEndpoint(getServiceUnit(), camelEndpoint, jbiComponent.createBinding(), processor);
-
+ Processor processor = jbiComponent.createCamelProcessor(camelEndpoint);
+ CamelProviderEndpoint endpoint = new CamelProviderEndpoint(getServiceUnit(), camelEndpoint, jbiComponent.createBinding(camelEndpoint), processor);
IntrospectionSupport.setProperties(endpoint, map);
return endpoint;
Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java?rev=835955&r1=835954&r2=835955&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java Fri Nov 13 19:15:12 2009
@@ -30,8 +30,6 @@
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
-import org.apache.camel.spi.HeaderFilterStrategy;
-import org.apache.camel.spi.HeaderFilterStrategyAware;
import org.apache.camel.spi.Synchronization;
import org.apache.servicemix.common.JbiConstants;
@@ -44,7 +42,7 @@
*
* @version $Revision: 426415 $
*/
-public class CamelProviderEndpoint extends ProviderEndpoint implements Synchronization, HeaderFilterStrategyAware {
+public class CamelProviderEndpoint extends ProviderEndpoint implements Synchronization {
public static final QName SERVICE_NAME = new QName("http://camel.apache.org/schema/jbi", "provider");
@@ -156,28 +154,10 @@
fail(me, new FaultException("Fault occured for " + exchange.getPattern() + " exchange", me, fault));
}
} else {
- Throwable t = exchange.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(me, e);
+ fail(me, binding.extractException(exchange));
}
} catch (MessagingException e) {
logger.warn("Unable to send JBI MessageExchange after successful Camel route invocation: " + me, e);
}
}
-
-
- public HeaderFilterStrategy getHeaderFilterStrategy() {
- return binding.getHeaderFilterStrategy();
- }
-
- public void setHeaderFilterStrategy(HeaderFilterStrategy strategy) {
- binding.setHeaderFilterStrategy(strategy);
- }
}
Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiBinding.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiBinding.java?rev=835955&r1=835954&r2=835955&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiBinding.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiBinding.java Fri Nov 13 19:15:12 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 java.util.concurrent.Callable;
import javax.jbi.messaging.InOptionalOut;
@@ -39,18 +36,20 @@
import org.apache.camel.ExchangePattern;
import org.apache.camel.Message;
import org.apache.camel.impl.DefaultExchange;
-import org.apache.camel.impl.DefaultHeaderFilterStrategy;
import org.apache.camel.spi.HeaderFilterStrategy;
-import org.apache.camel.spi.HeaderFilterStrategyAware;
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.exception.FaultException;
/**
* The binding of how Camel messages get mapped to JBI and back again
*
* @version $Revision: 563665 $
*/
-public class JbiBinding implements HeaderFilterStrategyAware {
+public class JbiBinding {
public static final String MESSAGE_EXCHANGE = "JbiMessageExchange";
public static final String OPERATION = "JbiOperation";
@@ -59,18 +58,36 @@
private static final Log LOG = LogFactory.getLog(JbiBinding.class);
private final CamelContext context;
- private HeaderFilterStrategy strategy;
-
+
+ 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;
+ }
+
/**
* Run a block of code with the {@link CamelContext#getApplicationContextClassLoader()} set as the thread context classloader.
*
@@ -181,7 +198,7 @@
public void copyHeadersFromJbiToCamel(MessageExchange from, Exchange to) {
for (Object object : from.getPropertyNames()) {
String key = object.toString();
- if (!getHeaderFilterStrategy().applyFilterToCamelHeaders(key, from.getProperty(key), null)) {
+ if (!strategies.applyFilterToCamelHeaders(key, from.getProperty(key), null)) {
to.setProperty(key, from.getProperty(key));
}
}
@@ -200,7 +217,7 @@
}
for (Object object : from.getPropertyNames()) {
String key = object.toString();
- if (!strategy.applyFilterToCamelHeaders(key, from.getProperty(key), to.getExchange())) {
+ if (!strategies.applyFilterToCamelHeaders(key, from.getProperty(key), to.getExchange())) {
to.setHeader(key, from.getProperty(key));
}
}
@@ -224,8 +241,8 @@
for (String key : message.getHeaders().keySet()) {
Object value = message.getHeader(key);
- if (isSerializable(value) && !getHeaderFilterStrategy().applyFilterToCamelHeaders(key, value, message.getExchange())) {
- normalizedMessage.setProperty(key, value);
+ if (value != null && !strategies.applyFilterToCamelHeaders(key, value, message.getExchange())) {
+ normalizedMessage.setProperty(key, value);
}
}
@@ -257,10 +274,28 @@
}
}
+ /**
+ * 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) {
+ Exception e = exchange.getException();
+ if (e == null || convertExceptions) {
+ e = context.getTypeConverter().convertTo(FaultException.class, exchange);
+ }
+ return e;
+ }
+
private void copyHeadersFromCamelToJbi(Exchange exchange, MessageExchange messageExchange) {
for (String key : exchange.getProperties().keySet()) {
if (messageExchange.getProperty(key) == null) {
- messageExchange.setProperty(key, exchange.getProperty(key));
+ Object value = exchange.getProperty(key);
+ if (!MESSAGE_EXCHANGE.equals(key) && value != null
+ && !strategies.applyFilterToCamelHeaders(key, value, exchange)) {
+ messageExchange.setProperty(key, value);
+ }
}
}
}
@@ -269,6 +304,10 @@
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);
}
@@ -293,20 +332,4 @@
}
return null;
}
-
- @SuppressWarnings("unchecked")
- protected boolean isSerializable(Object object) {
- return (object instanceof Serializable) && !(object instanceof Map) && !(object instanceof Collection);
- }
-
- public HeaderFilterStrategy getHeaderFilterStrategy() {
- if (strategy == null) {
- strategy = new DefaultHeaderFilterStrategy();
- }
- return strategy;
- }
-
- public void setHeaderFilterStrategy(HeaderFilterStrategy strategy) {
- this.strategy = strategy;
- }
}
Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java?rev=835955&r1=835954&r2=835955&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java Fri Nov 13 19:15:12 2009
@@ -67,10 +67,6 @@
return suName;
}
- public JbiBinding createBinding() {
- return new JbiBinding(camelContext);
- }
-
// Resolve Camel Endpoints
// -------------------------------------------------------------------------
public Endpoint createEndpoint(String uri) {
@@ -131,16 +127,26 @@
+ endpointUri);
}
jbiEndpoint = new CamelProviderEndpoint(getCamelJbiComponent()
- .getServiceUnit(), service, endpoint, createBinding(), processor);
- jbiEndpoint.setHeaderFilterStrategy(((JbiEndpoint) camelEndpoint).getHeaderFilterStrategy());
+ .getServiceUnit(), service, endpoint, createBinding(camelEndpoint), processor);
} else {
jbiEndpoint = new CamelProviderEndpoint(getCamelJbiComponent()
- .getServiceUnit(), camelEndpoint, createBinding(), processor);
+ .getServiceUnit(), camelEndpoint, createBinding(camelEndpoint), processor);
}
return jbiEndpoint;
}
- protected String createEndpointName() {
+ /*
+ * 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/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java?rev=835955&r1=835954&r2=835955&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java Fri Nov 13 19:15:12 2009
@@ -45,6 +45,8 @@
*/
public class JbiEndpoint extends DefaultEndpoint implements HeaderFilterStrategyAware {
+ private static final String STRICT_SERIALIZATION = "strict";
+
private String destinationUri;
private String mep;
@@ -52,18 +54,31 @@
private QName operation;
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;
- this.binding = jbiComponent.createBinding();
parseUri(uri);
+
+ //now create the binding based on the information read from the URI
+ this.binding = createBinding();
+ }
+
+ public JbiBinding createBinding() {
+ JbiBinding result = new JbiBinding(this.getCamelContext(), strictSerialization);
+ result.setConvertExceptions(convertExceptions);
+ result.addHeaderFilterStrategy(headerFilterStrategy);
+ return result;
}
public synchronized Producer createProducer() throws Exception {
@@ -144,13 +159,21 @@
Object object = registry.lookup(filter);
if (object instanceof HeaderFilterStrategy) {
headerFilterStrategy = (HeaderFilterStrategy)object;
- binding.setHeaderFilterStrategy(headerFilterStrategy);
}
params.remove("headerFilterStrategy");
- String endpointUri = this.destinationUri + URISupport.createQueryString(params);
- this.setEndpointUri(endpointUri);
-
}
+ String convertExceptions = (String) params.get("convertExceptions");
+ if (StringUtils.hasLength(convertExceptions)) {
+ this.setConvertExceptions(Boolean.valueOf(convertExceptions));
+ params.remove("convertExceptions");
+ }
+ String serialization = (String) params.get("serialization");
+ if (StringUtils.hasLength(serialization)) {
+ this.setStrictSerialization(STRICT_SERIALIZATION.equalsIgnoreCase(serialization));
+ params.remove("serialization");
+ }
+ String endpointUri = this.destinationUri + URISupport.createQueryString(params);
+ this.setEndpointUri(endpointUri);
}
} catch (URISyntaxException e) {
throw new JbiException(e);
@@ -207,10 +230,26 @@
}
public HeaderFilterStrategy getHeaderFilterStrategy() {
- return binding.getHeaderFilterStrategy();
+ return headerFilterStrategy;
}
public void setHeaderFilterStrategy(HeaderFilterStrategy strategy) {
- binding.setHeaderFilterStrategy(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/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/converter/JbiConverter.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/converter/JbiConverter.java?rev=835955&r1=835954&r2=835955&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/converter/JbiConverter.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/converter/JbiConverter.java Fri Nov 13 19:15:12 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.exception.FaultException;
/**
@@ -31,5 +33,17 @@
public Source convertFaultExceptionToSource(FaultException e) {
return e.getFault().getContent();
}
+
+ @Converter
+ public FaultException convertExchangeToFaultException(Exchange exchange) {
+ Exception 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/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/BasicSerializationHeaderFilterStrategy.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/BasicSerializationHeaderFilterStrategy.java?rev=835955&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/BasicSerializationHeaderFilterStrategy.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/BasicSerializationHeaderFilterStrategy.java Fri Nov 13 19:15:12 2009
@@ -0,0 +1,47 @@
+/*
+ * 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.Exchange;
+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, Exchange exchange) {
+ return doApplyFilter(o);
+ }
+
+ public boolean applyFilterToExternalHeaders(String s, Object o, Exchange exchange) {
+ return doApplyFilter(o);
+ }
+
+ private boolean doApplyFilter(Object o) {
+ return !(o instanceof Serializable) || (o instanceof Map) || (o instanceof Collection);
+ }
+}
Added: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/HeaderFilterStrategies.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/HeaderFilterStrategies.java?rev=835955&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/HeaderFilterStrategies.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/HeaderFilterStrategies.java Fri Nov 13 19:15:12 2009
@@ -0,0 +1,62 @@
+/*
+ * 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 java.util.Set;
+
+import org.apache.camel.Exchange;
+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, Exchange exchange) {
+ for (HeaderFilterStrategy strategy : strategies) {
+ if (strategy.applyFilterToCamelHeaders(s, o, exchange)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean applyFilterToExternalHeaders(String s, Object o, Exchange exchange) {
+ for (HeaderFilterStrategy strategy : strategies) {
+ if (strategy.applyFilterToExternalHeaders(s, o, exchange)) {
+ 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/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/StrictSerializationHeaderFilterStrategy.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/StrictSerializationHeaderFilterStrategy.java?rev=835955&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/StrictSerializationHeaderFilterStrategy.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/StrictSerializationHeaderFilterStrategy.java Fri Nov 13 19:15:12 2009
@@ -0,0 +1,70 @@
+/*
+ * 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.Exchange;
+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, Exchange exchange) {
+ return doApplyFilter(s, o);
+ }
+
+ public boolean applyFilterToExternalHeaders(String s, Object o, Exchange exchange) {
+ 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/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiBindingTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiBindingTest.java?rev=835955&r1=835954&r2=835955&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiBindingTest.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiBindingTest.java Fri Nov 13 19:15:12 2009
@@ -60,8 +60,8 @@
@Override
protected void setUp() throws Exception {
factory = new MockExchangeFactory();
- binding = new JbiBinding(new DefaultCamelContext());
- binding.setHeaderFilterStrategy(new MyHeaderFilterStrategy());
+ binding = new JbiBinding(new DefaultCamelContext(), false);
+ binding.addHeaderFilterStrategy(new MyHeaderFilterStrategy());
}
public void testCreateExchangeWithOperation() throws Exception {
@@ -217,13 +217,6 @@
exchange.getProperty(FILTERED_KEY));
}
- 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()));
- }
-
private class MyHeaderFilterStrategy implements HeaderFilterStrategy {
public boolean applyFilterToCamelHeaders(String headerName, Object headerValue, Exchange exchange) {
Added: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiCamelExceptionsTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiCamelExceptionsTest.java?rev=835955&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiCamelExceptionsTest.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiCamelExceptionsTest.java Fri Nov 13 19:15:12 2009
@@ -0,0 +1,96 @@
+/*
+ * 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")
+ .doTry()
+ .to("jbi:endpoint:urn:test:service:endpoint")
+ .doCatch(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/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiConvertExceptionsTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiConvertExceptionsTest.java?rev=835955&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiConvertExceptionsTest.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiConvertExceptionsTest.java Fri Nov 13 19:15:12 2009
@@ -0,0 +1,72 @@
+/*
+ * 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;
+import org.apache.servicemix.jbi.exception.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);
+ }
+ });
+ }
+ };
+ }
+}
Modified: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyToCamelObjectTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyToCamelObjectTest.java?rev=835955&r1=835954&r2=835955&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyToCamelObjectTest.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyToCamelObjectTest.java Fri Nov 13 19:15:12 2009
@@ -21,11 +21,11 @@
import javax.jbi.messaging.InOnly;
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.component.mock.MockEndpoint;
import org.apache.camel.converter.jaxp.StringSource;
-import org.apache.camel.Processor;
-import org.apache.camel.Exchange;
import org.apache.servicemix.client.DefaultServiceMixClient;
import org.apache.servicemix.client.ServiceMixClient;
import org.apache.servicemix.jbi.container.ActivationSpec;
@@ -73,7 +73,7 @@
};
}
- public static class MessageContainer {
+ public static final class MessageContainer {
private String message;
Added: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutCamelJMSFlowExceptionTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutCamelJMSFlowExceptionTest.java?rev=835955&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutCamelJMSFlowExceptionTest.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutCamelJMSFlowExceptionTest.java Fri Nov 13 19:15:12 2009
@@ -0,0 +1,104 @@
+/*
+ * 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.exception.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).redeliverDelay(300).handled(false));
+ 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>"));
+ }
+ };
+ }
+}
Modified: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutFaultTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutFaultTest.java?rev=835955&r1=835954&r2=835955&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutFaultTest.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutFaultTest.java Fri Nov 13 19:15:12 2009
@@ -16,22 +16,21 @@
*/
package org.apache.servicemix.camel;
+import javax.jbi.messaging.Fault;
import javax.jbi.messaging.MessageExchange;
-import javax.jbi.messaging.NormalizedMessage;
import javax.jbi.messaging.MessagingException;
-import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.NormalizedMessage;
import javax.jbi.servicedesc.ServiceEndpoint;
import javax.xml.namespace.QName;
+import org.apache.camel.converter.jaxp.StringSource;
import org.apache.servicemix.client.ServiceMixClient;
import org.apache.servicemix.jbi.FaultException;
-import org.apache.camel.converter.jaxp.StringSource;
/**
* @version $Revision: 1.1 $
*/
-public class JbiInOutFaultTest extends
- NonJbiCamelEndpointsIntegrationTest {
+public class JbiInOutFaultTest extends NonJbiCamelEndpointsIntegrationTest {
/*
* @see TestCase#setUp()
*/
Modified: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutFromCamelRoute.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutFromCamelRoute.java?rev=835955&r1=835954&r2=835955&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutFromCamelRoute.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutFromCamelRoute.java Fri Nov 13 19:15:12 2009
@@ -93,18 +93,20 @@
@Override
public void configure() throws Exception {
from("direct:in-out")
- .choice()
- .when(header(REPLY_HEADER).isEqualTo(Boolean.TRUE)).to("jbi:service:urn:test:in-out-reply?mep=in-out")
+ .choice()
+ .when(header(REPLY_HEADER).isEqualTo(Boolean.TRUE))
+ .to("jbi:service:urn:test:in-out-reply?mep=in-out")
.otherwise().to("jbi:service:urn:test:in-out-quiet?mep=in-out")
- .end().to("mock:done");
-
+ .end().to("mock:done");
+
from("direct:async-in-out")
- .threads(1)
- .choice()
- .when(header(REPLY_HEADER).isEqualTo(Boolean.TRUE)).to("jbi:service:urn:test:in-out-reply?mep=in-out")
+ .threads(1)
+ .choice()
+ .when(header(REPLY_HEADER).isEqualTo(Boolean.TRUE))
+ .to("jbi:service:urn:test:in-out-reply?mep=in-out")
.otherwise().to("jbi:service:urn:test:in-out-quiet?mep=in-out")
- .end().to("mock:done");
-
+ .end().to("mock:done");
+
from("jbi:service:urn:test:in-out-quiet").to("mock:in-out");
from("jbi:service:urn:test:in-out-reply").setBody(constant(REPLY)).to("mock:in-out");
}
Modified: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutPipelineTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutPipelineTest.java?rev=835955&r1=835954&r2=835955&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutPipelineTest.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutPipelineTest.java Fri Nov 13 19:15:12 2009
@@ -43,12 +43,12 @@
*
*/
public class JbiInOutPipelineTest extends JbiTestSupport {
-
+
+ private static final String HEADER_ORIGINAL = "original";
+ private static final String HEADER_TRANSFORMER = "transformer";
private static final String MESSAGE = "<just><a>test</a></just>";
+
private MyHeaderFilterStrategy myFilterStrategy = new MyHeaderFilterStrategy();
-
- private static final String HEADER_ORIGINAL = "original";
- private static final String HEADER_TRANSFORMER = "transformer";
public void testPipelineWithMessageHeadersAndAttachements() throws Exception {
ServiceMixClient client = new DefaultServiceMixClient(jbiContainer);
@@ -60,7 +60,7 @@
assertNotNull("Expecting to receive a DONE/ERROR MessageExchange", client.receive(10000));
client.done(exchange);
assertEquals(ExchangeStatus.DONE, exchange.getStatus());
-
+
// check the exchange message
NormalizedMessage normalizedMessage = exchange.getOutMessage();
assertNotNull(normalizedMessage);
@@ -71,11 +71,11 @@
assertNotNull(normalizedMessage.getProperty(HEADER_TRANSFORMER));
Thread.sleep(1000);
}
-
+
public void testPipelineWithMessageProviderHeaderFiltering() throws Exception {
ServiceMixClient client = new DefaultServiceMixClient(jbiContainer);
InOut exchange = client.createInOutExchange();
-
+
// Test providerEndpoint filterStrategy
exchange.setService(new QName("urn:test", "filterProvider"));
exchange.getInMessage().setContent(new StringSource(MESSAGE));
@@ -85,14 +85,14 @@
client.done(exchange);
assertEquals(ExchangeStatus.DONE, exchange.getStatus());
assertNull(exchange.getOutMessage().getProperty(HEADER_TRANSFORMER));
- Thread.sleep(1000);
+ Thread.sleep(1000);
}
-
+
public void testPipelineWithMessageConsumerHeaderFiltering() throws Exception {
-
- ServiceMixClient client = new DefaultServiceMixClient(jbiContainer);
+
+ ServiceMixClient client = new DefaultServiceMixClient(jbiContainer);
InOut exchange = client.createInOutExchange();
-
+
// Test consumerEndpoint filterStrategy
exchange.setService(new QName("urn:test", "filterConsumer"));
exchange.getInMessage().setContent(new StringSource(MESSAGE));
@@ -102,9 +102,9 @@
client.done(exchange);
assertEquals(ExchangeStatus.DONE, exchange.getStatus());
assertNull(exchange.getOutMessage().getProperty(HEADER_TRANSFORMER));
- Thread.sleep(1000);
+ Thread.sleep(1000);
}
-
+
@Override
protected void appendJbiActivationSpecs(List<ActivationSpec> activationSpecList) {
@@ -118,15 +118,15 @@
@Override
public void configure() throws Exception {
from("jbi:service:urn:test:input")
- .process(new Processor() {
- public void process(Exchange exchange) throws Exception {
- // do nothing here , just walk around the issue of CAMEL-1955
- }
- })
- .to("jbi:service:urn:test:addAttachments?mep=in-out")
- .to("jbi:service:urn:test:transformer?mep=in-out");
-
-
+ .process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ // do nothing here , just walk around the issue of CAMEL-1955
+ }
+ })
+ .to("jbi:service:urn:test:addAttachments?mep=in-out")
+ .to("jbi:service:urn:test:transformer?mep=in-out");
+
+
from("jbi:service:urn:test:transformer").process(new Processor() {
public void process(Exchange exchange) throws Exception {
// let's copy everything
@@ -136,12 +136,12 @@
assertNotNull(exchange.getOut().getAttachment("test1.xml"));
exchange.getOut().removeAttachment("test1.xml");
exchange.getOut().removeAttachment("test2.xml");
-
+
exchange.getOut().setHeader(HEADER_TRANSFORMER, "my-transformer-header-value");
exchange.getOut().removeHeader(HEADER_ORIGINAL);
- }
+ }
});
-
+
from("jbi:service:urn:test:addAttachments").process(new Processor() {
public void process(Exchange exchange) throws Exception {
// let's copy everything
@@ -150,43 +150,43 @@
exchange.getOut().addAttachment("test1.xml", new DataHandler(new FileDataSource("pom.xml")));
exchange.getOut().addAttachment("test2.xml", new DataHandler(new FileDataSource("pom.xml")));
}
-
+
});
-
+
from("jbi:service:urn:test:filterProvider?headerFilterStrategy=#myFilterStrategy")
- .process(new Processor() {
- public void process(Exchange exchange) throws Exception {
- // do nothing here , just walk around the issue of CAMEL-1955
- }
- })
- .to("jbi:service:urn:test:addAttachments?mep=in-out")
- .to("jbi:service:urn:test:transformer?mep=in-out");
-
-
+ .process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ // do nothing here , just walk around the issue of CAMEL-1955
+ }
+ })
+ .to("jbi:service:urn:test:addAttachments?mep=in-out")
+ .to("jbi:service:urn:test:transformer?mep=in-out");
+
+
from("jbi:service:urn:test:filterConsumer")
- .process(new Processor() {
- public void process(Exchange exchange) throws Exception {
- // do nothing here , just walk around the issue of CAMEL-1955
- }
- })
- .to("jbi:service:urn:test:addAttachments?mep=in-out")
- .to("jbi:service:urn:test:transformer?mep=in-out&headerFilterStrategy=#myFilterStrategy");
-
+ .process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ // do nothing here , just walk around the issue of CAMEL-1955
+ }
+ })
+ .to("jbi:service:urn:test:addAttachments?mep=in-out")
+ .to("jbi:service:urn:test:transformer?mep=in-out&headerFilterStrategy=#myFilterStrategy");
+
}
};
}
-
+
@Override
protected CamelContext createCamelContext() {
- try {
- JndiContext context = new JndiContext();
- context.bind("myFilterStrategy", myFilterStrategy);
- JndiRegistry registry = new JndiRegistry(context);
- return new DefaultCamelContext(registry);
- } catch (Exception e) {
- fail(e.getMessage());
- }
- return null;
+ try {
+ JndiContext context = new JndiContext();
+ context.bind("myFilterStrategy", myFilterStrategy);
+ JndiRegistry registry = new JndiRegistry(context);
+ return new DefaultCamelContext(registry);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ return null;
}
public class MyHeaderFilterStrategy extends DefaultHeaderFilterStrategy {
@@ -196,8 +196,7 @@
}
protected void initialize() {
- getOutFilter().add(HEADER_TRANSFORMER);
+ getOutFilter().add(HEADER_TRANSFORMER);
}
}
-
}
Added: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiStrictSerializationTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiStrictSerializationTest.java?rev=835955&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiStrictSerializationTest.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiStrictSerializationTest.java Fri Nov 13 19:15:12 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/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java?rev=835955&r1=835954&r2=835955&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java Fri Nov 13 19:15:12 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.CamelContext;
@@ -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 client;
protected ServiceMixClient servicemixClient;
-
+
/**
* Sends an exchange to the endpoint
*/
@@ -155,7 +162,7 @@
camelContext.start();
}
-
+
protected CamelContext createCamelContext() {
return new DefaultCamelContext();
}
@@ -181,10 +188,10 @@
return createActivationSpec(comp, service, "endpoint");
}
- protected ActivationSpec createActivationSpec(Object comp, QName service, String endpoint) {
+ protected ActivationSpec createActivationSpec(Object comp, QName service, String endpointName) {
ActivationSpec spec = new ActivationSpec(comp);
spec.setService(service);
- spec.setEndpoint(endpoint);
+ spec.setEndpoint(endpointName);
return spec;
}
@@ -198,7 +205,28 @@
}
protected MockEndpoint getMockEndpoint(String uri) {
- return (MockEndpoint)camelContext.getEndpoint(uri);
+ return (MockEndpoint) camelContext.getEndpoint(uri);
+ }
+
+ 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
+ }
+ });
}
Modified: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiToCamelCbrTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiToCamelCbrTest.java?rev=835955&r1=835954&r2=835955&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiToCamelCbrTest.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiToCamelCbrTest.java Fri Nov 13 19:15:12 2009
@@ -42,7 +42,7 @@
private static final String MESSAGE_IN_FRENCH = "<message>bonjour</message>";
private static final String MESSAGE_IN_ENGLISH = "<message>hello</message>";
private final SourceTransformer transformer = new SourceTransformer();
- private Level level = null;
+ private Level level;
@Override
protected void setUp() throws Exception {
Modified: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiToCamelStreamSourceTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiToCamelStreamSourceTest.java?rev=835955&r1=835954&r2=835955&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiToCamelStreamSourceTest.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiToCamelStreamSourceTest.java Fri Nov 13 19:15:12 2009
@@ -94,8 +94,8 @@
@Override
public void configure() throws Exception {
from("jbi:service:urn:test:stream")
- .to("jbi:service:urn:test:echo?mep=in-out")
- .convertBodyTo(String.class).to("mock:result");
+ .to("jbi:service:urn:test:echo?mep=in-out")
+ .convertBodyTo(String.class).to("mock:result");
}
};
}
Modified: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/TwoServicemixCamelSusTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/TwoServicemixCamelSusTest.java?rev=835955&r1=835954&r2=835955&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/TwoServicemixCamelSusTest.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/TwoServicemixCamelSusTest.java Fri Nov 13 19:15:12 2009
@@ -24,13 +24,11 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-public class TwoServicemixCamelSusTest extends
- NonJbiCamelEndpointsIntegrationTest {
- private static final transient Log LOG = LogFactory
- .getLog(TwoServicemixCamelSusTest.class);
+public class TwoServicemixCamelSusTest extends NonJbiCamelEndpointsIntegrationTest {
+
+ private static final transient Log LOG = LogFactory.getLog(TwoServicemixCamelSusTest.class);
- private void deploySu(CamelJbiComponent component, String suName)
- throws Exception {
+ private void deploySu(CamelJbiComponent component, String suName) throws Exception {
String serviceUnitConfiguration = suName + "-src/camel-context.xml";
URL url = getClass().getResource(serviceUnitConfiguration);
File path = new File(new URI(url.toString()));
@@ -43,8 +41,7 @@
component.getServiceUnitManager().start(suName);
}
- private void undeploySu(CamelJbiComponent component, String suName)
- throws Exception {
+ private void undeploySu(CamelJbiComponent component, String suName) throws Exception {
String serviceUnitConfiguration = suName + "-src/camel-context.xml";
URL url = getClass().getResource(serviceUnitConfiguration);
File path = new File(new URI(url.toString()));
Modified: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/converter/JbiConverterTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/converter/JbiConverterTest.java?rev=835955&r1=835954&r2=835955&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/converter/JbiConverterTest.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/converter/JbiConverterTest.java Fri Nov 13 19:15:12 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.camel.converter.JbiConverter;
import org.apache.servicemix.jbi.exception.FaultException;
import org.apache.servicemix.jbi.jaxp.StringSource;
@@ -50,4 +55,35 @@
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());
+ }
+
+ 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/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/test/InvalidSerializableObject.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/test/InvalidSerializableObject.java?rev=835955&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/test/InvalidSerializableObject.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/test/InvalidSerializableObject.java Fri Nov 13 19:15:12 2009
@@ -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.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/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/util/BasicSerializationHeaderFilterStrategyTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/util/BasicSerializationHeaderFilterStrategyTest.java?rev=835955&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/util/BasicSerializationHeaderFilterStrategyTest.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/util/BasicSerializationHeaderFilterStrategyTest.java Fri Nov 13 19:15:12 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", null));
+ assertTrue("An OutputStream is not serializable", strategy.applyFilterToCamelHeaders("key", new ByteArrayOutputStream(), null));
+ assertTrue("Maps can contain non-serializable data", strategy.applyFilterToCamelHeaders("key", new HashMap(), null));
+ assertTrue("Collections can contain non-serializable data", strategy.applyFilterToCamelHeaders("key", new ArrayList(), null));
+ }
+
+}
Added: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/util/HeaderFilterStrategiesTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/util/HeaderFilterStrategiesTest.java?rev=835955&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/util/HeaderFilterStrategiesTest.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/util/HeaderFilterStrategiesTest.java Fri Nov 13 19:15:12 2009
@@ -0,0 +1,66 @@
+/*
+ * 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.Exchange;
+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, Exchange exchange) {
+ return s.equals("A");
+ }
+
+ public boolean applyFilterToExternalHeaders(String s, Object o, Exchange exchange) {
+ return s.equals("1");
+ }
+ });
+ strategies.add(new HeaderFilterStrategy() {
+
+ public boolean applyFilterToCamelHeaders(String s, Object o, Exchange exchange) {
+ return s.equals("B");
+ }
+
+ public boolean applyFilterToExternalHeaders(String s, Object o, Exchange exchange) {
+ return s.equals("2");
+ }
+ });
+
+ assertTrue("A should have been filtered", strategies.applyFilterToCamelHeaders("A", null, null));
+ assertTrue("B should have been filtered", strategies.applyFilterToCamelHeaders("B", null, null));
+ assertFalse("C should not have been filtered", strategies.applyFilterToCamelHeaders("C", null, null));
+
+ assertTrue("1 should have been filtered", strategies.applyFilterToExternalHeaders("1", null, null));
+ assertTrue("2 should have been filtered", strategies.applyFilterToExternalHeaders("2", null, null));
+ assertFalse("3 should not have been filtered", strategies.applyFilterToExternalHeaders("3", null, null));
+ }
+
+ public void testIgnoreNullStrategies() {
+ HeaderFilterStrategies strategies = new HeaderFilterStrategies();
+ strategies.add(null);
+
+ assertFalse("XYZ should not have been filtered", strategies.applyFilterToCamelHeaders("XYZ", null, null));
+ }
+}
Added: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/util/StrictSerializationHeaderFilterStrategyTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/util/StrictSerializationHeaderFilterStrategyTest.java?rev=835955&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/util/StrictSerializationHeaderFilterStrategyTest.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/util/StrictSerializationHeaderFilterStrategyTest.java Fri Nov 13 19:15:12 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(), null));
+ assertTrue("Strategy should filter Serializable implementations that can not be serialized",
+ strategy.applyFilterToCamelHeaders("key", new InvalidSerializableObject(), null));
+ assertFalse("Strategy should not filter String - is Serializable",
+ strategy.applyFilterToCamelHeaders("key", "value", null));
+ }
+}