isis-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lechner Andreas <alech...@at.focusmr.com>
Subject Re: Questions for the Rest Interface for DomainService
Date Wed, 11 Mar 2015 08:58:06 GMT
Hi Dan,

thank you for the links.
I found a solution to parse the result json string.

best regards
Andreas

----- Ursprüngliche Mail -----
Von: "Dan Haywood" <dan@haywood-associates.co.uk>
An: "users" <users@isis.apache.org>
Gesendet: Dienstag, 3. März 2015 22:15:12
Betreff: Re: Questions for the Rest Interface for DomainService

Hi Andreas,

Sorry, never got round to answering this mail (got busy getting 1.8.0 out
of the door).

The short answer is that the way you parse the representations is up to
you, however we do have an applib that you can use, [1].

There is an incomplete test suite ("tck") that demonstrates the use of some
of the library. But a good example to look at is [2]... you can either call
resources in a HATEOAS style (follow the links), or in an RPC style (using
the RestEasy client-side proxy approach).

if you care about such things, there is also a C# applib (embedded in [3])
and also one for Javascript [4]

~~~
Alternatively, you can use Isis' experimental support for customized
(non-RO) representations [5].  This will allow you to define a DTO and
serialize into it, in the way I think you were trying to do.

HTH
Dan


[1]
https://github.com/apache/isis/tree/master/core/viewer-restfulobjects-applib/src/main/java/org/apache/isis/viewer/restfulobjects/applib
[2]
https://github.com/apache/isis/blob/master/tck/tck-viewer-restfulobjects/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobjectorservice/id/action/invoke/Get_givenActionSemanticsOfSafe_ok.java
[3] https://github.com/danhaywood/restfulobjects-wsa
[4] https://github.com/SpiroLibraries/Spiro.Models
[5]
http://isis.apache.org/components/viewers/restfulobjects/custom-representations.html




On 10 February 2015 at 11:20, Lechner Andreas <alechner@at.focusmr.com>
wrote:

