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

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

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

Request.setOptions介绍

[英]Sets this request's options from a given URI as defined in RFC 7252, Section 6.4.

This method requires the destination to be set already because it does not try to resolve a host name that is part of the given URI. Therefore, this method can be used as an alternative to the #setURI(String) and #setURI(URI) methods when DNS is not available.
[中]根据RFC 7252, Section 6.4中定义的给定URI设置此请求的选项。
此方法要求已设置destination,因为它不会尝试解析作为给定URI一部分的主机名。因此,当DNS不可用时,此方法可以用作#setURI(String)和#setURI(URI)方法的替代方法。

代码示例

代码示例来源:origin: org.opendaylight.iotdm/onem2mbenchmark-impl

public OdlOnem2mCoapRequestPrimitive build() {
    onem2mRequest.optionsSet.addUriQuery(onem2mRequest.uriQueryString);
    // M3 onem2mRequest.optionsSet.addUriQuery(onem2mRequest.uriQueryString);
    onem2mRequest.coapRequest.setOptions(onem2mRequest.optionsSet);
    return (onem2mRequest);
  }
}

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

/**
 * Sets the destination address and port and options from a given URI.
 * <p>
 * This method sets the <em>destination</em> to the IP address that the host part of the URI
 * has been resolved to and then delegates to the {@link #setOptions(URI)} method in order
 * to populate the request's options.
 * 
 * @param uri The target URI.
 * @return This request for command chaining.
 * @throws NullPointerException if the URI is {@code null}.
 * @throws IllegalArgumentException if the URI contains a non-resolvable host name, an
 *                                  unsupported scheme or a fragment.
 */
public Request setURI(final URI uri) {
  if (uri == null) {
    throw new NullPointerException("URI must not be null");
  }
  final String host = uri.getHost() == null ? "localhost" : uri.getHost();
  try {
    InetAddress destAddress = InetAddress.getByName(host);
    setDestination(destAddress);
    return setOptions(new URI(uri.getScheme(), null, host, uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()));
  } catch (UnknownHostException e) {
    throw new IllegalArgumentException("cannot resolve host name: " + host);
  } catch (URISyntaxException e) {
    // should not happen because we are creating the URI from an existing URI object
    LOGGER.log(Level.WARNING, "cannot set URI on request", e);
    throw new IllegalArgumentException(e);
  }
}

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

/**
 * Sets the destination address and port and options from a given URI.
 * <p>
 * This method sets the <em>destination</em> to the IP address that the host part of the URI
 * has been resolved to and then delegates to the {@link #setOptions(URI)} method in order
 * to populate the request's options.
 * 
 * @param uri The target URI.
 * @return This request for command chaining.
 * @throws NullPointerException if the URI is {@code null}.
 * @throws IllegalArgumentException if the URI contains a non-resolvable host name, an
 *                                  unsupported scheme or a fragment.
 */
public Request setURI(final URI uri) {
  if (uri == null) {
    throw new NullPointerException("URI must not be null");
  }
  final String host = uri.getHost() == null ? "localhost" : uri.getHost();
  try {
    InetAddress destAddress = InetAddress.getByName(host);
    setDestination(destAddress);
    return setOptions(new URI(uri.getScheme(), null, host, uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()));
  } catch (UnknownHostException e) {
    throw new IllegalArgumentException("cannot resolve host name: " + host);
  } catch (URISyntaxException e) {
    // should not happen because we are creating the URI from an existing URI object
    LOGGER.log(Level.WARNING, "cannot set URI on request", e);
    throw new IllegalArgumentException(e);
  }
}

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

@Test(expected = IllegalStateException.class)
public void testSetOptionsFailsIfDestinationIsNotSet() {
  Request.newGet().setOptions(URI.create("coap://iot.eclipse.org"));
}

代码示例来源: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: org.opendaylight.iotdm/onem2m-protocol-coap

request.setOptions(options);
return request;

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

options.clearUriPath();
options.clearUriQuery();
outgoingRequest.setOptions(options);

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

