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-6953] Updating service list formatter for REST endpoint to optionally link to WADL and/or Swagger
Date Mon, 27 Jun 2016 13:30:25 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes f188071fd -> 89e055d3a


[CXF-6953] Updating service list formatter for REST endpoint to optionally link to WADL and/or
Swagger


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

Branch: refs/heads/3.1.x-fixes
Commit: 89e055d3ad175002bce936b62d2fddf97044ca35
Parents: f188071
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Mon Jun 27 14:28:27 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Mon Jun 27 14:30:12 2016 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/provider/ProviderFactory.java     | 12 +++++++---
 .../jaxrs/provider/ServerProviderFactory.java   |  2 +-
 .../cxf/jaxrs/model/wadl/WadlGenerator.java     |  1 +
 .../jaxrs/swagger/AbstractSwaggerFeature.java   |  1 +
 .../servicelist/FormattedServiceListWriter.java | 23 +++++++++++++++++---
 .../ServiceListGeneratorServlet.java            | 13 ++---------
 .../UnformattedServiceListWriter.java           | 23 +++++++++++++++++---
 7 files changed, 54 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/89e055d3/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
index 4ee799c..fd850de 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
@@ -152,15 +152,21 @@ public abstract class ProviderFactory {
                      new MultipartProvider());
         Object prop = factory.getBus().getProperty("skip.default.json.provider.registration");
         if (!PropertyUtils.isTrue(prop)) {
-            factory.setProviders(false, false, createProvider(JSON_PROVIDER_NAME));
+            factory.setProviders(false, false, createProvider(JSON_PROVIDER_NAME, factory.getBus()));
         }
             
     }
     
