You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2016/07/08 15:55:38 UTC

cxf git commit: Spring boot scan demo updates

Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 35b673cc6 -> a95fdec3f


Spring boot scan demo updates


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

Branch: refs/heads/3.1.x-fixes
Commit: a95fdec3fc81f92692ce12aab8e5b7a7e6862ebf
Parents: 35b673c
Author: Sergey Beryozkin <sb...@gmail.com>
Authored: Fri Jul 8 16:50:49 2016 +0100
Committer: Sergey Beryozkin <sb...@gmail.com>
Committed: Fri Jul 8 16:55:16 2016 +0100

----------------------------------------------------------------------
 .../release/samples/jax_rs/spring_boot/pom.xml  | 60 +++++++++----------
 .../jax_rs/spring_boot_scan/application/README  | 20 +++++--
 .../jax_rs/spring_boot_scan/application/pom.xml | 59 +++++++++++-------
 .../rs/client/SampleRestClientApplication.java  | 51 +++++++++++-----
 .../rs/service/SampleRestApplication.java       | 63 ++++++++++++++++++++
 .../rs/service/SampleScanRestApplication.java   | 63 --------------------
 .../src/main/resources/application.yml          | 10 ++--
 .../spring_boot_scan/eureka-registry/README     | 14 +++++
 .../spring_boot_scan/eureka-registry/pom.xml    |  4 +-
 9 files changed, 203 insertions(+), 141 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/a95fdec3/distribution/src/main/release/samples/jax_rs/spring_boot/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/spring_boot/pom.xml b/distribution/src/main/release/samples/jax_rs/spring_boot/pom.xml
index 870edd1..3899ffd 100644
--- a/distribution/src/main/release/samples/jax_rs/spring_boot/pom.xml
+++ b/distribution/src/main/release/samples/jax_rs/spring_boot/pom.xml
@@ -28,35 +28,35 @@
         </dependency>
     </dependencies>
     <profiles>
-        <profile>
-            <id>server</id>
-    <build>
-      <defaultGoal>spring-boot:run</defaultGoal>
-      <plugins>
-        <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>
-           </configuration>  
-        </plugin>
-      </plugins>
-    </build>
-    </profile>
+       <profile>
+         <id>server</id>
+         <build>
+           <defaultGoal>spring-boot:run</defaultGoal>
+           <plugins>
+             <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>
+              </configuration>  
+             </plugin>
+           </plugins>
+          </build>
+       </profile>
     </profiles>
 </project>

http://git-wip-us.apache.org/repos/asf/cxf/blob/a95fdec3/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/README
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/README b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/README
index 40dbcf5..8f27dac 100644
--- a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/README
+++ b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/README
@@ -6,11 +6,20 @@ and deployed in a single JAX-RS endpoint.
 
 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:
+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
+
+2. Run the server 
+----
+$ mvn -Pserver
 ----
 
 http://localhost:8080/services/helloservice/sayHello/ApacheCxfUser
@@ -24,9 +33,12 @@ 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.
 
+
+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, do
+
 To run the client from a command line open a new terminal window and run:
 
 ----
-$ mvn exec:java
+$ mvn -Pclient
 ----
-

http://git-wip-us.apache.org/repos/asf/cxf/blob/a95fdec3/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 3e00ca6..0b52e28 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
@@ -14,6 +14,8 @@
     
     <properties>
         <cxf.version>3.1.7-SNAPSHOT</cxf.version>
+        <spring.boot.version>1.3.5.RELEASE</spring.boot.version>
+        <spring.cloud.eureka.version>1.1.3.RELEASE</spring.cloud.eureka.version>
     </properties>
     <dependencies>
         <dependency>
@@ -30,31 +32,48 @@
         <dependency>
             <groupId>org.springframework.cloud</groupId>
             <artifactId>spring-cloud-starter-eureka</artifactId>
-            <version>1.0.0.RELEASE</version>
+            <version>${spring.cloud.eureka.version}</version>
         </dependency>
         <!-- Actuator Endpoints --> 
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-actuator</artifactId>
-            <version>1.3.5.RELEASE</version>
+            <version>${spring.boot.version}</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>
+    <profiles>
+       <profile>
+         <id>server</id>
+         <build>
+           <defaultGoal>spring-boot:run</defaultGoal>
+           <plugins>
+             <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>
+       </profile>
+    </profiles>
 </project>

http://git-wip-us.apache.org/repos/asf/cxf/blob/a95fdec3/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
index 183c4a8..47ef38c 100644
--- 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
@@ -18,26 +18,45 @@
  */
 package sample.rs.client;
 
-import org.springframework.context.support.ClassPathXmlApplicationContext;
+import javax.ws.rs.core.UriBuilder;
 
-import sample.rs.service.HelloService;
+import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
+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 sample.rs.service.HelloService;
 
-public final class SampleRestClientApplication {
-    private HelloService helloService;
-    
+@SpringBootApplication
+@EnableEurekaClient
+public class SampleRestClientApplication {
     public static void main(String[] args) {
-        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("sample/rs/client/client.xml");
-        SampleRestClientApplication clientApp = ctx.getBean(SampleRestClientApplication.class);
-        System.out.println(clientApp.getHelloService().sayHello("ApacheCxfUser"));
-        ctx.close();
-    }
+        new SpringApplicationBuilder(SampleRestClientApplication.class)
+            .web(false)
+            .run(args);
+    }  
+    @Bean
+    CommandLineRunner initDiscoveryClient(final DiscoveryClient discoveryClient) {
+      
+      return new CommandLineRunner() {
 
-    public HelloService getHelloService() {
-        return helloService;
+        @Override
+        public void run(String... runArgs) throws Exception {
+            //TODO: Wire it in a CXF FailoverStrategy
+            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"));
+                }
+                HelloService service = JAXRSClientFactory.create(ub.build(), HelloService.class);
+                System.out.println(service.sayHello("ApacheCxfProxyUser"));
+            }
+            
+        }
+      };
     }
