com.zeus.ZXTMServlet
Interface ZXTMServletRequest

All Superinterfaces:
ServletRequest
All Known Subinterfaces:
ZXTMHttpServletRequest

public interface ZXTMServletRequest
extends ServletRequest

The ZXTMServletRequest interface is an extension to the standard ServletRequest class. In particular, it provides methods to allow the Servlet to alter the supplied request. The modified request can then be forwarded by ZXTM on to a backend node in order to generate a response. This means that Servlets in ZXTM do not have to be content generators, they can also modify the requests that other servers will use to generate a response. When ZXTM invokes a Servlet, the ServletRequest parameter can be safely cast into a ZXTMServletRequest. This will enable your Servlet to use the ZXTM extensions to the base Servlet API. For example, a typical Servlet can do the following:

 public void service( ServletRequest req, ServletResponse res )
 {
     ZXTMServletRequest zreq = (ZXTMServletRequest)req;
     ZXTMServletResponse zres = (ZXTMServletResponse)res;
     
     // zreq and zres can now be used to access the extended ZXTM
     // functionality
 }
 
As well as the new methods exposed via this class and ZXTMServletResponse, many of ZXTM's features are controllable via the Servlet attributes, which can be queried and set with ServletRequest.getAttribute() and ServletRequest.setAttribute(). These attributes provide similar functionality to common TrafficScript functions, as shown below:
Attribute nameDescription TrafficScript equivalent
argsAny arguments that were supplied to the Servlet with the TrafficScript java.run() function
avoidnodesA space-separated list of nodes that ZXTM should not use when choosing where to send this requestrequest.avoidNode()
bandwidthBandwidth class nameresponse.setBandwidthClass()
cache0 to disable caching, 1 to enable cachinghttp.cache.enable()
cachekeyCache index hinthttp.cache.setKey()
compress0 to disable compression, 1 to leave as default, 2 to force enable http.compress.enable()
dstipDestination IP address (IP that client connected to) request.getLocalIP()
dstportPort that the client connected torequest.getLocalPort()
idempotent0 to disable re-sending request, 1 to enable request.setIdempotent()
logenabled0 to disable logging, 1 to enable request.setLogEnabled()
nodeNode used for this connection (read-only)connection.getNode()
persistenceGet/set persistence classconnection.setPersistence()
persistencekeySet additional persistence data connection.setPersistenceKey()
persistencenodeGet/set node for NamedNode persistence connection.setPersistenceNode()
poolGet/set the pool to use for this requestpool.select()
proxyPick a specific host (name:port) to forward-proxy to pool.select()
resendable1 if this request is resendable by a response rule request.isResendable()
retriesNumber of retries that this request has had request.getRetries()
ruleName of the current TrafficScript rulerule.getName()
serverbandwidthServer bandwidth class namerequest.setBandwidthClass()
serverdstipIP address of the node used for this request response.getRemoteIP()
serverdstportPort of the node used for this request response.getRemotePort()
serversrcipLocal IP address used for connection to backend node response.getLocalIP()
serversrcportLocal port used for connection to backend node response.getLocalPort()
servertosType of Service flag for the server connection request.setToS()
servicelevelSLM class to useconnection.setServiceLevelClass()
srcipIP address of the clientrequest.getRemoteIP()
srcportPort of the clientrequest.getRemotePort()
ssl_sessionidSSL session IDssl.sslSessionID()
SSL_PROTOCOLSSL protocol
ssl_ciphersSSL cipher usedssl.clientCipher()
ssl_cipher_sizeSSL cipher size (bits)ssl.clientCipher()
SSL_VERSION_INTERFACESSL library version
tosType of Service flag for the client connectionresponse.setToS()
virtualserverName of the virtual serverconnection.getVirtualServer()


