You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@isis.apache.org by Erik de Hair <e....@pocos.nl> on 2017/04/10 09:57:08 UTC

Using the restful interface with view models

Hi,

For some use case we have a Wicket wizard using Apache Isis view models 
where each step enriches the view model as returned by the previous step 
until it is ready to submit. I was trying to redo this using the restful 
interface but I can't figure out what's the objectId of the returned 
view model. I need that I to start the actions related to the next step.

So I have an action 
/objects/WbaAvailability/{objectId}/actions/startAccessOrderCopper/invoke where 
object WbaAvailability is a view model. An other action (executed 
before) returns a list of WbaAvailabilities. But how to use one of these 
and invoke the startAccessOrderCopper-action?

Thanks,
Erik

Re: Using the restful interface with view models

Posted by Erik de Hair <e....@pocos.nl>.
Hi Dan,

This sounds like an 'easy' solution. How about validation of the payload 
and creating the correct xml-response together with (probably) the same 
response codes as the RO viewer? I believe it would also be nice to have 
the capability of 'unmarshalling' json objects to view models. That way 
there would be a nice and complete counterpart of an xml webservice.

For now I need a quick fix. I have to prepare a demo (proof of concept) 
for next tuesday. I will be using the RO viewer and flattened objects as 
a list of scalar parameters for now.

Thanks,
Erik


