CAMEL-7999: More components include documentation
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ca52ba53 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ca52ba53 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ca52ba53 Branch: refs/heads/master Commit: ca52ba53091fa9e66a5e2fc677ad215946d62527 Parents: 0d99e50 Author: Claus Ibsen <davscl...@apache.org> Authored: Fri Dec 19 14:06:04 2014 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Fri Dec 19 14:06:04 2014 +0100 ---------------------------------------------------------------------- .../camel/component/dns/DnsComponent.java | 24 +++--- .../camel/component/dns/DnsConstants.java | 10 +-- .../camel/component/dns/DnsDigEndpoint.java | 83 -------------------- .../camel/component/dns/DnsDigProducer.java | 69 ++++++++++++++++ .../apache/camel/component/dns/DnsEndpoint.java | 69 ++++++++++++++++ .../camel/component/dns/DnsIpEndpoint.java | 59 -------------- .../camel/component/dns/DnsIpProducer.java | 43 ++++++++++ .../camel/component/dns/DnsLookupEndpoint.java | 79 ------------------- .../camel/component/dns/DnsLookupProducer.java | 64 +++++++++++++++ .../org/apache/camel/component/dns/DnsType.java | 23 ++++++ .../component/dns/DnsWikipediaProducer.java | 61 ++++++++++++++ .../camel/component/dns/WikipediaEndpoint.java | 76 ------------------ 12 files changed, 344 insertions(+), 316 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/ca52ba53/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsComponent.java b/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsComponent.java index 1321ab6..13a6fd8 100644 --- a/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsComponent.java +++ b/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsComponent.java @@ -19,7 +19,7 @@ package org.apache.camel.component.dns; import java.util.Map; import org.apache.camel.Endpoint; -import org.apache.camel.impl.DefaultComponent; +import org.apache.camel.impl.UriEndpointComponent; /** * The DNS components creates endpoints of the form: <br/> @@ -65,20 +65,18 @@ import org.apache.camel.impl.DefaultComponent; * <p/> * </p> */ -public class DnsComponent extends DefaultComponent { +public class DnsComponent extends UriEndpointComponent { + + public DnsComponent() { + super(DnsEndpoint.class); + } 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 { - throw new IllegalArgumentException(uri + " is unsupported by the DNS component"); - } + DnsType type = DnsType.valueOf(remaining); + DnsEndpoint endpoint = new DnsEndpoint(uri, this); + endpoint.setDnsType(type); + setProperties(endpoint, parameters); + return endpoint; } } http://git-wip-us.apache.org/repos/asf/camel/blob/ca52ba53/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsConstants.java ---------------------------------------------------------------------- diff --git a/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsConstants.java b/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsConstants.java index 8b4b22c..00aed88 100644 --- a/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsConstants.java +++ b/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsConstants.java @@ -19,12 +19,10 @@ package org.apache.camel.component.dns; public class DnsConstants { - public static final String OPERATION_DIG = "dig"; - - public static final String OPERATION_IP = "ip"; - public static final String OPERATION_LOOKUP = "lookup"; - - public static final String OPERATION_WIKIPEDIA = "wikipedia"; + public static final String OPERATION_DIG = DnsType.dig.name(); + public static final String OPERATION_IP = DnsType.ip.name(); + public static final String OPERATION_LOOKUP = DnsType.lookup.name(); + public static final String OPERATION_WIKIPEDIA = DnsType.wikipedia.name(); public static final String DNS_CLASS = "dns.class"; http://git-wip-us.apache.org/repos/asf/camel/blob/ca52ba53/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsDigEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsDigEndpoint.java b/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsDigEndpoint.java deleted file mode 100644 index 2058441..0000000 --- a/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsDigEndpoint.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * 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.component.dns; - -import org.apache.camel.Consumer; -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.Producer; -import org.apache.camel.impl.DefaultEndpoint; -import org.apache.camel.impl.DefaultProducer; -import org.xbill.DNS.DClass; -import org.xbill.DNS.Message; -import org.xbill.DNS.Name; -import org.xbill.DNS.Record; -import org.xbill.DNS.SimpleResolver; -import org.xbill.DNS.Type; - -/** - * An endpoint for dig-like operations over DNS adresses. - * <p/> - * Inspired from Dig.java coming with the distribution of dnsjava, - * though most if not all options are unsupported. - */ -public class DnsDigEndpoint extends DefaultEndpoint { - - public DnsDigEndpoint(DnsComponent component) { - super("dns://dig", component); - } - - public Consumer createConsumer(Processor arg0) throws Exception { - throw new UnsupportedOperationException(); - } - - public Producer createProducer() throws Exception { - return new DefaultProducer(this) { - public void process(Exchange exchange) throws Exception { - String server = exchange.getIn().getHeader(DnsConstants.DNS_SERVER, String.class); - - SimpleResolver resolver = new SimpleResolver(server); - 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; - } - - String dclassValue = exchange.getIn().getHeader(DnsConstants.DNS_CLASS, String.class); - if (dclassValue == null) { - dclassValue = ""; - } - - int dclass = DClass.value(dclassValue); - if (dclass == -1) { - // by default, value is IN. - dclass = DClass.IN; - } - - 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); - exchange.getIn().setBody(response); - } - }; - } - - public boolean isSingleton() { - return false; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/ca52ba53/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsDigProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsDigProducer.java b/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsDigProducer.java new file mode 100644 index 0000000..cd756ea --- /dev/null +++ b/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsDigProducer.java @@ -0,0 +1,69 @@ +/** + * 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.component.dns; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.impl.DefaultProducer; +import org.xbill.DNS.DClass; +import org.xbill.DNS.Message; +import org.xbill.DNS.Name; +import org.xbill.DNS.Record; +import org.xbill.DNS.SimpleResolver; +import org.xbill.DNS.Type; + +/** + * A producer for dig-like operations over DNS adresses. + * <p/> + * Inspired from Dig.java coming with the distribution of dnsjava, + * though most if not all options are unsupported. + */ +public class DnsDigProducer extends DefaultProducer { + + public DnsDigProducer(Endpoint endpoint) { + super(endpoint); + } + + @Override + public void process(Exchange exchange) throws Exception { + String server = exchange.getIn().getHeader(DnsConstants.DNS_SERVER, String.class); + + SimpleResolver resolver = new SimpleResolver(server); + 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; + } + + String dclassValue = exchange.getIn().getHeader(DnsConstants.DNS_CLASS, String.class); + if (dclassValue == null) { + dclassValue = ""; + } + + int dclass = DClass.value(dclassValue); + if (dclass == -1) { + // by default, value is IN. + dclass = DClass.IN; + } + + 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); + exchange.getIn().setBody(response); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/ca52ba53/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsEndpoint.java b/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsEndpoint.java new file mode 100644 index 0000000..d36fdf0 --- /dev/null +++ b/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsEndpoint.java @@ -0,0 +1,69 @@ +/** + * 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.component.dns; + +import org.apache.camel.Component; +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.impl.DefaultEndpoint; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriPath; + +@UriEndpoint(scheme = "dns", label = "networking") +public class DnsEndpoint extends DefaultEndpoint { + + @UriPath + private DnsType dnsType; + + public DnsEndpoint(String endpointUri, Component component) { + super(endpointUri, component); + } + + @Override + public Producer createProducer() throws Exception { + if (DnsType.dig == dnsType) { + return new DnsDigProducer(this); + } else if (DnsType.ip == dnsType) { + return new DnsIpProducer(this); + } else if (DnsType.lookup == dnsType) { + return new DnsLookupProducer(this); + } else if (DnsType.wikipedia == dnsType) { + return new DnsWikipediaProducer(this); + } + // should not happen + return null; + } + + @Override + public Consumer createConsumer(Processor processor) throws Exception { + throw new UnsupportedOperationException("Consumer not supported"); + } + + @Override + public boolean isSingleton() { + return false; + } + + public DnsType getDnsType() { + return dnsType; + } + + public void setDnsType(DnsType dnsType) { + this.dnsType = dnsType; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/ca52ba53/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsIpEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsIpEndpoint.java b/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsIpEndpoint.java deleted file mode 100644 index aec8119..0000000 --- a/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsIpEndpoint.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * 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.component.dns; - -import java.net.InetAddress; - -import org.apache.camel.Component; -import org.apache.camel.Consumer; -import org.apache.camel.Exchange; -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; - -/** - * An endpoint to conduct IP address lookup from the host name. - */ -public class DnsIpEndpoint extends DefaultEndpoint { - - public DnsIpEndpoint(Component component) { - super("dns://ip", component); - } - - public Producer createProducer() throws Exception { - return new DefaultProducer(this) { - - public void process(Exchange exchange) throws Exception { - String domain = exchange.getIn().getHeader(DnsConstants.DNS_DOMAIN, String.class); - ObjectHelper.notEmpty(domain, "Header " + DnsConstants.DNS_DOMAIN); - - InetAddress address = InetAddress.getByName(domain); - exchange.getIn().setBody(address); - } - }; - } - - public Consumer createConsumer(Processor processor) throws Exception { - throw new UnsupportedOperationException("Creating a consumer is not supported"); - } - - public boolean isSingleton() { - return false; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/ca52ba53/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsIpProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsIpProducer.java b/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsIpProducer.java new file mode 100644 index 0000000..d72ea56 --- /dev/null +++ b/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsIpProducer.java @@ -0,0 +1,43 @@ +/** + * 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.component.dns; + +import java.net.InetAddress; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.impl.DefaultProducer; +import org.apache.camel.util.ObjectHelper; + +/** + * A producer to conduct IP address lookup from the host name. + */ +public class DnsIpProducer extends DefaultProducer { + + public DnsIpProducer(Endpoint endpoint) { + super(endpoint); + } + + @Override + public void process(Exchange exchange) throws Exception { + String domain = exchange.getIn().getHeader(DnsConstants.DNS_DOMAIN, String.class); + ObjectHelper.notEmpty(domain, "Header " + DnsConstants.DNS_DOMAIN); + + InetAddress address = InetAddress.getByName(domain); + exchange.getIn().setBody(address); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/ca52ba53/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsLookupEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsLookupEndpoint.java b/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsLookupEndpoint.java deleted file mode 100644 index facc27e..0000000 --- a/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsLookupEndpoint.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * 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.component.dns; - -import org.apache.camel.CamelException; -import org.apache.camel.Component; -import org.apache.camel.Consumer; -import org.apache.camel.Exchange; -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; - -/** - * An endpoint to manage lookup operations, using the API from dnsjava. - */ -public class DnsLookupEndpoint extends DefaultEndpoint { - - public DnsLookupEndpoint(Component component) { - super("dns://lookup", component); - } - - public Consumer createConsumer(Processor processor) throws Exception { - throw new UnsupportedOperationException(); - } - - public Producer createProducer() throws Exception { - return new DefaultProducer(this) { - public void process(Exchange exchange) throws Exception { - 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) { - dnsType = Type.value(String.valueOf(type)); - } - Object dclass = exchange.getIn().getHeader(DnsConstants.DNS_CLASS); - Integer dnsClass = null; - if (dclass != null) { - dnsClass = DClass.value(String.valueOf(dclass)); - } - - Lookup lookup = (dnsClass == null) - ? (dnsType == null ? new Lookup(dnsName) : new Lookup(dnsName, dnsType)) - : new Lookup(dnsName, dnsType, dnsClass); - - lookup.run(); - if (lookup.getAnswers() != null) { - exchange.getIn().setBody(lookup.getAnswers()); - } else { - throw new CamelException(lookup.getErrorString()); - } - } - }; - } - - public boolean isSingleton() { - return false; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/ca52ba53/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsLookupProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsLookupProducer.java b/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsLookupProducer.java new file mode 100644 index 0000000..54a6096 --- /dev/null +++ b/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsLookupProducer.java @@ -0,0 +1,64 @@ +/** + * 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.component.dns; + +import org.apache.camel.CamelException; +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +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; + +/** + * A producer to manage lookup operations, using the API from dnsjava. + */ +public class DnsLookupProducer extends DefaultProducer { + + public DnsLookupProducer(Endpoint endpoint) { + super(endpoint); + } + + @Override + public void process(Exchange exchange) throws Exception { + 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) { + dnsType = Type.value(String.valueOf(type)); + } + Object dclass = exchange.getIn().getHeader(DnsConstants.DNS_CLASS); + Integer dnsClass = null; + if (dclass != null) { + dnsClass = DClass.value(String.valueOf(dclass)); + } + + Lookup lookup = (dnsClass == null) + ? (dnsType == null ? new Lookup(dnsName) : new Lookup(dnsName, dnsType)) + : new Lookup(dnsName, dnsType, dnsClass); + + lookup.run(); + if (lookup.getAnswers() != null) { + exchange.getIn().setBody(lookup.getAnswers()); + } else { + throw new CamelException(lookup.getErrorString()); + } + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/ca52ba53/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsType.java ---------------------------------------------------------------------- diff --git a/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsType.java b/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsType.java new file mode 100644 index 0000000..3a78d94 --- /dev/null +++ b/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsType.java @@ -0,0 +1,23 @@ +/** + * 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.component.dns; + +public enum DnsType { + + dig, ip, lookup, wikipedia + +} http://git-wip-us.apache.org/repos/asf/camel/blob/ca52ba53/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsWikipediaProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsWikipediaProducer.java b/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsWikipediaProducer.java new file mode 100644 index 0000000..2a2ca70 --- /dev/null +++ b/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsWikipediaProducer.java @@ -0,0 +1,61 @@ +/** + * 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.component.dns; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.impl.DefaultProducer; +import org.xbill.DNS.DClass; +import org.xbill.DNS.Message; +import org.xbill.DNS.Name; +import org.xbill.DNS.Record; +import org.xbill.DNS.Section; +import org.xbill.DNS.SimpleResolver; +import org.xbill.DNS.Type; + +/** + * an endpoint to make queries against wikipedia using + * the short TXT query. + * <p/> + * See here for a reference: + * http://www.commandlinefu.com/commands/view/2829/query-wikipedia-via-console-over-dns + * <p/> + * This endpoint accepts the following header: + * term: a simple term to use to query wikipedia. + */ +public class DnsWikipediaProducer extends DefaultProducer { + + public DnsWikipediaProducer(Endpoint endpoint) { + super(endpoint); + } + + @Override + public void process(Exchange exchange) throws Exception { + SimpleResolver resolver = new SimpleResolver(); + int type = Type.TXT; + Name name = Name.fromString(String.valueOf(exchange.getIn().getHeader(DnsConstants.TERM)) + ".wp.dg.cx", Name.root); + Record rec = Record.newRecord(name, type, DClass.IN); + Message query = Message.newQuery(rec); + Message response = resolver.send(query); + Record[] records = response.getSectionArray(Section.ANSWER); + if (records.length > 0) { + exchange.getIn().setBody(records[0].rdataToString()); + } else { + exchange.getIn().setBody(null); + } + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/ca52ba53/components/camel-dns/src/main/java/org/apache/camel/component/dns/WikipediaEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-dns/src/main/java/org/apache/camel/component/dns/WikipediaEndpoint.java b/components/camel-dns/src/main/java/org/apache/camel/component/dns/WikipediaEndpoint.java deleted file mode 100644 index 36e62b4..0000000 --- a/components/camel-dns/src/main/java/org/apache/camel/component/dns/WikipediaEndpoint.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * 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.component.dns; - -import org.apache.camel.Component; -import org.apache.camel.Consumer; -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.Producer; -import org.apache.camel.impl.DefaultEndpoint; -import org.apache.camel.impl.DefaultProducer; -import org.xbill.DNS.DClass; -import org.xbill.DNS.Message; -import org.xbill.DNS.Name; -import org.xbill.DNS.Record; -import org.xbill.DNS.Section; -import org.xbill.DNS.SimpleResolver; -import org.xbill.DNS.Type; - -/** - * an endpoint to make queries against wikipedia using - * the short TXT query. - * <p/> - * See here for a reference: - * http://www.commandlinefu.com/commands/view/2829/query-wikipedia-via-console-over-dns - * <p/> - * This endpoint accepts the following header: - * term: a simple term to use to query wikipedia. - */ -public class WikipediaEndpoint extends DefaultEndpoint { - - public WikipediaEndpoint(Component component) { - super("dns:///wikipedia", component); - } - - public Consumer createConsumer(Processor processor) throws Exception { - throw new UnsupportedOperationException(); - } - - public Producer createProducer() throws Exception { - return new DefaultProducer(this) { - public void process(Exchange exchange) throws Exception { - SimpleResolver resolver = new SimpleResolver(); - int type = Type.TXT; - Name name = Name.fromString(String.valueOf(exchange.getIn().getHeader(DnsConstants.TERM)) + ".wp.dg.cx", Name.root); - Record rec = Record.newRecord(name, type, DClass.IN); - Message query = Message.newQuery(rec); - Message response = resolver.send(query); - Record[] records = response.getSectionArray(Section.ANSWER); - if (records.length > 0) { - exchange.getIn().setBody(records[0].rdataToString()); - } else { - exchange.getIn().setBody(null); - } - } - }; - } - - public boolean isSingleton() { - return false; - } -}