org.bss.esb.util
Class NetUtil

java.lang.Object
  extended byorg.bss.esb.util.NetUtil

public class NetUtil
extends java.lang.Object

Utility class that offers methods for performing the network operations such as:

 1. Http POST/GET/PUT operations
 2. Obtaining a client FTPClient for performing FTP operation.
 

Version:
1.0
Author:
Balwinder Sodhi
See Also:
FTPClient, HttpClient

Constructor Summary
NetUtil()
           
 
Method Summary
static void closeFtpSession(org.apache.commons.net.ftp.FTPClient ftp)
          Closes the FTPClient session and logs out from FTP server.
static byte[] doHttpGet(java.lang.String strURL, java.lang.String user, java.lang.String password)
          Does an HTTP GET from the supplied URL.
static int doHttpPost(java.lang.String strURL, java.io.InputStream input, java.lang.String contentType, java.lang.String user, java.lang.String password)
          Does an HTTP POST of the resource available via the supplied InputStream.
static int doHttpPut(java.lang.String strURL, java.io.InputStream input, java.lang.String contentType, java.lang.String user, java.lang.String password)
          Does an HTTP PUT of the resource available via the supplied InputStream.
static org.apache.commons.net.ftp.FTPClient getFtpClient(java.lang.String host, int port, java.lang.String user, java.lang.String passwd)
          Gets the initialized FTPClient instance.
static org.apache.commons.net.ftp.FTPClient getFtpClient(java.lang.String host, java.lang.String user, java.lang.String passwd)
          Gets the initialized FTPClient instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NetUtil

public NetUtil()
Method Detail

doHttpPost

public static int doHttpPost(java.lang.String strURL,
                             java.io.InputStream input,
                             java.lang.String contentType,
                             java.lang.String user,
                             java.lang.String password)
                      throws java.lang.Exception
Does an HTTP POST of the resource available via the supplied InputStream.

Parameters:
strURL - URL for the request target
input - InputStream for the resource to be POSTed
contentType -
user - User name for authenticating to target host
password - Password for authenticating to target host
Returns:
HTTP status code for the reply.
Throws:
java.lang.Exception

doHttpPut

public static int doHttpPut(java.lang.String strURL,
                            java.io.InputStream input,
                            java.lang.String contentType,
                            java.lang.String user,
                            java.lang.String password)
                     throws java.lang.Exception
Does an HTTP PUT of the resource available via the supplied InputStream.

Parameters:
strURL - URL for the request target
input - InputStream for the resource to be PUT
contentType -
user - User name for authenticating to target host
password - Password for authenticating to target host
Returns:
HTTP status code for the reply.
Throws:
java.lang.Exception

doHttpGet

public static byte[] doHttpGet(java.lang.String strURL,
                               java.lang.String user,
                               java.lang.String password)
                        throws java.lang.Exception
Does an HTTP GET from the supplied URL. The data read in is written into the OutputStream that we pass in.

Parameters:
strURL - URL for the request target
user - User name for authenticating to target host
password - Password for authenticating to target host
Returns:
byte[] The response body.
Throws:
java.lang.Exception

getFtpClient

public static org.apache.commons.net.ftp.FTPClient getFtpClient(java.lang.String host,
                                                                int port,
                                                                java.lang.String user,
                                                                java.lang.String passwd)
                                                         throws java.lang.Exception
Gets the initialized FTPClient instance. It connects to the default FTP port.

Parameters:
host - - FTP host
port - FTP port#
user - - FTP user
passwd - - FTP password
Returns:
FTPClient - The initialized instance of FTPClient
Throws:
java.lang.Exception

getFtpClient

public static org.apache.commons.net.ftp.FTPClient getFtpClient(java.lang.String host,
                                                                java.lang.String user,
                                                                java.lang.String passwd)
                                                         throws java.lang.Exception
Gets the initialized FTPClient instance. It connects to the default FTP port (21).

Parameters:
host - - FTP host
user - - FTP user
passwd - - FTP password
Returns:
FTPClient - The initialized instance of FTPClient
Throws:
java.lang.Exception

closeFtpSession

public static void closeFtpSession(org.apache.commons.net.ftp.FTPClient ftp)
Closes the FTPClient session and logs out from FTP server.

Parameters:
ftp - - The FTPClient.


Copyright © 2005 Balwinder Sodhi. All Rights Reserved.