xmlBlaster 2.2.0 API

org.xmlBlaster.client.protocol.http.common
Class XmlBlasterAccessRawBase

java.lang.Object
  extended by org.xmlBlaster.client.protocol.http.common.XmlBlasterAccessRawBase
All Implemented Interfaces:
I_XmlBlasterAccessRaw
Direct Known Subclasses:
XmlBlasterAccessRaw

public abstract class XmlBlasterAccessRawBase
extends java.lang.Object
implements I_XmlBlasterAccessRaw

A java client implementation to access xmlBlaster using a persistent http connection for instant callback messages.

You can control logging with the Applet PARAM tag, logging output is put to the Java console of your browser:

 <PARAM name="xmlBlaster/logLevels" value="ERROR,WARN">
 with more logging:
 <PARAM name="xmlBlaster/logLevels" value="ERROR,WARN,INFO,DEBUG">
 
See the example applet HelloWorld3 on how to use it.

Author:
Marcel Ruff
See Also:
HelloWorld3

Field Summary
private  I_CallbackRaw callback
           
private  java.util.Hashtable cookie
           
protected  int instanceCount
           
private  boolean isConnected
           
protected  java.lang.String logLevels
           
protected  I_Log logListener
           
private static java.lang.Object mutexer
           
static boolean ONEWAY
           
private  PersistentRequest persistentHttpConnection
           
protected  java.util.Hashtable properties
           
private static int staticInstanceCounter
           
protected  java.lang.String xmlBlasterServletUrl
          Typically "http://localhost:8080/xmlBlaster/AppletServlet"
 
Fields inherited from interface org.xmlBlaster.client.protocol.http.common.I_XmlBlasterAccessRaw
CONNECT_NAME, CREATE_SESSIONID_NAME, DISCONNECT_NAME, ERASE_NAME, EXCEPTION_NAME, GET_NAME, PING_NAME, PONG_NAME, PUBLISH_NAME, SUBSCRIBE_NAME, UNSUBSCRIBE_NAME, UPDATE_NAME
 
Constructor Summary
XmlBlasterAccessRawBase(java.util.Hashtable properties)
          Provides access to xmlBlaster server.
 
Method Summary
 java.lang.String connect(java.lang.String qos, I_CallbackRaw callback)
          Connect to xmlBlaster.
abstract  I_Connection createConnection(java.lang.String urlString)
          Creates a connection to the specified servlet.
abstract  byte[] decodeBase64(java.lang.String data)
          decodes binary data to Base64.
 void disconnect(java.lang.String qos)
           
abstract  java.lang.String encodeBase64(byte[] data)
          Url encodes the string
 java.util.Hashtable[] erase(java.lang.String xmlKey, java.lang.String qos)
           
protected  java.util.Hashtable extractCookies(java.lang.String cookieTxt)
          Converts a string containing all cookies to an hashtable containing all cookies as key/value pairs.
 Msg[] get(java.lang.String xmlKey, java.lang.String qos)
           
 java.util.Hashtable getHtmlProperties()
          Get a list of all PARAM in the HTML file following our convention.
 int getInstanceCount()
          Access the unique counter of this object instance.
 java.lang.String getInstanceId()
          Access the unique counter of this object instance for logging.
 java.lang.String getXmlBlasterServletUrl()
          Access the URL of the xmlBlaster servlet.
 boolean isConnected()
          Check wether we are connected
 void isConnected(boolean isConnected)
           
protected  void log(java.lang.String level, java.lang.String text)
          Log to java console of the browser of the logListener if any is registered
 void log(java.lang.String location, java.lang.String level, java.lang.String text)
          Log to the logListener or to the java console of the browser if logListener is null.
 java.util.Hashtable ping(java.lang.String qos)
          Returns "/qos/state/@info"="OK" if communication from servlet to xmlBlaster is OK
Returns "/qos/state/@info"="POLLING" if communication from servlet to xmlBlaster is down but polling
Returns "/qos/state/@info"="DEAD" if communication from servlet to xmlBlaster is permanently lost
(package private)  java.lang.Object postRequest(java.lang.String actionType, java.lang.String key, java.lang.String qos, byte[] content, boolean oneway)
          Send a http request to the servlet.
 java.util.Hashtable publish(java.lang.String xmlKey, byte[] content, java.lang.String qos)
           
 void readCookie(I_Connection conn)
          reads the cookie and stores it.
 java.lang.String sendXmlScript(java.lang.String xmlRequest)
          Send a xml script request to xmlBlaster.
 void setLogListener(I_Log logListener)
          Register to receive the logging output
private  java.lang.String startPersistentHttpConnection()
           
 java.util.Hashtable subscribe(java.lang.String xmlKey, java.lang.String qos)
           
 java.util.Hashtable[] unSubscribe(java.lang.String xmlKey, java.lang.String qos)
           
 java.lang.String update(java.lang.String cbSessionId, java.util.Hashtable updateKey, byte[] content, java.util.Hashtable updateQos)
          see I_CallbackRaw#update
 void writeCookie(I_Connection conn)
           
