JAX-RS 2.0 Support for HalBuilder

293 views
Skip to first unread message

Mark Derricutt

unread,
Jun 28, 2013, 5:38:18 AM6/28/13
to hal-d...@googlegroups.com, halbuil...@googlegroups.com, REST Discuss
'lo all,

Just added a super simple JAX-RS 2.0 support module for my HalBuilder
JVM API which I intend to release sometime over the weekend:

https://github.com/HalBuilder/halbuilder-jaxrs

along with a small sample application at:


https://github.com/HalBuilder/halbuilder-examples/tree/develop/halbuilder-jersey-example

Basically, when configuring Jersey ( I've not looked at RestEasy yet )
you simple tell it to also scan the
"com.theoryinpractise.halbuilder.jaxrs" package to pick up the support
classes, then in your resource class just return your representation object:

@GET
@Produces({RepresentationFactory.HAL_JSON,
RepresentationFactory.HAL_XML})
public Representation getIt() {
Representation rep = representationFactory.newRepresentation();
rep.withProperty("message", "Got it!");
return rep;
}

and voila - content neg. is all handled by JAX-RS out of the box:

$ curl -H "Accept: application/hal+xml"
http://localhost:8080/myapp/myresource
<resource>
<link rel="website" href="http://gotohal.net" />
<message>Got it!</message>
</resource>

$ curl http://localhost:8080/myapp/myresource
{
"_links" : {
"website" : {
"href" : "http://gotohal.net"
}
},
"message" : "Got it!"
}

So far I've added the @Produces side of things, tho @Consumes should be
just as simple and should be added before the release.

Note that the support ONLY works for returning
Representation/ReadableRepresentation and not arbitrary objects - this
is me trying to make you think of links/representations etc. as
first-class things.

Mark

Abiel Woldu

unread,
Jul 9, 2013, 2:16:12 AM7/9/13
to halbuil...@googlegroups.com, hal-d...@googlegroups.com, REST Discuss

Michael McCarthy

unread,
Sep 6, 2013, 4:25:31 AM9/6/13
to hal-d...@googlegroups.com, halbuil...@googlegroups.com, REST Discuss
Hi Mark,

Interesting stuff, just looking into using this now. How this work with regards to status codes etc? We're returning JAX-RS Response objects from our Resource classes so we can specify the status code, is your suggestion that you would return a Representation instead of a Resource, or would you build a Response with a Representation inside it and have this still work?

Thanks

Ted M. Young

unread,
Jan 28, 2014, 5:34:42 PM1/28/14
to halbuil...@googlegroups.com
Hi,

Has anyone configured HalBuilder to work with JAX-RS 1.1 as a Provider? I'm using Dropwizard 0.6.2, which uses Jersey 1.17, so can't (yet) use this jax-rs module.

It looks like I can use the JaxRsHalBuilderSupport class as-is, but before I spend time playing around with it to see if it works, I figured I'd see if anyone else has done this.

Thanks,
;ted



On Friday, June 28, 2013 2:38:18 AM UTC-7, Mark Derricutt wrote:

Mark Derricutt

unread,
Jan 29, 2014, 6:11:33 PM1/29/14
to halbuil...@googlegroups.com

Sadly not that I'm aware of,

I never actually got around to actually doing a maven release of that simple JAX-RS module, but it if you work out what needs to change, I'll gladly take a PR and release.

Mark

Reply all
Reply to author
Forward
0 new messages