Java Code Examples for org.springframework.cloud.gateway.handler.predicate.PredicateDefinition#setName()
The following examples show how to use
org.springframework.cloud.gateway.handler.predicate.PredicateDefinition#setName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RouteController.java From spring-cloud-gateway-nacos with Apache License 2.0 | 6 votes |
private RouteDefinition assembleRouteDefinition(GatewayRouteDefinition gwdefinition) { RouteDefinition definition = new RouteDefinition(); List<PredicateDefinition> pdList=new ArrayList<>(); definition.setId(gwdefinition.getId()); List<GatewayPredicateDefinition> gatewayPredicateDefinitionList=gwdefinition.getPredicates(); for (GatewayPredicateDefinition gpDefinition: gatewayPredicateDefinitionList) { PredicateDefinition predicate = new PredicateDefinition(); predicate.setArgs(gpDefinition.getArgs()); predicate.setName(gpDefinition.getName()); pdList.add(predicate); } definition.setPredicates(pdList); URI uri = UriComponentsBuilder.fromHttpUrl(gwdefinition.getUri()).build().toUri(); definition.setUri(uri); return definition; }
Example 2
Source File: DynamicRouteServiceImpl.java From spring-cloud-gateway-nacos with Apache License 2.0 | 5 votes |
/** * spring: cloud: gateway: routes: #当访问http://localhost:8080/baidu,直接转发到https://www.baidu.com/ - id: baidu_route uri: http://baidu.com:80/ predicates: - Path=/baidu * @param args */ public static void main(String[] args) { GatewayRouteDefinition definition = new GatewayRouteDefinition(); GatewayPredicateDefinition predicate = new GatewayPredicateDefinition(); Map<String, String> predicateParams = new HashMap<>(8); definition.setId("jd_route"); predicate.setName("Path"); predicateParams.put("pattern", "/jd"); predicate.setArgs(predicateParams); definition.setPredicates(Arrays.asList(predicate)); String uri="http://www.jd.com"; //URI uri = UriComponentsBuilder.fromHttpUrl("http://www.baidu.com").build().toUri(); definition.setUri(uri); System.out.println("definition:"+JSON.toJSONString(definition)); RouteDefinition definition1 = new RouteDefinition(); PredicateDefinition predicate1 = new PredicateDefinition(); Map<String, String> predicateParams1 = new HashMap<>(8); definition1.setId("baidu_route"); predicate1.setName("Path"); predicateParams1.put("pattern", "/baidu"); predicate1.setArgs(predicateParams1); definition1.setPredicates(Arrays.asList(predicate1)); URI uri1 = UriComponentsBuilder.fromHttpUrl("http://www.baidu.com").build().toUri(); definition1.setUri(uri1); System.out.println("definition1:"+JSON.toJSONString(definition1)); }
Example 3
Source File: GatewayDiscoveryClientAutoConfiguration.java From spring-cloud-gateway with Apache License 2.0 | 5 votes |
public static List<PredicateDefinition> initPredicates() { ArrayList<PredicateDefinition> definitions = new ArrayList<>(); // TODO: add a predicate that matches the url at /serviceId? // add a predicate that matches the url at /serviceId/** PredicateDefinition predicate = new PredicateDefinition(); predicate.setName(normalizeRoutePredicateName(PathRoutePredicateFactory.class)); predicate.addArg(PATTERN_KEY, "'/'+serviceId+'/**'"); definitions.add(predicate); return definitions; }
Example 4
Source File: DynamicRouteConfigurationService.java From wecube-platform with Apache License 2.0 | 4 votes |
protected void buildRouteDefinition(String context, DynamicRouteItemInfo itemInfo) { RouteDefinition rd = new RouteDefinition(); rd.setId(context + ROUTE_ID_SUFFIX); String urlStr = String.format("%s://%s:%s", itemInfo.getHttpScheme(), itemInfo.getHost(), itemInfo.getPort()); URI uri = UriComponentsBuilder.fromHttpUrl(urlStr).build().toUri(); rd.setUri(uri); PredicateDefinition pd = new PredicateDefinition(); pd.setName("Path"); Map<String, String> predicateParams = new HashMap<>(8); predicateParams.put("pattern", String.format("/%s/**", context)); pd.setArgs(predicateParams); rd.setPredicates(Arrays.asList(pd)); List<FilterDefinition> filters = new ArrayList<>(); FilterDefinition fdDynamicRoute = new FilterDefinition(); fdDynamicRoute.setName("DynamicRoute"); fdDynamicRoute.addArg("enabled", "true"); filters.add(fdDynamicRoute); if (dynamicRouteProperties.isEnableRetry()) { FilterDefinition fdRetry = new FilterDefinition(); fdRetry.setName("ExRetry"); fdRetry.addArg("retries", "10"); fdRetry.addArg("series", "SERVER_ERROR"); // fdRetry.addArg("statuses", "NOT_FOUND"); fdRetry.addArg("methods", "GET,POST,PUT,DELETE"); fdRetry.addArg("exceptions", "java.io.IOException,java.net.ConnectException"); filters.add(fdRetry); } rd.setFilters(filters); add(rd); log.debug("### route added:{} {} {}", itemInfo.getContext(), itemInfo.getHost(), itemInfo.getPort()); }