org.dmonix.net
Class NetUtil

java.lang.Object
  extended byorg.dmonix.net.NetUtil

public abstract class NetUtil
extends java.lang.Object

Class with net related utility methods.

Copyright: Copyright (c) 2004

Company: dmonix.org

Version:
1.0
Author:
Peter Nerg

Field Summary
static java.lang.String CONTENT_TYPE_PLAIN
          Content type plain set in the HTTP header.
static java.lang.String CONTENT_TYPE_XML
          Content type XML set in the HTTP header.
static java.lang.String ENCODING_ISO_8859_1
          ISO Latin Alphabet No. 1, a.k.a.
static java.lang.String ENCODING_US_ASCII
          Seven-bit ASCII, a.k.a.
static java.lang.String ENCODING_UTF_16
          Sixteen-bit UCS Transformation Format, byte order identified by an optional byte-order mark.
static java.lang.String ENCODING_UTF_16BE
          Sixteen-bit UCS Transformation Format, big-endian byte order.
static java.lang.String ENCODING_UTF_16LE
          Sixteen-bit UCS Transformation Format, little-endian byte order.
static java.lang.String ENCODING_UTF_8
          Eight-bit UCS Transformation Format.
 
Constructor Summary
NetUtil()
           
 
Method Summary
static java.lang.String getExternalIPAddress()
          The method returns the IP-address as seen by servers/clients outside the local LAN.
static java.util.Date getModifiedDate(java.net.URL url)
          Returns the date of the last modification for the remote file.
static void resetProxy()
          Resets/removes the system parameters for the proxy host.
static void resetSocketTimeout()
          Resets/removes the socket timeout.
static java.lang.String sendHTTPGetRequest(java.lang.String address, int port, java.lang.String file, java.lang.String contentType, java.lang.String requestString)
          Send a HTTP get request.
static java.lang.String sendHTTPGetRequest(java.lang.String address, java.lang.String file)
          Send a HTTP get request.
static java.lang.String sendHTTPPostRequest(java.lang.String address, int port, java.lang.String file, java.lang.String contentType, java.lang.String requestString)
          Send a HTTP post request.
static java.lang.String sendHTTPPostRequest(java.lang.String address, java.lang.String file)
          Send a HTTP post request.
static java.lang.String sendHTTPSGetRequest(java.lang.String address, int port, java.lang.String file, java.lang.String contentType, java.lang.String requestString)
          Send a HTTPS get request.
static java.lang.String sendHTTPSGetRequest(java.lang.String address, java.lang.String file)
          Send a HTTPS get request.
static java.lang.String sendHTTPSPostRequest(java.lang.String address, int port, java.lang.String file, java.lang.String contentType, java.lang.String requestString)
          Send a HTTPS post request.
static java.lang.String sendHTTPSPostRequest(java.lang.String address, java.lang.String file)
          Send a HTTPS post request.
static void setProxy(java.lang.String proxyHost, java.lang.String proxyPort)
          Sets the system parameters used to determine the proxy.
 void setSocketTimeout(java.lang.String timeout)
          Sets the socket timeout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTENT_TYPE_PLAIN

public static final java.lang.String CONTENT_TYPE_PLAIN
Content type plain set in the HTTP header.

See Also:
Constant Field Values

CONTENT_TYPE_XML

public static final java.lang.String CONTENT_TYPE_XML
Content type XML set in the HTTP header.

See Also:
Constant Field Values

ENCODING_US_ASCII

public static final java.lang.String ENCODING_US_ASCII
Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the Unicode character set.

See Also:
Constant Field Values

ENCODING_ISO_8859_1

public static final java.lang.String ENCODING_ISO_8859_1
ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1.

See Also:
Constant Field Values

ENCODING_UTF_8

public static final java.lang.String ENCODING_UTF_8
Eight-bit UCS Transformation Format.

See Also:
Constant Field Values

ENCODING_UTF_16BE

public static final java.lang.String ENCODING_UTF_16BE
Sixteen-bit UCS Transformation Format, big-endian byte order.

See Also:
Constant Field Values

ENCODING_UTF_16LE

public static final java.lang.String ENCODING_UTF_16LE
Sixteen-bit UCS Transformation Format, little-endian byte order.

See Also:
Constant Field Values

ENCODING_UTF_16

public static final java.lang.String ENCODING_UTF_16
Sixteen-bit UCS Transformation Format, byte order identified by an optional byte-order mark.

See Also:
Constant Field Values
Constructor Detail

NetUtil

public NetUtil()
Method Detail

getExternalIPAddress

public static java.lang.String getExternalIPAddress()
                                             throws java.io.IOException,
                                                    java.net.MalformedURLException
The method returns the IP-address as seen by servers/clients outside the local LAN.
The method does not return the locally configured IP-address for the client, i.e. the IP-address configured for the client in the LAN.
Instead the method returns IP-address as perceived by servers outside the LAN.
This means that the method returns the IP-address of the proxy/firewall/gateway server.
The method attemps to contact http://www.dmonix.org/getIP.jsp to find out the IP-address.

Returns:
The IP-address
Throws:
java.io.IOException
java.net.MalformedURLException

getModifiedDate

