Package org.xmlBlaster.util

Examples of org.xmlBlaster.util.MsgUnit


      log.info("testFilter() with filterMessageContentBiggerAs=" + filterMessageContentBiggerAs + " ...");

      log.info("TEST 1: Testing filtered message");
      String content = "12345678901"; // content is too long, our plugin denies this message
      try {
         PublishReturnQos rq = con.publish(new MsgUnit("<key oid='MSG'/>", content.getBytes(), null));
         log.info("TEST 1: SUCCESS returned state=" + rq.getState());
         assertTrue("Return OK", !Constants.STATE_OK.equals(rq.getState()));
      } catch(XmlBlasterException e) {
         log.warning("XmlBlasterException: " + e.getMessage());
         assertTrue("publish - XmlBlasterException: " + e.getMessage(), false);
      }
      try {
         MsgUnit[] msgUnits = con.get("<key oid='MSG'/>", null);
         assertTrue("Invalid return", msgUnits!=null);
         assertEquals("Expected no returned message", 0, msgUnits.length);
      } catch(XmlBlasterException e) {
         log.warning("get - XmlBlasterException: " + e.getMessage());
         fail("get - XmlBlasterException: " + e.getMessage());
      }


      log.info("TEST 2: Testing unfiltered message");
      content = "1234567890";
      try {
         PublishReturnQos rq = con.publish(new MsgUnit("<key oid='MSG'/>", content.getBytes(), null));
         assertEquals("Return not OK", Constants.STATE_OK, rq.getState());
         log.info("TEST 2: SUCCESS");
      } catch(XmlBlasterException e) {
         log.warning("XmlBlasterException: " + e.getMessage());
         assertTrue("publish - XmlBlasterException: " + e.getMessage(), false);
      }
      try {
         MsgUnit[] msgUnits = con.get("<key oid='MSG'/>", null);
         assertTrue("Expected one returned message", msgUnits!=null);
         assertTrue("Expected exactly one returned message", msgUnits.length==1);
         assertTrue("Message content in corrupted '" + new String(msgUnits[0].getContent()) + "' versus '" + content + "'",
                msgUnits[0].getContent().length == content.length());
         log.info("Success: Got one message.");
      } catch(XmlBlasterException e) {
         log.warning("get - XmlBlasterException: " + e.getMessage());
         fail("get - XmlBlasterException: " + e.getMessage());
      }

      log.info("TEST 3: Test what happens if the plugin throws an exception");
      try {   // see THROW_EXCEPTION_FOR_LEN=3
         con.publish(new MsgUnit("<key oid='MSG'/>", "123".getBytes(), null));
         fail("publish - expected an XmlBlasterException");
      } catch(XmlBlasterException e) {
         log.warning("TEST 3: SUCCESS XmlBlasterException: " + e.getMessage());
      }
