to.etc.net
Class NetTools

java.lang.Object
  extended by to.etc.net.NetTools

public final class NetTools
extends java.lang.Object

Utilities for net access.

Author:
Frits Jalvingh Created on Jan 27, 2005

Nested Class Summary
static class NetTools.HttpInputStream
           
 
Method Summary
static void appendRootRelativeURL(java.lang.Appendable a, javax.servlet.http.HttpServletRequest req, java.lang.String rurl)
          Constructs an URL that is relative to the root of the server from an application-root based URL.
static java.lang.String getApplicationContext(javax.servlet.http.HttpServletRequest req)
          This returns the application's context path without any slashes!!.
static java.lang.String getApplicationURL(javax.servlet.http.HttpServletRequest req)
          Returns the URL to the root of the application.
static java.lang.String getHostName(javax.servlet.http.HttpServletRequest req)
           
static int getHostPort(javax.servlet.http.HttpServletRequest req)
           
static java.lang.String getHostURL(javax.servlet.http.HttpServletRequest req)
           
static void getHostURL(java.lang.StringBuffer sb, javax.servlet.http.HttpServletRequest req)
          Takes the host= parameter in the header to construct the real hostname.
static java.lang.String getInputPath(javax.servlet.http.HttpServletRequest req)
          Takes an input request and returns a proper relative path for the request.
static java.lang.String getRootRelativeURL(javax.servlet.http.HttpServletRequest req, java.lang.String rurl)
           
static java.io.InputStream httpGetStream(java.lang.String url, int timeout)
          Calls an external server and returns the response as an inputstream.
static java.lang.String httpGetString(java.lang.String url, int timeout)
          Calls an external server and returns the response as a string.
static org.w3c.dom.Document httpGetXMLDocument(java.lang.String url, int timeout, boolean namespaceaware)
          Calls an external server and tries to retrieve an XML formatted document from it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getHostURL

public static void getHostURL(java.lang.StringBuffer sb,
                              javax.servlet.http.HttpServletRequest req)
Takes the host= parameter in the header to construct the real hostname.

Parameters:
sb -
req -
Throws:
java.lang.Exception

getHostURL

public static java.lang.String getHostURL(javax.servlet.http.HttpServletRequest req)

getHostName

public static java.lang.String getHostName(javax.servlet.http.HttpServletRequest req)

getHostPort

public static int getHostPort(javax.servlet.http.HttpServletRequest req)

getInputPath

public static java.lang.String getInputPath(javax.servlet.http.HttpServletRequest req)
Takes an input request and returns a proper relative path for the request. This properly handles URLEncoding and returns a string which NEVER starts with a '/', and which contains no hostname or port.

Parameters:
req -
Returns:

getApplicationURL

public static java.lang.String getApplicationURL(javax.servlet.http.HttpServletRequest req)
Returns the URL to the root of the application. This is the complete host URL including http://, host name and port number, followed by the webapp's context. The path is guaranteed to end in a slash.

Parameters:
req -
Returns:

getApplicationContext

public static java.lang.String getApplicationContext(javax.servlet.http.HttpServletRequest req)
This returns the application's context path without any slashes!!. So for a webapp deployed to http://www.test.nl:8080/demoapp/ this will return the string "demoapp". For a root application this returns the empty string.

Parameters:
req -
Returns:

appendRootRelativeURL

public static void appendRootRelativeURL(java.lang.Appendable a,
                                         javax.servlet.http.HttpServletRequest req,
                                         java.lang.String rurl)
                                  throws java.io.IOException
Constructs an URL that is relative to the root of the server from an application-root based URL. So for a webapp deployed to "http://www.test.nl:8080/demoapp/" and a relative URL "general/images/button.png" this will append the string "/demoapp/general/images/button.png" to the appendable passed.

Parameters:
a -
Throws:
java.io.IOException - Nonsense exception needed by stupid Java checked exception crap

getRootRelativeURL

public static java.lang.String getRootRelativeURL(javax.servlet.http.HttpServletRequest req,
                                                  java.lang.String rurl)

httpGetXMLDocument

public static org.w3c.dom.Document httpGetXMLDocument(java.lang.String url,
                                                      int timeout,
                                                      boolean namespaceaware)
                                               throws java.lang.Exception
Calls an external server and tries to retrieve an XML formatted document from it. The document is then returned.

Throws:
java.lang.Exception

httpGetStream

public static java.io.InputStream httpGetStream(java.lang.String url,
                                                int timeout)
                                         throws java.lang.Exception
Calls an external server and returns the response as an inputstream.

Parameters:
url -
Returns:
Throws:
java.lang.Exception

httpGetString

public static java.lang.String httpGetString(java.lang.String url,
                                             int timeout)
                                      throws java.lang.Exception
Calls an external server and returns the response as a string.

Parameters:
url -
Returns:
Throws:
java.lang.Exception