On 04/12/2017 04:38 PM, Dan Haywood wrote:
> That architecture probably would work, but I'm just wondering if it might
> be less work overall enhancing the current RO viewer to teach it how to
> handle XML payloads.
>
> In DomainObjectResourceServerSide (and similarly
> DomainServiceResourceServiceSide) there are the JAX-RS endpoints that
> process the inbound payloads, for example [1] for PUT and [2] for POST
> action.
>
> The call to init() just reads the body of the HTTP call to a UTF string,
> and stores in the ResourceContext data structure.
>
> This string is then converted to a JsonRepresentation being the arguments,
> eg [3]
>
> The arguments remain in Json form through to the DomainResourceHelper
> utilty class, where they are unmarshalled using [4]:
>
>      final ObjectActionArgHelper argHelper = new
> ObjectActionArgHelper(rendererContext, objectAdapter, action);
>      final List<ObjectAdapter> argAdapters =
> argHelper.parseAndValidateArguments(arguments);
>
> For [3], I'm thinking that a different sort of JsonRepresentation could be
> created, perhaps only happens if the HTTP Content-Type is set appropriately
> [5] to some special value; this could then let the JsonRepresentation also
> be self-describing, eg
>
> { "_isis_dtoType": "com.mycompany.mydto.SomeDto",
>    "_isis_dto": { "<xml>... serialization of an instance of this DTO </xml>"
> }
>
> For [4], we could instead "peek" inside the JsonRepresentation and if the
> "_isis_dtoType" property is present, then unmarshall the object itself
> using JAXB.
>
> I reckon that might only be a change to a dozen or so lines, and would be a
> very useful new capability of the RO viewer.
>
> WDYT?
> Dan
>
>
> [1]
> https://github.com/apache/isis/blob/master/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/DomainObjectResourceServerside.java#L487
> [2]
> https://github.com/apache/isis/blob/master/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/DomainObjectResourceServerside.java#L513
>
> [3]
> https://github.com/apache/isis/blob/master/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/DomainObjectResourceServerside.java#L518
>
> [4]
> https://github.com/apache/isis/blob/master/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/DomainResourceHelper.java#L363
> [5] https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
>
>
>
> On Wed, 12 Apr 2017 at 14:27 Erik de Hair <e....@pocos.nl> wrote:
>
>> Hi Dan,
>>
>> Thanks for your help. I'm not sure about the architecture.
>>
>> Would the following architecture do the trick:
>> - write my own xml web service, accepting xml complying to the view
>> model's xsd
>> - use the jaxb service to unmarshall the input to a domain entity
>> - use the wrapperfactory to wrap the actual service method call for
>> validation to be handled by Apache isis
>> - how to use a possible validation error as a response?
>>
>> Thanks,
>> Erik
>>
>>
>> On 04/12/2017 02:15 PM, Dan Haywood wrote:
>>> Hi Erik,
>>> sorry not to reply sooner.
>>>
>>> I'm afraid that serializing objects in this fashion isn't possible in the
>>> RO viewer.  The best/only workaround I can give you right now is to
>> define
>>> the property as a string and then to send the JSON as a string and
>>> deserialize within the receiving action:
>>>
>>>
>>> public void exampleAction(String addressAsJson, String foo) {
>>>       Address address = fromJson(addressAsJson);
>>> }
>>>
>>> Or, you could use XML of course.  The JAXB-style of view models would
>> make
>>> the deserialization easier actually, so you might want to go that route,
>>> using JaxbService [1]
>>>
>>> HTH
>>> Dan
>>>
>>> [1]
>> http://isis.apache.org/guides/rgsvc/rgsvc.html#_rgsvc_api_JaxbService
>>>
>>>
>>> On Wed, 12 Apr 2017 at 12:27 Erik de Hair <e....@pocos.nl> wrote:
>>>
>>>> Anyone? I can do this writing my own service class but I would like to
>>>> use Apache Isis' error handling etc.
>>>>
>>>> Erik
>>>>
>>>>
>>>> On 04/10/2017 05:44 PM, Erik de Hair wrote:
>>>>> Still figuring some things out...
>>>>>
>>>>> Is it possible to expose some service method using the RO viewer with
>>>>> complex type parameters like below?
>>>>>
>>>>> public void exampleAction(Address address, String foo){
>>>>>       // process input...
>>>>> }
>>>>>
>>>>> public class Address {
>>>>>       private String zipCode;
>>>>>       private String number;
>>>>> }
>>>>>
>>>>> I tried annotating the Address class with @ViewModel but then the RO
>>>>> viewer expects a link to an existing view model. I would like our
>>>>> external partners using the RO viewer to create json-objects (or xml?)
>>>>> that will be accepted by 'exampleAction'. How to do that?
>>>>>
>>>>> Thanks,
>>>>> Erik
>>>>>
>>>>>
>>>>> On 04/10/2017 11:57 AM, Erik de Hair wrote:
>>>>>> Hi,
>>>>>>
>>>>>> For some use case we have a Wicket wizard using Apache Isis view
>>>>>> models where each step enriches the view model as returned by the
>>>>>> previous step until it is ready to submit. I was trying to redo this
>>>>>> using the restful interface but I can't figure out what's the
>>>>>> objectId of the returned view model. I need that I to start the
>>>>>> actions related to the next step.
>>>>>>
>>>>>> So I have an action
>>>>>>
>> /objects/WbaAvailability/{objectId}/actions/startAccessOrderCopper/invoke
>>>>>> where object WbaAvailability is a view model. An other action
>>>>>> (executed before) returns a list of WbaAvailabilities. But how to use
>>>>>> one of these and invoke the startAccessOrderCopper-action?
>>>>>>
>>>>>> Thanks,
>>>>>> Erik
>>


Re: Using the restful interface with view models

Posted by Dan Haywood <da...@haywood-associates.co.uk>.
That architecture probably would work, but I'm just wondering if it might
be less work overall enhancing the current RO viewer to teach it how to
handle XML payloads.

In DomainObjectResourceServerSide (and similarly
DomainServiceResourceServiceSide) there are the JAX-RS endpoints that
process the inbound payloads, for example [1] for PUT and [2] for POST
action.

The call to init() just reads the body of the HTTP call to a UTF string,
and stores in the ResourceContext data structure.

This string is then converted to a JsonRepresentation being the arguments,
eg [3]

The arguments remain in Json form through to the DomainResourceHelper
utilty class, where they are unmarshalled using [4]:

    final ObjectActionArgHelper argHelper = new
ObjectActionArgHelper(rendererContext, objectAdapter, action);
    final List<ObjectAdapter> argAdapters =
argHelper.parseAndValidateArguments(arguments);

For [3], I'm thinking that a different sort of JsonRepresentation could be
created, perhaps only happens if the HTTP Content-Type is set appropriately
[5] to some special value; this could then let the JsonRepresentation also
be self-describing, eg

{ "_isis_dtoType": "com.mycompany.mydto.SomeDto",
  "_isis_dto": { "<xml>... serialization of an instance of this DTO </xml>"
}

For [4], we could instead "peek" inside the JsonRepresentation and if the
"_isis_dtoType" property is present, then unmarshall the object itself
using JAXB.

I reckon that might only be a change to a dozen or so lines, and would be a
very useful new capability of the RO viewer.

WDYT?
Dan


[1]
https://github.com/apache/isis/blob/master/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/DomainObjectResourceServerside.java#L487
[2]
https://github.com/apache/isis/blob/master/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/DomainObjectResourceServerside.java#L513

[3]
https://github.com/apache/isis/blob/master/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/DomainObjectResourceServerside.java#L518

[4]
https://github.com/apache/isis/blob/master/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/DomainResourceHelper.java#L363
[5] https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type



On Wed, 12 Apr 2017 at 14:27 Erik de Hair <e....@pocos.nl> wrote:

> Hi Dan,
>
> Thanks for your help. I'm not sure about the architecture.
>
> Would the following architecture do the trick:
> - write my own xml web service, accepting xml complying to the view
> model's xsd
> - use the jaxb service to unmarshall the input to a domain entity
> - use the wrapperfactory to wrap the actual service method call for
> validation to be handled by Apache isis
> - how to use a possible validation error as a response?
>
> Thanks,
> Erik
>
>
> On 04/12/2017 02:15 PM, Dan Haywood wrote:
> > Hi Erik,
> > sorry not to reply sooner.
> >
> > I'm afraid that serializing objects in this fashion isn't possible in the
> > RO viewer.  The best/only workaround I can give you right now is to
> define
> > the property as a string and then to send the JSON as a string and
> > deserialize within the receiving action:
> >
> >
> > public void exampleAction(String addressAsJson, String foo) {
> >      Address address = fromJson(addressAsJson);
> > }
> >
> > Or, you could use XML of course.  The JAXB-style of view models would
> make
> > the deserialization easier actually, so you might want to go that route,
> > using JaxbService [1]
> >
> > HTH
> > Dan
> >
> > [1]
> http://isis.apache.org/guides/rgsvc/rgsvc.html#_rgsvc_api_JaxbService
> >
> >
> >
> > On Wed, 12 Apr 2017 at 12:27 Erik de Hair <e....@pocos.nl> wrote:
> >
> >> Anyone? I can do this writing my own service class but I would like to
> >> use Apache Isis' error handling etc.
> >>
> >> Erik
> >>
> >>
> >> On 04/10/2017 05:44 PM, Erik de Hair wrote:
> >>> Still figuring some things out...
> >>>
> >>> Is it possible to expose some service method using the RO viewer with
> >>> complex type parameters like below?
> >>>
> >>> public void exampleAction(Address address, String foo){
> >>>      // process input...
> >>> }
> >>>
> >>> public class Address {
> >>>      private String zipCode;
> >>>      private String number;
> >>> }
> >>>
> >>> I tried annotating the Address class with @ViewModel but then the RO
> >>> viewer expects a link to an existing view model. I would like our
> >>> external partners using the RO viewer to create json-objects (or xml?)
> >>> that will be accepted by 'exampleAction'. How to do that?
> >>>
> >>> Thanks,
> >>> Erik
> >>>
> >>>
> >>> On 04/10/2017 11:57 AM, Erik de Hair wrote:
> >>>> Hi,
> >>>>
> >>>> For some use case we have a Wicket wizard using Apache Isis view
> >>>> models where each step enriches the view model as returned by the
> >>>> previous step until it is ready to submit. I was trying to redo this
> >>>> using the restful interface but I can't figure out what's the
> >>>> objectId of the returned view model. I need that I to start the
> >>>> actions related to the next step.
> >>>>
> >>>> So I have an action
> >>>>
> >>
> /objects/WbaAvailability/{objectId}/actions/startAccessOrderCopper/invoke
> >>>> where object WbaAvailability is a view model. An other action
> >>>> (executed before) returns a list of WbaAvailabilities. But how to use
> >>>> one of these and invoke the startAccessOrderCopper-action?
> >>>>
> >>>> Thanks,
> >>>> Erik
> >>
>
>

Re: Using the restful interface with view models

Posted by Erik de Hair <e....@pocos.nl>.
Hi Dan,

Thanks for your help. I'm not sure about the architecture.

Would the following architecture do the trick:
- write my own xml web service, accepting xml complying to the view 
model's xsd
- use the jaxb service to unmarshall the input to a domain entity
- use the wrapperfactory to wrap the actual service method call for 
validation to be handled by Apache isis
- how to use a possible validation error as a response?

Thanks,
Erik


On 04/12/2017 02:15 PM, Dan Haywood wrote:
> Hi Erik,
> sorry not to reply sooner.
>
> I'm afraid that serializing objects in this fashion isn't possible in the
> RO viewer.  The best/only workaround I can give you right now is to define
> the property as a string and then to send the JSON as a string and
> deserialize within the receiving action:
>
>
> public void exampleAction(String addressAsJson, String foo) {
>      Address address = fromJson(addressAsJson);
> }
>
> Or, you could use XML of course.  The JAXB-style of view models would make
> the deserialization easier actually, so you might want to go that route,
> using JaxbService [1]
>
> HTH
> Dan
>
> [1] http://isis.apache.org/guides/rgsvc/rgsvc.html#_rgsvc_api_JaxbService
>
>
>
> On Wed, 12 Apr 2017 at 12:27 Erik de Hair <e....@pocos.nl> wrote:
>
>> Anyone? I can do this writing my own service class but I would like to
>> use Apache Isis' error handling etc.
>>
>> Erik
>>
>>
>> On 04/10/2017 05:44 PM, Erik de Hair wrote:
>>> Still figuring some things out...
>>>
>>> Is it possible to expose some service method using the RO viewer with
>>> complex type parameters like below?
>>>
>>> public void exampleAction(Address address, String foo){
>>>      // process input...
>>> }
>>>
>>> public class Address {
>>>      private String zipCode;
>>>      private String number;
>>> }
>>>
>>> I tried annotating the Address class with @ViewModel but then the RO
>>> viewer expects a link to an existing view model. I would like our
>>> external partners using the RO viewer to create json-objects (or xml?)
>>> that will be accepted by 'exampleAction'. How to do that?
>>>
>>> Thanks,
>>> Erik
>>>
>>>
>>> On 04/10/2017 11:57 AM, Erik de Hair wrote:
>>>> Hi,
>>>>
>>>> For some use case we have a Wicket wizard using Apache Isis view
>>>> models where each step enriches the view model as returned by the
>>>> previous step until it is ready to submit. I was trying to redo this
>>>> using the restful interface but I can't figure out what's the
>>>> objectId of the returned view model. I need that I to start the
>>>> actions related to the next step.
>>>>
>>>> So I have an action
>>>>
>> /objects/WbaAvailability/{objectId}/actions/startAccessOrderCopper/invoke
>>>> where object WbaAvailability is a view model. An other action
>>>> (executed before) returns a list of WbaAvailabilities. But how to use
>>>> one of these and invoke the startAccessOrderCopper-action?
>>>>
>>>> Thanks,
>>>> Erik
>>


Re: Using the restful interface with view models

Posted by Dan Haywood <da...@haywood-associates.co.uk>.
Hi Erik,
sorry not to reply sooner.

I'm afraid that serializing objects in this fashion isn't possible in the
RO viewer.  The best/only workaround I can give you right now is to define
the property as a string and then to send the JSON as a string and
deserialize within the receiving action:


public void exampleAction(String addressAsJson, String foo) {
    Address address = fromJson(addressAsJson);
}

Or, you could use XML of course.  The JAXB-style of view models would make
the deserialization easier actually, so you might want to go that route,
using JaxbService [1]

HTH
Dan

[1] http://isis.apache.org/guides/rgsvc/rgsvc.html#_rgsvc_api_JaxbService



On Wed, 12 Apr 2017 at 12:27 Erik de Hair <e....@pocos.nl> wrote:

> Anyone? I can do this writing my own service class but I would like to
> use Apache Isis' error handling etc.
>
> Erik
>
>
> On 04/10/2017 05:44 PM, Erik de Hair wrote:
> > Still figuring some things out...
> >
> > Is it possible to expose some service method using the RO viewer with
> > complex type parameters like below?
> >
> > public void exampleAction(Address address, String foo){
> >     // process input...
> > }
> >
> > public class Address {
> >     private String zipCode;
> >     private String number;
> > }
> >
> > I tried annotating the Address class with @ViewModel but then the RO
> > viewer expects a link to an existing view model. I would like our
> > external partners using the RO viewer to create json-objects (or xml?)
> > that will be accepted by 'exampleAction'. How to do that?
> >
> > Thanks,
> > Erik
> >
> >
> > On 04/10/2017 11:57 AM, Erik de Hair wrote:
> >> Hi,
> >>
> >> For some use case we have a Wicket wizard using Apache Isis view
> >> models where each step enriches the view model as returned by the
> >> previous step until it is ready to submit. I was trying to redo this
> >> using the restful interface but I can't figure out what's the
> >> objectId of the returned view model. I need that I to start the
> >> actions related to the next step.
> >>
> >> So I have an action
> >>
> /objects/WbaAvailability/{objectId}/actions/startAccessOrderCopper/invoke
> >> where object WbaAvailability is a view model. An other action
> >> (executed before) returns a list of WbaAvailabilities. But how to use
> >> one of these and invoke the startAccessOrderCopper-action?
> >>
> >> Thanks,
> >> Erik
> >
>
>

Re: Using the restful interface with view models

Posted by Erik de Hair <e....@pocos.nl>.
Anyone? I can do this writing my own service class but I would like to 
use Apache Isis' error handling etc.

Erik


On 04/10/2017 05:44 PM, Erik de Hair wrote:
> Still figuring some things out...
>
> Is it possible to expose some service method using the RO viewer with 
> complex type parameters like below?
>
> public void exampleAction(Address address, String foo){
>     // process input...
> }
>
> public class Address {
>     private String zipCode;
>     private String number;
> }
>
> I tried annotating the Address class with @ViewModel but then the RO 
> viewer expects a link to an existing view model. I would like our 
> external partners using the RO viewer to create json-objects (or xml?) 
> that will be accepted by 'exampleAction'. How to do that?
>
> Thanks,
> Erik
>
>
> On 04/10/2017 11:57 AM, Erik de Hair wrote:
>> Hi,
>>
>> For some use case we have a Wicket wizard using Apache Isis view 
>> models where each step enriches the view model as returned by the 
>> previous step until it is ready to submit. I was trying to redo this 
>> using the restful interface but I can't figure out what's the 
>> objectId of the returned view model. I need that I to start the 
>> actions related to the next step.
>>
>> So I have an action 
>> /objects/WbaAvailability/{objectId}/actions/startAccessOrderCopper/invoke 
>> where object WbaAvailability is a view model. An other action 
>> (executed before) returns a list of WbaAvailabilities. But how to use 
>> one of these and invoke the startAccessOrderCopper-action?
>>
>> Thanks,
>> Erik
>


Re: Using the restful interface with view models

Posted by Erik de Hair <e....@pocos.nl>.
Still figuring some things out...

Is it possible to expose some service method using the RO viewer with 
complex type parameters like below?

public void exampleAction(Address address, String foo){
     // process input...
}

public class Address {
     private String zipCode;
     private String number;
}

I tried annotating the Address class with @ViewModel but then the RO 
viewer expects a link to an existing view model. I would like our 
external partners using the RO viewer to create json-objects (or xml?) 
that will be accepted by 'exampleAction'. How to do that?

Thanks,
Erik


On 04/10/2017 11:57 AM, Erik de Hair wrote:
> Hi,
>
> For some use case we have a Wicket wizard using Apache Isis view 
> models where each step enriches the view model as returned by the 
> previous step until it is ready to submit. I was trying to redo this 
> using the restful interface but I can't figure out what's the objectId 
> of the returned view model. I need that I to start the actions related 
> to the next step.
>
> So I have an action 
> /objects/WbaAvailability/{objectId}/actions/startAccessOrderCopper/invoke 
> where object WbaAvailability is a view model. An other action 
> (executed before) returns a list of WbaAvailabilities. But how to use 
> one of these and invoke the startAccessOrderCopper-action?
>
> Thanks,
> Erik


Re: Using the restful interface with view models

Posted by Erik de Hair <e....@pocos.nl>.
Problem solved. I tried the instanceId but when calling an action on the 
view model I received a 404. That was correct because the action was 
hidden for the logged in user. I was mislead by the Swagger ui listing 
the action while there was a hide-method for the action.

Erik

On 04/10/2017 11:57 AM, Erik de Hair wrote:
> Hi,
>
> For some use case we have a Wicket wizard using Apache Isis view 
> models where each step enriches the view model as returned by the 
> previous step until it is ready to submit. I was trying to redo this 
> using the restful interface but I can't figure out what's the objectId 
> of the returned view model. I need that I to start the actions related 
> to the next step.
>
> So I have an action 
> /objects/WbaAvailability/{objectId}/actions/startAccessOrderCopper/invoke 
> where object WbaAvailability is a view model. An other action 
> (executed before) returns a list of WbaAvailabilities. But how to use 
> one of these and invoke the startAccessOrderCopper-action?
>
> Thanks,
> Erik