This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/main by this push:
     new 5af87bddb0 Fixing jax_rs/spring_boot_scan samples
5af87bddb0 is described below

commit 5af87bddb070ddd14c56bb3e764a831b32b5e456
Author: Andriy Redko <[email protected]>
AuthorDate: Sun Dec 18 13:16:22 2022 -0500

    Fixing jax_rs/spring_boot_scan samples
---
 .../application/src/main/resources/application.yml |  5 ++
 .../application/src/main/resources/bootstrap.yml   |  3 --
 .../samples/jax_rs/spring_boot_scan/client/pom.xml | 27 +++++++++++
 .../rs/client/SampleRestClientApplication.java     | 55 +++++++++++++++++-----
 .../spring_boot_scan/eureka-registry/pom.xml       | 10 ++++
 .../src/main/resources/application.yml             |  5 --
 6 files changed, 84 insertions(+), 21 deletions(-)

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 2ea2b07296..93d65d16fc 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,3 +1,8 @@
+spring:
+  application:
+    instance_id: jaxrs-hello-world-service
+    name: jaxrs-hello-world-service
+
 server:
   port: 8080
   servlet-path: /system
diff --git 
a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/resources/bootstrap.yml
 
b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/resources/bootstrap.yml
deleted file mode 100644
index 64c10bc677..0000000000
--- 
a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/resources/bootstrap.yml
+++ /dev/null
@@ -1,3 +0,0 @@
-spring:
-  application:
-    name: jaxrs-hello-world-service
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
index 1b64c6d965..7d6756a278 100644
--- 
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
@@ -11,6 +11,15 @@
     <name>Spring Boot CXF REST Scan Application Client</name>
     <description>Spring Boot CXF REST Scan Application Client</description>
 
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>com.google.code.gson</groupId>
+                <artifactId>gson</artifactId>
+                <version>${cxf.gson.version}</version>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
     <dependencies>
         <!-- CXF JAX-RS Client -->
         <dependency>
@@ -29,6 +38,24 @@
             <groupId>org.springframework.cloud</groupId>
             <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
             <version>${spring.cloud.eureka.version}</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.sun.jersey</groupId>
+                    <artifactId>jersey-client</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>com.sun.jersey</groupId>
+                    <artifactId>jersey-core</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>com.sun.jersey.contribs</groupId>
+                    <artifactId>jersey-apache-client4</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
         <!-- Zest Circuit Breaker used by CXF Failover Feature -->
         <dependency>
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
index 5c8c5e61b2..25d7cf848b 100644
--- 
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
@@ -18,6 +18,10 @@
  */
 package sample.rs.client;
 
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -25,6 +29,7 @@ import jakarta.ws.rs.core.UriBuilder;
 
 import org.apache.cxf.annotations.Provider;
 import org.apache.cxf.annotations.Provider.Type;
+import org.apache.cxf.clustering.CircuitBreakerTargetSelector;
 import org.apache.cxf.clustering.FailoverStrategy;
 import org.apache.cxf.clustering.RandomStrategy;
 import org.apache.cxf.clustering.circuitbreaker.CircuitBreakerFailoverFeature;
@@ -37,6 +42,8 @@ import 
org.springframework.boot.builder.SpringApplicationBuilder;
 import org.springframework.cloud.client.ServiceInstance;
 import org.springframework.cloud.client.discovery.DiscoveryClient;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import 
org.springframework.cloud.netflix.eureka.http.DefaultEurekaClientHttpRequestFactorySupplier;
+import 
org.springframework.cloud.netflix.eureka.http.RestTemplateDiscoveryClientOptionalArgs;
 import org.springframework.context.annotation.Bean;
 import org.springframework.stereotype.Component;
 
@@ -47,6 +54,15 @@ import sample.rs.service.HelloService;
 @EnableJaxRsProxyClient
 public class SampleRestClientApplication {
     public static void main(String[] args) {
+        URL.setURLStreamHandlerFactory(protocol -> "eureka".equals(protocol) ? 
new URLStreamHandler() {
+            protected URLConnection openConnection(URL url) throws IOException 
{
+                return new URLConnection(url) {
+                    public void connect() throws IOException {
+                    }
+                };
+            }
+        } : null);
+
         new SpringApplicationBuilder(SampleRestClientApplication.class)
             .web(WebApplicationType.NONE)
             .run(args);
@@ -63,6 +79,11 @@ public class SampleRestClientApplication {
         };
     }
 
+    @Bean
+    RestTemplateDiscoveryClientOptionalArgs 
restTemplateDiscoveryClientOptionalArgs() {
+        return new RestTemplateDiscoveryClientOptionalArgs(new 
DefaultEurekaClientHttpRequestFactorySupplier());
+    }
+
     /**
      * Basic Random selection of statically prepared addresses.
      * More advanced strategies will periodically pull DiscoveryClient
@@ -72,25 +93,33 @@ public class SampleRestClientApplication {
     @Provider(Type.Feature)
     static class EurekaFailoverFeature extends CircuitBreakerFailoverFeature {
         @Autowired
-        DiscoveryClient discoveryClient;
-        List<String> addresses = new LinkedList<>();
+        private DiscoveryClient discoveryClient;
+        private List<String> addresses = new LinkedList<>();
 
         EurekaFailoverFeature() {
-            super("eureka://registry");
+            super();
+            setDelegate(new 
EurekaFailoverFeaturePortable(CircuitBreakerTargetSelector.DEFAULT_THESHOLD,
+                CircuitBreakerTargetSelector.DEFAULT_TIMEOUT, 
"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"));
+        private class EurekaFailoverFeaturePortable extends 
CircuitBreakerFailoverFeature.Portable {
+            EurekaFailoverFeaturePortable(int threshold, long timeout, String 
clientBootstrapAddress) {
+                super(threshold, timeout, clientBootstrapAddress);
+            }
+
+            @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());
                 }
-                addresses.add(ub.build().toString());
+                RandomStrategy rs = new RandomStrategy();
+                rs.setAlternateAddresses(addresses);
+                return rs;
             }
-            RandomStrategy rs = new RandomStrategy();
-            rs.setAlternateAddresses(addresses);
-            return rs;
         }
     }
 }
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 bfc3783808..03be990cb9 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
@@ -22,6 +22,16 @@
                 <type>pom</type>
                 <scope>import</scope>
             </dependency>
+            <dependency>
+                <groupId>jakarta.ws.rs</groupId>
+                <artifactId>jakarta.ws.rs-api</artifactId>
+               <version>3.1.0</version>
+            </dependency>
+            <dependency>
+                <groupId>com.google.code.gson</groupId>
+                <artifactId>gson</artifactId>
+                <version>${cxf.gson.version}</version>
+            </dependency>
         </dependencies>
     </dependencyManagement>
     <dependencies>
diff --git 
a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/eureka-registry/src/main/resources/application.yml
 
b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/eureka-registry/src/main/resources/application.yml
index e5b7ab73fa..f7293b615a 100644
--- 
a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/eureka-registry/src/main/resources/application.yml
+++ 
b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/eureka-registry/src/main/resources/application.yml
@@ -1,10 +1,5 @@
-
-
 server:
   port: 8761
-
-
-
 eureka:
   client:
     registerWithEureka: false

Reply via email to