org.springframework.cloud.netflix.zuul.filters.Route Java Examples
The following examples show how to use
org.springframework.cloud.netflix.zuul.filters.Route.
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: RoutesResource.java From jhipster-microservices-example with Apache License 2.0 | 6 votes |
@GetMapping("/routes") @Timed public ResponseEntity<List<RouteVM>> getRoutes() { List<Route> routes = routeLocator.getRoutes(); Map<String, RouteVM> routeVMs = new HashMap<>(); routeVMs.put(null, registryRoute()); routes.forEach(route -> { RouteVM routeVM = new RouteVM(); routeVM.setPath(route.getFullPath()); routeVM.setPrefix(route.getPrefix()); routeVM.setAppName(extractName(route.getId())); routeVM.setServiceId(route.getId()); routeVM.setServiceInstances(discoveryClient.getInstances(route.getId())); routeVMs.put(route.getId(), routeVM); }); fillStatus(routeVMs); return new ResponseEntity<>(new ArrayList<>(routeVMs.values()), HttpStatus.OK); }
Example #2
Source File: _AccessControlFilter.java From jhipster-ribbon-hystrix with GNU General Public License v3.0 | 6 votes |
/** * Filter requests on endpoints that are not in the list of authorized microservices endpoints. */ @Override public boolean shouldFilter() { String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI(); // If the request Uri does not start with the path of the authorized endpoints, we block the request for (Route route : routeLocator.getRoutes()) { String serviceUrl = route.getFullPath(); String serviceName = route.getId(); // If this route correspond to the current request URI // We do a substring to remove the "**" at the end of the route URL if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) { if (isAuthorizedRequest(serviceUrl, serviceName, requestUri)) { return false; } } } return true; }
Example #3
Source File: _GatewayResource.java From jhipster-ribbon-hystrix with GNU General Public License v3.0 | 6 votes |
/** * GET /routes : get the active routes. * * @return the ResponseEntity with status 200 (OK) and with body the list of routes */ @RequestMapping(value = "/routes", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<List<RouteDTO>> activeRoutes() { List<Route> routes = routeLocator.getRoutes(); List<RouteDTO> routeDTOs = new ArrayList<>(); routes.forEach(route -> { RouteDTO routeDTO = new RouteDTO(); routeDTO.setPath(route.getFullPath()); routeDTO.setServiceId(route.getId()); routeDTO.setServiceInstances(discoveryClient.getInstances(route.getId())); routeDTOs.add(routeDTO); }); return new ResponseEntity<>(routeDTOs, HttpStatus.OK); }
Example #4
Source File: AccessControlFilter.java From e-commerce-microservice with Apache License 2.0 | 6 votes |
/** * Filter requests on endpoints that are not in the list of authorized microservices endpoints. */ @Override public boolean shouldFilter() { String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI(); String contextPath = RequestContext.getCurrentContext().getRequest().getContextPath(); // If the request Uri does not start with the path of the authorized endpoints, we block the request for (Route route : routeLocator.getRoutes()) { String serviceUrl = contextPath + route.getFullPath(); String serviceName = route.getId(); // If this route correspond to the current request URI // We do a substring to remove the "**" at the end of the route URL if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) { return !isAuthorizedRequest(serviceUrl, serviceName, requestUri); } } return true; }
Example #5
Source File: GatewayResource.java From e-commerce-microservice with Apache License 2.0 | 6 votes |
/** * GET /routes : get the active routes. * * @return the ResponseEntity with status 200 (OK) and with body the list of routes */ @GetMapping("/routes") @Timed @Secured(AuthoritiesConstants.ADMIN) public ResponseEntity<List<RouteVM>> activeRoutes() { List<Route> routes = routeLocator.getRoutes(); List<RouteVM> routeVMs = new ArrayList<>(); routes.forEach(route -> { RouteVM routeVM = new RouteVM(); routeVM.setPath(route.getFullPath()); routeVM.setServiceId(route.getId()); routeVM.setServiceInstances(discoveryClient.getInstances(route.getLocation())); routeVMs.add(routeVM); }); return new ResponseEntity<>(routeVMs, HttpStatus.OK); }
Example #6
Source File: AbstractRateLimitFilter.java From spring-cloud-zuul-ratelimit with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") protected List<Policy> policy(Route route, HttpServletRequest request) { List<Policy> policies = (List<Policy>) RequestContext.getCurrentContext().get(CURRENT_REQUEST_POLICY); if (policies != null) { return policies; } String routeId = route != null ? route.getId() : null; RequestContext.getCurrentContext().put(ALREADY_LIMITED, false); policies = properties.getPolicies(routeId).stream() .filter(policy -> applyPolicy(request, route, policy)) .collect(Collectors.toList()); addObjectToCurrentRequestContext(CURRENT_REQUEST_POLICY, policies); return policies; }
Example #7
Source File: AccessControlFilter.java From jhipster-ribbon-hystrix with GNU General Public License v3.0 | 6 votes |
/** * Filter requests on endpoints that are not in the list of authorized microservices endpoints. */ @Override public boolean shouldFilter() { String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI(); // If the request Uri does not start with the path of the authorized endpoints, we block the request for (Route route : routeLocator.getRoutes()) { String serviceUrl = route.getFullPath(); String serviceName = route.getId(); // If this route correspond to the current request URI // We do a substring to remove the "**" at the end of the route URL if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) { if (isAuthorizedRequest(serviceUrl, serviceName, requestUri)) { return false; } } } return true; }
Example #8
Source File: GatewayResource.java From jhipster-ribbon-hystrix with GNU General Public License v3.0 | 6 votes |
/** * GET /routes : get the active routes. * * @return the ResponseEntity with status 200 (OK) and with body the list of routes */ @RequestMapping(value = "/routes", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<List<RouteDTO>> activeRoutes() { List<Route> routes = routeLocator.getRoutes(); List<RouteDTO> routeDTOs = new ArrayList<>(); routes.forEach(route -> { RouteDTO routeDTO = new RouteDTO(); routeDTO.setPath(route.getFullPath()); routeDTO.setServiceId(route.getId()); routeDTO.setServiceInstances(discoveryClient.getInstances(route.getId())); routeDTOs.add(routeDTO); }); return new ResponseEntity<>(routeDTOs, HttpStatus.OK); }
Example #9
Source File: RateLimitPreFilterTest.java From spring-cloud-zuul-ratelimit with Apache License 2.0 | 6 votes |
@BeforeEach public void setUp() { MockitoAnnotations.initMocks(this); CounterFactory.initialize(new EmptyCounterFactory()); when(httpServletRequest.getContextPath()).thenReturn(""); when(httpServletRequest.getRequestURI()).thenReturn("/servicea/test"); when(httpServletRequest.getRemoteAddr()).thenReturn("127.0.0.1"); RequestContext requestContext = new RequestContext(); requestContext.setRequest(httpServletRequest); requestContext.setResponse(httpServletResponse); RequestContext.testSetCurrentContext(requestContext); RequestContextHolder.setRequestAttributes(requestAttributes); rateLimitProperties = new RateLimitProperties(); rateLimitProperties.setAddResponseHeaders(false); UrlPathHelper urlPathHelper = new UrlPathHelper(); RateLimitUtils rateLimitUtils = new DefaultRateLimitUtils(rateLimitProperties); Route route = new Route("servicea", "/test", "servicea", "/servicea", null, Collections.emptySet()); TestRouteLocator routeLocator = new TestRouteLocator(Collections.emptyList(), Lists.newArrayList(route)); target = new RateLimitPreFilter(rateLimitProperties, routeLocator, urlPathHelper, rateLimiter, rateLimitKeyGenerator, rateLimitUtils, eventPublisher); }
Example #10
Source File: RoutesResource.java From jhipster-registry with Apache License 2.0 | 6 votes |
@GetMapping("/routes") public ResponseEntity<List<RouteVM>> getRoutes() { List<Route> routes = routeLocator.getRoutes(); Map<String, RouteVM> routeVMs = new HashMap<>(); routeVMs.put(null, registryRoute()); routes.stream() .map(route -> { RouteVM routeVM = new RouteVM(); routeVM.setPath(route.getFullPath()); routeVM.setPrefix(route.getPrefix()); routeVM.setAppName(extractName(route.getId())); routeVM.setServiceId(route.getId()); routeVM.setServiceInstances(discoveryClient.getInstances(route.getId())); return routeVM; }) // we don't need the service sets. They come in as of eureka.fetch-registry=true, which is needed for requests against UAA .filter(routeVM -> routeVM.getServiceInstances() == null || routeVM.getServiceInstances().isEmpty()) .forEach(route -> routeVMs.put(route.getServiceId(), route)); fillStatus(routeVMs); return new ResponseEntity<>(new ArrayList<>(routeVMs.values()), HttpStatus.OK); }
Example #11
Source File: AccessControlFilter.java From okta-jhipster-microservices-oauth-example with Apache License 2.0 | 6 votes |
/** * Filter requests on endpoints that are not in the list of authorized microservices endpoints. */ @Override public boolean shouldFilter() { String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI(); String contextPath = RequestContext.getCurrentContext().getRequest().getContextPath(); // If the request Uri does not start with the path of the authorized endpoints, we block the request for (Route route : routeLocator.getRoutes()) { String serviceUrl = contextPath + route.getFullPath(); String serviceName = route.getId(); // If this route correspond to the current request URI // We do a substring to remove the "**" at the end of the route URL if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) { return !isAuthorizedRequest(serviceUrl, serviceName, requestUri); } } return true; }
Example #12
Source File: GatewayResource.java From okta-jhipster-microservices-oauth-example with Apache License 2.0 | 6 votes |
/** * GET /routes : get the active routes. * * @return the ResponseEntity with status 200 (OK) and with body the list of routes */ @GetMapping("/routes") @Timed @Secured(AuthoritiesConstants.ADMIN) public ResponseEntity<List<RouteVM>> activeRoutes() { List<Route> routes = routeLocator.getRoutes(); List<RouteVM> routeVMs = new ArrayList<>(); routes.forEach(route -> { RouteVM routeVM = new RouteVM(); routeVM.setPath(route.getFullPath()); routeVM.setServiceId(route.getId()); routeVM.setServiceInstances(discoveryClient.getInstances(route.getLocation())); routeVMs.add(routeVM); }); return new ResponseEntity<>(routeVMs, HttpStatus.OK); }
Example #13
Source File: AccessControlFilter.java From cubeai with Apache License 2.0 | 6 votes |
/** * Filter requests on endpoints that are not in the list of authorized microservices endpoints. */ @Override public boolean shouldFilter() { String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI(); // 使用ng2-file-upload上传文件时,如果通过zuul路由,URL前面需要加'zuul'前缀 if (requestUri.startsWith("/zuul")) { requestUri = requestUri.substring(5); } // If the request Uri does not start with the path of the authorized endpoints, we block the request for (Route route : routeLocator.getRoutes()) { String serviceUrl = route.getFullPath(); String serviceName = route.getId(); // If this route correspond to the current request URI // We do a substring to remove the "**" at the end of the route URL if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) { return !isAuthorizedRequest(serviceUrl, serviceName, requestUri); } } return true; }
Example #14
Source File: AccessControlFilter.java From jhipster-registry with Apache License 2.0 | 6 votes |
/** * Filter requests on endpoints that are not in the list of authorized microservices endpoints. */ @Override public boolean shouldFilter() { String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI(); String contextPath = RequestContext.getCurrentContext().getRequest().getContextPath(); // If the request Uri does not start with the path of the authorized endpoints, we block the request for (Route route : routeLocator.getRoutes()) { String serviceUrl = contextPath + route.getFullPath(); String serviceName = route.getId(); // If this route correspond to the current request URI // We do a substring to remove the "**" at the end of the route URL if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) { return !isAuthorizedRequest(serviceUrl, serviceName, requestUri); } } return true; }
Example #15
Source File: AccessControlFilter.java From jhipster-microservices-example with Apache License 2.0 | 6 votes |
/** * Filter requests on endpoints that are not in the list of authorized microservices endpoints. */ @Override public boolean shouldFilter() { String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI(); // If the request Uri does not start with the path of the authorized endpoints, we block the request for (Route route : routeLocator.getRoutes()) { String serviceUrl = route.getFullPath(); String serviceName = route.getId(); // If this route correspond to the current request URI // We do a substring to remove the "**" at the end of the route URL if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) { return !isAuthorizedRequest(serviceUrl, serviceName, requestUri); } } return true; }
Example #16
Source File: AccessControlFilter.java From java-microservices-examples with Apache License 2.0 | 6 votes |
/** * Filter requests on endpoints that are not in the list of authorized microservices endpoints. */ @Override public boolean shouldFilter() { String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI(); String contextPath = RequestContext.getCurrentContext().getRequest().getContextPath(); // If the request Uri does not start with the path of the authorized endpoints, we block the request for (Route route : routeLocator.getRoutes()) { String serviceUrl = contextPath + route.getFullPath(); String serviceName = route.getId(); // If this route correspond to the current request URI // We do a substring to remove the "**" at the end of the route URL if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) { return !isAuthorizedRequest(serviceUrl, serviceName, requestUri); } } return true; }
Example #17
Source File: AccessControlFilter.java From tutorials with MIT License | 6 votes |
/** * Filter requests on endpoints that are not in the list of authorized microservices endpoints. */ @Override public boolean shouldFilter() { String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI(); // If the request Uri does not start with the path of the authorized endpoints, we block the request for (Route route : routeLocator.getRoutes()) { String serviceUrl = route.getFullPath(); String serviceName = route.getId(); // If this route correspond to the current request URI // We do a substring to remove the "**" at the end of the route URL if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) { return !isAuthorizedRequest(serviceUrl, serviceName, requestUri); } } return true; }
Example #18
Source File: AccessControlFilter.java From jhipster-microservices-example with Apache License 2.0 | 6 votes |
/** * Filter requests on endpoints that are not in the list of authorized microservices endpoints. */ @Override public boolean shouldFilter() { String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI(); log.debug(requestUri); // If the request Uri does not start with the path of the authorized endpoints, we block the request for (Route route : routeLocator.getRoutes()) { String serviceUrl = route.getFullPath(); String serviceName = route.getId(); // If this route correspond to the current request URI // We do a substring to remove the "**" at the end of the route URL if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) { return !isAuthorizedRequest(serviceUrl, serviceName, requestUri); } } return true; }
Example #19
Source File: AccessControlFilter.java From flair-registry with Apache License 2.0 | 6 votes |
/** * Filter requests on endpoints that are not in the list of authorized microservices endpoints. */ @Override public boolean shouldFilter() { String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI(); log.debug(requestUri); // If the request Uri does not start with the path of the authorized endpoints, we block the request for (Route route : routeLocator.getRoutes()) { String serviceUrl = route.getFullPath(); String serviceName = route.getId(); // If this route correspond to the current request URI // We do a substring to remove the "**" at the end of the route URL if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) { return !isAuthorizedRequest(serviceUrl, serviceName, requestUri); } } return true; }
Example #20
Source File: GatewayResource.java From tutorials with MIT License | 6 votes |
/** * GET /routes : get the active routes. * * @return the ResponseEntity with status 200 (OK) and with body the list of routes */ @GetMapping("/routes") @Timed @Secured(AuthoritiesConstants.ADMIN) public ResponseEntity<List<RouteVM>> activeRoutes() { List<Route> routes = routeLocator.getRoutes(); List<RouteVM> routeVMs = new ArrayList<>(); routes.forEach(route -> { RouteVM routeVM = new RouteVM(); routeVM.setPath(route.getFullPath()); routeVM.setServiceId(route.getId()); routeVM.setServiceInstances(discoveryClient.getInstances(route.getLocation())); routeVMs.add(routeVM); }); return new ResponseEntity<>(routeVMs, HttpStatus.OK); }
Example #21
Source File: AccessControlFilter.java From tutorials with MIT License | 6 votes |
/** * Filter requests on endpoints that are not in the list of authorized microservices endpoints. */ @Override public boolean shouldFilter() { String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI(); String contextPath = RequestContext.getCurrentContext().getRequest().getContextPath(); // If the request Uri does not start with the path of the authorized endpoints, we block the request for (Route route : routeLocator.getRoutes()) { String serviceUrl = contextPath + route.getFullPath(); String serviceName = route.getId(); // If this route correspond to the current request URI // We do a substring to remove the "**" at the end of the route URL if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) { return !isAuthorizedRequest(serviceUrl, serviceName, requestUri); } } return true; }
Example #22
Source File: RateLimitPostFilter.java From spring-cloud-zuul-ratelimit with Apache License 2.0 | 5 votes |
@Override public Object run() { RequestContext ctx = RequestContext.getCurrentContext(); HttpServletRequest request = ctx.getRequest(); Route route = route(request); policy(route, request).forEach(policy -> { long requestTime = System.currentTimeMillis() - getRequestStartTime(); String key = rateLimitKeyGenerator.key(request, route, policy); rateLimiter.consume(policy, key, requestTime > 0 ? requestTime : 1); }); return null; }
Example #23
Source File: AbstractRateLimitFilter.java From spring-cloud-zuul-ratelimit with Apache License 2.0 | 5 votes |
private boolean applyPolicy(HttpServletRequest request, Route route, Policy policy) { List<MatchType> types = policy.getType(); boolean isAlreadyLimited = (boolean) RequestContext.getCurrentContext().get(ALREADY_LIMITED); if (policy.isBreakOnMatch() && !isAlreadyLimited && types.stream().allMatch(type -> type.apply(request, route, rateLimitUtils))) { RequestContext.getCurrentContext().put(ALREADY_LIMITED, true); } return (types.isEmpty() || types.stream().allMatch(type -> type.apply(request, route, rateLimitUtils))) && !isAlreadyLimited; }
Example #24
Source File: GatewayResource.java From tutorials with MIT License | 5 votes |
/** * GET /routes : get the active routes. * * @return the ResponseEntity with status 200 (OK) and with body the list of routes */ @GetMapping("/routes") @Timed public ResponseEntity<List<RouteVM>> activeRoutes() { List<Route> routes = routeLocator.getRoutes(); List<RouteVM> routeVMs = new ArrayList<>(); routes.forEach(route -> { RouteVM routeVM = new RouteVM(); routeVM.setPath(route.getFullPath()); routeVM.setServiceId(route.getId()); routeVM.setServiceInstances(discoveryClient.getInstances(route.getId())); routeVMs.add(routeVM); }); return new ResponseEntity<>(routeVMs, HttpStatus.OK); }
Example #25
Source File: GatewaySwaggerResourcesProvider.java From tutorials with MIT License | 5 votes |
@Override public List<SwaggerResource> get() { List<SwaggerResource> resources = new ArrayList<>(); //Add the default swagger resource that correspond to the gateway's own swagger doc resources.add(swaggerResource("default", "/v2/api-docs")); //Add the registered microservices swagger docs as additional swagger resources List<Route> routes = routeLocator.getRoutes(); routes.forEach(route -> { resources.add(swaggerResource(route.getId(), route.getFullPath().replace("**", "v2/api-docs"))); }); return resources; }
Example #26
Source File: HaloDocsController.java From halo-docs with Apache License 2.0 | 5 votes |
@GetMapping("/docsMeteData") public List<DocsResource> addUser() { List<DocsResource> resources = new ArrayList<DocsResource>(); List<Route> routes = routeLocator.getRoutes(); //在这里遍历的时候,可以排除掉敏感微服务的路由 routes.forEach(route -> resources.add(docsResource(route.getId(), route.getFullPath().replace("**", "docs")))); return resources; }
Example #27
Source File: RegistrySwaggerResourcesProvider.java From jhipster-registry with Apache License 2.0 | 5 votes |
@Override public List<SwaggerResource> get() { List<SwaggerResource> resources = new ArrayList<>(); //Add the registry swagger resource that correspond to the jhipster-registry's own swagger doc resources.add(swaggerResource("jhipster-registry", "/v2/api-docs")); //Add the registered microservices swagger docs as additional swagger resources List<Route> routes = routeLocator.getRoutes(); routes.forEach(route -> { resources.add(swaggerResource(route.getId(), route.getFullPath().replace("**", "v2/api-docs"))); }); return resources; }
Example #28
Source File: TestRouteLocator.java From spring-cloud-zuul-ratelimit with Apache License 2.0 | 5 votes |
@Override public Route getMatchingRoute(String path) { return this.routes.stream() .filter(route -> path.startsWith(route.getPrefix())) .findFirst() .orElse(null); }
Example #29
Source File: GatewaySwaggerResourcesProvider.java From jhipster-ribbon-hystrix with GNU General Public License v3.0 | 5 votes |
@Override public List<SwaggerResource> get() { List<SwaggerResource> resources = new ArrayList<>(); //Add the default swagger resource that correspond to the gateway's own swagger doc resources.add(swaggerResource("default", "/v2/api-docs")); //Add the registered microservices swagger docs as additional swagger resources List<Route> routes = routeLocator.getRoutes(); routes.forEach(route -> { resources.add(swaggerResource(route.getId(), route.getFullPath().replace("**", "v2/api-docs"))); }); return resources; }
Example #30
Source File: ProxyRedirectFilter.java From spring-cloud-netflix-zuul-websocket with Apache License 2.0 | 5 votes |
@Override public boolean shouldFilter() { RequestContext ctx = RequestContext.getCurrentContext(); boolean isRedirect = ctx.getResponseStatusCode() == 301 || ctx.getResponseStatusCode() == 302; if (!isRedirect) return false; boolean hasCorrectLocation = false; List<Pair<String, String>> zuulResponseHeaders = ctx.getZuulResponseHeaders(); for (Pair<String, String> zuulResponseHeader : zuulResponseHeaders) { if ("Location".equalsIgnoreCase(zuulResponseHeader.first())) { HttpServletRequest request = ctx.getRequest(); String path = urlPathHelper.getPathWithinApplication(request); Route route = routeLocator.getMatchingRoute(path); UriComponents redirectTo = ServletUriComponentsBuilder .fromHttpUrl(zuulResponseHeader.second()).build(); UriComponents routeLocation = ServletUriComponentsBuilder .fromHttpUrl(route.getLocation()).build(); if (redirectTo.getHost().equalsIgnoreCase(routeLocation.getHost()) && redirectTo.getPort() == routeLocation.getPort()) { String toLocation = ServletUriComponentsBuilder .fromHttpUrl(zuulResponseHeader.second()) .host(request.getServerName()) .port(request.getServerPort()) .replacePath( buildRoutePath(route, zuulResponseHeader.second())) .build().toUriString(); ctx.put(REDIRECT_TO_URL, toLocation); hasCorrectLocation = true; break; } } } return hasCorrectLocation; }