xmlBlaster 2.2.0 API

org.xmlBlaster.protocol.http.appletproxy
Class AppletServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.xmlBlaster.protocol.http.appletproxy.AppletServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig, I_LogListener

public class AppletServlet
extends javax.servlet.http.HttpServlet
implements I_LogListener

This servlet supports requests from an applet and sends instant message callbacks to it.

The servlet doesn't leave the doGet() method after an invocation of actionType "connect" keeping a permanent http connection.

The logging output is redirected to the normal servlet log file. If you use Apache/Jserv, look into /var/log/httpd/jserv.log, for tomcat 5.x check jakarta-tomcat/logs/catalina.out

The file

xmlBlaster/demo/http/WEB-INF/web.xml

allows to switch on/off logging and to choose any other xmlBlaster client side configuration like queue sizes etc.

Author:
Marcel Ruff xmlBlaster@marcelruff.info
See Also:
XmlBlasterAccessRaw, HelloWorld3, Serialized Form

Field Summary
static java.lang.String ENCODING
           
private  Global initialGlobal
           
private static java.util.logging.Logger log
           
static long requestCounter
           
private static long serialVersionUID
           
private  Timeout timeout
           
 
Constructor Summary
AppletServlet()
           
 
Method Summary
protected  void connect(java.lang.String ME, java.util.logging.Logger log, javax.servlet.http.HttpSession session, java.lang.String qos, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
           
private  java.lang.String decode(java.lang.String in, java.lang.String encoding)
           
 void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          This method is supported just for cases where the servlet is contacted directy from a browser in which case it is easy for the user to pass the data directly via the url.
 void doGetFake(java.lang.String ME, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.lang.String actionType, MsgHolder msgHolder)
          GET request from the browser, usually to do an initial login.
 void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          POST request from the applet.
protected  MsgHolder extractMessage(java.lang.String ME, java.util.logging.Logger log, javax.servlet.http.HttpServletRequest req, MsgHolder binaryMsg)
           
static java.lang.String getAttribute(javax.servlet.http.HttpServletRequest req, java.lang.String name, java.lang.String defaultVal)
          Get a request attribute, if not found the session is checked, if not found again, the given default is returned.
static boolean getParameter(javax.servlet.http.HttpServletRequest req, java.lang.String name, boolean defaultVal)
           
static java.lang.String getParameter(javax.servlet.http.HttpServletRequest req, java.lang.String name, java.lang.String defaultVal)
          Get the request parameter.
private  PushHandler getPushHandler(javax.servlet.http.HttpServletRequest req)
           
 void init(javax.servlet.ServletConfig conf)
          This method is invoked only once when the servlet is started.
static void initSystemProperties(javax.servlet.ServletConfig conf)
          Setting the system properties.
 void log(java.util.logging.LogRecord record)
          Event fired by Logger.java through interface I_LogListener.
private  MsgHolder readBinaryProtocol(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          This method is used by the binary protocol.
private  byte[] readBodyContent(javax.servlet.http.HttpServletRequest req)
           
private  void writeResponse(javax.servlet.http.HttpServletResponse res, java.lang.String actionType, java.lang.Object obj)
          Transforms the given text to send it back to the applet.
private  void writeResponse(javax.servlet.http.HttpServletResponse res, java.lang.String actionType, java.lang.String text)
           
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static java.util.logging.Logger log

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

initialGlobal

private Global initialGlobal

timeout

private Timeout timeout

ENCODING

public static final java.lang.String ENCODING
See Also:
Constant Field Values

requestCounter

public static long requestCounter
Constructor Detail

AppletServlet

public AppletServlet()
Method Detail

init

public void init(javax.servlet.ServletConfig conf)
          throws javax.servlet.ServletException
This method is invoked only once when the servlet is started.

Specified by:
init in interface javax.servlet.Servlet
Overrides:
init in class javax.servlet.GenericServlet
Parameters:
conf - init parameter of the servlet
Throws:
javax.servlet.ServletException

connect

protected void connect(java.lang.String ME,
                       java.util.logging.Logger log,
                       javax.servlet.http.HttpSession session,
                       java.lang.String qos,
                       javax.servlet.http.HttpServletRequest req,
                       javax.servlet.http.HttpServletResponse res)
                throws XmlBlasterException,
                       java.io.IOException,
                       javax.servlet.ServletException
Throws:
XmlBlasterException
java.io.IOException
javax.servlet.ServletException

doGetFake

public void doGetFake(java.lang.String ME,
                      javax.servlet.http.HttpServletRequest req,
                      javax.servlet.http.HttpServletResponse res,
                      java.lang.String actionType,
                      MsgHolder msgHolder)
               throws javax.servlet.ServletException,
                      java.io.IOException
GET request from the browser, usually to do an initial login.

Used for login and for keeping a permanent http connection.
The sessionId from the login is delivered back to the browser, and will be used for all following calls to this and other servlets.
It is important that this login servlet generates the sessionId and no other servlet generates one - so call other servlets *after* successful login.

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

decode

private final java.lang.String decode(java.lang.String in,
                                      java.lang.String encoding)

readBodyContent

private byte[] readBodyContent(javax.servlet.http.HttpServletRequest req)

readBinaryProtocol

private MsgHolder readBinaryProtocol(javax.servlet.http.HttpServletRequest req,
                                     javax.servlet.http.HttpServletResponse res)
                              throws java.io.IOException
This method is used by the binary protocol. It passes all information in the http body.

Parameters:
req -
res -
Returns:
null if it was no binary protocol, otherwise an Object[3] = { (String)key, (String)qos, byte[] content } where every one of the three elements could be null.
Throws:
java.io.IOException

extractMessage

protected MsgHolder extractMessage(java.lang.String ME,
                                   java.util.logging.Logger log,
                                   javax.servlet.http.HttpServletRequest req,
                                   MsgHolder binaryMsg)

doGet

public void doGet(javax.servlet.http.HttpServletRequest req,
                  javax.servlet.http.HttpServletResponse res)
           throws javax.servlet.ServletException,
                  java.io.IOException
This method is supported just for cases where the servlet is contacted directy from a browser in which case it is easy for the user to pass the data directly via the url.

Overrides:
doGet in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
java.io.IOException

doPost

public void doPost(javax.servlet.http.HttpServletRequest req,
                   javax.servlet.http.HttpServletResponse res)
            throws javax.servlet.ServletException,
                   java.io.IOException
POST request from the applet.

Handles all requests coming from the applet. It reads the passed parameters either from the url (in which case they are encoded) or directly from the input stream (the body of the request). In the latter case they are binary data which is not encoded and is refered to as binary protocol. The asynchronous updates are pushed back using PushHandler.java

Overrides:
doPost in class javax.servlet.http.HttpServlet
Parameters:
req - Data from browser
res - Response of the servlet
Throws:
javax.servlet.ServletException
java.io.IOException

initSystemProperties

public static final void initSystemProperties(javax.servlet.ServletConfig conf)
Setting the system properties.

These may be overwritten in zone.properties, e.g. servlets.default.initArgs=servlets.default.initArgs=org.xml.sax.parser=org.apache.crimson.parser.Parser2

We set the properties to choose JacORB and Suns XML parser as a default.


writeResponse

private void writeResponse(javax.servlet.http.HttpServletResponse res,
                           java.lang.String actionType,
                           java.lang.String text)
                    throws java.io.IOException
Throws:
java.io.IOException
See Also:
#writeResponse(HttpServletResponse, String, text)

writeResponse

private void writeResponse(javax.servlet.http.HttpServletResponse res,
                           java.lang.String actionType,
                           java.lang.Object obj)
                    throws java.io.IOException
Transforms the given text to send it back to the applet.

The actionType and the text are java.io.Serialized and than Base64 encoded.

Parameters:
res -
actionType - A type with the applet knows how to read, "subscribe" etc. for subscribe return QoS
Throws:
java.io.IOException

getPushHandler

private PushHandler getPushHandler(javax.servlet.http.HttpServletRequest req)
                            throws XmlBlasterException
Returns:
The PushHandler of this session, never null
Throws:
If - no PushHandler exists
XmlBlasterException

log

public void log(java.util.logging.LogRecord record)
Event fired by Logger.java through interface I_LogListener.

Log output from log.info(); etc. into Servlet log file.

Note that System.err.println("Hello"); will be printed into the Apache error log file /var/log/httpd.error_log
I don't know what other web servers are doing with it.

System.out.println("Hello"); will be printed to the console where you started the servlet engine.

Specified by:
log in interface I_LogListener

getParameter

public static final java.lang.String getParameter(javax.servlet.http.HttpServletRequest req,
                                                  java.lang.String name,
                                                  java.lang.String defaultVal)
Get the request parameter.
NOTE: Servlet API 2.1 or higher

Parameters:
req - request from client
name - parameter name
defaultVal - default value if parameter not found
Returns:
The value

getAttribute

public static final java.lang.String getAttribute(javax.servlet.http.HttpServletRequest req,
                                                  java.lang.String name,
                                                  java.lang.String defaultVal)
Get a request attribute, if not found the session is checked, if not found again, the given default is returned.
NOTE: Servlet API 2.1 or higher

Parameters:
req - request from client
name - parameter name
defaultVal - default value if parameter not found
Returns:
The value

getParameter

public static final boolean getParameter(javax.servlet.http.HttpServletRequest req,
                                         java.lang.String name,
                                         boolean defaultVal)
See Also:
getParameter(HttpServletRequest, String, String)

xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.