xmlBlaster 2.2.0 API

org.xmlBlaster.protocol.http.ajax
Class AjaxServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.xmlBlaster.protocol.http.ajax.AjaxServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig, AjaxServletMBean

public class AjaxServlet
extends javax.servlet.http.HttpServlet
implements AjaxServletMBean

This servlet supports requests from a browser, it queries the topic given by "gpsTopicId" configuration which needs to contain GPS coordinates (published for example by a PDA).

Use xmlBlaster/demo/http/gps.html to display the coordinates in a map.

Callback messages are send as xml to the browser:
 <xmlBlasterResponse>
  <update>
    <qos>...</qos>
    <key>...</key>
    <content>...</content>
  </update>
 </xmlBlasterResponse>
 

Author:
Marcel Ruff xmlBlaster@marcelruff.info 2007
See Also:
Serialized Form

Field Summary
private  java.util.Map blasterInstanceMap
          key is the browser sessionId
private  java.util.Set blockedIPs
           
private  ContextNode contextNode
           
private  int maxInactiveInterval
           
private  int maxUserSessions
          We support additional admin sessions
private  JmxMBeanHandle mbeanHandle
          My JMX registration
private  java.util.Properties props
           
private static long serialVersionUID
           
 
Constructor Summary
AjaxServlet()
           
 
Method Summary
 void add(java.lang.String sessionId, BlasterInstance blasterInstance)
           
 void addBlockedIP(java.lang.String ip)
           
 java.lang.String cleanupOldSessionsKeepGivenAmount(int maxSessions, java.lang.String notificationText, boolean creationTimestamp)
           
private  void cleanupSession(javax.servlet.http.HttpServletRequest req)
           
 void clearBlockedIPs()
           
 void destroy()
           
 void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
           ServletSessionTimeout according to specification: The default timeout period for sessions is defined by the servlet container and can be obtained via the getMaxInactiveInterval method of the HttpSession interface.
 void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
           
 boolean get(javax.servlet.http.HttpServletRequest req, java.lang.String key, boolean defaultVal)
           
 int get(javax.servlet.http.HttpServletRequest req, java.lang.String key, int defaultVal)
           
 long get(javax.servlet.http.HttpServletRequest req, java.lang.String key, long defaultVal)
           
private  BlasterInstance getBlasterInstance(javax.servlet.http.HttpServletRequest req)
           
 BlasterInstance[] getBlasterInstances()
           
 java.lang.String[] getBlockedIPs()
           
private  int getConfProp(java.lang.String key, int def)
           
 ContextNode getContextNode()
           
 java.lang.String getInfo(javax.servlet.http.HttpServletRequest req)
           
 java.lang.String getInfo(javax.servlet.http.HttpServletRequest req, boolean more, boolean all)
           
private  java.util.Locale getLocale(javax.servlet.http.HttpServletRequest request)
           
 int getMaxUserSessions()
           
 int getNumBlasterInstances()
           
 boolean getReqProp(javax.servlet.http.HttpServletRequest req, java.lang.String key, boolean def)
          Access a boolean parameter.
 java.lang.String getServletInfo()
           
private  java.lang.String getText(javax.servlet.http.HttpServletRequest request, java.lang.String key, java.lang.String defaultVal, java.lang.String arg1, java.lang.String arg2)
          Support for internationalization of exceptions.
private  BlasterInstance hasBlasterInstance(javax.servlet.http.HttpServletRequest req)
           
 void init(javax.servlet.ServletConfig conf)
           
 boolean isBlockedIP(java.lang.String ip)
           
 void log(java.lang.String text)
           
 boolean maxUserSessionsReached(javax.servlet.http.HttpServletRequest req)
           
 void removeBlasterInstance(java.lang.String sessionId)
           
 void setMaxUserSessions(int maxUserSessions)
           
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

props

private java.util.Properties props

maxInactiveInterval

private int maxInactiveInterval

contextNode

private ContextNode contextNode

mbeanHandle

private JmxMBeanHandle mbeanHandle
My JMX registration


blockedIPs

private java.util.Set blockedIPs

blasterInstanceMap

private java.util.Map blasterInstanceMap
key is the browser sessionId


maxUserSessions

private int maxUserSessions
We support additional admin sessions

Constructor Detail

AjaxServlet

public AjaxServlet()
Method Detail

getConfProp

private int getConfProp(java.lang.String key,
                        int def)

init

public void init(javax.servlet.ServletConfig conf)
          throws javax.servlet.ServletException
Specified by:
init in interface javax.servlet.Servlet
Overrides:
init in class javax.servlet.GenericServlet
Throws:
javax.servlet.ServletException

doPost

public void doPost(javax.servlet.http.HttpServletRequest req,
                   javax.servlet.http.HttpServletResponse res)
            throws javax.servlet.ServletException,
                   java.io.IOException
Overrides:
doPost in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
java.io.IOException

getInfo

public java.lang.String getInfo(javax.servlet.http.HttpServletRequest req)

