From: erickson Date: Wed, 9 May 2007 18:13:38 +0000 (+0000) Subject: fixed some logic bugs with the body parsing, added some comments X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=2d3cba34b66e8b360945612ac5ed2b34d02afa52;p=opensrf%2Fbjwebb.git fixed some logic bugs with the body parsing, added some comments git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@878 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/java/org/opensrf/net/xmpp/XMPPReader.java b/src/java/org/opensrf/net/xmpp/XMPPReader.java index 39ea0c2..9f5bdb4 100644 --- a/src/java/org/opensrf/net/xmpp/XMPPReader.java +++ b/src/java/org/opensrf/net/xmpp/XMPPReader.java @@ -11,7 +11,7 @@ import java.util.Date; /** * Slim XMPP Stream reader. This reader only understands enough XMPP - * to handle logins and recv messages. + * to handle logins and recv messages. It's implemented as a StAX parser. * @author Bill Erickson, Georgia Public Library Systems */ public class XMPPReader implements Runnable { @@ -68,7 +68,7 @@ public class XMPPReader implements Runnable { * @param inStream the inbound XML stream */ public XMPPReader(InputStream inStream) { - msgQueue = new ConcurrentLinkedQueue(); + msgQueue = new ConcurrentLinkedQueue(); this.inStream = inStream; resetBuffers(); xmlState = XMLState.IN_NOTHING; @@ -144,7 +144,8 @@ public class XMPPReader implements Runnable { } - /** Thread kickoff point */ + + /** Kickoff the thread */ public void run() { read(); } @@ -157,9 +158,10 @@ public class XMPPReader implements Runnable { public void read() { try { + XMLInputFactory factory = XMLInputFactory.newInstance(); - /** disable as many features as possible to speed up the parsing */ + /** disable as many unused features as possible to speed up the parsing */ factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE); factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE); @@ -227,19 +229,9 @@ public class XMPPReader implements Runnable { String name = reader.getName().toString(); - if("stream:stream".equals(name)) { - setXMPPStreamState(XMPPStreamState.CONNECT_RECV); - return; - } - - if("iq".equals(name)) { - if("result".equals(reader.getAttributeValue(null, "type"))) - setXMPPStreamState(XMPPStreamState.CONNECTED); - return; - } - if("message".equals(name)) { xmlState = XMLState.IN_BODY; + /** add a special case for the opensrf "router_from" attribute */ String rf = reader.getAttributeValue(null, "router_from"); if( rf != null ) @@ -250,11 +242,27 @@ public class XMPPReader implements Runnable { return; } + if("body".equals(name)) { + xmlState = XMLState.IN_BODY; + return; + } + if("thread".equals(name)) { xmlState = XMLState.IN_THREAD; return; } + if("stream:stream".equals(name)) { + setXMPPStreamState(XMPPStreamState.CONNECT_RECV); + return; + } + + if("iq".equals(name)) { + if("result".equals(reader.getAttributeValue(null, "type"))) + setXMPPStreamState(XMPPStreamState.CONNECTED); + return; + } + if("status".equals(name)) { xmlState = XMLState.IN_STATUS; return; diff --git a/src/java/org/opensrf/test/TestXMPP.java b/src/java/org/opensrf/test/TestXMPP.java index 8a34a2e..2fba67f 100644 --- a/src/java/org/opensrf/test/TestXMPP.java +++ b/src/java/org/opensrf/test/TestXMPP.java @@ -6,6 +6,10 @@ import org.opensrf.net.xmpp.XMPPSession; public class TestXMPP { + /** + * Connects to the jabber server and waits for inbound messages. + * If a recipient is provided, a small message is sent to the recipient. + */ public static void main(String args[]) throws Exception { String host; @@ -23,7 +27,7 @@ public class TestXMPP { resource = args[4]; } catch(ArrayIndexOutOfBoundsException e) { - System.err.println("usage: org.opensrf.test.TestXMPP "); + System.err.println("usage: org.opensrf.test.TestXMPP []"); return; } @@ -33,7 +37,9 @@ public class TestXMPP { XMPPMessage msg; if( args.length == 6 ) { + /** they specified a recipient */ + recipient = args[5]; msg = new XMPPMessage(); msg.setTo(recipient); @@ -45,7 +51,7 @@ public class TestXMPP { while(true) { System.out.println("waiting for message..."); - msg = session.recv(-1); + msg = session.recv(-1); /* wait forever for a message to arrive */ System.out.println("got message: " + msg.toXML()); } }