cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [02/42] cxf git commit: Moving a demo client code into its module
Date Tue, 26 Jul 2016 00:41:07 GMT
Moving a demo client code into its module


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

Branch: refs/heads/master-jaxrs-2.1
Commit: 11e18bf5622cafdb10723cee895885d676b35a7b
Parents: 131449d
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Mon Jul 18 10:36:26 2016 +0300
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Mon Jul 18 10:36:26 2016 +0300

----------------------------------------------------------------------
 .../jax_rs/spring_boot_scan/application/pom.xml | 33 +------
 .../rs/client/SampleRestClientApplication.java  | 95 --------------------
 .../src/main/resources/application.yml          |  5 +-
 .../jax_rs/spring_boot_scan/client/README       | 33 +++++++
 .../jax_rs/spring_boot_scan/client/pom.xml      | 64 +++++++++++++
 .../rs/client/SampleRestClientApplication.java  | 95 ++++++++++++++++++++
 .../java/sample/rs/service/HelloService.java    | 34 +++++++
 .../client/src/main/resources/application.yml   | 12 +++
 8 files changed, 240 insertions(+), 131 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/11e18bf5/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/pom.xml
b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/pom.xml
index 50c3f98..856becc 100644
--- a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/pom.xml
+++ b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/pom.xml
@@ -6,7 +6,7 @@
         <artifactId>spring-boot-starter-parent</artifactId>
         <version>1.3.6.RELEASE</version>
     </parent> 
-    <artifactId>spring-boot-sample-rs-cxf-scan</artifactId>
+    <artifactId>spring-boot-sample-rs-cxf-scan-app</artifactId>
     <groupId>org.apache.cxf.samples</groupId>
     <version>3.2.0-SNAPSHOT</version>
     <name>Spring Boot CXF REST Scan Application</name>
@@ -29,11 +29,6 @@
             <artifactId>cxf-rt-rs-service-description-swagger</artifactId>
             <version>${cxf.version}</version>
         </dependency>
-        <dependency>
-            <groupId>org.apache.cxf</groupId>
-            <artifactId>cxf-rt-features-clustering</artifactId>
-            <version>${cxf.version}</version>
-        </dependency>
         <!-- Eureka Service Discovery Client -->
         <dependency>
             <groupId>org.springframework.cloud</groupId>
@@ -46,11 +41,6 @@
             <artifactId>spring-boot-actuator</artifactId>
             <version>${spring.boot.version}</version>
         </dependency>
-        <dependency>
-            <groupId>org.qi4j.library</groupId>
-            <artifactId>org.qi4j.library.circuitbreaker</artifactId>
-            <version>${cxf.zest.version}</version>
-        </dependency>
     </dependencies>
     <profiles>
        <profile>
@@ -61,27 +51,6 @@
              <plugin>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-maven-plugin</artifactId>
-              <configuration>
-                <mainClass>sample.rs.service.SampleRestApplication</mainClass>
-              </configuration>  
-             </plugin>
-           </plugins>
-          </build>
-       </profile>
-       <profile>
-         <id>client</id>
-         <build>
-           <defaultGoal>spring-boot:run</defaultGoal>
-           <plugins>
-             <plugin>
-              <groupId>org.springframework.boot</groupId>
-              <artifactId>spring-boot-maven-plugin</artifactId>
-              <configuration>
-                <mainClass>sample.rs.client.SampleRestClientApplication</mainClass>
-                <arguments>
-                   <argument>--eureka.client.registerWithEureka=false</argument>
-                 </arguments>
-              </configuration>  
              </plugin>
            </plugins>
           </build>

