Search in sources :

Example 1 with RemoteSession

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();
    }
}
Also used : ServletException(javax.servlet.ServletException) RemoteSession(org.apache.cayenne.remote.RemoteSession) ClientMessage(org.apache.cayenne.remote.ClientMessage)

Example 2 with RemoteSession

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;
}
Also used : DataChannel(org.apache.cayenne.DataChannel) HttpSession(javax.servlet.http.HttpSession) RemoteSession(org.apache.cayenne.remote.RemoteSession)

Example 3 with RemoteSession

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;
}
Also used : DataChannel(org.apache.cayenne.DataChannel) HttpSession(javax.servlet.http.HttpSession) RemoteSession(org.apache.cayenne.remote.RemoteSession)

Example 4 with RemoteSession

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;
}
Also used : RemoteSession(org.apache.cayenne.remote.RemoteSession)

Example 5 with RemoteSession

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;
}
Also used : RemoteSession(org.apache.cayenne.remote.RemoteSession)

Aggregations

RemoteSession (org.apache.cayenne.remote.RemoteSession)6 DataChannel (org.apache.cayenne.DataChannel)3 HttpSession (javax.servlet.http.HttpSession)2 HashMap (java.util.HashMap)1 ServletException (javax.servlet.ServletException)1 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1 ObjectContextFactory (org.apache.cayenne.configuration.ObjectContextFactory)1 Query (org.apache.cayenne.query.Query)1 ClientMessage (org.apache.cayenne.remote.ClientMessage)1 QueryMessage (org.apache.cayenne.remote.QueryMessage)1 Test (org.junit.Test)1