cxf-commits mailing list archives

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

sergeyb pushed a commit to branch 3.1.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/3.1.x-fixes by this push:
     new b7b53c8  [CXF-7492] More updates
b7b53c8 is described below

commit b7b53c85a2423e04647f3afe096287bbceac0bf2
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     | 21 ++++++++++++++-------
 .../tools/wadlto/jaxrs/SecureConnectionHelper.java | 22 ++++++++++++++++++++++
 .../cxf/tools/wadlto/jaxrs/SourceGenerator.java    | 10 ++--------
 3 files changed, 38 insertions(+), 15 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 261630b..463fe49 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,9 +114,9 @@ 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) {
@@ -204,11 +205,17 @@ 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 eb17e7f..c1f17a1 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;
@@ -1870,12 +1868,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