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


Java Util.EMPTY_REQUEST属性代码示例

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


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

示例1: createOkRequest

/**
 * Creates an OkHttp {@link Request} from the supplied information.
 *
 * <p>This method allows a {@code null} value for {@code requestHeaders} for situations where a
 * connection is already connected and access to the headers has been lost. See {@link
 * java.net.HttpURLConnection#getRequestProperties()} for details.
 */
public static Request createOkRequest(
    URI uri, String requestMethod, Map<String, List<String>> requestHeaders) {
  // OkHttp's Call API requires a placeholder body; the real body will be streamed separately.
  RequestBody placeholderBody = HttpMethod.requiresRequestBody(requestMethod)
      ? Util.EMPTY_REQUEST
      : null;

  Request.Builder builder = new Request.Builder()
      .url(uri.toString())
      .method(requestMethod, placeholderBody);

  if (requestHeaders != null) {
    Headers headers = extractOkHeaders(requestHeaders, null);
    builder.headers(headers);
  }
  return builder.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:JavaApiConverter.java

示例2: createOkResponseForCachePut

/**
 * Creates an OkHttp {@link Response} using the supplied {@link URI} and {@link URLConnection} to
 * supply the data. The URLConnection is assumed to already be connected. If this method returns
 * {@code null} the response is uncacheable.
 */
public static Response createOkResponseForCachePut(URI uri, URLConnection urlConnection)
    throws IOException {

  HttpURLConnection httpUrlConnection = (HttpURLConnection) urlConnection;

  Response.Builder okResponseBuilder = new Response.Builder();

  // Request: Create one from the URL connection.
  Headers responseHeaders = createHeaders(urlConnection.getHeaderFields());
  // Some request headers are needed for Vary caching.
  Headers varyHeaders = varyHeaders(urlConnection, responseHeaders);
  if (varyHeaders == null) {
    return null;
  }

  // OkHttp's Call API requires a placeholder body; the real body will be streamed separately.
  String requestMethod = httpUrlConnection.getRequestMethod();
  RequestBody placeholderBody = HttpMethod.requiresRequestBody(requestMethod)
      ? Util.EMPTY_REQUEST
      : null;

  Request okRequest = new Request.Builder()
      .url(uri.toString())
      .method(requestMethod, placeholderBody)
      .headers(varyHeaders)
      .build();
  okResponseBuilder.request(okRequest);

  // Status line
  StatusLine statusLine = StatusLine.parse(extractStatusLine(httpUrlConnection));
  okResponseBuilder.protocol(statusLine.protocol);
  okResponseBuilder.code(statusLine.code);
  okResponseBuilder.message(statusLine.message);

  // A network response is required for the Cache to find any Vary headers it needs.
  Response networkResponse = okResponseBuilder.build();
  okResponseBuilder.networkResponse(networkResponse);

  // Response headers
  Headers okHeaders = extractOkResponseHeaders(httpUrlConnection, okResponseBuilder);
  okResponseBuilder.headers(okHeaders);

  // Response body
  ResponseBody okBody = createOkBody(urlConnection);
  okResponseBuilder.body(okBody);

  // Handle SSL handshake information as needed.
  if (httpUrlConnection instanceof HttpsURLConnection) {
    HttpsURLConnection httpsUrlConnection = (HttpsURLConnection) httpUrlConnection;

    Certificate[] peerCertificates;
    try {
      peerCertificates = httpsUrlConnection.getServerCertificates();
    } catch (SSLPeerUnverifiedException e) {
      peerCertificates = null;
    }

    Certificate[] localCertificates = httpsUrlConnection.getLocalCertificates();

    String cipherSuiteString = httpsUrlConnection.getCipherSuite();
    CipherSuite cipherSuite = CipherSuite.forJavaName(cipherSuiteString);
    Handshake handshake = Handshake.get(null, cipherSuite,
        nullSafeImmutableList(peerCertificates), nullSafeImmutableList(localCertificates));
    okResponseBuilder.handshake(handshake);
  }

  return okResponseBuilder.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:73,代码来源:JavaApiConverter.java

示例3: transformRequest

private static Request transformRequest(HttpRequest request) {
  Request.Builder builder = new Request.Builder();

  RequestLine requestLine = request.getRequestLine();
  String method = requestLine.getMethod();
  builder.url(requestLine.getUri());

  String contentType = null;
  for (Header header : request.getAllHeaders()) {
    String name = header.getName();
    if ("Content-Type".equalsIgnoreCase(name)) {
      contentType = header.getValue();
    } else {
      builder.header(name, header.getValue());
    }
  }

  RequestBody body = null;
  if (request instanceof HttpEntityEnclosingRequest) {
    HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
    if (entity != null) {
      // Wrap the entity in a custom Body which takes care of the content, length, and type.
      body = new HttpEntityBody(entity, contentType);

      Header encoding = entity.getContentEncoding();
      if (encoding != null) {
        builder.header(encoding.getName(), encoding.getValue());
      }
    } else {
      body = Util.EMPTY_REQUEST;
    }
  }
  builder.method(method, body);

  return builder.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:36,代码来源:OkApacheClient.java

示例4: createOkResponseForCachePut

/**
 * Creates an OkHttp {@link Response} using the supplied {@link URI} and {@link URLConnection} to
 * supply the data. The URLConnection is assumed to already be connected. If this method returns
 * {@code null} the response is uncacheable.
 */
public static Response createOkResponseForCachePut(URI uri, URLConnection urlConnection)
    throws IOException {

  HttpURLConnection httpUrlConnection = (HttpURLConnection) urlConnection;

  Response.Builder okResponseBuilder = new Response.Builder();

  // Request: Create one from the URL connection.
  Headers responseHeaders = createHeaders(urlConnection.getHeaderFields());
  // Some request headers are needed for Vary caching.
  Headers varyHeaders = varyHeaders(urlConnection, responseHeaders);
  if (varyHeaders == null) {
    return null;
  }

  // OkHttp's Call API requires a placeholder body; the real body will be streamed separately.
  String requestMethod = httpUrlConnection.getRequestMethod();
  RequestBody placeholderBody = HttpMethod.requiresRequestBody(requestMethod)
      ? Util.EMPTY_REQUEST
      : null;

  Request okRequest = new Request.Builder()
      .url(uri.toString())
      .method(requestMethod, placeholderBody)
      .headers(varyHeaders)
      .build();
  okResponseBuilder.request(okRequest);

  // Status line
  StatusLine statusLine = StatusLine.parse(extractStatusLine(httpUrlConnection));
  okResponseBuilder.protocol(statusLine.protocol);
  okResponseBuilder.code(statusLine.code);
  okResponseBuilder.message(statusLine.message);

  // A network response is required for the Cache to find any Vary headers it needs.
  Response networkResponse = okResponseBuilder.build();
  okResponseBuilder.networkResponse(networkResponse);

  // Response headers
  Headers okHeaders = extractOkResponseHeaders(httpUrlConnection, okResponseBuilder);
  okResponseBuilder.headers(okHeaders);

  // Response body
  ResponseBody okBody = createOkBody(urlConnection);
  okResponseBuilder.body(okBody);

  // Handle SSL handshake information as needed.
  if (httpUrlConnection instanceof HttpsURLConnection) {
    HttpsURLConnection httpsUrlConnection = (HttpsURLConnection) httpUrlConnection;

    Certificate[] peerCertificates;
    try {
      peerCertificates = httpsUrlConnection.getServerCertificates();
    } catch (SSLPeerUnverifiedException e) {
      peerCertificates = null;
    }

    Certificate[] localCertificates = httpsUrlConnection.getLocalCertificates();

    String cipherSuiteString = httpsUrlConnection.getCipherSuite();
    CipherSuite cipherSuite = CipherSuite.forJavaName(cipherSuiteString);
    Handshake handshake = Handshake.get(TlsVersion.SSL_3_0, cipherSuite,
        nullSafeImmutableList(peerCertificates), nullSafeImmutableList(localCertificates));
    okResponseBuilder.handshake(handshake);
  }

  return okResponseBuilder.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:73,代码来源:JavaApiConverter.java

示例5: checkMethodAndBody

protected void checkMethodAndBody() {
  if (method == null) {
    throw new NullPointerException("method == null");
  }
  if (method.length() == 0) {
    throw new IllegalArgumentException("method.length() == 0");
  }
  if (body != null && !HttpMethod.permitsRequestBody(method)) {
    throw new IllegalArgumentException("method " + method + " must not have a request body.");
  }
  if (body == null && HttpMethod.requiresRequestBody(method)) {
    this.body = Util.EMPTY_REQUEST;
  }
}
 
开发者ID:febit,项目名称:febit,代码行数:14,代码来源:EasyRequest.java


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