Java Reference
In-Depth Information
3. Modify the CustomerClientXML and CustomerClientJSON classes as
follows:
a. Replace the customer.data.* imports with customer.xml.* im-
ports and import the JAXBElement and ObjectFactory classes:
import customer.xml.Address;
import customer.xml.Customer;
import customer.xml.ObjectFactory;
import javax.xml.bind.JAXBElement;
b. Create an ObjectFactory instance and a JAXBElement<Customer>
instance at the beginning of the main method:
Click here to view code image
public static void main(String[] args) {
Client client = Client.create();
ObjectFactory factory = new ObjectFactory();
WebResource webResource = ...;
...
customer.setPhone("12341234");
JAXBElement<Customer> customerJAXB = fact-
ory.createCustomer(customer);
ClientResponse response = webResource.type("application/
xml")
.post(ClientResponse.class, customerJAXB);
...
}
c. Modify the GET request after testing the DELETE method:
Click here to view code image
response = webRe-
source.path("1").accept(MediaType.APPLICATION_XML)
.get(ClientResponse.class);
entity = response.getEntity(Customer.class);
logger.log(Level.INFO, "GET status: {0}", re-
sponse.getStatus());
try {
logger.info(entity.getAddress().getCity());
} catch (NullPointerException ne) {
// null after deleting the only customer
logger.log(Level.INFO, "After DELETE, city is: {0}",
ne.getCause());
}
Search WWH ::




Custom Search