How to reference Bundle Service in web resource like JSP, Servlet? [message #100497] |
Mon, 29 October 2007 02:03  |
Eclipse User |
|
|
|
Originally posted by: lifesting.gmail.com
I created a bundle and bound a service *SmsService* on it's context,
below is the class body:
public class Activator implements BundleActivator {
private ServiceRegistration serviceReg;
public void start(BundleContext context) throws Exception {
SmsService service = xxx;
serviceReg = context.registerService(SmsService.class.getName(),
service,new Hashtable());
}
public void stop(BundleContext context) throws Exception {
serviceReg.unregister();
}
}
I also created a Servlet in this bundle, in which there's a method
invocation on the registered service above:
public class SendMessageServlet extends HttpServlet {
protected void doPost(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, IOException {
.....
SmsService sms = ....//Get the registered service
sms.sendMessage(XXX);
}
}
The only valid method after try is to add a field references
BundleContext and set it's value in Servlet constructor:
public class SendMessageServlet extends HttpServlet {
private BundleContext context;
public SendMessageServlet(BundleContext context)
{
this.context =context;
}
......
}
As you see, this way need every Servlet import Bundle explicitly, is
there a more elegant method?
Thanks a lot!
|
|
|
|
Re: How to reference Bundle Service in web resource like JSP, Servlet? [message #101262 is a reply to message #100497] |
Wed, 07 November 2007 20:59  |
Eclipse User |
|
|
|
Originally posted by: bob.yang.unison.net.cn
Hello David,
I have the similar issue, because I want to use the
'org.eclipse.equinox.http.registry' bundle to registry servlet by using
eclipse extension point mechanism. But I can not find a way to supply
BundleContext object to my servlet when using
'org.eclipse.equinox.http.registry' bundle.
any idea?
David BY Chan wrote:
> I created a bundle and bound a service *SmsService* on it's context,
> below is the class body:
>
> public class Activator implements BundleActivator {
>
> private ServiceRegistration serviceReg;
>
> public void start(BundleContext context) throws Exception {
> SmsService service = xxx;
> serviceReg = context.registerService(SmsService.class.getName(),
> service,new Hashtable());
> }
>
>
> public void stop(BundleContext context) throws Exception {
> serviceReg.unregister();
> }
>
> }
>
> I also created a Servlet in this bundle, in which there's a method
> invocation on the registered service above:
>
> public class SendMessageServlet extends HttpServlet {
> protected void doPost(HttpServletRequest
> req, HttpServletResponse resp)
> throws ServletException, IOException {
> .....
> SmsService sms = ....//Get the registered service
> sms.sendMessage(XXX);
> }
> }
>
> The only valid method after try is to add a field references
> BundleContext and set it's value in Servlet constructor:
>
> public class SendMessageServlet extends HttpServlet {
> private BundleContext context;
> public SendMessageServlet(BundleContext context)
> {
> this.context =context;
> }
> ......
> }
>
> As you see, this way need every Servlet import Bundle explicitly, is
> there a more elegant method?
>
> Thanks a lot!
|
|
|
Powered by
FUDForum. Page generated in 0.03096 seconds