java - How best to implement link relations for HATEOAS in XML? -



java - How best to implement link relations for HATEOAS in XML? -

we have java server web application core of scheme contains complex domain model designed according principles of domain driven design. part, these domain objects have been affectly little applications other concerns.

we looking set rest web services api in front end of scheme , struggling how best implement hateoas links come within our own new media type. example, lets have domain class foo has id , name properties jax-b annotations:

@xmltype(name = "foo") public class fooimpl implements foo { private string name; private string id; ...snip.... @xmlid @xmlattribute @override public string getid() { homecoming id; } @xmlelement @override public string getname() { homecoming name; } @override public void setname(final string name) { this.name = name; } }

but xml want homecoming looks this:

<foo id="123" href="http://myserver.com/foos/123"> <name>myfoo</name> <links> <link rel="previous" href="http://myserver.com/foos/122" type="application/mything+xml" /> <link rel="next" href="http://myserver.com/foos/124" type="application/mything+xml" /> <link rel="edit" href="http://myserver.com/foos/123" type="application/mything+xml" /> <link rel="revise" href="http://myserver.com/foos/123" method="put" type="application/mything+xml" /> <link rel="cancel" href="http://myserver.com/foos/123?op="cancel"" method="post" type="application/mything+xml" /> </links> </foo>

what best way such not have pollute domain design these media type links, can still utilize powerfulness of jax-b xml marshalling? here thoughts:

1) jax-b adapters - utilize these modify xml entities , insert links..is possible? reasonable? examples?

2) dto layer - create new rest service layer converts domain objects in dtos. far been able avoid hassle of dtos. while provide total flexibility in homecoming client, not looking create domain agnostic clients here.

3) link headers - idea, don't think work (by itself) because our resources contain collections of sub-resources. in case subresources still have marshalled xml contains links/hrefs, etc. while link headers solves problem top level type, doesn't solve entire problem. sense free otherwise!

is there approach help me avoid dtos , yet remain transparent domain model?

the problem correctly generating links requires knowing context within beingness generated, in turn means simple jaxb interceptors won't job: won't know url insert. what's more, generating next , previous links require knowing values are; it's not safe consecutive, imply resource changing url when other resource deleted, madness.

the safest, easiest method going wrapper class (with jaxb serialization annotations on it) delegates dao layer info needs. while can fair amount of code write, it's @ to the lowest degree easy such code right. fancy automated decoration much harder.

java web-services rest jaxb domain-driven-design

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -