use of org.apache.cayenne.remote.RemoteSession in project cayenne by apache.
the class ROPServlet method doPost.
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
String serviceId = req.getPathInfo();
String objectId = req.getParameter("id");
if (objectId == null) {
objectId = req.getParameter("ejbid");
}
ROPRequestContext.start(serviceId, objectId, req, resp);
String operation = req.getParameter(ROPConstants.OPERATION_PARAMETER);
if (operation != null) {
switch(operation) {
case ROPConstants.ESTABLISH_SESSION_OPERATION:
RemoteSession session = remoteService.establishSession();
serializationService.serialize(session, resp.getOutputStream());
break;
case ROPConstants.ESTABLISH_SHARED_SESSION_OPERATION:
String sessionName = req.getParameter(ROPConstants.SESSION_NAME_PARAMETER);
RemoteSession sharedSession = remoteService.establishSharedSession(sessionName);
serializationService.serialize(sharedSession, resp.getOutputStream());
break;
default:
throw new ServletException("Unknown operation: " + operation);
}
} else {
Object response = remoteService.processMessage(serializationService.deserialize(req.getInputStream(), ClientMessage.class));
serializationService.serialize(response, resp.getOutputStream());
}
} catch (RuntimeException | ServletException e) {
throw e;
} catch (Throwable e) {
throw new ServletException(e);
} finally {
ROPRequestContext.end();
}
}
use of org.apache.cayenne.remote.RemoteSession in project cayenne by apache.
the class HttpRemoteService method createServerSession.
/**
* Creates a new ServerSession based on a shared DataChannel. Returned ServerSession
* is stored in HttpSession for future reuse.
*
* @param name shared session name used to lookup a shared DataChannel.
*/
@Override
protected ServerSession createServerSession(String name) {
if (name == null) {
throw new IllegalArgumentException("Name is null for shared session.");
}
HttpSession httpSession = getSession(true);
DataChannel channel;
synchronized (sharedChannels) {
channel = getSharedChannel(name);
if (channel == null) {
channel = createChannel();
saveSharedChannel(name, channel);
logger.debug("Starting a new shared channel: " + name);
} else {
logger.debug("Joining existing shared channel: " + name);
}
}
RemoteSession remoteSession = createRemoteSession(httpSession.getId(), name, true);
ServerSession serverSession = new ServerSession(remoteSession, channel);
httpSession.setAttribute(SESSION_ATTRIBUTE, serverSession);
return serverSession;
}
use of org.apache.cayenne.remote.RemoteSession in project cayenne by apache.
the class HttpRemoteService method createServerSession.
/**
* Creates a new ServerSession with a dedicated DataChannel. Returned ServerSession is
* stored in HttpSession for future reuse.
*/
@Override
protected ServerSession createServerSession() {
HttpSession httpSession = getSession(true);
DataChannel channel = createChannel();
RemoteSession remoteSession = createRemoteSession(httpSession.getId(), null, false);
ServerSession serverSession = new ServerSession(remoteSession, channel);
httpSession.setAttribute(SESSION_ATTRIBUTE, serverSession);
return serverSession;
}
use of org.apache.cayenne.remote.RemoteSession in project cayenne by apache.
the class BaseRemoteService method establishSession.
@Override
public RemoteSession establishSession() {
logger.debug("Session requested by client");
RemoteSession session = createServerSession().getSession();
logger.debug("Established client session: " + session);
return session;
}
use of org.apache.cayenne.remote.RemoteSession in project cayenne by apache.
the class BaseRemoteService method createRemoteSession.
protected RemoteSession createRemoteSession(String sessionId, String name, boolean enableEvents) {
RemoteSession session = (enableEvents) ? new RemoteSession(sessionId, eventBridgeFactoryName, eventBridgeParameters) : new RemoteSession(sessionId);
session.setName(name);
return session;
}
Aggregations