http://git-wip-us.apache.org/repos/asf/cxf/blob/11e18bf5/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/java/sample/rs/client/SampleRestClientApplication.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/java/sample/rs/client/SampleRestClientApplication.java
b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/java/sample/rs/client/SampleRestClientApplication.java
deleted file mode 100644
index 660cec9..0000000
--- a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/java/sample/rs/client/SampleRestClientApplication.java
+++ /dev/null
@@ -1,95 +0,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.
- */
-package sample.rs.client;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import javax.ws.rs.core.UriBuilder;
-
-import org.apache.cxf.annotations.Provider;
-import org.apache.cxf.annotations.Provider.Type;
-import org.apache.cxf.clustering.FailoverStrategy;
-import org.apache.cxf.clustering.RandomStrategy;
-import org.apache.cxf.clustering.circuitbreaker.CircuitBreakerFailoverFeature;
-import org.apache.cxf.jaxrs.client.spring.EnableJaxRsProxyClient;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.CommandLineRunner;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.builder.SpringApplicationBuilder;
-import org.springframework.cloud.client.ServiceInstance;
-import org.springframework.cloud.client.discovery.DiscoveryClient;
-import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
-import org.springframework.context.annotation.Bean;
-import org.springframework.stereotype.Component;
-
-import sample.rs.service.HelloService;
-
-@SpringBootApplication
-@EnableEurekaClient
-@EnableJaxRsProxyClient
-public class SampleRestClientApplication {
-    public static void main(String[] args) {
-        new SpringApplicationBuilder(SampleRestClientApplication.class)
-            .web(false)
-            .run(args);
-    }  
-    @Bean
-    CommandLineRunner initProxyClient(final HelloService service) {
-      
-      return new CommandLineRunner() {
-        @Override
-        public void run(String... runArgs) throws Exception {
-            System.out.println(service.sayHello("ApacheCxfProxyUser1"));
-            System.out.println(service.sayHello("ApacheCxfProxyUser2"));
-        }
-      };
-    }
-
-    /**
-     * Basic Random selection of statically prepared addresses.
-     * More advanced strategies will periodically pull DiscoveryClient
-     * to update the addresses list
-     */
-    @Component
-    @Provider(Type.Feature)
-    static class EurekaFailoverFeature extends CircuitBreakerFailoverFeature {
-        @Autowired
-        DiscoveryClient discoveryClient;
-        List<String> addresses = new LinkedList<String>();
-        
-        public EurekaFailoverFeature() {
-            super("eureka://registry");
-        }
-        
-        @Override
-        public FailoverStrategy getStrategy()  {
-            for (ServiceInstance s : discoveryClient.getInstances("jaxrs-hello-world-service"))
{
-                UriBuilder ub = UriBuilder.fromUri(s.getUri());
-                if (s.getMetadata().containsKey("servletPath")) {
-                    ub.path(s.getMetadata().get("servletPath"));
-                }
-                addresses.add(ub.build().toString());
-            }
-            RandomStrategy rs = new RandomStrategy();
-            rs.setAlternateAddresses(addresses);
-            return rs;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/cxf/blob/11e18bf5/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/resources/application.yml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/resources/application.yml
b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/resources/application.yml
index 26fb5aa..d59f2c1 100644
--- a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/resources/application.yml
+++ b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/resources/application.yml
@@ -9,13 +9,10 @@ cxf:
   jaxrs:
     component-scan: true
     classes-scan-packages: org.apache.cxf.jaxrs.swagger
-    client:
-      address: eureka://registry
-      classes-scan-packages: sample.rs.service
 
 eureka:
   client:
-    registerWithEureka: ${register.with.eureka:true}
+    registerWithEureka: true
     serviceUrl:
       defaultZone: http://127.0.0.1:8761/eureka/
   instance:

http://git-wip-us.apache.org/repos/asf/cxf/blob/11e18bf5/distribution/src/main/release/samples/jax_rs/spring_boot_scan/client/README
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/client/README b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/client/README
new file mode 100644
index 0000000..d42c304
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/client/README
@@ -0,0 +1,33 @@
+== Spring Boot - Samples - CXF Rest Client 
+
+This sample project demonstrates how to use CXF JAX-RS client code
+with Spring Boot.
+
+The application registers itself with Eureka Registry.  
+The client discovers the client address from the registry and invokes it.
+
+The sample uses Maven. It can be built and run from the command line.
+
+To run the client from a command line:
+
+1. 
+If you have not started a eureka-registry application then build and start it 
+first in the eureka-registry folder in a separate terminal window:
+
+$ mvn spring-boot:run
+
+If you have not started a demo application then build and start it 
+first in the application folder in a separate terminal window:
+
+----
+$ mvn -Pserver
+----
+
+
+Before running a command line client check the application has been registered, open a browser

+and try "http://localhost:8761/eureka/apps". Once you see a registration record, 
+open a new terminal window and run the client:
+
+----
+$ mvn -Pclient
+----

http://git-wip-us.apache.org/repos/asf/cxf/blob/11e18bf5/distribution/src/main/release/samples/jax_rs/spring_boot_scan/client/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/client/pom.xml
b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/client/pom.xml
new file mode 100644
index 0000000..660755d
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/client/pom.xml
@@ -0,0 +1,64 @@
+<?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.3.6.RELEASE</version>
+    </parent> 
+    <artifactId>spring-boot-sample-rs-cxf-scan-client</artifactId>
+    <groupId>org.apache.cxf.samples</groupId>
+    <version>3.2.0-SNAPSHOT</version>
+    <name>Spring Boot CXF REST Scan Application Client</name>
+    <description>Spring Boot CXF REST Scan Application Client</description>
+    
+    <properties>
+        <cxf.version>3.2.0-SNAPSHOT</cxf.version>
+        <cxf.zest.version>2.1</cxf.zest.version> 
+        <spring.boot.version>1.3.6.RELEASE</spring.boot.version>
+        <spring.cloud.eureka.version>1.1.3.RELEASE</spring.cloud.eureka.version>
+    </properties>
+    <dependencies>
+        <!-- CXF JAX-RS Client -->
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-rs-client</artifactId>
+            <version>${cxf.version}</version>
+        </dependency>
+        <!-- CXF FailoverFeature - pluggable with various strategies -->
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-features-clustering</artifactId>
+            <version>${cxf.version}</version>
+        </dependency>
+        <!-- Eureka Service Discovery Client -->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-eureka</artifactId>
+            <version>${spring.cloud.eureka.version}</version>
+        </dependency>
+        <!-- Zest Circuit Breaker used by CXF Failover Feature -->
+        <dependency>
+            <groupId>org.qi4j.library</groupId>
+            <artifactId>org.qi4j.library.circuitbreaker</artifactId>
+            <version>${cxf.zest.version}</version>
+        </dependency>
+    </dependencies>
+    <profiles>
+       <profile>
+         <id>client</id>
+         <build>
+           <defaultGoal>spring-boot:run</defaultGoal>
+           <plugins>
+             <plugin>
+              <groupId>org.springframework.boot</groupId>
+              <artifactId>spring-boot-maven-plugin</artifactId>
+              <configuration>
+                <mainClass>sample.rs.client.SampleRestClientApplication</mainClass>
+              </configuration>  
+             </plugin>
+           </plugins>
+          </build>
+       </profile>
+    </profiles>
+</project>

http://git-wip-us.apache.org/repos/asf/cxf/blob/11e18bf5/distribution/src/main/release/samples/jax_rs/spring_boot_scan/client/src/main/java/sample/rs/client/SampleRestClientApplication.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/client/src/main/java/sample/rs/client/SampleRestClientApplication.java
b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/client/src/main/java/sample/rs/client/SampleRestClientApplication.java
new file mode 100644
index 0000000..660cec9
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/client/src/main/java/sample/rs/client/SampleRestClientApplication.java
@@ -0,0 +1,95 @@
+/**
+ * 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 java.util.LinkedList;
+import java.util.List;
+
+import javax.ws.rs.core.UriBuilder;
+
+import org.apache.cxf.annotations.Provider;
+import org.apache.cxf.annotations.Provider.Type;
+import org.apache.cxf.clustering.FailoverStrategy;
+import org.apache.cxf.clustering.RandomStrategy;
+import org.apache.cxf.clustering.circuitbreaker.CircuitBreakerFailoverFeature;
+import org.apache.cxf.jaxrs.client.spring.EnableJaxRsProxyClient;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.cloud.client.ServiceInstance;
+import org.springframework.cloud.client.discovery.DiscoveryClient;
+import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
+import org.springframework.context.annotation.Bean;
+import org.springframework.stereotype.Component;
+
+import sample.rs.service.HelloService;
+
+@SpringBootApplication
+@EnableEurekaClient
+@EnableJaxRsProxyClient
+public class SampleRestClientApplication {
+    public static void main(String[] args) {
+        new SpringApplicationBuilder(SampleRestClientApplication.class)
+            .web(false)
+            .run(args);
+    }  
+    @Bean
+    CommandLineRunner initProxyClient(final HelloService service) {
+      
+      return new CommandLineRunner() {
+        @Override
+        public void run(String... runArgs) throws Exception {
+            System.out.println(service.sayHello("ApacheCxfProxyUser1"));
+            System.out.println(service.sayHello("ApacheCxfProxyUser2"));
+        }
+      };
+    }
+
+    /**
+     * Basic Random selection of statically prepared addresses.
+     * More advanced strategies will periodically pull DiscoveryClient
+     * to update the addresses list
+     */
+    @Component
+    @Provider(Type.Feature)
+    static class EurekaFailoverFeature extends CircuitBreakerFailoverFeature {
+        @Autowired
+        DiscoveryClient discoveryClient;
+        List<String> addresses = new LinkedList<String>();
+        
+        public EurekaFailoverFeature() {
+            super("eureka://registry");
+        }
+        
+        @Override
+        public FailoverStrategy getStrategy()  {
+            for (ServiceInstance s : discoveryClient.getInstances("jaxrs-hello-world-service"))
{
+                UriBuilder ub = UriBuilder.fromUri(s.getUri());
+                if (s.getMetadata().containsKey("servletPath")) {
+                    ub.path(s.getMetadata().get("servletPath"));
+                }
+                addresses.add(ub.build().toString());
+            }
+            RandomStrategy rs = new RandomStrategy();
+            rs.setAlternateAddresses(addresses);
+            return rs;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/11e18bf5/distribution/src/main/release/samples/jax_rs/spring_boot_scan/client/src/main/java/sample/rs/service/HelloService.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/client/src/main/java/sample/rs/service/HelloService.java
b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/client/src/main/java/sample/rs/service/HelloService.java
new file mode 100644
index 0000000..706b054
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/client/src/main/java/sample/rs/service/HelloService.java
@@ -0,0 +1,34 @@
+/**
+ * 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 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;
+ 
+@Path("/sayHello")
+public interface HelloService {
+ 
+    @GET
+    @Path("/{a}")
+    @Produces(MediaType.TEXT_PLAIN)
+    String sayHello(@PathParam("a") String a);
+    
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/11e18bf5/distribution/src/main/release/samples/jax_rs/spring_boot_scan/client/src/main/resources/application.yml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/client/src/main/resources/application.yml
b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/client/src/main/resources/application.yml
new file mode 100644
index 0000000..f74a0a7
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/client/src/main/resources/application.yml
@@ -0,0 +1,12 @@
+cxf:
+  jaxrs:
+    client:
+      address: eureka://registry
+      classes-scan-packages: sample.rs.service
+
+eureka:
+  client:
+    registerWithEureka: false
+    serviceUrl:
+      defaultZone: http://127.0.0.1:8761/eureka/
+


Mime
View raw message