cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject cxf-dosgi git commit: Add swagger config to rest example
Date Tue, 11 Apr 2017 15:29:22 GMT
Repository: cxf-dosgi
Updated Branches:
  refs/heads/master 1fbc19490 -> 89d9b3955


Add swagger config to rest example


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

Branch: refs/heads/master
Commit: 89d9b395551dbc1b6107046751a5f11b699984fd
Parents: 1fbc194
Author: Christian Schneider <chris@die-schneider.net>
Authored: Tue Apr 11 17:29:15 2017 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Tue Apr 11 17:29:15 2017 +0200

----------------------------------------------------------------------
 samples/rest/README.md                          |  2 +-
 samples/rest/api/pom.xml                        |  6 +++++
 .../cxf/dosgi/samples/rest/TaskResource.java    |  3 +++
 samples/rest/impl-jackson/bnd.bnd               |  3 +++
 samples/rest/impl-jackson/pom.xml               |  6 +++++
 .../dosgi/samples/rest/impl/JacksonIntent.java  |  9 +++----
 .../samples/rest/impl/TaskResourceImpl.java     | 25 ++++++++++++++++----
 7 files changed, 45 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/89d9b395/samples/rest/README.md
----------------------------------------------------------------------
diff --git a/samples/rest/README.md b/samples/rest/README.md
index 57e4ff7..eda3e1d 100644
--- a/samples/rest/README.md
+++ b/samples/rest/README.md
@@ -16,7 +16,7 @@ Unpack karaf 4 into a server and client directory.
 Start the server karaf
 
 ```
-feature:repo-add cxf-dosgi-samples 2.0.0
+feature:repo-add cxf-dosgi-samples 2.2.0-SNAPSHOT
 feature:install cxf-dosgi-sample-rest-impl
 rsa:endpoints
 ```

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/89d9b395/samples/rest/api/pom.xml
----------------------------------------------------------------------
diff --git a/samples/rest/api/pom.xml b/samples/rest/api/pom.xml
index 3be339c..355a19a 100644
--- a/samples/rest/api/pom.xml
+++ b/samples/rest/api/pom.xml
@@ -40,6 +40,12 @@
             <artifactId>org.apache.servicemix.specs.jsr339-api-2.0.1</artifactId>
             <version>2.6.0</version>
         </dependency>
