com.netflix.zuul.context
Class RequestContext

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Object>
          extended by com.netflix.zuul.context.RequestContext
All Implemented Interfaces:
java.io.Serializable, java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object>, java.util.Map<java.lang.String,java.lang.Object>

public class RequestContext
extends java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Object>

The Request Context holds request, response, state information and data for ZuulFilters to access and share. The RequestContext lives for the duration of the request and is ThreadLocal. extensions of RequestContext can be substituted by setting the contextClass. Most methods here are convenience wrapper methods; the RequestContext is an extension of a ConcurrentHashMap

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
protected static java.lang.Class<? extends RequestContext> contextClass
           
protected static java.lang.ThreadLocal<? extends RequestContext> threadLocal
           
 
Constructor Summary
RequestContext()
           
 
Method Summary
 void addOriginResponseHeader(java.lang.String name, java.lang.String value)
          adds a header to the origin response headers
 void addZuulRequestHeader(java.lang.String name, java.lang.String value)
          add a header to be sent to the origin
 void addZuulResponseHeader(java.lang.String name, java.lang.String value)
          add a header to be sent to the response
 RequestContext copy()
          Mkaes a copy of the RequestContext.
 boolean debugRequest()
          gets debugRequest
 boolean debugRequestHeadersOnly()
           
 boolean debugRouting()
           
 boolean getBoolean(java.lang.String key)
          Convenience method to return a boolean value for a given key
 boolean getBoolean(java.lang.String key, boolean defaultResponse)
          Convenience method to return a boolean value for a given key
static RequestContext getCurrentContext()
          Get the current RequestContext
 java.lang.Integer getOriginContentLength()
          returns the content-length of the origin response
 java.util.List<com.netflix.util.Pair<java.lang.String,java.lang.String>> getOriginResponseHeaders()
          the Origin response headers
 javax.servlet.http.HttpServletRequest getRequest()
           
 java.util.Map<java.lang.String,java.util.List<java.lang.String>> getRequestQueryParams()
           
 javax.servlet.http.HttpServletResponse getResponse()
           
 java.lang.String getResponseBody()
           
 java.io.InputStream getResponseDataStream()
           
 boolean getResponseGZipped()
           
 int getResponseStatusCode()
          returns the response status code.
 java.net.URL getRouteHost()
           
 java.lang.Throwable getThrowable()
          returns a set throwable
 boolean getZuulEngineRan()
          true if zuulEngineRan
 java.util.Map<java.lang.String,java.lang.String> getZuulRequestHeaders()
          return the list of requestHeaders to be sent to the origin
 java.util.List<com.netflix.util.Pair<java.lang.String,java.lang.String>> getZuulResponseHeaders()
          returns the current response header list
 boolean isChunkedRequestBody()
           
 boolean isGzipRequested()
           
 void removeRouteHost()
          removes "routeHost" key
 boolean sendZuulResponse()
          If this value if true then the response should be sent to the client.
 void set(java.lang.String key)
          sets a key value to Boolen.TRUE
 void set(java.lang.String key, java.lang.Object value)
          puts the key, value into the map.
 void setChunkedRequestBody()
          sets chunkedRequestBody to true
static void setContextClass(java.lang.Class<? extends RequestContext> clazz)
          Override the default RequestContext
 void setDebugRequest(boolean bDebug)
          sets "debugRequest"
 void setDebugRequestHeadersOnly(boolean bHeadersOnly)
          sets "debugRequestHeadersOnly" to bHeadersOnly
 void setDebugRouting(boolean bDebug)
          sets debugRouting
 void setOriginContentLength(java.lang.Integer v)
          sets the content-length from the origin response
 void setOriginContentLength(java.lang.String v)
          sets the content-length from the origin response
 void setRequest(javax.servlet.http.HttpServletRequest request)
          sets the HttpServletRequest into the "request" key
 void setRequestQueryParams(java.util.Map<java.lang.String,java.util.List<java.lang.String>> qp)
          sets the request query params list
 void setResponse(javax.servlet.http.HttpServletResponse response)
          sets the "response" key to the HttpServletResponse passed in
 void setResponseBody(java.lang.String body)
          sets the "responseBody" value as a String.
 void setResponseDataStream(java.io.InputStream responseDataStream)
          sets the InputStream of the response into the responseDataStream
 void setResponseGZipped(boolean gzipped)
          sets the flag responseGZipped if the response is gzipped
 void setResponseStatusCode(int nStatusCode)
          Use this instead of response.setStatusCode()
 void setRouteHost(java.net.URL routeHost)
          sets routeHost
 void setSendZuulResponse(boolean bSend)
          sets the sendZuulResponse boolean
 void setThrowable(java.lang.Throwable th)
          sets a throwable
 void setZuulEngineRan()
          sets zuulEngineRan to true
