1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| package cn.ray.gateway.sdk.domain.service;
import cn.hutool.http.HttpUtil; import cn.ray.gateway.sdk.GatewayException; import cn.ray.gateway.sdk.common.Result; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.TypeReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
import java.util.HashMap; import java.util.Map;
public class GatewayCenterService {
private Logger logger = LoggerFactory.getLogger(GatewayCenterService.class);
public void doRegisterApplication(String address, String systemId, String systemName, String systemType, String systemRegistry) { Map<String, Object> paramMap = new HashMap<>(); paramMap.put("systemId", systemId); paramMap.put("systemName", systemName); paramMap.put("systemType", systemType); paramMap.put("systemRegistry", systemRegistry); String resultStr; try { resultStr = HttpUtil.post(address + "/wg/admin/register/registerApplication", paramMap, 2000); } catch (Exception e) { logger.error("应用服务注册异常,链接资源不可用:{}", address + "/wg/admin/register/registerApplication"); throw e; } Result<Boolean> result = JSON.parseObject(resultStr, new TypeReference<Result<Boolean>>() { }); logger.info("向网关中心注册应用服务 systemId:{} systemName:{} 注册结果:{}", systemId, systemName, resultStr); if (!"0000".equals(result.getCode()) && !"0003".equals(result.getCode())) { throw new GatewayException("注册应用服务异常 [systemId:" + systemId + "] 、[systemRegistry:" + systemRegistry + "]"); } }
public void doRegisterApplicationInterface(String address, String systemId, String interfaceId, String interfaceName, String interfaceVersion) { Map<String, Object> paramMap = new HashMap<>(); paramMap.put("systemId", systemId); paramMap.put("interfaceId", interfaceId); paramMap.put("interfaceName", interfaceName); paramMap.put("interfaceVersion", interfaceVersion); String resultStr; try { resultStr = HttpUtil.post(address + "/wg/admin/register/registerApplicationInterface", paramMap, 2000); } catch (Exception e) { logger.error("应用服务接口注册异常,链接资源不可用:{}", address + "/wg/admin/register/registerApplicationInterface"); throw e; } Result<Boolean> result = JSON.parseObject(resultStr, new TypeReference<Result<Boolean>>() { }); logger.info("向网关中心注册应用接口服务 systemId:{} interfaceId:{} interfaceName:{} 注册结果:{}", systemId, interfaceId, interfaceName, resultStr); if (!"0000".equals(result.getCode()) && !"0003".equals(result.getCode())) { throw new GatewayException("向网关中心注册应用接口服务异常 [systemId:" + systemId + "] 、[interfaceId:" + interfaceId + "]"); } }
public void doRegisterApplicationInterfaceMethod(String address, String systemId, String interfaceId, String methodId, String methodName, String parameterType, String uri, String httpCommandType, Integer auth) { Map<String, Object> paramMap = new HashMap<>(); paramMap.put("systemId", systemId); paramMap.put("interfaceId", interfaceId); paramMap.put("methodId", methodId); paramMap.put("methodName", methodName); paramMap.put("parameterType", parameterType); paramMap.put("uri", uri); paramMap.put("httpCommandType", httpCommandType); paramMap.put("auth", auth);
String resultStr; try { resultStr = HttpUtil.post(address + "/wg/admin/register/registerApplicationInterfaceMethod", paramMap, 2000); } catch (Exception e) { logger.error("应用服务接口注册方法异常,链接资源不可用:{}", address + "/wg/admin/register/registerApplicationInterfaceMethod"); throw e; } Result<Boolean> result = JSON.parseObject(resultStr, new TypeReference<Result<Boolean>>() { }); logger.info("向网关中心注册应用接口方法服务 systemId:{} interfaceId:{} methodId:{} 注册结果:{}", systemId, interfaceId, methodId, resultStr); if (!"0000".equals(result.getCode()) && !"0003".equals(result.getCode())) throw new GatewayException("向网关中心注册应用接口方法服务异常 [systemId:" + systemId + "] 、[interfaceId:" + interfaceId + "]、[methodId:]" + methodId + "]"); } }
|