Package org.persvr.remote

Examples of org.persvr.remote.RequestHelper


    HttpServletResponse response = event.getHttpServletResponse();
   
    if (event.getEventType() == CometEvent.EventType.BEGIN) {
      request.setAttribute("org.persvr.tomcatcomet", true);
      // need to call this to get the user registered
      new RequestHelper(request,response); // must register this connection
      event.setTimeout(COMET_TIMEOUT);
      // don't do anything yet, wait until read
      doPost(request,event.getHttpServletResponse());

    }     
View Full Code Here


    }
  }
  @Override
  protected void service(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    final RequestHelper requestHelper = new RequestHelper((HttpServletRequest)request,(HttpServletResponse)response);
    if (jettyServlet != null) {
      // use the Jetty Bayeux implementation if available
      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");
            obj.put("advice", advice);
            List connectionTypes = new ArrayList();
            connectionTypes.add("rest-channels");
            obj.put("supportedConnectionTypes", connectionTypes);
            respondImmediately = true;
          }
          else if (channel.equals("/meta/connect")) {
            obj.put("error","");
            Map advice = new HashMap();
            advice.put("reconnect", "retry");
            obj.put("advice", advice);
          }
          else if (channel.equals("/meta/disconnect")) {
            respondImmediately = true;
          }
          else if (channel.equals("/meta/subscribe")) {
            //TODO: Need to implement this copying from PersevereFilter
          }
          else if (channel.equals("/meta/unsubscribe")) {
            //TODO: Need to implement this
          }
          else
            throw new RuntimeException("Unknown meta channel");
        }
        else {
          // publish event
          List target = (List) Client.getCurrentObjectResponse().requestData(channel, false);
          Object appendingItem = requestHelper.convertJsonStringToObject(obj.get("instances").toString());
          target.add(appendingItem);
        }
      }
      ServletOutputStream outStream = response.getOutputStream();
      if (respondImmediately) {
View Full Code Here

TOP

Related Classes of org.persvr.remote.RequestHelper

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.