public class Main extends WebApp {
public XML hello(String what) {
return [[
<html>
<head><title>Example</title></head>
<body>
<p>Hello <{ what }></p>
</body>
</html>
]];
}}
Figure 2: A “hello world” web application.
means that we avoid many of the security considera-
tions that programmers have if using a client-oriented
architecture, as e.g. GWT. A concrete example of this
advantage is shown in (Møller and Schwarz, 2009).
One of the typical arguments in favor of a client-
oriented approach is the opportunity to create rich
user interfaces—however, such effects are possible
also in server-oriented frameworks using tag libraries
containing JavaScript code. Also, pushing computa-
tion to the client-side may imply a decreased load on
the server, but, on the other hand, it often conflicts
with the use of ORM systems: It is difficult to ensure
high performance if the application code is physically
separated from the ORM system.
Figure 1 illustrates the basic architecture. As in
many other newer server-oriented frameworks, a dis-
patcher on the server receives the client HTTP re-
quests and invokes the appropriate server code, here
called web methods. Many frameworks rely on sep-
arate configuration files for mapping from request
URLs to application code. To decrease coupling, our
web methods are instead discovered using introspec-
tion of the web application code, as in e.g. CherryPy.
The web methods have formal parameters for receiv-
ing arguments from the clients and return values to be
sent as response.
As an example, the tiny web application shown
in Figure 2 accepts HTTP GET requests of the form
http://example.org/Main/hello?what=World
and returns a small XHTML page as response.
The class
Main
is a web application that contains
a single web method
hello
. We explain the XML
construction and the
[[...]]
notation in Section 3.
Following the ‘convention over configuration’
principle, no application specific configuration is
required to make this run—unlike the situation in, for
example, Struts or RIFE (Bevin, 2007).
The architecture is a variant of the Model-View-
Controller pattern that many other frameworks also
apply. Most importantly, the model is separated from
the main web application code. However, we propose
a less rigid division between the view and the con-
troller than used in other frameworks, as we explain
in Section 3.
In the following sections, we go into more details and
extend this basic architecture to fulfill the require-
ments we defined, which includes introducing the no-
tions of XML producers and event handlers and the
page event and page update actions appearing in Fig-
ure 1.
3 GENERATING XML OUTPUT
A common approach to generating XHTML output
dynamically in web application frameworks is to use
a template system, either where templates contain
code for dynamic construction of content (as in e.g.
ASP.NET, PHP, or RoR) or where templates contain
placeholders where the code can insert content (as
in e.g. RIFE). Another approach is to use GUI com-
ponents that are assembled programatically (as e.g.
GWT or Wicket). Web services, on the other hand,
need the ability to also receive and decompose XML
data, which is often done completely differently in a
DOM-style fashion.
All those systems lack the ability to ensure, at
compile time, that output is always well-formed and
valid XML data. This is known to affect reliability
and may lead to, for example, cross site scripting vul-
nerabilities.
We propose a solution that (1) unifies the template
approach and the DOM-style approach, (2) permits
static validation analysis, and (3) avoids many secu-
rity issues by design. This approach is a further devel-
opment of the JWIG framework presented in (Chris-
tensen et al., 2003).
We build on a new version of the XACT sys-
tem (Kirkegaard et al., 2004). XML data is repre-
sented as well-formed XML fragments that are first-
class values, meaning that they can be stored in vari-
ables and passed between methods (unlike most other
template systems). Figure 2 shows an XML value
constant (enclosed by
[[...]]
, using a simple syn-
tax extension to Java) that contains a snippet of code
(enclosed by
<{...}>
in XML content or
{...}
in at-
tribute values), which at runtime evaluates to a value
that gets inserted. The syntax extension reduces the
burden of working with XML data inside Java pro-
grams and is desugared to ordinary Java code.
XML values may also contain named gaps where
other XML values or strings can be inserted, which
makes it easy to reuse them. As an example, the fol-
lowing code defines a wrapper for XHTML pages and
stores it in a variable
w
:
XML w = [[<html>
<head><title>My Pink Web App</title></head>
JWIG: YET ANOTHER FRAMEWORK FOR MAINTAINABLE AND SECURE WEB APPLICATIONS
49