-
Notifications
You must be signed in to change notification settings - Fork 16
Picocontainer Integration
Integration EverRest framework with Picocontainer.
To integrate EverRest with Picocontainer you need extend org.everrest.pico.EverrestComposer
class. You able add you JAX-RS components in one of scoped container application, session or request. Adding component in request scope container minds new instance of components will be created for each request. Adding component is session scope container minds one instance of component per HTTP session. And adding component in apllication scope container minds one instance of component per web application.
public class MyComposer extends EverrestComposer
{
@Override
protected void doComposeApplication(MutablePicoContainer container, ServletContext servletContext)
{
container.addComponent(MyProvider.class);
}
@Override
protected void doComposeRequest(MutablePicoContainer container)
{
container.addComponent(MyResource.class);
}
@Override
protected void doComposeSession(MutablePicoContainer container)
{
}
}
In example above MyResource
is JAX-RS resource and it will work in per-request lifecycle and MyProvider
is JAX-RS provider and will work in singleton lifecycle. After that you need set full qualified name of MyComposer
as contex-param
with name webapp-composer-class
. You can find more details about picocontainer web framework here http://picocontainer.org/web/. Then you need add following in web.xml
:
<context-param>
<param-name>webapp-composer-class</param-name>
<param-value>org.everrest.example.MyComposer</param-value>
</context-param>
<listener>
<listener-class>org.picocontainer.web.PicoServletContainerListener</listener-class>
</listener>
<filter>
<filter-name>picoFilter</filter-name>
<filter-class>org.everrest.pico.servlet.EverrestPicoFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>picoFilter</filter-name>
<url-pattern>/**</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>EverrestServlet</servlet-name>
<servlet-class>org.everrest.core.servlet.EverrestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>EverrestServlet</servlet-name>
<url-pattern>/**</url-pattern>
</servlet-mapping>
Once you do EverRest and Picocontainer are set up.
Example of EverRest and Picocontainer integration can be found at subversion repository, see project everrest/everrest-integration/everrest-integration-picocontainer-sample
. You can simple run it with command mvn jetty:run
.
See details how-to try example in README.html in correspond project.