jacquard 1.12.0 by The Web Engineering Factory and Toolworks

uk.co.weft.htform
Class Servlet

java.lang.Object
  extended byjavax.servlet.GenericServlet
      extended byjavax.servlet.http.HttpServlet
          extended byuk.co.weft.maybeupload.MaybeUploadServlet
              extended byuk.co.weft.htform.Servlet
All Implemented Interfaces:
ResourceConsumer, java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
DataTable, Graphic, ICalServlet, Stylist, Thumbnail, WithExceptionHandlerServlet

public abstract class Servlet
extends MaybeUploadServlet
implements ResourceConsumer

This is a basic servlet which produces nothing; to produce anything, specialise generateContent(). A Servlet may have a database connection -- it has all the glue. but it does not whinge if it hasn't got one. Specialised sub-classes do that whinging.

A note on the security model: this class does not currently support database level security, as connections are cached in a pool for re-use and may be re-used in other sessions with other browsers. Prepared queries are also attached to sessions in the public pool. If security is a consideration use AuthenticatedForm.

This class (and consequently all servlets which are subclasses of this class) know about the following configuration parameters:

content_type
String: the mime type of the output of this servlet. Optional. Defaults to 'text/html'.
cookie_domain
String: the domain for cookies created by this servlet. Usually the hostname of the server. Must be prefixed by a dot. Optional. No default.
cookie_path
String: the path for cookies created by this servlet. Usually the name of the webapp of which this servlet forms a part. Optional. Defaults to "/" (anywhere on this server)
cookie_ttl
Integer: the time to live for cookies created by this servlet, in seconds. Optional, defaults to one day.
cookies
String: a space separated list of initial cookies to set up, if any. Note that you can only specify the cookie names, the values must come from the context (although as the config forms part of the context you could specify them separately in the config). Optional. No default.
countrycode
String: the countrycode to use to calculate the locale. Optional. Defaults to UK.
driver_name
String: the class name of the JDBC database driver to use. Required if a database is used. No default.
db_password
String: the password to be used to communicate with the database. Optional, but see AuthenticatedForm. May be passed in the context.
db_username
String: the username to be used to communicate with the database. Optional, but see AuthenticatedForm. May be passed in the context.
db_url
String: the JDBC URL to use to communicate with the database. Required if a database is used. No default.
debug
Boolean. If 'true', turn on context dumps when exceptions are reported, and insert other debugging information as comments. WARNING! This is extremely insecure! You absolutely should not use this option on a production system!
first_time_redirect
String: the relative URL of a servlet to redirect to if this is the first time this webapp has been used. Optional. Defaults to servlet/firsttime.
identity
String: the identity string to be returned by this servlet in the getServletInfo() call. Optional. Defaults to Created using Jacquard
language
String: the language to use to calculate the locale. Optional. Defaults to "EN" (English).
parse_path_info
String: space separated list of tokens which may safely be parsed out of the URL path-part. If set to (e.g.) foo and the servlet has an appropriate servlet mapping, http://host/webapp/servlet/foo_bar.html is handled in exactly the same way as http://host/webapp/servlet?foo=bar. Optional. No default (i.e. the path info will not be parsed).
resource_bundle_name
String: the base name of the resource bundle which will be used for internationalisation of messages, etc. Optional. Defaults to jacquard. The appropriate resouce bundle must of course be on the classpath.
timezone
String: the timezone to use to parse and display dates and times. Optional. Defaults to "BST".

Note that as of revision 1.24 (Jacquard 1.4.6), Servlet (and all classes inheriting from it) will support Secure Sockets Layer (HTTPS) connections, but only if you are using Java 1.4 or have JSSE loaded. If you don't, the SSL code will report this in the log on startup, but will not interfere with standard HTTP operation.

Version:
$Revision: 1.51.4.5 $ This revision: $Author: simon $
Author:
Simon Brooke
See Also:
AuthenticatedForm, Serialized Form

Field Summary
protected  java.util.GregorianCalendar calendar
          handy to have a calendar around to help with manipulating dates
protected  javax.servlet.ServletConfig conf
          My configuration object, passed to me when I was created
protected  java.lang.String contentType
          the MIME type of my content
static java.lang.String CONTENTTYPECONFIGTOKEN
          a configuration token on which I will seek my content type specifier in my configuraton
