|
@ -22,6 +22,7 @@ import java.util.stream.Stream;
|
|
|
|
|
|
public class GatewayProcessor implements Processor {
|
|
public class GatewayProcessor implements Processor {
|
|
static Map<String, AppApi> apiMap = new HashMap<>();
|
|
static Map<String, AppApi> apiMap = new HashMap<>();
|
|
|
|
static final String agUrl = "http://192.168.1.221:10000";
|
|
|
|
|
|
public void process(Exchange exchange) throws Exception {
|
|
public void process(Exchange exchange) throws Exception {
|
|
Message inMessage = exchange.getIn();
|
|
Message inMessage = exchange.getIn();
|
|
@ -34,7 +35,7 @@ public class GatewayProcessor implements Processor {
|
|
public String secret(@Body String body, Exchange exchange) throws IOException, ParseException {
|
|
public String secret(@Body String body, Exchange exchange) throws IOException, ParseException {
|
|
System.out.println(body);
|
|
System.out.println(body);
|
|
String appKey = exchange.getIn().getHeaders().get("appKey").toString();
|
|
String appKey = exchange.getIn().getHeaders().get("appKey").toString();
|
|
return "restlet:http://192.168.1.221:10000/api/v1.0/admin/apps/" + appKey;
|
|
|
|
|
|
return "restlet:"+ agUrl + "/api/v1.0/admin/apps/" + appKey;
|
|
}
|
|
}
|
|
|
|
|
|
public String route(Exchange exchange) throws IOException, ParseException {
|
|
public String route(Exchange exchange) throws IOException, ParseException {
|
|
@ -127,7 +128,7 @@ public class GatewayProcessor implements Processor {
|
|
private boolean checkAuthorized(Map<String, Object> params) {
|
|
private boolean checkAuthorized(Map<String, Object> params) {
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
//TODO 设置固定的验证入口地址
|
|
//TODO 设置固定的验证入口地址
|
|
HTTPResponse response = HttpClientKit.get("http://192.168.1.221:10000/api/v1.0/admin/appApiAuth?appId=" + params.get("appKey") + "&apiName=" + params.get("api"));
|
|
|
|
|
|
HTTPResponse response = HttpClientKit.get(agUrl + "/api/v1.0/admin/appApiAuth?appId=" + params.get("appKey") + "&apiName=" + params.get("api"));
|
|
if (response.getStatusCode() != 200) {
|
|
if (response.getStatusCode() != 200) {
|
|
System.out.println("验证API权限,请求失败!");
|
|
System.out.println("验证API权限,请求失败!");
|
|
return false;
|
|
return false;
|
|
@ -206,7 +207,7 @@ public class GatewayProcessor implements Processor {
|
|
return appApi;
|
|
return appApi;
|
|
}
|
|
}
|
|
|
|
|
|
HTTPResponse response = HttpClientKit.get("http://192.168.1.221:10000/api/v1.0/admin/appApi/search?filters=methodName%3D" + api + "&size=15&page=1");
|
|
|
|
|
|
HTTPResponse response = HttpClientKit.get(agUrl + "/api/v1.0/admin/appApi/search?filters=methodName%3D" + api + "&size=15&page=1");
|
|
if (response.getStatusCode() != 200) {
|
|
if (response.getStatusCode() != 200) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
@ -226,7 +227,7 @@ public class GatewayProcessor implements Processor {
|
|
private String getSecret(String appKey) {
|
|
private String getSecret(String appKey) {
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
//TODO 设置固定的验证入口地址
|
|
//TODO 设置固定的验证入口地址
|
|
HTTPResponse response = HttpClientKit.get("http://192.168.1.221:10000/api/v1.0/admin/apps/" + appKey);
|
|
|
|
|
|
HTTPResponse response = HttpClientKit.get(agUrl + "/api/v1.0/admin/apps/" + appKey);
|
|
if (response.getStatusCode() != 200) {
|
|
if (response.getStatusCode() != 200) {
|
|
System.out.println("获取app的secret请求失败!");
|
|
System.out.println("获取app的secret请求失败!");
|
|
return "";
|
|
return "";
|