Nested Class Summary
static class ZXTMServletRequest.DataType
           
 
Method Summary
 void emitEvent(String event, String message)
          This creates a custom event which can cause the alerting system to run an action.
 String geoGetCity(InetAddress ip)
          Returns the city name of a given IPv4 address, or null if no information is available.
 String geoGetCity(String ip)
          Returns the city name of a given IPv4 address, or null if no information is available.
 String geoGetCountry(InetAddress ip)
          Returns the country name of a given IPv4 address, or null if no information is available.
 String geoGetCountry(String ip)
          Returns the country name of a given IPv4 address, or null if no information is available.
 String geoGetCountryCode(String ip)
          Returns the 2-character country code of a given IPv4 address, or null if no information is available.
 double geoGetDistanceKM(double[] coord1, double[] coord2)
          Returns the distance in kilometres between two points on the Earth's surface (given as lat-lon coordinate pairs).
 double geoGetDistanceKM(double lat1, double lon1, double lat2, double lon2)
          Returns the distance in kilometres between two points on the Earth's surface (given as lat-lon coordinates).
 double geoGetDistanceMiles(double[] coord1, double[] coord2)
          Returns the distance in miles between two points on the Earth's surface (given as lat-lon coordinate pairs).
 double geoGetDistanceMiles(double lat1, double lon1, double lat2, double lon2)
          Returns the distance in miles between two points on the Earth's surface (given as lat-lon coordinates).
 double geoGetIPDistanceKM(InetAddress ip1, InetAddress ip2)
          Returns the distance in kilometres between two IPv4 addresses, or -1 if either location can't be found.
 double geoGetIPDistanceKM(String ip1, String ip2)
          Returns the distance in kilometres between two IPv4 addresses, or -1 if either location can't be found.
 double geoGetIPDistanceMiles(InetAddress ip1, InetAddress ip2)
          Returns the distance in miles between two IPv4 addresses, or -1 if either location can't be found.
 double geoGetIPDistanceMiles(String ip1, String ip2)
          Returns the distance in miles between two IPv4 addresses, or -1 if either location can't be found.
 double[] geoGetLatLon(InetAddress ip)
          Returns the latitude and longitude of a given IPv4 address, or null if no information is available.
 double[] geoGetLatLon(String ip)
          Returns the latitude and longitude of a given IPv4 address, or null if no information is available.
 String geoGetRegion(InetAddress ip)
          Returns the region name of a given IPv4 address, or null if no information is available.
 String geoGetRegion(String ip)
          Returns the region name of a given IPv4 address, or null if no information is available.
 String geoGetRegionCode(InetAddress ip)
          Returns the 2-character region code (in the US this is a state code) of a given IPv4 address, or null if no information is available.
 String geoGetRegionCode(String ip)
          Returns the 2-character region code (in the US this is a state code) of a given IPv4 address, or null if no information is available.
 int getActiveNodes(String pool)
          Returns the number of nodes that are alive in the named pool.
 String getConnectionData(String key)
          Read connection-specific data that has been set by other servlets or TrafficScript rules.
 ZXTMServletRequest.DataType getConnectionDataType(String key)
          Get the type of the connection-specific data that has been set by other servlets or TrafficScript rules.
 String getData(String key)
          Read global data that has been set by other servlets or TrafficScript rules.
 ZXTMServletRequest.DataType getDataType(String key)
          Get the type of the global data that has been set by other servlets or TrafficScript rules.
 ServletOutputStream getOutputStream()
          Returns a ServletOutputStream suitable for writing binary data in the request.
 int getSLMConforming(String slm)
          Returns the current percentage of requests that are meeting the specified Service Level Monitoring class' objectives.
 int getSLMThreshold(String slm)
          Returns the percentage of requests that must meet the specified Service Level Monitoring class' objectives, for the class to be considered OK.
 PrintWriter getWriter()
          Returns a PrintWriter object that can send character text to the server.
 void incrementCounter(int counter)
          Increment a counter by 1, equivalent to TrafficScript's counter.increment()
 void incrementCounter(int counter, int inc)
          Increment a counter, equivalent to TrafficScript's counter.increment()
 boolean isSLMOK(String slm)
          Checks if the specified Service Level Monitoring class is meeting its objectives.
 void setConnectionData(String key, String value)
          Set connection-specific data.
 void setConnectionData(String key, String value, ZXTMServletRequest.DataType type)
          Set connection-specific data.
 void setData(String key, String value)
          Set global data.
 void setData(String key, String value, ZXTMServletRequest.DataType type)
          Set global data.
 
