org.eclipse.californium.core.coap.Request.getResponse()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(3.5k)|赞(0)|评价(0)|浏览(107)

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

Request.getResponse介绍

[英]Gets the response or null if none has arrived yet.
[中]获取响应,如果还没有响应,则返回null。

代码示例

代码示例来源:origin: eclipse/californium

/**
 * Create a key for the cache starting from a request and the
 * content-type of the corresponding response.
 * 
 * @param request
 * @return
 * @throws URISyntaxException
 */
private static CacheKey fromContentTypeOption(Request request) throws URISyntaxException {
  if (request == null) {
    throw new IllegalArgumentException("request == null");
  }
  Response response = request.getResponse();
  if (response == null) {
    return fromAcceptOptions(request).get(0);
  }
  String proxyUri = request.getOptions().getProxyUri();
  int mediaType = response.getOptions().getContentFormat();
  if (mediaType < 0) {
    // content-format option not set, use default
    mediaType = MediaTypeRegistry.TEXT_PLAIN;
  }
  byte[] payload = request.getPayload();
  // create the new cacheKey
  CacheKey cacheKey = new CacheKey(proxyUri, mediaType, payload);
  cacheKey.setResponse(response);
  return cacheKey;
}

代码示例来源:origin: org.eclipse.californium/californium-proxy

/**
 * Create a key for the cache starting from a request and the
 * content-type of the corresponding response.
 * 
 * @param request
 * @return
 * @throws URISyntaxException
 */
private static CacheKey fromContentTypeOption(Request request) throws URISyntaxException {
  if (request == null) {
    throw new IllegalArgumentException("request == null");
  }
  Response response = request.getResponse();
  if (response == null) {
    return fromAcceptOptions(request).get(0);
  }
  String proxyUri = request.getOptions().getProxyUri();
  int mediaType = response.getOptions().getContentFormat();
  if (mediaType < 0) {
    // content-format option not set, use default
    mediaType = MediaTypeRegistry.TEXT_PLAIN;
  }
  byte[] payload = request.getPayload();
  // create the new cacheKey
  CacheKey cacheKey = new CacheKey(proxyUri, mediaType, payload);
  cacheKey.setResponse(response);
  return cacheKey;
}

代码示例来源:origin: eclipse/californium

response = request.getResponse();

代码示例来源:origin: eclipse/californium

/**
 * Verifies that incoming responses are not delivered to their originating requests
 * if a subclass has already processed the response.
 */
@Test
public void testDeliverResponseYieldsToSubclass() {
  // GIVEN a message deliverer subclass that processes all incoming responses
  ServerMessageDeliverer deliverer = new ServerMessageDeliverer(rootResource) {
    @Override
    protected boolean preDeliverResponse(Exchange exchange, Response response) {
      return true;
    }
  };
  // WHEN a response is received
  deliverer.deliverResponse(outboundRequest, incomingResponse);
  // THEN the response is not delivered to the request
  assertNull(outboundRequest.getRequest().getResponse());
}

代码示例来源:origin: eclipse/californium

/**
   * Verifies that incoming responses are delivered to their originating requests
   * if a subclass has not already processed the response.
   */
  @Test
  public void testDeliverResponseProcessesResponseAfterPreDeliverResponse() {

    // GIVEN a message deliverer subclass that adds a custom option to incoming
    // responses
    ServerMessageDeliverer deliverer = new ServerMessageDeliverer(rootResource) {

      @Override
      protected boolean preDeliverResponse(Exchange exchange, Response response) {
        response.getOptions().addOption(new Option(200));
        return false;
      }
    };

    // WHEN a response is received
    deliverer.deliverResponse(outboundRequest, incomingResponse);

    // THEN the response is delivered to the request
    assertNotNull(outboundRequest.getRequest().getResponse());
    // and the response contains the custom option
    assertTrue(outboundRequest.getRequest().getResponse().getOptions().hasOption(200));
  }
}

相关文章

微信公众号

最新文章

更多