@POST @Consumes("application/json") public Response post(StaticAnnouncement announcement, @Context UriInfo uriInfo) { if (!nodeInfo.getEnvironment().equals(announcement.getEnvironment())) { return Response.status(BAD_REQUEST) .entity( format( "Environment mismatch. Expected: %s, Provided: %s", nodeInfo.getEnvironment(), announcement.getEnvironment())) .build(); } Id<Service> id = Id.random(); String location = Objects.firstNonNull(announcement.getLocation(), "/somewhere/" + id); Service service = Service.copyOf(announcement).setId(id).setLocation(location).build(); store.put(service); URI uri = UriBuilder.fromUri(uriInfo.getBaseUri()) .path(StaticAnnouncementResource.class) .path("{id}") .build(id); return Response.created(uri).entity(service).build(); }
@GET @Produces("application/json") public Services get() { return new Services(nodeInfo.getEnvironment(), store.getAll()); }