This section introduces the interaction between client and server.
Establish session:
The following flow diagram demonstrates how a session
is established:
The eRCP application invokes MobileAdapter.establishSession() to
create session with BTT server application.
MobileAdapter sets HTTP Request Property User-Agent as mobile,
and then sends HTTP request http://<server_address>:<port>/<url>?
createSession=true to Server side. The <url> is
defined in bttmobile.properties. The BTT server application knows that the
request is from mobile channel and its purpose is to create session.
MobileRequestServlet creates ChannelContext using ChannelDriver.createChannelContext().
ChannelContext is initialized with attributes of Request, Response, ChannelDriver, DeviceType and RequestData.
MobileRequestServlet invokes ChannelDriver.service() to process request.
ChannelDriver parses the request header and data, and then fills the created
http session to ChannelContext (in attribute ChannelSession).
Then it invokes MobileRequestHandler to process the request.
MobileRequestHandler determines that it is a session creation request.
It invokes the StartupOp Operation, which is defined in btt.xml.
You can write business logic in this operation, for example, creating Session
Context and then chaining it to root context; creating operation context and
then chaining it to Session Context.
MobileRequestHandler invokes MobileRepresentationHandler to commit SessionContext.
SessionContext and all its children are committed into DB. This recovers Session
data after the application restarted.
MobileRepresentationHandler returns after SessionContext is committed.
MobileRequestHandler returns.
ChannelDriver returns.
MobileRequestServlet returns http message 200 to client, which means the
request has been handled successfully.
MobileAdapter parses HTTP header, and gets session id from HTTP header
attribute Set-cookie, which is used in continuous request.
MobileAdapter returns true for method establishSession() if
all the requests are handled correctly. If not, it returns false.
Invoke server side operation:
The following flow diagram demonstrates
how server side operation is invoked:
The eRCP application invokes MobileAdapter.invoke () to
invoke operation in server side.
MobileAdapter sets HTTP Request Property User-Agent as mobile,
and cookie as sessionid, which is gotten
from establishing session, and then it sends HTTP request http://<server_address>:<port>/<url>?action=<Server
Operation ID>&responseDataId=<Response data ID> to server
side (<Server Operation ID> and <Response data
ID> are defined in server side XML files). With the request property cookie,
BTT server application knows where the request is from. MobileAdapter also
sends the serialized object, which is the input parameter for server operation
over HTTP.
MobileRequestServlet creates ChannelContext using ChannelDriver.createChannelContext().
ChannelContext is initialized with attributes of Request, Response, ChannelDriver, DeviceType and RequestData.
MobileRequestServlet invokes ChannelDriver.service() to
process request.
ChannelDriver parses the request header and data, and fills the existing
HTTP session to ChannelContext (in attribute ChannelSession).
Then it invokes MobileRequestHandler to process the request.
MobileRequestHandler determines that it is a service request. It parses
the request data into Operation context and chains the operation context to
session context, and then it invokes specified server operation.
MobileRequestHandler gets result from operation context after Server Operation
returns.
MobileRequestHandler invokes MobileRepresentationHandler to process reply.
MobileRepresentationHandler returns after the reply is processed.
MobileRequestHandler returns.
ChannelDriver returns.
MobileRequestServlet returns HTTP message 200 to client which
means the request has been handled successfully. And besides that, it returns
serialized output Javabean to client.
MobileAdapter parses HTTP data and gets the output Javabean.