Package org.xmlBlaster.util

Examples of org.xmlBlaster.util.MsgUnitRaw


            msgInfo.setRequestId("7711");
            msgInfo.setMethodName(MethodName.PUBLISH);
            msgInfo.setSecretSessionId("oxf6hZs");
            msgInfo.setChecksum(false);
            msgInfo.setCompressed(false);
            MsgUnitRaw msg = new MsgUnitRaw("<key oid='hello'/>", "Hello world"
                  .getBytes(), "<qos></qos>");
            msgInfo.addMessage(msg);

            rawMsg = msgInfo.createRawMsg(className);
            String send = msgInfo.toLiteral();
            System.out.println(testName + ": Created and ready to send: \n|"
                  + send + "|");
         } catch (XmlBlasterException e) {
            System.out.println(e.getMessage());
         }
         {
            ByteArrayInputStream in = new ByteArrayInputStream(rawMsg);
            I_MsgInfoParser parser = MsgInfoParserFactory.instance()
                  .getMsgInfoParser(glob, null, className, null);
            MsgInfo msgInfo = parser.parse(in)[0];
            // System.out.println("\nReceived: \n" + msgInfo.dump());
            String literal = msgInfo.toLiteral();
            System.out.println("Received: \n|" + literal + "|");
            if (parser.toLiteral(rawMsg).equals(literal))
               System.out.println(testName + ": SUCCESS");
            else
               System.out.println(testName + ": FAILURE");
         }

         testName = "Testing many qos/key/content";
         System.out.println("\n----------------------\n" + testName);
         try {
            MsgInfo msgInfo = new MsgInfo(glob);
            msgInfo.setMsgInfoParser(className);
            msgInfo.setType(MsgInfo.INVOKE_BYTE);
            msgInfo.setRequestId("7711");
            msgInfo.setMethodName(MethodName.PUBLISH_ARR);
            msgInfo.setSecretSessionId("oxf6hZs");
            msgInfo.setChecksum(false);
            msgInfo.setCompressed(false);
            msgInfo.addMessage(new MsgUnitRaw("<key oid='x1'/>", "Hello1"
                  .getBytes(), "<qos/>"));
            msgInfo.addMessage(new MsgUnitRaw("<key oid='x2'/>", "Hello2"
                  .getBytes(), "<qos/>"));
            // msgInfo.addMessage(new MsgUnitRaw("<key oid='x3'/>",
            // "Hello3".getBytes(), "<qos/>"));
            // msgInfo.addMessage(new MsgUnitRaw("<key oid='x4'/>",
            // "Hello4".getBytes(), "<qos/>"));

            rawMsg = msgInfo.createRawMsg();
            String send = msgInfo.toLiteral();
            System.out.println(testName + ": Created and ready to send: \n|"
                  + send + "|");
         } catch (XmlBlasterException e) {
            System.out.println(e.getMessage());
         }
         {
            MsgInfo msgInfo = MsgInfo.parse(glob, progressListener,
                  new ByteArrayInputStream(rawMsg), className, null)[0];
            // System.out.println("\nReceived: \n" + msgInfo.dump());
            String receive = msgInfo.toLiteral();
            System.out.println("Received: \n|" + receive + "|");
            if (msgInfo.getMsgInfoParser(className, null).toLiteral(rawMsg).equals(
                  receive))
               System.out.println(testName + ": SUCCESS");
            else
               System.out.println(testName + ": FAILURE");
         }

         testName = "Testing qos/key";
         System.out.println("\n----------------------\n" + testName);
         {
            MsgInfo msgInfo = new MsgInfo(glob);
            msgInfo.setMsgInfoParser(className);
            msgInfo.setType(MsgInfo.INVOKE_BYTE);
            msgInfo.setRequestId("7711");
            msgInfo.setMethodName(MethodName.GET);
            msgInfo.setSecretSessionId("oxf6hZs");
            msgInfo.setChecksum(false);
            msgInfo.setCompressed(false);
            msgInfo.addKeyAndQos("<key oid='ooo'></key>", "<qos></qos>");

            rawMsg = msgInfo.createRawMsg();
            String send = msgInfo.toLiteral();
            System.out.println(testName + ": Created and ready to send: \n|"
                  + send + "|");
         }
         {
            MsgInfo msgInfo = MsgInfo.parse(glob, progressListener, rawMsg,
                  className, null)[0];
            // System.out.println("\nReceived: \n" + msgInfo.dump());
            String receive = msgInfo.toLiteral();
            System.out.println("Received: \n|" + receive + "|");
            if (msgInfo.getMsgInfoParser(className, null).toLiteral(rawMsg).equals(
                  receive))
               System.out.println(testName + ": SUCCESS");
            else
               System.out.println(testName + ": FAILURE");
         }

         testName = "Testing qos return";
         System.out.println("\n----------------------\n" + testName);
         {
            MsgInfo msgInfo = new MsgInfo(glob);
            msgInfo.setMsgInfoParser(className);
            msgInfo.setType(MsgInfo.RESPONSE_BYTE);
            msgInfo.setRequestId("7711");
            msgInfo.setMethodName(MethodName.PUBLISH);
            msgInfo.setSecretSessionId("oxf6hZs");
            msgInfo.setChecksum(false);
            msgInfo.setCompressed(false);
            msgInfo.addMessage("<qos></qos>");

            rawMsg = msgInfo.createRawMsg();
            String send = msgInfo.toLiteral();
            System.out.println(testName + ": Created and ready to send: \n|"
                  + send + "|");
         }
         {
            MsgInfo msgInfo = MsgInfo.parse(glob, progressListener, rawMsg,
                  className, null)[0];
            if (msgInfo.getMessageArr().length != 1) {
               System.out.println(testName + ": FAILURE numMsg="
                     + msgInfo.getMessageArr().length);
            }
            // System.out.println("\nReceived: \n" + msgInfo.dump());
            String receive = msgInfo.toLiteral();
            System.out.println("Received: \n|" + receive + "|");
            if (msgInfo.getMsgInfoParser(className, null).toLiteral(rawMsg).equals(
                  receive))
               System.out.println(testName + ": SUCCESS");
            else
               System.out.println(testName + ": FAILURE rawMsg sent="
                     + msgInfo.getMsgInfoParser(className, null).toLiteral(rawMsg));
         }

         testName = "Testing nothing";
         System.out.println("\n----------------------\n" + testName);
         {
            MsgInfo msgInfo = new MsgInfo(glob);
            msgInfo.setMsgInfoParser(className);
            msgInfo.setType(MsgInfo.INVOKE_BYTE);
            msgInfo.setRequestId("7711");
            msgInfo.setMethodName(MethodName.GET);
            msgInfo.setSecretSessionId("oxf6hZs");
            msgInfo.setChecksum(false);
            msgInfo.setCompressed(false);

            rawMsg = msgInfo.createRawMsg();
            String send = msgInfo.getMsgInfoParser(className, null).toLiteral(rawMsg);
            System.out.println(testName + ": Created and ready to send: \n|"
                  + send + "|");
         }
         {
            MsgInfo msgInfo = MsgInfo.parse(glob, progressListener, rawMsg,
                  className, null)[0];
            if (msgInfo.getMessageArr().length > 0) {
               System.out.println(testName + ": FAILURE msgLength="
                     + msgInfo.getMessageArr().length + " dump="
                     + msgInfo.getMessageArr()[0].toXml(""));
            } else {
               // System.out.println("\nReceived: \n" + msgInfo.dump());
               String receive = msgInfo.toLiteral();
               System.out.println("Received: \n|" + receive + "|");
               if (msgInfo.getMsgInfoParser(className, null).toLiteral(rawMsg)
                     .equals(receive))
                  System.out.println(testName + ": SUCCESS");
               else
                  System.out.println(testName + ": FAILURE");
            }
         }

         if (className.equals(XbfParser.class.getName())) {
            testName = "Testing really nothing (ONLY WORKS WITH XfbParser as no valid XML)";
            System.out.println("\n----------------------\n" + testName);
            {
               rawMsg = "        10".getBytes();
               String send = MsgInfoParserFactory.instance().getMsgInfoParser(
                     glob, progressListener, XbfParser.class.getName(), null).toLiteral(
                     rawMsg);
               System.out.println(testName + ": Created and ready to send: \n|"
                     + send + "|");
            }
            {
               MsgInfo msgInfo = MsgInfo.parse(glob, progressListener, rawMsg,
                     className, null)[0];
               msgInfo.setSecretSessionId(null);
               if (msgInfo.getMessageArr().length > 0) {
                  System.out.println(testName + ": FAILURE");
               } else {
                  // System.out.println("\nReceived: \n" + msgInfo.dump());
                  String receive = msgInfo.getMsgInfoParser(className, null).toLiteral(
                        msgInfo.createRawMsg());
                  System.out.println("Received: \n|" + receive + "|");
                  if ("        25**I**11*ping***".equals(receive))
                     System.out.println(testName + ": SUCCESS");
                  else
                     System.out.println(testName + ": FAILURE");
               }
            }
         }

         testName = "Testing XmlBlasterException";
         System.out.println("\n----------------------\n" + testName);
         {
            MsgInfo msgInfo = new MsgInfo(glob);
            msgInfo.setMsgInfoParser(className);
            msgInfo.setType(MsgInfo.EXCEPTION_BYTE);
            msgInfo.setRequestId("7711");
            msgInfo.setMethodName(MethodName.PUBLISH);
            msgInfo.setSecretSessionId("oxf6hZs");
            msgInfo.setChecksum(false);
            msgInfo.setCompressed(false);
            XmlBlasterException ex = new XmlBlasterException(glob,
                  ErrorCode.INTERNAL_UNKNOWN, "QueueOverflow",
                  "The destination queue is full");
            msgInfo.addException(ex);

            rawMsg = msgInfo.createRawMsg();
            String send = msgInfo.getMsgInfoParser(className, null).toLiteral(rawMsg);
            System.out.println(testName + ": Created and ready to send: \n|"
                  + send + "|");
         }
         {
            MsgInfo msgInfo = MsgInfo.parse(glob, progressListener, rawMsg,
                  className, null)[0];
            // System.out.println("\nReceived: \n" + msgInfo.dump());
            String receive = msgInfo.toLiteral();
            System.out.println("Received: \n|" + receive + "|");
            if (msgInfo.getMsgInfoParser(className, null).toLiteral(rawMsg).equals(
                  receive))
               System.out.println(testName + ": SUCCESS");
            else
               System.out.println(testName + ": FAILURE");
         }

         testName = "Testing qos/key/content return value";
         System.out.println("\n----------------------\n" + testName);
         try {
            MsgInfo msgInfo = new MsgInfo(glob);
            msgInfo.setMsgInfoParser(className);
            msgInfo.setType(MsgInfo.RESPONSE_BYTE);
            msgInfo.setRequestId("7711");
            msgInfo.setMethodName(MethodName.GET);
            // msgInfo.setSecretSessionId("oxf6hZs");
            msgInfo.setChecksum(false);
            msgInfo.setCompressed(false);
            MsgUnitRaw msg = new MsgUnitRaw("<key oid='hello'/>",
                  "Hello world response".getBytes(), "<qos></qos>");
            msgInfo.addMessage(msg);

            rawMsg = msgInfo.createRawMsg();
            String send = msgInfo.getMsgInfoParser(className, null).toLiteral(rawMsg);
View Full Code Here


      String qos = null;
      for (int ii=0; ii<Integer.MAX_VALUE; ii++) {
         qos = toString(buf);
         if (buf.offset >= buf.buf.length) {
            if (qos.length() > 0) {
               MsgUnitRaw msgUnit = new MsgUnitRaw(null, (byte[])null, qos);
               msgInfo.addMessage(msgUnit);
            }
            break;
         }

         String key = toString(buf);
         if (buf.offset >= buf.buf.length) {
            MsgUnitRaw msgUnit = new MsgUnitRaw(key, (byte[])null, qos);
            msgInfo.addMessage(msgUnit);
            break;
         }

         if (log.isLoggable(Level.FINE)) log.fine("Getting messageUnit #" + ii);
         MsgUnitRaw msgUnit = new MsgUnitRaw(key, toByte(buf), qos);
         msgInfo.addMessage(msgUnit);

         if (buf.offset >= buf.buf.length) break;
      }
View Full Code Here

         if (lenUnzipped > 0)
            out.write(new String(""+lenUnzipped).getBytes());
         out.write(NULL_BYTE);

         for (int ii=0; ii<msgInfo.getMessages().size(); ii++) {
            MsgUnitRaw unit = (MsgUnitRaw)msgInfo.getMessages().elementAt(ii);
            out.write(unit.getQos().getBytes());
            out.write(NULL_BYTE);
            out.write(unit.getKey().getBytes());
            out.write(NULL_BYTE);
            byte[] tmp = unit.getContent();
            out.write((""+tmp.length).getBytes());
            out.write(NULL_BYTE);
            out.write(tmp);
         }
View Full Code Here

         log.severe("Sending message arrays with '" + methodName.toString() + "' is not implemented");
         return false;
      }
     
     
      MsgUnitRaw msgUnitRaw = new MsgUnitRaw(super.key.toString(),
            super.contentData, super.qos.toString());
      msgInfo.setMethodName(methodName);
      msgInfo.setSecretSessionId(sessionId);
      msgInfo.setRequestId(requestId);
      msgInfo.setType(type);
