Rest.li instead of Restlet

21 views
Skip to first unread message

jaydatt desai

unread,
Aug 4, 2014, 9:59:44 AM8/4/14
to qi4j...@googlegroups.com
Hi Guys,

Here we have a question regarding our new approach we are trying to integrate, Well we are trying to use Rest.li instead of Restlet.
So, this Restlet is already integrated with Qi4j stack and working perfectly, but can any one please give us a guideline that "how can we use  Rest.li  with Qi4j stack?"

I mean we need to call the Qi4j stack using Rest.li. e.g. calling Qi4j context, services, Roles, etc..... using Rest.li instead of Restlet...

Niclas Hedhman

unread,
Aug 4, 2014, 11:17:08 PM8/4/14
to jaydatt desai, qi4j...@googlegroups.com

That depends on the exact details of Rest.li, and somewhat about exactly what you want to do.

In essence; "Qi4j Objects" are the mechanism to instantiate classes, which may contain Qi4j annotations. This is done via the ObjectFactory and it has a "uses" argument, which will match the provided object instances with @Uses annotated fields or constructor parameters of the corresponding type.

Example;

public class MyAuthorizer extends ThirdPartyAuthorizer
{
     @Uses
     ThirdPartyContect context;

     @Service
     AuthorizationService

  :
  :
}

@Mixins(AuthorizerFactory.DefaultImpl)
public interface AuthorizerFactory
{
    MyAuthorizer create();

    public abstract class DefaultImpl
        implements AuthorizerFactory
    {

        @Structure
        ObjectFactory of;

        ThirdPartyContext context;

        public DefaultImpl()
        {
            context = initializeContext();
        }

        public MyAuthorizer create() 
        {
            return of.newObject( MyAuthorizer.class, context );
        }
    }
}

Also note that Objects, like all Qi4j constructs, need to be declared in the application structure, i.e. ModuleAssembly has a objects() method. It also means that Visibility applies accordingly.

Hope that helps

Niclas

--
You received this message because you are subscribed to the Google Groups "qi4j-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qi4j-dev+u...@googlegroups.com.
To post to this group, send email to qi4j...@googlegroups.com.
Visit this group at http://groups.google.com/group/qi4j-dev.
For more options, visit https://groups.google.com/d/optout.



--
Niclas Hedhman, Software Developer
河南南路555弄15号1901室。
http://www.qi4j.org - New Energy for Java

I live here; http://tinyurl.com/3xugrbk
I work here; http://tinyurl.com/6a2pl4j
I relax here; http://tinyurl.com/2cgsug

jaydatt desai

unread,
Aug 5, 2014, 3:45:09 AM8/5/14
to qi4j...@googlegroups.com
Hi Niclas,


Thanks for the idea you given us about the @Uses, I have a look on it but somehow I am not getting how can this helpful to me.
I guess I have to give you more details about the requirement, so that you can give me a better solution.

Well this 2 things Resource and context: we are now thinking to use Rest.li resources for calling our Qi4j stack, now this Rest.li Resources are individual and not related to Qi4j stack, so some how we need to glue this rest.li resrouces with the Qi4j stack so that Qi4j context will be available in Rest.li resources.

Simple question here is : How can I call Qi4j context from rest.li resource? (I need to some way to call this context)

Niclas Hedhman

unread,
Aug 5, 2014, 6:37:10 AM8/5/14
to jaydatt desai, qi4j...@googlegroups.com

So, if you think that it is best if Rest.li can "manage" the Qi4j Runtime, then you should probably look closer at ImportedServices, which is a way to 'inject' a bridge from the outside into the Qi4j Runtime. The Imported Service's lifecycle is handled by an external system (the Service Importer)

Another way to do that is to use the Qi4j API/SPI (which is implemented by the Qi4j Runtime) to lookup services in modules and so forth.

