Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2571618896 for ; Wed, 12 Aug 2015 10:44:07 +0000 (UTC) Received: (qmail 3310 invoked by uid 500); 12 Aug 2015 10:44:07 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 3249 invoked by uid 500); 12 Aug 2015 10:44:07 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 3240 invoked by uid 99); 12 Aug 2015 10:44:06 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Aug 2015 10:44:06 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A4AD3E03A8; Wed, 12 Aug 2015 10:44:06 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ay@apache.org To: commits@cxf.apache.org Message-Id: <9c5230ffa0594874a8a5d7f049552882@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: cxf git commit: [CXF-6530] Add a webapp version of Swagger2Feature sample using spring Date: Wed, 12 Aug 2015 10:44:06 +0000 (UTC) Repository: cxf Updated Branches: refs/heads/master 20c1dfa69 -> f7b77f3a5 [CXF-6530] Add a webapp version of Swagger2Feature sample using spring Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/f7b77f3a Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/f7b77f3a Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/f7b77f3a Branch: refs/heads/master Commit: f7b77f3a552dabeb3269c1fa5791ead88fbef878 Parents: 20c1dfa Author: Akitoshi Yoshida Authored: Wed Aug 12 12:43:10 2015 +0200 Committer: Akitoshi Yoshida Committed: Wed Aug 12 12:43:10 2015 +0200 ---------------------------------------------------------------------- .../jax_rs/description_swagger2_web/README.txt | 24 +++ .../jax_rs/description_swagger2_web/pom.xml | 179 +++++++++++++++++++ .../java/demo/jaxrs/swagger/server/Item.java | 49 +++++ .../java/demo/jaxrs/swagger/server/Sample.java | 130 ++++++++++++++ .../src/main/webapp/WEB-INF/context.xml | 62 +++++++ .../src/main/webapp/WEB-INF/web.xml | 41 +++++ .../src/main/webapp/index.html | 84 +++++++++ distribution/src/main/release/samples/pom.xml | 1 + 8 files changed, 570 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/f7b77f3a/distribution/src/main/release/samples/jax_rs/description_swagger2_web/README.txt ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger2_web/README.txt b/distribution/src/main/release/samples/jax_rs/description_swagger2_web/README.txt new file mode 100644 index 0000000..7ecb9f2 --- /dev/null +++ b/distribution/src/main/release/samples/jax_rs/description_swagger2_web/README.txt @@ -0,0 +1,24 @@ +JAX-RS Swagger2Feature Demo using WebApp with Spring +================= + +The demo shows a basic usage of Swagger API documentation with REST based Web Services using +JAX-RS 2.0 (JSR-339). In this demo, the Swagger2Feature is configured using Spring. +Swagger UI is available at: http://localhost:9000/ + +Building and running the demo using Maven +--------------------------------------- + +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 + mvn package tomcat7:run (from one command line window) + + +To remove the target dir, run mvn clean". + + + http://git-wip-us.apache.org/repos/asf/cxf/blob/f7b77f3a/distribution/src/main/release/samples/jax_rs/description_swagger2_web/pom.xml ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger2_web/pom.xml b/distribution/src/main/release/samples/jax_rs/description_swagger2_web/pom.xml new file mode 100644 index 0000000..7a19507 --- /dev/null +++ b/distribution/src/main/release/samples/jax_rs/description_swagger2_web/pom.xml @@ -0,0 +1,179 @@ + + + + 4.0.0 + jax_rs_description_swagger2_web + war + JAX-RS Swagger2 WebApp Demo + JAX-RS Basic Demo + + org.apache.cxf.samples + cxf-samples + 3.1.3-SNAPSHOT + ../.. + + + + ${project.version} + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.9 + + + generate-resources + + unpack + + + + + org.webjars + swagger-ui + 2.1.0 + true + ${project.build.directory}/swagger-ui + **/*.gz + + + + + + + + maven-resources-plugin + 2.6 + + + copy-resources + generate-resources + + copy-resources + + + ${project.build.directory}/${project.artifactId}-${project.version} + + + ${project.build.directory}/swagger-ui/META-INF/resources/webjars/swagger-ui/2.1.0 + true + + index.html + + + + + + + + + org.apache.tomcat.maven + tomcat7-maven-plugin + 2.1 + + ${project.build.directory}/${project.artifactId}-${project.version} + 9000 + / + + + + run-tomcat + + true + + + run + + + + + + + + + + io.swagger + swagger-jaxrs + + + javax.ws.rs + jsr311-api + + + + + org.webjars + swagger-ui + 2.1.0 + provided + + + javassist + javassist + 3.12.1.GA + + + com.fasterxml.jackson.jaxrs + jackson-jaxrs-json-provider + 2.4.1 + + + com.fasterxml.jackson.core + jackson-core + 2.4.1 + + + org.apache.cxf + cxf-rt-transports-http + 3.1.3-SNAPSHOT + + + org.apache.cxf + cxf-rt-frontend-jaxrs + 3.1.3-SNAPSHOT + + + org.apache.cxf + cxf-rt-rs-service-description + 3.1.3-SNAPSHOT + + + commons-lang + commons-lang + + + javax.ws.rs + javax.ws.rs-api + + + + + org.springframework + spring-context + + + org.springframework + spring-web + + + http://git-wip-us.apache.org/repos/asf/cxf/blob/f7b77f3a/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/java/demo/jaxrs/swagger/server/Item.java ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/java/demo/jaxrs/swagger/server/Item.java b/distribution/src/main/release/samples/jax_rs/description_swagger2_web/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_web/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/f7b77f3a/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/java/demo/jaxrs/swagger/server/Sample.java ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/java/demo/jaxrs/swagger/server/Sample.java b/distribution/src/main/release/samples/jax_rs/description_swagger2_web/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_web/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/f7b77f3a/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 new file mode 100644 index 0000000..7adc4ad --- /dev/null +++ b/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/WEB-INF/context.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + http://git-wip-us.apache.org/repos/asf/cxf/blob/f7b77f3a/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/WEB-INF/web.xml b/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..942887a --- /dev/null +++ b/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,41 @@ + + + + + CXF Swagger2 Spring Sample + + contextConfigLocation + WEB-INF/context.xml + + + org.springframework.web.context.ContextLoaderListener + + + CXF Service Servlet + CXFServiceServlet + org.apache.cxf.transport.servlet.CXFServlet + 1 + + + CXFServiceServlet + /app/* + + http://git-wip-us.apache.org/repos/asf/cxf/blob/f7b77f3a/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/index.html ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/index.html b/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/index.html new file mode 100644 index 0000000..19d5cf2 --- /dev/null +++ b/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/index.html @@ -0,0 +1,84 @@ + + + + + Swagger UI + JAX-RS demo + + + + + + + + + + + + + + + + + + + + +
 
+
+ + http://git-wip-us.apache.org/repos/asf/cxf/blob/f7b77f3a/distribution/src/main/release/samples/pom.xml ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/pom.xml b/distribution/src/main/release/samples/pom.xml index 40b6910..905d636 100644 --- a/distribution/src/main/release/samples/pom.xml +++ b/distribution/src/main/release/samples/pom.xml @@ -54,6 +54,7 @@ jax_rs/search jax_rs/description_swagger jax_rs/description_swagger2 + jax_rs/description_swagger2_web jax_rs/basic_oidc jax_rs/big_query callback