public static java.util.Date getModifiedDate(java.net.URL url)
                                      throws java.io.IOException
Returns the date of the last modification for the remote file.
This is done by sending a HTTP HEAD request and read the Last-Modified parameter in the answer.

Parameters:
url - The URL of the file
Returns:
The date, null if not possible to parse
Throws:
java.io.IOException

setProxy

public static void setProxy(java.lang.String proxyHost,
                            java.lang.String proxyPort)
Sets the system parameters used to determine the proxy.
The method sets system properties, i.e.the method only needs to be run once.

Parameters:
proxyHost - The host
proxyPort - The port

resetProxy

public static void resetProxy()
Resets/removes the system parameters for the proxy host.


setSocketTimeout

public void setSocketTimeout(java.lang.String timeout)
Sets the socket timeout.

Parameters:
timeout - socket timeout in millis

resetSocketTimeout

public static void resetSocketTimeout()
Resets/removes the socket timeout.


sendHTTPGetRequest

public static java.lang.String sendHTTPGetRequest(java.lang.String address,
                                                  java.lang.String file)
                                           throws java.io.IOException,
                                                  java.net.MalformedURLException
Send a HTTP get request.
Default HTTP parameters are:

Parameters:
address - The remote address
file - The remote file
Returns:
The response string from the remote server
Throws:
java.io.IOException
java.net.MalformedURLException

sendHTTPGetRequest

public static java.lang.String sendHTTPGetRequest(java.lang.String address,
                                                  int port,
                                                  java.lang.String file,
                                                  java.lang.String contentType,
                                                  java.lang.String requestString)
                                           throws java.io.IOException,
                                                  java.net.MalformedURLException
Send a HTTP get request.

Parameters:
address - The remote address
port - The remote port
file - The remote file
contentType - content type
requestString - The string to send
Returns:
The response string from the remote server
Throws:
java.io.IOException
java.net.MalformedURLException
See Also:
CONTENT_TYPE_PLAIN, CONTENT_TYPE_XML

sendHTTPPostRequest

public static java.lang.String sendHTTPPostRequest(java.lang.String address,
                                                   java.lang.String file)
                                            throws java.io.IOException,
                                                   java.net.MalformedURLException
Send a HTTP post request.
Default HTTP parameters are:

Parameters:
address - The remote address
file - The remote file
Returns:
The response string from the remote server
Throws:
java.io.IOException
java.net.MalformedURLException

sendHTTPPostRequest

public static java.lang.String sendHTTPPostRequest(java.lang.String address,
                                                   int port,
                                                   java.lang.String file,
                                                   java.lang.String contentType,
                                                   java.lang.String requestString)
                                            throws java.io.IOException,
                                                   java.net.MalformedURLException
Send a HTTP post request.

Parameters:
address - The remote address
port - The remote port
file - The remote file
contentType - content type
requestString - The string to send
Returns:
The response string from the remote server
Throws:
java.io.IOException
java.net.MalformedURLException
See Also:
CONTENT_TYPE_PLAIN, CONTENT_TYPE_XML

sendHTTPSGetRequest

public static java.lang.String sendHTTPSGetRequest(java.lang.String address,
                                                   java.lang.String file)
                                            throws java.io.IOException,
                                                   java.net.MalformedURLException
Send a HTTPS get request.
Default HTTPS parameters are:

Parameters:
address - The remote address
file - The remote file
Returns:
The response string from the remote server
Throws:
java.io.IOException
java.net.MalformedURLException

sendHTTPSGetRequest

public static java.lang.String sendHTTPSGetRequest(java.lang.String address,
                                                   int port,
                                                   java.lang.String file,
                                                   java.lang.String contentType,
                                                   java.lang.String requestString)
                                            throws java.io.IOException,
                                                   java.net.MalformedURLException
Send a HTTPS get request.

Parameters:
address - The remote address
port - The remote port
file - The remote file
contentType - content type
requestString - The string to send
Returns:
The response string from the remote server
Throws:
java.io.IOException
java.net.MalformedURLException
See Also:
CONTENT_TYPE_PLAIN, CONTENT_TYPE_XML

sendHTTPSPostRequest

public static java.lang.String sendHTTPSPostRequest(java.lang.String address,
                                                    java.lang.String file)
                                             throws java.io.IOException,
                                                    java.net.MalformedURLException
Send a HTTPS post request.
Default HTTPS parameters are:

Parameters:
address - The remote address
file - The remote file
Returns:
The response string from the remote server
Throws:
java.io.IOException
java.net.MalformedURLException

sendHTTPSPostRequest

public static java.lang.String sendHTTPSPostRequest(java.lang.String address,
                                                    int port,
                                                    java.lang.String file,
                                                    java.lang.String contentType,
                                                    java.lang.String requestString)
                                             throws java.io.IOException,
                                                    java.net.MalformedURLException
Send a HTTPS post request.

Parameters:
address - The remote address
port - The remote port
file - The remote file
contentType - content type
requestString - The string to send
Returns:
The response string from the remote server
Throws:
java.io.IOException
java.net.MalformedURLException
See Also:
CONTENT_TYPE_PLAIN, CONTENT_TYPE_XML


Copyright © 1998-2005 dmonix.org Peter Nerg, All Rights Reserved.