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

x33g5p2x  于2022-01-26 转载在 其他  
字(3.4k)|赞(0)|评价(0)|浏览(63)

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

OptionSet.getUriHost介绍

[英]Returns the string value of the Uri-Host option.
[中]返回Uri主机选项的字符串值。

代码示例

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

@Test
public void testSetOptionsSetsUriHostOption() {
  Request req = Request.newGet();
  req.setDestination(InetAddress.getLoopbackAddress());
  req.setOptions(URI.create("coap://iot.eclipse.org"));
  assertThat(req.getDestinationPort(), is(CoAP.DEFAULT_COAP_PORT));
  assertThat(req.getOptions().getUriHost(), is("iot.eclipse.org"));
}

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

options.add(new Option(OptionNumberRegistry.IF_MATCH, value));
if (hasUriHost())
  options.add(new Option(OptionNumberRegistry.URI_HOST, getUriHost()));
if (etag_list != null) for (byte[] value:etag_list)
  options.add(new Option(OptionNumberRegistry.ETAG, value));

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

options.add(new Option(OptionNumberRegistry.IF_MATCH, value));
if (hasUriHost())
  options.add(new Option(OptionNumberRegistry.URI_HOST, getUriHost()));
if (etag_list != null) for (byte[] value:etag_list)
  options.add(new Option(OptionNumberRegistry.ETAG, value));

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

@Test
public void testSetURIDoesNotSetUriHostOptionForIp4Address() {
  Request req = Request.newGet().setURI("coap://192.168.0.1");
  assertNull(req.getOptions().getUriHost());
}

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

String host = getOptions().getUriHost();
if (host == null) {
  if (getDestination() != null) {

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

@Test
public void testSetURIDoesNotSetUriHostOptionForIp6Address() {
  // use www.google.com's IPv6 address
  Request req = Request.newGet().setURI("coap://[2a00:1450:4001:817::2003]");
  assertNull(req.getOptions().getUriHost());
}

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

String host = getOptions().getUriHost();
if (host == null) {
  if (getDestination() != null) {

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

@Test
public void testSetURISetsUriHostOptionToHostName() {
  assumeTrue(dnsIsWorking());
  Request req = Request.newGet().setURI("coaps://localhost");
  assertNotNull(req.getDestination());
  assertThat(req.getDestinationPort(), is(CoAP.DEFAULT_COAP_SECURE_PORT));
  assertThat(req.getOptions().getUriHost(), is("localhost"));
}

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

/**
 * Verifies that the URI examples from <a href="https://tools.ietf.org/html/rfc7252#section-6.3">
 * RFC 7252, Section 6.3</a> result in the same option values.
 * @throws URISyntaxException 
 */
@Test
public void testSetOptionsCompliesWithRfcExample() throws URISyntaxException {
  String[] exampleUris = new String[]{
      "coap://example.com:5683/~sensors/temp.xml",
      "coap://EXAMPLE.com/%7Esensors/temp.xml",
      "coap://EXAMPLE.com:/%7esensors/temp.xml"
  };
  for (String uriString : exampleUris) {
    URI uri = new URI(uriString);
    Request req = Request.newGet();
    // explicitly set destination address so that we do not rely on working DNS
    req.setDestination(InetAddress.getLoopbackAddress());
    req.setOptions(uri);
    assertThat(req.getOptions().getUriHost(), is("example.com"));
    assertThat(req.getDestinationPort(), is(5683));
    assertThat(req.getOptions().getUriPort(), is(nullValue()));
    assertThat(req.getOptions().getUriPathString(), is("~sensors/temp.xml"));
  }
}

相关文章

微信公众号

最新文章

更多