But, IMHO, I think it is probably better if Qi4j manages the Rest.li subsystem. I don't know enough about the Rest.li architecture to tell you exactly how to do this. But in principle; Use THEIR interfaces (if any), subclass their implementations as declared Mixins, and hook into their instantiation mechanism (if any) to instantiate the types that it manages.

Also, note that ObjectFactory can "injectInto()" a ready java class the fields with Qi4j annotations, if for instance there is no hook for the instantiation, but you can get hold of the object before it is used.

I am not sure which way Rickard implemented the Rest libraries, but by looking at the bootstrapping code there, one should get an idea of how it is done.


Niclas


--
You received this message because you are subscribed to the Google Groups "qi4j-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qi4j-dev+u...@googlegroups.com.
To post to this group, send email to qi4j...@googlegroups.com.
Visit this group at http://groups.google.com/group/qi4j-dev.
For more options, visit https://groups.google.com/d/optout.

jaydatt desai

unread,
Aug 6, 2014, 1:48:38 AM8/6/14
to qi4j...@googlegroups.com, jaydat...@gmail.com, nic...@hedhman.org
Hi Niclas,

Thanks a lot for the detailed explanations, you have shown me different possibilities how I can achieve this, so from that I think I will look at the bootstrapping code first as you suggested, and I guess it will show me the proper direction by which I can achieve this, thanks a lot again I will now start looking bootstrapping code for this and come back if I found any hurdles or if I found the solutions.

Jaydatt Desai

unread,
Aug 8, 2014, 3:08:42 AM8/8/14
to qi4j...@googlegroups.com, jaydat...@gmail.com, nic...@hedhman.org
Hi Niclas,

Well I am able hook Rest.li with Qi4j successfully :), The trick here is Rest.li is calling their resources by creating "new resource" every time, so instead of creating new resource I have modified the code to create "new Qi4j  instance for same resource", so as a result I am able to call Qi4j aspects in Rest.li resources. I also need to modify other code, but this is the main trick for hooking Rest.li + Qi4j runtime, so wanted to thank you again as your suggestions helps me for achieving this. 

P.S. 
Let me know if exact information needed about this integration, I will provide that, but I guess this will be useful if some one wants to integrate Rest.li with Qi4j.

Thank you,
Jaydatt

Niclas Hedhman

unread,
Aug 8, 2014, 3:42:07 AM8/8/14
to Jaydatt Desai, qi4j...@googlegroups.com

So, you have a factory instance that is an Qi4j composite, and that is called for each request, and hence you can create Qi4j managed resources and hand them back to Rest.li ??

Niclas

Niclas Hedhman

unread,
Aug 8, 2014, 3:54:30 AM8/8/14
to jaydatt desai, qi4j...@googlegroups.com
If you think it is generic enough, feel free to add it as a library.


On Fri, Aug 8, 2014 at 3:44 PM, jaydatt desai <jaydat...@gmail.com> wrote:
Yes this is the way I did it...
--
Thanks & Regards,
Jaydatt Desai

Paul Merlin

unread,
Aug 8, 2014, 6:17:20 AM8/8/14
to qi4j...@googlegroups.com
Niclas Hedhman a écrit :
> If you think it is generic enough, feel free to add it as a library.
Jaydatt,

If you need some help adding a library to the SDK (build/doc/etc..) feel
free to email me directly so I can give you some guidance.

Cheers

/Paul

jaydatt desai

unread,
Aug 10, 2014, 4:07:20 AM8/10/14
to Niclas Hedhman, qi4j...@googlegroups.com
Yes this is the way I did it...
On Fri, Aug 8, 2014 at 1:11 PM, Niclas Hedhman <nic...@hedhman.org> wrote:

Jaydatt Desai

unread,
Aug 11, 2014, 1:32:02 AM8/11/14
to qi4j...@googlegroups.com, pa...@nosphere.org
Hi Paul,Niclas,

@Niclas: Yes I will add it as a library
@Paul: Yes I will surely take your assistance when i needed to add it

Thank you guys...
Reply all
Reply to author
Forward
0 new messages