Package org.xmlBlaster.util

Examples of org.xmlBlaster.util.MsgUnitRaw


    *
    */
   public static MsgUnitRaw vector2MsgUnitRaw(Vector vec)
      throws XmlBlasterException
   {
      MsgUnitRaw ret = null;
      int size = vec.size();
      if (size != 3) {
         throw new XmlBlasterException(Global.instance(), ErrorCode.USER_WRONG_API_USAGE, ME, "Can't create a MessageUnit from " + size + " tokens");
      }

      try {
         Enumeration enumeration = vec.elements();
         String xmlKey = (String)enumeration.nextElement();
         Object obj = enumeration.nextElement();
         byte[] content = null;
         if (obj instanceof byte[]) {
            content = (byte[])obj;
         }
         else {
            String str = (String)obj;
            content = str.getBytes();
         }
         String qos = (String)enumeration.nextElement();
         ret = new MsgUnitRaw(xmlKey, content, qos);

      }

      catch (ClassCastException e) {
         for (int i=0; i<vec.size(); i++) {
View Full Code Here


    *
    */
   public static MsgUnitRaw objArray2MsgUnitRaw(Object[] inObj) throws XmlBlasterException {
      if (inObj == null)
         return null;
      MsgUnitRaw ret = null;
      if (inObj.length != 3) {
         throw new XmlBlasterException(Global.instance(), ErrorCode.USER_WRONG_API_USAGE, ME, "Can't create a MessageUnit from " + inObj.length + " tokens");
      }

      try {
         for (int i=0; i < inObj.length; i++) {
            String xmlKey = (String)inObj[0];
            byte[] content = null;
            if (inObj[1] instanceof byte[]) {
               content = (byte[])inObj[1];
            }
            else {
               String str = (String)inObj[1];
               content = str.getBytes();
            }
            String qos = (String)inObj[2];
            ret = new MsgUnitRaw(xmlKey, content, qos);
         }
      }

      catch (ClassCastException e) {
         for (int i=0; i<inObj.length; i++) {
View Full Code Here

      System.out.println("The Original Messages & strings: \n\n");

      try {
         for (int i=0; i < 5; i++) {
            msgs[i] = new MsgUnitRaw("<key uid='" + i + "'></key>", content, "<qos></qos>");
            strings[i] = new String("string nr. " + (i+1) );
            System.out.println(msgs[i].getKey() + " " + strings[i]);
         }

View Full Code Here

            }
         }

         // 2b. Generate dead letters if there is a raw message which we could not parse
         if (msgErrorInfo.getMsgUnitRaw() != null) {
             MsgUnitRaw msgUnitRaw = msgErrorInfo.getMsgUnitRaw();
             glob.getRequestBroker().publishDeadMessageRaw(msgErrorInfo.getSessionName(), msgUnitRaw, message, null);
         }

         // We do a auto logout if the callback is down
         if (dispatchManager == null || dispatchManager.isDead()) {
View Full Code Here

      log.info("cbSessionId=" + cbSessionId);
      String[] ret = new String[corbaMsgUnitArr.length];
      try {
         MsgUnitRaw[] msgUnitArr = OrbInstanceFactory.convert(glob, corbaMsgUnitArr);
         for (int ii=0; ii<msgUnitArr.length; ii++) {
            MsgUnitRaw msgUnit = msgUnitArr[ii];
            UpdateKey xmlKey = null;
            try {
               xmlKey = new UpdateKey(null, msgUnit.getKey());
            } catch (XmlBlasterException e) {
               log.severe(e.getMessage());
            }
            log.info("Callback invoked for " + xmlKey.toString() + " content length = " + msgUnit.getContent().length);
            log.info(new String(msgUnit.getContent()));
            ret[ii] = Constants.RET_OK; // "<qos><state id='OK'/></qos>";
         }
      }
      catch (XmlBlasterException e) {
         log.severe(e.getMessage());
View Full Code Here

                            "      <DRIVER id='FileProof' pollingFreq='10'>" +
                            "      </DRIVER>"+
                            "   </AGENT>" +
                            "</key>";
            String content = "<file><size>1024 kBytes</size><creation>1.1.2000</creation></file>";
            MsgUnitRaw msgUnit = new MsgUnitRaw(xmlKey, content.getBytes(), "<qos></qos>");
            log.fine("Publishing ...");
            stop.restart();
            try {
               String pubXml = blasterServer.publish(sessionId, msgUnit);

               // Parse the returned XML string
               PublishReturnQos q = new PublishReturnQos(glob, pubXml);
               publishOid = q.getKeyOid();
               log.info("   Returned oid=" + publishOid);
            } catch(XmlBlasterException e) {
               log.warning("XmlBlasterException: " + e.getMessage());
            }
            log.fine("Publishing done" + stop.nice());
         }


         //----------- get() the previous message OID -------
         {
            log.fine("get() using the exact oid ...");
            String xmlKey = "<key oid='" + publishOid + "' queryType='EXACT'>\n" +
                            "</key>";
            stop.restart();
            MsgUnitRaw[] msgArr = null;
            try {
               msgArr = blasterServer.get(sessionId, xmlKey, "<qos></qos>");

               log.info("Got " + msgArr.length + " messages:");
               for (int ii=0; ii<msgArr.length; ii++) {
                  System.out.println(msgArr[ii].getKey() +
                             "\n################### RETURN CONTENT: ##################\n\n" +
                              new String(msgArr[ii].getContent()) +
                             "\n\n#######################################");
               }
            } catch(XmlBlasterException e) {
               log.severe("XmlBlasterException: " + e.getMessage());
               System.exit(1);
            }
         }


         //----------- Construct a second message and publish it ---------
         {
            String xmlKey = "<?xml version='1.0' encoding='ISO-8859-1' ?>\n" +
                            "<key oid='Export-11' contentMime='text/plain'>" +
                            "<AGENT id='192.168.124.29' subId='1' type='generic'>" +
                               "<DRIVER id='ProgramExecute'>" +
                                  "<EXECUTABLE>export</EXECUTABLE>" +
                                  "<FILE>out.txt</FILE>" +
                               "</DRIVER>" +
                            "</AGENT>" +
                            "</key>";
            String content = "Export program started";
            MsgUnitRaw msgUnit = new MsgUnitRaw(xmlKey, content.getBytes(), "<qos></qos>");
            log.fine("Publishing ...");
            stop.restart();
            try {
               String pubXml = blasterServer.publish(sessionId, msgUnit);
View Full Code Here

            }
            else {
               mu = new MsgUnit(mu, null, null, msgQosData);
            }

            MsgUnitRaw raw = new MsgUnitRaw(mu, mu.getKeyData().toXml(), mu.getContent(), mu.getQosData().toXml());
            if (address.oneway() || entry.updateOneway()) {
               if (oneways == null) oneways = new ArrayList();
               oneways.add(new Holder(entry, raw, entry.getSubscriptionId()));
            }
            else {
               if (responders == null) responders = new ArrayList();
               responders.add(new Holder(entry, raw, entry.getSubscriptionId()));
            }
         }
      }

      exportCrypt(responders, MethodName.UPDATE);
      exportCrypt(oneways, MethodName.UPDATE_ONEWAY);

      if (oneways != null) {
         MsgUnitRaw[] raws = new MsgUnitRaw[oneways.size()];
         for (int i=0; i<oneways.size(); i++) {
            raws[i] = ((Holder)oneways.get(i)).msgUnitRaw;
         }
         cbDriver.sendUpdateOneway(raws);
         connectionsHandler.getDispatchStatistic().incrNumUpdate(oneways.size());
         if (log.isLoggable(Level.FINE)) log.fine(ME+": Success, sent " + oneways.size() + " oneway messages.");
         I_Checkpoint cp = glob.getCheckpointPlugin();
         if (cp != null) {
            for (int i=0; i<oneways.size(); i++) {
               Holder h = (Holder)oneways.get(i);
               cp.passingBy(I_Checkpoint.CP_UPDATE_ACK, (MsgUnit)h.msgUnitRaw.getMsgUnit(),
                     sessionName, null);
            }
         }
      }

      if (responders != null) {
         if (log.isLoggable(Level.FINE)) log.fine(ME+": Before update " + responders.size() + " acknowledged messages ...");
         MsgUnitRaw[] raws = new MsgUnitRaw[responders.size()];
         for (int i=0; i<responders.size(); i++) {
            raws[i] = ((Holder)responders.get(i)).msgUnitRaw;
         }
         String[] rawReturnVal = null;
         try {
            rawReturnVal = cbDriver.sendUpdate(raws);
         }
         catch (Throwable t) {
            // http://www.xmlblaster.org/xmlBlaster/doc/requirements/interface.update.html#exception
            XmlBlasterException ex = (t instanceof XmlBlasterException) ? (XmlBlasterException)t :
               new XmlBlasterException(glob, ErrorCode.USER_UPDATE_INTERNALERROR, ME, "Callback failed", t);
            if (!ex.isServerSide()) { // Transform remote exceptions must be of type user.* or communication.*
               if (!ex.isUser() && !ex.isCommunication())
                  ex = new XmlBlasterException(glob, ErrorCode.USER_UPDATE_INTERNALERROR, ME, "Callback failed", ex);
            }
            throw ex;
         }
         connectionsHandler.getDispatchStatistic().incrNumUpdate(raws.length);
         if (log.isLoggable(Level.FINE)) log.fine(ME+": Success, sent " + raws.length + " acknowledged messages, return value #1 is '" + rawReturnVal[0] + "'");

         I_Checkpoint cp = glob.getCheckpointPlugin();
         if (cp != null) {
            for (int i=0; i<raws.length; i++) {
               cp.passingBy(I_Checkpoint.CP_UPDATE_ACK, (MsgUnit)raws[i].getMsgUnit(),
                     sessionName, null);
            }
         }

         // this is done since the client could send one single bulk acknowledge
         if (rawReturnVal != null && rawReturnVal.length == 1 && raws.length > 1) {
            String bulkReturnValue = rawReturnVal[0];
            log.fine("Reconstructing return values of a bulk acknowledge '" + bulkReturnValue + "'");
            rawReturnVal = new String[raws.length];
            for (int i=0; i < rawReturnVal.length; i++)
               rawReturnVal[i] = bulkReturnValue;
         }

         if (rawReturnVal != null && rawReturnVal.length == raws.length) {
            I_MsgSecurityInterceptor securityInterceptor = connectionsHandler.getDispatchManager().getMsgSecurityInterceptor();
            for (int i=0; i<rawReturnVal.length; i++) {
               MsgQueueUpdateEntry entry = ((Holder)responders.get(i)).msgQueueUpdateEntry;
               if (!entry.wantReturnObj())
                  continue;

               if (securityInterceptor != null) {
                  // decrypt ...
                  CryptDataHolder dataHolder = new CryptDataHolder(MethodName.UPDATE,
                        new MsgUnitRaw(null, (byte[])null, rawReturnVal[i]));
                  dataHolder.setReturnValue(true);
                  rawReturnVal[i] = securityInterceptor.importMessage(dataHolder).getQos();
               }

               // create object
View Full Code Here

   public String getUpdateException(String ex) throws XmlBlasterException {
      return getLiteral(ex, MethodName.UPDATE, MsgInfo.EXCEPTION_BYTE);
   }
  
   private String getLiteral(String qos, MethodName methodName, byte typeByte) throws XmlBlasterException {
      MsgUnitRaw[] msgArr = { new MsgUnitRaw(null, (byte[])null, qos) };
      return getLiteral(msgArr, methodName, typeByte);
   }
View Full Code Here

      MsgUnitRaw[] msgArr = { new MsgUnitRaw(null, (byte[])null, qos) };
      return getLiteral(msgArr, methodName, typeByte);
   }

   private String getLiteral(String key, String qos, MethodName methodName) throws XmlBlasterException {
      MsgUnitRaw[] msgArr = { new MsgUnitRaw(key, (byte[])null, qos) };
      return getLiteral(msgArr, methodName, MsgInfo.INVOKE_BYTE);
   }
View Full Code Here

                      String updateQosLiteral) throws XmlBlasterException
   {
      // import (decrypt) message
      I_ClientPlugin secPlgn = getSecurityPlugin();
      if (secPlgn != null) {
         MsgUnitRaw in = new MsgUnitRaw(updateKeyLiteral, content, updateQosLiteral);
         CryptDataHolder dataHolder = new CryptDataHolder(MethodName.UPDATE, in, null);
         MsgUnitRaw msg = secPlgn.importMessage(dataHolder);
         updateKeyLiteral = msg.getKey();
         content = msg.getContent();
         updateQosLiteral = msg.getQos();
      }

      // parse XML key and QoS
      UpdateKey updateKey = null;
      UpdateQos updateQos = null;
      try {
         updateKey = new UpdateKey(glob, updateKeyLiteral);
         //updateKey.init(updateKeyLiteral); // does the parsing
         updateQos = new UpdateQos(glob, updateQosLiteral); // does the parsing
      }
      catch (XmlBlasterException e) {
         log.severe("Parsing error: " + e.toString());
         throw new XmlBlasterException(glob, ErrorCode.USER_UPDATE_ILLEGALARGUMENT, ME+".update", "Parsing error", e);
      }

      // invoke client code
      try {
         // Now we know all about the received message, dump it or do some checks
         /*
         if (log.isLoggable(Level.FINEST)) log.dump(ME+".UpdateKey", "\n" + updateKey.toXml());
         if (log.isLoggable(Level.FINEST)) log.dump(ME+".content", "\n" + new String(content));
         if (log.isLoggable(Level.FINEST)) log.dump(ME+".UpdateQos", "\n" + updateQos.toXml());
         */
         if (log.isLoggable(Level.FINE)) log.fine("Received message [" + updateKey.getOid() + "] from publisher " + updateQos.getSender());

         String ret = update(cbSessionId, updateKey, content, updateQos);

         DispatchStatistic statistic = getDispatchStatistic();
         if (statistic != null) statistic.incrNumUpdate(1);
        
         // export (encrypt) return value
         if (secPlgn != null) {
            MsgUnitRaw msg = new MsgUnitRaw(null, (byte[])null, ret);
            CryptDataHolder dataHolder = new CryptDataHolder(MethodName.UPDATE, msg, null);
            dataHolder.setReturnValue(true);
            ret = secPlgn.exportMessage(dataHolder).getQos();
         }

View Full Code Here

TOP

Related Classes of org.xmlBlaster.util.MsgUnitRaw

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.