static void testSetCurrentContext(RequestContext context)
          set an overriden "test" context
 void unset()
          unsets the threadLocal context.
 
Methods inherited from class java.util.concurrent.ConcurrentHashMap
clear, contains, containsKey, containsValue, elements, entrySet, get, isEmpty, keys, keySet, put, putAll, putIfAbsent, remove, remove, replace, replace, size, values
 
Methods inherited from class java.util.AbstractMap
clone, equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

contextClass

protected static java.lang.Class<? extends RequestContext> contextClass

threadLocal

protected static final java.lang.ThreadLocal<? extends RequestContext> threadLocal
Constructor Detail

RequestContext

public RequestContext()
Method Detail

setContextClass

public static void setContextClass(java.lang.Class<? extends RequestContext> clazz)
Override the default RequestContext

Parameters:
clazz -

testSetCurrentContext

public static void testSetCurrentContext(RequestContext context)
set an overriden "test" context

Parameters:
context -

getCurrentContext

public static RequestContext getCurrentContext()
Get the current RequestContext

Returns:
the current RequestContext

getBoolean

public boolean getBoolean(java.lang.String key)
Convenience method to return a boolean value for a given key

Parameters:
key -
Returns:
true or false depending what was set. default is false

getBoolean

public boolean getBoolean(java.lang.String key,
                          boolean defaultResponse)
Convenience method to return a boolean value for a given key

Parameters:
key -
defaultResponse -
Returns:
true or false depending what was set. default defaultResponse

set

public void set(java.lang.String key)
sets a key value to Boolen.TRUE

Parameters:
key -

set

public void set(java.lang.String key,
                java.lang.Object value)
puts the key, value into the map. a null value will remove the key from the map

Parameters:
key -
value -

getZuulEngineRan

public boolean getZuulEngineRan()
true if zuulEngineRan

Returns:

setZuulEngineRan

public void setZuulEngineRan()
sets zuulEngineRan to true


getRequest

public javax.servlet.http.HttpServletRequest getRequest()
Returns:
the HttpServletRequest from the "request" key

setRequest

public void setRequest(javax.servlet.http.HttpServletRequest request)
sets the HttpServletRequest into the "request" key

Parameters:
request -

getResponse

public javax.servlet.http.HttpServletResponse getResponse()
Returns:
the HttpServletResponse from the "response" key

setResponse

public void setResponse(javax.servlet.http.HttpServletResponse response)
sets the "response" key to the HttpServletResponse passed in

Parameters:
response -

getThrowable

public java.lang.Throwable getThrowable()
returns a set throwable

Returns:
a set throwable

setThrowable

public void setThrowable(java.lang.Throwable th)
sets a throwable

Parameters:
th -

setDebugRouting

public void setDebugRouting(boolean bDebug)
sets debugRouting

Parameters:
bDebug -

debugRouting

public boolean debugRouting()
Returns:
"debugRouting"

setDebugRequestHeadersOnly

public void setDebugRequestHeadersOnly(boolean bHeadersOnly)
sets "debugRequestHeadersOnly" to bHeadersOnly

Parameters:
bHeadersOnly -

debugRequestHeadersOnly

public boolean debugRequestHeadersOnly()
Returns:
"debugRequestHeadersOnly"

setDebugRequest

public void setDebugRequest(boolean bDebug)
sets "debugRequest"

Parameters:
bDebug -

debugRequest

