org.springframework.cloud.netflix.zuul.filters.ZuulProperties Java Examples

The following examples show how to use org.springframework.cloud.netflix.zuul.filters.ZuulProperties. 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: DynamicRouteLocator.java    From pig with MIT License 6 votes vote down vote up
/**
 * 重写路由配置
 * <p>
 * 1. properties 配置。
 * 2. eureka 默认配置。
 * 3. DB数据库配置。
 *
 * @return 路由表
 */
@Override
protected LinkedHashMap<String, ZuulProperties.ZuulRoute> locateRoutes() {
    LinkedHashMap<String, ZuulProperties.ZuulRoute> routesMap = new LinkedHashMap<>();
    //读取properties配置、eureka默认配置
    routesMap.putAll(super.locateRoutes());
    log.debug("初始默认的路由配置完成");
    routesMap.putAll(locateRoutesFromDb());
    LinkedHashMap<String, ZuulProperties.ZuulRoute> values = new LinkedHashMap<>();
    for (Map.Entry<String, ZuulProperties.ZuulRoute> entry : routesMap.entrySet()) {
        String path = entry.getKey();
        if (!path.startsWith("/")) {
            path = "/" + path;
        }
        if (StrUtil.isNotBlank(this.properties.getPrefix())) {
            path = this.properties.getPrefix() + path;
            if (!path.startsWith("/")) {
                path = "/" + path;
            }
        }
        values.put(path, entry.getValue());
    }
    return values;
}
 
Example #2
Source File: ApimlRoutingConfig.java    From api-layer with Eclipse Public License 2.0 6 votes vote down vote up
@Bean
@Autowired
public ApimlRouteLocatorStub discoveryClientRouteLocator(DiscoveryClient discovery,
                                                               ZuulProperties zuulProperties,
                                                               ServiceRouteMapper serviceRouteMapper,
                                                               WebSocketProxyServerHandler webSocketProxyServerHandler,
                                                               PageRedirectionFilter pageRedirectionFilter,
                                                         ApplicationRegistry applicationRegistry
                                                         ) {
    List<RoutedServicesUser> routedServicesUsers = new ArrayList<>();
    routedServicesUsers.add(locationFilter());
    routedServicesUsers.add(webSocketProxyServerHandler);
    routedServicesUsers.add(pageRedirectionFilter);
    zuulProperties.setDecodeUrl(false);

    return new ApimlRouteLocatorStub("", discovery, zuulProperties, serviceRouteMapper, routedServicesUsers, applicationRegistry);
}
 
Example #3
Source File: NacosDynRouteLocator.java    From microservices-platform with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, ZuulProperties.ZuulRoute> loadDynamicRoute() {
    Map<String, ZuulRoute> routes = new LinkedHashMap<>();
    if (zuulRouteEntities == null) {
        zuulRouteEntities = getNacosConfig();
    }
    for (ZuulRouteEntity result : zuulRouteEntities) {
        if (StrUtil.isBlank(result.getPath()) || !result.isEnabled()) {
            continue;
        }
        ZuulRoute zuulRoute = new ZuulRoute();
        BeanUtil.copyProperties(result, zuulRoute);
        routes.put(zuulRoute.getPath(), zuulRoute);
    }
    return routes;
}
 
Example #4
Source File: JdbcRouteLocator.java    From open-cloud with MIT License 6 votes vote down vote up
/**
 * 加载路由配置
 *
 * @return
 */
@Override
protected Map<String, ZuulProperties.ZuulRoute> locateRoutes() {
    LinkedHashMap<String, ZuulProperties.ZuulRoute> routesMap = Maps.newLinkedHashMap();
    routesMap.putAll(super.locateRoutes());
    //从db中加载路由信息
    routesMap.putAll(loadRoutes());
    //优化一下配置
    LinkedHashMap<String, ZuulProperties.ZuulRoute> values = Maps.newLinkedHashMap();
    for (Map.Entry<String, ZuulProperties.ZuulRoute> entry : routesMap.entrySet()) {
        String path = entry.getKey();
        // Prepend with slash if not already present.
        if (!path.startsWith("/")) {
            path = "/" + path;
        }
        if (StringUtils.hasText(this.properties.getPrefix())) {
            path = this.properties.getPrefix() + path;
            if (!path.startsWith("/")) {
                path = "/" + path;
            }
        }
        values.put(path, entry.getValue());
    }
    return values;
}
 
