Net Overview


Probably the most fundamental thing to understand about the Net package is that it is intended to provide protocol access, not a higher-level abstraction. In practice, this means that objects tend to have methods that are highly sequential and generally more "procedural" in flavor. The following list indicates the packages of the Net packageyou'll notice that they mostly correspond directly to the supported protocol list mentioned previously.

examples

org.apache.commons.net

org.apache.commons.net.bsd

org.apache.commons.net.ftp

org.apache.commons.net.ftp.parser

org.apache.commons.net.io

org.apache.commons.net.nntp

org.apache.commons.net.pop3

org.apache.commons.net.smtp

org.apache.commons.net.telnet

org.apache.commons.net.tftp

org.apache.commons.net.util

Let's look at one of these packages in a bit more depth. Figure 4-1 shows the ftp package classes. The key classes are FTPClient (a representation of the connection with methods to perform standard FTP connectivity), and FTPFile (which wraps directory and file list information). Most of the FTPClient methods are quite literal, issuing commands across a single connectionfor example, methods such as FTPClient.deleteFile(java.lang.String pathname) or FTPClient makeDirectory(java.lang.String pathname).

Figure 4-1. FTP class diagram


Origins of Commons Net

According to the Apache Jakarta Commons Net web site, the package was originally developed as a commercial suite, NetComponents:

"NetComponents was originally a commercial product, but after ORO dissolved, it was continued to be made available for those who found it useful. However, no updates have been made since version 1.3.8, released in 1998. Now that certain contract obligations have expired, it is possible to make the source code freely available under the Apache Software License."

It's fortunate that even though ORO dissolved, the time and energy to convert this to an Apache Jakarta project was made. It should be noted that the comment to the effect that "no changes have been made" is incorrect, as browsing the reports of the project shows that it is still under active development as of this writing.


The usage of the Net package classes is fairly straight forward: a connection is established, the initial reply code is read, information is sent back and forth, and then the connection is disconnected.

Warning:

It is important to remember that checking for the initial reply code is not optional. Issuing other commands won't work until you retrieve that first reply code.


In this chapter, you'll look at two simple web applications that make use of this library, one to access an FTP server, the other to access an NNTP server. Neither implements a full "client," but they do demonstrate two approaches to accessing the server. The first, the FTP "gateway," opens a connection to the FTP server, reads the resulting data, and then closes the connection. The second, the NNTP "gateway," maintains a single connection to the NNTP server and attempts to cache data retrieved (a reasonable assumption, given the mostly read-and-post nature of NNTP).



    Apache Jakarta Commons(c) Reusable Java Components
    Real World Web Services
    ISBN: N/A
    EAN: 2147483647
    Year: 2006
    Pages: 137
    Authors: Will Iverson

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net