/**
* The only response by this application is an
index.html
file.
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/html");
OutputStream out = resp.getOutputStream();
InputStream in = getClass().getResourceAsStream("index.html");
for (int c = 0; (c = in.read()) != -1;) {
out.write((char)c);
}
}
## Deployment Descriptor to enable JEST
The sample web application deploys *demo.SimpleApp* servlet *and* JEST
servlet. The essential aspect of the deployment descriptor
*WEB-INF/web.xml* is shown below
Demo Application with JEST Servlet
index.html
demo
demo.SimpleApp
demo
/*
jest
org.apache.openjpa.persistence.jest.JESTServlet
persistence.unit
jestdemo
jest
/jest/*
## Discovery of Persistent Unit
As can be seen in `WEB-INF/web.xml` above, the JEST servlet
`org.apache.openjpa.persistence.jest.JESTServlet` needs to know the
persistent unit name `jestdemo` to _discover_ the actual
`EntityManagerFactory` instantiated by its sibling `demo.SimpleApp`
servlet. This discovery of an `EntityManagerFactory` instantiated by
another component is possible because the said
`EntityManagerFactory` is being pooled by OpenJPA. A more general
discovery mechanics where JEST can discover a `EntityManagerFactory`
instantiated and injected by the container
would be available in future.
## Building the sample application
An Ant build script `build.xml` is provided and a `build.properties` to
adjust for local settings. To suit your local environment, please edit the
`build.properties` for OpenJPA library and `META-INF/persistence.xml`
for database specifics. The supplied build file compiles two persistent
domain classes `demo.Actor` and `demo.Movie`, enhanced them and
packages them in an web archive `demo.war`. The script assumes that the
OpenJPA library and the JDBC driver (the sample persistence descriptor uses
MySQL, by deafult) are available in shared library of the Servlet Container
and hence does _not_ package these libraries in the web archive
`demo.war`.
## Deploying the sample application
The next step is to deploy this simple web archive `demo.war` in a
Servlet Container such as Tomcat or a a JEE container. We do not describe
these steps because they are fairly standard.
## JEST in action
Once the sample web application is deployed, say in Tomcat running on
`localhost:8080`, open the web browser
and
you should see the web page served by `demo.SimpleApp`. This step
initializes `demo.SimpleApp` and hence the persistence unit `jestdemo`.
Now, if you go to URL , the JEST
welcome page will be displayed -- which is JavaScript enabled web page that
demonstrates currently available JEST facilities such as finding or
querying for instances.