public boolean debugRequest()
gets debugRequest

Returns:
debugRequest

removeRouteHost

public void removeRouteHost()
removes "routeHost" key


setRouteHost

public void setRouteHost(java.net.URL routeHost)
sets routeHost

Parameters:
routeHost - a URL

getRouteHost

public java.net.URL getRouteHost()
Returns:
"routeHost" URL

setResponseBody

public void setResponseBody(java.lang.String body)
sets the "responseBody" value as a String. This is the response sent back to the client.

Parameters:
body -

getResponseBody

public java.lang.String getResponseBody()
Returns:
the String response body to be snt back to the requesting client

setResponseDataStream

public void setResponseDataStream(java.io.InputStream responseDataStream)
sets the InputStream of the response into the responseDataStream

Parameters:
responseDataStream -

setResponseGZipped

public void setResponseGZipped(boolean gzipped)
sets the flag responseGZipped if the response is gzipped

Parameters:
gzipped -

getResponseGZipped

public boolean getResponseGZipped()
Returns:
true if responseGZipped is true (the response is gzipped)

getResponseDataStream

public java.io.InputStream getResponseDataStream()
Returns:
the InputStream Response

sendZuulResponse

public boolean sendZuulResponse()
If this value if true then the response should be sent to the client.

Returns:

setSendZuulResponse

public void setSendZuulResponse(boolean bSend)
sets the sendZuulResponse boolean

Parameters:
bSend -

getResponseStatusCode

public int getResponseStatusCode()
returns the response status code. Default is 200

Returns:

setResponseStatusCode

public void setResponseStatusCode(int nStatusCode)
Use this instead of response.setStatusCode()

Parameters:
nStatusCode -

addZuulRequestHeader

public void addZuulRequestHeader(java.lang.String name,
                                 java.lang.String value)
add a header to be sent to the origin

Parameters:
name -
value -

getZuulRequestHeaders

public java.util.Map<java.lang.String,java.lang.String> getZuulRequestHeaders()
return the list of requestHeaders to be sent to the origin

Returns:
the list of requestHeaders to be sent to the origin

addZuulResponseHeader

public void addZuulResponseHeader(java.lang.String name,
                                  java.lang.String value)
add a header to be sent to the response

Parameters:
name -
value -

getZuulResponseHeaders

public java.util.List<com.netflix.util.Pair<java.lang.String,java.lang.String>> getZuulResponseHeaders()
returns the current response header list

Returns:
a List> of response headers

getOriginResponseHeaders

public java.util.List<com.netflix.util.Pair<java.lang.String,java.lang.String>> getOriginResponseHeaders()
the Origin response headers

Returns:
the List> of headers sent back from the origin

addOriginResponseHeader

public void addOriginResponseHeader(java.lang.String name,
                                    java.lang.String value)
adds a header to the origin response headers

Parameters:
name -
value -

getOriginContentLength

public java.lang.Integer getOriginContentLength()
returns the content-length of the origin response

Returns:
the content-length of the origin response

setOriginContentLength

public void setOriginContentLength(java.lang.Integer v)
sets the content-length from the origin response

Parameters:
v -

setOriginContentLength

public void setOriginContentLength(java.lang.String v)
sets the content-length from the origin response

Parameters:
v - parses the string into an int

isChunkedRequestBody

public boolean isChunkedRequestBody()
Returns:
true if the request body is chunked

setChunkedRequestBody

public void setChunkedRequestBody()
sets chunkedRequestBody to true


isGzipRequested

public boolean isGzipRequested()
Returns:
true is the client request can accept gzip encoding. Checks the "accept-encoding" header

unset

public void unset()
unsets the threadLocal context. Done at the end of the request.


copy

public RequestContext copy()
Mkaes a copy of the RequestContext. This is used for debugging.

Returns:

getRequestQueryParams

public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getRequestQueryParams()
Returns:
Map> of the request Query Parameters

setRequestQueryParams

public void setRequestQueryParams(java.util.Map<java.lang.String,java.util.List<java.lang.String>> qp)
sets the request query params list

Parameters:
qp - Map> qp