⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlrpcconnection.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
      }   }   /**    * Publish multiple messages in one sweep.    * <p />    * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/interface.publish.html">The interface.publish requirement</a>    */   public final String[] publishArr(MsgUnitRaw[] msgUnitArr)      throws XmlBlasterException   {      if (log.isLoggable(Level.FINER)) log.finer("Entering publishArr: id=" + sessionId);      if (msgUnitArr == null) {         log.severe("The argument of method publishArr() are invalid");         throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, ME,                                       "The argument of method publishArr() are invalid");      }      try {         Vector msgUnitArrWrap = ProtoConverter.messageUnitArray2Vector(msgUnitArr);         // prepare the argument list (as a Vector)         Vector args = new Vector();         args.addElement(sessionId);         args.addElement(msgUnitArrWrap);         Vector returnVectorWrap = (Vector)getXmlRpcClient().execute("xmlBlaster.publishArr", args);      // re-extractXmlBlasterException the resuts to String[]         return ProtoConverter.vector2StringArray(returnVectorWrap);      }      catch (ClassCastException e) {         log.severe("not a valid String[]: " + e.toString());         throw new XmlBlasterException(glob, ErrorCode.INTERNAL_UNKNOWN, ME+".publishArr", "Not a valid String[]", e);      }      catch (IOException e) {         throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION, ME, "publishArr", e);      }      catch (XmlRpcException e) {         throw extractXmlBlasterException(glob, e);      }   }   /**    * Publish multiple messages in one sweep.    * <p />    * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/interface.publish.html">The interface.publish requirement</a>    */   public final void publishOneway(MsgUnitRaw[] msgUnitArr)      throws XmlBlasterException   {      if (log.isLoggable(Level.FINER)) log.finer("Entering publishOneway: id=" + sessionId);      if (msgUnitArr == null) {         log.severe("The argument of method publishOneway() are invalid");         throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, ME,                                       "The argument of method publishOneway() are invalid");      }      try {         Vector msgUnitArrWrap = ProtoConverter.messageUnitArray2Vector(msgUnitArr);         Vector args = new Vector();         args.addElement(sessionId);         args.addElement(msgUnitArrWrap);         getXmlRpcClient().execute("xmlBlaster.publishOneway", args);      }      catch (ClassCastException e) {         log.severe(e.toString());         e.printStackTrace();         throw XmlBlasterException.convert(glob, ME, "publishOneway Class Cast Exception", e);      }      catch (IOException e) {         throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION, ME, "publishOneway", e);      }      catch (XmlRpcException e) {         throw extractXmlBlasterException(glob, e);      }   }   /*    * Delete messages.    * <p />   public final String[] erase (XmlKey xmlKey, EraseQosServer eraseQoS)      throws XmlBlasterException   {      String xmlKey_literal = xmlKey.toXml();      String eraseQoS_literal = eraseQoS.toXml();      return erase(xmlKey_literal, eraseQoS_literal);   }    */   /**    * Delete messages.    * <p />    * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/interface.erase.html">The interface.erase requirement</a>    */   public final String[] erase(String xmlKey_literal, String qos_literal)      throws XmlBlasterException   {      if (log.isLoggable(Level.FINER)) log.finer("Entering erase() id=" + sessionId);      try {         // prepare the argument list (as a Vector) for xml-rpc         Vector args = new Vector();         args.addElement(sessionId);         args.addElement(xmlKey_literal);         args.addElement(qos_literal);         Vector vec = (Vector)getXmlRpcClient().execute("xmlBlaster.erase", args);         return ProtoConverter.vector2StringArray(vec);      }      catch (ClassCastException e) {         log.severe("not a valid Vector: " + e.toString());         throw XmlBlasterException.convert(glob, ME, "erase Class Cast Exception", e);      }      catch (IOException e1) {         log.severe("IO exception: " + e1.toString() + " sessionId=" + this.sessionId);         throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION, ME, "erase", e1);      }      catch (XmlRpcException e) {         throw extractXmlBlasterException(glob, e);      }   }   /*    * Synchronous access a message.    * <p />   public final MsgUnitRaw[] get (XmlKey xmlKey, GetQosServer getQoS)      throws XmlBlasterException   {      String xmlKey_literal = xmlKey.toXml();      String getQoS_literal = getQoS.toXml();      return get(xmlKey_literal, getQoS_literal);   }    */   /**    * Synchronous access a message.    * <p />    * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/interface.get.html">The interface.get requirement</a>    */   public final MsgUnitRaw[] get(String xmlKey_literal,                                  String qos_literal) throws XmlBlasterException   {      if (log.isLoggable(Level.FINER)) log.finer("Entering get() xmlKey=\n" + xmlKey_literal + ") ...");      try {         Vector args = new Vector();         args.addElement(sessionId);         args.addElement(xmlKey_literal);         args.addElement(qos_literal);         Vector retVector = (Vector)getXmlRpcClient().execute("xmlBlaster.get", args);         // extractXmlBlasterException the vector of vectors to a MsgUnitRaw[] type         return ProtoConverter.vector2MsgUnitRawArray(retVector);      }      catch (ClassCastException e) {         log.severe("not a valid Vector: " + e.toString());         throw XmlBlasterException.convert(glob, ME, "get Class Cast Exception", e);      }      catch (IOException e1) {         log.severe("IO exception: " + e1.toString());         throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION, ME, "get", e1);      }      catch (XmlRpcException e) {         throw extractXmlBlasterException(glob, e);      }   }   public static XmlBlasterException extractXmlBlasterException(Global glob, XmlRpcException e) {      return extractXmlBlasterException(glob, e, ErrorCode.INTERNAL_UNKNOWN);   }      /**    * Helma XmlRpc does in XmlRpcServer.java:314 an exception.toString() which is sent back to the client.     * <br />    * xml-rpc exception: org.apache.xmlrpc.XmlRpcException: java.lang.Exception: errorCode=resource.unavailable message=The key 'NotExistingMessage' is not available.    * @param glob    * @param e The original exception    * @param fallback The error code to use if e is unparsable    */   public static XmlBlasterException extractXmlBlasterException(Global glob, XmlRpcException e, ErrorCode fallback) {      XmlBlasterException ex = XmlBlasterException.parseToString(glob, e.toString(), fallback);      ex.isServerSide(true);      return ex;   }   /**    * Check server.    * @see <a href="http://www.xmlBlaster.org/xmlBlaster/src/java/org/xmlBlaster/protocol/corba/xmlBlaster.idl" target="others">CORBA xmlBlaster.idl</a>    */   public String ping(String str) throws XmlBlasterException   {      try {         Vector args = new Vector();         args.addElement("");         return (String)getXmlRpcClient().execute("xmlBlaster.ping", args);      }      catch (ClassCastException e) {         log.severe(e.toString());         e.printStackTrace();         throw XmlBlasterException.convert(glob, ME, "ping Class Cast Exception", e);      }      catch (IOException e) {         throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION, ME, "ping", e);      }      catch (XmlRpcException e) {         throw extractXmlBlasterException(glob, e);      }   }   public String toXml() throws XmlBlasterException   {      return toXml("");   }   /**    * Dump of the server, remove in future.    */   public String toXml(String extraOffset) throws XmlBlasterException   {      if (!isLoggedIn()) return "<noConnection />";      try {         Vector args = new Vector();         args.addElement(extraOffset);         return (String)this.xmlRpcClient.execute("xmlBlaster.toXml", args);      }      catch (ClassCastException e) {         log.severe("not a valid Vector: " + e.toString());         throw XmlBlasterException.convert(glob, ME, "toXml Class Cast Exception", e);      }      catch (IOException e) {         log.severe("IO exception: " + e.toString());         throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION, ME, "toXml", e);      }      catch (XmlRpcException e) {         throw extractXmlBlasterException(glob, e);      }   }   /**    * Register a listener for to receive information about the progress of incoming data.     * Only one listener is supported, the last call overwrites older calls. This implementation    * does nothing here, it just returns null.    *     * @param listener Your listener, pass 0 to unregister.    * @return The previously registered listener or 0    */   public I_ProgressListener registerProgressListener(I_ProgressListener listener) {      log.fine("This method is currently not implemeented.");      return null;   }      /**    * Command line usage.    * <p />    * These variables may be set in xmlBlaster.properties as well.    * Don't use the "-" prefix there.    */   public static String usage()   {      String text = "\n";      text += "XmlRpcConnection 'XMLRPC' options:\n";      text += "   -dispatch/connection/plugin/xmlrpc/port\n";      text += "                       Specify a port number where xmlBlaster XMLRPC web server listens.\n";      text += "                       Default is port "+org.xmlBlaster.protocol.xmlrpc.XmlRpcDriver.DEFAULT_HTTP_PORT+", the port 0 switches this feature off.\n";      text += "   -dispatch/connection/plugin/xmlrpc/hostname\n";      text += "                       Specify a hostname where the xmlBlaster web server runs.\n";      text += "                       Default is the localhost.\n";      text += "   -dispatch/callback/plugin/xmlrpc/port\n";      text += "                       Specify a port number for the callback web server to listen.\n";      text += "                       Default is port "+XmlRpcCallbackServer.DEFAULT_CALLBACK_PORT+", the port 0 switches this feature off.\n";      text += "   -dispatch/callback/plugin/xmlrpc/hostname\n";      text += "                       Specify a hostname where the callback web server shall run.\n";      text += "                       Default is the localhost (useful for multi homed hosts).\n";      text += "   -plugin/xmlrpc/debug\n";      text += "                       true switches on detailed XMLRPC debugging [false].\n";      text += "\n";      return text;   }   /**    * For Testing.    * <pre>    * java org.xmlBlaster.client.protocol.xmlrpc.XmlRpcConnection    * </pre>    */   public static void main(String args[])   {   /*      final String ME = "XmlRpcHttpClient";      try { Global.init(args); } catch(XmlBlasterException e) { log.severe(e.toString()); }      // build the proxy      try {         XmlRpcConnection proxy = new XmlRpcConnection("http://localhost:8080", 8081);         String qos = "<qos><callback type='XMLRPC'>http://localhost:8081</callback></qos>";         String sessionId = "Session1";         String loginAnswer = proxy.login("LunaMia", "silence", qos, sessionId);         log.info(ME, "The answer from the login is: " + loginAnswer);         String contentString = "This is a simple Test Message for the xml-rpc Protocol";         byte[] content = contentString.getBytes();         org.xmlBlaster.client.key.PublishKey xmlKey = new org.xmlBlaster.client.key.PublishKey("", "text/xml", null);         MsgUnitRaw msgUnit = new MsgUnitRaw(xmlKey.toXml(), content, "<qos></qos>");         String publishOid = proxy.publish(sessionId, msgUnit);         log.info(ME, "Published message with " + publishOid);         org.xmlBlaster.client.key.SubscribeKey subscribeKey = new org.xmlBlaster.client.key.SubscribeKey(publishOid);         log.info(ME, "Subscribe key: " + subscribeKey.toXml());         proxy.subscribe(sessionId, subscribeKey.toXml(), "");         // wait some time if necessary ....         proxy.erase(sessionId, subscribeKey.toXml(), "");         log.exit(ME, "Good bye.");      } catch(XmlBlasterException e) {         log.error(ME, "XmlBlasterException: " + e.toString());      }      // wait for some time here ....     */   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -