This is an automated email from the ASF dual-hosted git repository.
reta pushed a commit to branch 3.6.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/3.6.x-fixes by this push:
new 11b688757b Fixing jax_rs/spring_boot_scan samples
11b688757b is described below
commit 11b688757bf2300cd390a3edfeec1219188dd5e0
Author: Andriy Redko <[email protected]>
AuthorDate: Sun Dec 18 14:04:17 2022 -0500
Fixing jax_rs/spring_boot_scan samples
---
.../application/src/main/resources/application.yml | 5 ++
.../application/src/main/resources/bootstrap.yml | 3 --
.../rs/service/SampleRestApplicationTest.java | 2 +-
.../samples/jax_rs/spring_boot_scan/client/pom.xml | 4 ++
.../rs/client/SampleRestClientApplication.java | 55 +++++++++++++++++-----
.../src/main/resources/application.yml | 4 --
6 files changed, 52 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/application/src/test/java/sample/rs/service/SampleRestApplicationTest.java
b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/test/java/sample/rs/service/SampleRestApplicationTest.java
index 7ecbe9a33a..876e2729c2 100644
---
a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/test/java/sample/rs/service/SampleRestApplicationTest.java
+++
b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/test/java/sample/rs/service/SampleRestApplicationTest.java
@@ -20,9 +20,9 @@ package sample.rs.service;
import org.apache.cxf.jaxrs.client.WebClient;
import org.junit.jupiter.api.Test;
-import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.boot.test.web.server.LocalServerPort;
import static org.junit.jupiter.api.Assertions.assertEquals;
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 48fd9ccb1e..f77656c695 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
@@ -45,6 +45,10 @@
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>${spring.cloud.eureka.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
<!-- Zest Circuit Breaker used by CXF Failover Feature -->
<dependency>
<groupId>org.qi4j.library</groupId>
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 0da32ed633..461a76da97 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 javax.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.netflix.eureka.EnableEurekaClient;
+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/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..2456368ead 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,6 @@
-
-
server:
port: 8761
-
-
eureka:
client:
registerWithEureka: false