Example #5
Source File: DynamicRouteLocator.java    From Taroco with Apache License 2.0 6 votes vote down vote up
/**
 * 重写路由配置
 *
 * @return 路由表
 */
@Override
protected LinkedHashMap<String, ZuulProperties.ZuulRoute> locateRoutes() {
    //读取properties配置、eureka默认配置
    LinkedHashMap<String, ZuulProperties.ZuulRoute> routesMap = new LinkedHashMap<>(super.locateRoutes());
    log.debug("初始默认的路由配置完成");
    routesMap.putAll(locateRoutesFromCache());
    LinkedHashMap<String, ZuulProperties.ZuulRoute> values = new LinkedHashMap<>();
    for (Map.Entry<String, ZuulProperties.ZuulRoute> entry : routesMap.entrySet()) {
        String path = entry.getKey();
        if (!path.startsWith("/")) {
            path = "/" + path;
        }
        if (StrUtil.isNotBlank(this.properties.getPrefix())) {
            path = this.properties.getPrefix() + path;
            if (!path.startsWith("/")) {
                path = "/" + path;
            }
        }
        values.put(path, entry.getValue());
    }
    return values;
}
 
Example #6
Source File: TrieRouteMatcherTest.java    From zuul-trie-matcher-spring-cloud-starter with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotMatchWildcardRoute() {
    // given
    final String path = "/accounts/";

    // when
    final ZuulProperties.ZuulRoute result = instance.getMatchingRoute(path);

    // then
    assertNull(result);
}
 
Example #7
Source File: CassandraZuulRouteStoreTest.java    From zuul-route-cassandra-spring-cloud-starter with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRetrieveEmptyRouteList() {

    // given
    cassandraTemplate.truncate("zuul_routes");

    // when
    final List<ZuulProperties.ZuulRoute> routes = instance.findAll();

    // then
    assertTrue(routes.isEmpty());
}
 
Example #8
Source File: CassandraZuulRouteStoreTest.java    From zuul-route-cassandra-spring-cloud-starter with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRetrieveConfiguredRoutes() {

    // when
    final List<ZuulProperties.ZuulRoute> routes = instance.findAll();

    // then
    assertFalse(routes.isEmpty());
    assertEquals(2, routes.size());
    final Map<String, ZuulProperties.ZuulRoute> routeMap = asMap(routes);
    assertEquals("resource", routeMap.get("resource").getId());
    assertEquals("/api/**", routeMap.get("resource").getPath());
    assertEquals("rest-service", routeMap.get("resource").getServiceId());
}
 
Example #9
Source File: CassandraZuulRouteStoreTest.java    From zuul-route-cassandra-spring-cloud-starter with Apache License 2.0 5 votes vote down vote up
private Map<String, ZuulProperties.ZuulRoute> asMap(List<ZuulProperties.ZuulRoute> routes) {
    final Map<String, ZuulProperties.ZuulRoute> map = new HashMap<String, ZuulProperties.ZuulRoute>();
    for(ZuulProperties.ZuulRoute route : routes) {
        map.put(route.getId(), route);
    }
    return map;
}
 
Example #10
Source File: ApplicationRegistry.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Add new route to a service.
 *
 * @param service    Details of the service to be registered in the Gateway
 * @param addTimeout Whether the custom metadata should be provided for given service.
 */
