Hi,
I'm wrestling with a service which is going to be called by a
hand-written javascript client (written by others). The client wants to
send something like this:
{
"urls": [ { "id": "test-1", "url": "http://example.com/abc" }, { "id":
"test-2", "url": "http://example.com/def" } ]
}
and get back
{
"urls": [ { "id": "test-1", "url": "http://example.com/ybpnyubftnnfwqs" },
{ "id": "test-2", "url": "http://example.com/63dgjrevlhnsufqw" } ]
}
The second part was simple. I created
@ViewModel
public class IdentifiedUrl {
protected String id;
protected String url;
...
and
@ViewModel
public class UrlList {
protected Set<IdentifiedUrl> urls;
...
Then, in my domain service, I can create an action:
public UrlList encodeUrls(@Parameter @ParameterLayout(named = "urls") String
urls)
HashSet<IdentifiedUrl> responseUrls= new HashSet<IdentifiedUrl>();
responseUrls.add(new IdentifiedUrl("test-1",
"http://example.com/102398432313410948710798713028941209374"));
responseUrls.add(new IdentifiedUrl("test-2",
"http://example.com/123452309028954723049875023152310239843"));
return new UrlList(responseUrls);
}
and when called with the header Accept:
application/json;profile="urn:org.apache.isis/v1",
returns
{
"urls" : [ {
"$$href" :
"http://localhost:12080/restful/objects/com.example.mas.dom.services.IdentifiedUrl/PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPG1lbWVudG8vPg==",
"$$title" : "Untitled Identified Url",
"$$instanceId" :
"PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPG1lbWVudG8vPg==",
"id" : "test-2",
"url" : "http://example.com/123452309028954723049875023152310239843"
}, {
"$$href" :
"http://localhost:12080/restful/objects/com.example.mas.dom.services.IdentifiedUrl/PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPG1lbWVudG8vPg==",
"$$title" : "Untitled Identified Url",
"$$instanceId" :
"PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPG1lbWVudG8vPg==",
"id" : "test-1",
"url" : "http://example.com/102398432313410948710798713028941209374"
} ]
}
But regarding the action argument, I don't get anywhere. Can someone
please propose which direction to take? It would be helpful if the JSON
which needs to be posted could be in a 'simple' representation.
Thanks a lot
Kambiz