xmlBlaster 2.2.0 API

org.xmlBlaster.protocol.http
Class HttpPushHandler

java.lang.Object
  extended by org.xmlBlaster.protocol.http.HttpPushHandler
All Implemented Interfaces:
I_Callback

public class HttpPushHandler
extends java.lang.Object
implements I_Callback

This handles and hides the different http push modes when sending data back to the browser through method update().
Push mode works with keeping a permanent http connection

TODO: HTTP 1.1 specifies rfc2616 that the connection stays open as the default case. How must this code be changed?

See Java Servlet Programming from Jason Hunter

Author:
Marcel Ruff xmlBlaster@marcelruff.info

Nested Class Summary
private  class HttpPushHandler.HttpPingThread
          Ping the browser, to avoid that the web server or the browser closes the http connection after a vendor specific timeout.
 
Field Summary
private  boolean browserIsReady
          Check it the browser is ready to accept more messages
private  I_Callback callbackInterceptor
           
private  boolean closed
          Current http connection state
private  boolean firstPush
           
private  boolean handlesMultipart
          handlesMultipart is true for netscape browser
private  java.lang.String head
          The header of the HTML page
private static java.util.logging.Logger log
           
private  java.lang.String ME
           
private  javax.servlet.ServletOutputStream outMulti
           
private  java.io.PrintWriter outPlain
           
private  long PING_INTERVAL
          Ping the browser every 10 seconds.
private  HttpPushHandler.HttpPingThread pingThread
          Check browser and holds the http connection
private  java.util.Vector pushQueue
          Queue to hold messages (class PushDataItem) until the browser is ready for them
private  javax.servlet.http.HttpServletRequest req
           
private  javax.servlet.http.HttpServletResponse res
           
private  java.lang.String sessionId
           
private  java.lang.String tail
          The tail of the HTML page
private  I_XmlBlasterAccess xmlBlasterAccess
           
 
Constructor Summary
HttpPushHandler(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.lang.String sessionId, java.lang.String loginName, I_XmlBlasterAccess xmlBlasterAccess)
          Use this constructor if you are too lazy to pass a HTML header, a default will be used.
 
Method Summary
static java.lang.String alert(java.lang.String text)
          Display a popup alert message containing the error text.
 void cleanup()
          Delegates the cleanup call to HttpPushHandler
 boolean closed()
          check's whether the HTTP connection is closed or not
private  boolean doesHandleMultipart()
          Determine if the browser can handle multipart pushs.
 I_XmlBlasterAccess getXmlBlasterAccess()
           
private  void initialize(java.lang.String head, java.lang.String tail)
           
 boolean isBrowserReady()
          check's whether the browser is ready to accept more messages or not [if (parent.browserReady != null) parent.browserReady();].
 void message(java.lang.String text)
          Calls the message method in the parentframe of the callback frame.
 void ping(java.lang.String state)
          calls the ping method in the parentframe of the callback frame The data must be Javascript code
 void pong()
          This is the browser response for our previous ping.
 void push(PushDataItem item)
          Updating data to the browser (callback/push mode).
private  void pushToBrowser()
          Pushing messages in the queue to the browser
 void setBrowserIsReady(boolean ready)
           
 void setClosed(boolean closed)
           
 void setProxyInterceptor(I_Callback interceptor)
          If you implement I_ProxyInterceptor and register it here, your update() implementation is called and may manipulate the received message from xmlBlaster before it is sent to the browser.
 void shutdownBrowserConnection()
          Don't forget to call this method when you want to close the connection.
 void startPing()
           
 java.lang.String update(java.lang.String sessionId, UpdateKey updateKey, byte[] content, UpdateQos updateQos)
          Pushes received message back to browser or applet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ME

private java.lang.String ME

log

private static java.util.logging.Logger log

PING_INTERVAL

private final long PING_INTERVAL
Ping the browser every 10 seconds.
You need to adjust ping() in persistenWindow/index.html as well, if you change the value here.

See Also:
Constant Field Values

xmlBlasterAccess

private I_XmlBlasterAccess xmlBlasterAccess

callbackInterceptor

private I_Callback callbackInterceptor

req

private javax.servlet.http.HttpServletRequest req

res

private javax.servlet.http.HttpServletResponse res

sessionId

private java.lang.String sessionId

closed

private boolean closed
Current http connection state


outMulti

private javax.servlet.ServletOutputStream outMulti

outPlain

private java.io.PrintWriter outPlain

head

private java.lang.String head
The header of the HTML page


tail

private java.lang.String tail
The tail of the HTML page


browserIsReady

private boolean browserIsReady
Check it the browser is ready to accept more messages


