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:20:17 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes bd63ff19e -> 1ed21f665


[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/1ed21f66
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/1ed21f66
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/1ed21f66

Branch: refs/heads/3.0.x-fixes
Commit: 1ed21f665a36aa8ecfcfb97f6a3cfa48c078a7d0
Parents: bd63ff1
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:20:02 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/1ed21f66/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/1ed21f66/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 166adbf..2165c20 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
@@ -126,6 +126,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/1ed21f66/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 2cf5aab..43d40de 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
@@ -29,6 +29,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.util.ArrayList;
@@ -91,6 +92,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;
@@ -224,6 +226,7 @@ public class SourceGenerator {
     private boolean validateWadl;    
     private SchemaCollection schemaCollection = new SchemaCollection();
     private String encoding;
+    private String namePassword;
     private boolean createJavaDocs;
     
     public SourceGenerator() {
@@ -1868,9 +1871,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, "UTF-8"));
         } catch (Exception ex) {
@@ -2036,6 +2048,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/1ed21f66/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