cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-7492] Adding a namePassword wadltojava option
Date Tue, 05 Sep 2017 12:19:20 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 4e311c2b8 -> 5829820c4


[CXF-7492] Adding a namePassword wadltojava option


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

Branch: refs/heads/3.1.x-fixes
Commit: 5829820c46670c7b99934ada9fdb40c0ab192295
Parents: 4e311c2
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Tue Sep 5 12:55:28 2017 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Tue Sep 5 13:19:03 2017 +0100

----------------------------------------------------------------------
 .../cxf/tools/wadlto/WadlToolConstants.java     |  3 ++-
 .../cxf/tools/wadlto/jaxrs/JAXRSContainer.java  |  1 +
 .../cxf/tools/wadlto/jaxrs/SourceGenerator.java | 20 ++++++++++++++++++--
 .../cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml   | 10 ++++++++++
 4 files changed, 31 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/5829820c/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
index 50611a4..2f9d7b1 100644
--- a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
+++ b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
@@ -47,7 +47,8 @@ public final class WadlToolConstants {
     
     public static final String CFG_CATALOG = ToolConstants.CFG_CATALOG;
     public static final String CFG_BINDING = ToolConstants.CFG_BINDING;
-    
+    public static final String CFG_NAME_PASSWORD = "namePassword";
+
     public static final String CFG_NO_TYPES = ToolConstants.CFG_NO_TYPES;
     public static final String CFG_NO_VOID_FOR_EMPTY_RESPONSES = "noVoidForEmptyResponses";
     public static final String CFG_NO_ADDRESS_BINDING = ToolConstants.CFG_NO_ADDRESS_BINDING;

http://git-wip-us.apache.org/repos/asf/cxf/blob/5829820c/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
----------------------------------------------------------------------
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 8780898..91a056e 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
@@ -127,6 +127,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.setNamePassword((String)context.get(WadlToolConstants.CFG_NAME_PASSWORD));
 
         String wadlNs = (String)context.get(WadlToolConstants.CFG_WADL_NAMESPACE);
         if (wadlNs != null) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/5829820c/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
----------------------------------------------------------------------
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 399fc23..86bc3df 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,6 +28,7 @@ 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;
@@ -92,6 +93,7 @@ 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;
@@ -225,6 +227,7 @@ public class SourceGenerator {
     private boolean validateWadl;    
     private SchemaCollection schemaCollection = new SchemaCollection();
     private String encoding;
+    private String namePassword;
     private boolean createJavaDocs;
     
     public SourceGenerator() {
@@ -1864,9 +1867,18 @@ public class SourceGenerator {
             InputStream is = null;
             if (!href.startsWith("http")) {
                 is = ResourceUtils.getResourceStream(href, bus);
-            }
+            } 
             if (is == null) {
-                is = URI.create(href).toURL().openStream();
+                URL url = URI.create(href).toURL();
+                if (namePassword != null) {
+                    HttpURLConnection conn = (HttpURLConnection)url.openConnection();
+                    conn.setRequestMethod("GET");
+                    String encodedAuth = "Basic " + Base64Utility.encode(namePassword.getBytes());
+                    conn.setRequestProperty("Authorization", encodedAuth);
+                    is = conn.getInputStream();
+                } else {
+                    is = url.openStream();
+                }
             }
             return readXmlDocument(new InputStreamReader(is, StandardCharsets.UTF_8));
         } catch (Exception ex) {
@@ -2032,6 +2044,10 @@ public class SourceGenerator {
         this.supportBeanValidation = supportBeanValidation;
     }
 
+    public void setNamePassword(String namePassword) {
+        this.namePassword = namePassword;
+    }
+
     private static class GrammarInfo {
         private Map<String, String> nsMap = new HashMap<String, String>();
         private Map<String, String> elementTypeMap = new HashMap<String, String>();

http://git-wip-us.apache.org/repos/asf/cxf/blob/5829820c/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
index 6bec5ba..784d978 100644
--- a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
+++ b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
@@ -259,6 +259,16 @@ Examples:
                 <annotation>Convert WADL doc elements to JavaDocs</annotation>
                 <switch>javaDocs</switch>
             </option>
+            <option id="namePassword" maxOccurs="1">
+                <annotation>
+                    Specifies a colon separated user name and password for retrieving the
+                    remote WADL content from the servers requiring Basic authentication 
                    
+                </annotation>
+                <associatedArgument placement="afterSpace">
+                    <annotation>namePassword</annotation>
+                </associatedArgument>
+                <switch>namePassword</switch>
+            </option>
         </optionGroup>
         <optionGroup id="common_options">
             <option id="help" maxOccurs="1">


Mime
View raw message