options.clearUriPath();
options.clearUriQuery();
outgoingRequest.setOptions(options);

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

refresh.setOptions(request.getOptions());

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

refresh.setOptions(request.getOptions());

代码示例来源: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"));
  }
}

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

/**
 * Send request with option "cancel observe" (GET with Observe=1).
 */
private void sendCancelObserve() {
  Request request = this.request;
  Request cancel = Request.newGet();
  cancel.setDestination(request.getDestination());
  cancel.setDestinationPort(request.getDestinationPort());
  // use same Token
  cancel.setToken(request.getToken());
  // copy options, but set Observe to cancel
  cancel.setOptions(request.getOptions());
  cancel.setObserveCancel();
  
  // dispatch final response to the same message observers
  for (MessageObserver mo: request.getMessageObservers()) {
    cancel.addMessageObserver(mo);
  }
  
  endpoint.sendRequest(cancel);
}

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

private static Request getNextRequestBlock(final Request request, final BlockwiseStatus status) {
  int num = status.getCurrentNum();
  int szx = status.getCurrentSzx();
  Request block = new Request(request.getCode());
  // do not enforce CON, since NON could make sense over SMS or similar transports
  block.setType(request.getType());
  block.setDestination(request.getDestination());
  block.setDestinationPort(request.getDestinationPort());
  // copy options
  block.setOptions(new OptionSet(request.getOptions()));
  // copy message observers so that a failing blockwise request also notifies observers registered with
  // the original request
  block.addMessageObservers(request.getMessageObservers());
  int currentSize = 1 << (4 + szx);
  int from = num * currentSize;
  int to = Math.min((num + 1) * currentSize, request.getPayloadSize());
  int length = to - from;
  byte[] blockPayload = new byte[length];
  System.arraycopy(request.getPayload(), from, blockPayload, 0, length);
  block.setPayload(blockPayload);
  boolean m = (to < request.getPayloadSize());
  block.getOptions().setBlock1(szx, m, num);
  status.setComplete(!m);
  return block;
}

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

private static Request getNextRequestBlock(final Request request, final BlockwiseStatus status) {
  int num = status.getCurrentNum();
  int szx = status.getCurrentSzx();
  Request block = new Request(request.getCode());
  // do not enforce CON, since NON could make sense over SMS or similar transports
  block.setType(request.getType());
  block.setDestination(request.getDestination());
  block.setDestinationPort(request.getDestinationPort());
  // copy options
  block.setOptions(new OptionSet(request.getOptions()));
  // copy message observers so that a failing blockwise request also notifies observers registered with
  // the original request
  block.addMessageObservers(request.getMessageObservers());
  int currentSize = 1 << (4 + szx);
  int from = num * currentSize;
  int to = Math.min((num + 1) * currentSize, request.getPayloadSize());
  int length = to - from;
  byte[] blockPayload = new byte[length];
  System.arraycopy(request.getPayload(), from, blockPayload, 0, length);
  block.setPayload(blockPayload);
  boolean m = (to < request.getPayloadSize());
  block.getOptions().setBlock1(szx, m, num);
  status.setComplete(!m);
  return block;
}

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

/**
 * Send request with option "cancel observe" (GET with Observe=1).
 */
private void sendCancelObserve() {
  Request request = this.request;
  Request cancel = Request.newGet();
  cancel.setDestination(request.getDestination());
  cancel.setDestinationPort(request.getDestinationPort());
  // use same Token
  cancel.setToken(request.getToken());
  // copy options, but set Observe to cancel
  cancel.setOptions(request.getOptions());
  cancel.setObserveCancel();
  // dispatch final response to the same message observers
  for (MessageObserver mo : request.getMessageObservers()) {
    cancel.addMessageObserver(mo);
  }
  endpoint.sendRequest(cancel);
}

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

block.setOptions(new OptionSet(request.getOptions()));

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

block.setOptions(new OptionSet(request.getOptions()));

相关文章