[ https://issues.apache.org/jira/browse/CXF-8286?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17115944#comment-17115944 ]
Konrad Windszus commented on CXF-8286: -------------------------------------- I use the following code for initialization {code} /** Create webservice port via JAXRS proxy factory. * * * @param <T> Port class * @param clazz Port class * @param accessToken the token * @param needUnwrapRootValue if {@code true} the root element is always unwrapped when doing the unmarshalling * @param enableLogging if {@code true} request and response logging is enabled * @return Port object */ public static <T> T create(final Class<T> clazz, final String accessToken, boolean needUnwrapRootValue, boolean enableLogging) { // https://issues.apache.org/jira/browse/CXF-8286 JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(API_BASE_ADDRESS); bean.setFeatures(getFeatures(enableLogging, API_BASE_ADDRESS)); bean.setProviders(getProviders(needUnwrapRootValue, accessToken)); bean.setServiceClass(clazz); WebClient webClient = bean.createWebClient(); T proxy = JAXRSClientFactory.fromClient(webClient, clazz); //T proxy = bean.create(clazz); ClientConfiguration config = WebClient.getConfig(proxy); // add interceptor which sets property org.apache.cxf.transport.service_not_available to true in case of 429 responses config.getInInterceptors().add(new RateLimitingInterceptor()); // make sure that failover works //((JAXRSServiceImpl)config.getEndpoint().getService()).setCreateServiceModel(true); return proxy; } private static List<Feature> getFeatures(boolean enableLogging, String address) { final List<Feature> features = new ArrayList<>(); FailoverFeature failoverFeature = new CircuitBreakerFailoverFeature(); RetryStrategy retryStrategy = new RetryStrategy(); retryStrategy.setMaxNumberOfRetries(3); // for retry handling need to set the same alternate address (https://issues.apache.org/jira/browse/CXF-2036) retryStrategy.setAlternateAddresses(Collections.singletonList(address)); failoverFeature.setStrategy(retryStrategy); features.add(failoverFeature); if (enableLogging) { features.add(new LoggingFeature()); } return features; } private static List<Object> getProviders(boolean needUnwrapRootValue, final String accessToken) { // use jackson for JSON deserialization List<Object> providers = new ArrayList<Object>(); // unwrap the root value in the JSON: // http://stackoverflow.com/questions/11704255/jackson-json-deserialization-with-root-element ObjectMapper om = new ObjectMapper(); om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, needUnwrapRootValue); om.configure(SerializationFeature.WRAP_ROOT_VALUE, false); providers.add(new JacksonJsonProvider(om)); providers.add(new AuthenticationRequestFilter(accessToken)); providers.add(new BonuslyResponseExceptionMapper()); providers.add(new ErrorHandlerReaderInterceptor()); return providers; } {code} But the failover is not happening, as the circuit breaker removes the only available alternateAddress at https://github.com/apache/cxf/blob/master/rt/features/clustering/src/main/java/org/apache/cxf/clustering/CircuitBreakerTargetSelector.java#L160. I will try with just retry handler now... > AbstractStaticFailoverStrategy.getEndpoints() never returns anything for > JAX-RS clients (with RetryStrategy) > ------------------------------------------------------------------------------------------------------------ > > Key: CXF-8286 > URL: https://issues.apache.org/jira/browse/CXF-8286 > Project: CXF > Issue Type: Improvement > Affects Versions: 3.3.6, 3.2.13 > Reporter: Konrad Windszus > Assignee: Andriy Redko > Priority: Major > > When creating a JAX-RS client like described in > https://cxf.apache.org/docs/jax-rs-failover.html with > {code} > JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); > bean.setAddress(API_BASE_ADDRESS); > FailoverFeature failoverFeature = new CircuitBreakerFailoverFeature(); > RetryStrategy retryStrategy = new RetryStrategy(); > retryStrategy.setMaxNumberOfRetries(3); > failoverFeature.setStrategy(retryStrategy); > bean.setFeatures(Collection.singletonList(failureFeature)); > WebClient webClient = bean.createWebClient(); > > T proxy = JAXRSClientFactory.fromClient(webClient, clazz); > {code} > The method > https://github.com/apache/cxf/blob/517b88cb2c293115e0dce1c1105f448e9dc21164/rt/features/clustering/src/main/java/org/apache/cxf/clustering/AbstractStaticFailoverStrategy.java#L133 > always returns an empty list (due to the > https://github.com/apache/cxf/blob/517b88cb2c293115e0dce1c1105f448e9dc21164/rt/features/clustering/src/main/java/org/apache/cxf/clustering/AbstractStaticFailoverStrategy.java#L135 > getting the empty list from > https://github.com/apache/cxf/blob/38582fbab7ca33b1383715f1f5094b9b46a0303f/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceImpl.java#L112). > Why is the endpoints/services not correctly set up for Jax RS clients for the > failover handling to work. What else do I need to do here? -- This message was sent by Atlassian Jira (v8.3.4#803005)