getInfo

public java.lang.String getInfo(javax.servlet.http.HttpServletRequest req,
                                boolean more,
                                boolean all)

getLocale

private java.util.Locale getLocale(javax.servlet.http.HttpServletRequest request)

getText

private java.lang.String getText(javax.servlet.http.HttpServletRequest request,
                                 java.lang.String key,
                                 java.lang.String defaultVal,
                                 java.lang.String arg1,
                                 java.lang.String arg2)
Support for internationalization of exceptions. Throw e.g. ajaxServlet_de.properties into the war CLASSPATH

Parameters:
request -
key - The key to lookup the text
defaultVal - The text to take if not found
arg1 - Can be null
arg2 - Can be null
Returns:
The localized text depending on the browser language

cleanupSession

private void cleanupSession(javax.servlet.http.HttpServletRequest req)

getReqProp

public boolean getReqProp(javax.servlet.http.HttpServletRequest req,
                          java.lang.String key,
                          boolean def)
Access a boolean parameter.

Parameters:
req -
key - The URL key
def - The default if not found
Returns:
boolean support without value: "&admin&name=xy" will return true for admin

doGet

public void doGet(javax.servlet.http.HttpServletRequest req,
                  javax.servlet.http.HttpServletResponse res)
           throws javax.servlet.ServletException,
                  java.io.IOException
 ServletSessionTimeout according to specification:
 The default timeout period for sessions is defined by the servlet container and
        can be obtained via the getMaxInactiveInterval method of the HttpSession
        interface. This timeout can be changed by the Developer using the
        setMaxInactiveInterval method of the HttpSession interface. The timeout
        periods used by these methods are defined in seconds. By definition, if the timeout
        period for a session is set to -1, the session will never expire.
 

We have set the maxInactiveInterval to 1800 sec in web.xml (30 min):

If no Ajax call arrives after the given timeout the servlet-session dies, as a browser user may choose to halt NMEA updates we must set this to a high enough value.

The web.xml setting <session-config> 30 </session-config> is overwritten by our maxInactiveInterval

Test: http://localhost:8080/watchee/ajax?ActionType=request&task=getRawPhoto&locationPictureId=5823&random=0.6236216717670112

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

get

public boolean get(javax.servlet.http.HttpServletRequest req,
                   java.lang.String key,
                   boolean defaultVal)

get

public long get(javax.servlet.http.HttpServletRequest req,
                java.lang.String key,
                long defaultVal)

get

public int get(javax.servlet.http.HttpServletRequest req,
               java.lang.String key,
               int defaultVal)

add

public void add(java.lang.String sessionId,
                BlasterInstance blasterInstance)

removeBlasterInstance

public void removeBlasterInstance(java.lang.String sessionId)

hasBlasterInstance

private BlasterInstance hasBlasterInstance(javax.servlet.http.HttpServletRequest req)
                                    throws XmlBlasterException
Parameters:
req -
Returns:
null if not known
Throws:
XmlBlasterException

getBlasterInstance

private BlasterInstance getBlasterInstance(javax.servlet.http.HttpServletRequest req)
                                    throws XmlBlasterException
Throws:
XmlBlasterException

getServletInfo

public java.lang.String getServletInfo()
Specified by:
getServletInfo in interface javax.servlet.Servlet
Overrides:
getServletInfo in class javax.servlet.GenericServlet

getNumBlasterInstances

public int getNumBlasterInstances()
Specified by:
getNumBlasterInstances in interface AjaxServletMBean

getBlasterInstances

public BlasterInstance[] getBlasterInstances()

destroy

public void destroy()
Specified by:
destroy in interface javax.servlet.Servlet
Overrides:
destroy in class javax.servlet.GenericServlet

log

public void log(java.lang.String text)
Overrides:
log in class javax.servlet.GenericServlet

getContextNode

public ContextNode getContextNode()

cleanupOldSessionsKeepGivenAmount

public java.lang.String cleanupOldSessionsKeepGivenAmount(int maxSessions,
                                                          java.lang.String notificationText,
                                                          boolean creationTimestamp)
Specified by:
cleanupOldSessionsKeepGivenAmount in interface AjaxServletMBean

isBlockedIP

public boolean isBlockedIP(java.lang.String ip)

addBlockedIP

public void addBlockedIP(java.lang.String ip)

clearBlockedIPs

public void clearBlockedIPs()
Specified by:
clearBlockedIPs in interface AjaxServletMBean

getBlockedIPs

public java.lang.String[] getBlockedIPs()
Specified by:
getBlockedIPs in interface AjaxServletMBean

getMaxUserSessions

public int getMaxUserSessions()
Specified by:
getMaxUserSessions in interface AjaxServletMBean

setMaxUserSessions

public void setMaxUserSessions(int maxUserSessions)
Specified by:
setMaxUserSessions in interface AjaxServletMBean

maxUserSessionsReached

public boolean maxUserSessionsReached(javax.servlet.http.HttpServletRequest req)

xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.