JAX-RS Client [BAEL-595] (#992)

* WatchService vs. Apache Commons IO Mnitoring

* Indentation fixed

* Indentation fixed

* JAX-RS API using Jersey [BAEL-558]

* JAX-RS API using Jersey [BAEL-558]

* Modifications made to remove xml

* applicationContext.xml removed

* All try catch moved to ExceptionMapper

* fixes

* review comments incorporated

* module renamed

* JAX-RS client [BAEL-595]

* jersey-core dependency removed

* assert changed to assertEquals

* messagebody readers and writers removed

* pom dependency corrected and other minor changes
This commit is contained in:
Saptarshi Basu
2017-01-31 13:17:23 +05:30
committed by Sunil Mogadati
parent 6c2ed878c0
commit 4fe878d6d4
4 changed files with 103 additions and 14 deletions
@@ -0,0 +1,31 @@
package com.baeldung.client.rest;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.baeldung.server.model.Employee;
public class RestClient {
private static final String REST_URI = "http://localhost:8082/spring-jersey/resources/employees";
private Client client = ClientBuilder.newClient();
public Response createJsonEmployee(Employee emp) {
return client.target(REST_URI).request(MediaType.APPLICATION_JSON).post(Entity.entity(emp, MediaType.APPLICATION_JSON));
}
public Employee getJsonEmployee(int id) {
return client.target(REST_URI).path(new Integer(id).toString()).request(MediaType.APPLICATION_JSON).get(Employee.class);
}
public Response createXmlEmployee(Employee emp) {
return client.target(REST_URI).request(MediaType.APPLICATION_XML).post(Entity.entity(emp, MediaType.APPLICATION_XML));
}
public Employee getXmlEmployee(int id) {
return client.target(REST_URI).path(new Integer(id).toString()).request(MediaType.APPLICATION_XML).get(Employee.class);
}
}