You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by jb...@apache.org on 2010/04/15 15:49:58 UTC
svn commit: r934406 - in
/servicemix/components/engines/servicemix-camel/trunk/src:
main/java/org/apache/servicemix/camel/
main/java/org/apache/servicemix/camel/util/
test/java/org/apache/servicemix/camel/
test/java/org/apache/servicemix/camel/util/
Author: jbonofre
Date: Thu Apr 15 13:49:58 2010
New Revision: 934406
URL: http://svn.apache.org/viewvc?rev=934406&view=rev
Log:
[SMXCOMP-735] Add a serialization=nocheck option to bypass any serializeable test.
Added:
servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/HeaderFilterStrategyConstants.java (with props)
servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/NoCheckSerializationHeaderFilterStrategy.java (with props)
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiNoCheckSerializationTest.java (with props)
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/util/NoCheckSerializationHeaderFilterStrategyTest.java (with props)
Modified:
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/JbiEndpoint.java
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiBindingTest.java
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=934406&r1=934405&r2=934406&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 Thu Apr 15 13:49:58 2010
@@ -42,6 +42,8 @@ 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.HeaderFilterStrategyConstants;
+import org.apache.servicemix.camel.util.NoCheckSerializationHeaderFilterStrategy;
import org.apache.servicemix.camel.util.StrictSerializationHeaderFilterStrategy;
import org.apache.servicemix.jbi.exception.FaultException;
@@ -69,15 +71,21 @@ public class JbiBinding {
* @param context the CamelContext
*/
public JbiBinding(CamelContext context) {
- this(context, false);
+ this(context, HeaderFilterStrategyConstants.BASIC);
}
- public JbiBinding(CamelContext context, boolean strictSerialization) {
+ public JbiBinding(CamelContext context, String serialization) {
this.context = context;
- if (strictSerialization) {
- strategies.add(new StrictSerializationHeaderFilterStrategy());
- } else {
+ if (serialization == null) {
strategies.add(new BasicSerializationHeaderFilterStrategy());
+ } else {
+ if (serialization.equalsIgnoreCase(HeaderFilterStrategyConstants.STRICT)) {
+ strategies.add(new StrictSerializationHeaderFilterStrategy());
+ } else if (serialization.equalsIgnoreCase(HeaderFilterStrategyConstants.NOCHECK)) {
+ strategies.add(new NoCheckSerializationHeaderFilterStrategy());
+ } else {
+ strategies.add(new BasicSerializationHeaderFilterStrategy());
+ }
}
}
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=934406&r1=934405&r2=934406&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 Thu Apr 15 13:49:58 2010
@@ -45,8 +45,6 @@ import org.springframework.util.StringUt
*/
public class JbiEndpoint extends DefaultEndpoint implements HeaderFilterStrategyAware {
- private static final String STRICT_SERIALIZATION = "strict";
-
private String destinationUri;
private String mep;
@@ -57,7 +55,7 @@ public class JbiEndpoint extends Default
private boolean convertExceptions;
- private boolean strictSerialization;
+ private String serialization;
private HeaderFilterStrategy headerFilterStrategy;
@@ -75,7 +73,7 @@ public class JbiEndpoint extends Default
}
public JbiBinding createBinding() {
- JbiBinding result = new JbiBinding(this.getCamelContext(), strictSerialization);
+ JbiBinding result = new JbiBinding(this.getCamelContext(), serialization);
result.setConvertExceptions(convertExceptions);
result.addHeaderFilterStrategy(headerFilterStrategy);
return result;
@@ -169,7 +167,7 @@ public class JbiEndpoint extends Default
}
String serialization = (String) params.get("serialization");
if (StringUtils.hasLength(serialization)) {
- this.setStrictSerialization(STRICT_SERIALIZATION.equalsIgnoreCase(serialization));
+ this.setSerialization(serialization);
params.remove("serialization");
}
String endpointUri = this.destinationUri + URISupport.createQueryString(params);
@@ -245,11 +243,11 @@ public class JbiEndpoint extends Default
return convertExceptions;
}
- public void setStrictSerialization(boolean strictSerialization) {
- this.strictSerialization = strictSerialization;
+ public void setSerialization(String serialization) {
+ this.serialization = serialization;
}
- public boolean isStrictSerialization() {
- return strictSerialization;
+ public String getSerialization() {
+ return serialization;
}
}
Added: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/HeaderFilterStrategyConstants.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/HeaderFilterStrategyConstants.java?rev=934406&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/HeaderFilterStrategyConstants.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/HeaderFilterStrategyConstants.java Thu Apr 15 13:49:58 2010
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.camel.util;
+
+/**
+ * <p>
+ * Constants to define the different HeaderFilterStrategy classes.
+ * </p>
+ *
+ * @author jbonofre
+ * @author slewis
+ */
+public class HeaderFilterStrategyConstants {
+
+ public static final String STRICT = "strict";
+ public static final String BASIC = "basic";
+ public static final String NOCHECK = "nocheck";
+
+}
Propchange: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/HeaderFilterStrategyConstants.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/NoCheckSerializationHeaderFilterStrategy.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/NoCheckSerializationHeaderFilterStrategy.java?rev=934406&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/NoCheckSerializationHeaderFilterStrategy.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/NoCheckSerializationHeaderFilterStrategy.java Thu Apr 15 13:49:58 2010
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.camel.util;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.HeaderFilterStrategy;
+
+/**
+ * <p>
+ * {@link org.apache.camel.spi.HeaderFilterStrategy} that allows any property values through.
+ * </p>
+ *
+ * @author jbonofre
+ * @author slewis
+ */
+public class NoCheckSerializationHeaderFilterStrategy 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 false;
+ }
+
+}
Propchange: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/util/NoCheckSerializationHeaderFilterStrategy.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
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=934406&r1=934405&r2=934406&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 Thu Apr 15 13:49:58 2010
@@ -58,7 +58,7 @@ public class JbiBindingTest extends Test
@Override
protected void setUp() throws Exception {
factory = new MockExchangeFactory();
- binding = new JbiBinding(new DefaultCamelContext(), false);
+ binding = new JbiBinding(new DefaultCamelContext());
binding.addHeaderFilterStrategy(new MyHeaderFilterStrategy());
}
Added: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiNoCheckSerializationTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiNoCheckSerializationTest.java?rev=934406&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiNoCheckSerializationTest.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiNoCheckSerializationTest.java Thu Apr 15 13:49:58 2010
@@ -0,0 +1,90 @@
+/*
+ * 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.servicemix.camel.test.InvalidSerializableObject;
+import org.apache.servicemix.client.DefaultServiceMixClient;
+import org.apache.servicemix.client.ServiceMixClient;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+
+/**
+ * <p>
+ * Testcase for serialization=NOCHECK (doesn't remove any non-serializable objects).
+ * </p>
+ *
+ * @author jbonofre
+ * @author slewis
+ */
+public class JbiNoCheckSerializationTest 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 testInOutWithNoCheckSerialization() 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));
+ assertTrue("Non-serializable values are still in the headers", exchange.getOutMessage().getPropertyNames().contains(NON_SERIALIZABLE_KEY));
+ assertTrue("Invalid serializable values are still 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=nocheck")
+ .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");
+ }
+ };
+ }
+
+}
Propchange: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiNoCheckSerializationTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/util/NoCheckSerializationHeaderFilterStrategyTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/util/NoCheckSerializationHeaderFilterStrategyTest.java?rev=934406&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/util/NoCheckSerializationHeaderFilterStrategyTest.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/util/NoCheckSerializationHeaderFilterStrategyTest.java Thu Apr 15 13:49:58 2010
@@ -0,0 +1,44 @@
+/*
+ * 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 org.apache.camel.spi.HeaderFilterStrategy;
+import org.apache.servicemix.camel.test.InvalidSerializableObject;
+
+import junit.framework.TestCase;
+
+/**
+ * <p>
+ * Test case for {@link org.apache.servicemix.camel.util.NoCheckSerializationHeaderFilterStrategy}
+ * </p>
+ *
+ * @author jbonofre
+ * @author slewis
+ */
+public class NoCheckSerializationHeaderFilterStrategyTest extends TestCase {
+
+ private HeaderFilterStrategy strategy = new NoCheckSerializationHeaderFilterStrategy();
+
+ public void testApplyFilterToCamelHeaders() {
+ assertFalse("Strategy shouldn't filter ByteArrayInputStream - is not serializable", strategy.applyFilterToCamelHeaders("key", new ByteArrayOutputStream(), null));
+ assertFalse("Strategy shouldn't filter Serializable implementations that can not be serialized", strategy.applyFilterToCamelHeaders("key", new InvalidSerializableObject(), null));
+ assertFalse("Strategy shouldn't filter String - is Serializable", strategy.applyFilterToCamelHeaders("key", "value", null));
+ }
+
+}
Propchange: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/util/NoCheckSerializationHeaderFilterStrategyTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain