Author: iocanel
Date: Sat Feb  4 18:23:18 2012
New Revision: 1240577

URL: http://svn.apache.org/viewvc?rev=1240577&view=rev
Log:
[CAMEL-4859] Fixed possible NPE during avro component initiallization.

Modified:
    
camel/trunk/components/camel-avro/src/main/java/org/apache/camel/component/avro/AvroComponent.java

Modified: 
camel/trunk/components/camel-avro/src/main/java/org/apache/camel/component/avro/AvroComponent.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-avro/src/main/java/org/apache/camel/component/avro/AvroComponent.java?rev=1240577&r1=1240576&r2=1240577&view=diff
==============================================================================
--- 
camel/trunk/components/camel-avro/src/main/java/org/apache/camel/component/avro/AvroComponent.java
 (original)
+++ 
camel/trunk/components/camel-avro/src/main/java/org/apache/camel/component/avro/AvroComponent.java
 Sat Feb  4 18:23:18 2012
@@ -57,16 +57,9 @@ public class AvroComponent extends Defau
         } else {
             config = new AvroConfiguration();
         }
-        URI enpointUri = new URI(URISupport.normalizeUri(remaining));
-        config.parseURI(enpointUri, parameters, this);
-        setProperties(config, parameters);
 
-        if (config.getProtocol() == null && config.getProtocolClassName() != 
null) {
-            Class<?> protocolClass = 
getCamelContext().getClassResolver().resolveClass(config.getProtocolClassName());
-            Field f = protocolClass.getField("PROTOCOL");
-            Protocol protocol = (Protocol) f.get(null);
-            config.setProtocol(protocol);
-        }
+        URI enpointUri = new URI(URISupport.normalizeUri(remaining));
+        applyToConfiguration(config, enpointUri, parameters);
 
         if (AvroConstants.AVRO_NETTY_TRANSPORT.equals(enpointUri.getScheme())) 
{
             return new AvroNettyEndpoint(remaining, this, config);
@@ -77,6 +70,33 @@ public class AvroComponent extends Defau
         }
     }
 
+    /**
+     * Applies enpoint parameters to configuration & resolves protocol and 
other required configuration properties.
+     * @param config
+     * @param enpointUri
+     * @param parameters
+     * @throws Exception
+     */
+    private void applyToConfiguration(AvroConfiguration config, URI 
enpointUri, Map<String, Object> parameters) throws Exception {
+        config.parseURI(enpointUri, parameters, this);
+        setProperties(config, parameters);
+
+        if (config.getProtocol() == null && config.getProtocolClassName() != 
null) {
+            Class<?> protocolClass = 
getCamelContext().getClassResolver().resolveClass(config.getProtocolClassName());
+            if (protocolClass != null) {
+                Field f = protocolClass.getField("PROTOCOL");
+                if (f != null) {
+                    Protocol protocol = (Protocol) f.get(null);
+                    config.setProtocol(protocol);
+                }
+            }
+        }
+
+        if (config.getProtocol() == null) {
+            throw new IllegalArgumentException("Avro configuration does not 
contain protocol");
+        }
+    }
+
 
     public AvroConfiguration getConfiguration() {
         return configuration;


Reply via email to