Java Reference
In-Depth Information
Example 21.2 is what we get when we run this program against one of the
author's DNS domains.
7
Example 21.2
Running
GetDomain
against the
multitool.net
domain
[mschwarz@cassidy simpleApp]$ java GetDomain multitool.net
Object [baroni: java.lang.Object]
Object [erik: java.lang.Object]
Object [www: java.lang.Object]
Object [class: java.lang.Object]
Object [jboss: java.lang.Object]
Object [penguin: java.lang.Object]
Object [mail: java.lang.Object]
Object [cvs: java.lang.Object]
Object [stiletto: java.lang.Object]
Object [penfold: java.lang.Object]
Object [ns2: java.lang.Object]
Object [ns1: java.lang.Object]
Object [irc: java.lang.Object]
[mschwarz@cassidy simpleApp]$
The
GetDomain main()
method.
This is another “single class” program
example. In this case, the
main()
method creates an instance of the class,
passing the first command-line argument to the constructor. We'll cover the
constructor in the next section. By now, you will recognize that this is one of
the purely pedagogical examples. Note the complete lack of input validation
and error checking on the number and content of the command-line argu-
ments.
Establishing an initial context.
For both naming and directory services, it
is necessary to establish an
initial context
. A context is a collected set of names.
A directory system is a connected set of contexts. Our example is for DNS.
We must set an initial context for DNS. The class constructor (lines 11-15)
does that.
7. Note that directory operations in the JNDI DNS Service Provider Interface are done with
DNS zone transfers. Many domains, especially large domains, disable zone transfers either for
security reasons, or because they generate a lot of network traffic and are a popular tool for
Denial of Service (DoS) attacks on name servers. To put it simply: This program won't work
on a lot of domains, especially from outside.