|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.isomorphic.rpc.RPCManager
Provides the ability to decode RPCRequests
and
DSRequests
sent by the browser into Java
Objects, and send back Java Object as responses.
This class has a client-side counterpart that is also called RPCManager. The client-side RPCManager enables you to send one or more RPCRequests to an arbitrary URL. In the Java logic at those URLs, you'll need to instantiate this RPCManager to process and respond to the requests.
Note that a single RPC transaction can contain more than one RPC request. See the discussion on queueing in the documentation for the client-side RPCManager on why this is useful.
All RPC requests require a response. If your application needs nothing more than an ack of the successful completion of a given request, use the sendSuccess()/sendFailure() convenience methods on this class to ack the request. The RPCManager keeps track of request/response pairs and automatically streams all responses to the client as a batch once you've provided a response for each request.
Note that when you call any of the send() methods on this class, no data is actually sent back over the wire until you have responded to all requests.
RPCRequest
,
RPCResponse
,
Init
Constructor Summary | |
RPCManager(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
RPCManager constructor for use in Servlets or Filters. |
|
RPCManager(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.io.Writer out)
RPCManager constructor for use in JSPs. |
Method Summary | |
void |
doCustomResponse()
If you're using Direct Method Invocation, you can call doCustomResponse() to suppress the normal RPCManager response so that you can send your own custom response via the servletResponse output stream. |
java.lang.Object |
getData()
Convenience method for getting the data of a single RPCRequest. |
RPCRequest |
getRequest()
Convenience method for getting a single RPCRequest when you know this HTTP request only contains one RPCRequest. |
java.util.List |
getRequests()
Returns a list of RPC requests sent in this HTTP transaction. |
static boolean |
isRPC(javax.servlet.http.HttpServletRequest request)
|
static boolean |
isXmlHttp(javax.servlet.http.HttpServletRequest request)
|
static void |
processRequest(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Instantiates an RPCManager and invokes execute() on each RPCRequest or DSRequest in this HTTP request. |
int |
requestCount()
Returns the number of RPC requests contained in the current HTTP request. |
void |
send(DSRequest dsRequest,
DSResponse dsResponse)
When responding to DataSource requests sent by the client, use this method. |
void |
send(DSRequest dsRequest,
java.lang.Object data)
Convenience method. |
void |
send(java.lang.Object data)
Convenience method for sending some data back in response to a single RPCRequest. |
void |
send(RPCRequest rpcRequest,
java.lang.Object data)
Convenience method. |
void |
send(RPCRequest rpcRequest,
RPCResponse rpcResponse)
When responding to a set of RPC requests sent as part of one HTTP request (if you used startQueue() sendQueue() on the client) you need to pair the responses to the requests. |
void |
send(RPCResponse rpcResponse)
Convenience method for sending some data back in response to a single RPCRequest. |
void |
sendFailure(java.lang.Object request,
java.lang.String error)
If the request processing failed for some reason, you can encode your own failure response in a standard response, or use this convenience method to send a failure notification on the client. Unless your client-side request specified the willHandleError flag, whatever message you send back here will be alert()ed on the client. |
void |
sendFailure(java.lang.Object request,
java.lang.Throwable t)
Takes a Throwable , formats the stack trace and calls sendFailure(rpcRequst, error). |
void |
sendSuccess(RPCRequest rpcRequest)
Every RPC request requires a response. |
void |
sendXMLString(DSRequest dsRequest,
java.lang.String xml)
Convenience method. |
void |
sendXMLString(RPCRequest rpcRequest,
java.lang.String xml)
Convenience method. |
void |
setResponseCharset(java.lang.String charset)
Sets the charset of the response. |
Constructor Detail |
public RPCManager(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.lang.Exception
request
- The 'request' variable provided in the context of the JSPresponse
- The 'response' variable provided in the context of the JSPClientMustResubmitException
- if the client must resubmit the request.java.lang.Exception
- if the request is malformed.public RPCManager(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.io.Writer out) throws java.lang.Exception
request
- The 'request' variable provided in the context of the JSPresponse
- The 'response' variable provided in the context of the JSPout
- The 'out' variable provided in the context of the JSPClientMustResubmitException
- if the client must resubmit the request.java.lang.Exception
- if the request is malformed.Method Detail |
public static boolean isRPC(javax.servlet.http.HttpServletRequest request)
public static boolean isXmlHttp(javax.servlet.http.HttpServletRequest request)
public void doCustomResponse()
This is useful for implementing file download functionality in response to an RPC request.
Note if you are not using DMI, but simply using the RPCManager, you can avoid the RPCManager response by simply not calling RPCManager.send().
public void setResponseCharset(java.lang.String charset)
public java.lang.Object getData()
public RPCRequest getRequest()
public java.util.List getRequests()
public int requestCount()
public void send(java.lang.Object data) throws java.lang.Exception
data
- to send backjava.lang.Exception
- if there is an error sending the responsepublic void send(RPCResponse rpcResponse) throws java.lang.Exception
rpcResponse
- containing the data to send backjava.lang.Exception
- if there is an error sending the responsepublic void send(RPCRequest rpcRequest, RPCResponse rpcResponse) throws java.lang.Exception
rpcRequest
- the request you're responding torpcResponse
- your responsejava.lang.Exception
- if there is an error sending the responsepublic void send(RPCRequest rpcRequest, java.lang.Object data) throws java.lang.Exception
RPCResponse rpcResponse = new RPCResponse(); rpcResponse.setData(data); rpcResponse.setStatus(RPCResponse.STATUS_SUCCESS); send(rpcRequest, rpcResponse);
rpcRequest
- the request you're responding todata
- to send as the payload of the responsejava.lang.Exception
- if there is an error sending the responsepublic void sendXMLString(RPCRequest rpcRequest, java.lang.String xml) throws java.lang.Exception
org.w3c.dom.Element
object to RPCResponse.setData().java.lang.Exception
- if there is an error sending the responsepublic void send(DSRequest dsRequest, DSResponse dsResponse) throws java.lang.Exception
dsRequest
- the request you're responding todsRequest
- your responsejava.lang.Exception
- if there is an error sending the responsepublic void send(DSRequest dsRequest, java.lang.Object data) throws java.lang.Exception
DSResponse dsResponse = new DSResponse(); dsResponse.setData(data); dsResponse.setStatus(DSResponse.STATUS_SUCCESS); send(dsRequest, dsResponse);
dsRequest
- the request you're responding todata
- to send as the payload of the responsejava.lang.Exception
- if there is an error sending the responsepublic void sendXMLString(DSRequest dsRequest, java.lang.String xml) throws java.lang.Exception
java.lang.Exception
- if there is an error sending the responsepublic void sendSuccess(RPCRequest rpcRequest) throws java.lang.Exception
rpcRequest
- the request that completed successfullyjava.lang.Exception
- if there is an error sending the responsepublic void sendFailure(java.lang.Object request, java.lang.String error) throws java.lang.Exception
request
- the request that failederror
- the error string to send to the clientjava.lang.Exception
- if there is an error sending the responsepublic void sendFailure(java.lang.Object request, java.lang.Throwable t) throws java.lang.Exception
Throwable
, formats the stack trace and calls sendFailure(rpcRequst, error).request
- the request that failedt
- the exception you wish to report to the clientjava.lang.Exception
- if there is an error sending the responsepublic static void processRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
request
- The HttpServletRequestresponse
- The HttpServletResponsejavax.servlet.ServletException
- As per HttpServlet.service()java.io.IOException
- As per HttpServlet.service()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |