oss.net.pstream
Class PortletStreamParameters

java.lang.Object
  |
  +--oss.net.pstream.PortletStreamParameters

public class PortletStreamParameters
extends java.lang.Object

Author:
Matt "skyleach" Gregory In the early versions of the streamer, the Parameters was a helper class to contain all the parameters loaded from the pstream.properties file. That file has gone the way of the dodo and the dinosoar and this class has evolved. In it's current form, it is used as a state machine for the proxy from the beginning of a proxy job to the end, preserving a large and growing array of parameters and objects specific to both a single iteration of the proxy and to all of them. For this reason, there is both preserved state objects in this class (used by many connections without changing) and a temporary state used by only one thread at a time and nullified after each execution. This class has mostly grown out of necessety as the modular nature of the streamer requires unified access to a very large number of parameters through a one-stop interface. This class is most definitely NOT threadsafe.

Constructor Summary
PortletStreamParameters(PortletStreamParameters Params, java.lang.String Name)
          Constructs a new list of parmeters using another parameters object as a template.
PortletStreamParameters(java.lang.String Name)
          Constructor which builds an empty parameters object with the exception of it's unique name.
 
Method Summary
 void addResponseHeader(java.lang.String key, java.lang.String value)
          Method addResponseHeader appends a new header with the given value, even should that header already exist in the response.
 void addRewriter(Rewriter rw)
          Method addRewriter adds a new rewriter to the stack.
 boolean debug()
          Method debug tells you if debug is turned on.
 void debug(boolean On)
          Method debug.
 void endSession()
          Resets this object and prepares it for the next proxy request.
 java.lang.String getContentBuffer()
          Method getContentBuffer returns the ResponseBody as a string, and if it has not yet been fetched it is fetched when this method is called.
 java.lang.String getContext()
          Method getContext returns the context path, or the buffer if the context path has been rewritten.
 java.lang.String getEscapedTargetURI()
          Method getEscapedTargetURI returns the target uri escaped to UTF8 with the exception of the URI-specific characters.
 java.lang.String getFullRequestHeaderValue(java.lang.String Name)
          Method getFullRequestHeaderValue returns the full (unaltered) value from the request header.
 java.lang.String getFullResponseHeaderValue(java.lang.String Name)
          Method getFullResponseHeaderValue returns the full value of the response header with the given Name, null if that header does not exist.
 java.lang.String getHost()
          Returns the host name passed in the request header or, if that header has not been set, returns the hostname from the request (and sets the Host header equal to this).
 org.apache.commons.httpclient.HttpMethodBase getMethod()
           
 java.lang.String getName()
          Returns the unique name of this configuration set.
 java.lang.String getPath()
          Method getPath wraps the HttpServletRequest.getPathInfo() method.
 int getPort()
          Method getPort.
 java.lang.String getProtocol()
          Method getProtocol.
 java.lang.String getRequestHeaderValue(java.lang.String Name)
          Method getRequestHeaderValue gets the value of a request header, or gets the first value if there are more than one.
 java.io.InputStream getResponseBodyInputStream()
          Method getResponseBodyInputStream returns the response body as an input stream.
 java.lang.String getResponseHeaderValue(java.lang.String Name)
          Method getResponseHeaderValue returns the response header value associated with the given name, the first part only if there are multiple values, null if it doesn't exist.
 RewriterVector getRewiters()
          Method getRewiters.
 java.lang.String getTargetHost()
          returns the Hostname of the host this proxy is proxying for.
 java.lang.String getTargetPath()
          Method getTargetPath returns the path from the target URI object.
 int getTargetPort()
          Method getTargetPort.
 java.lang.String getTargetProtocol()
          Method getTargetProtocol.
 java.lang.String getTargetQuery()
          Method getTargetQuery.
 java.lang.String getTargetURI()
          Method getTargetURI.
 java.lang.String getTargetURLAsString()
          Method getTargetURLAsString.
 java.util.HashMap getUserRequestHeaders()
          Method getUserRequestHeaders.
 java.util.HashMap getUserResponseHeaders()
          Method getUserResponseHeaders.
 java.lang.String getUservar(java.lang.String name)
          Method getUservar looks up the value of the given user variable.
 java.util.HashMap getUservars()
          Method getUservars returns the uservar hashmap.
 void presetResponseHeaders()
          Method presetResponseHeaders will attempt to set all the response headers from the target host to the client but will simply return if the HttpServletResponse object is null.
 void setContentBuffer(java.lang.String ContentBuffer)
          Method setContentBuffer sets the buffer for the content.
 void setContext(java.lang.String Context)
          Method setContext sets the context path buffer.
 void setHost(java.lang.String Host)
          Sets the host header in the HttpMethodBase
 void setResponseHeader(java.lang.String key, java.lang.String value)
          Method setResponseHeader sets the value of a response header with the given name (key).
 void setTargetPath(java.lang.String TargetPath)
          Method setTargetPath sets the path of the method.
 void setTargetQuery(org.apache.commons.httpclient.NameValuePair[] Params)
          Method setTargetQuery.
 void setTargetQuery(java.lang.String Query)
          Method setTargetQuery.
 void setTargetURI(java.lang.String TargetURI)
          Method setTargetURI sets the target URI in a single go.
 void setUserRequestHeader(java.lang.String Name, java.lang.String Value)
          Method setUserRequestHeader sets a new header to be proxied to the target host.
 void setUserResponseHeader(java.lang.String Name, java.lang.String Value)
          Method setUserResponseHeader sets a new header to be proxied back to the client.
 void setUservar(java.lang.String name, java.lang.String value)
          Method setUservar sets the value of a user variable.
 void setUservars(java.util.HashMap UV)
          Method setUservars sets the hashmap in this object to point to the hashmap UV.
 void startSession(org.apache.commons.httpclient.HttpClient client, org.apache.commons.httpclient.HttpMethodBase method, javax.servlet.http.HttpServletRequest Request, javax.servlet.http.HttpServletResponse Response, java.util.HashSet BlockHeaders)
          Sets the state of this parameters object to active (and makes it immediately unsafe for threading).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PortletStreamParameters

