Java Reference
In-Depth Information
public void create_XML(Object requestEntity) throws
ClientErrorException {
webTarget.request(javax.ws.rs.core.MediaType.APPLICATION_XML).
post(javax.ws.rs.client.Entity.entity(requestEntity,
javax.ws.rs.core.MediaType.APPLICATION_XML));
}
public void create_JSON(Object requestEntity) throws
ClientErrorException {
webTarget.request(javax.ws.rs.core.MediaType.APPLICATION_JSON).
post(javax.ws.rs.client.Entity.entity(requestEntity,
javax.ws.rs.core.MediaType.APPLICATION_JSON));
}
public <T> T findAll_XML(Class<T> responseType) throws
ClientErrorException {
WebTarget resource = webTarget;
return
resource.request(javax.ws.rs.core.MediaType.APPLICATION_
XML).
get(responseType);
}
public <T> T findAll_JSON(Class<T> responseType) throws
ClientErrorException {
WebTarget resource = webTarget;
return resource.request(
javax.ws.rs.core.MediaType.APPLICATION_JSON).
get(responseType);
}
public void remove(String id) throws ClientErrorException {
webTarget.path(java.text.MessageFormat.format("{0}",
new Object[]{id})).request().delete();
}
public void close() {
client.close();
}
}
The generated Java client code uses the JAX-RS client API introduced in JAX-RS 2.0.
As we can see, NetBeans generates wrapper methods for each of the methods in our
RESTful web service. NetBeans generates two versions of each method: one that
produces and/or consumes XML and another one that produces and/or consumes
JSON. Each method uses generics so that we can set the return type of these methods
at run time.
 
Search WWH ::




Custom Search