Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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 io.xream.x7.reyc.internal;
import com.github.kristofa.brave.httpclient.BraveHttpRequestInterceptor;
import com.github.kristofa.brave.httpclient.BraveHttpResponseInterceptor;
import io.github.resilience4j.circuitbreaker.CircuitBreaker;
import io.github.resilience4j.circuitbreaker.CircuitBreakerOpenException;
import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry;
import io.github.resilience4j.retry.Retry;
import io.github.resilience4j.retry.RetryConfig;
import io.github.resilience4j.retry.RetryRegistry;
import io.vavr.control.Try;
import io.xream.x7.reyc.ReyClient;
import io.xream.x7.reyc.Url;
import io.xream.x7.reyc.TracingConfig;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMethod;
import x7.core.bean.KV;
import x7.core.exception.BusyException;
import x7.core.exception.RemoteServiceException;
import x7.core.exception.ReyClientConnectException;
import x7.core.util.HttpClientUtil;
import x7.core.util.JsonX;
import x7.core.util.StringUtil;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Supplier;
import java.util.regex.Pattern;
public class ClientResolver {
private static Logger logger = LoggerFactory.getLogger(ReyClient.class);
private static CircuitBreakerRegistry circuitBreakerRegistry;
private static RetryRegistry retryRegistry;
private static BraveHttpRequestInterceptor requestInterceptor;
private static BraveHttpResponseInterceptor responseInterceptor;
private static HttpClientProperies properies;
public static void init(HttpClientProperies p, CircuitBreakerRegistry c, RetryRegistry r) {
circuitBreakerRegistry = c;
properies = p;
retryRegistry = r;
}
public static void initInterceptor(BraveHttpRequestInterceptor req, BraveHttpResponseInterceptor rep) {
requestInterceptor = req;
responseInterceptor = rep;
}
private static Pattern pattern = Pattern.compile("\\{[\\w]*\\}");
protected static R r(String remoteIntfName, String methodName, Object[] args) {
ClientParsed parsed = ClientParser.get(remoteIntfName);
String url = parsed.getUrl();
MethodParsed methodParsed = parsed.getMap().get(methodName);
if (methodParsed == null)
throw new RuntimeException("RequestMapping NONE: " + remoteIntfName + "." + methodName);
String mapping = methodParsed.getRequestMapping();
url = url + mapping;
List