You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/06/13 16:07:03 UTC
svn commit: r546882 - in /activemq/camel/trunk/camel-core/src:
main/java/org/apache/camel/impl/DefaultCamelContext.java
main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java
test/java/org/apache/camel/issues/Issue3Test.java
Author: jstrachan
Date: Wed Jun 13 07:07:03 2007
New Revision: 546882
URL: http://svn.apache.org/viewvc?view=rev&rev=546882
Log:
added fix for strange null handling in type converters & intermittent Issue3Test failure
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/Issue3Test.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?view=diff&rev=546882&r1=546881&r2=546882
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Wed Jun 13 07:07:03 2007
@@ -17,23 +17,10 @@
*/
package org.apache.camel.impl;
-import static org.apache.camel.util.ServiceHelper.startServices;
-import static org.apache.camel.util.ServiceHelper.stopServices;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.Callable;
-
import org.apache.camel.CamelContext;
import org.apache.camel.Component;
-import org.apache.camel.Consumer;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
import org.apache.camel.ResolveEndpointFailedException;
import org.apache.camel.Route;
import org.apache.camel.RuntimeCamelException;
@@ -47,6 +34,16 @@
import org.apache.camel.util.FactoryFinder;
import org.apache.camel.util.NoFactoryAvailableException;
import org.apache.camel.util.ObjectHelper;
+import static org.apache.camel.util.ServiceHelper.startServices;
+import static org.apache.camel.util.ServiceHelper.stopServices;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
/**
* Represents the context used to configure routes and the policies to use.
@@ -63,12 +60,15 @@
private ExchangeConverter exchangeConverter;
private Injector injector;
private ComponentResolver componentResolver;
- private boolean autoCreateComponents=true;
-
+ private boolean autoCreateComponents = true;
+
/**
* Adds a component to the container.
*/
public void addComponent(String componentName, final Component component) {
+ if (component == null) {
+ throw new IllegalArgumentException("Component cannot be null");
+ }
synchronized (components) {
if (components.containsKey(componentName)) {
throw new IllegalArgumentException("Component previously added: " + componentName);
@@ -79,24 +79,27 @@
}
public Component getComponent(String name) {
- // synchronize the look up and auto create so that 2 threads can't
- // concurrently auto create the same component.
+ // synchronize the look up and auto create so that 2 threads can't
+ // concurrently auto create the same component.
synchronized (components) {
- Component component = components.get(name);
- if( component == null && autoCreateComponents ) {
+ Component component = components.get(name);
+ if (component == null && autoCreateComponents) {
try {
- component = getComponentResolver().resolveComponent(name, this);
- addComponent(name, component);
- if( isStarted() ) {
- // If the component is looked up after the context is started,
- // lets start it up.
- startServices(component);
- }
- } catch (Exception e) {
- throw new RuntimeCamelException("Could not auto create component: "+name, e);
- }
- }
- return component;
+ component = getComponentResolver().resolveComponent(name, this);
+ if (component != null) {
+ addComponent(name, component);
+ if (isStarted()) {
+ // If the component is looked up after the context is started,
+ // lets start it up.
+ startServices(component);
+ }
+ }
+ }
+ catch (Exception e) {
+ throw new RuntimeCamelException("Could not auto create component: " + name, e);
+ }
+ }
+ return component;
}
}
@@ -109,7 +112,7 @@
throw new IllegalArgumentException("The component is not of type: " + componentType + " but is: " + component);
}
}
-
+
/**
* Removes a previously added component.
*
@@ -188,31 +191,29 @@
answer = endpoints.get(uri);
if (answer == null) {
try {
-
- // Use the URI prefix to find the component.
+
+ // Use the URI prefix to find the component.
String splitURI[] = ObjectHelper.splitOnCharacter(uri, ":", 2);
if (splitURI[1] == null) {
throw new IllegalArgumentException("Invalid URI, it did not contain a scheme: " + uri);
}
String scheme = splitURI[0];
Component component = getComponent(scheme);
-
-
- // Ask the component to resolve the endpoint.
+
+ // Ask the component to resolve the endpoint.
if (component != null) {
-
- // Have the component create the endpoint if it can.
+
+ // Have the component create the endpoint if it can.
answer = component.createEndpoint(uri);
-
+
// If it's a singleton then auto register it.
- if( answer!=null && answer.isSingleton() ) {
- if (answer != null) {
- startServices(answer);
- endpoints.put(uri, answer);
- }
+ if (answer != null && answer.isSingleton()) {
+ if (answer != null) {
+ startServices(answer);
+ endpoints.put(uri, answer);
+ }
}
}
-
}
catch (Exception e) {
throw new ResolveEndpointFailedException(uri, e);
@@ -222,7 +223,6 @@
return answer;
}
-
public <T extends Endpoint> T getEndpoint(String name, Class<T> endpointType) {
Endpoint endpoint = getEndpoint(name);
if (endpointType.isInstance(endpoint)) {
@@ -233,7 +233,6 @@
}
}
-
// Route Management Methods
//-----------------------------------------------------------------------
public List<Route> getRoutes() {
@@ -312,9 +311,9 @@
//-----------------------------------------------------------------------
protected void doStart() throws Exception {
- if (components != null) {
+ if (components != null) {
for (Component component : components.values()) {
- startServices(component);
+ startServices(component);
}
}
startRoutes(routes);
@@ -322,7 +321,7 @@
protected void doStop() throws Exception {
stopServices(servicesToClose);
- if (components != null) {
+ if (components != null) {
for (Component component : components.values()) {
stopServices(component);
}
@@ -386,12 +385,11 @@
return new DefaultComponentResolver();
}
- public boolean isAutoCreateComponents() {
- return autoCreateComponents;
- }
-
- public void setAutoCreateComponents(boolean autoCreateComponents) {
- this.autoCreateComponents = autoCreateComponents;
- }
+ public boolean isAutoCreateComponents() {
+ return autoCreateComponents;
+ }
+ public void setAutoCreateComponents(boolean autoCreateComponents) {
+ this.autoCreateComponents = autoCreateComponents;
+ }
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java?view=diff&rev=546882&r1=546881&r2=546882
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java Wed Jun 13 07:07:03 2007
@@ -71,6 +71,10 @@
}
}
+ // lets avoid NullPointerException when converting to boolean for null values
+ if (boolean.class.isAssignableFrom(toType)) {
+ return (T) Boolean.FALSE;
+ }
return null;
}
@@ -104,7 +108,7 @@
}
protected <T> TypeConverter getOrFindTypeConverter(Class toType, Object value) {
- Class fromType = Object.class;
+ Class fromType = null;
if (value != null) {
fromType = value.getClass();
}
Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/Issue3Test.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/Issue3Test.java?view=diff&rev=546882&r1=546881&r2=546882
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/Issue3Test.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/Issue3Test.java Wed Jun 13 07:07:03 2007
@@ -42,7 +42,7 @@
final Message in = exchange.getIn();
assertNotNull("Message is Null", in);
String isDebugString = in.getHeader("someproperty", String.class);
- assertNull(isDebugString);
+ assertNull("Header should be null but is: " + isDebugString, isDebugString);
assertNotNull("Message is Null", in);