Package org.xmlBlaster.util

Examples of org.xmlBlaster.util.MsgUnit


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


            "   </route>\n" +
            "   <topic readonly='true'/>\n" +
            "</qos>\n";

         PublishQosServer publishQosServer = new PublishQosServer(glob, xml, true); // true prevents new timestamp
         MsgUnit msgUnit = new MsgUnit(publishKey.getData(), "HO".getBytes(), publishQosServer.getData());
         StorageId storageId = new StorageId(glob, "mystore", "someid");
         MsgUnitWrapper msgUnitWrapper = new MsgUnitWrapper(glob, msgUnit, storageId);

         I_EntryFactory factory = glob.getEntryFactory(); // storageId.getStrippedId()
View Full Code Here

      log.info("Creating topic " + keyOid);
      try {
         PublishKey pk = new PublishKey(glob, publishOid, "text/xml", "1.0");
         PublishQos pq = new PublishQos(glob);
         pq.setTopicProperty(topicProperty);
         MsgUnit msgUnit = new MsgUnit(pk, senderContent, pq);
         PublishReturnQos publishReturnQos = con.publish(msgUnit);
         assertEquals("Retunred oid is invalid", publishOid, publishReturnQos.getKeyOid());
         log.info("Topic oid=" + publishOid + " created: " + msgUnit.toXml());
      } catch(XmlBlasterException e) {
         log.severe("publish() XmlBlasterException: " + e.getMessage());
         assertTrue("publish - XmlBlasterException: " + e.getMessage(), false);
      }
   }
View Full Code Here

            TopicProperty topicProperty = new TopicProperty(glob);
            topicProperty.setDestroyDelay(topicDestroyDelay);
            topicProperty.setCreateDomEntry(false);
            pq.setTopicProperty(topicProperty);
         }
         MsgUnit msgUnit = new MsgUnit(pk, senderContent, pq);
         PublishReturnQos publishReturnQos = con.publish(msgUnit);
         assertEquals("Retunred oid is invalid", publishOid, publishReturnQos.getKeyOid());
         log.info("Sending of '" + senderContent + "' done, returned oid=" + publishOid + " " + msgUnit.toXml());
      } catch(XmlBlasterException e) {
         log.severe("publish() XmlBlasterException: " + e.getMessage());
         assertTrue("publish - XmlBlasterException: " + e.getMessage(), false);
      }
   }
View Full Code Here

      log.info("TEST 2: The published message does match the pattern");
      try {
         PublishQos pubQos = new PublishQos(this.glob);
         pubQos.addClientProperty("posX", 50);
         pubQos.addClientProperty("posY", 150);
         MsgUnit msgUnit = new MsgUnit(new PublishKey(this.glob, "MSG"), content, pubQos);
         con.publish(msgUnit);
      } catch(XmlBlasterException e) {
         log.warning("XmlBlasterException: " + e.getMessage());
         assertTrue("publish - XmlBlasterException: " + e.getMessage(), false);
      }

      try {
         GetQos qos = new GetQos(glob);
         qos.addAccessFilter(new AccessFilterQos(glob, "Sql92Filter", "1.0", filter));

         MsgUnit[] msgUnits = con.get("<key oid='MSG'/>", qos.toXml());
         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("XmlBlasterException: " + e.getMessage());
         assertTrue("get - XmlBlasterException: " + e.getMessage(), false);
      }


      log.info("TEST 2: The published message does NOT match the pattern");
      try {
         PublishQos pubQos = new PublishQos(this.glob);
         pubQos.addClientProperty("posX", 250);
         pubQos.addClientProperty("posY", 150);
         MsgUnit msgUnit = new MsgUnit(new PublishKey(this.glob, "MSG"), content, pubQos);
         con.publish(msgUnit);
      } catch(XmlBlasterException e) {
         log.warning("XmlBlasterException: " + e.getMessage());
         assertTrue("publish - XmlBlasterException: " + e.getMessage(), false);
      }
View Full Code Here

      filter.initialize(scope);
      String content = "SomethingFancy";
      String queryStr = "/qos";
      String qos = "<qos/>";
     
      MsgUnit msgUnit = new MsgUnit("<key oid='Hello'/>", content, qos);
      msgUnit.getQosData().setRcvTimestamp(new Timestamp());
      SessionInfo sessionInfo = null;

      PluginInfo info = new PluginInfo(glob, null, "XPathFilter", "1.0");
      info.getParameters().put(XPathFilter.MATCH_AGAINST_QOS, ""+true);
      filter.init(glob, info);
     
      {
         Query query = new Query(glob, queryStr);
         boolean ret = filter.match(sessionInfo, msgUnit, query);
         System.out.println("Match: " + ret + "\nResult: " + msgUnit.getQos());
         assertTrue(queryStr + " should match", ret);
      }

      {
         queryStr = "/a";
         Query query = new Query(glob, queryStr);
         boolean ret = filter.match(sessionInfo, msgUnit, query);
         System.out.println("Match: " + ret + "\nResult: " + msgUnit.getQos());
         assertFalse(queryStr + " shouldn't match", ret);
      }
   }
View Full Code Here

         "    <c/>" +
         "  </xsl:template>" +
         "</xsl:stylesheet>");
     
      try {
         MsgUnit msgUnit = new MsgUnit("<key oid='Hello'/>", content, qos);
         msgUnit.getQosData().setRcvTimestamp(new Timestamp());
         SessionInfo sessionInfo = null;
  
         PluginInfo info = new PluginInfo(glob, null, "XPathFilter", "1.0");
         info.getParameters().put(XPathFilter.XSL_CONTENT_TRANSFORMER_FILE_NAME, xslFile);
         filter.init(glob, info);
        
         Query query = new Query(glob, queryStr);
         boolean ret = filter.match(sessionInfo, msgUnit, query);
         System.out.println("Match: " + ret + "\nResult: " + msgUnit.getContentStr());
         assertTrue(ret);
         assertXMLEqual("<c/>", msgUnit.getContentStr());
      }
      finally {
         File f = new File(xslFile);
         f.delete();
      }
