Java Reference
In-Depth Information
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import customer.data.Address;
import customer.data.Customer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ws.rs.core.MediaType;
public class CustomerClientXML {
public static final Logger logger =
Log-
ger.getLogger(CustomerClientXML.class.getCanonicalName());
public static void main(String[] args) {
Client client = Client.create();
// Define the URL for testing the example application
WebResource webResource =
client.resource("http://localhost:8080/customer/rest/
Customer");
// Test the POST method
Customer customer = new Customer();
Address address = new Address();
customer.setAddress(address);
customer.setId(1);
customer.setFirstname("Duke");
customer.setLastname("OfJava");
address.setNumber(1);
address.setStreet("Duke's Drive");
address.setCity("JavaTown");
address.setZip("1234");
address.setState("JA");
address.setCountry("USA");
customer.setEmail("duke@java.net");
customer.setPhone("12341234");
ClientResponse response =
webResource.type("application/
xml").post(ClientResponse.class,
customer);
logger.info("POST status: {0}" + response.getStatus());
if (response.getStatus() == 201) {
Search WWH ::




Custom Search