You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2016/05/31 00:36:55 UTC

[05/17] cxf git commit: Adding JAX-RS Spring Boot Scan demo

Adding JAX-RS Spring Boot Scan demo


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

Branch: refs/heads/master-jaxrs-2.1
Commit: 7d16c1fe81ec33e58d69c9bf655c01218ace61bf
Parents: b97c78f
Author: Sergey Beryozkin <sb...@gmail.com>
Authored: Sun May 29 17:37:30 2016 +0100
Committer: Sergey Beryozkin <sb...@gmail.com>
Committed: Sun May 29 17:37:30 2016 +0100

----------------------------------------------------------------------
 .../jax_rs/jaxrs_spring_boot_scan/README        | 28 ++++++++
 .../jax_rs/jaxrs_spring_boot_scan/pom.xml       | 69 ++++++++++++++++++++
 .../rs/client/SampleRestClientApplication.java  | 35 ++++++++++
 .../rs/service/SampleScanRestApplication.java   | 42 ++++++++++++
 .../sample/rs/service/hello1/HelloService.java  | 42 ++++++++++++
 .../sample/rs/service/hello2/HelloService2.java | 42 ++++++++++++
 .../src/main/resources/application.properties   |  1 +
 7 files changed, 259 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/7d16c1fe/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/README
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/README b/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/README
new file mode 100644
index 0000000..e46b561
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/README
@@ -0,0 +1,28 @@
+== Spring Boot - Samples - CXF Rest Web Services 
+
+This sample project demonstrates how to use http://projects.spring.io/spring-rs-cxf/[CXF Rest Web Services]
+with Spring Boot. 
+
+The sample uses Maven. It can be built and run from the command line:
+
+----
+$ mvn spring-boot:run
+----
+
+http://localhost:8080/services/helloservice/sayHello/ApacheCxfUser
+
+will display "Hello ApacheCxfUser, Welcome to CXF RS Spring Boot World!!!"
+
+http://localhost:8080/services/helloservice/sayHello2/ApacheCxfUser
+
+will display "Hello2 ApacheCxfUser, Welcome to CXF RS Spring Boot World!!!"
+
+http://localhost:8080/services/helloservice/swagger.json will return a Swagger JSON
+description of services.
+
+To run the client from a command line open a new terminal window and run:
+
+----
+$ mvn exec:java
+----
+