public PortletStreamParameters(java.lang.String Name)
Constructor which builds an empty parameters object with the exception of it's unique name.

Parameters:
Name - The unique name (per config file) of this configuration.

PortletStreamParameters

public PortletStreamParameters(PortletStreamParameters Params,
                               java.lang.String Name)
Constructs a new list of parmeters using another parameters object as a template.

Parameters:
Params - - The parameters to use as a template.
Name - - The unique name for this parameters object to assume.
Method Detail

startSession

public void startSession(org.apache.commons.httpclient.HttpClient client,
                         org.apache.commons.httpclient.HttpMethodBase method,
                         javax.servlet.http.HttpServletRequest Request,
                         javax.servlet.http.HttpServletResponse Response,
                         java.util.HashSet BlockHeaders)
Sets the state of this parameters object to active (and makes it immediately unsafe for threading). After this point, all methods of this object are active, before this point, most methods in this object will return invalid data, null, or throw exceptions.

Parameters:
client - The HttpClient which will be used to execute the methods used in this proxy request. This client is consulted for Host, Protocol and Port rewrite variables.
method - The HttpMethodBase used in this proxy request. The method is consulted for the majority of rewrite variables. This method also sets all the headers which will be passed to the proxy host, pulling them from the request object.
Request - The HttpServletRequest object which is consulted for all the request headers which are proxied.
Response - The HttpServletResponse object, which can be null. The response is only passively used by this object to get and set response headers when asked to do so by other classes. Each of these methods returns safely if the response is null.
BlockHeaders - A HashSet of headers which will be blocked from the proxy host (not proxied).

endSession

public void endSession()
Resets this object and prepares it for the next proxy request. This method resets the following things to null: HttpClient _client, HttpMethod _method, HttpServletRequest _request, HttpServletResponse _response, String _content_buffer, String _context_path_buffer. Note: at some point I want _content_buffer and _context_path_buffer to go away. The method by which this will be accomplished isn't really fully formed yet, but I should think that it will be something like using uservars to store them.


getName

public java.lang.String getName()
Returns the unique name of this configuration set.

Returns:
String the name.

getMethod

public org.apache.commons.httpclient.HttpMethodBase getMethod()
Returns:
HttpMethod the method associated with this proxy request.

getHost

public java.lang.String getHost()
Returns the host name passed in the request header or, if that header has not been set, returns the hostname from the request (and sets the Host header equal to this).

Returns:
String - the Host name, stripped of the port, if there is one, from the HttpServletRequest Host header or, failing that, from the HttpServletRequest.getServerName() method.

setHost

