rms的call方法,添加有header的重载

This commit is contained in:
wangkang
2017-11-28 08:29:21 +08:00
parent e54c903b8e
commit e9942b22b6
@@ -7,6 +7,7 @@
package org.itkk.udf.rms;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.itkk.udf.core.exception.PermissionException;
import org.itkk.udf.rms.meta.ApplicationMeta;
@@ -65,6 +66,7 @@ public class Rms {
* @param host 地址
* @param port 端口
* @param serviceCode 服务代码
* @param headers headers
* @param input 输入参数
* @param uriParam uri参数
* @param responseType 返回类型
@@ -73,7 +75,7 @@ public class Rms {
* @param <O> 输出类型
* @return 服务结果
*/
public <I, O> ResponseEntity<O> call(String host, int port, String serviceCode, I input, String uriParam, ParameterizedTypeReference<O> responseType, Map<String, ?> uriVariables) {
public <I, O> ResponseEntity<O> call(String host, int port, String serviceCode, HttpHeaders headers, I input, String uriParam, ParameterizedTypeReference<O> responseType, Map<String, ?> uriVariables) {
//客户端权限验证
verification(serviceCode);
//获取服务元数据
@@ -88,6 +90,10 @@ public class Rms {
}
//构建请求头
HttpHeaders httpHeaders = buildSystemTagHeaders(serviceCode);
//添加请求头
if (MapUtils.isNotEmpty(headers)) {
httpHeaders.putAll(headers);
}
//构建请求消息体
HttpEntity<I> requestEntity = new HttpEntity<>(input, httpHeaders);
//请求并且返回
@@ -95,6 +101,61 @@ public class Rms {
return externalRestTemplate.exchange(path, HttpMethod.resolve(method), requestEntity, responseType, uriVariables != null ? uriVariables : new HashMap<String, String>());
}
/**
* 远程服务调用 (不走ribbon)
*
* @param host 地址
* @param port 端口
* @param serviceCode 服务代码
* @param input 输入参数
* @param uriParam uri参数
* @param responseType 返回类型
* @param uriVariables rest参数
* @param <I> 输入类型
* @param <O> 输出类型
* @return 服务结果
*/
public <I, O> ResponseEntity<O> call(String host, int port, String serviceCode, I input, String uriParam, ParameterizedTypeReference<O> responseType, Map<String, ?> uriVariables) {
return this.call(host, port, serviceCode, null, input, uriParam, responseType, uriVariables);
}
/**
* 描述 : 远程服务调用
*
* @param serviceCode 服务代码
* @param headers headers
* @param input 输入参数
* @param uriParam uri参数
* @param responseType 返回类型
* @param uriVariables rest参数
* @param <I> 输入类型
* @param <O> 输出类型
* @return 服务结果
*/
public <I, O> ResponseEntity<O> call(String serviceCode, HttpHeaders headers, I input, String uriParam, ParameterizedTypeReference<O> responseType, Map<String, ?> uriVariables) {
//客户端权限验证
verification(serviceCode);
//构建请求路径
String path = getRmsUrl(serviceCode);
//获得请求方法
String method = getRmsMethod(serviceCode);
//拼装路径参数
if (StringUtils.isNotBlank(uriParam)) {
path += uriParam;
}
//构建请求头
HttpHeaders httpHeaders = buildSystemTagHeaders(serviceCode);
//添加请求头
if (MapUtils.isNotEmpty(headers)) {
httpHeaders.putAll(headers);
}
//构建请求消息体
HttpEntity<I> requestEntity = new HttpEntity<>(input, httpHeaders);
//请求并且返回
log.debug("rms url : {} , method : {} ", path, method);
return restTemplate.exchange(path, HttpMethod.resolve(method), requestEntity, responseType, uriVariables != null ? uriVariables : new HashMap<String, String>());
}
/**
* 描述 : 远程服务调用
*
@@ -108,23 +169,7 @@ public class Rms {
* @return 服务结果
*/
public <I, O> ResponseEntity<O> call(String serviceCode, I input, String uriParam, ParameterizedTypeReference<O> responseType, Map<String, ?> uriVariables) {
//客户端权限验证
verification(serviceCode);
//构建请求路径
String path = getRmsUrl(serviceCode);
//获得请求方法
String method = getRmsMethod(serviceCode);
//拼装路径参数
if (StringUtils.isNotBlank(uriParam)) {
path += uriParam;
}
//构建请求头
HttpHeaders httpHeaders = buildSystemTagHeaders(serviceCode);
//构建请求消息体
HttpEntity<I> requestEntity = new HttpEntity<>(input, httpHeaders);
//请求并且返回
log.debug("rms url : {} , method : {} ", path, method);
return restTemplate.exchange(path, HttpMethod.resolve(method), requestEntity, responseType, uriVariables != null ? uriVariables : new HashMap<String, String>());
return this.call(serviceCode, null, input, uriParam, responseType, uriVariables);
}
/**