Exemplo n.º 1
0
 /**
  * Creates an intent from a POST of a JSON string and attempts to apply it.
  *
  * @param stream input JSON
  * @return status of the request - CREATED if the JSON is correct, BAD_REQUEST if the JSON is
  *     invalid
  */
 @POST
 @Consumes(MediaType.APPLICATION_JSON)
 @Produces(MediaType.APPLICATION_JSON)
 public Response createIntent(InputStream stream) {
   try {
     IntentService service = get(IntentService.class);
     ObjectNode root = (ObjectNode) mapper().readTree(stream);
     Intent intent = codec(Intent.class).decode(root, this);
     service.submit(intent);
     UriBuilder locationBuilder =
         uriInfo
             .getBaseUriBuilder()
             .path("intents")
             .path(Short.toString(intent.appId().id()))
             .path(Long.toString(intent.id().fingerprint()));
     return Response.created(locationBuilder.build()).build();
   } catch (IOException ioe) {
     throw new IllegalArgumentException(ioe);
   }
 }
Exemplo n.º 2
0
 @Override
 public void submit(Intent intent) {
   intentService.submit(intent);
 }