protected  java.lang.String cookieDomain
          the domain for my cookies
protected  java.lang.String cookiePath
          the path for my cookies
static java.lang.String COOKIESCONFIGTOKEN
          a configuration token on which I will seek the names of any initial cookies to set in my configuraton
protected  int cookieTTL
          the default time-to-live of cookies
protected  java.lang.String dbPassword
          and password to connect me to the database, if any
protected  java.lang.String dbUrl
          where to find the database: there is no safe default.
protected  java.lang.String dbUsername
          the username...
protected  boolean debug
          print additional diagnostics on error
static java.lang.String DEBUGCONFIGTOKEN
          a configuration token on which I will check whether to run in debugging mode
protected  java.lang.String driverName
          the classname of my database driver, if any
protected  boolean embedded
          whether I am embedded in an existing (e.g.
protected  java.util.Locale here
          where we are operating - defaults to UK english
protected  java.lang.String identity
          my identity
static java.lang.String localeMagicToken
          Deprecated. use LOCALEMAGICTOKEN
static java.lang.String LOCALEMAGICTOKEN
          the magic token on which to store the request locale in the context, once we have computed it.
static java.lang.String outputStreamMagicToken
          Deprecated. use OUTPUTSTREAMMAGICTOKEN
static java.lang.String OUTPUTSTREAMMAGICTOKEN
          The magic token on which I store my output stream in the context
protected  Context parsePathInfo
          a hashtable of keys I'm prepared to parse out of the path info string
static java.lang.String PATHINFOMAGICTOKEN
          the magic token on which I will store the path info in the context
protected  boolean ready
          Flag to say whether second-stage initialisation is complete.
static java.lang.String redirectMagicToken
          Deprecated. use REDIRECTMAGICTOKEN
static java.lang.String REDIRECTMAGICTOKEN
          The magic token on which to store where to redirect to after a service.
static java.lang.String requestMagicToken
          Deprecated. use REQUESTMAGICTOKEN
static java.lang.String REQUESTMAGICTOKEN
          the token on which I store my request in the context
protected  java.lang.String resourceBundleName
          the name of the resource bundle I will search for resources.
static java.lang.String responseMagicToken
          Deprecated. use RESPONSEMAGICTOKEN
static java.lang.String RESPONSEMAGICTOKEN
          the token on which I store my response in the context
static java.lang.String servletMagicToken
          Deprecated. use SERVLETMAGICTOKEN
static java.lang.String SERVLETMAGICTOKEN
          the token on which I store my servlet in the context
static java.lang.String sessionMagicToken
          Deprecated. use SESSIONMAGICTOKEN
static java.lang.String SESSIONMAGICTOKEN
          the token on which I store my session in the context
static java.lang.String USEHTTPSCONFIGTOKEN
          a token in which I shall look in my config for whether or not to handle HTTPS in the Servlet.
protected  java.util.TimeZone zone
          the timezone in which we are operating -defaults to BST
 
Fields inherited from class uk.co.weft.maybeupload.MaybeUploadServlet
allowOverwrite, maxUpload, saveUploadedFilesToDisk, silentlyRename, uploadDir, uploadDirPath, uploadDirURL
 
Fields inherited from interface uk.co.weft.htform.ResourceConsumer
RESOURCEBUNDLEMAGICTOKEN
 
Constructor Summary
Servlet()
           
 
Method Summary
protected  void addCookie(java.lang.String name)
          To use cookies, add named cookies using this method; do this once, at initialisation time, not each service.
protected  void addCookie(java.lang.String name, int ttl)
          add a new cookie with this expiration period in seconds
protected  Context coerceCookiesToContext(javax.servlet.http.HttpServletRequest req)
          Coerce cookies from a servlet request to a context, so we can handle them generically
protected  Context coerceToContext(javax.servlet.http.HttpSession other)
          Coerce this HTTPSession to a Context, so we can handle it generically
protected  Context coerceToContext(javax.servlet.ServletConfig other)
          Coerce this ServletConfig to a Context, so that we can handle it generically
protected  Context coerceToContext(javax.servlet.ServletContext other)
          This is where terminology really gets confusing, and vague names like 'context' don't really help: ServletContext is a Servlet 2.2 spec term which refers to what JServ called a servlet zone, which contains a configuration namespace, whereas our Context is just a namespace.
protected  Context coerceToContext(javax.servlet.ServletRequest other)
          Coerce this servlet request to a Context, so we can handle it generically; if I accept values passed in the pathInfo, parse for them as well (first)
protected  java.net.URL coerceToUrl(java.lang.String spec)
          coerce this string to a valid URL.
protected  Context createContext(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Create a context object.
protected  void doGet(MaybeUploadRequestWrapper req, javax.servlet.http.HttpServletResponse res)
          Really perform service of an HTTP GET request, by printing myself on the response stream
protected  void doPost(MaybeUploadRequestWrapper req, javax.servlet.http.HttpServletResponse res)
          Really perform service of an HTTP POST request, by printing myself on the response stream
protected  Context fixupMagicValues(Context context, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Fix up the magic values stored on the context by this class.
protected abstract  void generateContent(Context context)
          Specialise! Do not use! Output the whole document including headers
 java.util.Calendar getCalendar()
          Return my calendar, surprisingly enough; this contains my localisation stuff.
protected  java.lang.String getContentType(Context context)
          Return my content type in this context.
 boolean getDebug()
           
 java.util.Locale getLocale(Context context)
          get the client-side locale if it can be deduced from the context, else server side.
 javax.servlet.ServletOutputStream getOutputStream(Context context)
          a convenience method for getting hold of the ServletOutputStream I should have put into the context -- asuming this context is mine, of course
 java.lang.Object getResource(java.lang.String key, Context context)
          Deprecated. i18n code is still experimental and the only call I commit to supporting in the longer term is grs(String,Context)
 java.lang.String getResourceString(java.lang.String key, Context context)
          Deprecated. i18n code is still experimental and the only call I commit to supporting in the longer term is grs(String,Context)
 java.lang.String getServletInfo()
          tell the world about me.
 java.lang.String grs(java.lang.String key)
          Deprecated. use grs(String,Context)
 java.lang.String grs(java.lang.String key, Context context)
          shorthand for getResourceString; identical to it.
protected  void handleAction(Context context)
          Intended to handle actions implied by the context before the page is served; for example, different submit buttons with different actions.
protected  void handleCookies(Context context)
          Sort out the business of sending and receiving cookies
 boolean handleRedirect(Context context)
          Set up redirect headers if context contains a valid URL as the value of redirectMagicToken; return true in this case.
 void init(Context config)
          Basic initialisation, taking my configuration from this Context
 void init(javax.servlet.ServletConfig config)
          Initialisation: Set up my variables from my configuration.
protected  void makeReady(Context context)
          Second-stage initialisation hook.
protected  void outputRedirectBlock(Context context)
          Possibly output a stub HTML page with a 'refresh' meta.
 void setCookieValues(Context context)
          To use cookies, add named cookies using addCookie(); do this once, at initialisation time, not each service.
protected  void storeOnSession(Context context, java.lang.String key, java.lang.String value)
          Deprecated. still experimental; may not be supported in future
protected  void whinge(javax.servlet.ServletOutputStream out, java.lang.Exception e)
          Deprecated. you really, really ought to be passing a context
protected  void whinge(javax.servlet.ServletOutputStream out, java.lang.Exception e, Context context)
          Last line-of-defence error reporter.
 
Methods inherited from class uk.co.weft.maybeupload.MaybeUploadServlet
doDelete, doHead, doOptions, doPut, doTrace, getUploadDir, getUploadURL, service
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, 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

CONTENTTYPECONFIGTOKEN

public static final java.lang.String CONTENTTYPECONFIGTOKEN
a configuration token on which I will seek my content type specifier in my configuraton

See Also:
Constant Field Values

COOKIESCONFIGTOKEN

public static final java.lang.String COOKIESCONFIGTOKEN
a configuration token on which I will seek the names of any initial cookies to set in my configuraton

See Also:
Constant Field Values

DEBUGCONFIGTOKEN

public static final java.lang.String DEBUGCONFIGTOKEN
a configuration token on which I will check whether to run in debugging mode

Since:
Jacquard 1.10.12
See Also:
Constant Field Values

LOCALEMAGICTOKEN

public static final java.lang.String LOCALEMAGICTOKEN
the magic token on which to store the request locale in the context, once we have computed it. The value I put there will be a java.util.Locale and you can rely on this unless you break it

See Also:
Constant Field Values

OUTPUTSTREAMMAGICTOKEN

public static final java.lang.String OUTPUTSTREAMMAGICTOKEN
The magic token on which I store my output stream in the context

See Also:
Constant Field Values

PATHINFOMAGICTOKEN

public static final java.lang.String PATHINFOMAGICTOKEN
the magic token on which I will store the path info in the context

See Also:
Constant Field Values

REDIRECTMAGICTOKEN

public static final java.lang.String REDIRECTMAGICTOKEN
The magic token on which to store where to redirect to after a service. If you set this to a URL in (for example) the store( Context) method of a TableWrapperForm, after storing it will cause the browser to redirect to that URL

See Also:
Constant Field Values

REQUESTMAGICTOKEN

public static final java.lang.String REQUESTMAGICTOKEN
the token on which I store my request in the context

See Also:
Constant Field Values

RESPONSEMAGICTOKEN

public static final java.lang.String RESPONSEMAGICTOKEN
the token on which I store my response in the context

See Also:
Constant Field Values

SERVLETMAGICTOKEN

public static final java.lang.String SERVLETMAGICTOKEN
the token on which I store my servlet in the context

See Also:
Constant Field Values

SESSIONMAGICTOKEN

public static final java.lang.String SESSIONMAGICTOKEN
the token on which I store my session in the context

See Also:
Constant Field Values

USEHTTPSCONFIGTOKEN

public static final java.lang.String USEHTTPSCONFIGTOKEN
a token in which I shall look in my config for whether or not to handle HTTPS in the Servlet. You almost certainly don't want to do this, it is better handled by Apache.

Since:
Jacquard 1.10.19; prior to that HTTPS code was included anyway.
See Also:
Constant Field Values

requestMagicToken

public static final java.lang.String requestMagicToken
Deprecated. use REQUESTMAGICTOKEN

the token on which I store my request in the context

See Also:
Constant Field Values

responseMagicToken

public static final java.lang.String responseMagicToken
Deprecated. use RESPONSEMAGICTOKEN

the token on which I store my response in the context

See Also:
Constant Field Values

servletMagicToken

public static final java.lang.String servletMagicToken
Deprecated. use SERVLETMAGICTOKEN

the token on which I store my servlet (myself) in the context

See Also:
Constant Field Values

sessionMagicToken

public static final java.lang.String sessionMagicToken
Deprecated. use SESSIONMAGICTOKEN

the token on which I store my session in the context

See Also:
Constant Field Values

outputStreamMagicToken

public static final java.lang.String outputStreamMagicToken
Deprecated. use OUTPUTSTREAMMAGICTOKEN

The magic token on which I store my output stream in the context

See Also:
Constant Field Values

redirectMagicToken

public static final java.lang.String redirectMagicToken
Deprecated. use REDIRECTMAGICTOKEN

The magic token on which to store where to redirect to after a service. If you set this to a URL in (for example) the store( Context) method of a TableWrapperForm, after storing it will cause the browser to redirect to that URL.

See Also:
Constant Field Values

localeMagicToken

public static final java.lang.String localeMagicToken
Deprecated. use LOCALEMAGICTOKEN

the magic token on which to store the request locale in the context, once we have computed it. The value I put there will be a java.util.Locale and you can rely on this unless you break it.

See Also:
Constant Field Values

parsePathInfo

protected Context parsePathInfo
a hashtable of keys I'm prepared to parse out of the path info string


calendar

protected java.util.GregorianCalendar calendar
handy to have a calendar around to help with manipulating dates


here

protected java.util.Locale here
where we are operating - defaults to UK english


conf

protected javax.servlet.ServletConfig conf
My configuration object, passed to me when I was created


contentType

protected java.lang.String contentType
the MIME type of my content


cookieDomain

protected java.lang.String cookieDomain
the domain for my cookies


cookiePath

protected java.lang.String cookiePath
the path for my cookies


dbPassword

protected java.lang.String dbPassword
and password to connect me to the database, if any


dbUrl

protected java.lang.String dbUrl
where to find the database: there is no safe default.


dbUsername

protected java.lang.String dbUsername
the username...


driverName

protected java.lang.String driverName
the classname of my database driver, if any


identity

protected java.lang.String identity
my identity


resourceBundleName

protected java.lang.String resourceBundleName
the name of the resource bundle I will search for resources. By default, 'jacquard'


zone

protected java.util.TimeZone zone
the timezone in which we are operating -defaults to BST


debug

protected boolean debug
print additional diagnostics on error


embedded

protected boolean embedded
whether I am embedded in an existing (e.g. JHTML) page


ready

protected boolean ready
Flag to say whether second-stage initialisation is complete. Problem is many servlets have initialisation things they can only do when they have a connection, and at init() time they don't have. This is a hook to allow them to do that. You really, really do not want to mess with this.


cookieTTL

protected int cookieTTL
the default time-to-live of cookies

Constructor Detail

Servlet

public Servlet()
Method Detail

getCalendar

public java.util.Calendar getCalendar()
Return my calendar, surprisingly enough; this contains my localisation stuff.

Returns:
my calendar.

setCookieValues

public void setCookieValues(Context context)
To use cookies, add named cookies using addCookie(); do this once, at initialisation time, not each service. To set cookies values at service time, specialise this method -- the default one does nothing. Simply use context.setValue( name_of_cookie).

Parameters:
context - the context in which the cookie values will be set.

getDebug

public boolean getDebug()
Returns:
the current value of my debug field

getLocale

public java.util.Locale getLocale(Context context)
get the client-side locale if it can be deduced from the context, else server side.


getOutputStream

public javax.servlet.ServletOutputStream getOutputStream(Context context)
a convenience method for getting hold of the ServletOutputStream I should have put into the context -- asuming this context is mine, of course

Parameters:
context - the context to look in for the stream
Returns:
the output stream if there is one in the context and it is a ServletOutputStream, else null

getResource

public java.lang.Object getResource(java.lang.String key,
                                    Context context)
Deprecated. i18n code is still experimental and the only call I commit to supporting in the longer term is grs(String,Context)

return the value of the resource with the given key as whatever sort of object it happens to be. In the end if the resource cannot be found throw an exception.

Specified by:
getResource in interface ResourceConsumer
Parameters:
key - the key to search for
context - teh context in which to make request; may contain locale information
Returns:
a locale-sepecific value for key, if found, else the key itself.

getResourceString

public java.lang.String getResourceString(java.lang.String key,
                                          Context context)
Deprecated. i18n code is still experimental and the only call I commit to supporting in the longer term is grs(String,Context)

return as a string the value of the resource with the given key. If in the end the resource cannot be found just return the key.

Specified by:
getResourceString in interface ResourceConsumer
Parameters:
key - the key to search for
context - the context in which to make this call (may contain locale information)
Returns:
a locale-sepecific value for key, if found, else the key itself.

getServletInfo

public java.lang.String getServletInfo()
tell the world about me.

Specified by:
getServletInfo in interface javax.servlet.Servlet
Returns:
my identity string.

grs

public java.lang.String grs(java.lang.String key,
                            Context context)
shorthand for getResourceString; identical to it.

Specified by:
grs in interface ResourceConsumer
See Also:
#getResourceString(String)

grs

public java.lang.String grs(java.lang.String key)
Deprecated. use grs(String,Context)

In Jacquard 1.8 I had a one arg grs(); this is here for backwards compatibility only. I still haven't fully sussed the best way to do i18n, and this way only does server-side i18n which definitely isn't good enough. But since I published the API I'd better support it.

Specified by:
grs in interface ResourceConsumer

handleRedirect

public boolean handleRedirect(Context context)
                       throws java.net.MalformedURLException,
                              java.io.IOException
Set up redirect headers if context contains a valid URL as the value of redirectMagicToken; return true in this case. If no value or value not a valid URL return false.

Parameters:
context - the context for this service
Returns:
a flag indicating whether a redirect has been handled
Throws:
java.io.IOException - may be passed through from outputRedirectBlock
java.net.MalformedURLException - if value of redirectMagicToken in context is not a valid (relative) URL

init

public final void init(javax.servlet.ServletConfig config)
                throws javax.servlet.ServletException
Initialisation: Set up my variables from my configuration. If a database connection is specified in my config, attempt to set it up. The database connection may fail. If it does, it fails silently; a Servlet is not by default guaranteed to have a connection. Subclasses which do require a connection should call super.init(), and then call try getConnection(): if getConnection() throws an Exception, then the subclass should throw an UnavailableException

Specified by:
init in interface javax.servlet.Servlet
Overrides:
init in class MaybeUploadServlet
Parameters:
config - my Servlet configuration.
Throws:
javax.servlet.ServletException - doesn't; thing which specialise me may

init

public void init(Context config)
          throws InitialisationException
Basic initialisation, taking my configuration from this Context

Throws:
InitialisationException

getContentType

protected java.lang.String getContentType(Context context)
Return my content type in this context. The default method simply returns the value of the contentType iv; specialise if you need to compute the content type.

Returns:
my content type in this context.

addCookie

protected void addCookie(java.lang.String name)
To use cookies, add named cookies using this method; do this once, at initialisation time, not each service. To set cookies values at service time, specialise setCookieValues() q.v. creates a new cookie object and adds it to my cookies Vector. Do not use the cookie mechanisms in htform unless to pass values to non-htform dynamic content. Simply put persistent values on the Context instead.

Parameters:
name - the name of the cookie to set - also, the name which contexts will be searched on to provide the cookie value.

addCookie

protected void addCookie(java.lang.String name,
                         int ttl)
add a new cookie with this expiration period in seconds

Parameters:
name - the name of the cookie to set - also, the name which contexts will be searched on to provide the cookie value.
ttl - time to live for this cookie in seconds.

coerceCookiesToContext

protected Context coerceCookiesToContext(javax.servlet.http.HttpServletRequest req)
Coerce cookies from a servlet request to a context, so we can handle them generically

Parameters:
req - the ServletRequest to coerce.
Returns:
the context.

coerceToContext

protected Context coerceToContext(javax.servlet.ServletContext other)
This is where terminology really gets confusing, and vague names like 'context' don't really help: ServletContext is a Servlet 2.2 spec term which refers to what JServ called a servlet zone, which contains a configuration namespace, whereas our Context is just a namespace. Note that the code of this method is identical to the ServletConfig variant... I do wish Sun had required these things to implement (

Parameters:
other - the ServletContext to coerce.
Returns:
the context.
See Also:
Map

coerceToContext

protected Context coerceToContext(javax.servlet.ServletConfig other)
Coerce this ServletConfig to a Context, so that we can handle it generically

Parameters:
other - the ServletConfig to coerce.
Returns:
the context.

coerceToContext

protected Context coerceToContext(javax.servlet.http.HttpSession other)
                           throws javax.servlet.ServletException
Coerce this HTTPSession to a Context, so we can handle it generically

Parameters:
other - the HttpSession to coerce.
Returns:
a context
Throws:
javax.servlet.ServletException

coerceToContext

protected Context coerceToContext(javax.servlet.ServletRequest other)
                           throws javax.servlet.ServletException
Coerce this servlet request to a Context, so we can handle it generically; if I accept values passed in the pathInfo, parse for them as well (first)

Parameters:
other - the ServletRequest to coerce.
Returns:
the context.
Throws:
javax.servlet.ServletException

createContext

protected Context createContext(javax.servlet.http.HttpServletRequest request,
                                javax.servlet.http.HttpServletResponse response)
                         throws DataStoreException,
                                javax.servlet.ServletException
Create a context object. Done in a separate method so that subclasses can do their own special thing in populating the context; however, rather than specialising this it may be better (and simpler) to specialise fixupMagicValues q.v.

Note that it is this class which establishes the precedence (masking) of values as they appear in the context, namely:

Parameters:
request - the request object for this service
response - the response object for this service
Returns:
a context constructed around this request and response
Throws:
No - , I know this doesn't actually throw an exception. But things which specialise me may want to.
DataStoreException
javax.servlet.ServletException
See Also:
fixupMagicValues(uk.co.weft.dbutil.Context, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

fixupMagicValues

protected Context fixupMagicValues(Context context,
                                   javax.servlet.http.HttpServletRequest request,
                                   javax.servlet.http.HttpServletResponse response)
Fix up the magic values stored on the context by this class. Specialisations are strongly urged to start with a call to super.fixupMagicValues() - do this unless you're really sure you know what you are doing, otherwise horrible things will happen. You have been warned.

Parameters:
context - the context in which the values are to be fixed
request - the request for this service
response - the response to this request
Returns:
the same context.

generateContent

protected abstract void generateContent(Context context)
                                 throws java.lang.Exception
Specialise! Do not use! Output the whole document including headers

Parameters:
context - the context in which to generate this content.
Throws:
java.lang.Exception

coerceToUrl

protected java.net.URL coerceToUrl(java.lang.String spec)
                            throws java.net.MalformedURLException
coerce this string to a valid URL.

Parameters:
spec - a string representing a URL or a full or relative file path name; if relative, relative to the document root of my web-app.
Returns:
a URL representation of the spec
Throws:
java.net.MalformedURLException - if the string cannot be coerced to a valid URL

doGet

protected void doGet(MaybeUploadRequestWrapper req,
                     javax.servlet.http.HttpServletResponse res)
              throws javax.servlet.ServletException,
                     java.io.IOException
Really perform service of an HTTP GET request, by printing myself on the response stream

Overrides:
doGet in class MaybeUploadServlet
Parameters:
req - the request object for this service
res - the response object for this service
Throws:
javax.servlet.ServletException
java.io.IOException

doPost

protected void doPost(MaybeUploadRequestWrapper req,
                      javax.servlet.http.HttpServletResponse res)
               throws javax.servlet.ServletException,
                      java.io.IOException
Really perform service of an HTTP POST request, by printing myself on the response stream

Overrides:
doPost in class MaybeUploadServlet
Parameters:
req - a request wrapper which know how to handle upload
res - a standard servlet response
Throws:
javax.servlet.ServletException
java.io.IOException

handleAction

protected void handleAction(Context context)
                     throws java.lang.Exception
Intended to handle actions implied by the context before the page is served; for example, different submit buttons with different actions. Specialise, if you want to do any action handling. Default does nothing.

Parameters:
context - the context for this service.
Throws:
doesn - 't actually throw an exception but things which specialise it may want to
java.lang.Exception
See Also:
Form.handleAction(uk.co.weft.dbutil.Context)

handleCookies

protected void handleCookies(Context context)
                      throws javax.servlet.ServletException,
                             java.io.IOException
Sort out the business of sending and receiving cookies

Parameters:
context - the context for this service, from which cookie values will be read and into which cookie values will be set.
Throws:
javax.servlet.ServletException
java.io.IOException

makeReady

protected void makeReady(Context context)
                  throws DataStoreException,
                         javax.servlet.ServletException
Second-stage initialisation hook. Problem is many servlets have initialisation things they can only do when they have a connection, and at init() time they don't have. This is a hook to allow them to do that. Specialisations must set the flag, and are advised to do so with a super.makeReady() call.

Parameters:
context - my first context.
Throws:
Specialisations - may want to throw exceptions for various reasons, which is why the possibility of a ServletException or DataStoreException is provided for.
DataStoreException
javax.servlet.ServletException

outputRedirectBlock

protected void outputRedirectBlock(Context context)
                            throws java.io.IOException
Possibly output a stub HTML page with a 'refresh' meta. Should be redundent, because only output it a type 302 response has already been sent, so should never be seen... but does no harm

Parameters:
context - the context for this service
Throws:
java.io.IOException - if output barfs.

storeOnSession

protected void storeOnSession(Context context,
                              java.lang.String key,
                              java.lang.String value)
                       throws DataStoreException
Deprecated. still experimental; may not be supported in future

Sometimes the best way to pass a value around is to store it explicitly on the session. Using hidden widgets to pass values around is insecure because users can inspect page source, and is in any case not persistent. Values stored on the session can of course be retrieved by context.get(String) but will be masked there by values from cookies or the service.

Parameters:
context - the context in which this is being passed around
key - the key against which the value should be stored
value - the value to store
Throws:
DataStoreException - if no session can be found; may become more specialised exception in mature implementation
Since:
Jacquard 1.10.10

whinge

protected void whinge(javax.servlet.ServletOutputStream out,
                      java.lang.Exception e,
                      Context context)
               throws javax.servlet.ServletException
Last line-of-defence error reporter.

Parameters:
out - an output stream to print on
e - an exception to whinge about
context - the context in which the problem occurred.
Throws:
javax.servlet.ServletException

whinge

protected void whinge(javax.servlet.ServletOutputStream out,
                      java.lang.Exception e)
               throws javax.servlet.ServletException,
                      java.io.IOException
Deprecated. you really, really ought to be passing a context

Last line-of-defence error reporter.

Parameters:
out - an output stream to print on
e - an exception to whinge about
Throws:
javax.servlet.ServletException
java.io.IOException

jacquard 1.12.0 by The Web Engineering Factory and Toolworks