org.mmbase.servlet
Class BridgeServlet

Package class diagram package BridgeServlet
java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.mmbase.servlet.MMBaseServlet
              extended by org.mmbase.servlet.BridgeServlet
All Implemented Interfaces:
Serializable, Servlet, ServletConfig, MMBaseStarter
Direct Known Subclasses:
Performance

public abstract class BridgeServlet
extends MMBaseServlet

BridgeServlet is an MMBaseServlet with a bridge Cloud in it. Extending from this makes it easy to implement servlet implemented with the MMBase bridge interfaces. An advantage of this is that security is used, which means that you cannot unintentionly serve content to the whole world which should actually be protected by the security mechanism. Another advantage is that implementation using the bridge is easier/clearer. The query of a bridge servlet can possible start with session= in which case the cloud is taken from that session attribute with that name. Otherewise 'cloud_mmbase' is supposed. All this is only done if there was a session active at all. If not, or the session variable was not found, that an anonymous cloud is used. Object can only be accessed by alias if a mapping on query string is used (so not e.g. /images/*, but /img.db). Normally this is no problem, because the alias is resolved by the image-tag. But if for some reason you need aliases to be working on the URL, you must map to URL's with a question mark.

Since:
MMBase-1.6
Version:
$Id: BridgeServlet.java 45359 2011-02-23 08:33:03Z michiel $
Author:
Michiel Meeuwissen
See Also:
Serialized Form

Nested Class Summary
static class BridgeServlet.QueryParts
          Keeps track of determined information, to avoid redetermining it.
 
Field Summary
static Pattern FILE_PATTERN
          Pattern used for the 'filename' part of the request.
static String MESSAGE_ATTRIBUTE
           
 
Fields inherited from class org.mmbase.servlet.MMBaseServlet
mmbase, retryAfter
 
Constructor Summary
BridgeServlet()
           
 
Method Summary
protected  Node desperatelyGetNode(Cloud cloud, String nodeIdentifier)
          Extensions can override this, to produce a node, even if cloud.hasNode failed.
protected  Cloud findCloud(Cloud c, String nodeNumber, BridgeServlet.QueryParts query)
          Tries to find a Cloud which can read the given node.
protected  Cloud getAnonymousCloud()
          Obtains an 'anonymous' cloud.
protected  Cloud getClassCloud()
          Obtains a cloud using 'class' security.
protected  Cloud getCloud(BridgeServlet.QueryParts qp)
          Obtains a cloud object, using a QueryParts object.
protected  String getCloudName()
          The name of the mmbase cloud which must be used.
protected  long getLastModified(HttpServletRequest req)
          The idea is that a 'bridge servlet' on default serves 'nodes', and that there could be defined a 'last modified' time for nodes.
protected  Node getNode(BridgeServlet.QueryParts query)
          Servlets would often need a node.
protected  Node getServedNode(BridgeServlet.QueryParts qp, Node node)
          If the node associated with the resonse is another node then the node associated with the request.\ (E.g.
 void init()
          Inits lastmodifiedField.
protected  BridgeServlet.QueryParts readQuery(HttpServletRequest req, HttpServletResponse res)
          Creates a QueryParts object which wraps request and response and the parse result of them.
static BridgeServlet.QueryParts readQuery(String query)
           
protected  BridgeServlet.QueryParts readQueryFromRequestURI(HttpServletRequest req, HttpServletResponse res)
           
static BridgeServlet.QueryParts readServletPath(String servletPath)
           
 
Methods inherited from class org.mmbase.servlet.MMBaseServlet
associateMapping, checkInited, decRefCount, destroy, doGet, getAssociations, getBasePath, getMMBase, getRequestURL, getServletByAssociation, getServletByMapping, getServletInfo, getServletMappings, getServletMappingsByAssociation, incRefCount, service, setInitException, setMMBase
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doPut, doTrace, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MESSAGE_ATTRIBUTE

public static final String MESSAGE_ATTRIBUTE
See Also:
Constant Field Values

FILE_PATTERN

public static final Pattern FILE_PATTERN
Pattern used for the 'filename' part of the request. The a node-identifying string may be present in it, and it the one capturing group. It is a digit optionially followed by +.* (used in ImageServlet for url-triggered icache production)

Constructor Detail

BridgeServlet

public BridgeServlet()
Method Detail

getCloudName

protected String getCloudName()
The name of the mmbase cloud which must be used. At the moment this is not supported (every mmbase cloud is called 'mmbase').


readQuery

protected BridgeServlet.QueryParts readQuery(HttpServletRequest req,
                                             HttpServletResponse res)
                                      throws IOException
Creates a QueryParts object which wraps request and response and the parse result of them.

Returns:
A QueryParts or null if something went wrong (in that case an error was sent, using the response).
Throws:
IOException

readQueryFromRequestURI

protected BridgeServlet.QueryParts readQueryFromRequestURI(HttpServletRequest req,
                                                           HttpServletResponse res)
                                                    throws IOException
Throws:
IOException

readServletPath

public static BridgeServlet.QueryParts readServletPath(String servletPath)
Since:
MMBase-1.7.4

readQuery

public static BridgeServlet.QueryParts readQuery(String query)
Since:
MMBase-1.7.4

getCloud

protected final Cloud getCloud(BridgeServlet.QueryParts qp)
Obtains a cloud object, using a QueryParts object.

Returns:
A Cloud or null if unsuccessful (this may not be fatal).

getAnonymousCloud

protected final Cloud getAnonymousCloud()
Obtains an 'anonymous' cloud.


getClassCloud

protected Cloud getClassCloud()
Obtains a cloud using 'class' security. If e.g. you authorize org.mmbase.servlet.ImageServlet by class-security for read all rights, it will be used.

Since:
MMBase-1.8

findCloud

protected Cloud findCloud(Cloud c,
                          String nodeNumber,
                          BridgeServlet.QueryParts query)
                   throws IOException
Tries to find a Cloud which can read the given node.

Throws:
IOException
Since:
MMBase-1.8

getNode

protected final Node getNode(BridgeServlet.QueryParts query)
                      throws IOException
Servlets would often need a node. This function provides it.

Parameters:
query - A QueryParts object, which you must have obtained by readQuery(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
Throws:
IOException

desperatelyGetNode

protected Node desperatelyGetNode(Cloud cloud,
                                  String nodeIdentifier)
Extensions can override this, to produce a node, even if cloud.hasNode failed. ('title aliases' e.g.).

Since:
MMBase-1.7.5

getServedNode

protected Node getServedNode(BridgeServlet.QueryParts qp,
                             Node node)
                      throws IOException
If the node associated with the resonse is another node then the node associated with the request.\ (E.g. a icache based on a url with an image node).

Parameters:
qp - A QueryParts object, which you must have obtained by readQuery(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
node - The node which is specified on the URL (obtained by getNode(org.mmbase.servlet.BridgeServlet.QueryParts)
Throws:
IOException
Since:
MMBase-1.7.4

getLastModified

protected long getLastModified(HttpServletRequest req)
The idea is that a 'bridge servlet' on default serves 'nodes', and that there could be defined a 'last modified' time for nodes. This can't be determined right now, so 'now' is returned. This function is defined in HttpServlet

Overrides:
getLastModified in class HttpServlet

init

public void init()
          throws ServletException
Inits lastmodifiedField. The init of an MMBaseServlet checks if MMBase is running. It not then it is started.

Overrides:
init in class MMBaseServlet
Throws:
ServletException


MMBase2 Core 2.0-SNAPSHOT - 2013-11-29T11:08