A similar simplification is possible when the body of the request is a
graph.

So that instead of
   public Response addUser(@Context UriInfo uriInfo, String userData) {
        Graph inputGraph = parseGraphFromString(userData);

One can just use
   public Response addUser(@Context UriInfo uriInfo, Graph inputGraph) {

As stanbol has currently no such MessageBodyReader to support this I've
created STANBOL-988 to add a small bundle from Clerezza. With this bundle
we have however two MessageBodyWriters for TripleCollections. The one in
org.apache.stanbol.commons.web.base.writers also supports
application/octet-stream and text/plain as format for serializing them.
More important I think would be to add JSON_LD.

Cheers,
Reto


On Sun, Mar 17, 2013 at 4:33 PM, Reto Bachmann-Gmür <[email protected]> wrote:

> Hi Danny
>
> I just wanted to point a possible simplification of JAX-RS methods.
>
> For example from commit 1457449:
>
>      @GET
>      @Path("users/{username}")
> -    @Produces(SupportedFormat.TURTLE)
> -    public Response getUserTurtle(@PathParam("username") String userName)
> -          throws UnsupportedEncodingException {
> +    public TripleCollection getUserContext(@PathParam("username") String
> userName) {
> -        ByteArrayOutputStream baos = new ByteArrayOutputStream();
> -
> -        serializer.serialize(baos, getUser(userName).getNodeContext(),
> -                SupportedFormat.TURTLE);
> -        String serialized = new String(baos.toByteArray(), "utf-8");
> -        // System.out.println("User = "+serialized);
> -        return Response.ok(serialized).build();
> +        return getUser(userName).getNodeContext();
>      }
>
> 9 lines of code less and additionally the advantage that not just turtle
> but any supported RDF serialization. The trick is not to care about
> serialization but just return a triple collection and let the serialization
> be the business of the installed MessageBodyWriterS. NOte that if you want
> to enforce turtle you could just leave the @Produces annotation there. The
> same is also possible for the submitted content, I'll now look at this.
>
> Cheer,
> Reto
>

Reply via email to