> Hi,
>
> i have another question to this topic. :-)
>
> How do you parse the response object from json?
>
> Now i use for testing:
>
>         ClientRequest findRequest = new ClientRequest(
>                 "
> http://localhost:8080/restful/services/DeliverableService/actions/find/invoke
> ",
>                 executor);
>
>
>         StringBuilder findStringBuilder = new StringBuilder();
>         findStringBuilder
>                         .append("{")
>                         .append("\"deliverable\": {\"value\": {\"href\": ")
>                         .append("\"
> http://localhost:8080/restful/objects/Deliverable/I_3\"}} ")
>                         .append("}");
>
>         findRequest.body("application/json", findStringBuilder.toString());
>         ClientResponse<Deliverable> findResponse =
> findRequest.post(Deliverable.class);
>         Deliverable deliverable = findResponse.getEntity();
>
> My Service looks like:
>
>         @NotContributed
>         @MemberOrder(sequence = "3")
>         @Named("Find One Deliverable")
>         public Deliverable find(final @Named("deliverable") Deliverable
> deliverable) {
>                 return deliverable;
>         }
>
>         public List<Deliverable> autoComplete0Find(final @MinLength(1)
> String search) {
>         ....
>
> I get everytime the error
> Caused by: org.codehaus.jackson.map.exc.UnrecognizedPropertyException:
> Unrecognized field "links" (Class dom.crm.dim.Deliverable), not marked as
> ignorable
> because there is no class member "links" in Deliverable.
>
> Do you use a own library to parse the json string to object?
> Or which technology do you use for this?
>
> br
> Andreas
>
>
>
> ----- Ursprüngliche Mail -----
> Von: "Dan Haywood" <dan@haywood-associates.co.uk>
> An: "users" <users@isis.apache.org>
> Gesendet: Dienstag, 10. Februar 2015 09:14:05
> Betreff: Re: Questions for the Rest Interface for DomainService
>
> On 10 February 2015 at 07:33, Lechner Andreas <alechner@at.focusmr.com>
> wrote:
>
> > hi,
> >
> > thank you Dan, and Martin also.
> >
> > The hint with the reference of DeliGroup was useful.
> >
> >
> Glad you have it sorted.
>
>
>
> > I had to add "I_" before the ObjectID to get it working with my
> > postgresql database.
> >
> >
> That "I_" prefix is the way in which the RO viewer encodes an integer.  For
> a long it would be "L_" etc.
>
> That said, strictly speaking you should consider the URL as opaque  The
> value to provide is that of the "links[self].href" in the representation of
> the entity you want to reference.
>
> Cheers
> Dan
>
>
>
> > Here my working result:
> >
> > {
> >     "deliverableName": {"value": "NAME_ABC5"},
> >     "deliverableDescription": {"value": "DESC_ABC5"},
> >     "deliGroup": {"value": {"href": "
> > http://localhost:8080/restful/objects/DeliGroup/I_3"}}
> > }
> >
> > br
> > Andreas
> >
> > ----- Ursprüngliche Mail -----
> > Von: "Dan Haywood" <dan@haywood-associates.co.uk>
> > An: "users" <users@isis.apache.org>
> > Gesendet: Sonntag, 8. Februar 2015 12:52:07
> > Betreff: Re: Questions for the Rest Interface for DomainService
> >
> > On 5 February 2015 at 14:22, Lechner Andreas <alechner@at.focusmr.com>
> > wrote:
> >
> > > public class DeliverableService {
> > >
> > >
> > >         @NotContributed
> > >         @MemberOrder(sequence = "2")
> > >         @Named("Create New Deliverable")
> > >         public Deliverable createNew(final @Named("DeliverableName")
> > > String deliverableName,
> > >                         final @Named("DeliverableDescription") String
> > > deliverableDescription,
> > >                         final @Named("DeliGroup") DeliGroup deliGroup
> > >                 ) {
> > >
> > >          }
> > > -------------------------------------
> > >
> > >
> > > now I want to call this service over the rest interface.
> > > I think the URL should be
> > >
> > >
> >
> http://localhost:8080/restful/services/DeliverableService/actions/createNew/invoke
> > >
> > >
> > > I tried to test it over the "RESTClient" Plugin for Firefox with
> > following
> > > JSON String
> > >
> > > JSON String:
> > > {
> > >     "deliverableName": {"value": "NAME_ABC"},
> > >     "deliverableDescription": {"value": "DESC_ABC"},
> > >     "deliGroup": {
> > >         "historyId": { "value": "1"},
> > >         "deliGroupName": { "value": "Factored" }
> > >     }
> > > }
> > >
> > > After removing the "deliGroup" part in DomainService class, and in the
> > > JSON String, it was working.
> > > {
> > >     "deliverableName": {"value": "NAME_ABC"},
> > >     "deliverableDescription": {"value": "DESC_ABC"}
> > > }
> > >
> > > How has the JSON String to look?
> > >
> > >
> >
> > The Restful Objects spec [1] explains how to submit arguments that are
> > references to entity types (such as "DeliGroup"); basically you send a
> > "value.href" pointing to the object; see section 2.9.2.1
> >
> > Something like:
> >
> > {
> >     "deliverableName": {"value": "NAME_ABC"},
> >     "deliverableDescription": {"value": "DESC_ABC"},
> >     "deliGroup": { "value": { "href": "
> > http://localhost:8080/restful/objects/DeliGroup/1" } }
> > }
> >
> > As for submitting this JSON, it is described in section 2.10; basically:
> > * if the action has "safe" semantics, ie invoked via HTTP GET, then this
> > string is URL encoded and appended to the end of the URL (after the ?).
> > * if the action has "Idempotent" semantics (invoked via HTTP PUT) or
> > non-idempotent semantics (invoked via HTTP POST) then the JSON string is
> > simply the body of the request.
> >
> > HTH
> > Dan
> >
> > [1] http://restfulobjects.org/download/
> >
>

Mime
View raw message