📄 msginfo.java
字号:
Iterator it = this.bounceObjects.entrySet().iterator(); ArrayList list = new ArrayList(); while (it.hasNext()) { Map.Entry entry = (Map.Entry)it.next(); if (entry.getValue() instanceof AttachmentHolder) list.add(entry.getValue()); } return (AttachmentHolder[])list.toArray(new AttachmentHolder[list.size()]); } /** * @return Returns the value, is null if none is found */ public Object getBounceObject(String key) { if (this.bounceObjects == null || key == null) return null; return this.bounceObjects.get(key); } /** * Sets the given map. */ public void setBounceObjects(Map bounceObjects) { this.bounceObjects = bounceObjects; } /** * You can use this as a generic store to convej stuff in MsgInfo. * * @param key * The identifier of the object. * @param value * The bounceObjects to set, if null nothing happens. */ public Object setBounceObject(String key, Object value) { if (value == null) return null; if (this.bounceObjects == null) this.bounceObjects = new HashMap(); return this.bounceObjects.put(key, value); } /** * @return Returns the progressListener. */ public I_ProgressListener getProgressListener() { return this.progressListener; } /** * java org.xmlBlaster.util.xbformat.MsgInfo * java org.xmlBlaster.util.xbformat.MsgInfo org.xmlBlaster.util.xbformat.XmlScriptParser * TODO: Put into test suite with xmlunit */ public static void main(String[] args) { try { Global glob = new Global(args); I_ProgressListener progressListener = null; byte[] rawMsg = null; String testName; String className = XbfParser.class.getName(); if (args.length > 0) className = args[0]; System.out.println("\nUsing parser '" + className + "'"); testName = "Testing 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); 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); 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, 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 a QoS return value"; 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.ERASE); // msgInfo.setSecretSessionId(""); msgInfo.setChecksum(false); msgInfo.setCompressed(false); msgInfo.addMessage("<qos><state id='OK'/></qos>"); 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"); } } catch (Throwable e) { e.printStackTrace(); System.err.println(e.toString()); } } /** * Check if we got an explicit requestId or if we extracted it for example from the email-sentDate. * @return Returns the requestIdGuessed. */ public boolean isRequestIdGuessed() { return this.requestIdGuessed; } /** * @param requestIdGuessed The requestIdGuessed to set. */ public void setRequestIdGuessed(boolean requestIdGuessed) { this.requestIdGuessed = requestIdGuessed; } public I_PluginConfig getPluginConfig() { return pluginConfig; } public void setPluginConfig(I_PluginConfig pluginConfig) { this.pluginConfig = pluginConfig; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -