You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by D Tim Cummings <ti...@triptera.com.au.INVALID> on 2021/08/03 03:27:47 UTC

Integrating Agrest in Tapestry app

Does anyone have experience integrating Agrest (https://agrest.io/) into
a Tapestry app? My Tapestry app uses Cayenne ORM and it looks like
Agrest works well with Cayenne to produce REST functionality. It would
be helpful to see some sample code.

Thanks in advance

Tim




Re: Integrating Agrest in Tapestry app

Posted by Alejandro Scandroli <al...@gmail.com>.
Hi all

In case you want to follow the topic I posted some comments on the
issue that Tim reported on GitHub.
https://github.com/tynamo/tapestry-resteasy/issues/19

Cheers!
Alejandro.



On Sat, Aug 7, 2021 at 2:57 AM D Tim Cummings
<ti...@triptera.com.au.invalid> wrote:
>
> Thanks for your help Ben. I guess I don't need to use agrest. I can use
> tapestry-resteasy with cayenne persistence.
>
> Cheers
>
> Tim
>
> On 6/8/21 23:03, Ben Weidig wrote:
> > Hi Tim,
> >
> > your code looks fine to me, but it seems like this is a limitation of
> > tapestry-resteasy.
> >
> > The project wraps the configuration of RESTEasy to make it easier to use
> > with Tapestry.
> > The method
> > https://github.com/tynamo/tapestry-resteasy/blob/0111a37e842a67e49b47752de85d738676c179e9/src/main/java/org/tynamo/resteasy/ResteasyRequestFilter.java#L138
> > goes over the contributed instances and classes, but it doesn't support all
> > the available types RESTEasy has to offer, so it throws the exception
> > you're getting.
> > Only Resources and Providers are supported, but AgRuntime is a "Feature"
> > type.
> >
> > The only option I see (without tapestry-resteasy adding it) is overriding
> > the ResteasyRequestFilter and extending the conditions for provider
> > detection to allow instances of Feature, too.
> > Features are internally registered like providers if I saw it correctly in
> > the RESTEasy code.
> >
> > I've only read the tapestry-resteasy/RESTEasy source code and not tested it
> > with a running project, so it might not be that easy.
> >
> >
> > On Fri, Aug 6, 2021 at 1:52 PM D Tim Cummings <ti...@triptera.com.au.invalid>
> > wrote:
> >
> >> Hi Ben
> >>
> >> I followed your suggestions and was able to get rest working with
> >> tapestry-resteasy without using persistence. However when I added agrest
> >> tapestry resteasy threw an exception unknown class type:
> >> io.agrest.runtime.AgRuntime. My code is as follows. I am using a simple
> >> data model from https://github.com/agrestio/agrest-bookstore-example .
> >> Could you please check I have implemented your suggestions correctly.
> >>
> >>  - add tapestry-resteasy to your project
> >>
> >> <dependency>
> >>     <groupId>org.tynamo</groupId>
> >>     <artifactId>tapestry-resteasy</artifactId>
> >>     <version>0.7.0</version>
> >> </dependency>
> >>
> >>  - write a service to setup the AgRuntime
> >>
> >> public class AgrestServiceImpl implements AgrestService {
> >>   public AgrestServiceImpl() {
> >>     ServerRuntime runtime =
> >> ServerRuntime.builder().addConfig("cayenne-project.xml").build();
> >>     AgCayenneModule cayenneExt = AgCayenneBuilder.build(runtime);
> >>     agRuntime = new AgBuilder().module(cayenneExt).build();
> >>   }
> >>   private AgRuntime agRuntime;
> >>   public AgRuntime agRuntime() {
> >>     return agRuntime;
> >>   }
> >> }
> >>
> >>
> >>  - write a simple resource with a single @GET method using Agrest
> >>
> >> @Path("/category")
> >> @Produces(MediaType.APPLICATION_JSON)
> >> public class CategoryResource {
> >>   @Context
> >>   private Configuration config;
> >>   @GET
> >>   public DataResponse<Category> getAll(@Context UriInfo uriInfo) {
> >>       return Ag.select(Category.class, config).uri(uriInfo).get();
> >>   }
> >> }
> >>
> >>
> >>  - contribute the AgRuntime and resource like in my previous mail.
> >>
> >>     @Contribute(javax.ws.rs.core.Application.class)
> >>     public static void configureRestProviders(Configuration<Object>
> >> singletons, AgrestService svcAgrest) {
> >>         singletons.add(svcAgrest.agRuntime());
> >>         singletons.addInstance(CategoryResource.class);
> >>     }
> >>
> >>
> >>  - test it with your browser or curl
> >>
> >> http://localhost:8089/tapestry-agrest/rest/category
> >>
> >> java.lang.RuntimeException: Exception constructing service
> >> 'ResteasyRequestFilter': Error invoking constructor public
> >>
> >> org.tynamo.resteasy.ResteasyRequestFilter(java.lang.String,org.slf4j.Logger,org.apache.tapestry5.http.services.ApplicationGlobals,javax.ws.rs.core.Application,org.apache.tapestry5.ioc.services.SymbolSource,boolean,org.apache.tapestry5.ioc.services.UpdateListenerHub,long,long,boolean)
> >>  throws javax.servlet.ServletException: Application.getSingletons()
> >> returned unknown class type: io.agrest.runtime.AgRuntime
> >>
> >>
> >> On 3/8/21 22:06, Ben Weidig wrote:
> >>> tapestry-resteasy is just bringing RESTEasy to Tapestry.
> >>> There's no dependency to JPA/Hibernate.
> >>> Do you mean the PersistenceService in the example on the page under "Code
> >>> your singleton resource"?
> >>> That's not a necessity, just an example for a Rest resource.
> >>> In your case, you would use Agrest instead.
> >>>
> >>> You don't need to edit web.xml because tapestry-resteasy uses a Tapestry
> >>> HttpServletRequestFilter to piggyback Tapstry itself, instead of going
> >>> through the a custom servlet defined in the web.xml.
> >>> Everything that would be done in the web.xml is done with code instead.
> >>> This way, you don't need an extra Bridge to handle service injection.
> >>>
> >>>
> >> https://github.com/tynamo/tapestry-resteasy/blob/master/src/main/java/org/tynamo/resteasy/ResteasyRequestFilter.java
> >>> The next steps for simple proof-of-concept would be something like this:
> >>>
> >>> - add tapestry-resteasy to your project
> >>> - write a service to setup the AgRuntime
> >>> - write a simple resource with a single @GET method using Agrest
> >>> - contribute the AgRuntime and resource like in my previous mail.
> >>> - test it with your browser or curl
> >>>
> >>> Hope this helps!
> >>>
> >>> On Tue, Aug 3, 2021 at 1:12 PM D Tim Cummings
> >> <ti...@triptera.com.au.invalid>
> >>> wrote:
> >>>
> >>>> Thanks for this very detailed reply. I will work through what you have
> >>>> suggested and see how I go.
> >>>>
> >>>> I had a look at tapestry-resteasy but it seems to rely on hibernate or
> >>>> jpa and I am using cayenne. I am not sure what is required for
> >>>> org.tynamo.services.PersistenceService. Also tapestry-resteasy says I
> >>>> don't need to edit web.xml.
> >>>>
> >>>> Another example I am following says I do need to edit web.xml.
> >>>> https://github.com/andrus/wowodc13 is an example for tapestry and
> >>>> cayenne and jersey 1.x rest. It seems to rely on a JerseyTapestryBridge
> >>>> [1] but the code looks specific to jersey 1.x and wouldn't work with
> >>>> jersey 2.x
> >>>>
> >>>> Cheers
> >>>>
> >>>> Tim
> >>>>
> >>>> [1]
> >>>>
> >>>>
> >> https://github.com/andrus/wowodc13/blob/master/site/src/main/java/demo/rest/jersey/JerseyTapestryBridge.java
> >>>> On 3/8/21 17:15, Ben Weidig wrote:
> >>>>> Hi Tim,
> >>>>>
> >>>>> full disclosure: I haven't used Cayenne or Agrest, but I checked out
> >>>> their
> >>>>> documentation.
> >>>>>
> >>>>> I don't think there's anything Tapestry-specific needed to get it up
> >> and
> >>>>> running except setting up Rest.
> >>>>> They say in their docs that you still have to write your JAX-RS
> >> endpoints
> >>>>> and do security yourself.
> >>>>>
> >>>>> For JAX-RS, there's tapestry-resteasy
> >>>>> https://www.tynamo.org/tapestry-resteasy+guide/
> >>>>> There are examples how to add Rest to Tapestry and register your
> >>>> resources.
> >>>>> The AgRuntime should be contributable just like a Rest resource.
> >> RestEasy
> >>>>> treats many of its classes are contributable (Resources, Provider,
> >> etc.).
> >>>>> You could create a service to build it.
> >>>>>
> >>>>> @Contribute(javax.ws.rs.core.Application.class)
> >>>>> public static void configureRestProviders(Configuration<Object>
> >>>> singletons,
> >>>>> YourAgRuntimeBuilder builder) {
> >>>>>     singletons.add(builder.build());
> >>>>>     singletons.addInstance(YourCredentialsInterceptor.class);
> >>>>>     singletons.addInstance(YourResource.class);
> >>>>> }
> >>>>>
> >>>>> For security, we use custom headers containing an API key/secret that
> >> are
> >>>>> validated by a javax.ws.rs.container.ContainerRequestFilter with
> >>>>> @Priority(Priorities.AUTHENTICATION) and
> >>>>> @Priority(Priorities.AUTHORIZATION) and plug in your security code.
> >>>>>
> >>>>> But as said before, I haven't tested it, and it just looks this way to
> >> me
> >>>>> at first glance.
> >>>>>
> >>>>> Cheers,
> >>>>> Ben
> >>>>>
> >>>>> On Tue, Aug 3, 2021 at 5:28 AM D Tim Cummings
> >>>> <ti...@triptera.com.au.invalid>
> >>>>> wrote:
> >>>>>
> >>>>>> Does anyone have experience integrating Agrest (https://agrest.io/)
> >>>> into
> >>>>>> a Tapestry app? My Tapestry app uses Cayenne ORM and it looks like
> >>>>>> Agrest works well with Cayenne to produce REST functionality. It would
> >>>>>> be helpful to see some sample code.
> >>>>>>
> >>>>>> Thanks in advance
> >>>>>>
> >>>>>> Tim
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >>
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Integrating Agrest in Tapestry app

Posted by D Tim Cummings <ti...@triptera.com.au.INVALID>.
Thanks for your help Ben. I guess I don't need to use agrest. I can use
tapestry-resteasy with cayenne persistence.

Cheers

Tim

On 6/8/21 23:03, Ben Weidig wrote:
> Hi Tim,
>
> your code looks fine to me, but it seems like this is a limitation of
> tapestry-resteasy.
>
> The project wraps the configuration of RESTEasy to make it easier to use
> with Tapestry.
> The method
> https://github.com/tynamo/tapestry-resteasy/blob/0111a37e842a67e49b47752de85d738676c179e9/src/main/java/org/tynamo/resteasy/ResteasyRequestFilter.java#L138
> goes over the contributed instances and classes, but it doesn't support all
> the available types RESTEasy has to offer, so it throws the exception
> you're getting.
> Only Resources and Providers are supported, but AgRuntime is a "Feature"
> type.
>
> The only option I see (without tapestry-resteasy adding it) is overriding
> the ResteasyRequestFilter and extending the conditions for provider
> detection to allow instances of Feature, too.
> Features are internally registered like providers if I saw it correctly in
> the RESTEasy code.
>
> I've only read the tapestry-resteasy/RESTEasy source code and not tested it
> with a running project, so it might not be that easy.
>
>
> On Fri, Aug 6, 2021 at 1:52 PM D Tim Cummings <ti...@triptera.com.au.invalid>
> wrote:
>
>> Hi Ben
>>
>> I followed your suggestions and was able to get rest working with
>> tapestry-resteasy without using persistence. However when I added agrest
>> tapestry resteasy threw an exception unknown class type:
>> io.agrest.runtime.AgRuntime. My code is as follows. I am using a simple
>> data model from https://github.com/agrestio/agrest-bookstore-example .
>> Could you please check I have implemented your suggestions correctly.
>>
>>  - add tapestry-resteasy to your project
>>
>> <dependency>
>>     <groupId>org.tynamo</groupId>
>>     <artifactId>tapestry-resteasy</artifactId>
>>     <version>0.7.0</version>
>> </dependency>
>>
>>  - write a service to setup the AgRuntime
>>
>> public class AgrestServiceImpl implements AgrestService {
>>   public AgrestServiceImpl() {
>>     ServerRuntime runtime =
>> ServerRuntime.builder().addConfig("cayenne-project.xml").build();
>>     AgCayenneModule cayenneExt = AgCayenneBuilder.build(runtime);
>>     agRuntime = new AgBuilder().module(cayenneExt).build();
>>   }
>>   private AgRuntime agRuntime;
>>   public AgRuntime agRuntime() {
>>     return agRuntime;
>>   }
>> }
>>
>>
>>  - write a simple resource with a single @GET method using Agrest
>>
>> @Path("/category")
>> @Produces(MediaType.APPLICATION_JSON)
>> public class CategoryResource {
>>   @Context
>>   private Configuration config;
>>   @GET
>>   public DataResponse<Category> getAll(@Context UriInfo uriInfo) {
>>       return Ag.select(Category.class, config).uri(uriInfo).get();
>>   }
>> }
>>
>>
>>  - contribute the AgRuntime and resource like in my previous mail.
>>
>>     @Contribute(javax.ws.rs.core.Application.class)
>>     public static void configureRestProviders(Configuration<Object>
>> singletons, AgrestService svcAgrest) {
>>         singletons.add(svcAgrest.agRuntime());
>>         singletons.addInstance(CategoryResource.class);
>>     }
>>
>>
>>  - test it with your browser or curl
>>
>> http://localhost:8089/tapestry-agrest/rest/category
>>
>> java.lang.RuntimeException: Exception constructing service
>> 'ResteasyRequestFilter': Error invoking constructor public
>>
>> org.tynamo.resteasy.ResteasyRequestFilter(java.lang.String,org.slf4j.Logger,org.apache.tapestry5.http.services.ApplicationGlobals,javax.ws.rs.core.Application,org.apache.tapestry5.ioc.services.SymbolSource,boolean,org.apache.tapestry5.ioc.services.UpdateListenerHub,long,long,boolean)
>>  throws javax.servlet.ServletException: Application.getSingletons()
>> returned unknown class type: io.agrest.runtime.AgRuntime
>>
>>
>> On 3/8/21 22:06, Ben Weidig wrote:
>>> tapestry-resteasy is just bringing RESTEasy to Tapestry.
>>> There's no dependency to JPA/Hibernate.
>>> Do you mean the PersistenceService in the example on the page under "Code
>>> your singleton resource"?
>>> That's not a necessity, just an example for a Rest resource.
>>> In your case, you would use Agrest instead.
>>>
>>> You don't need to edit web.xml because tapestry-resteasy uses a Tapestry
>>> HttpServletRequestFilter to piggyback Tapstry itself, instead of going
>>> through the a custom servlet defined in the web.xml.
>>> Everything that would be done in the web.xml is done with code instead.
>>> This way, you don't need an extra Bridge to handle service injection.
>>>
>>>
>> https://github.com/tynamo/tapestry-resteasy/blob/master/src/main/java/org/tynamo/resteasy/ResteasyRequestFilter.java
>>> The next steps for simple proof-of-concept would be something like this:
>>>
>>> - add tapestry-resteasy to your project
>>> - write a service to setup the AgRuntime
>>> - write a simple resource with a single @GET method using Agrest
>>> - contribute the AgRuntime and resource like in my previous mail.
>>> - test it with your browser or curl
>>>
>>> Hope this helps!
>>>
>>> On Tue, Aug 3, 2021 at 1:12 PM D Tim Cummings
>> <ti...@triptera.com.au.invalid>
>>> wrote:
>>>
>>>> Thanks for this very detailed reply. I will work through what you have
>>>> suggested and see how I go.
>>>>
>>>> I had a look at tapestry-resteasy but it seems to rely on hibernate or
>>>> jpa and I am using cayenne. I am not sure what is required for
>>>> org.tynamo.services.PersistenceService. Also tapestry-resteasy says I
>>>> don't need to edit web.xml.
>>>>
>>>> Another example I am following says I do need to edit web.xml.
>>>> https://github.com/andrus/wowodc13 is an example for tapestry and
>>>> cayenne and jersey 1.x rest. It seems to rely on a JerseyTapestryBridge
>>>> [1] but the code looks specific to jersey 1.x and wouldn't work with
>>>> jersey 2.x
>>>>
>>>> Cheers
>>>>
>>>> Tim
>>>>
>>>> [1]
>>>>
>>>>
>> https://github.com/andrus/wowodc13/blob/master/site/src/main/java/demo/rest/jersey/JerseyTapestryBridge.java
>>>> On 3/8/21 17:15, Ben Weidig wrote:
>>>>> Hi Tim,
>>>>>
>>>>> full disclosure: I haven't used Cayenne or Agrest, but I checked out
>>>> their
>>>>> documentation.
>>>>>
>>>>> I don't think there's anything Tapestry-specific needed to get it up
>> and
>>>>> running except setting up Rest.
>>>>> They say in their docs that you still have to write your JAX-RS
>> endpoints
>>>>> and do security yourself.
>>>>>
>>>>> For JAX-RS, there's tapestry-resteasy
>>>>> https://www.tynamo.org/tapestry-resteasy+guide/
>>>>> There are examples how to add Rest to Tapestry and register your
>>>> resources.
>>>>> The AgRuntime should be contributable just like a Rest resource.
>> RestEasy
>>>>> treats many of its classes are contributable (Resources, Provider,
>> etc.).
>>>>> You could create a service to build it.
>>>>>
>>>>> @Contribute(javax.ws.rs.core.Application.class)
>>>>> public static void configureRestProviders(Configuration<Object>
>>>> singletons,
>>>>> YourAgRuntimeBuilder builder) {
>>>>>     singletons.add(builder.build());
>>>>>     singletons.addInstance(YourCredentialsInterceptor.class);
>>>>>     singletons.addInstance(YourResource.class);
>>>>> }
>>>>>
>>>>> For security, we use custom headers containing an API key/secret that
>> are
>>>>> validated by a javax.ws.rs.container.ContainerRequestFilter with
>>>>> @Priority(Priorities.AUTHENTICATION) and
>>>>> @Priority(Priorities.AUTHORIZATION) and plug in your security code.
>>>>>
>>>>> But as said before, I haven't tested it, and it just looks this way to
>> me
>>>>> at first glance.
>>>>>
>>>>> Cheers,
>>>>> Ben
>>>>>
>>>>> On Tue, Aug 3, 2021 at 5:28 AM D Tim Cummings
>>>> <ti...@triptera.com.au.invalid>
>>>>> wrote:
>>>>>
>>>>>> Does anyone have experience integrating Agrest (https://agrest.io/)
>>>> into
>>>>>> a Tapestry app? My Tapestry app uses Cayenne ORM and it looks like
>>>>>> Agrest works well with Cayenne to produce REST functionality. It would
>>>>>> be helpful to see some sample code.
>>>>>>
>>>>>> Thanks in advance
>>>>>>
>>>>>> Tim
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Integrating Agrest in Tapestry app

Posted by Ben Weidig <be...@netzgut.net>.
Hi Tim,

your code looks fine to me, but it seems like this is a limitation of
tapestry-resteasy.

The project wraps the configuration of RESTEasy to make it easier to use
with Tapestry.
The method
https://github.com/tynamo/tapestry-resteasy/blob/0111a37e842a67e49b47752de85d738676c179e9/src/main/java/org/tynamo/resteasy/ResteasyRequestFilter.java#L138
goes over the contributed instances and classes, but it doesn't support all
the available types RESTEasy has to offer, so it throws the exception
you're getting.
Only Resources and Providers are supported, but AgRuntime is a "Feature"
type.

The only option I see (without tapestry-resteasy adding it) is overriding
the ResteasyRequestFilter and extending the conditions for provider
detection to allow instances of Feature, too.
Features are internally registered like providers if I saw it correctly in
the RESTEasy code.

I've only read the tapestry-resteasy/RESTEasy source code and not tested it
with a running project, so it might not be that easy.


On Fri, Aug 6, 2021 at 1:52 PM D Tim Cummings <ti...@triptera.com.au.invalid>
wrote:

> Hi Ben
>
> I followed your suggestions and was able to get rest working with
> tapestry-resteasy without using persistence. However when I added agrest
> tapestry resteasy threw an exception unknown class type:
> io.agrest.runtime.AgRuntime. My code is as follows. I am using a simple
> data model from https://github.com/agrestio/agrest-bookstore-example .
> Could you please check I have implemented your suggestions correctly.
>
>  - add tapestry-resteasy to your project
>
> <dependency>
>     <groupId>org.tynamo</groupId>
>     <artifactId>tapestry-resteasy</artifactId>
>     <version>0.7.0</version>
> </dependency>
>
>  - write a service to setup the AgRuntime
>
> public class AgrestServiceImpl implements AgrestService {
>   public AgrestServiceImpl() {
>     ServerRuntime runtime =
> ServerRuntime.builder().addConfig("cayenne-project.xml").build();
>     AgCayenneModule cayenneExt = AgCayenneBuilder.build(runtime);
>     agRuntime = new AgBuilder().module(cayenneExt).build();
>   }
>   private AgRuntime agRuntime;
>   public AgRuntime agRuntime() {
>     return agRuntime;
>   }
> }
>
>
>  - write a simple resource with a single @GET method using Agrest
>
> @Path("/category")
> @Produces(MediaType.APPLICATION_JSON)
> public class CategoryResource {
>   @Context
>   private Configuration config;
>   @GET
>   public DataResponse<Category> getAll(@Context UriInfo uriInfo) {
>       return Ag.select(Category.class, config).uri(uriInfo).get();
>   }
> }
>
>
>  - contribute the AgRuntime and resource like in my previous mail.
>
>     @Contribute(javax.ws.rs.core.Application.class)
>     public static void configureRestProviders(Configuration<Object>
> singletons, AgrestService svcAgrest) {
>         singletons.add(svcAgrest.agRuntime());
>         singletons.addInstance(CategoryResource.class);
>     }
>
>
>  - test it with your browser or curl
>
> http://localhost:8089/tapestry-agrest/rest/category
>
> java.lang.RuntimeException: Exception constructing service
> 'ResteasyRequestFilter': Error invoking constructor public
>
> org.tynamo.resteasy.ResteasyRequestFilter(java.lang.String,org.slf4j.Logger,org.apache.tapestry5.http.services.ApplicationGlobals,javax.ws.rs.core.Application,org.apache.tapestry5.ioc.services.SymbolSource,boolean,org.apache.tapestry5.ioc.services.UpdateListenerHub,long,long,boolean)
>  throws javax.servlet.ServletException: Application.getSingletons()
> returned unknown class type: io.agrest.runtime.AgRuntime
>
>
> On 3/8/21 22:06, Ben Weidig wrote:
> > tapestry-resteasy is just bringing RESTEasy to Tapestry.
> > There's no dependency to JPA/Hibernate.
> > Do you mean the PersistenceService in the example on the page under "Code
> > your singleton resource"?
> > That's not a necessity, just an example for a Rest resource.
> > In your case, you would use Agrest instead.
> >
> > You don't need to edit web.xml because tapestry-resteasy uses a Tapestry
> > HttpServletRequestFilter to piggyback Tapstry itself, instead of going
> > through the a custom servlet defined in the web.xml.
> > Everything that would be done in the web.xml is done with code instead.
> > This way, you don't need an extra Bridge to handle service injection.
> >
> >
> https://github.com/tynamo/tapestry-resteasy/blob/master/src/main/java/org/tynamo/resteasy/ResteasyRequestFilter.java
> >
> > The next steps for simple proof-of-concept would be something like this:
> >
> > - add tapestry-resteasy to your project
> > - write a service to setup the AgRuntime
> > - write a simple resource with a single @GET method using Agrest
> > - contribute the AgRuntime and resource like in my previous mail.
> > - test it with your browser or curl
> >
> > Hope this helps!
> >
> > On Tue, Aug 3, 2021 at 1:12 PM D Tim Cummings
> <ti...@triptera.com.au.invalid>
> > wrote:
> >
> >> Thanks for this very detailed reply. I will work through what you have
> >> suggested and see how I go.
> >>
> >> I had a look at tapestry-resteasy but it seems to rely on hibernate or
> >> jpa and I am using cayenne. I am not sure what is required for
> >> org.tynamo.services.PersistenceService. Also tapestry-resteasy says I
> >> don't need to edit web.xml.
> >>
> >> Another example I am following says I do need to edit web.xml.
> >> https://github.com/andrus/wowodc13 is an example for tapestry and
> >> cayenne and jersey 1.x rest. It seems to rely on a JerseyTapestryBridge
> >> [1] but the code looks specific to jersey 1.x and wouldn't work with
> >> jersey 2.x
> >>
> >> Cheers
> >>
> >> Tim
> >>
> >> [1]
> >>
> >>
> https://github.com/andrus/wowodc13/blob/master/site/src/main/java/demo/rest/jersey/JerseyTapestryBridge.java
> >>
> >> On 3/8/21 17:15, Ben Weidig wrote:
> >>> Hi Tim,
> >>>
> >>> full disclosure: I haven't used Cayenne or Agrest, but I checked out
> >> their
> >>> documentation.
> >>>
> >>> I don't think there's anything Tapestry-specific needed to get it up
> and
> >>> running except setting up Rest.
> >>> They say in their docs that you still have to write your JAX-RS
> endpoints
> >>> and do security yourself.
> >>>
> >>> For JAX-RS, there's tapestry-resteasy
> >>> https://www.tynamo.org/tapestry-resteasy+guide/
> >>> There are examples how to add Rest to Tapestry and register your
> >> resources.
> >>> The AgRuntime should be contributable just like a Rest resource.
> RestEasy
> >>> treats many of its classes are contributable (Resources, Provider,
> etc.).
> >>> You could create a service to build it.
> >>>
> >>> @Contribute(javax.ws.rs.core.Application.class)
> >>> public static void configureRestProviders(Configuration<Object>
> >> singletons,
> >>> YourAgRuntimeBuilder builder) {
> >>>     singletons.add(builder.build());
> >>>     singletons.addInstance(YourCredentialsInterceptor.class);
> >>>     singletons.addInstance(YourResource.class);
> >>> }
> >>>
> >>> For security, we use custom headers containing an API key/secret that
> are
> >>> validated by a javax.ws.rs.container.ContainerRequestFilter with
> >>> @Priority(Priorities.AUTHENTICATION) and
> >>> @Priority(Priorities.AUTHORIZATION) and plug in your security code.
> >>>
> >>> But as said before, I haven't tested it, and it just looks this way to
> me
> >>> at first glance.
> >>>
> >>> Cheers,
> >>> Ben
> >>>
> >>> On Tue, Aug 3, 2021 at 5:28 AM D Tim Cummings
> >> <ti...@triptera.com.au.invalid>
> >>> wrote:
> >>>
> >>>> Does anyone have experience integrating Agrest (https://agrest.io/)
> >> into
> >>>> a Tapestry app? My Tapestry app uses Cayenne ORM and it looks like
> >>>> Agrest works well with Cayenne to produce REST functionality. It would
> >>>> be helpful to see some sample code.
> >>>>
> >>>> Thanks in advance
> >>>>
> >>>> Tim
> >>>>
> >>>>
> >>>>
> >>>>
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Integrating Agrest in Tapestry app

Posted by D Tim Cummings <ti...@triptera.com.au.INVALID>.
Hi Ben

I followed your suggestions and was able to get rest working with
tapestry-resteasy without using persistence. However when I added agrest
tapestry resteasy threw an exception unknown class type:
io.agrest.runtime.AgRuntime. My code is as follows. I am using a simple
data model from https://github.com/agrestio/agrest-bookstore-example .
Could you please check I have implemented your suggestions correctly.

 - add tapestry-resteasy to your project

<dependency>
    <groupId>org.tynamo</groupId>
    <artifactId>tapestry-resteasy</artifactId>
    <version>0.7.0</version>
</dependency>

 - write a service to setup the AgRuntime

public class AgrestServiceImpl implements AgrestService {
  public AgrestServiceImpl() {
    ServerRuntime runtime = ServerRuntime.builder().addConfig("cayenne-project.xml").build();
    AgCayenneModule cayenneExt = AgCayenneBuilder.build(runtime);
    agRuntime = new AgBuilder().module(cayenneExt).build();
  }
  private AgRuntime agRuntime;
  public AgRuntime agRuntime() {
    return agRuntime;
  }
}


 - write a simple resource with a single @GET method using Agrest

@Path("/category")
@Produces(MediaType.APPLICATION_JSON)
public class CategoryResource {
  @Context
  private Configuration config;
  @GET
  public DataResponse<Category> getAll(@Context UriInfo uriInfo) {
      return Ag.select(Category.class, config).uri(uriInfo).get();
  }
}


 - contribute the AgRuntime and resource like in my previous mail.

    @Contribute(javax.ws.rs.core.Application.class)
    public static void configureRestProviders(Configuration<Object> singletons, AgrestService svcAgrest) {
        singletons.add(svcAgrest.agRuntime());
        singletons.addInstance(CategoryResource.class);
    }


 - test it with your browser or curl

http://localhost:8089/tapestry-agrest/rest/category

java.lang.RuntimeException: Exception constructing service 
'ResteasyRequestFilter': Error invoking constructor public 
org.tynamo.resteasy.ResteasyRequestFilter(java.lang.String,org.slf4j.Logger,org.apache.tapestry5.http.services.ApplicationGlobals,javax.ws.rs.core.Application,org.apache.tapestry5.ioc.services.SymbolSource,boolean,org.apache.tapestry5.ioc.services.UpdateListenerHub,long,long,boolean)
 throws javax.servlet.ServletException: Application.getSingletons() 
returned unknown class type: io.agrest.runtime.AgRuntime


On 3/8/21 22:06, Ben Weidig wrote:
> tapestry-resteasy is just bringing RESTEasy to Tapestry.
> There's no dependency to JPA/Hibernate.
> Do you mean the PersistenceService in the example on the page under "Code
> your singleton resource"?
> That's not a necessity, just an example for a Rest resource.
> In your case, you would use Agrest instead.
>
> You don't need to edit web.xml because tapestry-resteasy uses a Tapestry
> HttpServletRequestFilter to piggyback Tapstry itself, instead of going
> through the a custom servlet defined in the web.xml.
> Everything that would be done in the web.xml is done with code instead.
> This way, you don't need an extra Bridge to handle service injection.
>
> https://github.com/tynamo/tapestry-resteasy/blob/master/src/main/java/org/tynamo/resteasy/ResteasyRequestFilter.java
>
> The next steps for simple proof-of-concept would be something like this:
>
> - add tapestry-resteasy to your project
> - write a service to setup the AgRuntime
> - write a simple resource with a single @GET method using Agrest
> - contribute the AgRuntime and resource like in my previous mail.
> - test it with your browser or curl
>
> Hope this helps!
>
> On Tue, Aug 3, 2021 at 1:12 PM D Tim Cummings <ti...@triptera.com.au.invalid>
> wrote:
>
>> Thanks for this very detailed reply. I will work through what you have
>> suggested and see how I go.
>>
>> I had a look at tapestry-resteasy but it seems to rely on hibernate or
>> jpa and I am using cayenne. I am not sure what is required for
>> org.tynamo.services.PersistenceService. Also tapestry-resteasy says I
>> don't need to edit web.xml.
>>
>> Another example I am following says I do need to edit web.xml.
>> https://github.com/andrus/wowodc13 is an example for tapestry and
>> cayenne and jersey 1.x rest. It seems to rely on a JerseyTapestryBridge
>> [1] but the code looks specific to jersey 1.x and wouldn't work with
>> jersey 2.x
>>
>> Cheers
>>
>> Tim
>>
>> [1]
>>
>> https://github.com/andrus/wowodc13/blob/master/site/src/main/java/demo/rest/jersey/JerseyTapestryBridge.java
>>
>> On 3/8/21 17:15, Ben Weidig wrote:
>>> Hi Tim,
>>>
>>> full disclosure: I haven't used Cayenne or Agrest, but I checked out
>> their
>>> documentation.
>>>
>>> I don't think there's anything Tapestry-specific needed to get it up and
>>> running except setting up Rest.
>>> They say in their docs that you still have to write your JAX-RS endpoints
>>> and do security yourself.
>>>
>>> For JAX-RS, there's tapestry-resteasy
>>> https://www.tynamo.org/tapestry-resteasy+guide/
>>> There are examples how to add Rest to Tapestry and register your
>> resources.
>>> The AgRuntime should be contributable just like a Rest resource. RestEasy
>>> treats many of its classes are contributable (Resources, Provider, etc.).
>>> You could create a service to build it.
>>>
>>> @Contribute(javax.ws.rs.core.Application.class)
>>> public static void configureRestProviders(Configuration<Object>
>> singletons,
>>> YourAgRuntimeBuilder builder) {
>>>     singletons.add(builder.build());
>>>     singletons.addInstance(YourCredentialsInterceptor.class);
>>>     singletons.addInstance(YourResource.class);
>>> }
>>>
>>> For security, we use custom headers containing an API key/secret that are
>>> validated by a javax.ws.rs.container.ContainerRequestFilter with
>>> @Priority(Priorities.AUTHENTICATION) and
>>> @Priority(Priorities.AUTHORIZATION) and plug in your security code.
>>>
>>> But as said before, I haven't tested it, and it just looks this way to me
>>> at first glance.
>>>
>>> Cheers,
>>> Ben
>>>
>>> On Tue, Aug 3, 2021 at 5:28 AM D Tim Cummings
>> <ti...@triptera.com.au.invalid>
>>> wrote:
>>>
>>>> Does anyone have experience integrating Agrest (https://agrest.io/)
>> into
>>>> a Tapestry app? My Tapestry app uses Cayenne ORM and it looks like
>>>> Agrest works well with Cayenne to produce REST functionality. It would
>>>> be helpful to see some sample code.
>>>>
>>>> Thanks in advance
>>>>
>>>> Tim
>>>>
>>>>
>>>>
>>>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Integrating Agrest in Tapestry app

Posted by Ben Weidig <be...@netzgut.net>.
tapestry-resteasy is just bringing RESTEasy to Tapestry.
There's no dependency to JPA/Hibernate.
Do you mean the PersistenceService in the example on the page under "Code
your singleton resource"?
That's not a necessity, just an example for a Rest resource.
In your case, you would use Agrest instead.

You don't need to edit web.xml because tapestry-resteasy uses a Tapestry
HttpServletRequestFilter to piggyback Tapstry itself, instead of going
through the a custom servlet defined in the web.xml.
Everything that would be done in the web.xml is done with code instead.
This way, you don't need an extra Bridge to handle service injection.

https://github.com/tynamo/tapestry-resteasy/blob/master/src/main/java/org/tynamo/resteasy/ResteasyRequestFilter.java

The next steps for simple proof-of-concept would be something like this:

- add tapestry-resteasy to your project
- write a service to setup the AgRuntime
- write a simple resource with a single @GET method using Agrest
- contribute the AgRuntime and resource like in my previous mail.
- test it with your browser or curl

Hope this helps!

On Tue, Aug 3, 2021 at 1:12 PM D Tim Cummings <ti...@triptera.com.au.invalid>
wrote:

> Thanks for this very detailed reply. I will work through what you have
> suggested and see how I go.
>
> I had a look at tapestry-resteasy but it seems to rely on hibernate or
> jpa and I am using cayenne. I am not sure what is required for
> org.tynamo.services.PersistenceService. Also tapestry-resteasy says I
> don't need to edit web.xml.
>
> Another example I am following says I do need to edit web.xml.
> https://github.com/andrus/wowodc13 is an example for tapestry and
> cayenne and jersey 1.x rest. It seems to rely on a JerseyTapestryBridge
> [1] but the code looks specific to jersey 1.x and wouldn't work with
> jersey 2.x
>
> Cheers
>
> Tim
>
> [1]
>
> https://github.com/andrus/wowodc13/blob/master/site/src/main/java/demo/rest/jersey/JerseyTapestryBridge.java
>
> On 3/8/21 17:15, Ben Weidig wrote:
> > Hi Tim,
> >
> > full disclosure: I haven't used Cayenne or Agrest, but I checked out
> their
> > documentation.
> >
> > I don't think there's anything Tapestry-specific needed to get it up and
> > running except setting up Rest.
> > They say in their docs that you still have to write your JAX-RS endpoints
> > and do security yourself.
> >
> > For JAX-RS, there's tapestry-resteasy
> > https://www.tynamo.org/tapestry-resteasy+guide/
> > There are examples how to add Rest to Tapestry and register your
> resources.
> >
> > The AgRuntime should be contributable just like a Rest resource. RestEasy
> > treats many of its classes are contributable (Resources, Provider, etc.).
> > You could create a service to build it.
> >
> > @Contribute(javax.ws.rs.core.Application.class)
> > public static void configureRestProviders(Configuration<Object>
> singletons,
> > YourAgRuntimeBuilder builder) {
> >     singletons.add(builder.build());
> >     singletons.addInstance(YourCredentialsInterceptor.class);
> >     singletons.addInstance(YourResource.class);
> > }
> >
> > For security, we use custom headers containing an API key/secret that are
> > validated by a javax.ws.rs.container.ContainerRequestFilter with
> > @Priority(Priorities.AUTHENTICATION) and
> > @Priority(Priorities.AUTHORIZATION) and plug in your security code.
> >
> > But as said before, I haven't tested it, and it just looks this way to me
> > at first glance.
> >
> > Cheers,
> > Ben
> >
> > On Tue, Aug 3, 2021 at 5:28 AM D Tim Cummings
> <ti...@triptera.com.au.invalid>
> > wrote:
> >
> >> Does anyone have experience integrating Agrest (https://agrest.io/)
> into
> >> a Tapestry app? My Tapestry app uses Cayenne ORM and it looks like
> >> Agrest works well with Cayenne to produce REST functionality. It would
> >> be helpful to see some sample code.
> >>
> >> Thanks in advance
> >>
> >> Tim
> >>
> >>
> >>
> >>
>
>

Re: Integrating Agrest in Tapestry app

Posted by D Tim Cummings <ti...@triptera.com.au.INVALID>.
Thanks Thiago and Ben for your great responses. I am working through
these suggestions at the moment.

I thought I would build a fresh tapestry app based on the quickstart and
introduce tapestry-resteasy and agrest.

Tim

On 6/8/21 02:14, Thiago H. de Paula Figueiredo wrote:
> Ouch, I should have checked Ben's brilliant response before I wrote my own,
> inferior one.
>
> On Thu, Aug 5, 2021 at 1:12 PM Thiago H. de Paula Figueiredo <
> thiagohp@gmail.com> wrote:
>
>> On Tue, Aug 3, 2021 at 8:12 AM D Tim Cummings <ti...@triptera.com.au.invalid>
>> wrote:
>>
>>> I had a look at tapestry-resteasy but it seems to rely on hibernate or
>>> jpa and I am using cayenne.
>>
>> tapestry-resteasy doesn't rely on either Hibernate or JPA nor any other
>> ORM:
>> https://repo1.maven.org/maven2/org/tynamo/tapestry-resteasy/0.7.0/tapestry-resteasy-0.7.0.pom
>>
>>
>>> I am not sure what is required for
>>> org.tynamo.services.PersistenceService.
>>
>> I don't think it's needed either. I guess you're confusing the code
>> examples with requirements.
>>
>>
>>> Also tapestry-resteasy says I
>>> don't need to edit web.xml.
>>>
>> That's correct. tapestry-resteasy it takes care of telling
>> Tapestry-the-page-framework to not handle requests to the REST URLs while
>> also handling these URLs inside Tapestry (either as an RequestFilter or an
>> HttpServletRequestFilter). Tapestry itself is implemented as a servlet
>> filter receiving all requests, even though it may not actually provide the
>> response for all of them.
>>
>> --
>> Thiago
>>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Integrating Agrest in Tapestry app

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Ouch, I should have checked Ben's brilliant response before I wrote my own,
inferior one.

On Thu, Aug 5, 2021 at 1:12 PM Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Tue, Aug 3, 2021 at 8:12 AM D Tim Cummings <ti...@triptera.com.au.invalid>
> wrote:
>
>> I had a look at tapestry-resteasy but it seems to rely on hibernate or
>> jpa and I am using cayenne.
>
>
> tapestry-resteasy doesn't rely on either Hibernate or JPA nor any other
> ORM:
> https://repo1.maven.org/maven2/org/tynamo/tapestry-resteasy/0.7.0/tapestry-resteasy-0.7.0.pom
>
>
>> I am not sure what is required for
>> org.tynamo.services.PersistenceService.
>
>
> I don't think it's needed either. I guess you're confusing the code
> examples with requirements.
>
>
>> Also tapestry-resteasy says I
>> don't need to edit web.xml.
>>
>
> That's correct. tapestry-resteasy it takes care of telling
> Tapestry-the-page-framework to not handle requests to the REST URLs while
> also handling these URLs inside Tapestry (either as an RequestFilter or an
> HttpServletRequestFilter). Tapestry itself is implemented as a servlet
> filter receiving all requests, even though it may not actually provide the
> response for all of them.
>
> --
> Thiago
>


-- 
Thiago

Re: Integrating Agrest in Tapestry app

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, Aug 3, 2021 at 8:12 AM D Tim Cummings <ti...@triptera.com.au.invalid>
wrote:

> I had a look at tapestry-resteasy but it seems to rely on hibernate or
> jpa and I am using cayenne.


tapestry-resteasy doesn't rely on either Hibernate or JPA nor any other
ORM:
https://repo1.maven.org/maven2/org/tynamo/tapestry-resteasy/0.7.0/tapestry-resteasy-0.7.0.pom


> I am not sure what is required for
> org.tynamo.services.PersistenceService.


I don't think it's needed either. I guess you're confusing the code
examples with requirements.


> Also tapestry-resteasy says I
> don't need to edit web.xml.
>

That's correct. tapestry-resteasy it takes care of telling
Tapestry-the-page-framework to not handle requests to the REST URLs while
also handling these URLs inside Tapestry (either as an RequestFilter or an
HttpServletRequestFilter). Tapestry itself is implemented as a servlet
filter receiving all requests, even though it may not actually provide the
response for all of them.

--
Thiago

Re: Integrating Agrest in Tapestry app

Posted by D Tim Cummings <ti...@triptera.com.au.INVALID>.
Thanks for this very detailed reply. I will work through what you have
suggested and see how I go.

I had a look at tapestry-resteasy but it seems to rely on hibernate or
jpa and I am using cayenne. I am not sure what is required for
org.tynamo.services.PersistenceService. Also tapestry-resteasy says I
don't need to edit web.xml.

Another example I am following says I do need to edit web.xml.
https://github.com/andrus/wowodc13 is an example for tapestry and
cayenne and jersey 1.x rest. It seems to rely on a JerseyTapestryBridge
[1] but the code looks specific to jersey 1.x and wouldn't work with
jersey 2.x

Cheers

Tim

[1]
https://github.com/andrus/wowodc13/blob/master/site/src/main/java/demo/rest/jersey/JerseyTapestryBridge.java

On 3/8/21 17:15, Ben Weidig wrote:
> Hi Tim,
>
> full disclosure: I haven't used Cayenne or Agrest, but I checked out their
> documentation.
>
> I don't think there's anything Tapestry-specific needed to get it up and
> running except setting up Rest.
> They say in their docs that you still have to write your JAX-RS endpoints
> and do security yourself.
>
> For JAX-RS, there's tapestry-resteasy
> https://www.tynamo.org/tapestry-resteasy+guide/
> There are examples how to add Rest to Tapestry and register your resources.
>
> The AgRuntime should be contributable just like a Rest resource. RestEasy
> treats many of its classes are contributable (Resources, Provider, etc.).
> You could create a service to build it.
>
> @Contribute(javax.ws.rs.core.Application.class)
> public static void configureRestProviders(Configuration<Object> singletons,
> YourAgRuntimeBuilder builder) {
>     singletons.add(builder.build());
>     singletons.addInstance(YourCredentialsInterceptor.class);
>     singletons.addInstance(YourResource.class);
> }
>
> For security, we use custom headers containing an API key/secret that are
> validated by a javax.ws.rs.container.ContainerRequestFilter with
> @Priority(Priorities.AUTHENTICATION) and
> @Priority(Priorities.AUTHORIZATION) and plug in your security code.
>
> But as said before, I haven't tested it, and it just looks this way to me
> at first glance.
>
> Cheers,
> Ben
>
> On Tue, Aug 3, 2021 at 5:28 AM D Tim Cummings <ti...@triptera.com.au.invalid>
> wrote:
>
>> Does anyone have experience integrating Agrest (https://agrest.io/) into
>> a Tapestry app? My Tapestry app uses Cayenne ORM and it looks like
>> Agrest works well with Cayenne to produce REST functionality. It would
>> be helpful to see some sample code.
>>
>> Thanks in advance
>>
>> Tim
>>
>>
>>
>>


Re: Integrating Agrest in Tapestry app

Posted by Ben Weidig <be...@netzgut.net>.
Hi Tim,

full disclosure: I haven't used Cayenne or Agrest, but I checked out their
documentation.

I don't think there's anything Tapestry-specific needed to get it up and
running except setting up Rest.
They say in their docs that you still have to write your JAX-RS endpoints
and do security yourself.

For JAX-RS, there's tapestry-resteasy
https://www.tynamo.org/tapestry-resteasy+guide/
There are examples how to add Rest to Tapestry and register your resources.

The AgRuntime should be contributable just like a Rest resource. RestEasy
treats many of its classes are contributable (Resources, Provider, etc.).
You could create a service to build it.

@Contribute(javax.ws.rs.core.Application.class)
public static void configureRestProviders(Configuration<Object> singletons,
YourAgRuntimeBuilder builder) {
    singletons.add(builder.build());
    singletons.addInstance(YourCredentialsInterceptor.class);
    singletons.addInstance(YourResource.class);
}

For security, we use custom headers containing an API key/secret that are
validated by a javax.ws.rs.container.ContainerRequestFilter with
@Priority(Priorities.AUTHENTICATION) and
@Priority(Priorities.AUTHORIZATION) and plug in your security code.

But as said before, I haven't tested it, and it just looks this way to me
at first glance.

Cheers,
Ben

On Tue, Aug 3, 2021 at 5:28 AM D Tim Cummings <ti...@triptera.com.au.invalid>
wrote:

> Does anyone have experience integrating Agrest (https://agrest.io/) into
> a Tapestry app? My Tapestry app uses Cayenne ORM and it looks like
> Agrest works well with Cayenne to produce REST functionality. It would
> be helpful to see some sample code.
>
> Thanks in advance
>
> Tim
>
>
>
>