camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1073665 - in /camel/trunk/components/camel-dns: ./ src/main/java/org/apache/camel/component/dns/ src/main/java/org/apache/camel/component/dns/types/
Date Wed, 23 Feb 2011 09:56:21 GMT
Author: davsclaus
Date: Wed Feb 23 09:56:20 2011
New Revision: 1073665

URL: http://svn.apache.org/viewvc?rev=1073665&view=rev
Log:
CAMEL-3667: Polished camel-dns.

Modified:
    camel/trunk/components/camel-dns/   (props changed)
    camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsComponent.java
    camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsConstants.java
    camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsDigEndpoint.java
    camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsIpEndpoint.java
    camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsLookupEndpoint.java
    camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/WikipediaEndpoint.java
    camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/types/DnsConverter.java
    camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/types/DnsRecordConverter.java

Propchange: camel/trunk/components/camel-dns/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Feb 23 09:56:20 2011
@@ -0,0 +1,9 @@
+.project
+.checkstyle
+.pmd
+.classpath
+target
+.settings
+eclipse-classes
+*.i??
+classes

Modified: camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsComponent.java?rev=1073665&r1=1073664&r2=1073665&view=diff
==============================================================================
--- camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsComponent.java
(original)
+++ camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsComponent.java
Wed Feb 23 09:56:20 2011
@@ -70,20 +70,14 @@ public class DnsComponent extends Defaul
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object>
parameters) throws Exception {
         if (DnsConstants.OPERATION_IP.equals(remaining)) {
             return new DnsIpEndpoint(this);
+        } else if (DnsConstants.OPERATION_LOOKUP.equals(remaining)) {
+            return new DnsLookupEndpoint(this);
+        } else if (DnsConstants.OPERATION_DIG.equals(remaining)) {
+            return new DnsDigEndpoint(this);
+        } else if (DnsConstants.OPERATION_WIKIPEDIA.equals(remaining)) {
+            return new WikipediaEndpoint(this);
         } else {
-            if (DnsConstants.OPERATION_LOOKUP.equals(remaining)) {
-                return new DnsLookupEndpoint(this);
-            } else {
-                if (DnsConstants.OPERATION_DIG.equals(remaining)) {
-                    return new DnsDigEndpoint(this);
-                } else {
-                    if (DnsConstants.OPERATION_WIKIPEDIA.equals(remaining)) {
-                        return new WikipediaEndpoint(this);
-                    } else {
-                        throw new IllegalArgumentException(uri + "is unsupported by the DNS
component");
-                    }
-                }
-            }
+            throw new IllegalArgumentException(uri + " is unsupported by the DNS component");
         }
     }
 

Modified: camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsConstants.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsConstants.java?rev=1073665&r1=1073664&r2=1073665&view=diff
==============================================================================
--- camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsConstants.java
(original)
+++ camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsConstants.java
Wed Feb 23 09:56:20 2011
@@ -29,6 +29,7 @@ public class DnsConstants {
     public static final String DNS_CLASS = "dns.class";
 
     public static final String DNS_NAME = "dns.name";
+    public static final String DNS_DOMAIN = "dns.domain";
 
     public static final String DNS_SERVER = "dns.server";
     public static final String DNS_TYPE = "dns.type";

Modified: camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsDigEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsDigEndpoint.java?rev=1073665&r1=1073664&r2=1073665&view=diff
==============================================================================
--- camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsDigEndpoint.java
(original)
+++ camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsDigEndpoint.java
Wed Feb 23 09:56:20 2011
@@ -22,6 +22,7 @@ import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
 import org.xbill.DNS.DClass;
 import org.xbill.DNS.Message;
 import org.xbill.DNS.Name;
@@ -39,7 +40,6 @@ public class DnsDigEndpoint extends Defa
 
     public DnsDigEndpoint(DnsComponent component) {
         super("dns://dig", component);
-
     }
 
     public Consumer createConsumer(Processor arg0) throws Exception {
@@ -48,25 +48,23 @@ public class DnsDigEndpoint extends Defa
 
     public Producer createProducer() throws Exception {
         return new DefaultProducer(this) {
-
             public void process(Exchange exchange) throws Exception {
-                String server = null;
-                if (exchange.getIn().getHeader(DnsConstants.DNS_SERVER) != null) {
-                    server = String.valueOf(exchange.getIn().
-                        getHeader(DnsConstants.DNS_SERVER));
-                }
+                String server = exchange.getIn().getHeader(DnsConstants.DNS_SERVER, String.class);
+                ObjectHelper.notEmpty(server, "Header " + DnsConstants.DNS_SERVER);
+
                 SimpleResolver resolver = new SimpleResolver(server);
-                int type = Type.value(String.valueOf(exchange.getIn().getHeader(DnsConstants.DNS_TYPE)));
+                int type = Type.value(exchange.getIn().getHeader(DnsConstants.DNS_TYPE, String.class));
                 if (type == -1) {
                     // default: if unparsable value given, use A.
                     type = Type.A;
                 }
-                int dclass = DClass.value(String.valueOf(exchange.getIn().getHeader(DnsConstants.DNS_CLASS)));
+                int dclass = DClass.value(exchange.getIn().getHeader(DnsConstants.DNS_CLASS,
String.class));
                 if (dclass == -1) {
                     // by default, value is IN.
                     dclass = DClass.IN;
                 }
-                Name name = Name.fromString(String.valueOf(exchange.getIn().getHeader(DnsConstants.DNS_NAME)),
Name.root);
+
+                Name name = Name.fromString(exchange.getIn().getHeader(DnsConstants.DNS_NAME,
String.class), Name.root);
                 Record rec = Record.newRecord(name, type, dclass);
                 Message query = Message.newQuery(rec);
                 Message response = resolver.send(query);

Modified: camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsIpEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsIpEndpoint.java?rev=1073665&r1=1073664&r2=1073665&view=diff
==============================================================================
--- camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsIpEndpoint.java
(original)
+++ camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsIpEndpoint.java
Wed Feb 23 09:56:20 2011
@@ -25,6 +25,7 @@ import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
 import org.xbill.DNS.Address;
 
 /**
@@ -40,22 +41,21 @@ public class DnsIpEndpoint extends Defau
         return new DefaultProducer(this) {
 
             public void process(Exchange exchange) throws Exception {
-                Object domain = exchange.getIn().getHeader("dns.domain");
-                if (!(domain instanceof String) || ((String) domain).length() == 0) {
-                    throw new IllegalArgumentException("Invalid or null domain :" + domain);
-                }
-                InetAddress address = Address.getByName((String) domain);
+                String domain = exchange.getIn().getHeader(DnsConstants.DNS_DOMAIN, String.class);
+                ObjectHelper.notEmpty(domain, "Header " + DnsConstants.DNS_DOMAIN);
+
+                InetAddress address = Address.getByName(domain);
                 exchange.getOut().setBody(address);
             }
         };
     }
 
-    public boolean isSingleton() {
-        return false;
-    }
-
     public Consumer createConsumer(Processor processor) throws Exception {
         throw new UnsupportedOperationException("Creating a consumer is not supported");
     }
 
+    public boolean isSingleton() {
+        return false;
+    }
+
 }

Modified: camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsLookupEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsLookupEndpoint.java?rev=1073665&r1=1073664&r2=1073665&view=diff
==============================================================================
--- camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsLookupEndpoint.java
(original)
+++ camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsLookupEndpoint.java
Wed Feb 23 09:56:20 2011
@@ -23,6 +23,7 @@ import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
 import org.xbill.DNS.DClass;
 import org.xbill.DNS.Lookup;
 import org.xbill.DNS.Type;
@@ -42,13 +43,10 @@ public class DnsLookupEndpoint extends D
 
     public Producer createProducer() throws Exception {
         return new DefaultProducer(this) {
-
             public void process(Exchange exchange) throws Exception {
-                Object name = exchange.getIn().getHeader(DnsConstants.DNS_NAME);
-                if (name == null || "".equals(name)) {
-                    throw new IllegalArgumentException("name is null or empty");
-                }
-                String dnsName = String.valueOf(name);
+                String dnsName = exchange.getIn().getHeader(DnsConstants.DNS_NAME, String.class);
+                ObjectHelper.notEmpty(dnsName, "Header " + DnsConstants.DNS_NAME);
+
                 Object type = exchange.getIn().getHeader(DnsConstants.DNS_TYPE);
                 Integer dnsType = null;
                 if (type != null) {
@@ -60,7 +58,7 @@ public class DnsLookupEndpoint extends D
                     dnsClass = DClass.value(String.valueOf(dclass));
                 }
 
-                Lookup lookup = null;
+                Lookup lookup;
                 if (dnsType != null && dnsClass != null) {
                     lookup = new Lookup(dnsName, dnsType, dnsClass);
                 } else {
@@ -78,7 +76,6 @@ public class DnsLookupEndpoint extends D
                     exchange.getOut().setBody(lookup.getErrorString());
                 }
             }
-
         };
     }
 

Modified: camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/WikipediaEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/WikipediaEndpoint.java?rev=1073665&r1=1073664&r2=1073665&view=diff
==============================================================================
--- camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/WikipediaEndpoint.java
(original)
+++ camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/WikipediaEndpoint.java
Wed Feb 23 09:56:20 2011
@@ -53,7 +53,6 @@ public class WikipediaEndpoint extends D
 
     public Producer createProducer() throws Exception {
         return new DefaultProducer(this) {
-
             public void process(Exchange exchange) throws Exception {
                 SimpleResolver resolver = new SimpleResolver();
                 int type = Type.TXT;

Modified: camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/types/DnsConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/types/DnsConverter.java?rev=1073665&r1=1073664&r2=1073665&view=diff
==============================================================================
--- camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/types/DnsConverter.java
(original)
+++ camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/types/DnsConverter.java
Wed Feb 23 09:56:20 2011
@@ -30,64 +30,43 @@ import org.xbill.DNS.Record;
  * A converter for all the DNS objects used by the DNS component.
  */
 @Converter
-public class DnsConverter {
+public final class DnsConverter {
+
+    private DnsConverter() {
+    }
 
-    /**
-     * @param record
-     * @return the String representation of a record.
-     */
     @Converter
-    public String convert(Record record) {
+    public static String toString(Record record) {
         return record.toString();
     }
 
-    /**
-     * @param records
-     * @return the String representation of a record.
-     */
     @Converter
-    public List<String> convert(Record[] records) {
+    public static List<String> toList(Record[] records) {
         List<String> list = new ArrayList<String>();
         for (Record rec : records) {
-            list.add(convert(rec));
+            list.add(toString(rec));
         }
         return list;
     }
 
-    /**
-     * @param message
-     * @return the String representation of a message.
-     */
     @Converter
-    public String convert(Message message) {
+    public static String toString(Message message) {
         return message.toString();
     }
 
-    /**
-     * @param address a DNS address
-     * @return its String representation.
-     */
     @Converter
-    public String convert(Address address) {
+    public static String toString(Address address) {
         return address.toString();
     }
 
-    /**
-     * @param address
-     * @return the host name of the address.
-     */
     @Converter
-    public String convert(InetAddress address) {
+    public static String toString(InetAddress address) {
         return address.getHostAddress();
     }
 
-    /**
-     * @param domain
-     * @return the InetAddress object for a given domain.
-     * @throws UnknownHostException
-     */
     @Converter
-    public InetAddress convert(String domain) throws UnknownHostException {
-        return Address.getByName((String) domain);
+    public static InetAddress toInetAddress(String domain) throws UnknownHostException {
+        return Address.getByName(domain);
     }
+
 }

Modified: camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/types/DnsRecordConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/types/DnsRecordConverter.java?rev=1073665&r1=1073664&r2=1073665&view=diff
==============================================================================
--- camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/types/DnsRecordConverter.java
(original)
+++ camel/trunk/components/camel-dns/src/main/java/org/apache/camel/component/dns/types/DnsRecordConverter.java
Wed Feb 23 09:56:20 2011
@@ -18,6 +18,7 @@ package org.apache.camel.component.dns.t
 
 import java.io.IOException;
 
+import org.apache.camel.Converter;
 import org.xbill.DNS.DClass;
 import org.xbill.DNS.ExtendedResolver;
 import org.xbill.DNS.Message;
@@ -31,14 +32,18 @@ import org.xbill.DNS.Type;
 /**
  * More converters for all the DNS objects used by the DNS component.
  */
-public class DnsRecordConverter {
+@Converter
+public final class DnsRecordConverter {
+
+    private DnsRecordConverter() {
+    }
 
     /**
      * @param ip, like "192.168.1.1"
      * @return the complete DNS record for that IP.
-     * @throws IOException
      */
-    public Record convert(String ip) throws IOException {
+    @Converter
+    public static Record toRecord(String ip) throws IOException {
         Resolver res = new ExtendedResolver();
 
         Name name = ReverseMap.fromAddress(ip);



Mime
View raw message