(package private) static void writeRequest(I_Connection conn, java.lang.String actionType, java.lang.String key, java.lang.String qos, byte[] content)
          The format: oid + \0 + key + '\0' + qos + '\0' + content: length = oid + key + qos + content + 3
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xmlBlasterServletUrl

protected java.lang.String xmlBlasterServletUrl
Typically "http://localhost:8080/xmlBlaster/AppletServlet"


persistentHttpConnection

private PersistentRequest persistentHttpConnection

callback

private I_CallbackRaw callback

ONEWAY

public static final boolean ONEWAY
See Also:
Constant Field Values

isConnected

private boolean isConnected

properties

protected java.util.Hashtable properties

logListener

protected I_Log logListener

logLevels

protected java.lang.String logLevels

cookie

private java.util.Hashtable cookie

staticInstanceCounter

private static int staticInstanceCounter

instanceCount

protected int instanceCount

mutexer

private static java.lang.Object mutexer
Constructor Detail

XmlBlasterAccessRawBase

public XmlBlasterAccessRawBase(java.util.Hashtable properties)
Provides access to xmlBlaster server.

Parameters:
properties - "xmlBlaster/servletUrl", "xmlBlaster/logLevels" (locally used) and additional properties which are send to the servlet.
The addtional properties must start with "servlet/xyz=someValue". The "servlet/" will be stripped away and in the web-servlet will arrive "xyz=someValue". The key/values are send in the URL.
See Also:
#parseAppletParameter
Method Detail

getInstanceId

public java.lang.String getInstanceId()
Description copied from interface: I_XmlBlasterAccessRaw
Access the unique counter of this object instance for logging.

Specified by:
getInstanceId in interface I_XmlBlasterAccessRaw

getInstanceCount

public int getInstanceCount()
Access the unique counter of this object instance.


setLogListener

public void setLogListener(I_Log logListener)
Register to receive the logging output

Specified by:
setLogListener in interface I_XmlBlasterAccessRaw
Parameters:
listener - If null we log to the java console of the browser

getHtmlProperties

public java.util.Hashtable getHtmlProperties()
Description copied from interface: I_XmlBlasterAccessRaw
Get a list of all PARAM in the HTML file following our convention.

All param names starting with "servlet/" are passed to the servlet. They must start with "servlet/xyz=someValue". The "servlet/" will be stripped away and in the web-servlet will arrive "xyz=someValue". The key/values are send in the URL.

As the applet class has no getAllParameters() method we expect a PARAM deliveredParamKeys which contains a list of all delivered PARAM in the HTML page:

    <applet ...>
       <param name="deliveredParamKeys" value="protocol,anotherKey,Key3">
       <param name="protocol" value="SOCKET">
       <param name="anotherKey" value="someValue">
       <param name="Key3" value="xxx">
    </applet>
 

It may contain additional customized properties from the applet programmer.

Specified by:
getHtmlProperties in interface I_XmlBlasterAccessRaw
Returns:
The found parameters
See Also:
I_XmlBlasterAccessRaw.getHtmlProperties()

log

protected void log(java.lang.String level,
                   java.lang.String text)
Log to java console of the browser of the logListener if any is registered


log

public void log(java.lang.String location,
                java.lang.String level,
                java.lang.String text)
Description copied from interface: I_XmlBlasterAccessRaw
Log to the logListener or to the java console of the browser if logListener is null.

Specified by:
log in interface I_XmlBlasterAccessRaw
Parameters:
location - Your class and/or method name
text - The text to log
See Also:
I_XmlBlasterAccessRaw.log(String, String, String)

getXmlBlasterServletUrl

public java.lang.String getXmlBlasterServletUrl()
Access the URL of the xmlBlaster servlet.

Returns:
Typically "http://localhost:8080/xmlBlaster/AppletServlet&appletInstanceCount=1"

isConnected

public void isConnected(boolean isConnected)

isConnected

public boolean isConnected()
Description copied from interface: I_XmlBlasterAccessRaw
Check wether we are connected

Specified by:
isConnected in interface I_XmlBlasterAccessRaw

startPersistentHttpConnection

private java.lang.String startPersistentHttpConnection()
                                                throws java.lang.Exception
Throws:
java.lang.Exception

connect

public java.lang.String connect(java.lang.String qos,
                                I_CallbackRaw callback)
                         throws java.lang.Exception
Description copied from interface: I_XmlBlasterAccessRaw
Connect to xmlBlaster.

Specified by:
connect in interface I_XmlBlasterAccessRaw
Parameters:
qos - If your qos is null the APPLET PARAMs will be checked for"xmlBlaster/loginName" and "xmlBlaster/passwd"
If your qos is "" the servlet will choose its configured connectQoS (take care on security issues!)
If qos is not null and pre-filled with authentication informations it will be used to authenticate at xmlBlaster
callback - Where to send asynchronous callback messages.
Returns:
never null TODO!!!: return JXPath Hashtable for easier parameter access Currently the ConnectQos.toXml() is returned
Throws:
java.lang.Exception
See Also:
I_XmlBlasterAccessRaw.connect(String, I_CallbackRaw)

