-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from btison/async-jaxrs
Using JaxRS 2.1 async request processing instead of vert.x for REST layer
- Loading branch information
Showing
7 changed files
with
127 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/com/redhat/cajun/navy/incident/rest/ApplicationHealthCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.redhat.cajun.navy.incident.rest; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import org.eclipse.microprofile.health.Health; | ||
import org.eclipse.microprofile.health.HealthCheck; | ||
import org.eclipse.microprofile.health.HealthCheckResponse; | ||
|
||
@Health | ||
@ApplicationScoped | ||
public class ApplicationHealthCheck implements HealthCheck { | ||
|
||
|
||
@Override | ||
public HealthCheckResponse call() { | ||
return HealthCheckResponse.named("Health check").up().build(); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
src/main/java/com/redhat/cajun/navy/incident/rest/IncidentsResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.redhat.cajun.navy.incident.rest; | ||
|
||
import java.util.concurrent.CompletionStage; | ||
import javax.inject.Inject; | ||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
import io.vertx.axle.core.eventbus.EventBus; | ||
import io.vertx.core.eventbus.DeliveryOptions; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
@Path("/incidents") | ||
public class IncidentsResource { | ||
|
||
@Inject | ||
EventBus bus; | ||
|
||
@GET | ||
@Path("/") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public CompletionStage<Response> incidents() { | ||
DeliveryOptions options = new DeliveryOptions().addHeader("action", "incidents"); | ||
return bus.<JsonObject>send("incident-service", new JsonObject(), options) | ||
.thenApply(msg -> Response.ok(msg.body().getJsonArray("incidents").encode()).build()); | ||
} | ||
|
||
@POST | ||
@Path("/") | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
public CompletionStage<Response> createIncident(String incident) { | ||
DeliveryOptions options = new DeliveryOptions().addHeader("action", "createIncident"); | ||
return bus.<JsonObject>send("incident-service", new JsonObject(incident), options) | ||
.thenApply(msg -> Response.status(200).build()); | ||
} | ||
|
||
@GET | ||
@Path("/{status}") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public CompletionStage<Response> incidentsByStatus(@PathParam("status") String status) { | ||
DeliveryOptions options = new DeliveryOptions().addHeader("action", "incidentsByStatus"); | ||
return bus.<JsonObject>send("incident-service", new JsonObject().put("status", status), options) | ||
.thenApply(msg -> Response.ok(msg.body().getJsonArray("incidents").encode()).build()); | ||
} | ||
|
||
@GET | ||
@Path("/incident/{id}") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public CompletionStage<Response> incidentById(@PathParam("id") String incidentId) { | ||
DeliveryOptions options = new DeliveryOptions().addHeader("action", "incidentById"); | ||
return bus.<JsonObject>send("incident-service", new JsonObject().put("incidentId", incidentId), options) | ||
.thenApply(msg -> { | ||
JsonObject incident = msg.body().getJsonObject("incident"); | ||
if (incident == null) { | ||
return Response.status(404).build(); | ||
} else { | ||
return Response.ok(incident.encode()).build(); | ||
} | ||
}); | ||
} | ||
|
||
@GET | ||
@Path("/byname/{name}") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public CompletionStage<Response> incidentsByName(@PathParam("name") String name) { | ||
DeliveryOptions options = new DeliveryOptions().addHeader("action", "incidentsByName"); | ||
return bus.<JsonObject>send("incident-service", new JsonObject().put("name", name), options) | ||
.thenApply(msg -> Response.ok(msg.body().getJsonArray("incidents").encode()).build()); | ||
} | ||
|
||
@POST | ||
@Path("/reset") | ||
public CompletionStage<Response> reset() { | ||
DeliveryOptions options = new DeliveryOptions().addHeader("action", "reset"); | ||
return bus.<JsonObject>send("incident-service", new JsonObject(), options) | ||
.thenApply(msg -> Response.ok().build()); | ||
} | ||
|
||
} |
112 changes: 0 additions & 112 deletions
112
src/main/java/com/redhat/cajun/navy/incident/rest/RestApi.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.