Created
September 21, 2018 17:59
-
-
Save eldermoraes/f08386a09bb560067ed3a3b3f831f0e5 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("playerGateway") | |
@Stateless | |
@Consumes(MediaType.APPLICATION_JSON) | |
@Produces(MediaType.APPLICATION_JSON) | |
public class PlayerGateway { | |
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-player/"); | |
} | |
@GET | |
@Path("findById") | |
public Response findById(@PathParam("id") Long id) { | |
WebTarget service = target.path("resources/playerService/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.fromResponse(response).build(); | |
} | |
@GET | |
@Path("findAll") | |
public Response findAll() { | |
WebTarget service = target.path("resources/playerService/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(Player player) { | |
WebTarget service = target.path("resources/playerService"); | |
Response response; | |
try { | |
response = service.request().post(Entity.json(player)); | |
} 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/playerService/" + 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