You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ay...@apache.org on 2015/08/14 14:41:21 UTC

cxf git commit: [CXF-6541] Add an OSGi version of Swagger2Feature sample using blueprint

Repository: cxf
Updated Branches:
  refs/heads/master 850a4436a -> b3c1804ba


[CXF-6541] Add an OSGi version of Swagger2Feature sample using blueprint


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

Branch: refs/heads/master
Commit: b3c1804ba33e0c2c7d991b585ba8147eb13ee07b
Parents: 850a443
Author: Akitoshi Yoshida <ay...@apache.org>
Authored: Fri Aug 14 14:37:24 2015 +0200
Committer: Akitoshi Yoshida <ay...@apache.org>
Committed: Fri Aug 14 14:39:12 2015 +0200

----------------------------------------------------------------------
 .../jax_rs/description_swagger2_osgi/README.txt |  31 +++++
 .../jax_rs/description_swagger2_osgi/pom.xml    | 122 +++++++++++++++++
 .../java/demo/jaxrs/swagger/server/Item.java    |  49 +++++++
 .../java/demo/jaxrs/swagger/server/Sample.java  | 130 +++++++++++++++++++
 .../resources/OSGI-INF/blueprint/context.xml    |  64 +++++++++
 5 files changed, 396 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/b3c1804b/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/README.txt
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/README.txt b/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/README.txt
new file mode 100644
index 0000000..96c080c
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/README.txt
@@ -0,0 +1,31 @@
+JAX-RS Swagger2Feature Demo for OSGi using Blueprint
+=================
+
+The demo shows a basic usage of Swagger 2.0 API documentation with REST based Web Services
+using JAX-RS 2.0 (JSR-339). In this demo, the Swagger2Feature is configured using Blueprint.
+
+Building and running the demo
+---------------------------------------
+
+From the base directory of this sample (i.e., where this README file is
+located), the Maven pom.xml file can be used to build and run the demo. 
+
+
+Using either UNIX or Windows:
+
+  mvn install
+
+//TO-DO add karaf's intruction to run the demo
+
+
+After installing this bundle on your Karaf instance, you will be able to find this service at
+
+  http://localhost:8181/cxf/swaggerSample
+
+And its Swagger API documents in json or yaml are available at
+
+  http://localhost:8181/cxf/swaggerSample/swagger.json
+  http://localhost:8181/cxf/swaggerSample/swagger.yaml
+
+
+