public void addApplication(Service service, boolean addTimeout, boolean corsEnabled) {
    String id = service.getId();
    String locationPattern = service.getLocationPattern();
    String serviceRoute = service.getServiceRoute();

    Applications applications = new Applications();
    Application withMetadata = new Application(id);

    Map<String, String> metadata = createMetadata(addTimeout, corsEnabled);

    withMetadata.addInstance(getStandardInstance(metadata, id));
    applications.addApplication(withMetadata);
    ZuulProperties.ZuulRoute route = new ZuulProperties.ZuulRoute(locationPattern, service.getId());
    zuulRouteLinkedHashMap.put(locationPattern, route);

    applicationsToReturn.put(id, applications);

    RoutedServices routedServices = new RoutedServices();
    routedServices.addRoutedService(new RoutedService("test", serviceRoute, ""));
    if (this.routedServicesUsers != null) {
        for (RoutedServicesUser routedServicesUser : routedServicesUsers) {
            routedServicesUser.addRoutedServices(id, routedServices);
        }
    } else {
        servicesToAdd.add(new Services(id, routedServices));
    }
}
 
Example #11
Source File: GatewayConfiguration.java    From open-cloud with MIT License 5 votes vote down vote up
/**
 * 路由加载器
 *
 * @return
 */
@Bean
public JdbcRouteLocator jdbcRouteLocator(ZuulProperties zuulProperties, ServerProperties serverProperties, JdbcTemplate jdbcTemplate, ApplicationEventPublisher publisher) {
    jdbcRouteLocator = new JdbcRouteLocator(serverProperties.getServlet().getContextPath(), zuulProperties, jdbcTemplate, publisher);
    log.info("JdbcRouteLocator:{}", jdbcRouteLocator);
    return jdbcRouteLocator;
}
 
Example #12
Source File: GatewayOverrideConfig.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@Bean
public SimpleRouteLocator simpleRouteLocator() {
    ZuulProperties properties = new ZuulProperties();
    properties.setRoutes(new HashMap<>());

    return new SimpleRouteLocator("", properties);
}
 
Example #13
Source File: TrieRouteMatcherTest.java    From zuul-trie-matcher-spring-cloud-starter with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldMatchWildcardRoute() {
    // given
    final String path = "/account/details";

    // when
    final ZuulProperties.ZuulRoute result = instance.getMatchingRoute(path);

    // then
    assertNotNull(result);
}
 
Example #14
Source File: TrieRouteMatcherTest.java    From zuul-trie-matcher-spring-cloud-starter with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotMatchExactRouteWithSuffix() {
    // given
    final String path = "/uaa/authorize";

    // when
    final ZuulProperties.ZuulRoute result = instance.getMatchingRoute(path);

    // then
    assertNull(result);
}
 
Example #15
Source File: TrieRouteMatcherTest.java    From zuul-trie-matcher-spring-cloud-starter with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldMatchExactRoute() {
    // given
    final String path = "/uaa/";

    // when
    final ZuulProperties.ZuulRoute result = instance.getMatchingRoute(path);

    // then
    assertNotNull(result);
}
 
Example #16
Source File: NacosDynRouteLocator.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
public NacosDynRouteLocator(NacosConfigProperties nacosConfigProperties, ApplicationEventPublisher publisher,
                            String servletPath, ZuulProperties properties) {
    super(servletPath, properties);
    this.nacosConfigProperties = nacosConfigProperties;
    this.publisher = publisher;
    this.locator = this;
    addListener();
}
 
Example #17
Source File: TrieRouteMatcherTest.java    From zuul-trie-matcher-spring-cloud-starter with Apache License 2.0 5 votes vote down vote up
protected Map<String, ZuulProperties.ZuulRoute> getRoutes() {

        final Map<String, ZuulProperties.ZuulRoute> routes =
                new HashMap<String, ZuulProperties.ZuulRoute>();
        routes.put("/uaa/", new ZuulProperties.ZuulRoute("uaa", "/uaa", "uaa", "/uaa", false, null));
        routes.put("/account/**", new ZuulProperties.ZuulRoute("account", "/account", "account", "/account", false, null));
        return routes;
    }
 
Example #18
Source File: DynamicRouteConfiguration.java    From Taroco with Apache License 2.0 5 votes vote down vote up
public DynamicRouteConfiguration(Registration registration, DiscoveryClient discovery,
                                 ZuulProperties zuulProperties, ServerProperties server, TarocoRedisRepository redisRepository) {
    this.registration = registration;
    this.discovery = discovery;
    this.zuulProperties = zuulProperties;
    this.server = server;
    this.redisRepository = redisRepository;
}
 
