gpt4 book ai didi

com.netflix.zuul.filters.ZuulFilter类的使用及代码示例

转载 作者:知者 更新时间:2024-03-18 19:27:31 28 4
gpt4 key购买 nike

本文整理了Java中com.netflix.zuul.filters.ZuulFilter类的一些代码示例,展示了ZuulFilter类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZuulFilter类的具体详情如下:
包路径:com.netflix.zuul.filters.ZuulFilter
类名称:ZuulFilter

ZuulFilter介绍

[英]BAse interface for ZuulFilters
[中]ZuFilter的基本接口

代码示例

代码示例来源:origin: Netflix/zuul

protected void recordFilterError(final I inMesg, final ZuulFilter<I, O> filter, final Throwable t) {
  // Add a log statement for this exception.
  final String errorMsg = "Filter Exception: filter=" + filter.filterName() +
      ", request-info=" + inMesg.getInfoForLogging() + ", msg=" + String.valueOf(t.getMessage());
  if (t instanceof ZuulException && !((ZuulException) t).shouldLogAsError()) {
    LOG.warn(errorMsg);
  }
  else {
    LOG.error(errorMsg, t);
  }
  // Store this filter error for possible future use. But we still continue with next filter in the chain.
  final SessionContext zuulCtx = inMesg.getContext();
  zuulCtx.getFilterErrors().add(new FilterError(filter.filterName(), filter.filterType().toString(), t));
  if (zuulCtx.debugRouting()) {
    Debug.addRoutingDebug(zuulCtx, "Running Filter failed " + filter.filterName() + " type:" +
        filter.filterType() + " order:" + filter.filterOrder() + " " + t.getMessage());
  }
}

代码示例来源:origin: Netflix/zuul

protected O handleFilterException(final I inMesg, final ZuulFilter<I, O> filter, final Throwable ex) {
  inMesg.getContext().setError(ex);
  if (filter.filterType() == ENDPOINT) {
    inMesg.getContext().setShouldSendErrorResponse(true);
  }
  recordFilterError(inMesg, filter, ex);
  return filter.getDefaultOutput(inMesg);
}

代码示例来源:origin: Netflix/zuul

private boolean isMessageBodyReadyForFilter(final ZuulFilter filter, final I inMesg) {
  return ((!filter.needsBodyBuffered(inMesg)) || (inMesg.hasCompleteBody()));
}

代码示例来源:origin: Netflix/zuul

void putFilter(String sName, ZuulFilter filter, long lastModified)
{
  List<ZuulFilter> list = hashFiltersByType.get(filter.filterType());
  if (list != null) {
    hashFiltersByType.remove(filter.filterType()); //rebuild this list
  }
  String nameAndType = filter.filterType() + ":" + filter.filterName();
  filtersByNameAndType.put(nameAndType, filter);
  filterRegistry.put(sName, filter);
  filterClassLastModified.put(sName, lastModified);
}

代码示例来源:origin: Netflix/zuul

protected final boolean shouldSkipFilter(final I inMesg, final ZuulFilter<I, O> filter) {
  if (filter.filterType() == ENDPOINT) {
    //Endpoints may not be skipped
    return false;
  }
  final SessionContext zuulCtx = inMesg.getContext();
  if (!filter.shouldFilter(inMesg)) {
    return true;
  }
  if ((zuulCtx.shouldStopFilterProcessing()) && (!filter.overrideStopFilterProcessing())) {
    return true;
  }
  if (zuulCtx.isCancelled()) {
    return true;
  }
  return false;
}

代码示例来源:origin: Netflix/zuul

