Package org.xmlBlaster.client

Examples of org.xmlBlaster.client.I_XmlBlasterAccess


            }

            ME  = "BlasterHttpProxyServlet-" + req.getRemoteAddr() + "-" +
                  connectQos.getSessionName().getLoginName() + "-" + sessionId;

            I_XmlBlasterAccess xmlBlasterAccess = glob.getXmlBlasterAccess();
            HttpPushHandler pushHandler = new HttpPushHandler(req, res, sessionId,
                                                     connectQos.getSessionName().getRelativeName(),
                                                     xmlBlasterAccess);

            xmlBlasterAccess.connect(connectQos, pushHandler);
            if (!session.isNew()) {
               pushHandler.startPing();
            }
            else {
               log.info("Login action, browser has not yet joined this sessionId (cookie), so first pings pong may return an invalid sessionId");
View Full Code Here


      /*HttpSession session =*/ req.getSession(false);
      String sessionId = req.getRequestedSessionId();

      log.info("Entering servlet doPost() ...");

      I_XmlBlasterAccess xmlBlaster = null;
      HttpPushHandler pushHandler = null;

      try {
         pushHandler = BlasterHttpProxy.getHttpPushHandler(sessionId);
         xmlBlaster = pushHandler.getXmlBlasterAccess();
      }
      catch (XmlBlasterException e) {
         log.severe("Caught XmlBlaster Exception: " + e.getMessage());
         return;
      }

      try {
         String actionType = Util.getParameter(req, "ActionType", "NONE");
         MethodName action;
         try {
            action = MethodName.toMethodName(actionType);
         }
         catch (IllegalArgumentException ie) {
            throw new Exception("Unknown or missing 'ActionType=" + actionType + "' please choose 'subscribe' 'unSubscribe' 'erase' etc.");
         }

         // Extract the message data
         String oid = Util.getParameter(req, "key.oid", null);
         if (oid != null) oid = Global.decode(oid, ENCODING);

         String key = Util.getParameter(req, "key", null);
         if (key != null) {
            key = Global.decode(key, ENCODING);
            if (log.isLoggable(Level.FINEST)) log.finest("key=\n'" + key + "'");
         }
        
         String content = Util.getParameter(req, "content", null);
         if (content != null) {
            content = Global.decode(content, ENCODING);
         }
         else
            content = "";
         if (log.isLoggable(Level.FINEST)) log.finest("content=\n'" + content + "'");

         String qos = Util.getParameter(req, "qos", null);
         if (qos != null) {
            qos = Global.decode(qos, ENCODING);
         }
         else
            qos = "";
         if (log.isLoggable(Level.FINEST)) log.finest("qos=\n'" + qos + "'");

         if (action.equals(MethodName.SUBSCRIBE)) { // "subscribe"
            log.fine("subscribe arrived ...");
           
            if (oid != null) {
               SubscribeKey xmlKey = new SubscribeKey(glob, oid);
               SubscribeReturnQos ret = xmlBlaster.subscribe(xmlKey.toXml(), qos);
               log.info("Subscribed to simple key.oid=" + oid + ": " + ret.getSubscriptionId());
            }
            else if (key != null) {
               SubscribeReturnQos ret = xmlBlaster.subscribe(key, qos);
               log.info("Subscribed to " + key + ": SubscriptionId=" + ret.getSubscriptionId() + " qos=" + qos);
            }
            else {
               String str = "Please call servlet with some 'key.oid=...' or 'key=<key ...' when subscribing";
               log.severe(str);
               htmlOutput(str, res);
               return;
            }
         }

         else if (action.equals(MethodName.UNSUBSCRIBE)) { // "unSubscribe"
            log.fine("unSubscribe arrived ...");
            //UnSubscribeReturnQos[] ret;

            if (oid != null) {
               UnSubscribeKey xmlKey = new UnSubscribeKey(glob, oid);
               /*ret = */xmlBlaster.unSubscribe(xmlKey.toXml(), qos);
            }
            else if (key != null) {
               /*ret = */xmlBlaster.unSubscribe(key, qos);
            }
            else {
               String str = "Please call servlet with some 'key.oid=...' or 'key=<key ...' when unsubscribing";
               log.severe(str);
               htmlOutput(str, res);
               return;
            }
         }

         else if (action.equals(MethodName.GET)) { // "get"
            throw new Exception("Synchronous ActionType=get is not supported");
         }

         else if (action.equals(MethodName.PUBLISH)) { // "publish"
            log.fine("publish arrived ...");
            if (key == null) {
               String str = "Please call servlet with some key when publishing";
               log.severe(str);
               htmlOutput(str, res);
               return;
            }
            if (content == null)
               content = "";

            log.info("Publishing '" + key + "'");
            MsgUnit msgUnit = new MsgUnit(glob, key, content.getBytes(), qos);
            try {
               PublishReturnQos prq = xmlBlaster.publish(msgUnit);
               log.fine("Success: Publishing done, returned oid=" + prq.getKeyOid());
            } catch(XmlBlasterException e) {
               log.warning("XmlBlasterException: " + e.getMessage());
            }
         }

         else if (action.equals(MethodName.ERASE)) { // "erase"
            log.fine("erase arrived ...");
            //EraseReturnQos[] ret;

            if (oid != null) {
               EraseKey ek = new EraseKey(glob, oid);
               /*ret =*/ xmlBlaster.erase(ek.toXml(), qos);
            }
            else if (key != null) {
               /*ret =*/ xmlBlaster.erase(key, qos);
            }
            else {
               String str = "Please call servlet with some 'key.oid=...' or 'key=<key ...' when subscribing";
               log.severe(str);
               htmlOutput(str, res);
View Full Code Here

      XmlBlasterException {
    String actionType = (String) req.getParameter("action");
    String smsText = (String) req.getParameter("cheapSmsSend");
    if (actionType != null && "publish".equals(actionType)) {
      log(ME + "Got action = '" + actionType + "' -> '" + smsText + "'");
      I_XmlBlasterAccess xmlBlaster = getXmlBlaster(req);
      String topicId = props.getProperty("smsBroadcastTopicId",
          "vehicle.sms.broadcast");
      PublishKey pk = new PublishKey(xmlBlaster.getGlobal(), topicId,
          "text/xml", "1.0");
      PublishQos pq = new PublishQos(xmlBlaster.getGlobal());
      pq.addClientProperty("sender", req.getSession().getId()); // TODO:
                                    // nice
                                    // name
      MsgUnit msgUnit = new MsgUnit(pk, smsText.getBytes("UTF-8"), pq);
      xmlBlaster.publish(msgUnit);
      return true;
    }
    return false;
  }
View Full Code Here

    return false;
  }

  private String getFeedback(HttpServletRequest req)
      throws XmlBlasterException, UnsupportedEncodingException {
    I_XmlBlasterAccess xmlBlaster = getXmlBlaster(req);
    String topicId = props.getProperty("smsFeedbackTopicId",
        "vehicle.sms.feedback");
    GetKey gk = new GetKey(xmlBlaster.getGlobal(), topicId);
    GetQos gq = new GetQos(xmlBlaster.getGlobal());
    MsgUnit[] msgs = xmlBlaster.getCached(gk, gq);
    if (msgs.length > 0) {
      // log(ME+ msgs.length + " msgs found ...");
      byte[] content = msgs[msgs.length - 1].getContent();
      String sms = new String(content, "UTF-8");
      return sms.trim();
View Full Code Here

    return null;
  }

  private Position getCurrentPosition(HttpServletRequest req)
      throws XmlBlasterException {
    I_XmlBlasterAccess xmlBlaster = getXmlBlaster(req);
    String topicId = props.getProperty("gpsTopicId", "vehicle.location");
    GetKey gk = new GetKey(xmlBlaster.getGlobal(), topicId);
    GetQos gq = new GetQos(xmlBlaster.getGlobal());
    MsgUnit[] msgs = xmlBlaster.getCached(gk, gq);
    if (msgs.length > 0) {
      // log(ME+ msgs.length + " msgs found ...");
      byte[] content = msgs[msgs.length - 1].getContent();
      return parsePosition(content);
    }
View Full Code Here

      if (warnAuth)
         log.warning("Login action, applet has not supplied connect QoS authentication information - we login with the servlets default authentication settings");
      else
         log.info("Login action with applet supplied connect QoS authentication information");

      I_XmlBlasterAccess xmlBlasterAccess = glob.getXmlBlasterAccess();
      PushHandler pushHandler = new PushHandler(req, res, session.getId(),
                                               connectQos.getSessionName().getRelativeName(),
                                               xmlBlasterAccess, this.timeout);
      xmlBlasterAccess.connect(connectQos, pushHandler);
      pushHandler.startPing();
      String key = "PushHandler"+getParameter(req, "appletInstanceCount", "0");
      session.setAttribute(key, pushHandler);

      // Don't fall out of doGet() to keep the HTTP connection open
View Full Code Here

      ME  += "-" + sessionId;
      if (log.isLoggable(Level.FINE)) log.fine("Entering servlet doPost() ...");

      Global glob = null;
      I_XmlBlasterAccess xmlBlaster = null;
      PushHandler pushHandler = null;
      Object returnObject = null;

      try {
         pushHandler = getPushHandler(req);
         xmlBlaster = pushHandler.getXmlBlasterAccess();
         glob = xmlBlaster.getGlobal();
      }
      catch (XmlBlasterException e) {
         log.warning("Caught XmlBlaster Exception: " + e.getMessage());
         writeResponse(res, I_XmlBlasterAccessRaw.EXCEPTION_NAME, e.getMessage());
         return;
      }

      try {
         // Extract the message data

         MsgHolder msg = extractMessage(ME, log, req, binaryMsg);
         String oid = msg.getOid();
         String key = msg.getKey();
         String qos = msg.getQos();
         String xmlRequest = msg.getKey(); // in case of xmlScript the request is sent as the key (all other are null)
         byte[] content = msg.getContent();
        
         if (actionType.equals(I_XmlBlasterAccessRaw.PING_NAME)) { // "ping"
            if (log.isLoggable(Level.FINE)) log.fine("ping arrived, qos=" + qos);
            Hashtable map = new Hashtable();
            if (xmlBlaster.isAlive()) {
               map.put("/qos/state/@id", Constants.STATE_OK);
               map.put("/qos/state/@info", ConnectionStateEnum.ALIVE.toString()); // "ALIVE"
            }
            else if (xmlBlaster.isPolling()) {
               map.put("/qos/state/@id", Constants.STATE_OK);
               map.put("/qos/state/@info", ConnectionStateEnum.POLLING.toString()); // "POLLING"
            }
            else {
               map.put("/qos/state/@id", Constants.STATE_WARN);
               map.put("/qos/state/@info", ConnectionStateEnum.DEAD.toString()); // "DEAD"
            }
            returnObject = map;
         }

         else if (actionType.equals(I_XmlBlasterAccessRaw.SUBSCRIBE_NAME)) { // "subscribe"
            if (log.isLoggable(Level.FINE)) log.fine("subscribe arrived ... oid=" + oid + ", key=" + key + ", qos=" + qos);
     
            if (oid != null) {
               SubscribeKey xmlKey = new SubscribeKey(glob, oid);
               SubscribeReturnQos ret = xmlBlaster.subscribe(xmlKey.toXml(), qos);
               returnObject = ret.getData().toJXPath();
               if (log.isLoggable(Level.FINE)) log.fine("Subscribed to simple key.oid=" + oid + ": " + ret.getSubscriptionId());
            }
            else if (key != null) {
               SubscribeReturnQos ret = xmlBlaster.subscribe(key, qos);
               returnObject = ret.getData().toJXPath();
               if (log.isLoggable(Level.FINE)) log.fine("Subscribed to " + key + ": SubscriptionId=" + ret.getSubscriptionId() + " qos=" + qos + " returnObject=" + returnObject.getClass().getName());
            }
            else {
               String str = "Please call servlet with some 'key.oid=...' or 'key=<key ...' when subscribing";
               log.warning(str);
               throw new XmlBlasterException(this.initialGlobal, ErrorCode.USER_CONFIGURATION, ME, str);
            }
         }

         else if (actionType.equals(I_XmlBlasterAccessRaw.UNSUBSCRIBE_NAME)) { // "unSubscribe"
            if (log.isLoggable(Level.FINE)) log.fine("unSubscribe arrived ...");
            UnSubscribeReturnQos[] ret;

            if (oid != null) {
               UnSubscribeKey xmlKey = new UnSubscribeKey(glob, oid);
               ret = xmlBlaster.unSubscribe(xmlKey.toXml(), qos);
            }
            else if (key != null) {
               ret = xmlBlaster.unSubscribe(key, qos);
            }
            else {
               String str = "Please call servlet with some 'key.oid=...' or 'key=<key ...' when unsubscribing";
               log.warning(str);
               throw new XmlBlasterException(this.initialGlobal, ErrorCode.USER_CONFIGURATION, ME, str);
            }
            Vector arr = new Vector();
            for (int ii=0; ii<ret.length; ii++) {
               arr.add(ret[ii].getData().toJXPath());
               if (log.isLoggable(Level.FINE)) log.fine("UnSubscribed " + ret[ii].getSubscriptionId());
            }
            returnObject = (Hashtable[])arr.toArray(new Hashtable[arr.size()]);
         }

         else if (actionType.equals(I_XmlBlasterAccessRaw.GET_NAME)) { // "get"
            if (log.isLoggable(Level.FINE)) log.fine("get arrived ...");
            MsgUnit[] msgUnitArr = xmlBlaster.get(key, qos);
            Vector list = new Vector(msgUnitArr.length*3);
            for (int i=0; i<msgUnitArr.length; i++) {
               list.add(((MsgQosData)msgUnitArr[i].getQosData()).toJXPath());
               list.add(((MsgKeyData)msgUnitArr[i].getKeyData()).toJXPath());
               list.add(msgUnitArr[i].getContent());
            }
            returnObject = list;
         }

         else if (actionType.equals(I_XmlBlasterAccessRaw.PUBLISH_NAME)) { // "publish"
            if (log.isLoggable(Level.FINE)) log.fine("publish arrived ...");
            if (key == null) {
               String str = "Please call servlet with some key when publishing";
               log.warning(str);
               XmlBlasterException x = new XmlBlasterException(this.initialGlobal, ErrorCode.USER_ILLEGALARGUMENT, ME, str);
               writeResponse(res, I_XmlBlasterAccessRaw.EXCEPTION_NAME, x.getMessage());
               return;
            }
            if (log.isLoggable(Level.FINE)) log.fine("Publishing '" + key + "'");
            MsgUnit msgUnit = new MsgUnit(glob, key, content, qos);
            try {
               PublishReturnQos prq = xmlBlaster.publish(msgUnit);
               returnObject = prq.getData().toJXPath();
               if (log.isLoggable(Level.FINE)) log.fine("Success: Publishing done, returned oid=" + prq.getKeyOid());
            } catch(XmlBlasterException e) {
               log.warning("XmlBlasterException: " + e.getMessage());
            }
         }

         else if (actionType.equals(I_XmlBlasterAccessRaw.ERASE_NAME)) { // "erase"
            if (log.isLoggable(Level.FINE)) log.fine("erase arrived ...");
            EraseReturnQos[] ret;

            if (oid != null) {
               EraseKey ek = new EraseKey(glob, oid);
               ret = xmlBlaster.erase(ek.toXml(), qos);
            }
            else if (key != null) {
               ret = xmlBlaster.erase(key, qos);
            }
            else {
               String str = "Please call servlet with some 'key.oid=...' or 'key=<key ...' when subscribing";
               log.warning(str);
               throw new XmlBlasterException(this.initialGlobal, ErrorCode.USER_CONFIGURATION, ME, str);
View Full Code Here

      if (isSocket) return;
      log.info("testCallbackFailure() ...");
      try {
         log.info("Connecting ...");
         Global globSub = this.glob.getClone(null);
         I_XmlBlasterAccess con = globSub.getXmlBlasterAccess();
         ConnectQos qos = new ConnectQos(globSub, name, passwd);
         con.connect(qos, this); // Login to xmlBlaster

         try {
            Client.shutdownCb(con, Client.Shutdown.KEEP_LOGGED_IN);
         }
         catch (Throwable e) {
            log.severe("testCallbackFailure: " + e.toString());
            fail(e.toString());
         }

         String subscribeOid = con.subscribe("<key oid='testCallbackMsg'/>", null).getSubscriptionId();
         log.info("Success: Subscribe on " + subscribeOid + " done");

         MsgUnit msgUnit = new MsgUnit("<key oid='testCallbackMsg'/>", "Bla".getBytes(), null);
         publishOid = con.publish(msgUnit).getKeyOid();
         log.info("Success: Publishing done, returned oid=" + publishOid);

         waitOnUpdate(2000L, 1);
         assertTrue("Expected a dead letter", isDeadMessage);
         isDeadMessage = false;
View Full Code Here

            this.mbeanHandle = this.global.registerMBean(contextNode, this);
        
         if (this.pool == null)
            this.pool = initializePersistentInfo();
        
         I_XmlBlasterAccess conn = this.global.getXmlBlasterAccess();
         this.user = get("mom.user", this.user);
         this.password = get("mom.password", this.password);
         ConnectQos connectQos = new ConnectQos(this.global, this.user, this.password);
         boolean persistentConnection = true;
         boolean persistentSubscription = true;
         connectQos.setPersistent(persistentConnection);
         connectQos.setMaxSessions(1);
         connectQos.setPtpAllowed(true);
         connectQos.setSessionTimeout(0L);
         String sessionName = REPL_MANAGER_SESSION;
         connectQos.setSessionName(new SessionName(this.global, sessionName));
         conn.connect(connectQos, this);
        
         // this is the instance passed from the outside, not a clone, otherwise
         // it will not find the plugin registry for the MIME plugin
         putObject("org.xmlBlaster.engine.Global", global);
         getEngineGlobal(this.global).getPluginRegistry().register(getType() + "," + getVersion(), this);

         this.sqlTopic = this.get("replication.sqlTopic", "sqlTopic");
         if (this.sqlTopic != null) {
            SubscribeKey subKey = new SubscribeKey(this.global, this.sqlTopic);
            SubscribeQos subQos = new SubscribeQos(this.global);
            subQos.setPersistent(persistentSubscription);
            subQos.setMultiSubscribe(false);
            conn.subscribe(subKey, subQos);
         }
        
         boolean wantsDeadLetters = true;
         if (wantsDeadLetters) {
            SubscribeKey subKey = new SubscribeKey(this.global, Constants.OID_DEAD_LETTER);
            SubscribeQos subQos = new SubscribeQos(this.global);
            // we probably need this to avoid missing messages when changing runlevels
            subQos.setPersistent(persistentSubscription);
            subQos.setMultiSubscribe(false);
            conn.subscribe(subKey, subQos);
         }
         this.maxResponseEntries = this.getLong("replication.sqlMaxEntries", 10L);

         RequestBroker rb = getEngineGlobal(this.global).getRequestBroker();
        
View Full Code Here

         }
        
         this.global.unregisterMBean(this.mbeanHandle);
         getEngineGlobal(this.global).getRequestBroker().getAuthenticate(null).removeClientListener(this);
         getEngineGlobal(this.global).getRequestBroker().removeSubscriptionListener(this);
         I_XmlBlasterAccess conn = this.global.getXmlBlasterAccess();
         if (this.sqlTopic != null) {
            UnSubscribeKey key = new UnSubscribeKey(this.global, this.sqlTopic);
            conn.unSubscribe(key, new UnSubscribeQos(this.global));
         }
         conn.disconnect(new DisconnectQos(this.global));
         this.replications.clear();
         this.replSlaveMap.clear();
         this.topicToPrefixMap.clear();
         this.counterMap.clear();
        
View Full Code Here

TOP

Related Classes of org.xmlBlaster.client.I_XmlBlasterAccess

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.