+        <dependency>
+            <groupId>io.swagger</groupId>
+            <artifactId>swagger-annotations</artifactId>
+            <version>1.5.13</version>
+            <optional>true</optional>
+        </dependency>
     </dependencies>
 
 </project>

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/89d9b395/samples/rest/api/src/main/java/org/apache/cxf/dosgi/samples/rest/TaskResource.java
----------------------------------------------------------------------
diff --git a/samples/rest/api/src/main/java/org/apache/cxf/dosgi/samples/rest/TaskResource.java
b/samples/rest/api/src/main/java/org/apache/cxf/dosgi/samples/rest/TaskResource.java
index e4a6798..2ccedb6 100644
--- a/samples/rest/api/src/main/java/org/apache/cxf/dosgi/samples/rest/TaskResource.java
+++ b/samples/rest/api/src/main/java/org/apache/cxf/dosgi/samples/rest/TaskResource.java
@@ -25,6 +25,9 @@ import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 
+import io.swagger.annotations.Api;
+
+@Api
 @Path("")
 @Produces("application/xml")
 public interface TaskResource {

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/89d9b395/samples/rest/impl-jackson/bnd.bnd
----------------------------------------------------------------------
diff --git a/samples/rest/impl-jackson/bnd.bnd b/samples/rest/impl-jackson/bnd.bnd
new file mode 100644
index 0000000..3a89c4b
--- /dev/null
+++ b/samples/rest/impl-jackson/bnd.bnd
@@ -0,0 +1,3 @@
+Import-Package: \
+	io.swagger.jaxrs,\
+	*
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/89d9b395/samples/rest/impl-jackson/pom.xml
----------------------------------------------------------------------
diff --git a/samples/rest/impl-jackson/pom.xml b/samples/rest/impl-jackson/pom.xml
index d8840f4..1ed144f 100644
--- a/samples/rest/impl-jackson/pom.xml
+++ b/samples/rest/impl-jackson/pom.xml
@@ -39,6 +39,12 @@
             <version>${project.version}</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-rs-service-description-swagger</artifactId>
+            <version>3.1.9</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
         	<groupId>org.apache.aries.rsa</groupId>
         	<artifactId>org.apache.aries.rsa.spi</artifactId>
         	<version>1.9.0</version>

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/89d9b395/samples/rest/impl-jackson/src/main/java/org/apache/cxf/dosgi/samples/rest/impl/JacksonIntent.java
----------------------------------------------------------------------
diff --git a/samples/rest/impl-jackson/src/main/java/org/apache/cxf/dosgi/samples/rest/impl/JacksonIntent.java
b/samples/rest/impl-jackson/src/main/java/org/apache/cxf/dosgi/samples/rest/impl/JacksonIntent.java
index dca20b2..980fcbe 100644
--- a/samples/rest/impl-jackson/src/main/java/org/apache/cxf/dosgi/samples/rest/impl/JacksonIntent.java
+++ b/samples/rest/impl-jackson/src/main/java/org/apache/cxf/dosgi/samples/rest/impl/JacksonIntent.java
@@ -20,23 +20,24 @@ package org.apache.cxf.dosgi.samples.rest.impl;
 
 import java.util.Arrays;
 import java.util.List;
-import java.util.concurrent.Callable;
 
 import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
+import org.apache.cxf.dosgi.common.api.IntentsProvider;
 import org.osgi.service.component.annotations.Component;
 
 
 /**
- * Only needed if jackson is used thorugh an external intent
+ * Not needed in the current example config.
+ * This shows how to export a custom intent.
  */
 @Component //
 (//
     property = "org.apache.cxf.dosgi.IntentName=jackson" //
 )
-public class JacksonIntent implements Callable<List<Object>> {
+public class JacksonIntent implements IntentsProvider {
 
     @Override
-    public List<Object> call() throws Exception {
+    public List<?> getIntents() {
         return Arrays.asList((Object)new JacksonJaxbJsonProvider());
     }
     

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/89d9b395/samples/rest/impl-jackson/src/main/java/org/apache/cxf/dosgi/samples/rest/impl/TaskResourceImpl.java
----------------------------------------------------------------------
diff --git a/samples/rest/impl-jackson/src/main/java/org/apache/cxf/dosgi/samples/rest/impl/TaskResourceImpl.java
b/samples/rest/impl-jackson/src/main/java/org/apache/cxf/dosgi/samples/rest/impl/TaskResourceImpl.java
index ab96eb2..f1855de 100644
--- a/samples/rest/impl-jackson/src/main/java/org/apache/cxf/dosgi/samples/rest/impl/TaskResourceImpl.java
+++ b/samples/rest/impl-jackson/src/main/java/org/apache/cxf/dosgi/samples/rest/impl/TaskResourceImpl.java
@@ -18,15 +18,20 @@
  */
 package org.apache.cxf.dosgi.samples.rest.impl;
 
-import java.util.Arrays;
+import static java.util.Arrays.asList;
+
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
+import io.swagger.annotations.Api;
 import org.apache.cxf.dosgi.common.api.IntentsProvider;
 import org.apache.cxf.dosgi.samples.rest.Task;
 import org.apache.cxf.dosgi.samples.rest.TaskResource;
+import org.apache.cxf.ext.logging.LoggingFeature;
+import org.apache.cxf.feature.Features;
+import org.apache.cxf.jaxrs.swagger.Swagger2Feature;
 import org.osgi.service.component.annotations.Component;
 
 @Component//
@@ -37,12 +42,13 @@ import org.osgi.service.component.annotations.Component;
     { //
       "service.exported.interfaces=*", //
       "service.exported.configs=org.apache.cxf.rs", //
-      //"service.exported.intents=jackson", // Only needed when defining jackson as external
intent
       "org.apache.cxf.rs.address=/tasks", //
       // By default CXF will favor the default json provider
       "cxf.bus.prop.skip.default.json.provider.registration=true"
     } //
 )
+@Api(value = "mytest")
+@Features(classes = {LoggingFeature.class})
 public class TaskResourceImpl implements TaskResource, IntentsProvider {
     Map<Integer, Task> taskMap;
 
@@ -59,7 +65,7 @@ public class TaskResourceImpl implements TaskResource, IntentsProvider {
         task.setDescription("");
         addOrUpdate(task);
     }
-
+    
     @Override
     public Task get(Integer id) {
         return taskMap.get(id);
@@ -70,6 +76,7 @@ public class TaskResourceImpl implements TaskResource, IntentsProvider {
         taskMap.put(task.getId(), task);
     }
 
+
     @Override
     public Task[] getAll() {
         return taskMap.values().toArray(new Task[]{});
@@ -82,7 +89,17 @@ public class TaskResourceImpl implements TaskResource, IntentsProvider
{
 
     @Override
     public List<?> getIntents() {
-        return Arrays.asList(new JacksonJaxbJsonProvider());
+        return asList(createSwaggerFeature(), new JacksonJaxbJsonProvider());
+    }
+
+    private Swagger2Feature createSwaggerFeature() {
+        Swagger2Feature swagger = new Swagger2Feature();
+        //swagger2Feature.setBasePath("/cxf/");
+        swagger.setUsePathBasedConfig(true);
+        swagger.setPrettyPrint(true);
+        swagger.setSupportSwaggerUi(true);
+        swagger.setScan(false);
+        return swagger;
     }
 
 }


Mime
View raw message