当前位置: 首页>>代码示例>>Java>>正文


Java Route类代码示例

本文整理汇总了Java中org.springframework.cloud.netflix.zuul.filters.Route的典型用法代码示例。如果您正苦于以下问题:Java Route类的具体用法?Java Route怎么用?Java Route使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Route类属于org.springframework.cloud.netflix.zuul.filters包,在下文中一共展示了Route类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldFilter

import org.springframework.cloud.netflix.zuul.filters.Route; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:oktadeveloper,项目名称:jhipster-microservices-example,代码行数:21,代码来源:AccessControlFilter.java

示例2: getRoutes

import org.springframework.cloud.netflix.zuul.filters.Route; //导入依赖的package包/类
@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);
}
 
开发者ID:oktadeveloper,项目名称:jhipster-microservices-example,代码行数:23,代码来源:RoutesResource.java

示例3: shouldFilter

import org.springframework.cloud.netflix.zuul.filters.Route; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:oktadeveloper,项目名称:jhipster-microservices-example,代码行数:23,代码来源:AccessControlFilter.java

示例4: activeRoutes

import org.springframework.cloud.netflix.zuul.filters.Route; //导入依赖的package包/类
/**
 * 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());
        List<ServiceInstance> serviceInstances = discoveryClient.getInstances(route.getId());
        routeVM.setServiceInstances(serviceInstances);
        routeVM.setServiceInstancesStatus(receiveServiceStatus(serviceInstances));
        routeVM.setServiceMetadata(extractServiceMetaData(routeVM));
        routeVMs.add(routeVM);
    });
    return new ResponseEntity<>(routeVMs, HttpStatus.OK);
}
 
开发者ID:xm-online,项目名称:xm-gate,代码行数:23,代码来源:GatewayResource.java

示例5: shouldFilter

import org.springframework.cloud.netflix.zuul.filters.Route; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:xm-online,项目名称:xm-gate,代码行数:21,代码来源:AccessControlFilter.java

示例6: activeRoutes

import org.springframework.cloud.netflix.zuul.filters.Route; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:xetys,项目名称:jhipster-ribbon-hystrix,代码行数:22,代码来源:GatewayResource.java

示例7: shouldFilter

import org.springframework.cloud.netflix.zuul.filters.Route; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:xetys,项目名称:jhipster-ribbon-hystrix,代码行数:23,代码来源:AccessControlFilter.java

示例8: key

import org.springframework.cloud.netflix.zuul.filters.Route; //导入依赖的package包/类
@Override
public String key(final HttpServletRequest request, final Route route, final Policy policy) {
    final List<Type> types = policy.getType();
    final StringJoiner joiner = new StringJoiner(":");
    joiner.add(properties.getKeyPrefix());
    if (route != null) {
        joiner.add(route.getId());
    }
    if (!types.isEmpty()) {
        if (types.contains(Type.URL) && route != null) {
            joiner.add(route.getPath());
        }
        if (types.contains(Type.ORIGIN)) {
            joiner.add(getRemoteAddress(request));
        }
        if (types.contains(Type.USER)) {
            joiner.add(request.getRemoteUser() != null ? request.getRemoteUser() : ANONYMOUS_USER);
        }
    }
    return joiner.toString();
}
 
开发者ID:marcosbarbero,项目名称:spring-cloud-zuul-ratelimit,代码行数:22,代码来源:DefaultRateLimitKeyGenerator.java

示例9: activeRoutes

import org.springframework.cloud.netflix.zuul.filters.Route; //导入依赖的package包/类
/**
 * 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<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);
}
 
开发者ID:axel-halin,项目名称:Thesis-JHipster,代码行数:22,代码来源:_GatewayResource.java

示例10: getRestoredPath

import org.springframework.cloud.netflix.zuul.filters.Route; //导入依赖的package包/类
private String getRestoredPath(ZuulProperties zuulProperties, Route route,
		UriComponents redirectedUriComps) {
	StringBuilder path = new StringBuilder();
	String redirectedPathWithoutGlobal = downstreamHasGlobalPrefix(zuulProperties)
			? redirectedUriComps.getPath()
					.substring(("/" + zuulProperties.getPrefix()).length())
			: redirectedUriComps.getPath();

	if (downstreamHasGlobalPrefix(zuulProperties)) {
		path.append("/" + zuulProperties.getPrefix());
	}
	else {
		path.append(zuulHasGlobalPrefix(zuulProperties)
				? "/" + zuulProperties.getPrefix() : "");
	}

	path.append(downstreamHasRoutePrefix(route) ? "" : "/" + route.getPrefix())
			.append(redirectedPathWithoutGlobal);

	return path.toString();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:22,代码来源:LocationRewriteFilter.java

示例11: addProxyPrefix

import org.springframework.cloud.netflix.zuul.filters.Route; //导入依赖的package包/类
private void addProxyPrefix(RequestContext ctx, Route route) {
	String forwardedPrefix = ctx.getRequest().getHeader(X_FORWARDED_PREFIX_HEADER);
	String contextPath = ctx.getRequest().getContextPath();
	String prefix = StringUtils.hasLength(forwardedPrefix) ? forwardedPrefix
			: (StringUtils.hasLength(contextPath) ? contextPath : null);
	if (StringUtils.hasText(route.getPrefix())) {
		StringBuilder newPrefixBuilder = new StringBuilder();
		if (prefix != null) {
			if (prefix.endsWith("/") && route.getPrefix().startsWith("/")) {
				newPrefixBuilder.append(prefix, 0, prefix.length() - 1);
			}
			else {
				newPrefixBuilder.append(prefix);
			}
		}
		newPrefixBuilder.append(route.getPrefix());
		prefix = newPrefixBuilder.toString();
	}
	if (prefix != null) {
		ctx.addZuulRequestHeader(X_FORWARDED_PREFIX_HEADER, prefix);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:23,代码来源:PreDecorationFilter.java

示例12: ignoredPathsShouldNotReturnAHandler

import org.springframework.cloud.netflix.zuul.filters.Route; //导入依赖的package包/类
@Test
public void ignoredPathsShouldNotReturnAHandler() throws Exception {
	assertThat(mappingWithIgnoredPathsAndRoutes(Arrays.asList("/p1/**"),
			new Route("p1", "/p1/**", "p1", "", null, null))
					.getHandler(requestForAPath("/p1"))).isNull();

	assertThat(mappingWithIgnoredPathsAndRoutes(Arrays.asList("/p1/**/p3/"),
			new Route("p1", "/p1/**/p3", "p1", "", null, null))
			.getHandler(requestForAPath("/p1/p2/p3"))).isNull();

	assertThat(mappingWithIgnoredPathsAndRoutes(Arrays.asList("/p1/**/p3/**"),
			new Route("p1", "/p1/**/p3", "p1", "", null, null))
			.getHandler(requestForAPath("/p1/p2/p3"))).isNull();

	assertThat(mappingWithIgnoredPathsAndRoutes(Arrays.asList("/p1/**/p4/"),
			new Route("p1", "/p1/**/p4/", "p1", "", null, null))
			.getHandler(requestForAPath("/p1/p2/p3/p4"))).isNull();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:19,代码来源:ZuulHandlerMappingTests.java

示例13: setUp

import org.springframework.cloud.netflix.zuul.filters.Route; //导入依赖的package包/类
@Before
public void setUp() {
	this.locator = new RouteLocator() {
		@Override
		public Collection<String> getIgnoredPaths() {
			return null;
		}

		@Override
		public List<Route> getRoutes() {
			List<Route> routes = new ArrayList<>();
			routes.add(new Route("foo", "foopath", "foolocation", null, true, Collections.EMPTY_SET));
			routes.add(new Route("bar", "barpath", "barlocation", "/bar-prefix", true, Collections.EMPTY_SET));
			return routes;
		}

		@Override
		public Route getMatchingRoute(String path) {
			return null;
		}
	};
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:23,代码来源:RoutesEndpointTests.java

示例14: setUp

import org.springframework.cloud.netflix.zuul.filters.Route; //导入依赖的package包/类
@Before
public void setUp() {
	this.locator = new RouteLocator() {
		@Override
		public Collection<String> getIgnoredPaths() {
			return null;
		}

		@Override
		public List<Route> getRoutes() {
			List<Route> routes = new ArrayList<>();
			routes.add(new Route("foo", "foopath", "foolocation", null, true, Collections.EMPTY_SET));
			routes.add(new Route("bar", "barpath", "barlocation", "bar-prefix", true, Collections.EMPTY_SET));
			return routes;
		}

		@Override
		public Route getMatchingRoute(String path) {
			return null;
		}
	};
	endpoint = spy(new RoutesEndpoint(locator));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:24,代码来源:RoutesEndpointDetailsTests.java

示例15: shouldAddBackGlobalPrefixIfPresent

import org.springframework.cloud.netflix.zuul.filters.Route; //导入依赖的package包/类
@Test
public void shouldAddBackGlobalPrefixIfPresent() {
	RequestContext context = RequestContext.getCurrentContext();
	ZuulProperties zuulProperties = new ZuulProperties();
	zuulProperties.setPrefix("global");
	zuulProperties.setStripPrefix(true);
	LocationRewriteFilter filter = setFilterUpWith(context, zuulProperties,
			new Route("service1", "/something/redirectingUri", "service1", "prefix",
					false, Collections.EMPTY_SET, true),
			"/global/prefix/redirectingUri",
			"/something/redirectedUri;someparam?param1=abc");
	filter.run();
	assertThat(getLocationHeader(context).second()).isEqualTo(String.format(
			"%s/global/prefix/something/redirectedUri;someparam?param1=abc",
			ZUUL_BASE_URL));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:17,代码来源:LocationRewriteFilterTests.java


注:本文中的org.springframework.cloud.netflix.zuul.filters.Route类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。