handlesMultipart

private boolean handlesMultipart
handlesMultipart is true for netscape browser


pingThread

private HttpPushHandler.HttpPingThread pingThread
Check browser and holds the http connection


pushQueue

private java.util.Vector pushQueue
Queue to hold messages (class PushDataItem) until the browser is ready for them


firstPush

private boolean firstPush
Constructor Detail

HttpPushHandler

public HttpPushHandler(javax.servlet.http.HttpServletRequest req,
                       javax.servlet.http.HttpServletResponse res,
                       java.lang.String sessionId,
                       java.lang.String loginName,
                       I_XmlBlasterAccess xmlBlasterAccess)
                throws javax.servlet.ServletException,
                       java.io.IOException
Use this constructor if you are too lazy to pass a HTML header, a default will be used.

Parameters:
req - The request object
res - The response object
sessionId - The browser id
loginName - For loggin only
xmlBlasterAccess - Not yet logged in
Throws:
javax.servlet.ServletException
java.io.IOException
Method Detail

getXmlBlasterAccess

public I_XmlBlasterAccess getXmlBlasterAccess()

initialize

private void initialize(java.lang.String head,
                        java.lang.String tail)
                 throws java.io.IOException
Throws:
java.io.IOException

shutdownBrowserConnection

public void shutdownBrowserConnection()
Don't forget to call this method when you want to close the connection.


setProxyInterceptor

public void setProxyInterceptor(I_Callback interceptor)
If you implement I_ProxyInterceptor and register it here, your update() implementation is called and may manipulate the received message from xmlBlaster before it is sent to the browser.

Parameters:
interceptor - Your optional implementation

cleanup

public void cleanup()
Delegates the cleanup call to HttpPushHandler


startPing

public void startPing()
               throws javax.servlet.ServletException,
                      java.io.IOException
Throws:
javax.servlet.ServletException
java.io.IOException

closed

public boolean closed()
check's whether the HTTP connection is closed or not


setClosed

public void setClosed(boolean closed)

isBrowserReady

public final boolean isBrowserReady()
check's whether the browser is ready to accept more messages or not [if (parent.browserReady != null) parent.browserReady();]. This shows, that the browser had processed the whole message. If the Browser implements this javascript function, it could send a browserReady signal back to the BlasterHttpProxyServlet. This feature solves the problem, that the browser got messages too fast and could not process all content of the message.


setBrowserIsReady

public void setBrowserIsReady(boolean ready)

doesHandleMultipart

private boolean doesHandleMultipart()
                             throws java.io.IOException
Determine if the browser can handle multipart pushs. Only Netscape returns true.

Throws:
java.io.IOException

push

public void push(PushDataItem item)
          throws javax.servlet.ServletException,
                 java.io.IOException
Updating data to the browser (callback/push mode). The data must be Javascript code

Parameters:
str -
Throws:
javax.servlet.ServletException
java.io.IOException

pushToBrowser

private void pushToBrowser()
                    throws javax.servlet.ServletException,
                           java.io.IOException
Pushing messages in the queue to the browser

Throws:
javax.servlet.ServletException
java.io.IOException

update

public java.lang.String update(java.lang.String sessionId,
                               UpdateKey updateKey,
                               byte[] content,
                               UpdateQos updateQos)
Pushes received message back to browser or applet.

Browser: Calls the update method in the parentframe of the callback frame The data must be Javascript code

Applet: The callbacks are java-serialized Map for key/qos etc.

Specified by:
update in interface I_Callback
Parameters:
sessionId - The session ID specified by the client which registered the callback. You can specify a cbSessionId during connection (with ConnectQos) and this is bounced back here so you can authenticate the message.
updateKey - The arrived key containing the topic name
content - The arrived message content. This is your payload.
See Also:
I_XmlBlasterAccess

alert

public static final java.lang.String alert(java.lang.String text)
Display a popup alert message containing the error text.

This method wraps your text into javascript/alert code and escapes "\n" and "'" characters

Parameters:
text - The error text

message

public void message(java.lang.String text)
Calls the message method in the parentframe of the callback frame.

See callback.js message() method. Can be used by applications to send a message to the browser.

Parameters:
text - This must be Javascript code (usually a message string)

ping

public void ping(java.lang.String state)
          throws javax.servlet.ServletException,
                 java.io.IOException
calls the ping method in the parentframe of the callback frame The data must be Javascript code

Parameters:
state - The string "refresh"
When login is done successfully, state="loginSucceeded" is sent one time
Throws:
javax.servlet.ServletException
java.io.IOException

pong

public void pong()
This is the browser response for our previous ping.


xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.