Created
September 21, 2018 18:19
-
-
Save eldermoraes/4e028e3f1bee5dbb1eb36f7469f1779f to your computer and use it in GitHub Desktop.
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
@Path("rankGateway") | |
@Stateless | |
@Consumes(MediaType.APPLICATION_JSON) | |
@Produces(MediaType.APPLICATION_JSON) | |
public class RankGateway { | |
private final String hostURI = "http://localhost:8080/"; | |
private Client client; | |
private WebTarget target; | |
@PostConstruct | |
public void init() { | |
client = ClientBuilder.newClient(); | |
target = client.target(hostURI + "microservice-rank/"); | |
} | |
@GET | |
@Path("findById") | |
public Response findById(@PathParam("id") Long id) { | |
WebTarget service = target.path("resources/playerRankHistoryService/findById/" + id); | |
Response response; | |
try { | |
response = service.request().get(); | |
} catch (ProcessingException e) { | |
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e).build(); | |
} | |
return Response.ok(response).build(); | |
} | |
@GET | |
@Path("findAll") | |
public Response findAll() { | |
WebTarget service = target.path("resources/playerRankHistoryService/findAll/"); | |
Response response; | |
try { | |
response = service.request().get(); | |
} catch (ProcessingException e) { | |
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e).build(); | |
} | |
return Response.fromResponse(response).build(); | |
} | |
@POST | |
public Response save(PlayerRankHistory rank) { | |
WebTarget service = target.path("resources/playerRankHistoryService"); | |
Response response; | |
try { | |
response = service.request().post(Entity.json(rank)); | |
} catch (ProcessingException e) { | |
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e).build(); | |
} | |
return Response.fromResponse(response).build(); | |
} | |
@DELETE | |
@Path("{id}") | |
public Response remove(Long id) { | |
WebTarget service = target.path("resources/playerRankHistoryService/" + id); | |
Response response; | |
try { | |
response = service.request().delete(); | |
} catch (ProcessingException e) { | |
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e).build(); | |
} | |
return Response.fromResponse(response).build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment