本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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();
}
示例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);
}
示例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();
}
示例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);
}
}
示例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();
}
示例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;
}
};
}
示例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));
}
示例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));
}