cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject [cxf] branch master updated: [CXF-7492] More updates
Date Thu, 14 Sep 2017 15:11:59 GMT
This is an automated email from the ASF dual-hosted git repository.

sergeyb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new ea6e59b  [CXF-7492] More updates
     new c50fcb6  Merge branch 'master' of https://gitbox.apache.org/repos/asf/cxf
ea6e59b is described below

commit ea6e59b4026408ba195cea6fb55c2163f453e25d
Author: Sergey Beryozkin <sberyozkin@gmail.com>
AuthorDate: Thu Sep 14 16:11:26 2017 +0100

    [CXF-7492] More updates
---
 .../cxf/tools/wadlto/jaxrs/JAXRSContainer.java     | 17 ++++++++++++-----
 .../tools/wadlto/jaxrs/SecureConnectionHelper.java | 22 ++++++++++++++++++++++
 .../cxf/tools/wadlto/jaxrs/SourceGenerator.java    | 10 ++--------
 3 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
index ee6e16a..9ac7fe5 100644
--- a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
+++ b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
@@ -21,6 +21,7 @@ package org.apache.cxf.tools.wadlto.jaxrs;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.net.URL;
@@ -113,8 +114,8 @@ public class JAXRSContainer extends AbstractCXFToolContainer {
     private void processWadl() {
         File outDir = new File((String)context.get(WadlToolConstants.CFG_OUTPUTDIR));
         String wadlURL = getAbsoluteWadlURL();
-
-        String wadl = readWadl(wadlURL);
+        String authorization = (String)context.get(WadlToolConstants.CFG_AUTHORIZATION);
+        String wadl = readWadl(wadlURL, authorization);
 
         SourceGenerator sg = new SourceGenerator();
         sg.setBus(getBus());
@@ -127,7 +128,7 @@ public class JAXRSContainer extends AbstractCXFToolContainer {
         sg.setPackageName((String)context.get(WadlToolConstants.CFG_PACKAGENAME));
         sg.setResourceName((String)context.get(WadlToolConstants.CFG_RESOURCENAME));
         sg.setEncoding((String)context.get(WadlToolConstants.CFG_ENCODING));
-        sg.setAuthorization((String)context.get(WadlToolConstants.CFG_AUTHORIZATION));
+        sg.setAuthorization(authorization);
 
         String wadlNs = (String)context.get(WadlToolConstants.CFG_WADL_NAMESPACE);
         if (wadlNs != null) {
@@ -205,10 +206,16 @@ public class JAXRSContainer extends AbstractCXFToolContainer {
 
     }
 
-    protected String readWadl(String wadlURI) {
+    protected String readWadl(String wadlURI, String authorization) {
         try {
             URL url = new URL(wadlURI);
-            Reader reader = new InputStreamReader(url.openStream(), StandardCharsets.UTF_8);
+            InputStream is = null;
+            if (wadlURI.startsWith("https") && authorization != null) {
+                is = SecureConnectionHelper.getStreamFromSecureConnection(url, authorization);
+            } else {
+                is = url.openStream();
+            }
+            Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8);
             return IOUtils.toString(reader);
         } catch (IOException e) {
             throw new ToolException(e);
diff --git a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SecureConnectionHelper.java
b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SecureConnectionHelper.java
new file mode 100644
index 0000000..ecc9cc3
--- /dev/null
+++ b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SecureConnectionHelper.java
@@ -0,0 +1,22 @@
+package org.apache.cxf.tools.wadlto.jaxrs;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.apache.cxf.common.util.Base64Utility;
+
+public final class SecureConnectionHelper {
+    private SecureConnectionHelper() {
+        
+    }
+    
+    public static InputStream getStreamFromSecureConnection(URL url, String authorizationValue)
throws IOException {
+        HttpURLConnection conn = (HttpURLConnection)url.openConnection();
+        conn.setRequestMethod("GET");
+        String encodedAuth = "Basic " + Base64Utility.encode(authorizationValue.getBytes());
+        conn.setRequestProperty("Authorization", encodedAuth);
+        return conn.getInputStream();
+    }
+}
diff --git a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
index 8e769ea..0e2786a 100644
--- a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
+++ b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
@@ -28,7 +28,6 @@ import java.io.OutputStreamWriter;
 import java.io.Reader;
 import java.io.StringReader;
 import java.io.Writer;
-import java.net.HttpURLConnection;
 import java.net.URI;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
@@ -93,7 +92,6 @@ import org.apache.cxf.common.jaxb.JAXBUtils.JCodeModel;
 import org.apache.cxf.common.jaxb.JAXBUtils.S2JJAXBModel;
 import org.apache.cxf.common.jaxb.JAXBUtils.SchemaCompiler;
 import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.Base64Utility;
 import org.apache.cxf.common.util.PackageUtils;
 import org.apache.cxf.common.util.ReflectionInvokationHandler;
 import org.apache.cxf.common.util.StringUtils;
@@ -1861,12 +1859,8 @@ public class SourceGenerator {
             } 
             if (is == null) {
                 URL url = URI.create(href).toURL();
-                if (authorization != null) {
-                    HttpURLConnection conn = (HttpURLConnection)url.openConnection();
-                    conn.setRequestMethod("GET");
-                    String encodedAuth = "Basic " + Base64Utility.encode(authorization.getBytes());
-                    conn.setRequestProperty("Authorization", encodedAuth);
-                    is = conn.getInputStream();
+                if (href.startsWith("https") && authorization != null) {
+                    is = SecureConnectionHelper.getStreamFromSecureConnection(url, authorization);
                 } else {
                     is = url.openStream();
                 }

-- 
To stop receiving notification emails like this one, please contact
['"commits@cxf.apache.org" <commits@cxf.apache.org>'].

Mime
View raw message