Example #19
Source File: TrieRouteMatcher.java    From zuul-trie-matcher-spring-cloud-starter with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void setRoutes(Map<String, ZuulProperties.ZuulRoute> routes) {

    final Trie<ZuulRouteEntry> trie = createTrie();
    for (Map.Entry<String, ZuulProperties.ZuulRoute> route : routes.entrySet()) {
        trie.put(
                path(route.getKey()),
                new ZuulRouteEntry(route.getKey(), route.getValue(), isWildcard(route.getKey()))
        );
    }
    this.trie.lazySet(trie);
}
 
Example #20
Source File: CassandraZuulRouteStore.java    From zuul-route-cassandra-spring-cloud-starter with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ZuulProperties.ZuulRoute mapRow(Row row, int rowNum) throws DriverException {

    return new ZuulProperties.ZuulRoute(
            row.getString("id"),
            row.getString("path"),
            row.getString("service_id"),
            row.getString("url"),
            row.getBool("strip_prefix"),
            row.getBool("retryable")
    );
}
 
Example #21
Source File: CassandraZuulRouteStore.java    From zuul-route-cassandra-spring-cloud-starter with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public List<ZuulProperties.ZuulRoute> findAll() {

    final Select query = QueryBuilder.select().from(keyspace, table);
    return cassandraOperations.query(query, ZUUL_ROUTE_MAPPER);
}
 
Example #22
Source File: CustomRouteLocator.java    From oneplatform with Apache License 2.0 5 votes vote down vote up
@Override  
  protected Map<String, ZuulProperties.ZuulRoute> locateRoutes() {  
      LinkedHashMap<String, ZuulProperties.ZuulRoute> routesMap = new LinkedHashMap<>();  
      
      routesMap.putAll(super.locateRoutes());  
      
      ModuleEntityMapper entityMapper = null;
      try {entityMapper = InstanceFactory.getInstance(ModuleEntityMapper.class);} catch (Exception e) {}
      if(entityMapper == null)return routesMap;
      
      List<ModuleEntity> serviceModules = entityMapper.findAllEnabled();
      
      String path = null;
      ZuulProperties.ZuulRoute zuulRoute = null;
      for (ModuleEntity module : serviceModules) {
      	if(module.getEnabled() == false 
      			|| module.getServiceId().equalsIgnoreCase(GlobalContants.MODULE_NAME) 
      			|| ModuleType.plugin.name().equals(module.getModuleType()))continue;
      	path = String.format("/%s/**", module.getRouteName());
      	
      	zuulRoute = new ZuulProperties.ZuulRoute();  
      	zuulRoute.setPath(path);
      	zuulRoute.setId(module.getRouteName());
      	zuulRoute.setServiceId(module.getServiceId());
      	
      	routesMap.put(path, zuulRoute);
      	registryRouteIds.add(module.getRouteName());
      	
      	logger.info("add new Route:{} = {}",path,JsonUtils.toJson(zuulRoute));
}

      return routesMap;  
  }
 
Example #23
Source File: StoreProxyRouteLocator.java    From zuul-route-cassandra-spring-cloud-starter with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void addConfiguredRoutes(Map<String, ZuulProperties.ZuulRoute> routes) {
    for (ZuulProperties.ZuulRoute route : store.findAll()) {
        routes.put(route.getPath(), route);
    }
}
 
Example #24
Source File: ProxyRouteLocator.java    From heimdall with Apache License 2.0 5 votes vote down vote up
public ProxyRouteLocator(String servletPath, DiscoveryClient discovery, ZuulProperties properties, ZuulRouteStorage storage) {

          super(servletPath, discovery, properties);
          this.storage = storage;
          this.discovery = discovery;
          this.properties = properties;
     }
 
