Esempio n. 1
0
  private Response rpc(Request request) {
    ServerScriptingSession session = findLocalSession(request);
    Response response = new Response();

    if (request.getRequestType() == Request.openSession) {
      if (session == null) {
        try {
          session = makeSession();
          session.setId(request.getSessionId());
          session.defineApi(getApiDefinition());
          session.defineClassMapping(getClassMapping());
          session.setLocator(new LocalSessionLocator(connection));
          session.start();
          registerSession(session);
        } catch (Throwable e) {
          response.setException(e);
        }
      }
    } else {
      synchronized (session) {
        try {
          if (request.getRequestType() == Request.getApiDefinition) {
            response.setResult(getApiDefinition());
          } else if (request.getRequestType() == Request.getVariable) {
            response.setResult(session.getVariable(request.getVariableName()));
          } else if (request.getRequestType() == Request.newObject) {
            response.setResult(session.newObject(request.getTypeName(), request.getArgs()));
          } else if (request.getRequestType() == Request.invokeMethod) {
            response.setResult(
                session.invokeMethod(request.getSelf(), request.getMethod(), request.getArgs()));
          } else if (request.getRequestType() == Request.setProperty) {
            session.putProperty(request.getSelf(), request.getPropertyName(), request.getValue());
          } else if (request.getRequestType() == Request.getProperty) {
            response.setResult(session.getProperty(request.getSelf(), request.getPropertyName()));
          } else if (request.getRequestType() == Request.closeSession) {
            session.end();
          } else {
            IllegalArgumentException e =
                new IllegalArgumentException("unknown request type" + request.getRequestType());
            response.setException(e);
          }
        } catch (Exception e) {
          response.setException(e);
        }
      }
    }

    return response;
  }
Esempio n. 2
0
 private void registerSession(ServerScriptingSession session) {
   sessions.put(session.getId(), session);
 }