use of httpsdemo.common.Customer in project cxf by apache.
the class Client method main.
public static void main(String[] args) throws Exception {
String keyStoreLoc = "src/main/config/clientKeystore.jks";
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(new FileInputStream(keyStoreLoc), "cspass".toCharArray());
SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(keyStore, null).loadKeyMaterial(keyStore, "ckpass".toCharArray()).build();
/*
* Send HTTP GET request to query customer info using portable HttpClient
* object from Apache HttpComponents
*/
SSLConnectionSocketFactory sf = new SSLConnectionSocketFactory(sslcontext);
System.out.println("Sending HTTPS GET request to query customer info");
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sf).build();
HttpGet httpget = new HttpGet(BASE_SERVICE_URL + "/123");
BasicHeader bh = new BasicHeader("Accept", "text/xml");
httpget.addHeader(bh);
CloseableHttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
entity.writeTo(System.out);
response.close();
httpclient.close();
/*
* Send HTTP PUT request to update customer info, using CXF WebClient method
* Note: if need to use basic authentication, use the WebClient.create(baseAddress,
* username,password,configFile) variant, where configFile can be null if you're
* not using certificates.
*/
System.out.println("\n\nSending HTTPS PUT to update customer name");
WebClient wc = WebClient.create(BASE_SERVICE_URL, CLIENT_CONFIG_FILE);
Customer customer = new Customer();
customer.setId(123);
customer.setName("Mary");
Response resp = wc.put(customer);
/*
* Send HTTP POST request to add customer, using JAXRSClientProxy
* Note: if need to use basic authentication, use the JAXRSClientFactory.create(baseAddress,
* username,password,configFile) variant, where configFile can be null if you're
* not using certificates.
*/
System.out.println("\n\nSending HTTPS POST request to add customer");
CustomerService proxy = JAXRSClientFactory.create(BASE_SERVICE_URL, CustomerService.class, CLIENT_CONFIG_FILE);
customer = new Customer();
customer.setName("Jack");
resp = wc.post(customer);
System.out.println("\n");
System.exit(0);
}
use of httpsdemo.common.Customer in project cxf by apache.
the class CustomerServiceImpl method init.
final void init() {
Customer c = new Customer();
c.setName("John");
c.setId(123);
customers.put(c.getId(), c);
}
use of httpsdemo.common.Customer in project cxf by apache.
the class CustomerServiceImpl method deleteCustomer.
public Response deleteCustomer(String id) {
System.out.println("----invoking deleteCustomer, Customer id is: " + id);
long idNumber = Long.parseLong(id);
Customer c = customers.get(idNumber);
Response r;
if (c != null) {
r = Response.ok().build();
customers.remove(idNumber);
} else {
r = Response.notModified().build();
}
return r;
}
use of httpsdemo.common.Customer in project cxf by apache.
the class CustomerServiceImpl method updateCustomer.
public Response updateCustomer(Customer customer) {
System.out.println("----invoking updateCustomer, Customer name is: " + customer.getName());
Customer c = customers.get(customer.getId());
Response r;
if (c != null) {
customers.put(customer.getId(), customer);
r = Response.ok().build();
} else {
r = Response.notModified().build();
}
return r;
}
use of httpsdemo.common.Customer in project cxf by apache.
the class CustomerServiceImpl method getCustomer.
public Customer getCustomer(String id) {
System.out.println("----invoking getCustomer, Customer id is: " + id);
long idNumber = Long.parseLong(id);
Customer c = customers.get(idNumber);
return c;
}
Aggregations