io.xream.x7.reyc.internal.HttpClientResolver Maven / Gradle / Ivy
/*
* 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.xream.x7.reyc.*;
import io.xream.x7.reyc.api.ReyTemplate;
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.RemoteServiceException;
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.regex.Pattern;
public class HttpClientResolver {
private static Logger logger = LoggerFactory.getLogger(ReyClient.class);
private static ReyTemplate reyTemplate;
private static BraveHttpRequestInterceptor requestInterceptor;
private static BraveHttpResponseInterceptor responseInterceptor;
private static HttpClientProperies properies;
public static void init(HttpClientProperies p, ReyTemplate rt) {
properies = p;
reyTemplate = rt;
}
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
© 2015 - 2025 Weber Informatics LLC | Privacy Policy