REQUIREMENT client.java.applet |
Type | NEW |
Priority | LOW |
Status | CLOSED |
Topic | XmlBlaster provides a tiny java client library for applets | ||||||
Des cription |
If you develop applets you can connect with our tiny client java library
Features
OverviewThe following illustration shows a typical use case, an applet running behind internet proxies (like squid) and firewalls. It contacts the Web Server, for example Apache, which directs the call to a servlet engine with xmlBlasters communication servlet. The servlet looks at the applet request and opens a connection to xmlBlaster to delegate the request. Note the two clients, the Browser client is an example which runs without an applet namely with pure Javascript callbacks. This example is described in requirement client.browser
Supported applet methdos are
|
||||||
Example Java |
You can try the persistent http online applet demo first:
The applet demo is currently only tested in mozilla 1.6 with a squid proxy. Other browsers may or may not work but support will follow. |
||||||
Example Java |
This example shows an applet which invokes the full set of supported methods. 1 package http.applet; 2 3 import org.xmlBlaster.client.protocol.http.applet.I_CallbackRaw; 4 import org.xmlBlaster.client.protocol.http.applet.I_XmlBlasterAccessRaw; 5 import org.xmlBlaster.client.protocol.http.applet.XmlBlasterAccessRaw; 6 import org.xmlBlaster.client.protocol.http.applet.Msg; 7 import java.applet.Applet; 8 import java.awt.Graphics; 9 import java.awt.TextArea; 10 import java.awt.Color; 11 import java.util.Map; 12 13 /** 14 * An example applet which connects to xmlBlaster using a persistent 15 * http tunnel for callbacks. 16 * 17 * @author <a href="mailto:xmlBlaster@marcelruff.info">Marcel Ruff</a> 18 * @see <a href="http://www.xmlblaster.org/xmlBlaster/demo/http/index.html"> 19 * http://www.xmlblaster.org/xmlBlaster/demo/http/index.html</a> 20 * @see org.xmlBlaster.util.qos.MsgQosData#toJXPath() 21 * @see org.xmlBlaster.util.key.MsgKeyData#toJXPath() 22 */ 23 public class HelloWorld3 extends Applet implements I_CallbackRaw 24 { 25 I_XmlBlasterAccessRaw xb; 26 TextArea textArea; 27 28 public void init(){ 29 System.out.println("HelloWorld3: Applet.init() called"); 30 try { 31 setBackground(Color.white); 32 setForeground(Color.black); 33 this.textArea = new TextArea("", 12, 60); 34 this.textArea.setBackground(Color.white); 35 this.textArea.setForeground(Color.black); 36 add(this.textArea); 37 repaint(); 38 39 this.xb = new XmlBlasterAccessRaw(this); 40 this.xb.connect(null, this); 41 print("Connected to xmlBlaster"); 42 43 Map subReturnQos = this.xb.subscribe("<key oid='HELLO'/>", "<qos/>"); 44 print("Subscribed, id=" + subReturnQos.get("/qos/subscribe/@id")); 45 46 Map pubReturnQos = this.xb.publish("<key oid='HELLO'/>", 47 "Hello World".getBytes(), "<qos/>"); 48 print("Published 'HELLO', returned status is " + 49 pubReturnQos.get("/qos/state/@id")); 50 51 Map[] unSubReturnQos = this.xb.unSubscribe("<key oid='" + 52 subReturnQos.get("/qos/subscribe/@id")+"'/>", "<qos/>"); 53 print("UnSubscribed " + unSubReturnQos.length + " topics"); 54 55 Msg[] msgs = this.xb.get("<key oid='HELLO'/>", "<qos/>"); 56 for (int i=0; i<msgs.length; i++) { 57 print("Get returned key=" + msgs[i].getKey().get("/key/@oid") + 58 " content=" + msgs[i].getContentStr()); 59 } 60 61 Map[] eraseReturnQos=this.xb.erase("<key oid='HELLO'/>","<qos/>"); 62 print("Erase " + eraseReturnQos.length + " topics"); 63 } 64 catch (Exception e) { 65 print("No connection to xmlBlaster: " + e.toString()); 66 e.printStackTrace(); 67 showStatus("HelloWorld3: No connection to xmlBlaster"); 68 } 69 } 70 71 private void print(String text) { 72 this.textArea.append("HelloWorld3: " + text + "\n"); 73 } 74 75 public void destroy(){ 76 print("Applet destroy ..."); 77 if (this.xb != null) { 78 this.xb.disconnect("<qos/>"); 79 this.xb = null; 80 print("Disconnected from xmlBlaster"); 81 } 82 } 83 84 /** 85 * Here you receive the callback messages from xmlBlaster. 86 */ 87 public String update(String cbSessionId, Map updateKey, byte[] content, 88 Map updateQos) throws Exception { 89 print("---- START update received -----"); 90 print("key=" + updateKey.get("/key/@oid") + " state=" + 91 updateQos.get("/qos/state/@id")); 92 print("update received: content=" + new String(content)); 93 print("---- END update received -----"); 94 return "<qos/>"; 95 } 96 }
In the When the applet is destroyed we disconnect from xmlBlaster. Finally we need to embed the applet into a html page: <html> <head> </head> <body> <h2>Hello World 3 Applet</h2> <applet code="http.applet.HelloWorld3.class" width="700" height="200" name="XmlBlasterAccess" archive="appletDemo.jar,xmlBlasterAppletLib.jar" MAYSCRIPT> <param name="deliveredParamKeys" value="protocol,xmlBlaster/logLevels" /> <param name="protocol" value="SOCKET" /> <param name="xmlBlaster/logLevels" value="ERROR,WARN,INFO" /> </applet> </body> </html> Specifying ConnectQosYou can specify the ConnectQos as the first parameter of the connect() method, here is an example
for a persistent login session called try { xb = new XmlBlasterAccessRaw(applet); String connectQos = "<qos>" + " <securityService type='htpasswd' version='1.0'>" + " <user>eduardo</user>" + " <passwd>secret</passwd>" + " </securityService>" + " <session name='eduardo/1' timeout='-1'/>" + " <persistent>true</persistent>" + "</qos>"; xb.connect(connectQos, applet); // registers applet.update() callback method ... |
||||||
Example Java |
Quick start installation of the above appletYou can try it with tomcat locally (no apache is necessary, i had tomcat 3.2.4, 4.1.29, 5.0.14 and 5.5 to test it, others should work as well): 1. Create a war file:cd xmlBlaster build -DTOMCAT_HOME=/opt/jakarta_tomcat deploy_war
Set TOMCAT_HOME to point to your installation and the 2. Start it (keep port 8080 free for tomcat)java org.xmlBlaster.Main -plugin/xmlrpc/port 8081 java http.dhtml.systemInfo.SystemInfoPublisher cd $TOMCAT_HOME/bin startup.sh 3. Start your browser and use this URL:http://localhost:8080/xmlBlaster/HelloWorld3.html http://localhost:8080/xmlBlaster/SystemInfoApplet.html |
||||||
Configure |
This client applet works without a XML parser to have a very small memory (download) footprint. The returned key and QoS are in a Map, the keys follow the JXPath syntax.
The interface I_XmlBlasterAccessRaw has two useful methods:
The servlet configuration, like logging and setting xmlBlaster-queue or connection parameters is done in
Note for developers:
NOTE: Configuration parameters are specified on command line (-someValue 17) or in the
xmlBlaster.properties file (someValue=17). See requirement "util.property" for details. |
||||||
Todo |
This beta release is considered stable, but we need to:
|
||||||
See API | org.xmlBlaster.client.protocol.http.common.I_XmlBlasterAccessRaw | ||||||
See REQ | interface | ||||||
See REQ | client.browser | ||||||
See | http://www.xmlblaster.org/xmlBlaster/demo/http/index.html | ||||||
See | http://jakarta.apache.org/tomcat/ | ||||||
See | http://www.xmlBlaster.org:8080/xmlBlaster/index.html | ||||||
See | http://www.xmlBlaster.org:8080/xmlBlaster/HelloWorld3.html | ||||||
See | http://www.xmlBlaster.org:8080/xmlBlaster/SystemInfoApplet.html |
This page is generated from the requirement XML file xmlBlaster/doc/requirements/client.java.applet.xml