public void setHost(java.lang.String Host)
Sets the host header in the HttpMethodBase

Parameters:
Host - The value to be set.

getTargetHost

public java.lang.String getTargetHost()
returns the Hostname of the host this proxy is proxying for.

Returns:
String the hostname.

getPort

public int getPort()
Method getPort.

Returns:
int The port from the host header, or failing that from the servlet container. If the host header exists but has no port 80 is returned.

getTargetPort

public int getTargetPort()
Method getTargetPort.

Returns:
int HttpClient.getPort()

getTargetProtocol

public java.lang.String getTargetProtocol()
Method getTargetProtocol.

Returns:
String HttpClient.getHostConfiguration().getProtocol().toString()

getProtocol

public java.lang.String getProtocol()
Method getProtocol.

Returns:
String HttpServletRequest.getScheme()

getPath

public java.lang.String getPath()
Method getPath wraps the HttpServletRequest.getPathInfo() method.

Returns:
String HttpServletRequest.getPathInfo().

getTargetPath

public java.lang.String getTargetPath()
Method getTargetPath returns the path from the target URI object.

Returns:
String HttpMethodBase.getURI.getPath()

setTargetPath

public void setTargetPath(java.lang.String TargetPath)
Method setTargetPath sets the path of the method.

Parameters:
TargetPath - HttpMethodBase.setPath(String TargetPath)

getTargetQuery

public java.lang.String getTargetQuery()
Method getTargetQuery.

Returns:
String HttpMethodBase.getURI().getQuery();

setTargetQuery

public void setTargetQuery(java.lang.String Query)
Method setTargetQuery.

Parameters:
Query - HttpMethodBase.setQueryString(Query)

setTargetQuery

public void setTargetQuery(org.apache.commons.httpclient.NameValuePair[] Params)
Method setTargetQuery.

Parameters:
Params - an array of NameValuePair objects passed to HttpMethodBase.setQueryString(Params)

getTargetURI

public java.lang.String getTargetURI()
Method getTargetURI.

Returns:
String HttpMethodBase.getURI().getURI()

getEscapedTargetURI

public java.lang.String getEscapedTargetURI()
Method getEscapedTargetURI returns the target uri escaped to UTF8 with the exception of the URI-specific characters.

Returns:
String HttpMethodBase.getURI().toString()

getTargetURLAsString

public java.lang.String getTargetURLAsString()
Method getTargetURLAsString.

Returns:
String HttpMethodBase.getHostConfiguration().getHostURL() + @see getTargetURI

addRewriter

public void addRewriter(Rewriter rw)
Method addRewriter adds a new rewriter to the stack.

Parameters:
rw -

getRewiters

public RewriterVector getRewiters()
Method getRewiters.

Returns:
RewriterVector

debug

public void debug(boolean On)
Method debug.

Parameters:
On -

debug

public boolean debug()
Method debug tells you if debug is turned on.

Returns:
boolean

getUservar

public java.lang.String getUservar(java.lang.String name)
Method getUservar looks up the value of the given user variable.

Parameters:
name - The name of the variable.
Returns:
String The value.

getUservars

public java.util.HashMap getUservars()
Method getUservars returns the uservar hashmap.

Returns:
HashMap

setUservar

public void setUservar(java.lang.String name,
                       java.lang.String value)
Method setUservar sets the value of a user variable.

Parameters:
name - The name of the variable.
value - the value to set.

setUservars

public void setUservars(java.util.HashMap UV)
Method setUservars sets the hashmap in this object to point to the hashmap UV. This method does not copy.

Parameters:
UV - The new hashmap.

getUserRequestHeaders

public java.util.HashMap getUserRequestHeaders()
Method getUserRequestHeaders.

Returns:
HashMap of user_request_headers. Null if none have been set.

getUserResponseHeaders

public java.util.HashMap getUserResponseHeaders()
Method getUserResponseHeaders.

Returns:
HashMap of user_response_headers. Null if none have been set.

setUserRequestHeader

public void setUserRequestHeader(java.lang.String Name,
                                 java.lang.String Value)
Method setUserRequestHeader sets a new header to be proxied to the target host. The end result will be a header that looks like <Name>: <Value>

Parameters:
Name - the name to give the header.
Value - the value to set for the header.

setUserResponseHeader

public void setUserResponseHeader(java.lang.String Name,
                                  java.lang.String Value)