Example #25
Source File: ZuulConfiguration.java    From heimdall with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean({ SimpleHostRoutingFilter.class, CloseableHttpClient.class })
public SimpleHostRoutingFilter simpleHostRoutingFilter(ProxyRequestHelper helper, ZuulProperties zuulProperties,
		ApacheHttpClientConnectionManagerFactory connectionManagerFactory,
		ApacheHttpClientFactory httpClientFactory) {
	return new CustomHostRoutingFilter(helper, zuulProperties, connectionManagerFactory, httpClientFactory, circuitBreakerManager);
}
 
Example #26
Source File: StoreProxyRouteLocator.java    From zuul-route-cassandra-spring-cloud-starter with Apache License 2.0 5 votes vote down vote up
/**
 * Creates new instance of {@link StoreProxyRouteLocator}
 * @param servletPath the application servlet path
 * @param discovery the discovery service
 * @param properties the zuul properties
 * @param store the route store
 */
public StoreProxyRouteLocator(String servletPath,
                              DiscoveryClient discovery,
                              ZuulProperties properties,
                              ZuulRouteStore store) {
    super(servletPath, discovery, properties);
    this.store = store;
}
 
Example #27
Source File: HeimdallDecorationFilter.java    From heimdall with Apache License 2.0 5 votes vote down vote up
public HeimdallDecorationFilter(ProxyRouteLocator routeLocator, String dispatcherServletPath, ZuulProperties properties, ProxyRequestHelper proxyRequestHelper, RequestHelper requestHelper, CredentialRepository credentialRepository, EnvironmentInfoRepository environmentInfoRepository) {

        super(routeLocator, dispatcherServletPath, properties, proxyRequestHelper);
        this.routeLocator = routeLocator;
        this.properties = properties;
        this.urlPathHelper.setRemoveSemicolonContent(properties.isRemoveSemicolonContent());
        this.dispatcherServletPath = dispatcherServletPath;
        this.proxyRequestHelper = proxyRequestHelper;
        this.zuulServletPath = properties.getServletPath();
        this.requestHelper = requestHelper;
        this.credentialRepository = credentialRepository;
        this.environmentInfoRepository = environmentInfoRepository;
    }
 
Example #28
Source File: LoadBalancedProxyTargetResolver.java    From spring-cloud-netflix-zuul-websocket with Apache License 2.0 5 votes vote down vote up
@Override
public URI resolveTarget(ZuulWebSocketProperties.WsBrokerage wsBrokerage) {
    ZuulProperties.ZuulRoute zuulRoute = resolveRoute(wsBrokerage);
    if (zuulRoute == null || StringUtils.isEmpty(zuulRoute.getServiceId())) return null;

    ServiceInstance serviceInstance = loadBalancerClient.choose(zuulRoute.getServiceId());
    return serviceInstance != null ? resolveUri(serviceInstance) : null;
}
 
Example #29
Source File: EurekaProxyTargetResolver.java    From spring-cloud-netflix-zuul-websocket with Apache License 2.0 5 votes vote down vote up
@Override
public URI resolveTarget(ZuulWebSocketProperties.WsBrokerage wsBrokerage) {
    ZuulProperties.ZuulRoute zuulRoute = resolveRoute(wsBrokerage);
    if (zuulRoute == null || StringUtils.isEmpty(zuulRoute.getServiceId())) return null;

    List<ServiceInstance> instances = discoveryClient.getInstances(zuulRoute.getServiceId());
    ServiceInstance serviceInstance = CollectionUtils.isEmpty(instances) ? null : instances.get(0);
    return serviceInstance != null ? resolveUri(serviceInstance) : null;
}
 
Example #30
Source File: UrlProxyTargetResolver.java    From spring-cloud-netflix-zuul-websocket with Apache License 2.0 5 votes vote down vote up
@Override
public URI resolveTarget(ZuulWebSocketProperties.WsBrokerage wsBrokerage) {
    ZuulProperties.ZuulRoute zuulRoute = resolveRoute(wsBrokerage);
    if (zuulRoute == null || StringUtils.isEmpty(zuulRoute.getUrl())) return null;

    try {
        return new URI(zuulRoute.getUrl());
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
}