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