-
-    public void setHelloService(HelloService helloService) {
-        this.helloService = helloService;
-    }  
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/a95fdec3/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/java/sample/rs/service/SampleRestApplication.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/java/sample/rs/service/SampleRestApplication.java b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/java/sample/rs/service/SampleRestApplication.java
new file mode 100644
index 0000000..60ef15e
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/java/sample/rs/service/SampleRestApplication.java
@@ -0,0 +1,63 @@
+/**
+ * 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.springframework.boot.SpringApplication;
+import org.springframework.boot.actuate.autoconfigure.ExportMetricWriter;
+import org.springframework.boot.actuate.metrics.Metric;
+import org.springframework.boot.actuate.metrics.writer.Delta;
+import org.springframework.boot.actuate.metrics.writer.MetricWriter;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
+import org.springframework.context.annotation.Bean;
+
+@SpringBootApplication
+@EnableEurekaClient
+public class SampleRestApplication {
+    public static void main(String[] args) {
+        SpringApplication.run(SampleRestApplication.class, args);
+    }
+ 
+    @Bean
+    @ExportMetricWriter
+    public MetricWriter metricWriter() {
+            return new MetricWriter() {
+
+                @Override
+                public void set(Metric<?> arg0) {
+                    // TODO Auto-generated method stub
+                    
+                }
+
+                @Override
+                public void increment(Delta<?> arg0) {
+                    // TODO Auto-generated method stub
+                    
+                }
+
+                @Override
+                public void reset(String arg0) {
+                    // TODO Auto-generated method stub
+                    
+                }
+                
+            };
+    }
+    
+    
+ }

http://git-wip-us.apache.org/repos/asf/cxf/blob/a95fdec3/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/java/sample/rs/service/SampleScanRestApplication.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/java/sample/rs/service/SampleScanRestApplication.java b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/java/sample/rs/service/SampleScanRestApplication.java
deleted file mode 100644
index 9940733..0000000
--- a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/java/sample/rs/service/SampleScanRestApplication.java
+++ /dev/null
@@ -1,63 +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.service;
-import org.apache.cxf.jaxrs.swagger.Swagger2Feature;
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.actuate.autoconfigure.ExportMetricWriter;
-import org.springframework.boot.actuate.metrics.Metric;
-import org.springframework.boot.actuate.metrics.writer.Delta;
-import org.springframework.boot.actuate.metrics.writer.MetricWriter;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.annotation.Bean;
-
-@SpringBootApplication
-@EnableEurekaClient
-public class SampleScanRestApplication {
-    public static void main(String[] args) {
-        SpringApplication.run(SampleScanRestApplication.class, args);
-    }
- 
-    @Bean
-    @ExportMetricWriter
-    public MetricWriter metricWriter() {
-            return new MetricWriter() {
-
-                @Override
-                public void set(Metric<?> arg0) {
-                    // TODO Auto-generated method stub
-                    
-                }
-
-                @Override
-                public void increment(Delta<?> arg0) {
-                    // TODO Auto-generated method stub
-                    
-                }
-
-                @Override
-                public void reset(String arg0) {
-                    // TODO Auto-generated method stub
-                    
-                }
-                
-            };
-    }
-}

http://git-wip-us.apache.org/repos/asf/cxf/blob/a95fdec3/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 b9582e6..45ddf9b 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
@@ -1,5 +1,5 @@
 server:
-  port: ${vcap.application.port:8080}
+  port: 8080
   servlet-path: /system
 
 cxf:
@@ -12,15 +12,13 @@ cxf:
 
 eureka:
   client:
+    registerWithEureka: ${register.with.eureka:true}
     serviceUrl:
-      defaultZone: ${vcap.services.eureka-service.credentials.uri:http://127.0.0.1:8761}/eureka/
+      defaultZone: http://127.0.0.1:8761/eureka/
   instance:
     statusPageUrlPath: /services/helloservice/info
     healthCheckUrlPath: /system/health
     metadataMap:
       instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}} 
-    
----
-spring:
-  profiles: cloud        
+      servletPath: ${cxf.path}
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/a95fdec3/distribution/src/main/release/samples/jax_rs/spring_boot_scan/eureka-registry/README
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/eureka-registry/README b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/eureka-registry/README
new file mode 100644
index 0000000..7da21aa
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/eureka-registry/README
@@ -0,0 +1,14 @@
+== Spring Boot - Eureka Registry Application 
+
+This sample project shows how to start Eureka Registry.  
+
+
+Run the registry application:
+ 
+----
+$ mvn spring-boot:run
+----
+
+Check the registry is live with typing "http://localhost:8761/eureka/apps" in a browser.
+
+Next run the demo server and once the registration record is available - the command line client.

http://git-wip-us.apache.org/repos/asf/cxf/blob/a95fdec3/distribution/src/main/release/samples/jax_rs/spring_boot_scan/eureka-registry/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/eureka-registry/pom.xml b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/eureka-registry/pom.xml
index e6aee0b..2bcd46b 100644
--- a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/eureka-registry/pom.xml
+++ b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/eureka-registry/pom.xml
@@ -5,8 +5,8 @@
 
     <parent>
         <groupId>org.springframework.cloud</groupId>
-        <artifactId>spring-cloud-starter-parent</artifactId>
-        <version>1.0.0.RELEASE</version>
+        <artifactId>spring-cloud-dependencies</artifactId>
+        <version>Brixton.RELEASE</version>
     </parent>
 
     <artifactId>eureka-registry-for-cxf</artifactId>