You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2010/12/20 10:48:33 UTC
svn commit: r1051031 - in /camel/trunk:
components/camel-blueprint/src/main/java/org/apache/camel/blueprint/
components/camel-blueprint/src/main/resources/org/apache/camel/blueprint/
tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blue...
Author: gnodet
Date: Mon Dec 20 09:48:33 2010
New Revision: 1051031
URL: http://svn.apache.org/viewvc?rev=1051031&view=rev
Log:
[CAMEL-3253] camel-blueprint: support for errorHandler
Added:
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelErrorHandlerFactoryBean.java
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-14.xml
Removed:
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/ErrorHandlerDefinition.java
Modified:
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
camel/trunk/components/camel-blueprint/src/main/resources/org/apache/camel/blueprint/jaxb.index
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprintTest.java
Modified: camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java?rev=1051031&r1=1051030&r2=1051031&view=diff
==============================================================================
--- camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java (original)
+++ camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java Mon Dec 20 09:48:33 2010
@@ -118,7 +118,7 @@ public class CamelContextFactoryBean ext
@XmlElement(name = "consumerTemplate", type = CamelConsumerTemplateFactoryBean.class, required = false),
@XmlElement(name = "proxy", type = CamelProxyFactoryBean.class, required = false),
@XmlElement(name = "export", type = CamelServiceExporterDefinition.class, required = false),
- @XmlElement(name = "errorHandler", type = ErrorHandlerDefinition.class, required = false)
+ @XmlElement(name = "errorHandler", type = CamelErrorHandlerFactoryBean.class, required = false)
})
private List beans;
@XmlElement(name = "routeBuilder", required = false)
Added: camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelErrorHandlerFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelErrorHandlerFactoryBean.java?rev=1051031&view=auto
==============================================================================
--- camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelErrorHandlerFactoryBean.java (added)
+++ camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelErrorHandlerFactoryBean.java Mon Dec 20 09:48:33 2010
@@ -0,0 +1,113 @@
+/**
+ * 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.camel.blueprint;
+
+import org.apache.aries.blueprint.ExtendedBlueprintContainer;
+import org.apache.camel.CamelContext;
+import org.apache.camel.LoggingLevel;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.DefaultErrorHandlerBuilder;
+import org.apache.camel.builder.ErrorHandlerBuilder;
+import org.apache.camel.builder.LoggingErrorHandlerBuilder;
+import org.apache.camel.core.xml.AbstractCamelFactoryBean;
+import org.apache.camel.model.RedeliveryPolicyDefinition;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+import org.osgi.service.blueprint.container.NoSuchComponentException;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+@XmlRootElement(name = "errorHandler")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class CamelErrorHandlerFactoryBean extends AbstractCamelFactoryBean<ErrorHandlerBuilder> {
+
+ @XmlAttribute
+ private ErrorHandlerType type = ErrorHandlerType.DefaultErrorHandler;
+ @XmlAttribute
+ private String deadLetterUri;
+ @XmlAttribute
+ private LoggingLevel level = LoggingLevel.ERROR;
+ @XmlAttribute
+ private Boolean useOriginalMessage;
+ @XmlAttribute
+ private String onRedeliveryRef;
+ @XmlAttribute
+ private String retryWhileRef;
+ @XmlElement
+ private RedeliveryPolicyDefinition redeliveryPolicy;
+ @XmlTransient
+ private BlueprintContainer blueprintContainer;
+
+ @Override
+ public ErrorHandlerBuilder getObject() throws Exception {
+ ErrorHandlerBuilder errorHandler = getObjectType().newInstance();
+ if (errorHandler instanceof DefaultErrorHandlerBuilder) {
+ DefaultErrorHandlerBuilder handler = (DefaultErrorHandlerBuilder) errorHandler;
+ if (deadLetterUri != null) {
+ handler.setDeadLetterUri(deadLetterUri);
+ }
+ if (useOriginalMessage != null) {
+ handler.setUseOriginalMessage(useOriginalMessage);
+ }
+ if (redeliveryPolicy != null) {
+ handler.setRedeliveryPolicy(redeliveryPolicy.createRedeliveryPolicy(getCamelContext(), null));
+ }
+ if (onRedeliveryRef != null) {
+ handler.setOnRedelivery(lookup(onRedeliveryRef, Processor.class));
+ }
+ if (retryWhileRef != null) {
+ handler.setRetryWhileRef(retryWhileRef);
+ }
+ } else if (errorHandler instanceof LoggingErrorHandlerBuilder) {
+ LoggingErrorHandlerBuilder handler = (LoggingErrorHandlerBuilder) errorHandler;
+ if (level != null) {
+ handler.setLevel(level);
+ }
+ }
+ return errorHandler;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Class<? extends ErrorHandlerBuilder> getObjectType() {
+ return (Class<ErrorHandlerBuilder>) type.getTypeAsClass();
+ }
+
+ public void setBlueprintContainer(BlueprintContainer blueprintContainer) {
+ this.blueprintContainer = blueprintContainer;
+ }
+
+ protected CamelContext getCamelContextWithId(String camelContextId) {
+ if (blueprintContainer != null) {
+ return (CamelContext) blueprintContainer.getComponentInstance(camelContextId);
+ }
+ return null;
+ }
+
+ protected <T> T lookup(String name, Class<T> type) {
+ try {
+ return type.cast(blueprintContainer.getComponentInstance(name));
+ } catch (NoSuchComponentException e) {
+ return null;
+ }
+ }
+
+}
Modified: camel/trunk/components/camel-blueprint/src/main/resources/org/apache/camel/blueprint/jaxb.index
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/resources/org/apache/camel/blueprint/jaxb.index?rev=1051031&r1=1051030&r2=1051031&view=diff
==============================================================================
--- camel/trunk/components/camel-blueprint/src/main/resources/org/apache/camel/blueprint/jaxb.index (original)
+++ camel/trunk/components/camel-blueprint/src/main/resources/org/apache/camel/blueprint/jaxb.index Mon Dec 20 09:48:33 2010
@@ -17,7 +17,8 @@
CamelConsumerTemplateFactoryBean
CamelContextFactoryBean
CamelEndpointFactoryBean
+CamelErrorHandlerFactoryBean
CamelProducerTemplateFactoryBean
CamelThreadPoolFactoryBean
CamelRouteContextFactoryBean
-CamelProxyFactoryBean
\ No newline at end of file
+CamelProxyFactoryBean
Modified: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprintTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprintTest.java?rev=1051031&r1=1051030&r2=1051031&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprintTest.java (original)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprintTest.java Mon Dec 20 09:48:33 2010
@@ -19,6 +19,10 @@ package org.apache.camel.itest.osgi.blue
import java.lang.reflect.Method;
import org.apache.camel.CamelContext;
+import org.apache.camel.Route;
+import org.apache.camel.builder.DeadLetterChannelBuilder;
+import org.apache.camel.builder.ErrorHandlerBuilderRef;
+import org.apache.camel.model.RouteDefinition;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Option;
@@ -32,6 +36,7 @@ import static org.ops4j.pax.exam.CoreOpt
import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.profile;
import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption;
import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.workingDirectory;
import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.newBundle;
@@ -174,6 +179,18 @@ public class CamelBlueprintTest extends
assertEquals(TestProxySender.class.getName(), proxy.getClass().getInterfaces()[0].getName());
}
+ @Test
+ public void testErrorHandler() throws Exception {
+ getInstalledBundle("CamelBlueprintTestBundle14").start();
+ BlueprintContainer ctn = getOsgiService(BlueprintContainer.class, "(osgi.blueprint.container.symbolicname=CamelBlueprintTestBundle14)", 5000);
+ CamelContext ctx = getOsgiService(CamelContext.class, "(camel.context.symbolicname=CamelBlueprintTestBundle14)", 5000);
+ assertEquals(1, ctx.getRoutes().size());
+ RouteDefinition rd = ctx.getRouteDefinitions().get(0);
+ assertNotNull(rd.getErrorHandlerRef());
+ Object eh = ctx.getRegistry().lookup(rd.getErrorHandlerRef());
+ assertEquals(DeadLetterChannelBuilder.class.getName(), eh.getClass().getName());
+ }
+
@Configuration
public static Option[] configure() throws Exception {
@@ -250,11 +267,17 @@ public class CamelBlueprintTest extends
bundle(newBundle()
.add("OSGI-INF/blueprint/test.xml", OSGiBlueprintTestSupport.class.getResource("blueprint-12.xml"))
- .add(TestProxySender.class)
.set(Constants.BUNDLE_SYMBOLICNAME, "CamelBlueprintTestBundle12")
.set(Constants.DYNAMICIMPORT_PACKAGE, "*")
.build()).noStart(),
+ bundle(newBundle()
+ .add("OSGI-INF/blueprint/test.xml", OSGiBlueprintTestSupport.class.getResource("blueprint-14.xml"))
+ .add(TestProxySender.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "CamelBlueprintTestBundle14")
+ .set(Constants.DYNAMICIMPORT_PACKAGE, "*")
+ .build()).noStart(),
+
// install the spring dm profile
profile("spring.dm").version("1.2.0"),
// this is how you set the default log level when using pax logging (logProfile)
@@ -273,7 +296,7 @@ public class CamelBlueprintTest extends
workingDirectory("target/paxrunner/"),
- // vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5008"),
+// vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5008"),
//felix(),
equinox());
Added: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-14.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-14.xml?rev=1051031&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-14.xml (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-14.xml Mon Dec 20 09:48:33 2010
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+ <camelContext xmlns="http://camel.apache.org/schema/blueprint">
+
+ <errorHandler id="dlc" deadLetterUri="mock:dead" type="DeadLetterChannel"/>
+
+ <route errorHandlerRef="dlc">
+ <from uri="direct:start"/>
+ <to uri="mock:result"/>
+ </route>
+
+ </camelContext>
+
+</blueprint>