View Full Code Here


      log.info("TEST 1: Testing filtered PtP message");
      String content = "12345678901"; // content is too long, our plugin denies this message
      try {
         PublishQos pq = new PublishQos(glob);
         pq.addDestination(new Destination(new SessionName(glob, name)));
         PublishReturnQos rq = con.publish(new MsgUnit("<key oid='MSG'/>", content.getBytes(), pq.toXml()));
         log.info("TEST 1: SUCCESS returned state=" + rq.getState());
         assertTrue("Return OK", !Constants.STATE_OK.equals(rq.getState()));
      } catch(XmlBlasterException e) {
         log.warning("XmlBlasterException: " + e.getMessage());
         assertTrue("publish - XmlBlasterException: " + e.getMessage(), false);
      }
      try {
         MsgUnit[] msgUnits = con.get("<key oid='MSG'/>", null);
         assertTrue("Invalid return", msgUnits!=null);
         assertEquals("Expected no returned message", 0, msgUnits.length);
      } catch(XmlBlasterException e) {
         log.warning("get - XmlBlasterException: " + e.getMessage());
         fail("get - XmlBlasterException: " + e.getMessage());
      }

      log.info("TEST 2: Testing unfiltered PtP message");
      content = "1234567890";
      try {
         PublishQos pq = new PublishQos(glob);
         pq.addDestination(new Destination(new SessionName(glob, name)));
         PublishReturnQos rq = con.publish(new MsgUnit("<key oid='MSG'/>", content.getBytes(), pq.toXml()));
         assertEquals("Return not OK", Constants.STATE_OK, rq.getState());
         log.info("TEST 2: SUCCESS");
      } catch(XmlBlasterException e) {
         log.warning("XmlBlasterException: " + e.getMessage());
         assertTrue("publish - XmlBlasterException: " + e.getMessage(), false);
      }

      log.info("TEST 3: Test what happens if the plugin throws an exception");
      try {   // see THROW_EXCEPTION_FOR_LEN=3
         PublishQos pq = new PublishQos(glob);
         pq.addDestination(new Destination(new SessionName(glob, name)));
         con.publish(new MsgUnit("<key oid='MSG'/>", "123".getBytes(), pq.toXml()));
         fail("publish - expected an XmlBlasterException");
      } catch(XmlBlasterException e) {
         log.warning("TEST 3: SUCCESS XmlBlasterException: " + e.getMessage());
      }
