瀏覽代碼

网关调用-2

huangzhiyong 8 年之前
父節點
當前提交
c6aa8cbcae

+ 1 - 1
hos-camel/src/main/java/gateway/processor/GatewayProcessor.java

@ -124,7 +124,7 @@ public class GatewayProcessor implements Processor {
        HTTPResponse response = HttpClientKit.get("http://localhost:10000/api/v1.0/admin/appApiAuth?appId=" + params.get("appKey") + "&apiName="+ apiMap.get("api"));
        if (response.getStatusCode() != 200) {
            System.out.println("请求失败!");
            System.out.println("验证API权限,请求失败!");
            return false;
        }

+ 5 - 5
hos-camel2/src/main/java/camel/gateway/processor/GatewayProcessor.java

@ -34,7 +34,7 @@ public class GatewayProcessor implements Processor {
    public String secret(@Body String body, Exchange exchange) throws IOException, ParseException {
        System.out.println(body);
        String appKey = exchange.getIn().getHeaders().get("appKey").toString();
        return "restlet:http://sdw2:10000/api/v1.0/admin/apps/" + appKey;
        return "restlet:http://192.168.1.221:10000/api/v1.0/admin/apps/" + appKey;
    }
    public String route(Exchange exchange) throws IOException, ParseException {
@ -127,9 +127,9 @@ public class GatewayProcessor implements Processor {
    private boolean checkAuthorized(Map<String, Object> params) {
        ObjectMapper objectMapper = new ObjectMapper();
        //TODO 设置固定的验证入口地址
        HTTPResponse response = HttpClientKit.get("http://192.168.131.109:10000/api/v1.0/admin/appApiAuth?appId=" + params.get("appKey") + "&apiName=" + params.get("api"));
        HTTPResponse response = HttpClientKit.get("http://localhost:10000/api/v1.0/admin/appApiAuth?appId=" + params.get("appKey") + "&apiName=" + params.get("api"));
        if (response.getStatusCode() != 200) {
            System.out.println("请求失败!");
            System.out.println("验证API权限,请求失败!");
            return false;
        }
@ -225,9 +225,9 @@ public class GatewayProcessor implements Processor {
    private String getSecret(String appKey) {
        ObjectMapper objectMapper = new ObjectMapper();
        //TODO 设置固定的验证入口地址
        HTTPResponse response = HttpClientKit.get("http://192.168.131.109:10000/api/v1.0/admin/apps/" + appKey);
        HTTPResponse response = HttpClientKit.get("http://localhost:10000/api/v1.0/admin/apps/" + appKey);
        if (response.getStatusCode() != 200) {
            System.out.println("请求失败!");
            System.out.println("获取app的secret请求失败!");
            return "";
        }

+ 1 - 1
hos-web-framework/src/main/java/com/yihu/hos/web/framework/util/controller/BaseController.java

@ -145,7 +145,7 @@ public class BaseController extends AbstractController {
            //TODO 设置固定的验证入口地址
        HTTPResponse response = HttpClientKit.post(url,requestParams);
        if (response.getStatusCode() != 200) {
            System.out.println("请求失败!");
            System.out.println("获取应用secret请求失败!");
            return "";
        }

+ 3 - 1
src/main/java/com/yihu/hos/common/CommonPageController.java

@ -129,6 +129,8 @@ public class CommonPageController extends BaseController {
        boolean auth = false;
        String clientId = request.getParameter(ContextAttributes.CLIENTID);
        String token = request.getParameter(ContextAttributes.ACCESSTOKEN);
        String loginName = request.getParameter(ContextAttributes.LOGIN_NAME);
        //通过clientId和 oauth2 code 获取token
//        String token = getToken(clientId, code);
        if (!StringUtils.isEmpty(token)) {
@ -137,7 +139,7 @@ public class CommonPageController extends BaseController {
            if (succ) {
                //TODO 根据token和clientId 获取用户信息
                SystemUser userInfo = new SystemUser();
                userInfo.setLoginCode("admin");
                userInfo.setLoginCode(loginName);
                userInfo.setUserName("管理员");
                session.setAttribute("userInfo", userInfo);
                try {

+ 1 - 1
src/main/java/com/yihu/hos/common/constants/ContextAttributes.java

@ -17,5 +17,5 @@ public interface ContextAttributes {
    //集成参数
    String ACCESSTOKEN = "accessToken";
    String CLIENTID = "clientId";
    String LOGIN_NAME = "loginName";
}

+ 4 - 1
src/main/resources/application.yml

@ -67,6 +67,7 @@ service-gateway:
spring:
  profiles: test
  administrators: jkzl
  clientId: 0e3DIdNaQ2
  #SAAS管理员账号,暂时配置在此处
  datasource:
      driverClassName: com.mysql.jdbc.Driver
@ -111,4 +112,6 @@ hos:
  mysql:
    filePath: /usr/local/esb/esb.sql   #租户基础表 sql文件位置
service-gateway:
  portalUrl: http://192.168.131.109:444/api/v1.0/portal
  portalUrl: http://192.168.131.109:444/api/v1.0/portal
  adminUrl: http://192.168.131.109:10000/api/v1.0/admin
  url: http://192.168.131.109:9999/api