-    protected static Object createProvider(String className) {
+    protected static Object createProvider(String className, Bus bus) {
         
         try {
-            return ClassLoaderUtils.loadClass(className, ProviderFactory.class).newInstance();
+            Class<?> cls = ClassLoaderUtils.loadClass(className, ProviderFactory.class);
+            for (Constructor<?> c : cls.getConstructors()) {
+                if (c.getParameterTypes().length == 1 && c.getParameterTypes()[0]
== Bus.class) {
+                    return c.newInstance(bus);
+                }
+            }
+            return cls.newInstance();
         } catch (Throwable ex) {
             String message = "Problem with creating the default provider " + className;
             if (ex.getMessage() != null) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/89e055d3/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
index 3d7d966..97311af 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
@@ -100,7 +100,7 @@ public final class ServerProviderFactory extends ProviderFactory {
     }
     
     private static ProviderInfo<ContainerRequestFilter> createWadlGenerator(Bus bus)
{
-        Object provider = createProvider(WADL_PROVIDER_NAME);
+        Object provider = createProvider(WADL_PROVIDER_NAME, bus);
         if (provider == null) {
             return null;
         } else {

http://git-wip-us.apache.org/repos/asf/cxf/blob/89e055d3/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
index 17b745f..e94a3ec 100644
--- a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
+++ b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
@@ -199,6 +199,7 @@ public class WadlGenerator implements ContainerRequestFilter {
     
     public WadlGenerator(Bus bus) {
         this.bus = bus;
+        this.bus.setProperty("wadl.service.descrition.available", "true");
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cxf/blob/89e055d3/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/AbstractSwaggerFeature.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/AbstractSwaggerFeature.java
b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/AbstractSwaggerFeature.java
index 139f838..c933b30 100644
--- a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/AbstractSwaggerFeature.java
+++ b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/AbstractSwaggerFeature.java
@@ -69,6 +69,7 @@ public abstract class AbstractSwaggerFeature extends AbstractFeature {
             addSwaggerResource(server);
 
             initializeProvider(server.getEndpoint(), bus);
+            bus.setProperty("swagger.service.descrition.available", "true");
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/89e055d3/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java
----------------------------------------------------------------------
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java
b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java
index 7903f86..ebd20f4 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java
@@ -22,6 +22,9 @@ import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.Map;
 
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.util.PropertyUtils;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.service.model.OperationInfo;
 import org.apache.cxf.transport.AbstractDestination;
 
@@ -30,15 +33,19 @@ public class FormattedServiceListWriter implements ServiceListWriter {
     private String title;
     private Map<String, String> atomMap;
     private boolean showForeignContexts;
+    private Bus bus;
     
     public FormattedServiceListWriter(String styleSheetPath, 
                                       String title,
                                       boolean showForeignContexts,
-                                      Map<String, String> atomMap) {
+                                      Bus bus) {
         this.styleSheetPath = styleSheetPath;
         this.title = title;
         this.showForeignContexts = showForeignContexts;
-        this.atomMap = atomMap;
+        this.bus = bus;
+        if (bus != null) {
+            this.atomMap = CastUtils.cast((Map<?, ?>)bus.getProperty("org.apache.cxf.extensions.logging.atom.pull"));
+        }
     }
 
     public String getContentType() {
@@ -161,8 +168,18 @@ public class FormattedServiceListWriter implements ServiceListWriter
{
         writer.write("<tr><td>");
         writer.write("<span class=\"field\">Endpoint address:</span> " + "<span
class=\"value\">"
                      + absoluteURL + "</span>");
-        writer.write("<br/><span class=\"field\">WADL :</span> " + "<a
href=\"" + absoluteURL
+        if (bus != null && PropertyUtils.isTrue(bus.getProperty("wadl.service.descrition.available")))
{
+            writer.write("<br/><span class=\"field\">WADL :</span> " +
"<a href=\"" + absoluteURL
                      + "?_wadl\">" + absoluteURL + "?_wadl" + "</a>");
+        }
+        if (bus != null && PropertyUtils.isTrue(bus.getProperty("swagger.service.descrition.available")))
{
+            String swaggerPath = "swagger.json";
+            if (!absoluteURL.endsWith("/")) {
+                swaggerPath = "/" + swaggerPath;
+            }
+            writer.write("<br/><span class=\"field\">Swagger :</span> "
+ "<a href=\"" + absoluteURL
+                     + swaggerPath + "\">" + absoluteURL + swaggerPath + "</a>");
+        }
         addAtomLinkIfNeeded(absoluteURL, atomMap, writer);
         writer.write("</td></tr>");
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/89e055d3/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListGeneratorServlet.java
----------------------------------------------------------------------
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListGeneratorServlet.java
b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListGeneratorServlet.java
index 8912fb3..93266fa 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListGeneratorServlet.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListGeneratorServlet.java
@@ -21,9 +21,7 @@ package org.apache.cxf.transport.servlet.servicelist;
 import java.io.IOException;
 import java.net.URL;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
@@ -88,17 +86,10 @@ public class ServiceListGeneratorServlet extends HttpServlet {
             return;
         }
         List<String> privateEndpoints;
-        Map<String, String> atomMap;
-        
         if (bus != null) {
             privateEndpoints = (List<String>)bus.getProperty("org.apache.cxf.private.endpoints");
-            // TODO : we may introduce a bus extension instead
-
-            atomMap = (Map<String, String>)bus
-                .getProperty("org.apache.cxf.extensions.logging.atom.pull");
         } else {
             privateEndpoints = new ArrayList<String>();
-            atomMap = new HashMap<String, String>();
         }
         
         AbstractDestination[] soapEndpoints = getSOAPEndpoints(destinations, privateEndpoints);
@@ -106,7 +97,7 @@ public class ServiceListGeneratorServlet extends HttpServlet {
         ServiceListWriter serviceListWriter;
         if ("false".equals(request.getParameter("formatted"))) {
             boolean renderWsdlList = "true".equals(request.getParameter("wsdlList"));
-            serviceListWriter = new UnformattedServiceListWriter(renderWsdlList);
+            serviceListWriter = new UnformattedServiceListWriter(renderWsdlList, bus);
         } else {
             String styleSheetPath;
             if (serviceListStyleSheet != null) {
@@ -116,7 +107,7 @@ public class ServiceListGeneratorServlet extends HttpServlet {
                 styleSheetPath = request.getRequestURI() + "/?stylesheet=1";
             }
             serviceListWriter = 
-                new FormattedServiceListWriter(styleSheetPath, title, showForeignContexts,
atomMap);
+                new FormattedServiceListWriter(styleSheetPath, title, showForeignContexts,
bus);
             
         }
         response.setContentType(serviceListWriter.getContentType());

http://git-wip-us.apache.org/repos/asf/cxf/blob/89e055d3/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/UnformattedServiceListWriter.java
----------------------------------------------------------------------
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/UnformattedServiceListWriter.java
b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/UnformattedServiceListWriter.java
index 5650c92..a36e545 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/UnformattedServiceListWriter.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/UnformattedServiceListWriter.java
@@ -21,14 +21,17 @@ package org.apache.cxf.transport.servlet.servicelist;
 import java.io.IOException;
 import java.io.PrintWriter;
 
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.util.PropertyUtils;
 import org.apache.cxf.transport.AbstractDestination;
 import org.apache.cxf.transport.servlet.ServletDestination;
 
 public class UnformattedServiceListWriter implements ServiceListWriter {
     boolean renderWsdlList;
-
-    public UnformattedServiceListWriter(boolean renderWsdlList) {
+    Bus bus;
+    public UnformattedServiceListWriter(boolean renderWsdlList, Bus bus) {
         this.renderWsdlList = renderWsdlList;
+        this.bus = bus;
     }
 
     public String getContentType() {
@@ -71,7 +74,21 @@ public class UnformattedServiceListWriter implements ServiceListWriter
{
                                                   AbstractDestination[] destinations) throws
IOException {
         for (AbstractDestination sd : destinations) {
             String address = getAbsoluteAddress(baseAddress, sd);
-            writer.write(address + "?_wadl\n");
+            boolean wadlAvailable = bus != null 
+                && PropertyUtils.isTrue(bus.getProperty("wadl.service.descrition.available"));
+            boolean swaggerAvailable = bus != null 
+                && PropertyUtils.isTrue(bus.getProperty("swagger.service.descrition.available"));
+            if (!wadlAvailable && !swaggerAvailable) {
+                writer.write(address + "\n");
+                return;
+            }
+            if (wadlAvailable) {
+                writer.write(address + "?_wadl\n");
+            }
+            if (swaggerAvailable) {
+                writer.write(address + "/swagger.json\n");
+            }
+            
         }
     }
 


Mime
View raw message