diff --git a/udf-starter-rms/src/main/java/org/itkk/udf/rms/Rms.java b/udf-starter-rms/src/main/java/org/itkk/udf/rms/Rms.java index 93a8236..a71021f 100644 --- a/udf-starter-rms/src/main/java/org/itkk/udf/rms/Rms.java +++ b/udf-starter-rms/src/main/java/org/itkk/udf/rms/Rms.java @@ -12,6 +12,7 @@ import org.itkk.udf.core.exception.PermissionException; import org.itkk.udf.rms.meta.ApplicationMeta; import org.itkk.udf.rms.meta.ServiceMeta; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpEntity; @@ -45,12 +46,56 @@ public class Rms { @Autowired private RestTemplate restTemplate; + /** + * externalRestTemplate + */ + @Autowired + @Qualifier("externalRestTemplate") + private RestTemplate externalRestTemplate; + /** * 描述 : 配置 */ @Autowired private RmsProperties rmsProperties; + /** + * 远程服务调用 (不走ribbon) + * + * @param host 地址 + * @param port 端口 + * @param serviceCode 服务代码 + * @param input 输入参数 + * @param uriParam uri参数 + * @param responseType 返回类型 + * @param uriVariables rest参数 + * @param 输入类型 + * @param 输出类型 + * @return 服务结果 + */ + public ResponseEntity call(String host, int port, String serviceCode, I input, String uriParam, ParameterizedTypeReference responseType, Map uriVariables) { + //客户端权限验证 + verification(serviceCode); + //获取服务元数据 + ServiceMeta serviceMeta = rmsProperties.getService().get(serviceCode); + //构建请求路径 + String path = serviceMeta.getIsHttps() ? Constant.HTTPS : Constant.HTTP; + path.concat(host).concat(":").concat(String.valueOf(port)).concat(serviceMeta.getUri()); + //获得请求方法 + String method = getRmsMethod(serviceCode); + //拼装路径参数 + if (StringUtils.isNotBlank(uriParam)) { + path += uriParam; + } + //构建请求头 + HttpHeaders httpHeaders = buildSystemTagHeaders(serviceCode); + //构建请求消息体 + HttpEntity requestEntity = new HttpEntity<>(input, httpHeaders); + //请求并且返回 + log.info("rms url : {} , method : {} ", path, method); + return externalRestTemplate.exchange(path, HttpMethod.resolve(method), requestEntity, responseType, uriVariables != null ? uriVariables : new HashMap()); + } + /** * 描述 : 远程服务调用 * @@ -63,8 +108,7 @@ public class Rms { * @param 输出类型 * @return 服务结果 */ - public ResponseEntity call(String serviceCode, I input, String uriParam, - ParameterizedTypeReference responseType, Map uriVariables) { + public ResponseEntity call(String serviceCode, I input, String uriParam, ParameterizedTypeReference responseType, Map uriVariables) { //客户端权限验证 verification(serviceCode); //构建请求路径 @@ -81,8 +125,7 @@ public class Rms { HttpEntity requestEntity = new HttpEntity<>(input, httpHeaders); //请求并且返回 log.info("rms url : {} , method : {} ", path, method); - return restTemplate.exchange(path, HttpMethod.resolve(method), requestEntity, responseType, - uriVariables != null ? uriVariables : new HashMap()); + return restTemplate.exchange(path, HttpMethod.resolve(method), requestEntity, responseType, uriVariables != null ? uriVariables : new HashMap()); } /**