]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/java/org/opensrf/test/TestXMPP.java
added shutdown call to cleanly disconnect from the opensrf network
[OpenSRF.git] / src / java / org / opensrf / test / TestXMPP.java
1 package org.opensrf.test;
2
3 import org.opensrf.net.xmpp.XMPPReader;
4 import org.opensrf.net.xmpp.XMPPMessage;
5 import org.opensrf.net.xmpp.XMPPSession;
6
7 public class TestXMPP {
8
9     /**
10      * Connects to the jabber server and waits for inbound messages.
11      * If a recipient is provided, a small message is sent to the recipient.
12      */
13     public static void main(String args[]) throws Exception {
14
15         String host;
16         int port;
17         String username;
18         String password;
19         String resource;
20         String recipient;
21
22         try {
23             host = args[0];
24             port = Integer.parseInt(args[1]);
25             username = args[2];
26             password = args[3];
27             resource = args[4];
28
29         } catch(ArrayIndexOutOfBoundsException e) {
30             System.err.println("usage: org.opensrf.test.TestXMPP <host> <port> <username> <password> <resource> [<recipient>]");
31             return;
32         }
33
34         XMPPSession session = new XMPPSession(host, port);
35         session.connect(username, password, resource);
36
37         XMPPMessage msg;
38
39         if( args.length == 6 ) {
40
41             /** they specified a recipient */
42
43             recipient = args[5];
44             msg = new XMPPMessage();
45             msg.setTo(recipient);
46             msg.setThread("test-thread");
47             msg.setBody("Hello, from java-xmpp");
48             System.out.println("Sending message to " + recipient);
49             session.send(msg);
50         }
51
52         while(true) {
53             System.out.println("waiting for message...");
54             msg = session.recv(-1); /* wait forever for a message to arrive */
55             System.out.println("got message: " + msg.toXML());
56         }
57     }
58 }
59
60
61
62
63