// Sent HTTP PUT request to update customer info
System.out.println("\n");
System.out.println("Sent HTTP PUT request to update customer info");
Client client = new Client();
String inputFile = client.getClass().getResource("update_customer.xml").getFile();
URIResolver resolver = new URIResolver(inputFile);
File input = new File(resolver.getURI());
PutMethod put = new PutMethod("http://localhost:9000/customerservice/customers");
RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
put.setRequestEntity(entity);
HttpClient httpclient = new HttpClient();
try {
int result = httpclient.executeMethod(put);
System.out.println("Response status code: " + result);
System.out.println("Response body: ");
System.out.println(put.getResponseBodyAsString());
} finally {
// Release current connection to the connection pool once you are
// done
put.releaseConnection();
}
// Sent HTTP POST request to add customer
System.out.println("\n");
System.out.println("Sent HTTP POST request to add customer");
inputFile = client.getClass().getResource("add_customer.xml").getFile();
resolver = new URIResolver(inputFile);
input = new File(resolver.getURI());
PostMethod post = new PostMethod("http://localhost:9000/customerservice/customers");
post.addRequestHeader("Accept" , "text/xml");
entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
post.setRequestEntity(entity);
httpclient = new HttpClient();