View Full Code Here

            parser.init(glob, null, null);
            MsgInfo msgInfo = new MsgInfo(glob, MsgInfo.RESPONSE_BYTE, "12",
                  MethodName.PING, "secret", null);
            byte[] content = null;
            String qos = null;
            MsgUnitRaw msg = new MsgUnitRaw(null, content, qos);
            msgInfo.addMessage(msg);
            byte[] raw = parser.createRawMsg(msgInfo);
            System.out.println(parser.toLiteral(raw));

            PipedInputStream in = new PipedInputStream();
            PipedOutputStream out = new PipedOutputStream(in);
            out.write(raw);
            out.flush();
            out.close();
            MsgInfo msgInfoNew = parser.parse(in)[0];
            byte[] rawNew = parser.createRawMsg(msgInfoNew);
            System.out.println("Parsed and dumped again:" + parser.toLiteral(rawNew));
         }
         {
            System.out.println("TEST1 SHOULD FORCE BASE64");
            parser.init(glob, null, null);
            MsgInfo msgInfo = new MsgInfo(glob, MsgInfo.INVOKE_BYTE, "12",
                  MethodName.PUBLISH, "secret", null);
            byte[] content = "hello&bye]]>".getBytes();
            //content[3] = 0;
            MsgUnitRaw msg = new MsgUnitRaw("<key oid='hello'/>", content, "<qos></qos>");
            msgInfo.addMessage(msg);
            byte[] raw = parser.createRawMsg(msgInfo);
            System.out.println("Initial creation:" + parser.toLiteral(raw));

            PipedInputStream in = new PipedInputStream();
            PipedOutputStream out = new PipedOutputStream(in);
            out.write(raw);
            out.flush();
            out.close();
            MsgInfo msgInfoNew = parser.parse(in)[0];
            byte[] rawNew = parser.createRawMsg(msgInfoNew);
            System.out.println("Parsed and dumped again:" + parser.toLiteral(rawNew));
         }
         {
            System.out.println("TEST2 SHOULD KEEP LITERAL STRING");
            parser.init(glob, null, null);
            MsgInfo msgInfo = new MsgInfo(glob, MsgInfo.INVOKE_BYTE, "12",
                  MethodName.PUBLISH, "secret", null);
            byte[] content = "Hello World!".getBytes();
            MsgUnitRaw msg = new MsgUnitRaw("<key oid='hello'/>", content, "<qos></qos>");
            msgInfo.addMessage(msg);
            byte[] raw = parser.createRawMsg(msgInfo);
            System.out.println("Initial creation:" + parser.toLiteral(raw));

            PipedInputStream in = new PipedInputStream();
            PipedOutputStream out = new PipedOutputStream(in);
            out.write(raw);
            out.flush();
            out.close();
            MsgInfo msgInfoNew = parser.parse(in)[0];
            byte[] rawNew = parser.createRawMsg(msgInfoNew);
            System.out.println("Parsed and dumped again:" + parser.toLiteral(rawNew));
         }
         {
            System.out.println("TEST3");
            parser.init(glob, null, null);
            MsgInfo msgInfo = new MsgInfo(glob, MsgInfo.RESPONSE_BYTE, "12",
                  MethodName.PUBLISH, "secret", null);
            byte[] content = null;
            String qos = "<qos>" +
                         "\n  <key oid='1'/>" +
                         "\n  <rcvTimestamp nanos='1131654994574000000'/>" +
                         "\n  <isPublish/>" +
                         "\n</qos>";
            MsgUnitRaw msg = new MsgUnitRaw(null, content, qos);
            msgInfo.addMessage(msg);
            byte[] raw = parser.createRawMsg(msgInfo);
            System.out.println(parser.toLiteral(raw));
         }
      } catch (Exception e) {
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.