Methods inherited from interface javax.servlet.ServletRequest
getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getLocale, getLocales, getParameter, getParameterMap, getParameterNames, getParameterValues, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRequestDispatcher, getScheme, getServerName, getServerPort, isSecure, removeAttribute, setAttribute, setCharacterEncoding
 

Method Detail

emitEvent

void emitEvent(String event,
               String message)
               throws InvalidParameterException
This creates a custom event which can cause the alerting system to run an action. Actions can be configured from the System -> Alerting page in the UI.

Parameters:
event - The event id which the alerting system will match against in order to trigger an action.
message - Detailed text explaining the event.
Throws:
InvalidParameterException - The event id must contain only alphanumeric characters and underscore.

geoGetCity

String geoGetCity(InetAddress ip)
                  throws InvalidParameterException,
                         IOException
Returns the city name of a given IPv4 address, or null if no information is available.

Parameters:
ip - An IPv4 address.
Throws:
InvalidParameterException
IOException

geoGetCity

String geoGetCity(String ip)
                  throws InvalidParameterException,
                         IOException
Returns the city name of a given IPv4 address, or null if no information is available.

Parameters:
ip - An IPv4 address.
Throws:
InvalidParameterException
IOException

geoGetCountry

String geoGetCountry(InetAddress ip)
                     throws InvalidParameterException,
                            IOException
Returns the country name of a given IPv4 address, or null if no information is available.

Parameters:
ip - An IPv4 address.
Throws:
InvalidParameterException
IOException

geoGetCountry

String geoGetCountry(String ip)
                     throws InvalidParameterException,
                            IOException
Returns the country name of a given IPv4 address, or null if no information is available.

Parameters:
ip - An IPv4 address.
Throws:
InvalidParameterException
IOException

geoGetCountryCode

String geoGetCountryCode(String ip)
                         throws InvalidParameterException,
                                IOException
Returns the 2-character country code of a given IPv4 address, or null if no information is available.

Parameters:
ip - An IPv4 address.
Throws:
InvalidParameterException
IOException

geoGetDistanceKM

double geoGetDistanceKM(double[] coord1,
                        double[] coord2)
Returns the distance in kilometres between two points on the Earth's surface (given as lat-lon coordinate pairs).

Parameters:
coord1 - Latitude and longitude pair for first point, as returned by @ref geoGetLatLon.
coord2 - Latitude and longitude pair for second point, as returned by @ref geoGetLatLon.

geoGetDistanceKM

double geoGetDistanceKM(double lat1,
                        double lon1,
                        double lat2,
                        double lon2)
Returns the distance in kilometres between two points on the Earth's surface (given as lat-lon coordinates).

Parameters:
lat1 - Latitude of first point.
lon1 - Longitude of first point.
lat2 - Latitude of second point.
lon2 - Longitude of second point.

geoGetDistanceMiles

double geoGetDistanceMiles(double[] coord1,
                           double[] coord2)
Returns the distance in miles between two points on the Earth's surface (given as lat-lon coordinate pairs).

Parameters:
coord1 - Latitude and longitude pair for first point, as returned by @ref geoGetLatLon.
coord2 - Latitude and longitude pair for second point, as returned by @ref geoGetLatLon.

geoGetDistanceMiles

double geoGetDistanceMiles(double lat1,
                           double lon1,
                           double lat2,
                           double lon2)
Returns the distance in miles between two points on the Earth's surface (given as lat-lon coordinates).

Parameters:
lat1 - Latitude of first point.
lon1 - Longitude of first point.
lat2 - Latitude of second point.
lon2 - Longitude of second point.

geoGetIPDistanceKM

double geoGetIPDistanceKM(InetAddress ip1,
                          InetAddress ip2)
                          throws IOException,
                                 InvalidParameterException
Returns the distance in kilometres between two IPv4 addresses, or -1 if either location can't be found.

Parameters:
ip1 - An IPv4 address.
ip2 - An IPv4 address.
Throws:
IOException
InvalidParameterException