Method setUserResponseHeader sets a new header to be proxied back to the client. The end result will be a header that looks like <Name>: <Value>

Parameters:
Name -
Value -

setTargetURI

public void setTargetURI(java.lang.String TargetURI)
Method setTargetURI sets the target URI in a single go. This method checks to see if there is a query string in the URI and if so, it splits off the query from the rest of the URI. It then calls

Parameters:
TargetURI - the URI to set.
See Also:
and/or @see setTargetQuery

getRequestHeaderValue

public java.lang.String getRequestHeaderValue(java.lang.String Name)
Method getRequestHeaderValue gets the value of a request header, or gets the first value if there are more than one.

Parameters:
Name - the name of the header.
Returns:
String HttpMethodBase.getRequestHeader(Name).getValue() or null if the header does not exist.

getFullRequestHeaderValue

public java.lang.String getFullRequestHeaderValue(java.lang.String Name)
Method getFullRequestHeaderValue returns the full (unaltered) value from the request header.

Parameters:
Name - the name of the header.
Returns:
String the value part of the header minus any <cr><lf> characters that may be lurking at the end of that string (Jetty doesn't like them much).

getResponseHeaderValue

public java.lang.String getResponseHeaderValue(java.lang.String Name)
Method getResponseHeaderValue returns the response header value associated with the given name, the first part only if there are multiple values, null if it doesn't exist.

Parameters:
Name - the name of the header.
Returns:
String the value of the header.

getFullResponseHeaderValue

public java.lang.String getFullResponseHeaderValue(java.lang.String Name)
Method getFullResponseHeaderValue returns the full value of the response header with the given Name, null if that header does not exist. This method will strip off any <cr><lt;lf> characters at the end of the header (Jetty does not like them).

Parameters:
Name - the name of the header.
Returns:
String The full value part of the header

setResponseHeader

public void setResponseHeader(java.lang.String key,
                              java.lang.String value)
Method setResponseHeader sets the value of a response header with the given name (key). This method is defined to quietly log an error to stderr if you attempt to set a header when the response is null and return.

Parameters:
key - the name of the header to set
value - the value of the header to set.

addResponseHeader

public void addResponseHeader(java.lang.String key,
                              java.lang.String value)
Method addResponseHeader appends a new header with the given value, even should that header already exist in the response. This method is defined to quietly log an error to stderr if you attempt to set a header when the response is null and return.

Parameters:
key - the name of the header to append.
value - the value of the header to append.

getContentBuffer

public java.lang.String getContentBuffer()
                                  throws PortletStreamException
Method getContentBuffer returns the ResponseBody as a string, and if it has not yet been fetched it is fetched when this method is called.

Returns:
String the response body from the HttpMethodBase.
Throws:
PortletStreamException - when this method times out or any other connection error occurs. This most often happens when getResponseBodyAsString is called on the HttpMethodBase when there is no response body (such as when a HEAD method was passed or when the response code was 302 (moved) or 304 (unchanged)).

getResponseBodyInputStream

public java.io.InputStream getResponseBodyInputStream()
                                               throws PortletStreamException,
                                                      java.io.IOException
Method getResponseBodyInputStream returns the response body as an input stream. If postfetch has been called and the response body has been rewritten then the input stream will be a ByteArrayInputStream reading the content from a buffer, otherwise it is the raw input stream from the HttpMethodBase.

Returns:
InputStream
Throws:
PortletStreamException - if this method is called and the response code is 302 (moved) or 304 (unchaned) in which case this method should never have been called.
java.io.IOException - if the stream is unexpectedly closed.

setContentBuffer

public void setContentBuffer(java.lang.String ContentBuffer)
Method setContentBuffer sets the buffer for the content.

Parameters:
ContentBuffer -

presetResponseHeaders

public void presetResponseHeaders()
Method presetResponseHeaders will attempt to set all the response headers from the target host to the client but will simply return if the HttpServletResponse object is null.


getContext

public java.lang.String getContext()
Method getContext returns the context path, or the buffer if the context path has been rewritten. I kindof think this is a kludge and I need to think of a more elegant way to handle this.

Returns:
String the context path or the context_path_buffer if it has been set.

setContext

public void setContext(java.lang.String Context)
Method setContext sets the context path buffer.

Parameters:
Context - the value to set this buffer to.


Copyright © 2000 Dummy Corp. All Rights Reserved.