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 Tue, 10 Feb 2015 11:20:00 GMT
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