geoGetIPDistanceKM

double geoGetIPDistanceKM(String ip1,
                          String ip2)
                          throws IOException,
                                 InvalidParameterException
Returns the distance in kilometres between two IPv4 addresses, or -1 if either location can't be found.

Parameters:
ip1 - An IPv4 address.
ip2 - An IPv4 address.
Throws:
IOException
InvalidParameterException

geoGetIPDistanceMiles

double geoGetIPDistanceMiles(InetAddress ip1,
                             InetAddress ip2)
                             throws IOException,
                                    InvalidParameterException
Returns the distance in miles between two IPv4 addresses, or -1 if either location can't be found.

Parameters:
ip1 - An IPv4 address.
ip2 - An IPv4 address.
Throws:
IOException
InvalidParameterException

geoGetIPDistanceMiles

double geoGetIPDistanceMiles(String ip1,
                             String ip2)
                             throws IOException,
                                    InvalidParameterException
Returns the distance in miles between two IPv4 addresses, or -1 if either location can't be found.

Parameters:
ip1 - An IPv4 address.
ip2 - An IPv4 address.
Throws:
IOException
InvalidParameterException

geoGetLatLon

double[] geoGetLatLon(InetAddress ip)
                      throws IOException,
                             InvalidParameterException
Returns the latitude and longitude of a given IPv4 address, or null if no information is available.

Parameters:
ip - An IPv4 address.
Throws:
IOException
InvalidParameterException

geoGetLatLon

double[] geoGetLatLon(String ip)
                      throws IOException,
                             InvalidParameterException
Returns the latitude and longitude of a given IPv4 address, or null if no information is available.

Parameters:
ip - An IPv4 address.
Throws:
IOException
InvalidParameterException

geoGetRegion

String geoGetRegion(InetAddress ip)
                    throws InvalidParameterException,
                           IOException
Returns the region name of a given IPv4 address, or null if no information is available.

Parameters:
ip - An IPv4 address.
Throws:
InvalidParameterException
IOException

geoGetRegion

String geoGetRegion(String ip)
                    throws InvalidParameterException,
                           IOException
Returns the region name of a given IPv4 address, or null if no information is available.

Parameters:
ip - An IPv4 address.
Throws:
InvalidParameterException
IOException

geoGetRegionCode

String geoGetRegionCode(InetAddress ip)
                        throws InvalidParameterException,
                               IOException
Returns the 2-character region code (in the US this is a state code) of a given IPv4 address, or null if no information is available.

Parameters:
ip - An IPv4 address.
Throws:
InvalidParameterException
IOException

geoGetRegionCode

String geoGetRegionCode(String ip)
                        throws InvalidParameterException,
                               IOException
Returns the 2-character region code (in the US this is a state code) of a given IPv4 address, or null if no information is available.

Parameters:
ip - An IPv4 address.
Throws:
InvalidParameterException
IOException

getActiveNodes

int getActiveNodes(String pool)
                   throws IOException
Returns the number of nodes that are alive in the named pool. This will not include any nodes that have been marked as 'draining'.

Parameters:
pool - the name of the pool to check
Returns:
the number of alive nodes
Throws:
IOException - if an error occurs when communicating with ZXTM

getConnectionData

String getConnectionData(String key)
                         throws IOException
Read connection-specific data that has been set by other servlets or TrafficScript rules.

Parameters:
key - the key to look up
Returns:
the stored value for that key, or null if the key was not found.
Throws:
IOException - if an error occurs when communicating with ZXTM

getConnectionDataType

ZXTMServletRequest.DataType getConnectionDataType(String key)
                                                  throws IOException
Get the type of the connection-specific data that has been set by other servlets or TrafficScript rules. This information can be used to correctly interpret data obtained using getConnectionData().

Throws:
IOException - if an error occurs when communicating with ZXTM

getData

String getData(String key)
               throws IOException
Read global data that has been set by other servlets or TrafficScript rules.

Throws:
IOException - if an error occurs when communicating with ZXTM

getDataType

ZXTMServletRequest.DataType getDataType(String key)
                                        throws IOException
