public class RemoteApplicationRequest extends Object implements Serializable
Asside from standard request artifacts (like cookies and headers and whatnot), this Object supports "tasks". Tasks are units of work which can be added to the request on an as-needed basis, and allow information be be exchanged between consumer and producer as well as custom code to be executed. The RegionComponent provides the ability for different pieces of ADF to add tasks to each request by creating these task invocations. The system typically works as follows:
String responseId = remoteApplicationRequest.addTask(MyRemoteTaskHandler.class, param1, param2, param3); RemoteApplicationResponse remoteApplicationResponse = RemoteApplicationUtils.run(remoteApplicationRequest); Object fromHandler = remoteApplicationResponse.getTaskResponse(responseId);
Obviously this is a simplistic usecase, but essentially what happens is the task is added to the remote request. That executes a TaskHandler called MyRemoteTaskHandler
on the producer which could do setup with the specified params before the faces lifecycle is run. It can then return a result after the faces lifecycle is run which is then retrieved from the response. It is in this way that the RemoteApplication system can be extended in functionality while allowing the base protocol and framework to remain relatively lean. Note: by default the RemoteApplicationRequest does not serialize the headers as part of its serialization stream. That is because, typically, these headers will be transmitted as part of the HTTP request. It is expected that frameworks which need to serialize this object will exchange the headers themselves. If this is not done, the header methods are expected to return an IllegalStateException. RemoteApplicationUtils
and its subsequent filter should ensure the header map is restored.
Modifier and Type | Class and Description |
---|---|
static class |
RemoteApplicationRequest.Operation
An enumeration of request types.
|
Constructor and Description |
---|
RemoteApplicationRequest(RemoteApplication app)
Constructs a new "INVOKE" RemoteApplicationRequest that will be used to run invoke type tasks on a producer.
|
RemoteApplicationRequest(RemoteApplication app, RemoteApplicationRequest.Operation operation, String resource)
Constructs a new RemoteApplicationRequest for a given Operation that will be used to make a connection to the producer.
|
RemoteApplicationRequest(RemoteApplication app, RemoteApplicationRequest.Operation operation, String resource, Iterator<Locale> locales)
Constructs a new RemoteApplicationRequest for a given Operation that will be used to make a connection to the producer.
|
RemoteApplicationRequest(RemoteApplicationRequest req, Map<String,List<String>> headers)
This is a copy constructor that can re-unite a RemoteApplicationRequest with its headers.
|
RemoteApplicationRequest(RemoteApplication app, String resource)
Constructs a new "EXECUTE" RemoteApplicationRequest that will be used to run a resource on the producer.
|
Modifier and Type | Method and Description |
---|---|
void |
addCookie(javax.servlet.http.Cookie cookie)
Adds a cookie to this request
|
void |
addCookies(List<? extends javax.servlet.http.Cookie> cookies)
Adds a list of cookies to this request
|
void |
addHeader(String name, String value)
Add's a header to the header map.
|
void |
addHeaders(String name, String[] values)
This add's multiple headers with the same name to this request.
|
String |
addOptionalTask(Class<? extends TaskHandler> taskHandler, Serializable defaultValue, Serializable... parameters)
Adds a task to this request.
|
String |
addOptionalTask(String taskHandler, Serializable defaultValue, Serializable... parameters)
Adds a task to this request.
|
String |
addTask(Class<? extends TaskHandler> taskHandler, Serializable... parameters)
Adds a task to this request.
|
String |
addTask(String taskHandler, Serializable... parameters)
Adds a task to this request.
|
void |
clearCookies()
Clears all the stored cookies on this request
|
List<? extends javax.servlet.http.Cookie> |
getCookies()
Returns an unmodifiable list of cookies which need to be sent back to to the remote application during this request.
|
String |
getHeader(String header)
Returns a single header value.
|
Map<String,List<String>> |
getHeaderMap()
Returns a map of headers.
|
List<String> |
getHeaderValues(String header)
Returns all of the values of a header.
|
List<Locale> |
getLocales()
Returns an unmodifiable list of locales that passed into its constructor This list is generally assumed to be listed according to importance with the default encoding being the first element.
|
String |
getMethod()
Returns the 'simulated' method of this remote request.
|
RemoteApplicationRequest.Operation |
getOperation()
Returns the operation which is to be performed by this request.
|
Map<String,String[]> |
getParameterMap()
Returns the parameter map used for this request.
|
String |
getQueryString()
Returns the current query string of this instance.
|
RemoteApplication |
getRemoteApplication()
Returns the RemoteApplication or the RemoteApplicationInstance used to create this class.
|
String |
getResource()
Returns the resource that should be retrieved by this RemoteApplicationRequest
|
List<TaskInvocation> |
getTaskInvocations()
Returns an unmodifiable list of TaskInvocation objects.
|
Map<String,List<org.apache.myfaces.trinidad.model.UploadedFile>> |
getUploadedFileMap()
Returns a list of UploadedFiles which should be sent as part of this request.
|
protected void |
initHeaderMap(Map<String,List<String>> m)
This protected method can be used to construct a case insensitive header map after serialization so that the header functions will not throw an
IllegalArgumentException . |
void |
setMethod(String method)
Sets the 'simulated' request method for this request.
|
protected void |
setParameterMap(Map<String,String[]> m)
This is used internally for the copy constructor and any other implementation which may need to directly set the parameterMap.
|
void |
setQueryString(String queryString)
Sets the query string of this request.
|
protected void |
setTaskInvocations(List<TaskInvocation> invocations) |
public RemoteApplicationRequest(RemoteApplication app)
app
- the RemoteApplication object representing the producerNullPointerException
- if the app property is null
public RemoteApplicationRequest(RemoteApplication app, String resource)
app
- the RemoteApplication object representing the producerresource
- the Resource to execute on the remote producer. This resource will be added to the url that is already present on the app representing the filter mapping.NullPointerException
- if either the app or the Resource is null
public RemoteApplicationRequest(RemoteApplication app, RemoteApplicationRequest.Operation operation, String resource)
app
- the RemoteApplication object representing the produceroperation
- the Operation to perform in the remote applicationresource
- the Resource to execute on the remote producer. This resource will be added to the url that is already present on the app representing the filter mapping. If this is an "invoke" type request, this property is ignored.NullPointerException
- if the app or the operation is null
IllegalArgumentException
- is resource is null
and operation is NOT "INVOKE".public RemoteApplicationRequest(RemoteApplicationRequest req, Map<String,List<String>> headers)
req
- The request Objectheaders
- Map of headers.public RemoteApplicationRequest(RemoteApplication app, RemoteApplicationRequest.Operation operation, String resource, Iterator<Locale> locales)
app
- the RemoteApplication object representing the produceroperation
- the Operation to perform in the remote applicationresource
- the Resource to execute on the remote producer. This resource will be added to the url that is already present on the app representing the filter mapping. If this is an "invoke" type request, this property is ignored.locales
- an iterator containing a list of locales.NullPointerException
- if the app or the operation is null
IllegalArgumentException
- is resource is null
and operation is NOT "INVOKE".public RemoteApplication getRemoteApplication()
public RemoteApplicationRequest.Operation getOperation()
RemoteApplicationRequest.Operation
.public String getResource()
public void setMethod(String method)
HttpServletRequest.getMetho()
on the producer. Valid methods are: GET, POST, HEAD, OPTIONS, PUT, DELETE, or TRACE. The default is GET.method
- the 'simulated' method of the remote request.public String getMethod()
public List<Locale> getLocales()
public List<? extends javax.servlet.http.Cookie> getCookies()
It is important to note that these cookies will be transmitted as real cookies across the HttpRequest, so setting cookies here should be sufficient for interacting with any 'front-end' servers or proxies which may get the request before it is sent to the final endpoint.
public void clearCookies()
public void addCookie(javax.servlet.http.Cookie cookie)
cookie
- the cookiepublic void addCookies(List<? extends javax.servlet.http.Cookie> cookies)
cookies
- The list of cookies.public void setQueryString(String queryString)
queryString
- a valid queryString without the leading "?".public String getQueryString()
public Map<String,String[]> getParameterMap()
HttpServletRequest
as such.protected void setParameterMap(Map<String,String[]> m)
m
- The paramater map.public Map<String,List<String>> getHeaderMap()
IllegalStateException
- if this object was serialized and the header map was not manually restored.public void addHeader(String name, String value)
name
- the name of the headervalue
- the value of the headerIllegalStateException
- if this object was serialized and the header map was not manually restored.public void addHeaders(String name, String[] values)
name
- The header name.values
- Array of headers to be associated with the name.IllegalStateException
- if this object was serialized and the header map was not manually restored.public String getHeader(String header)
null
. If the headers are present then the value of the first occurance of this header is returned. The name of the header will be converted to lower case when saved, and access to the header elements will be case insensitive.header
- The header name.null
.IllegalStateException
- if this object was serialized and the header map was not manually restored.public List<String> getHeaderValues(String header)
header
- The header name.IllegalStateException
- if this object was serialized and the header map was not manually restored.public String addTask(String taskHandler, Serializable... parameters)
taskHandler
- a string representing the classname of the handler being invokedparameters
- a list of parametersUnsupportedOperationException
- id this method is not supported for the type of request. Currently "fetch" type requests do not support task execution.public String addTask(Class<? extends TaskHandler> taskHandler, Serializable... parameters)
taskHandler
- a Class representing the classname of the handler being invokedparameters
- a list of parametersUnsupportedOperationException
- id this method is not supported for the type of request. Currently "fetch" type requests do not support task execution.public String addOptionalTask(String taskHandler, Serializable defaultValue, Serializable... parameters)
addTask(java.lang.Class, java.io.Serializable...)
method, this task handler will only be executed IF it exists on the producer. If the task handler does not exist on the producer, execution continues but the default value is returned to the consumer instead. Note: There are a couple of caviats to this API. First off, if the supplied task handler is not an instance of a TaskHandler OR if there was something wrong with instantiation, a TaskError response will be returned.taskHandler
- The task handlerdefaultValue
- If no paramter is available this default is usedparameters
- The parameters for the task.public String addOptionalTask(Class<? extends TaskHandler> taskHandler, Serializable defaultValue, Serializable... parameters)
addTask(String,Serializable...)
method, this task handler will only be executed IF it exists on the producer. If the task handler does not exist on the producer, execution continues but the default value is returned to the consumer instead. Note: There are a couple of caviats to this API. First off, if the supplied task handler is not an instance of a TaskHandler OR if there was something wrong with instantiation, a TaskError response will be returned.taskHandler
- The task handlerdefaultValue
- The default value if no paramters are sent in.parameters
- The parameters for the task.public List<TaskInvocation> getTaskInvocations()
protected void setTaskInvocations(List<TaskInvocation> invocations)
public Map<String,List<org.apache.myfaces.trinidad.model.UploadedFile>> getUploadedFileMap()
Map
where all of the UploadedFile instances should be stored.protected void initHeaderMap(Map<String,List<String>> m)
IllegalArgumentException
. Executing this method will always construct a new map which will replace the old one. If the parameter provided is null or an empty list then an empty set of headers will be provided.m
- Case insesitive header map.