use of httpsdemo.common.CustomerService 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);
}
Aggregations