I have found several references to spring and guice as DI mechanisms. It seems 
that a "provider" is needed to tell Jersey how to handle DI.

I'm looking at 
https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/core/spi/component/ioc/package-summary.html
 to see if I can put something together with iPojo.

David


On Aug 24, 2010, at 1:42 PM, David Allen wrote:

> Sorry, I spent so much time hoping to get the example going for you quickly 
> that I TOTALLY missed the point... My Jersey resource needs access to other 
> components of the system to construct the response, but when I try to add 
> @Requires in the resource code it doesn't seem to pick anything up. So I 
> tried a lot of things with setting up Jersey and wrapping classes, etc. to no 
> avail.
> 
> For instance, let's say there is a component that provides the current status:
> 
> public interface StatusProvider {
> 
>   String getStatus();
> 
> }
> 
> @Component(immediate=true)
> @Provides
> public class StatusProviderImpl implements StatusProvider {
> 
>   @Override
>   public String getStatus() {
>     return "active";
>   }
> 
> }
> 
> @Component(immediate=true)
> @Path("status")
> public class StatusResource {
> 
>   @Requires
>   private StatusProvider status;
> 
>   @GET
>   @Produces("text/plain")
>   public String getStatus() {
>       return status.getStatus();
>   }
> 
> }
> XML Config -
> <ipojo>
>   <instance component="com.sun.jersey.samples.osgihttpservice. 
> StatusProviderImpl"/>
>   <instance 
> component="com.sun.jersey.samples.osgihttpservice.StatusResource"/>
>   <instance 
> component="com.sun.jersey.samples.osgihttpservice.JerseyComponent"/>
> </ipojo>
> 
> When I fire this up and hit the url, then I get a null pointer for the 
> StatusProvider.
> 
> Hopefully it is just something dead simple that I am overlooking.
> 
> Thanks again,
> David
> 
> On Aug 24, 2010, at 9:46 AM, Clement Escoffier wrote:
> 
>> Hi,
>> 
>> So, I've tested and didn't get any issue. Here are my bundles (also deploy 
>> your feature)
>> 000047 ACT osgi.cmpn-4.2.0.200908310645
>> 000048 ACT org.apache.felix.ipojo-1.6.0
>> 000049 ACT ipojo-bundle-1.3  <-- the bundle I've created
>> 
>> My component is quite simple:
>> @Component(immediate=true)
>> public class JerseyComponent {
>> 
>>      @Bind
>>      public void bindHttp(HttpService http) {
>>        registerServlets(http);
>>      }
>> 
>>      @Unbind
>>      public void unbindHttp(HttpService http) {
>>        unregisterServlets(http);
>>      }
>> 
>>      private void registerServlets(HttpService http) {
>>        try {
>>            rawRegisterServlets(http);
>>        } catch (Exception ie) {
>>            throw new RuntimeException(ie);
>>        }
>>    }
>> 
>>    private void rawRegisterServlets(HttpService http) throws 
>> ServletException, NamespaceException, InterruptedException {
>>        http.registerServlet("/jersey-http-service-ipojo", new 
>> ServletContainer(), getJerseyServletParams(), null);
>>    }
>> 
>>    private void unregisterServlets(HttpService http) {
>>        http.unregister("/jersey-http-service-ipojo");
>>    }
>> 
>>    private Dictionary<String, String> getJerseyServletParams() {
>>        Dictionary<String, String> jerseyServletParams = new 
>> Hashtable<String, String>();
>>        jerseyServletParams.put("javax.ws.rs.Application", 
>> JerseyApplication.class.getName());
>>        return jerseyServletParams;
>>    }
>> 
>> }
>> 
>> Obviously, I've declared an instance in my metadata:
>>      <instance component="org.apache.felix.ipojo.jersey.JerseyComponent" />
>> 
>> The rest of the code is identical.
>> 
>> Could you give me more details about the issue ?
>> 
>> Regards,
>> 
>> Clement
>> 
>> On 23.08.2010, at 18:14, David Allen wrote:
>> 
>>> Hello Clement -
>>> 
>>> Here is the example project from the Jersey group:
>>> 
>>> http://download.java.net/maven/2/com/sun/jersey/samples/osgi-http-service/1.3/osgi-http-service-1.3-project.zip
>>> 
>>> Here is a feature I use to get all the dependencies and load it:
>>> 
>>> <feature name="restful" version="1.0">
>>>   <feature>http</feature>
>>>   <bundle>mvn:javax.ws.rs/jsr311-api/1.1.1</bundle>
>>>   <bundle>mvn:org.ops4j.pax.web/pax-web-extender-whiteboard/0.7.1</bundle>
>>>   
>>> <bundle>mvn:javax.xml.stream/com.springsource.javax.xml.stream/1.0.1</bundle>
>>>   
>>> <bundle>mvn:javax.activation/com.springsource.javax.activation/1.1.1</bundle>
>>>   <bundle>mvn:javax.xml.bind/com.springsource.javax.xml.bind/2.2.0</bundle>
>>>   <bundle>mvn:com.sun.jersey/jersey-core/1.3</bundle>
>>>   <bundle>mvn:com.sun.jersey/jersey-server/1.3</bundle>
>>>   <bundle>mvn:com.sun.jersey.samples.osgi-http-service/bundle/1.3</bundle>
>>> </feature>
>>> 
>>> When I hit http://localhost:8181/jersey-http-service/status I get the 
>>> correct "active" response.
>>> 
>>> Hopefully I didn't miss anything. Let me know if you need more information.
>>> 
>>> Thank you!
>>> David
>>> 
>>> 
>>> On Aug 23, 2010, at 2:27 AM, Clement Escoffier wrote:
>>> 
>>>> Hi,
>>>> 
>>>> Can send me or give me the url where to get the Jersey OSGi example ?
>>>> 
>>>> Regards,
>>>> 
>>>> Clement
>>>> 
>>>> On 23.08.2010, at 08:43, David Allen wrote:
>>>> 
>>>>> I have an extensive application wired using iPojo (love it!) but now I 
>>>>> want to create a REST API bundle where servlets are registered through 
>>>>> pax-web.
>>>>> 
>>>>> I was looking at Jersey for building out the endpoints, but I can't seem 
>>>>> to get Jersey/iPojo to play well. I have been able to run their OSGI 
>>>>> examples just fine, but when I try to replace the Activator with a Jersey 
>>>>> ServletContainer (or wrapper, or extendsion, etc) I get all sorts of 
>>>>> errors. I've also done the iPojo model fusion servlet example just fine.
>>>>> 
>>>>> Has anyone successfully wired up Jersey servlets using iPojo? If not, is 
>>>>> anyone using Restlet or a similar library with iPojo?
>>>>> 
>>>>> Cheers,
>>>>> David Allen
>>>>> 
>>>>> David Allen
>>>>> veloGraf Systems
>>>>> [email protected]
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: [email protected]
>>>>> For additional commands, e-mail: [email protected]
>>>>> 
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [email protected]
>>>> For additional commands, e-mail: [email protected]
>>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [email protected]
>>> For additional commands, e-mail: [email protected]
>>> 
>> 
> 

Reply via email to