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);