Get the type of the global data that has been set by other servlets or TrafficScript rules. This information can be used to correctly interpret data obtained using getData().

Throws:
IOException - if an error occurs when communicating with ZXTM

getOutputStream

ServletOutputStream getOutputStream()
                                    throws IOException
Returns a ServletOutputStream suitable for writing binary data in the request. Calling this method will replace all of the original data from the request. If you wish to modify the original data, you must read it using the getInputStream() method. Note that getInputStream() will always return the original data, even if it has been subsequently replaced by your Servlet.

Throws:
IOException - if an error occurs when communicating with ZXTM

getSLMConforming

int getSLMConforming(String slm)
                     throws IOException
Returns the current percentage of requests that are meeting the specified Service Level Monitoring class' objectives.

Returns:
the percentage of requests, as an integer value from 0-100
Throws:
IOException - if an error occurs when communicating with ZXTM

getSLMThreshold

int getSLMThreshold(String slm)
                    throws IOException
Returns the percentage of requests that must meet the specified Service Level Monitoring class' objectives, for the class to be considered OK.

Returns:
the percentage of requests, as an integer value from 0-100
Throws:
IOException - if an error occurs when communicating with ZXTM

getWriter

PrintWriter getWriter()
                      throws IOException
Returns a PrintWriter object that can send character text to the server. Calling this method will replace all of the original data from the request, just like getOutputStream(). If you wish to modify the original data, then you must read it using the getReader() method. Note that getReader() will always return the original data, even if it has been subsequently replaced by your Servlet.

Throws:
IOException - if an error occurs when communicating with ZXTM

incrementCounter

void incrementCounter(int counter)
Increment a counter by 1, equivalent to TrafficScript's counter.increment()

Parameters:
counter - the counter number to increment.
Throws:
IOException - if an error occurs when communicating with ZXTM

incrementCounter

void incrementCounter(int counter,
                      int inc)
Increment a counter, equivalent to TrafficScript's counter.increment()

Parameters:
counter - the counter number
inc - amount to increment the counter by.
Throws:
IOException - if an error occurs when communicating with ZXTM

isSLMOK

boolean isSLMOK(String slm)
                throws IOException
Checks if the specified Service Level Monitoring class is meeting its objectives.

Returns:
true if the SLM class is meeting its objectives.
Throws:
IOException - if an error occurs when communicating with ZXTM

setConnectionData

void setConnectionData(String key,
                       String value)
                       throws IOException
Set connection-specific data. This data can be read by other servlets or TrafficScript rules (via connection.data.get()) for this connection. If the supplied key already exists, then the supplied data will overwrite the original value.

Parameters:
key - the key to index the data with
value - the value to associate with the key
Throws:
IOException - if an error occurs when communicating with ZXTM

setConnectionData

void setConnectionData(String key,
                       String value,
                       ZXTMServletRequest.DataType type)
                       throws IOException
Set connection-specific data. This data can be read by other servlets or TrafficScript rules (via connection.data.get()) for this connection. If the supplied key already exists, then the supplied data will overwrite the original value.

Parameters:
key - the key to index the data with
value - the value to associate with the key
type - the type of the data being stored
Throws:
IOException - if an error occurs when communicating with ZXTM

setData

void setData(String key,
             String value)
             throws IOException
Set global data. This can be read by other servlets or TrafficScript rules (via data.get()). If the supplied key already exists, then the supplied data will overwrite the original value.

Parameters:
key - the key to index the data with
value - the value to associate with the key
Throws:
IOException - if an error occurs when communicating with ZXTM

setData

void setData(String key,
             String value,
             ZXTMServletRequest.DataType type)
             throws IOException
Set global data. This can be read by other servlets or TrafficScript rules (via data.get()). If the supplied key already exists, then the supplied data will overwrite the original value. Warning: This data is currently store per-ZXTM process. A key that is stored in one invocation of ZXTM will not be shared with the other ZXTM processes. This means that if the same servlet requests this key in a future connection, it may not be found.

Parameters:
key - the key to index the data with
value - the value to associate with the key
type - the type of the data being stored
Throws:
IOException - if an error occurs when communicating with ZXTM