View Full Code Here

      numReceived = 0;
      String xmlKey = "<key oid='" + oidExact + "' contentMime='" + contentMime + "' contentMimeExtended='" + contentMimeExtended + "'>\n" +
                      "</key>";
      senderContent = "Yeahh, i'm the new content";
      try {
         MsgUnit msgUnit = new MsgUnit(xmlKey, senderContent.getBytes(), "<qos></qos>");
         publishOid = senderConnection.publish(msgUnit).getKeyOid();
         log.info("Success: Publishing done, returned oid=" + publishOid);
      } catch(XmlBlasterException e) {
         log.warning("XmlBlasterException: " + e.getMessage());
         assertTrue("publish - XmlBlasterException: " + e.getMessage(), false);
View Full Code Here

   {
      log.info("testFilter() with XPath filter /news[@type='sport'] ...");

      log.info("TEST 1: Testing sport message");
      try {
         con.publish(new MsgUnit("<key oid='MSG' contentMime='text/xml'/>", "<news type='sport'></news>".getBytes(), null));
      } catch(XmlBlasterException e) {
         log.warning("XmlBlasterException: " + e.getMessage());
         assertTrue("publish - XmlBlasterException: " + e.getMessage(), false);
      }
      waitOnUpdate(subscribeOid,4000L, 1);


      log.info("TEST 2: Testing culture message");
      try {
         con.publish(new MsgUnit("<key oid='MSG' contentMime='text/xml'/>", "<news type='culture'></news>".getBytes(), null));
      } catch(XmlBlasterException e) {
         log.warning("XmlBlasterException: " + e.getMessage());
         assertTrue("publish - XmlBlasterException: " + e.getMessage(), false);
      }
      waitOnUpdate(subscribeOid2,4000L, 1);

      log.info("TEST 3: Testing AnotherMsG message");
      try {
         con.publish(new MsgUnit("<key oid='AnotherMsG' contentMime='text/xml'/>", "<news type='culture'></news>".getBytes(), null));
      } catch(XmlBlasterException e) {
         log.warning("XmlBlasterException: " + e.getMessage());
         assertTrue("publish - XmlBlasterException: " + e.getMessage(), false);
      }
      waitOnUpdate(subscribeOid3,4000L, 1);
     
      log.info("TEST 4: Testing extention functions");
      try {
         con.publish(new MsgUnit("<key oid='AnotherMsG' contentMime='text/xml'/>", "<news><body><p>A little message</p><p>With a Needle in second paragraph wich normal XPath string function would not see</p></body></news>".getBytes(), null));
      } catch(XmlBlasterException e) {
         log.warning("XmlBlasterException: " + e.getMessage());
         assertTrue("publish - XmlBlasterException: " + e.getMessage(), false);
      }
      waitOnUpdate(subscribeOid4,4000L, 1);
View Full Code Here

         //msgQosData.dirtyRead(null);//NodeId
         msgQosData.setPriority(PriorityEnum.LOW4_PRIORITY);
         msgQosData.setFromPersistenceStore(true);
         msgQosData.setLifeTime(4000L);
         msgQosData.setRemainingLifeStatic(6000L);
         MsgUnit msgUnit  = new MsgUnit(key.toXml(), content, msgQosData.toXml());

         log.fine("Testing" + msgQosData.toXml());

         SessionName receiver = new SessionName(glob, "receiver1");
         String subscriptionId = "subid";
         int redeliverCounter = 2;
         boolean updateOneway = true;
         org.xmlBlaster.engine.ServerScope global = new org.xmlBlaster.engine.ServerScope();
         MsgUnitWrapper msgWrapper = new MsgUnitWrapper(glob, msgUnit, queue.getStorageId());
         MsgQueueUpdateEntry entry = new MsgQueueUpdateEntry(global, msgWrapper, queue.getStorageId(),
                                         receiver, subscriptionId, updateOneway);
         entry.incrRedeliverCounter();
         entry.incrRedeliverCounter();

         queue.put(entry, false);
         I_QueueEntry returnEntry = queue.peek();

         boolean isUpdate = (returnEntry instanceof MsgQueueUpdateEntry);
         assertTrue("updateEntry: the return value is not an update ", isUpdate);
        
         MsgQueueUpdateEntry updateEntry = (MsgQueueUpdateEntry)returnEntry;

         assertEquals("The subscriptionId of the entry is different ", subscriptionId, updateEntry.getSubscriptionId());
         assertEquals("The state of the entry is different ", state, updateEntry.getState());
         assertEquals("The redeliverCounter of the entry is different ", redeliverCounter, updateEntry.getRedeliverCounter());
         assertEquals("The priority of the entry is different ", entry.getPriority(), updateEntry.getPriority());
         assertEquals("The oneway of the entry is different ", updateOneway, updateEntry.updateOneway());
         assertEquals("The persistent of the entry is different ", entry.isPersistent(), updateEntry.isPersistent());
         assertEquals("The receiver of the entry is different ", entry.getReceiver().toString(), updateEntry.getReceiver().toString());
         assertEquals("The uniqueId of the entry is different ", entry.getUniqueId(), updateEntry.getUniqueId());
         assertEquals("The msgUnitWrapperUniqueId of the entry is different ", entry.getMsgUnitWrapperUniqueId(), updateEntry.getMsgUnitWrapperUniqueId());
         assertEquals("The topic oid of the entry is different ", entry.getKeyOid(), updateEntry.getKeyOid());
         assertEquals("The topic oid of the entry is different ", entry.getStorageId().getId(), updateEntry.getStorageId().getId());
         log.info("SUCCESS: MsgQueueUpdateEntry: Persistent fields are read as expected");

         MsgUnit retMsgUnit = null;
         try {
            retMsgUnit = updateEntry.getMsgUnit();
         }
         catch (Throwable e) {  // Should not happen for RAM queue
            log.severe("Lookup failed, probably engine.Global has no Requestbroker, wi ignore the problem: " + e.getMessage());
            e.printStackTrace();
            return;
         }
         MsgQosData retMsgQosData = updateEntry.getMsgQosData();

         log.fine("Received" + retMsgQosData.toXml());

         // check message unit:
         assertEquals("The key of the message unit is different ", key.getOid(), retMsgUnit.getKeyData().getOid());
         assertEquals("The content of the message unit is different ", new String(retMsgUnit.getContent()), new String(content));
         //assertEquals("The qos of the message unit is different ", retMsgUnit.getQosData().isPersistent(), publishQosServer.isPersistent());
         //assertEquals("The qos of the message unit is different OLD="+oldXml+" NEW="+newXml, oldXml, newXml);

         assertEquals("msgQosData check failure: getSubscriptionId      ", msgQosData.getSubscriptionId(), retMsgQosData.getSubscriptionId());
//         assertEquals("msgQosData check failure: getPersistent             ", msgQosData.getPersistent(), retMsgQosData.getPersistent());
View Full Code Here

         //msgQosData.dirtyRead(null);//NodeId
         msgQosData.setPriority(PriorityEnum.LOW4_PRIORITY);
         msgQosData.setFromPersistenceStore(true);
         msgQosData.setLifeTime(4000L);
         msgQosData.setRemainingLifeStatic(6000L);
         MsgUnit msgUnit  = new MsgUnit(key.toXml(), content, msgQosData.toXml());

         log.fine("Testing" + msgQosData.toXml());

         org.xmlBlaster.engine.ServerScope global = new org.xmlBlaster.engine.ServerScope();
         MsgUnitWrapper msgWrapper = new MsgUnitWrapper(glob, msgUnit, queue.getStorageId());
         MsgQueueHistoryEntry entry = new MsgQueueHistoryEntry(global, msgWrapper, queue.getStorageId());

         queue.put(entry, false);
         I_QueueEntry returnEntry = queue.peek();

         boolean isHistory = (returnEntry instanceof MsgQueueHistoryEntry);
         assertTrue("historyEntry: the return value is not an update ", isHistory);
        
         MsgQueueHistoryEntry historyEntry = (MsgQueueHistoryEntry)returnEntry;

         assertEquals("The priority of the entry is different ", entry.getPriority(), historyEntry.getPriority());
         assertEquals("The persistent of the entry is different ", entry.isPersistent(), historyEntry.isPersistent());
         // The history queue is s LIFO, we have inverted the unique key
         assertEquals("The uniqueId of the entry is different ", entry.getUniqueId(), historyEntry.getUniqueId());
         assertEquals("The msgUnitWrapperUniqueId of the entry is different ", entry.getMsgUnitWrapperUniqueId(), historyEntry.getMsgUnitWrapperUniqueId());
         assertEquals("The topic oid of the entry is different ", entry.getKeyOid(), historyEntry.getKeyOid());
         assertEquals("The topic oid of the entry is different ", entry.getStorageId().getId(), historyEntry.getStorageId().getId());
         log.info("Persistent fields are read as expected");

         MsgUnit retMsgUnit = null;
         try {
            retMsgUnit = historyEntry.getMsgUnit();
         }
         catch (Throwable e) {  // Should not happen for RAM queue
            log.severe("Lookup failed, probably engine.Global has no Requestbroker, wi ignore the problem: " + e.getMessage());
            e.printStackTrace();
            return;
         }
         MsgQosData retMsgQosData = historyEntry.getMsgQosData();

         log.fine("Received" + retMsgQosData.toXml());

         // check message unit:
         assertEquals("The key of the message unit is different ", key.getOid(), retMsgUnit.getKeyData().getOid());
         assertEquals("The content of the message unit is different ", new String(retMsgUnit.getContent()), new String(content));
         //oldXml = oldXml.substring(oldXml.indexOf("remainingLife=");
         //String newXml = retMsgUnit.getQosData().toXml().trim();  TODO: strip remaining life first
         //assertEquals("The qos of the message unit is different OLD="+oldXml+" NEW="+newXml, oldXml, newXml); TODO

         assertEquals("msgQosData check failure: getSubscriptionId      ", msgQosData.getSubscriptionId(), retMsgQosData.getSubscriptionId());
View Full Code Here

                      "   </TestUnSub-AGENT>" +
                      "</key>";
      senderContent = "Yeahh, i'm the new content";
      PublishReturnQos publishReturnQos = null;
      try {
         MsgUnit msgUnit = new MsgUnit(xmlKey, senderContent.getBytes(), "<qos></qos>");
         publishReturnQos = senderConnection.publish(msgUnit);
         publishOid = publishReturnQos.getKeyOid();
         log.info("Success: Publishing done, returned oid=" + publishOid);
      } catch(XmlBlasterException e) {
         log.warning("XmlBlasterException: " + e.getMessage());
View Full Code Here

            PublishQos pq = new PublishQos(globSnd);
            Destination dest = new Destination(globSnd, new SessionName(globSnd, sessionNameRcv));
            pq.addDestination(dest);
            pq.setSubscribable(false);
            byte[] content = "Hello".getBytes();
            MsgUnit msgUnit = new MsgUnit(pk, content, pq);
            PublishReturnQos prq = conSnd.publish(msgUnit);
            log.info("Got status='" + prq.getState() + "' rcvTimestamp=" + prq.getRcvTimestamp().toString() +
                         " for published message '" + prq.getKeyOid() + "'");
            assertEquals("", 1, this.updateInterceptorRcv.waitOnUpdate(1000L, oid, Constants.STATE_OK));
            assertEquals("", secretCbSessionId, this.updateInterceptorRcv.getMsg(oid, Constants.STATE_OK).getCbSessionId());
            assertEquals("", 0, this.updateInterceptorSnd.waitOnUpdate(1000L, oid, Constants.STATE_OK));
           
            this.updateInterceptorRcv.clear();
            this.updateInterceptorSnd.clear();
         }

         {
            log.info("============ STEP 5: Publish PtP message which IS subscribable");
            PublishKey pk = new PublishKey(globSnd, oid, "text/xml", "1.0");
            PublishQos pq = new PublishQos(globSnd);
            Destination dest = new Destination(globSnd, new SessionName(globSnd, sessionNameRcv));
            pq.addDestination(dest);
            pq.setSubscribable(true);
            byte[] content = "Hello".getBytes();
            MsgUnit msgUnit = new MsgUnit(pk, content, pq);
            PublishReturnQos prq = conSnd.publish(msgUnit);
            log.info("Got status='" + prq.getState() + "' rcvTimestamp=" + prq.getRcvTimestamp().toString() +
                         " for published message '" + prq.getKeyOid() + "'");

            assertEquals("", 1, this.updateInterceptorRcv.waitOnUpdate(1000L, oid, Constants.STATE_OK));
View Full Code Here

      log.info("*****Publishing messages ...");

      try {
         PublishKey pk = new PublishKey(glob, "command-navigation", "text/plain", "1.0");
         PublishQos pq = new PublishQos(glob);
         MsgUnit msgUnit = new MsgUnit(pk.toXml(), "Hi".getBytes(), pq.toXml());
         con1.publish(msgUnit);
         log.info("Published message '" + pk.getOid() + "'");

         pk = new PublishKey(glob, "command-radar-1", "text/plain", "1.0");
         pq = new PublishQos(glob);
         msgUnit = new MsgUnit(pk.toXml(), "Hi".getBytes(), pq.toXml());
         con1.publish(msgUnit);
         log.info("Published message '" + pk.getOid() + "'");

         pk = new PublishKey(glob, "dummyTestSubXPathMany", "text/plain", "1.0");
         pq = new PublishQos(glob);
         msgUnit = new MsgUnit(pk.toXml(), "Hi".getBytes(), pq.toXml());
         con1.publish(msgUnit);
         log.info("Published message '" + pk.getOid() + "'");
      }
      catch (XmlBlasterException e) {
         fail("doPublish failed: " + e.toString());
View Full Code Here

         try {
            conn = factory.getConnection();
            String c = "<content>"+i+"</content>";
            String k = "<key oid='"+i+"' contentMime='text/xml'><TestLocalProtocol-AGENT id='"+i+"' type='generic'/></key>";
            log.info("Key: " +k);
            conn.publish(new MsgUnit(k, c.getBytes(), null));
         } catch(XmlBlasterException e) {
            log.warning("XmlBlasterException: " + e.getMessage());
            assertTrue("publish - XmlBlasterException: " + e.getMessage(), false);
         }finally {
           
View Full Code Here

TOP

Related Classes of org.xmlBlaster.util.MsgUnit

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.