how to get bundle context in the servlet registered by the org.eclipse.equinox.http.registry [message #101414] |
Sun, 11 November 2007 07:47 |
Eclipse User |
|
|
|
Originally posted by: bob.yang.unison.net.cn
hi,
I am using the org.eclipse.equinox.http.registry bundle to register a
servlet by specify the extension
'org.eclipse.equinox.http.registry.servlets', I want to use the OSGI
services in the servlet so I need a BundleContext object reference, how
can I get it?
Below is the exertion of the plugin.xml:
<extension
point="org.eclipse.equinox.http.registry.servlets">
<servlet
alias="/hello"
class="com.example.http.application.HelloServlet">
<init-param
name="message"
value="some values">
</init-param>
</servlet>
</extension>
Thanks!
Bob Yang
|
|
|
Re: how to get bundle context in the servlet registered by the org.eclipse.equinox.http.registry [message #101446 is a reply to message #101414] |
Sun, 11 November 2007 15:05 |
Eclipse User |
|
|
|
Originally posted by: skaegi.sympatico.ca
Hi Bob,
There are a couple of approaches:
1) You can save the BundleContext in a static variable in your Bundle
Activator. If you take this approach make sure to synchronize the setter and
getter.
2) Instead of putting the Servlet class in the extension put an
"IExecutableExtensionFacory" that will generate a Servlet instance with the
BundleContext pre-injected. A nice variation on this is to inject the actual
services you'll need instead of the BundleContext.
If you're starting to do anything OSGi specific in your Servlet you might
also consider directly using the Http Service instead of doing youre
registration declaratively via http.registry's extensions.
HTH
-Simon
"Bob Yang" <bob.yang@unison.net.cn> wrote in message
news:fh6bm9$c4l$1@build.eclipse.org...
> hi,
>
> I am using the org.eclipse.equinox.http.registry bundle to register a
> servlet by specify the extension
> 'org.eclipse.equinox.http.registry.servlets', I want to use the OSGI
> services in the servlet so I need a BundleContext object reference, how
> can I get it?
>
> Below is the exertion of the plugin.xml:
>
> <extension
> point="org.eclipse.equinox.http.registry.servlets">
> <servlet
> alias="/hello"
> class="com.example.http.application.HelloServlet">
> <init-param
> name="message"
> value="some values">
> </init-param>
> </servlet>
> </extension>
>
> Thanks!
>
> Bob Yang
|
|
|
Re: how to get bundle context in the servlet registered by the org.eclipse.equinox.http.registry [message #101455 is a reply to message #101414] |
Mon, 12 November 2007 01:53 |
Eclipse User |
|
|
|
Originally posted by: lifesting.gmail.com
Bob Yang wrote:
> hi,
>
> I am using the org.eclipse.equinox.http.registry bundle to register a
> servlet by specify the extension
> 'org.eclipse.equinox.http.registry.servlets', I want to use the OSGI
> services in the servlet so I need a BundleContext object reference, how
> can I get it?
>
> Below is the exertion of the plugin.xml:
>
> <extension
> point="org.eclipse.equinox.http.registry.servlets">
> <servlet
> alias="/hello"
> class="com.example.http.application.HelloServlet">
> <init-param
> name="message"
> value="some values">
> </init-param>
> </servlet>
> </extension>
>
> Thanks!
>
> Bob Yang
You can use Spring-OSGi to inject any service into the target Servlet,
that means using Spring Declaring instead of Eclipse extension.
|
|
|
|
Powered by
FUDForum. Page generated in 0.04213 seconds