http://git-wip-us.apache.org/repos/asf/cxf/blob/7d16c1fe/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/pom.xml b/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/pom.xml
new file mode 100644
index 0000000..18a41bb
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/pom.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>1.2.3.RELEASE</version>
+    </parent> 
+    <artifactId>spring-boot-sample-rs-cxf-scan</artifactId>
+    <name>Spring Boot CXF REST Application</name>
+    <description>Spring Boot CXF REST Application</description>
+    
+    <properties>
+        <cxf.version>3.2.0-SNAPSHOT</cxf.version>
+        <jetty.version>8.1.5.v20120716</jetty.version>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-spring-boot-starter-jax-rs</artifactId>
+            <version>${cxf.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-rs-client</artifactId>
+            <version>${cxf.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-rs-service-description</artifactId>
+            <version>${cxf.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>io.swagger</groupId>
+            <artifactId>swagger-jaxrs</artifactId>
+            <version>1.5.4</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>javax.ws.rs</groupId>
+                    <artifactId>jsr311-api</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>cglib</groupId>
+            <artifactId>cglib-nodep</artifactId>
+            <version>2.2.2</version>
+        </dependency>
+        
+    </dependencies>
+    <build>
+      <plugins>
+        <plugin>
+           <groupId>org.springframework.boot</groupId>
+           <artifactId>spring-boot-maven-plugin</artifactId>
+           <configuration>
+               <mainClass>sample.rs.service.SampleScanRestApplication</mainClass>
+           </configuration>  
+        </plugin>
+        <plugin>
+            <groupId>org.codehaus.mojo</groupId>
+            <artifactId>exec-maven-plugin</artifactId>
+            <configuration>
+              <mainClass>sample.rs.client.SampleRestClientApplication</mainClass>
+            </configuration>
+        </plugin>
+      </plugins>
+    </build>
+</project>

http://git-wip-us.apache.org/repos/asf/cxf/blob/7d16c1fe/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/src/main/java/sample/rs/client/SampleRestClientApplication.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/src/main/java/sample/rs/client/SampleRestClientApplication.java b/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/src/main/java/sample/rs/client/SampleRestClientApplication.java
new file mode 100644
index 0000000..f015097
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/src/main/java/sample/rs/client/SampleRestClientApplication.java
@@ -0,0 +1,35 @@
+/**
+ * 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 sample.rs.client;
+
+import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
+
+import sample.rs.service.hello1.HelloService;
+
+
+public final class SampleRestClientApplication {
+    private SampleRestClientApplication() {
+        
+    }
+    public static void main(String[] args) {
+        HelloService service = JAXRSClientFactory.create("http://localhost:8080/services/helloservice/", 
+                                  HelloService.class);
+        System.out.println(service.sayHello("ApacheCxfUser"));
+    }  
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/7d16c1fe/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/src/main/java/sample/rs/service/SampleScanRestApplication.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/src/main/java/sample/rs/service/SampleScanRestApplication.java b/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/src/main/java/sample/rs/service/SampleScanRestApplication.java
new file mode 100644
index 0000000..9f79c23
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/src/main/java/sample/rs/service/SampleScanRestApplication.java
@@ -0,0 +1,42 @@
+/**
+ * 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 sample.rs.service;
+import org.apache.cxf.jaxrs.spring.SpringComponentScanServer;
+import org.apache.cxf.jaxrs.swagger.Swagger2Feature;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Import;
+
+@SpringBootApplication
+@Import(SpringComponentScanServer.class)
+public class SampleScanRestApplication {
+    public static void main(String[] args) {
+        SpringApplication.run(SampleScanRestApplication.class, args);
+    }
+ 
+    @Bean
+    public Swagger2Feature swaggerFeature(ApplicationContext context) {
+        // Or create a simple Swagger2Feature @Component-annotated extension
+        // and drop this method if a default feature setup is OK
+        return new Swagger2Feature();
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/7d16c1fe/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/src/main/java/sample/rs/service/hello1/HelloService.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/src/main/java/sample/rs/service/hello1/HelloService.java b/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/src/main/java/sample/rs/service/hello1/HelloService.java
new file mode 100644
index 0000000..6672ecb
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/src/main/java/sample/rs/service/hello1/HelloService.java
@@ -0,0 +1,42 @@
+/**
+ * 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 sample.rs.service.hello1;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.springframework.stereotype.Service;
+
+import io.swagger.annotations.Api;
+ 
+@Path("/sayHello")
+@Service
+@Api("/sayHello")
+public class HelloService {
+ 
+    @GET
+    @Path("/{a}")
+    @Produces(MediaType.TEXT_PLAIN)
+    public String sayHello(@PathParam("a") String a) {
+        return "Hello " + a + ", Welcome to CXF RS Spring Boot World!!!";
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/7d16c1fe/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/src/main/java/sample/rs/service/hello2/HelloService2.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/src/main/java/sample/rs/service/hello2/HelloService2.java b/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/src/main/java/sample/rs/service/hello2/HelloService2.java
new file mode 100644
index 0000000..874e363
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/src/main/java/sample/rs/service/hello2/HelloService2.java
@@ -0,0 +1,42 @@
+/**
+ * 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 sample.rs.service.hello2;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.springframework.stereotype.Service;
+
+import io.swagger.annotations.Api;
+ 
+@Path("/sayHello2")
+@Service
+@Api("/sayHello2")
+public class HelloService2 {
+ 
+    @GET
+    @Path("/{a}")
+    @Produces(MediaType.TEXT_PLAIN)
+    public String sayHello(@PathParam("a") String a) {
+        return "Hello2 " + a + ", Welcome to CXF RS Spring Boot World!!!";
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/7d16c1fe/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/src/main/resources/application.properties
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/src/main/resources/application.properties b/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/src/main/resources/application.properties
new file mode 100644
index 0000000..27c5c26
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/jaxrs_spring_boot_scan/src/main/resources/application.properties
@@ -0,0 +1 @@
+cxf.path=/services/helloservice
\ No newline at end of file