if (filter.filterType() == INBOUND && inMesg.getContext().shouldSendErrorResponse()) {
if (filter.isDisabled()) {
  filterRunStatus = DISABLED;
  return filter.getDefaultOutput(inMesg);
  LOG.debug("Filter {} waiting for body, UUID {}", filter.filterName(), inMesg.getContext().getUUID());
  return null;  //wait for whole body to be buffered
  Debug.addRoutingDebug(inMesg.getContext(), "Filter " + filter.filterType().toString() + " " + filter.filterOrder() + " " + filter.filterName());
if (filter.getSyncType() == FilterSyncType.SYNC) {
  final SyncZuulFilter<I, O> syncFilter = (SyncZuulFilter) filter;
  final O outMesg = syncFilter.apply(inMesg);
  recordFilterCompletion(SUCCESS, filter, startTime, inMesg, snapshot);
  return (outMesg != null) ? outMesg : filter.getDefaultOutput(inMesg);
filter.incrementConcurrency();
resumer = new FilterChainResumer(inMesg, filter, snapshot, startTime);
filter.applyAsync(inMesg)
  .observeOn(Schedulers.from(getChannelHandlerContext(inMesg).executor()))
  .doOnUnsubscribe(resumer::decrementConcurrency)

代码示例来源:origin: Netflix/zuul

for (int i = 0; i < limit; i++) {
  final ZuulFilter<T, T> filter = filters[i];
  filterName = filter.filterName();
  if ((! filter.isDisabled()) && (! shouldSkipFilter(inMesg, filter))) {
    final HttpContent newChunk = filter.processContentChunk(inMesg, chunk);
    if (newChunk == null)  {

代码示例来源:origin: Netflix/zuul

public ZuulFilterChainRunner(ZuulFilter<T, T>[] zuulFilters, FilterUsageNotifier usageNotifier, FilterRunner<T, ?> nextStage) {
  super(zuulFilters[0].filterType(), usageNotifier, nextStage);
  this.filters = zuulFilters;
}

代码示例来源:origin: Netflix/zuul

@Override
public void filter(final HttpRequestMessage zuulReq, final HttpContent chunk) {
  if (zuulReq.getContext().isCancelled()) {
    chunk.release();
    return;
  }
  String endpointName = "-";
  try {
    ZuulFilter<HttpRequestMessage, HttpResponseMessage> endpoint = Preconditions.checkNotNull(
        getEndpoint(zuulReq), "endpoint");
    endpointName = endpoint.filterName();
    final HttpContent newChunk = endpoint.processContentChunk(zuulReq, chunk);
    if (newChunk != null) {
      //Endpoints do not directly forward content chunks to next stage in the filter chain.
      zuulReq.bufferBodyContents(newChunk);
      //deallocate original chunk if necessary
      if (newChunk != chunk) {
        chunk.release();
      }
      if (isFilterAwaitingBody(zuulReq) && zuulReq.hasCompleteBody() && !(endpoint instanceof ProxyEndpoint)) {
        //whole body has arrived, resume filter chain
        invokeNextStage(filter(endpoint, zuulReq));
      }
    }
  }
  catch (Exception ex) {
    handleException(zuulReq, endpointName, ex);
  }
}

代码示例来源:origin: Netflix/zuul

public ZuulFilterConcurrencyExceededException(ZuulFilter filter, int concurrencyLimit) {
    super(filter.filterName() + " exceeded concurrency limit of " + concurrencyLimit, true);
  }
}

代码示例来源:origin: Netflix/zuul

@Override
  public int compare(ZuulFilter o1, ZuulFilter o2) {
    return o1.filterOrder() - o2.filterOrder();
  }
});

代码示例来源:origin: Netflix/zuul

if (filter.filterType() == INBOUND && inMesg.getContext().shouldSendErrorResponse()) {
if (filter.isDisabled()) {
  filterRunStatus = DISABLED;
  return filter.getDefaultOutput(inMesg);
  LOG.debug("Filter {} waiting for body, UUID {}", filter.filterName(), inMesg.getContext().getUUID());
  return null;  //wait for whole body to be buffered
  Debug.addRoutingDebug(inMesg.getContext(), "Filter " + filter.filterType().toString() + " " + filter.filterOrder() + " " + filter.filterName());
if (filter.getSyncType() == FilterSyncType.SYNC) {
  final SyncZuulFilter<I, O> syncFilter = (SyncZuulFilter) filter;
  final O outMesg = syncFilter.apply(inMesg);
  recordFilterCompletion(SUCCESS, filter, startTime, inMesg, snapshot);
  return (outMesg != null) ? outMesg : filter.getDefaultOutput(inMesg);
filter.incrementConcurrency();
resumer = new FilterChainResumer(inMesg, filter, snapshot, startTime);
filter.applyAsync(inMesg)
  .observeOn(Schedulers.from(getChannelHandlerContext(inMesg).executor()))
  .doOnUnsubscribe(resumer::decrementConcurrency)

代码示例来源:origin: Netflix/zuul

protected final boolean shouldSkipFilter(final I inMesg, final ZuulFilter<I, O> filter) {
  if (filter.filterType() == ENDPOINT) {
    //Endpoints may not be skipped
    return false;
  }
  final SessionContext zuulCtx = inMesg.getContext();
  if (!filter.shouldFilter(inMesg)) {
    return true;
  }
  if ((zuulCtx.shouldStopFilterProcessing()) && (!filter.overrideStopFilterProcessing())) {
    return true;
  }
  if (zuulCtx.isCancelled()) {
    return true;
  }
  return false;
}

代码示例来源:origin: Netflix/zuul

for (int i = 0; i < limit; i++) {
  final ZuulFilter<T, T> filter = filters[i];
  filterName = filter.filterName();
  if ((! filter.isDisabled()) && (! shouldSkipFilter(inMesg, filter))) {
    final HttpContent newChunk = filter.processContentChunk(inMesg, chunk);
    if (newChunk == null)  {

代码示例来源:origin: Netflix/zuul

public <T extends ZuulMessage> ZuulFilter<T, T> [] getFilters(final ZuulFilter start, final ZuulFilter stop) {
  final List<ZuulFilter> zuulFilters = filterLoader.getFiltersByType(start.filterType());
  final ZuulFilter[] filters = new ZuulFilter[zuulFilters.size() + 2];
  filters[0] = start;
  for (int i=1, j=0; i < filters.length && j < zuulFilters.size(); i++,j++) {
    filters[i] = zuulFilters.get(j);
  }
  filters[filters.length -1] = stop;
  return filters;
}

代码示例来源:origin: Netflix/zuul

void putFilter(String sName, ZuulFilter filter, long lastModified)
{
  List<ZuulFilter> list = hashFiltersByType.get(filter.filterType());
  if (list != null) {
    hashFiltersByType.remove(filter.filterType()); //rebuild this list
  }
  String nameAndType = filter.filterType() + ":" + filter.filterName();
  filtersByNameAndType.put(nameAndType, filter);
  filterRegistry.put(sName, filter);
  filterClassLastModified.put(sName, lastModified);
}

代码示例来源:origin: Netflix/zuul

@Override
public void filter(final HttpRequestMessage zuulReq, final HttpContent chunk) {
  if (zuulReq.getContext().isCancelled()) {
    chunk.release();
    return;
  }
  String endpointName = "-";
  try {
    ZuulFilter<HttpRequestMessage, HttpResponseMessage> endpoint = Preconditions.checkNotNull(
        getEndpoint(zuulReq), "endpoint");
    endpointName = endpoint.filterName();
    final HttpContent newChunk = endpoint.processContentChunk(zuulReq, chunk);
    if (newChunk != null) {
      //Endpoints do not directly forward content chunks to next stage in the filter chain.
      zuulReq.bufferBodyContents(newChunk);
      //deallocate original chunk if necessary
      if (newChunk != chunk) {
        chunk.release();
      }
      if (isFilterAwaitingBody(zuulReq) && zuulReq.hasCompleteBody() && !(endpoint instanceof ProxyEndpoint)) {
        //whole body has arrived, resume filter chain
        invokeNextStage(filter(endpoint, zuulReq));
      }
    }
  }
  catch (Exception ex) {
    handleException(zuulReq, endpointName, ex);
  }
}

代码示例来源:origin: Netflix/zuul

public ZuulFilterConcurrencyExceededException(ZuulFilter filter, int concurrencyLimit) {
    super(filter.filterName() + " exceeded concurrency limit of " + concurrencyLimit, true);
  }
}

代码示例来源:origin: Netflix/zuul

@Override
  public int compare(ZuulFilter o1, ZuulFilter o2) {
    return o1.filterOrder() - o2.filterOrder();
  }
});

代码示例来源:origin: com.netflix.zuul/zuul-core

if (filter.filterType() == INBOUND && inMesg.getContext().shouldSendErrorResponse()) {
if (filter.isDisabled()) {
  filterRunStatus = DISABLED;
  return filter.getDefaultOutput(inMesg);
  LOG.debug("Filter {} waiting for body, UUID {}", filter.filterName(), inMesg.getContext().getUUID());
  return null;  //wait for whole body to be buffered
  Debug.addRoutingDebug(inMesg.getContext(), "Filter " + filter.filterType().toString() + " " + filter.filterOrder() + " " + filter.filterName());
if (filter.getSyncType() == FilterSyncType.SYNC) {
  final SyncZuulFilter<I, O> syncFilter = (SyncZuulFilter) filter;
  final O outMesg = syncFilter.apply(inMesg);
  recordFilterCompletion(SUCCESS, filter, startTime, inMesg, snapshot);
  return (outMesg != null) ? outMesg : filter.getDefaultOutput(inMesg);
filter.incrementConcurrency();
resumer = new FilterChainResumer(inMesg, filter, snapshot, startTime);
filter.applyAsync(inMesg)
  .observeOn(Schedulers.from(getChannelHandlerContext(inMesg).executor()))
  .doOnUnsubscribe(resumer::decrementConcurrency)

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com