diff --git a/usergw-service/src/main/java/cn/ecpark/service/usergw/config/ConfigGateway.java b/usergw-service/src/main/java/cn/ecpark/service/usergw/config/ConfigGateway.java index 296de96..1912550 100644 --- a/usergw-service/src/main/java/cn/ecpark/service/usergw/config/ConfigGateway.java +++ b/usergw-service/src/main/java/cn/ecpark/service/usergw/config/ConfigGateway.java @@ -13,8 +13,10 @@ import org.apache.dubbo.config.ReferenceConfig; import org.apache.dubbo.rpc.service.GenericService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.cloud.gateway.filter.FilterDefinition; import org.springframework.cloud.gateway.filter.NettyWriteResponseFilter; +import org.springframework.cloud.gateway.handler.RoutePredicateHandlerMapping; import org.springframework.cloud.gateway.handler.predicate.PredicateDefinition; import org.springframework.cloud.gateway.route.RouteDefinition; import org.springframework.cloud.gateway.route.RouteDefinitionLocator; @@ -25,6 +27,7 @@ import org.springframework.stereotype.Controller; import org.springframework.util.ReflectionUtils; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.reactive.config.WebFluxConfigurationSupport; +import org.springframework.web.reactive.result.method.AbstractHandlerMethodMapping; import org.springframework.web.reactive.result.method.RequestMappingInfo; import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping; import org.yaml.snakeyaml.Yaml; @@ -53,9 +56,9 @@ public class ConfigGateway implements RouteDefinitionLocator { private Http2Dubbo http2Dubbo; @Override - public Flux getRouteDefinitions() { + public Flux getRouteDefinitions() { // WebFluxConfigurationSupport a; - + Object inputStream = null; String[] gatewayConfigPathList = { "gateway.yml", "gateway.yaml", "Gateway.yml", "Gateway.yaml" }; for (String gatewayConfigPath : gatewayConfigPathList) { @@ -164,23 +167,28 @@ public class ConfigGateway implements RouteDefinitionLocator { return null; } - private void createHttp2Dubbo(Map configDubbo) { + private void createHttp2Dubbo(Map configDubbo) { try { - RequestMappingHandlerMapping requestMapping = (RequestMappingHandlerMapping) applicationContext.getBean("requestMappingHandlerMapping"); - - // Method targetMethod = ReflectionUtils.findMethod(Http2Dubbo.class, "H2DTest", HttpServerRequest.class, HttpServerResponse.class); // 找到处理该路由的方法 - requestMapping.registerMapping(RequestMappingInfo.paths("/test/xixi").methods(RequestMethod.POST).build(), - http2Dubbo, Http2Dubbo.class.getDeclaredMethod("H2DTest")); - - // 引用远程服务 - // try { - // ReferenceConfig reference = new ReferenceConfig(); // 该实例很重量,里面封装了所有与注册中心及服务提供方连接,请缓存 + + // RequestMappingHandlerMapping requestMapping = (RequestMappingHandlerMapping) applicationContext + // .getBean("requestMappingHandlerMapping"); + + // // Method targetMethod = ReflectionUtils.findMethod(Http2Dubbo.class, "H2DTest", + // // HttpServerRequest.class, HttpServerResponse.class); // 找到处理该路由的方法 - // reference.setInterface("com.xxx.XxxService"); // 弱类型接口名 - // reference.setVersion("2.0.0"); - // reference.setGeneric(true); // 声明为泛化接口 - // GenericService gs = reference.get(); + // requestMapping.registerMapping(RequestMappingInfo.paths("/test/xixi").methods(RequestMethod.POST).build(), + // http2Dubbo, Http2Dubbo.class.getDeclaredMethod("H2DTest")); + + // 引用远程服务 + // try { + // ReferenceConfig reference = new + // ReferenceConfig(); // 该实例很重量,里面封装了所有与注册中心及服务提供方连接,请缓存 + + // reference.setInterface("com.xxx.XxxService"); // 弱类型接口名 + // reference.setVersion("2.0.0"); + // reference.setGeneric(true); // 声明为泛化接口 + // GenericService gs = reference.get(); } catch (Exception e) { // TODO: 任何错误都直接终止退出 diff --git a/usergw-service/src/main/java/cn/ecpark/service/usergw/impl/http/Http2Dubbo.java b/usergw-service/src/main/java/cn/ecpark/service/usergw/impl/http/Http2Dubbo.java index 3e74c43..9f5b93c 100644 --- a/usergw-service/src/main/java/cn/ecpark/service/usergw/impl/http/Http2Dubbo.java +++ b/usergw-service/src/main/java/cn/ecpark/service/usergw/impl/http/Http2Dubbo.java @@ -3,6 +3,7 @@ package cn.ecpark.service.usergw.impl.http; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; @@ -10,6 +11,7 @@ import org.springframework.web.bind.annotation.RestController; * Http2Dubbo */ @Controller +@RestController public class Http2Dubbo { @@ -17,7 +19,13 @@ public class Http2Dubbo { public String H2DTest() { //Do clever stuff here - return "123"; + return "H2DTest"; // return new ResponseEntity<>(HttpStatus.OK); } + + + @RequestMapping("/test/fuck") + public String fuck() { + return "fuck"; + } } \ No newline at end of file