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

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

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

Response.getOptions介绍

暂无

代码示例

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

/**
 * Gets the set of options of this response.
 *
 * @return the options
 */
public OptionSet getOptions() {
  return response.getOptions();
}

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

/**
 * Checks whether this response has either a <em>block1</em> or
 * <em>block2</em> option.
 * 
 * @return {@code true} if this response has a block option.
 */
public boolean hasBlockOption() {
  return getOptions().hasBlock1() || getOptions().hasBlock2();
}

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

@Override
  protected boolean checkResponse(Request request, Response response) {
    boolean success = response.getOptions().hasBlock2();
    
    if (!success) {
      System.out.println("FAIL: no Block2 option");
    } else {
      success &= hasNonEmptyPalyoad(response);
      success &= hasContentType(response);
    }
    return success;
  }
}

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

@Override
public String toString() {
  String payload = getPayloadTracingString();
  return String.format("%s-%-6s MID=%5d, Token=%s, OptionSet=%s, %s", getType(), getCode(), getMID(), getTokenString(), getOptions(), payload);
}

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

@Override
public void receiveResponse(Exchange exchange, Response response) {
  if (!response.getOptions().hasObserve() && !exchange.getCurrentRequest().isMulticast())
    exchange.setComplete();
  if (deliverer != null) {
    deliverer.deliverResponse(exchange, response); // notify request that response has arrived
  } else {
    LOGGER.severe("Top of CoAP stack has no deliverer to deliver response");
  }
}

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

public void check(Response response) {
    assertTrue("Has no observe option", response.getOptions().hasObserve());
    storage.put(key, response.getOptions().getObserve());
  }
});

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

@Override
public void handleGET(CoapExchange exchange) {
  String payload = "Available commands:\n - GET: show statistics\n - POST write stats to file\n - DELETE: reset statistics\n\n";
  payload += getStatString();
  Response response = new Response(ResponseCode.CONTENT);
  response.setPayload(payload);
  response.getOptions().setContentFormat(MediaTypeRegistry.TEXT_PLAIN);
  exchange.respond(response);
}

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

@Override
public void handleGET(CoapExchange exchange) {
  String payload = "Available commands:\n - GET: show statistics\n - POST write stats to file\n - DELETE: reset statistics\n\n";
  payload += getStatString();
  Response response = new Response(ResponseCode.CONTENT);
  response.setPayload(payload);
  response.getOptions().setContentFormat(MediaTypeRegistry.TEXT_PLAIN);
  exchange.respond(response);
}

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

@Override
  public void check(final Response response) {
    assertTrue("Response has no ETag", response.getOptions().getETagCount() > 0);
    Object obj = storage.get(var);
    assertThat("Object stored under " + var + " is not an ETag", obj, is(instanceOf(byte[].class)));
    assertThat("Response contains wrong ETag", (byte[]) obj,
        is(response.getOptions().getETags().get(0)));
  }
});

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

public void check(Response response) {
    assertTrue("Has no observe option", response.getOptions().hasObserve());
    Object value = storage.get(key);
    if (value == null) {
      throw new IllegalArgumentException("Key " + key + " not found");
    }
    int V1 = (Integer) value;
    int V2 = response.getOptions().getObserve();
    boolean fresh = V1 < V2 && V2 - V1 < 1 << 23 || V1 > V2 && V1 - V2 > 1 << 23;
    assertTrue("Was not a fresh notification. Last obs=" + V1 + ", new=" + V2, fresh);
  }
});

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

@Override
public void check(final Response response) {
  assertThat("Wrong size2", response.getOptions().getSize2(), is(expectedSize));
}

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

@Override
public void handleGET(CoapExchange exchange) {
  String payload = "Available commands:\n - GET: show statistics\n - POST write stats to file\n - DELETE: reset statistics\n\n";
  payload += getStats();
  Response response = new Response(ResponseCode.CONTENT);
  response.setPayload(payload);
  response.getOptions().setContentFormat(MediaTypeRegistry.TEXT_PLAIN);
  exchange.respond(response);
}

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

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

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

@Override
public void handleGET(CoapExchange exchange) {
  String payload = "Available commands:\n - GET: show statistics\n - POST write stats to file\n - DELETE: reset statistics\n\n";
  payload += getStats();
  Response response = new Response(ResponseCode.CONTENT);
  response.setPayload(payload);
  response.getOptions().setContentFormat(MediaTypeRegistry.TEXT_PLAIN);
  exchange.respond(response);
}

代码示例来源:origin: org.github.leshan/leshan-client

private void buildResponse() {
  if (coapResponse == null) {
    lwM2mresponse = OperationResponse.failure(ResponseCode.GATEWAY_TIMEOUT, "Timed Out Waiting For Response.");
  } else if (ResponseCode.isSuccess(coapResponse.getCode())) {
    lwM2mresponse = OperationResponse
        .of(coapResponse, californiumClientIdentifierBuilder.getClientIdentifier());
  } else {
    lwM2mresponse = OperationResponse.failure(coapResponse.getCode(), "Request Failed on Server "
        + coapResponse.getOptions());
  }
}

代码示例来源:origin: org.eclipse.leshan/leshan-server-cf

private ValueResponse buildContentResponse(final LwM2mPath path, final Response coapResponse) {
  final ResponseCode code = ResponseCode.CONTENT;
  LwM2mNode content;
  try {
    content = LwM2mNodeDecoder.decode(coapResponse.getPayload(),
        ContentFormat.fromCode(coapResponse.getOptions().getContentFormat()), path);
  } catch (final InvalidValueException e) {
    final String msg = String.format("[%s] ([%s])", e.getMessage(), e.getPath().toString());
    throw new ResourceAccessException(code, path.toString(), msg, e);
  }
  return new ValueResponse(code, content);
}

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

protected boolean checkResponse(Request request, Response response) {
    boolean success = true;

    success &= checkType(Type.ACK, response.getType());
    success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
    success &= checkOption(MediaTypeRegistry.APPLICATION_LINK_FORMAT, response.getOptions().getContentFormat(), "Content-Format");
    success &= checkDiscoveryAttributes(EXPECTED_IF, response.getPayloadString());
    
    return success;
  }
}

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

protected boolean checkResponse(Request request, Response response) {
    boolean success = true;

    success &= checkType(Type.ACK, response.getType());
    success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
    success &= checkOption(MediaTypeRegistry.APPLICATION_LINK_FORMAT, response.getOptions().getContentFormat(), "Content-Format");
    success &= checkDiscoveryAttributes(EXPECTED_HREF, response.getPayloadString());

    return success;
  }
}

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

protected boolean checkResponse(Request request, Response response) {
    boolean success = true;

    success &= checkType(Type.ACK, response.getType());
    success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
    success &= checkOption(MediaTypeRegistry.APPLICATION_LINK_FORMAT, response.getOptions().getContentFormat(), "Content-Format");
    success &= hasNonEmptyPalyoad(response);
    success &= checkDiscoveryAttributes(EXPECTED_SZ, response.getPayloadString());

    return success;
  }
}

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

protected boolean checkResponse(Request request, Response response) {
    boolean success = true;

    success &= checkType(Type.ACK, response.getType());
    success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
    success &= checkOption(MediaTypeRegistry.APPLICATION_LINK_FORMAT, response.getOptions().getContentFormat(), "Content format");
    success &= hasNonEmptyPalyoad(response);
    success &= checkDiscoveryAttributes(EXPECTED_RT, response.getPayloadString());
    
    return success;
  }
}

相关文章