Package org.persvr.remote

Examples of org.persvr.remote.Client


   
  }


  protected EventStream getEventStream(HttpServletRequest req) throws IOException {
    Client stream;
    String createConnectionId = PersevereFilter.getParameter(req,"Create-Client-Id");
    String connectionId;
    if (createConnectionId == null) {
      connectionId = req.getRemoteAddr() + PersevereFilter.getParameter(req,"Client-Id");
      if (connectionId == null)
        throw new RuntimeException("You must include a Client-Id or Create-Client-Id header");
      stream = EventStream.streams.get(connectionId);
      if (stream == null || !stream.started)
        return null; // referring to a connection id that has been initialized yet
    }
    else { // create a new client id
      connectionId = req.getRemoteAddr() + createConnectionId;
      // else we are picking up connection that was initialized by subscription request
      synchronized(EventStream.streams){
        stream = EventStream.streams.get(connectionId);
        if (stream == null) {
          Object user = Client.getCurrentObjectResponse().getConnection().authorizedUser;
          EventStream.streams.put(connectionId, stream = new Client(connectionId));
          stream.authorizedUser = user;
        }
      }
      if(!stream.started){
        // call the onConnect function
View Full Code Here


    }

    if (req.getHeader("xdomainrequest") == null) {
      // if it is not IE8, we do not want to have multiple connections
      HttpSession session = req.getSession(true);
      Client otherConnection = (Client) session.getAttribute("org.persvr.channel");
      if (otherConnection != null && otherConnection != eventStream) {
        //TODO: Send reconnect advice
        otherConnection.fire(new ConnectionConflict()); // if there is another connection, we need to notify it
      }
      session.setAttribute("org.persvr.channel",eventStream);
    }
    else
      resp.setHeader("XDomainRequestAllowed", "1"); // allow this so we can support streaming in IE8
View Full Code Here

      public Object call(Context cx, Scriptable scope,
          Scriptable thisObj, Object[] args) {
        Boolean onlyConnected = args.length > 0 && Boolean.TRUE.equals(args[0]);
        Set users = new HashSet();
        for (Map.Entry<String, Client> entry : EventStream.streams.entrySet()){
          Client client = entry.getValue();
          if(!onlyConnected || client.isConnected()){
            Object user = client.getAuthorizedUser();
            if(user != null)
              users.add(user);
          }
        }
        return new PersistableArray(users.toArray());
View Full Code Here

    public void propertyChange(List<ObservedCall> evt) {
      for(ObservedCall call : evt){
        if ("MESSAGE".equalsIgnoreCase(call.getMethod())){
          try {
              IndividualRequest request = new Client(null).getIndividualRequest(null, null);
            ((RestChannelsBayeux)bayeux).internalPublish("/" + call.getSourceId(), new JSON.Literal(request.serialize(call.getContent())));
          } catch (IOException e) {
            throw new RuntimeException(e);
          }
        }
View Full Code Here

   */
  public void run(){
    String testsDirectory = System.getProperty("persevere.tests");
    // run the tests and then exit the VM, so we can run a report and finish
    log.info("Running Tests at " + testsDirectory);
    Client connection = new Client("testing");
    Client.registerThisConnection(connection.getIndividualRequest(null, null));

    try {
      File[] testFiles = new File(testsDirectory).listFiles(new FileFilter(){
        public boolean accept(File pathname) {
          return pathname.isFile() && pathname.getName().endsWith(".js");
View Full Code Here

  public static Identification<? extends Object> idForRelativeString(String startingId, String targetId) {
    if(targetId.startsWith("cid:")){
      targetId = targetId.substring(4);
      if(targetId.startsWith("/"))
        targetId = targetId.substring(absolutePathPrefix.length());
      Client client = Client.getCurrentObjectResponse().getConnection();
      Persistable obj = client.getClientSideObject(targetId);
      if(obj == null) {
        String sourceName = targetId.substring(0, targetId.indexOf('/'));
        obj = client.clientSideObject(targetId, Persevere.newObject(sourceName));
      }
      return obj.getId();
    }
    boolean absoluteStart = startingId.matches("\\w+tps?:/.*");
    if (targetId.startsWith("/")){
View Full Code Here

      e.printStackTrace();
    }
    UserSecurity.doPriviledgedAction(new PrivilegedAction(){
      Object output;
      public Object run() {
          Client connection = new Client("console");
          // give this thread a context/user
          Client.registerThisConnection(connection.getIndividualRequest(null, null));
          context = PersevereContextFactory.getContext();
          global = GlobalData.getGlobalScope();
          consoleScope = new NativeObject();
          // we may want to make this a prototype, so you can create unscoped variables without errors. Downside is it might mislead users as to what they can do in methods
          consoleScope.setParentScope(global);
View Full Code Here

    }
    static class LogStatus extends Thread {

    @Override
    public void run() {
      Client connection = new Client("dump");
      Client.registerThisConnection(connection.getIndividualRequest(null, null));
      while(true){
        try {
          Thread.sleep(50000);
        } catch (InterruptedException e) {
          e.printStackTrace();
View Full Code Here

      jettyServlet.service(request, response);
      return;
    }
    response.setContentType("application/json");
    Object json = JSON.parse(request.getParameter("message"));
      Client eventStream = null;
      if (json instanceof HashMap) {
        List array = new ArrayList();
        array.add(json);
        json = array;
      }
      List array = (List) json;
      boolean respondImmediately = false;
      for (int i = 0;i < array.size(); i++) {
        Map obj = (Map) array.get(i);
        String channel = (String) obj.get("channel");
        String clientId = (String) requestHelper.getRequest().getSession().getAttribute("clientId");
        if (clientId != null) {
          obj.put("clientId", clientId);
          eventStream = (Client) request.getSession().getAttribute(clientId);
        }
        obj.remove("ext");
        if (channel.startsWith("/meta")) {
          obj.put("successful", true);
          if (channel.equals("/meta/handshake")) {
            obj.put("authSuccessful", true);
            clientId = Math.random() + "";
            request.getSession().setAttribute(clientId,eventStream = new Client(clientId));
            eventStream.connectionId = clientId;
            requestHelper.getRequest().getSession().setAttribute("clientId", clientId);
            obj.put("clientId", clientId);
            Map advice = new HashMap();
            advice.put("reconnect", "retry");
View Full Code Here

    Persistable request = new PersistableObject();
    request.put("id", request, rpcId++);
   
    request.put("method",request, methodName);
    request.put("params",request, new PersistableArray(args));
    Client.IndividualRequest clientRequest = new Client("server-request").getIndividualRequest(null, null);
    clientRequest.setRequestedPath(target.toString(), target);
    String jsonRpcMessage = clientRequest.serialize(request);
      method.setRequestBody(jsonRpcMessage);
      try {
      int statusCode = GlobalData.httpClient.executeMethod(method);
View Full Code Here

TOP

Related Classes of org.persvr.remote.Client

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.