users@servlet-spec.java.net

[servlet-spec users] What about a WebContainer API ?

From: Antonio Goncalves <antonio.goncalves_at_gmail.com>
Date: Thu, 9 Feb 2012 15:23:59 +0100

Hi all,

The expert group is making progress on the future Servlet 3.1
specification... and I wanted to ask you about having a standard
WebContainer API.

In Java EE 6, most specifications have a Container API. We get a factory
and with this factory create a container :

*JPA : *
EntityManagerFactory emf =
Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = emf.createEntityManager()

*Bean Validation :*
ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
Validator validator = vf.getValidator();

*EJB :*
EJBContainer ec = EJBContainer.createEJBContainer(properties)

You also find this pattern in other places like JAXB for instance. This has
many benefits (embedding the EJBContainer into Tomcat in a standard way for
example), but one of them is being able to do some integration testing with
the container. More and more we trigger an embedded container in our
integration tests, "deploy" some components and invoke methods of them.

I was wondering if you had something like that in mind for Servlet 3.1 ?
Something to easily create a Web container :

Map<String, Object> properties = new HashMap<String, Object>();
properties.put(WebContainer.MODULES, new File[]{new File("target/classes"),
new File("target/myapp/classes")});
properties.put(WebContainer.WEB_XML, new
File("target/myapp/classes/WEB-INF/web.xml"));
WebContainer webc = WebContainer.createWebContainer("web.xml")

and then use HTTClient, HTTPUnit or the next JAX-RS client API to invoke
servlets.

Any thoughts ?

-- 
Antonio Goncalves
Software architect and Java Champion
Web site <http://www.antoniogoncalves.org> |
Twitter<http://twitter.com/agoncal>|
Blog <http://feeds.feedburner.com/AntonioGoncalves> |
LinkedIn<http://www.linkedin.com/in/agoncal>| Paris
JUG <http://www.parisjug.org>