cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: Starting updating Swagger2 _web demo to show the feature on 2 JAX-RS endpoints
Date Mon, 29 Aug 2016 13:06:12 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 59091dfee -> 35eb4eb1e


Starting updating Swagger2 _web demo to show the feature on 2 JAX-RS endpoints


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

Branch: refs/heads/master
Commit: 35eb4eb1ed527f95312b9d4ae31e44a56927abb7
Parents: 59091df
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Mon Aug 29 14:05:55 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Mon Aug 29 14:05:55 2016 +0100

----------------------------------------------------------------------
 .../java/demo/jaxrs/swagger/server/Server.java  |   2 +-
 .../java/demo/jaxrs/swagger/server/Sample2.java | 140 +++++++++++++++++++
 .../src/main/webapp/WEB-INF/context.xml         |  43 ++++--
 3 files changed, 174 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/35eb4eb1/distribution/src/main/release/samples/jax_rs/description_swagger2/src/main/java/demo/jaxrs/swagger/server/Server.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger2/src/main/java/demo/jaxrs/swagger/server/Server.java
b/distribution/src/main/release/samples/jax_rs/description_swagger2/src/main/java/demo/jaxrs/swagger/server/Server.java
index d35ab2e..22576af 100644
--- a/distribution/src/main/release/samples/jax_rs/description_swagger2/src/main/java/demo/jaxrs/swagger/server/Server.java
+++ b/distribution/src/main/release/samples/jax_rs/description_swagger2/src/main/java/demo/jaxrs/swagger/server/Server.java
@@ -39,7 +39,7 @@ public class Server {
         context.addServlet(servletHolder, "/*");  
         servletHolder.setInitParameter("jaxrs.serviceClasses", Sample.class.getName());
         servletHolder.setInitParameter("jaxrs.features", 
-            Swagger2Feature.class.getName() + "(basePath=/ usePathBasedConfig=true)");
+            Swagger2Feature.class.getName());
         servletHolder.setInitParameter("jaxrs.providers", StringUtils.join(
             new String[] {
                 MultipartProvider.class.getName(),

http://git-wip-us.apache.org/repos/asf/cxf/blob/35eb4eb1/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/java/demo/jaxrs/swagger/server/Sample2.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/java/demo/jaxrs/swagger/server/Sample2.java
b/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/java/demo/jaxrs/swagger/server/Sample2.java
new file mode 100644
index 0000000..5c08d53
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/java/demo/jaxrs/swagger/server/Sample2.java
@@ -0,0 +1,140 @@
+/**
+ * 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.Collections;
+import java.util.Map;
+import java.util.TreeMap;
+
+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("/sample2") 
+@Api(value = "/sample2", description = "Sample2 JAX-RS service with Swagger documentation")
+public class Sample2 {
+    private Map<String, Item> items;
+
+    public Sample2() {
+        items = Collections.synchronizedMap(new TreeMap<String, Item>(String.CASE_INSENSITIVE_ORDER));
+        items.put("Item 1", new Item("Item 1", "Value 1"));
+        items.put("Item 2", new Item("Item 2", "Value 2"));
+    }
+        
+    
+    @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(items.values()).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 items.get(name);
+    }
+    
+    @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) {
+        items.put(item.getName(), 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) {
+        Item item = new Item(name, value);
+        items.put(name,  item);
+        return item;
+    }
+    
+    @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) {
+        items.remove(name);
+        return Response.ok().build();
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/35eb4eb1/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/WEB-INF/context.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/WEB-INF/context.xml
b/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/WEB-INF/context.xml
index 40709dc..0893d38 100644
--- a/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/WEB-INF/context.xml
+++ b/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/WEB-INF/context.xml
@@ -27,38 +27,61 @@
 
     <import resource="classpath:META-INF/cxf/cxf.xml" />
 
+    <cxf:bus>
+        <cxf:features>
+            <cxf:logging />
+        </cxf:features>
+    </cxf:bus>
+    
     <!-- JAXRS providers -->
     <bean id="jsonProvider" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"
/>
-    <bean id="multipartProvider" class="org.apache.cxf.jaxrs.provider.MultipartProvider"
/>
     <bean id="originFilter" class="demo.jaxrs.swagger.server.ApiOriginFilter" />
 
-    <!-- Application resources -->
+    <!-- Application resource for the first Endpoint -->
     <bean id="sampleResource" class="demo.jaxrs.swagger.server.Sample" />
 
-    <!-- CXF Swagger2Feature -->  
+    <!-- Swagger2Feature for the first Endpoint -->  
     <bean id="swagger2Feature" class="org.apache.cxf.jaxrs.swagger.Swagger2Feature">
         <property name="basePath" value="/app/swaggerSample"/>
+        <property name="usePathBasedConfig" value="true"/>
     </bean>
 
-    <cxf:bus>
-        <cxf:features>
-            <cxf:logging />
-        </cxf:features>
-    </cxf:bus>
-
+    <!-- First Endpoint -->
     <jaxrs:server id="sampleServer" address="/swaggerSample">
         <jaxrs:serviceBeans>
             <ref bean="sampleResource" />
         </jaxrs:serviceBeans>
         <jaxrs:providers>
             <ref bean="jsonProvider" />
-            <ref bean="multipartProvider" />
             <ref bean="originFilter" />
         </jaxrs:providers>
         <jaxrs:features>
             <ref bean="swagger2Feature" />
         </jaxrs:features>
     </jaxrs:server>
+    
+    <!-- Application resource for the second Endpoint -->
+    <bean id="sampleResource2" class="demo.jaxrs.swagger.server.Sample2" />
+
+    <!-- Swagger2Feature for the second Endpoint -->  
+    <bean id="swagger2Feature2" class="org.apache.cxf.jaxrs.swagger.Swagger2Feature">
+        <property name="basePath" value="/app/swaggerSample2"/>
+        <property name="usePathBasedConfig" value="true"/>
+    </bean>
+
+    <!-- First Endpoint -->
+    <jaxrs:server id="sampleServer2" address="/swaggerSample2">
+        <jaxrs:serviceBeans>
+            <ref bean="sampleResource2" />
+        </jaxrs:serviceBeans>
+        <jaxrs:providers>
+            <ref bean="jsonProvider" />
+            <ref bean="originFilter" />
+        </jaxrs:providers>
+        <jaxrs:features>
+            <ref bean="swagger2Feature2" />
+        </jaxrs:features>
+    </jaxrs:server>
 
 </beans>
 <!-- END SNIPPET: beans -->


Mime
View raw message