View Full Code Here

   public void testCbSessionId() {
      log.info("testCbSessionId() ...");
      try {
         con.subscribe("<key oid='testCallbackMsg'/>", null);

         publishOid = con.publish(new MsgUnit("<key oid='testCallbackMsg'/>", "Bla".getBytes(), null)).getKeyOid();

         log.info("Success: Publishing done, returned oid=" + publishOid);

         assertEquals("returned oid", "testCallbackMsg", publishOid);
         assertEquals("numReceived after publishing", 1, this.updateInterceptor.waitOnUpdate(2000L, publishOid, Constants.STATE_OK));
View Full Code Here

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

      log.info("TEST 1: Testing unfiltered message");
      String content = "1234567890";
      try {
         con.publish(new MsgUnit("<key oid='MSG'/>", content.getBytes(), null));
      } catch(XmlBlasterException e) {
         log.warning("XmlBlasterException: " + e.getMessage());
         assertTrue("publish - XmlBlasterException: " + e.getMessage(), false);
      }

      try {
         GetQos qos = new GetQos(glob);
         qos.addAccessFilter(new AccessFilterQos(glob, "ContentLenFilter", "1.0", ""+filterMessageContentBiggerAs));

         MsgUnit[] msgUnits = con.get("<key oid='MSG'/>", qos.toXml());
         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("XmlBlasterException: " + e.getMessage());
         assertTrue("get - XmlBlasterException: " + e.getMessage(), false);
      }


      log.info("TEST 2: Testing filtered message");
      content = "12345678901"; // content is too long, our plugin denies this message
      try {
         con.publish(new MsgUnit("<key oid='MSG'/>", content.getBytes(), null));
      } catch(XmlBlasterException e) {
         log.warning("XmlBlasterException: " + e.getMessage());
         assertTrue("publish - XmlBlasterException: " + e.getMessage(), false);
      }

      try {
         GetQos qos = new GetQos(glob);
         qos.addAccessFilter(new AccessFilterQos(glob, "ContentLenFilter", "1.0", ""+filterMessageContentBiggerAs));

         MsgUnit[] msgUnits = con.get("<key oid='MSG'/>", qos.toXml());
         assertTrue("Expected one returned message", msgUnits!=null);
         assertEquals("Expected no returned message", 0, msgUnits.length);
         log.info("Success: Got no message.");
      } catch(XmlBlasterException e) {
         log.warning("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));
      } catch(XmlBlasterException e) {
         log.warning("XmlBlasterException: " + e.getMessage());
         fail("publish - XmlBlasterException: " + e.getMessage());
      }
View Full Code Here

         if (changeKey != null && changeKey.length() > 0)
            key = new PublishKey(this.glob, changeKey);
         else
            key = new PublishKey(this.glob, "dbWatcherUnspecified");
         key.setContentMime("text/xml");
         MsgUnit msg = new MsgUnit(key, out, qos);
         PublishReturnQos prq = this.con.publish(msg);
         String id = (prq.getRcvTimestamp()!=null)?prq.getRcvTimestamp().toString():"queued";
         if (log.isLoggable(Level.FINE)) log.fine("Published '" + prq.getKeyOid() + "' '" + id + "'");
         return id;
      }
      if (this.eraseOnDrop && "DROP".equals(command)) {
         String oid = this.glob.getMsgKeyFactory().readObject(pk).getOid();
         EraseKey ek = new EraseKey(glob, oid);
         EraseQos eq = new EraseQos(glob);
         con.erase(ek, eq);
         log.info("Topic '" + pk + "' is erased:" + out);
         return "0";
      }
      if (this.eraseOnDelete && "DELETE".equals(command)) {
         String oid = this.glob.getMsgKeyFactory().readObject(pk).getOid();
         EraseKey ek = new EraseKey(glob, oid);
         EraseQos eq = new EraseQos(glob);
         con.erase(ek, eq);
         log.info("Topic '" + pk + "' is erased:" + out);
         return "0";
      }
      if (log.isLoggable(Level.FINER))
         log.finer("Topic '" + pk + "' is published: " + out);
      try {
         String oid = (String)attrMap.remove(ContribConstants.TOPIC_NAME); // consume it since only used to inform this method
         if (destination != null) {
            pk = this.adminKey;
         }
         if (oid != null)
            pk = "<key oid='" + oid + "'/>";
         MsgUnit msgUnit = new MsgUnit(pk, out, this.publishQos);
         String tmp = msgUnit.getKeyData().getContentMime();
         // FIXME pass this in the map and set only if explicitly set in the map
         if (tmp == null || tmp.equals("text/plain")) {
            msgUnit.getKeyData().setContentMime("text/xml");
         }
         if (destination != null)
            ((MsgQosData)msgUnit.getQosData()).addDestination(destination);
         // to force to fill the client properties map !!
         ClientPropertiesInfo tmpInfo = new ClientPropertiesInfo(attrMap);
         new ClientPropertiesInfo(msgUnit.getQosData().getClientProperties(), tmpInfo);
         addStringPropToQos(attrMap, (MsgQosData)msgUnit.getQosData());

         PublishReturnQos prq = this.con.publish(msgUnit);
         String id = (prq.getRcvTimestamp()!=null)?prq.getRcvTimestamp().toString():"queued";
         if (log.isLoggable(Level.FINE))
            log.fine("Published '" + prq.getKeyOid() + "' '" + id + "'");
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.