public abstract class WebContext extends Object
Modifier and Type | Field and Description |
---|---|
static int |
CACHE_PRIORITY
Priority for the server cache web method.
|
static ServletContext |
context |
static int |
HANDLERS
Priority to use for handlers.
|
(package private) static String |
JWIG_DEFUNCT_SESSION |
Logger |
log
Logger.
|
static int |
MAX_PRIORITY
Priority for the main web method.
|
static int |
PRE_CACHE
Priority to use for web methods to be executed before the server cache,
such as authentication methods.
|
Constructor and Description |
---|
WebContext()
Constructs a new empty web context object.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addCookie(Cookie c,
boolean send_now)
Adds a cookie to the response.
|
static void |
addResponseInvalidator(Object obj)
Registers the given object as observable for the response.
|
Object |
augment()
Augments the current XML response with script code, JWIG logo, and web
app params.
|
Object |
cache()
Server cache web method.
|
protected String |
getCacheAugmentedString(String url) |
Cookie[] |
getCookies()
Returns (non-null) array of cookies from the request.
|
static URL |
getRequestURL()
Returns the URL of the current request.
|
static Response |
getResponse()
Returns the current response object.
|
static ServletContext |
getServletContext()
Returns the
ServletContext object. |
static HttpServletRequest |
getServletRequest()
Returns the
HttpServletRequest object. |
static HttpServletResponse |
getServletResponse()
Returns the
HttpServletResponse object. |
User |
getUser()
Gets the user for the request, using HTTP Basic authentication.
|
protected String |
getWebAppParam(String name)
Gets the string representation of the web app parameter with this name
|
<E> E |
getWebAppParam(String name,
Class<E> type)
Returns the web app parameter of the given name.
|
static URL |
getWebAppURL(boolean secure)
Generates a URL for the root of the current web application.
|
WebSite |
getWebSite()
Returns the web site object.
|
static URL |
getWebSiteURL()
Generates a URL for the root of this website.
|
static URL |
getWebSiteURL(boolean secure)
Generates a URL for the root of the web site.
|
Object |
handlers()
Invoked automatically from generated XML pages for executing a handler.
|
void |
handleUpdatedObjects()
Invalidates pages in the cache based on which objects are updated
|
boolean |
isSecure()
Checks whether the request was made using a secure channel, such as
SSL/TLS.
|
void |
jwigJS() |
Object |
main()
Main web method.
|
static URL |
makeURL(boolean secure,
Class<? extends WebApp> cl,
Map<String,?> webapp_args,
String method,
Object... args)
Generates a URL for the given web method within the same web site and in
the given web app, with web app arguments.
|
static URL |
makeURL(boolean secure,
Class<? extends WebApp> cl,
String method,
Object... args)
Generates a URL for the given web method within the same web site and in
the given web app.
|
static URL |
makeURL(boolean secure,
Map<String,?> webapp_args,
String method,
Object... args)
Generates a URL for the given web method within the same web site, with
web app arguments.
|
static URL |
makeURL(boolean secure,
String method,
Object... args)
Generates a URL for the given web method within the same web site.
|
static URL |
makeURL(Class<? extends WebApp> cl,
String method,
Object... args)
Generates a URL for the given web method within the same web site and in
the given web app.
|
static URL |
makeURL(Map<String,?> webapp_args,
String method,
Object... args)
Generates a URL for the given web method within the same web site, with
web app arguments.
|
static URL |
makeURL(String method,
Object... args)
Generates a URL for the given web method within the same web site.
|
static Object |
next()
Invokes the next web method in the chain.
|
static void |
punish(String key) |
SendFailedException |
sendEmail(Email message)
Sends an email using JavaMail.
|
List<SendFailedException> |
sendEmails(List<Email> messages)
Sends a collection of emails.
|
List<SendFailedException> |
sendEmailsAsynchronously(List<Email> messages)
Works like
sendEmails(java.util.List) but sends the emails in a
separate thread. |
static void |
sendResponse()
Sends the current response.
|
String |
touchSessions(Session[] s)
Invoked automatically from generated XML pages for refreshing active
sessions.
|
void |
transportSessionHandlers()
If a piece of XML contains a handler and this piece of XML is stored in a session
between requests, we need to make sure that the handler is transported
from one request to the next.
An example of this pattern exists in the guessing game example of jwig, where XML is stored in the session and updated from one request to the next. |
static void |
update(Object obj)
Informs observers that the given object has been updated.
|
public static final int CACHE_PRIORITY
cache()
,
Constant Field Valuespublic static ServletContext context
public static final int HANDLERS
handlers()
,
Constant Field Valuesstatic final String JWIG_DEFUNCT_SESSION
public final Logger log
public static final int MAX_PRIORITY
main()
,
Constant Field Valuespublic static final int PRE_CACHE
protected void addCookie(Cookie c, boolean send_now)
send_now
- if set, the cookie is sent immediately without storing it in
the response cachepublic static void addResponseInvalidator(Object obj)
@URLPattern(value="**") @Priority(value=2147483646) @GET @POST @PUT @DELETE @TRACE @HEAD public Object augment()
@GET @URLPattern(value="**") @Priority(value=500) public Object cache()
If-Modified-Since
and ETag
) and
whether the requested resource is in the server cache. Only considers GET
requests. Invokes next()
if a valid cached resource is not
available.public Cookie[] getCookies()
public static URL getRequestURL()
public static Response getResponse()
public static ServletContext getServletContext()
ServletContext
object.public static HttpServletRequest getServletRequest()
HttpServletRequest
object.public static HttpServletResponse getServletResponse()
HttpServletResponse
object.public User getUser()
protected String getWebAppParam(String name)
public <E> E getWebAppParam(String name, Class<E> type)
public static URL getWebAppURL(boolean secure)
secure
- if true, use https
, otherwise http
public final WebSite getWebSite()
public static URL getWebSiteURL()
public static URL getWebSiteURL(boolean secure)
secure
- if true, use https
, otherwise http
@Priority(value=0) @URLPattern(value="handlers/*") public Object handlers() throws IOException
IOException
@PUT @DELETE @POST @URLPattern(value="**") @Priority(value=500) public void handleUpdatedObjects()
public boolean isSecure()
@Priority(value=1000) @URLPattern(value="jwig.js") public void jwigJS() throws IOException
IOException
@URLPattern(value="**") @Priority(value=2147483647) @GET @POST @PUT @DELETE @TRACE @HEAD public final Object main() throws InterruptedException
InterruptedException
public static URL makeURL(boolean secure, Class<? extends WebApp> cl, Map<String,?> webapp_args, String method, Object... args)
secure
- if true, use https
, otherwise http
cl
- the web app to search for the method inwebapp_args
- web app arguments. This map can define values for arguments defined by the WebApp class (rather than the web method).
See section 4.3 in the manual for detailsmethod
- the name of the web methodargs
- arguments to the web method. These arguments will be encoded using toString
and will be part of the
request URL for the web method. The list of args must match the list of formal parameters in the web method both
in terms of number and types. The parameter will be mapped to names based on their order.public static URL makeURL(boolean secure, Class<? extends WebApp> cl, String method, Object... args)
secure
- if true, use https
, otherwise http
cl
- the web app to search for the method inmethod
- the name of the web methodargs
- arguments to the web method. These arguments will be encoded using toString
and will be part of the
request URL for the web method. The list of args must match the list of formal parameters in the web method both
in terms of number and types. The parameter will be mapped to names based on their order.public static URL makeURL(boolean secure, Map<String,?> webapp_args, String method, Object... args)
secure
- if true, use https
, otherwise http
webapp_args
- web app arguments. This map can define values for arguments defined by the WebApp class (rather than the web method).
See section 4.3 in the manual for detailsmethod
- the name of the web method (optionally qualified by the class
name, default: this web app)args
- arguments to the web method. These arguments will be encoded using toString
and will be part of the
request URL for the web method. The list of args must match the list of formal parameters in the web method both
in terms of number and types. The parameter will be mapped to names based on their order.public static URL makeURL(boolean secure, String method, Object... args)
secure
- if true, use https
, otherwise http
method
- the name of the web method (optionally qualified by the class
name, default: this web app)args
- arguments to the web method. These arguments will be encoded using toString
and will be part
of the request URL for the web method. The list of args must match the list of formal parameters in the web method
both in terms of number and types. The parameter will be mapped to names based on their order.public static URL makeURL(Class<? extends WebApp> cl, String method, Object... args)
https
if the current request
is on a secure connection.cl
- the web app to search for the method inmethod
- the name of the web methodargs
- arguments to the web method. These arguments will be encoded using toString
and
will be part of the request URL for the web method. The list of args must match the list of formal parameters
in the web method both in terms of number and types. The parameter will be mapped to names based on their order.public static URL makeURL(Map<String,?> webapp_args, String method, Object... args)
https
if the current request
is on a secure connection.webapp_args
- web app arguments. This map can define values for arguments defined by the WebApp class (rather than the web method).
See section 4.3 in the manual for detailsmethod
- the name of the web method (optionally qualified by the class
name, default: this web app)args
- arguments to the web method. These arguments will be encoded using toString
and will be part of the
request URL for the web method. The list of args must match the list of formal parameters in the web method both in
terms of number and types. The parameter will be mapped to names based on their order.public static URL makeURL(String method, Object... args)
https
if the current request is on a secure
connection.method
- the name of the web method (optionally qualified by the class
name, default: this web app)args
- arguments to the web method. These arguments will be encoded using toString
and will be part of
the request URL for the web method. The list of args must match the list of formal parameters in the web method
both in terms of number and types. The parameter will be mapped to names based on their order.public static Object next()
public static void punish(String key)
public SendFailedException sendEmail(Email message) throws JWIGException
mail.
are used for
setting up a JavaMail session when the web app is initialized.SendFailedException
or null if there is no errorJWIGException
- in case of other errors than SendFailedException
WebApp.setProperty(String, Object)
,
sendEmails(List)
public List<SendFailedException> sendEmails(List<Email> messages) throws JWIGException
SendFailedException
s, one for each message
being sent, with null meaning "no error"JWIGException
- in case of other errors than SendFailedException
sendEmail(Email)
public List<SendFailedException> sendEmailsAsynchronously(List<Email> messages) throws JWIGException
sendEmails(java.util.List)
but sends the emails in a
separate thread. For large batches of emails this means that the
application does not have to wait. Errors can however not be propagated
using this methodmessages
- Messages to sendJWIGException
public static void sendResponse()
@Priority(value=1000) public String touchSessions(Session[] s)
@Priority(value=2147483646) @URLPattern(value="**") public void transportSessionHandlers()
public static void update(Object obj)
XMLProducer
,
addResponseInvalidator(Object)
Copyright © 2008-2012 Anders Møller & Mathias Schwarz.