You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Ascharya Shetty <as...@gmail.com> on 2015/04/09 16:31:07 UTC
How to register a servlet as a service using felix scr
Hi,
The example below uses ipojo for registering the servlet as a service.
Can anyone point me how can I use Felix SCR annotations instead to acheive
the same ?
@Component(immediate = true)
@Instantiate
public class MyServlet extends HttpServlet {
@ServiceProperty
private String MY_SERVLET_ALIAS = "/my_service";
@Requires(optional = true, defaultimplementation = OtherServiceImpl.class)
private OtherService otherService;
@Bind
public void bindHttp(HttpService httpService) {
try {
httpService.registerServlet(MY_SERVLET_ALIAS, this,
null, null);
} catch (ServletException | NamespaceException e) {
LOG.error("Exception occurred when registering the recommendation
Service", e);
}
}
@Unbind
public void unbindHttp(HttpService httpService) {
httpService.unregister(MY_SERVLET_ALIAS);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
//some implementation
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
//some implementation
}
}