http://git-wip-us.apache.org/repos/asf/cxf/blob/b3c1804b/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/pom.xml b/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/pom.xml
new file mode 100644
index 0000000..1eaddb2
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/pom.xml
@@ -0,0 +1,122 @@
+<?xml version="1.0"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>jax_rs_description_swagger2_osgi</artifactId>
+    <packaging>bundle</packaging>
+    <name>CXF JAX-RS Swagger2 Blueprint Demo</name>
+    <description>JAX-RS Basic Demo</description>
+    <parent>
+        <groupId>org.apache.cxf.samples</groupId>
+        <artifactId>cxf-samples</artifactId>
+        <version>3.1.3-SNAPSHOT</version>
+        <relativePath>../..</relativePath>
+    </parent>
+
+    <properties>
+        <cxf.version>${project.version}</cxf.version>
+    </properties>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-SymbolicName>${project.groupId}.${project.artifactId};blueprint.aries.xml-validation:=false</Bundle-SymbolicName>
+                        <Import-Package>
+                            javax.ws.rs,
+                            javax.ws.rs.core,
+                            org.apache.cxf.jaxrs.provider,
+                            org.apache.cxf.jaxrs.swagger,
+                            org.osgi.service.blueprint,
+                            io.swagger.annotations,
+                            io.swagger.models,
+                            io.swagger.jaxrs.config,
+                            io.swagger.jaxrs.listing,
+                            *
+                        </Import-Package>
+                        <Export-Package>
+                        </Export-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>io.swagger</groupId>
+            <artifactId>swagger-jaxrs</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>javax.ws.rs</groupId>
+                    <artifactId>jsr311-api</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.webjars</groupId>
+            <artifactId>swagger-ui</artifactId>
+            <version>2.1.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>javassist</groupId>
+            <artifactId>javassist</artifactId>
+            <version>3.12.1.GA</version>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.jaxrs</groupId>
+            <artifactId>jackson-jaxrs-json-provider</artifactId>
+            <version>2.4.6</version>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-core</artifactId>
+            <version>2.4.6</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-transports-http</artifactId>
+            <version>3.1.3-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+            <version>3.1.3-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-rs-service-description</artifactId>
+            <version>3.1.3-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-lang</groupId>
+            <artifactId>commons-lang</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>javax.ws.rs</groupId>
+            <artifactId>javax.ws.rs-api</artifactId>
+        </dependency>
+    </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/cxf/blob/b3c1804b/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/src/main/java/demo/jaxrs/swagger/server/Item.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/src/main/java/demo/jaxrs/swagger/server/Item.java b/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/src/main/java/demo/jaxrs/swagger/server/Item.java
new file mode 100644
index 0000000..1b5be9b
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/src/main/java/demo/jaxrs/swagger/server/Item.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package demo.jaxrs.swagger.server;
+
+public class Item {
+    private String name;
+    private String value;
+    
+    public Item() {
+    }
+
+    public Item(final String name, final String value) {
+        this.name = name;
+        this.value = value;
+    }
+
+    public String getName() {
+        return name;
+    }
+    
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }       
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/b3c1804b/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/src/main/java/demo/jaxrs/swagger/server/Sample.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/src/main/java/demo/jaxrs/swagger/server/Sample.java b/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/src/main/java/demo/jaxrs/swagger/server/Sample.java
new file mode 100644
index 0000000..56d3213
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/src/main/java/demo/jaxrs/swagger/server/Sample.java
@@ -0,0 +1,130 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package demo.jaxrs.swagger.server;
+
+import java.util.Arrays;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+
+@Path("/sample") 
+@Api(value = "/sample", description = "Sample JAX-RS service with Swagger documentation")
+public class Sample {
+    @Produces({ MediaType.APPLICATION_JSON })
+    @GET
+    @ApiOperation(
+        value = "Get operation with Response and @Default value", 
+        notes = "Get operation with Response and @Default value", 
+        response = Item.class, 
+        responseContainer = "List"
+    )
+    public Response getItems(
+        @ApiParam(value = "Page to fetch", required = true) @QueryParam("page") @DefaultValue("1") int page) {
+        return Response.ok(
+            Arrays.asList(
+                new Item("Item 1", "Value 1"),
+                new Item("Item 2", "Value 2")
+            )
+        ).build();
+    }
+    
+    @Produces({ MediaType.APPLICATION_JSON })
+    @Path("/{name}")
+    @GET
+    @ApiOperation(
+        value = "Get operation with type and headers", 
+        notes = "Get operation with type and headers",
+        response = Item.class
+    )
+    public Item getItem(
+        @ApiParam(value = "language", required = true) @HeaderParam("Accept-Language") final String language,
+        @ApiParam(value = "name", required = true) @PathParam("name") String name) {
+        return new Item("name", "Value in " + language);
+    }
+    
+    @Consumes({ MediaType.APPLICATION_JSON })
+    @POST
+    @ApiOperation(
+        value = "Post operation with entity in a body", 
+        notes = "Post operation with entity in a body",
+        response = Item.class
+    )
+    public Response createItem(
+        @Context final UriInfo uriInfo,
+        @ApiParam(value = "item", required = true) final Item item) {
+        
+        return Response
+            .created(uriInfo.getBaseUriBuilder().path(item.getName()).build())
+            .entity(item).build();
+    }
+    
+    @Produces({ MediaType.APPLICATION_JSON })
+    @Path("/{name}")
+    @PUT
+    @ApiOperation(
+        value = "Put operation with form parameter", 
+        notes = "Put operation with form parameter",
+        response = Item.class
+    )
+    public Item updateItem(
+        @ApiParam(value = "name", required = true) @PathParam("name") String name,
+        @ApiParam(value = "value", required = true) @FormParam("value") String value) {        
+        return new Item(name, value);
+    }
+    
+    @Path("/{name}")
+    @DELETE
+    @ApiOperation(
+        value = "Delete operation with implicit header", 
+        notes = "Delete operation with implicit header"
+    )
+    @ApiImplicitParams(
+       @ApiImplicitParam(
+           name = "Accept-Language", 
+           value = "language", 
+           required = true, 
+           dataType = "String", 
+           paramType = "header"
+       )
+    )
+    public Response delete(@ApiParam(value = "name", required = true) @PathParam("name") String name) {
+        return Response.ok().build();
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/b3c1804b/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/src/main/resources/OSGI-INF/blueprint/context.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/src/main/resources/OSGI-INF/blueprint/context.xml b/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/src/main/resources/OSGI-INF/blueprint/context.xml
new file mode 100644
index 0000000..d1697a1
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/description_swagger2_osgi/src/main/resources/OSGI-INF/blueprint/context.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements. See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership. The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License. You may obtain a copy of the License at
+  
+  http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied. See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<!-- START SNIPPET: blueprint -->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:cxf="http://cxf.apache.org/blueprint/core"
+       xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
+
+       xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
+                           http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
+                           http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd">
+
+
+
+    <!-- JAXRS providers -->
+    <bean id="jsonProvider" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider" />
+    <bean id="multipartProvider" class="org.apache.cxf.jaxrs.provider.MultipartProvider" />
+
+    <!-- Application resources -->
+    <bean id="sampleResource" class="demo.jaxrs.swagger.server.Sample" />
+
+    <!-- CXF Swagger2Feature -->  
+    <bean id="swagger2Feature" class="org.apache.cxf.jaxrs.swagger.Swagger2Feature">
+        <property name="basePath" value="/app"/>
+    </bean>
+
+    <cxf:bus>
+        <cxf:features>
+            <cxf:logging />
+        </cxf:features>
+    </cxf:bus>
+
+    <jaxrs:server id="sampleServer" address="/swaggerSample">
+        <jaxrs:serviceBeans>
+            <ref component-id="sampleResource" />
+        </jaxrs:serviceBeans>
+        <jaxrs:providers>
+            <ref component-id="jsonProvider" />
+            <ref component-id="multipartProvider" />
+        </jaxrs:providers>
+        <jaxrs:features>
+            <ref component-id="swagger2Feature" />
+        </jaxrs:features>
+    </jaxrs:server>
+
+</blueprint>
+<!-- END SNIPPET: blueprint -->