sendXmlScript

public java.lang.String sendXmlScript(java.lang.String xmlRequest)
                               throws java.lang.Exception
Description copied from interface: I_XmlBlasterAccessRaw
Send a xml script request to xmlBlaster. You need to call connect() first!

Specified by:
sendXmlScript in interface I_XmlBlasterAccessRaw
Returns:
xml script returned
Throws:
java.lang.Exception
See Also:
I_XmlBlasterAccessRaw.connect(String, I_CallbackRaw)

ping

public java.util.Hashtable ping(java.lang.String qos)
                         throws java.lang.Exception
Description copied from interface: I_XmlBlasterAccessRaw
Returns "/qos/state/@info"="OK" if communication from servlet to xmlBlaster is OK
Returns "/qos/state/@info"="POLLING" if communication from servlet to xmlBlaster is down but polling
Returns "/qos/state/@info"="DEAD" if communication from servlet to xmlBlaster is permanently lost

Specified by:
ping in interface I_XmlBlasterAccessRaw
Returns:
never null, contains QoS in XJPath format
Throws:
java.lang.Exception

subscribe

public java.util.Hashtable subscribe(java.lang.String xmlKey,
                                     java.lang.String qos)
                              throws java.lang.Exception
Specified by:
subscribe in interface I_XmlBlasterAccessRaw
Returns:
never null, contains QoS in XJPath format
Throws:
java.lang.Exception

get

public Msg[] get(java.lang.String xmlKey,
                 java.lang.String qos)
          throws java.lang.Exception
Specified by:
get in interface I_XmlBlasterAccessRaw
Returns:
never null, contains keys and QoS in XJPath format
Throws:
java.lang.Exception

unSubscribe

public java.util.Hashtable[] unSubscribe(java.lang.String xmlKey,
                                         java.lang.String qos)
                                  throws java.lang.Exception
Specified by:
unSubscribe in interface I_XmlBlasterAccessRaw
Returns:
never null, contains QoS in XJPath format
Throws:
java.lang.Exception

publish

public java.util.Hashtable publish(java.lang.String xmlKey,
                                   byte[] content,
                                   java.lang.String qos)
                            throws java.lang.Exception
Specified by:
publish in interface I_XmlBlasterAccessRaw
Returns:
never null, contains QoS in XJPath format
Throws:
java.lang.Exception

erase

public java.util.Hashtable[] erase(java.lang.String xmlKey,
                                   java.lang.String qos)
                            throws java.lang.Exception
Specified by:
erase in interface I_XmlBlasterAccessRaw
Returns:
never null, contains QoS in XJPath format
Throws:
java.lang.Exception

disconnect

public void disconnect(java.lang.String qos)
Specified by:
disconnect in interface I_XmlBlasterAccessRaw

writeRequest

static void writeRequest(I_Connection conn,
                         java.lang.String actionType,
                         java.lang.String key,
                         java.lang.String qos,
                         byte[] content)
                  throws java.io.IOException
The format: oid + \0 + key + '\0' + qos + '\0' + content: length = oid + key + qos + content + 3

Parameters:
conn -
actionType -
key -
qos -
content -
Throws:
java.io.IOException

postRequest

java.lang.Object postRequest(java.lang.String actionType,
                             java.lang.String key,
                             java.lang.String qos,
                             byte[] content,
                             boolean oneway)
                       throws java.lang.Exception
Send a http request to the servlet.

Parameters:
request - The request string without the URL prefix, e.g. "?XmlBlasterAccessRawType=pong"
doPost - if true POST else GET
oneway - true for requests returning void
Returns:
The returned value for the given request, "" on error or for oneway messages
Throws:
java.lang.Exception

update

public java.lang.String update(java.lang.String cbSessionId,
                               java.util.Hashtable updateKey,
                               byte[] content,
                               java.util.Hashtable updateQos)
                        throws java.lang.Exception
see I_CallbackRaw#update

Throws:
java.lang.Exception

extractCookies

protected java.util.Hashtable extractCookies(java.lang.String cookieTxt)
Converts a string containing all cookies to an hashtable containing all cookies as key/value pairs.

Parameters:
cookieTxt - The string from which to extract the cookies
Returns:
an hashtable containing all found cookies as key/value pairs

readCookie

public void readCookie(I_Connection conn)
reads the cookie and stores it.

Parameters:
conn -

writeCookie

public void writeCookie(I_Connection conn)

encodeBase64

public abstract java.lang.String encodeBase64(byte[] data)
Url encodes the string

Parameters:
s -
enc -
Returns:

decodeBase64

public abstract byte[] decodeBase64(java.lang.String data)
decodes binary data to Base64. The returned bytes are all text characters.

Parameters:
data -
Returns:

createConnection

public abstract I_Connection createConnection(java.lang.String urlString)
                                       throws java.lang.Exception
Description copied from interface: I_XmlBlasterAccessRaw
Creates a connection to the specified servlet.

Specified by:
createConnection in interface I_XmlBlasterAccessRaw
Returns:
Throws:
java.lang.Exception

xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.