Search in sources :

Example 1 with Customer

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);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) CustomerService(httpsdemo.common.CustomerService) HttpEntity(org.apache.http.HttpEntity) Customer(httpsdemo.common.Customer) HttpGet(org.apache.http.client.methods.HttpGet) SSLContext(javax.net.ssl.SSLContext) KeyStore(java.security.KeyStore) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) WebClient(org.apache.cxf.jaxrs.client.WebClient) FileInputStream(java.io.FileInputStream) Response(javax.ws.rs.core.Response) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) BasicHeader(org.apache.http.message.BasicHeader)

Example 2 with Customer

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);
}
Also used : Customer(httpsdemo.common.Customer)

Example 3 with Customer

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;
}
Also used : Response(javax.ws.rs.core.Response) Customer(httpsdemo.common.Customer)

Example 4 with Customer

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;
}
Also used : Response(javax.ws.rs.core.Response) Customer(httpsdemo.common.Customer)

Example 5 with Customer

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;
}
Also used : Customer(httpsdemo.common.Customer)

Aggregations

Customer (httpsdemo.common.Customer)5 Response (javax.ws.rs.core.Response)3 CustomerService (httpsdemo.common.CustomerService)1 FileInputStream (java.io.FileInputStream)1 KeyStore (java.security.KeyStore)1 SSLContext (javax.net.ssl.SSLContext)1 WebClient (org.apache.cxf.jaxrs.client.WebClient)1 HttpEntity (org.apache.http.HttpEntity)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 BasicHeader (org.apache.http.message.BasicHeader)1