如何针对特定条件情况禁用zuul过滤器而不发送到映射URL

时间:2018-05-09 08:11:29

标签: spring-boot netflix-zuul spring-cloud-netflix

我有路由配置的zuul过滤器实现

 related:
      path: /api/search/related/**
      url: http://abc.xyz.neverhit.this.URl

并运行实现

 @Override
    public Object run() {
        RequestContext context = getCurrentContext();
        HttpServletRequest request = context.getRequest();
        UriComponents uri = UriComponentsBuilder.fromHttpUrl(recommendationsServiceHostname)
            .path("/recommendations/related")
            .query(request.getQueryString()).build();

        if (shouldRouteToRecommendationsService(request, uri)) {
            logger.info("Calling  proxy service");


            try {
                context.setRouteHost(new URL(uri.toString()));
            } catch (MalformedURLException ex) {
                logger.error("MalformedURLException for URL:" + uri.toString());
            }
        }
        else
        {
            //Something here or Solution that should handle a request like a filter is not present.
        }
        return null;
}

它适用于if部分并将请求发送到代理服务。问题在于其他部分。 我正在寻找的是在其他场景中它应该像过滤器一样从不存在它应该处理请求它处理从本地代码早期执行API调用。

任何黑客或适当的解决方案?

0 个答案:

没有答案