You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2017/06/26 18:10:02 UTC

[3/4] cxf git commit: updated https sample to use latest httpclient version

updated https sample to use latest httpclient version

# Conflicts:
#	distribution/src/main/release/samples/jax_rs/basic_https/src/main/java/httpsdemo/client/Client.java


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/a7ab146e
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/a7ab146e
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/a7ab146e

Branch: refs/heads/3.1.x-fixes
Commit: a7ab146e9df58cff4d40de52c0ce9ba38b293290
Parents: 6819cc5
Author: Dennis Kieselhorst <de...@apache.org>
Authored: Sun Jun 25 15:15:12 2017 +0200
Committer: Daniel Kulp <dk...@apache.org>
Committed: Mon Jun 26 13:20:35 2017 -0400

----------------------------------------------------------------------
 .../release/samples/jax_rs/basic_https/pom.xml  |  2 +-
 .../src/main/java/httpsdemo/client/Client.java  | 30 ++++++++++++--------
 2 files changed, 19 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/a7ab146e/distribution/src/main/release/samples/jax_rs/basic_https/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/basic_https/pom.xml b/distribution/src/main/release/samples/jax_rs/basic_https/pom.xml
index 756720a..723a6d8 100644
--- a/distribution/src/main/release/samples/jax_rs/basic_https/pom.xml
+++ b/distribution/src/main/release/samples/jax_rs/basic_https/pom.xml
@@ -29,7 +29,7 @@
         <relativePath>../..</relativePath>
     </parent>
     <properties>
-        <httpclient.version>4.2.1</httpclient.version>
+        <httpclient.version>4.5.3</httpclient.version>
     </properties>
     <profiles>
         <profile>

http://git-wip-us.apache.org/repos/asf/cxf/blob/a7ab146e/distribution/src/main/release/samples/jax_rs/basic_https/src/main/java/httpsdemo/client/Client.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/basic_https/src/main/java/httpsdemo/client/Client.java b/distribution/src/main/release/samples/jax_rs/basic_https/src/main/java/httpsdemo/client/Client.java
index 7147e2d..4f5751d 100644
--- a/distribution/src/main/release/samples/jax_rs/basic_https/src/main/java/httpsdemo/client/Client.java
+++ b/distribution/src/main/release/samples/jax_rs/basic_https/src/main/java/httpsdemo/client/Client.java
@@ -22,16 +22,19 @@ package httpsdemo.client;
 import java.io.FileInputStream;
 import java.security.KeyStore;
 
+import javax.net.ssl.SSLContext;
 import javax.ws.rs.core.Response;
+
 import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
 import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpGet;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.ssl.SSLSocketFactory;
-import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
 import org.apache.http.message.BasicHeader;
+import org.apache.http.ssl.SSLContexts;
 import httpsdemo.common.Customer;
 import httpsdemo.common.CustomerService;
 
@@ -50,24 +53,27 @@ public final class Client {
         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
          */
-        SSLSocketFactory sf = new SSLSocketFactory(keyStore, "ckpass", keyStore); 
-        Scheme httpsScheme = new Scheme("https", 9000, sf);
+        SSLConnectionSocketFactory sf = new SSLConnectionSocketFactory(sslcontext);
 
         System.out.println("Sending HTTPS GET request to query customer info");
-        DefaultHttpClient httpclient = new DefaultHttpClient();
-        httpclient.getConnectionManager().getSchemeRegistry().register(httpsScheme);
+        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);
-        HttpResponse response = httpclient.execute(httpget);
+        CloseableHttpResponse response = httpclient.execute(httpget);
         HttpEntity entity = response.getEntity();
         entity.writeTo(System.out);
-        httpclient.getConnectionManager().shutdown();
-        
+        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,