finagle-servlet
Finagle servlet is an adapter to allow Finagle based applications including Finatra-based applications into a servlet container that supports either Jetty Continuations or the Servlet API 3.0.
Quick Start
Jetty style continuations
Paste the following block of code into your web.xml file to use Jetty style continuations. Your-Service-Factory should be the fully qualified name of a class that implements ServiceFactory and has a zero-arg constructor.
<web-app> <!-- define a FinagleJettyServlet to use Jetty style continuations --> <servlet> <servlet-name>jetty</servlet-name> <servlet-class>com.github.savaki.finagle.servlet.jetty.FinagleJettyServlet</servlet-class> <init-param> <param-name>service.factory.classname</param-name> <param-value>com.github.savaki.finagle.servlet.EmptyServiceFactory</param-value> </init-param> </servlet> </web-app>
Servlet API 3.0
For a Servlet 3.0 container and support for AsyncContext, paste the following code block into your web.xml. Again, you'll want to replace Your-Service-Factory with the name of the service factory that you define.
<web-app> <!-- define a FinagleAsyncServlet to use the Servlet API 3.0 --> <servlet> <servlet-name>async</servlet-name> <servlet-class>com.github.savaki.finagle.servlet.servlet_30.FinagleAsyncServlet</servlet-class> <init-param> <param-name>service.factory.classname</param-name> <param-value>com.github.savaki.finagle.servlet.EmptyServiceFactory</param-value> </init-param> </servlet> </web-app>
Service Factory
To register services with the FinagleServlet, you'll need to implement the com.github.savaki.finagle.servlet.ServiceFactory interface.
FinatraServiceFactory
To use Finatra Controllers and Filters with the finagle-servlet adapter, you can implement a class as follows:
package your.pkg class MyFinatraAdapter extends FinatraServiceFactory { // add your controllers register(new MyController()) register(new Anotherontroller()) // and optionally add any filters that you may want addFilter(new MyFilter()) }
In your web.xml file, you can use your.pkg.MyFinatraAdapter in place of the value for service.factory.classname
ServiceFactory
For finagle projects that don't use finatra, you can simply implement the ServiceFactory interface to bind any Service[Request, Response] to a servlet container.
License
Released under the Apache License, version 2.0