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


Java Interceptor.intercept方法代码示例

本文整理汇总了Java中com.squareup.okhttp.Interceptor.intercept方法的典型用法代码示例。如果您正苦于以下问题:Java Interceptor.intercept方法的具体用法?Java Interceptor.intercept怎么用?Java Interceptor.intercept使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.squareup.okhttp.Interceptor的用法示例。


在下文中一共展示了Interceptor.intercept方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: proceed

import com.squareup.okhttp.Interceptor; //导入方法依赖的package包/类
public final Response proceed(Request paramRequest)
  throws IOException
{
  this.calls = (1 + this.calls);
  if (this.index > 0)
  {
    Interceptor localInterceptor2 = (Interceptor)HttpEngine.this.client.networkInterceptors.get(-1 + this.index);
    Address localAddress = HttpEngine.this.connection.route.address;
    if ((!paramRequest.url().getHost().equals(localAddress.uriHost)) || (Util.getEffectivePort(paramRequest.url()) != localAddress.uriPort)) {
      throw new IllegalStateException("network interceptor " + localInterceptor2 + " must retain the same host and port");
    }
    if (this.calls > 1) {
      throw new IllegalStateException("network interceptor " + localInterceptor2 + " must call proceed() exactly once");
    }
  }
  Response localResponse;
  if (this.index < HttpEngine.this.client.networkInterceptors.size())
  {
    NetworkInterceptorChain localNetworkInterceptorChain = new NetworkInterceptorChain(HttpEngine.this, 1 + this.index, paramRequest);
    Interceptor localInterceptor1 = (Interceptor)HttpEngine.this.client.networkInterceptors.get(this.index);
    localResponse = localInterceptor1.intercept(localNetworkInterceptorChain);
    if (localNetworkInterceptorChain.calls != 1) {
      throw new IllegalStateException("network interceptor " + localInterceptor1 + " must call proceed() exactly once");
    }
  }
  else
  {
    HttpEngine.this.transport.writeRequestHeaders(paramRequest);
    if ((HttpEngine.this.permitsRequestBody()) && (paramRequest.body != null))
    {
      BufferedSink localBufferedSink = Okio.buffer(HttpEngine.this.transport.createRequestBody(paramRequest, paramRequest.body.contentLength()));
      paramRequest.body.writeTo(localBufferedSink);
      localBufferedSink.close();
    }
    localResponse = HttpEngine.this.readNetworkResponse();
  }
  return localResponse;
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:39,代码来源:HttpEngine.java

示例2: proceed

import com.squareup.okhttp.Interceptor; //导入方法依赖的package包/类
public Response proceed(Request request) throws IOException {
    this.calls++;
    if (this.index > 0) {
        Interceptor caller = (Interceptor) this.this$0.client.networkInterceptors().get(this
                .index - 1);
        Address address = connection().getRoute().getAddress();
        if (!request.httpUrl().host().equals(address.getUriHost()) || request.httpUrl().port
                () != address.getUriPort()) {
            throw new IllegalStateException("network interceptor " + caller + " must retain " +
                    "the same host and port");
        } else if (this.calls > 1) {
            throw new IllegalStateException("network interceptor " + caller + " must call " +
                    "proceed() exactly once");
        }
    }
    if (this.index < this.this$0.client.networkInterceptors().size()) {
        HttpEngine$NetworkInterceptorChain chain = new HttpEngine$NetworkInterceptorChain
                (this.this$0, this.index + 1, request);
        Interceptor interceptor = (Interceptor) this.this$0.client.networkInterceptors().get
                (this.index);
        Response intercept = interceptor.intercept(chain);
        if (chain.calls != 1) {
            throw new IllegalStateException("network interceptor " + interceptor + " must " +
                    "call proceed() exactly once");
        } else if (intercept != null) {
            return intercept;
        } else {
            throw new NullPointerException("network interceptor " + interceptor + " returned " +
                    "null");
        }
    }
    HttpEngine.access$000(this.this$0).writeRequestHeaders(request);
    HttpEngine.access$102(this.this$0, request);
    if (this.this$0.permitsRequestBody(request) && request.body() != null) {
        BufferedSink bufferedRequestBody = Okio.buffer(HttpEngine.access$000(this.this$0)
                .createRequestBody(request, request.body().contentLength()));
        request.body().writeTo(bufferedRequestBody);
        bufferedRequestBody.close();
    }
    Response response = HttpEngine.access$200(this.this$0);
    int code = response.code();
    if ((code != 204 && code != 205) || response.body().contentLength() <= 0) {
        return response;
    }
    throw new ProtocolException("HTTP " + code + " had non-zero Content-Length: " + response.body().contentLength());
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:47,代码来源:HttpEngine$NetworkInterceptorChain.java


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