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

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

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

Request.newGet介绍

[英]Convenience factory method to construct a GET request and equivalent to new Request(Code.GET);
[中]构造GET请求的便利工厂方法,等价于new Request(Code.GET);

代码示例

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

public OdlOnem2mCoapRequestPrimitiveBuilder setOperationRetrieve() {
  onem2mRequest.coapRequest = Request.newGet();
  return this;
}
public OdlOnem2mCoapRequestPrimitiveBuilder setOperationUpdate() {

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

public CL01(String serverURI) {
  super(CL01.class.getSimpleName());
  // create the request
  Request request = Request.newGet();
  
  // set the parameters and execute the request
  executeRequest(request, serverURI, RESOURCE_URI);
}

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

/**
 * Sends a GET request and invokes the specified handler when a response
 * arrives.
 *
 * @param handler the Response handler
 */
public void get(CoapHandler handler) {
  asynchronous(Request.newGet().setURI(uri), handler);
}

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

@Override
public void visit(ReadRequest request) {
  coapRequest = Request.newGet();
  setTarget(coapRequest, destination, request.getPath());
}

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

public CB01(String serverURI) {
  super(CB01.class.getSimpleName());
  Request request = Request.newGet();
  request.getOptions().setBlock2(BlockOption.size2Szx(64), false, 0);
  // set the parameters and execute the request
  executeRequest(request, serverURI, "/large");
}

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

/**
 * Sends an observe request with the specified Accept option and invokes the
 * specified handler each time a notification arrives.
 *
 * @param handler the Response handler
 * @param accept the Accept option
 * @return the CoAP observe relation
 */
public CoapObserveRelation observe(CoapHandler handler, int accept) {
  Request request = Request.newGet().setURI(uri).setObserve();
  return observe(accept(request, accept), handler);
}

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

@Override
public void visit(DiscoverRequest request) {
  coapRequest = Request.newGet();
  setTarget(coapRequest, request.getPath());
  coapRequest.getOptions().setAccept(MediaTypeRegistry.APPLICATION_LINK_FORMAT);
}

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

private Exchange newOutboundRequest() {
    Request request = Request.newGet();
    request.setURI("coap://127.0.0.1:12000/test");
    Exchange exchange = new Exchange(request, Origin.LOCAL);
    return exchange;
  }
}

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

@Test
public void testSetURISetsDestination() {
  InetSocketAddress dest = InetSocketAddress.createUnresolved("192.168.0.1", 12000);
  Request req = Request.newGet().setURI("coap://192.168.0.1:12000");
  assertThat(req.getDestination().getHostAddress(), is(dest.getHostString()));
  assertThat(req.getDestinationPort(), is(dest.getPort()));
}

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

@Test
public void testSetURISetsDestinationPortBasedOnUriScheme() {
  Request req = Request.newGet().setURI("coap://127.0.0.1");
  assertThat(req.getDestinationPort(), is(CoAP.DEFAULT_COAP_PORT));
  req = Request.newGet().setURI("coaps://127.0.0.1");
  assertThat(req.getDestinationPort(), is(CoAP.DEFAULT_COAP_SECURE_PORT));
  req = Request.newGet().setURI("coap+tcp://127.0.0.1");
  assertThat(req.getDestinationPort(), is(CoAP.DEFAULT_COAP_PORT));
  req = Request.newGet().setURI("coaps+tcp://127.0.0.1");
  assertThat(req.getDestinationPort(), is(CoAP.DEFAULT_COAP_SECURE_PORT));
}

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

@Override
public void visit(ReadRequest request) {
  coapRequest = Request.newGet();
  if (request.getContentFormat() != null)
    coapRequest.getOptions().setAccept(request.getContentFormat().getCode());
  setTarget(coapRequest, request.getPath());
}

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

/**
 * Verifies that a URI with "path" and without "query part" is well formed.
 */
@Test
public void testGetURIWithPathAndWithoutQuery() {
  Request req = Request.newGet().setURI("coap://192.168.0.1:12000/30/40");
  String uri = req.getURI();
  assertThat(uri, is("coap://192.168.0.1:12000/30/40"));
}

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

/**
 * Verifies that a URI without "path" and with "query part" is well formed.
 */
@Test
public void testGetURIWithoutPathAndWithQuery() {
  Request req = Request.newGet().setURI("coap://192.168.0.1:12000?parameter");
  String uri = req.getURI();
  assertThat(uri, is("coap://192.168.0.1:12000/?parameter"));
}

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

/**
 * Verifies that a URI without "path" and "query part" is well formed.
 */
@Test
public void testGetURIWithoutPathAndQuery() {
  Request req = Request.newGet().setURI("coap://192.168.0.1:12000");
  String uri = req.getURI();
  assertThat(uri, is("coap://192.168.0.1:12000/"));
}

代码示例来源: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/leshan

@Override
public void visit(ObserveRequest request) {
  coapRequest = Request.newGet();
  if (request.getContentFormat() != null)
    coapRequest.getOptions().setAccept(request.getContentFormat().getCode());
  coapRequest.setObserve();
  setTarget(coapRequest, request.getPath());
  // add context info to the observe request
  coapRequest.setUserContext(ObserveUtil.createCoapObserveRequestContext(endpoint, registrationId, request));
}

代码示例来源: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: eclipse/californium

@Test
public void testDiscoveryFiltering() {
  final String expectedTree = "</sensors/light>;if=\"sensor\";rt=\"light-lux\"";
  Request request = Request.newGet();
  request.setURI("coap://localhost/.well-known/core?rt=light-lux");
  DiscoveryResource discovery = new DiscoveryResource(root);
  String serialized = discovery.discoverTree(root, request.getOptions().getUriQuery());
  System.out.println(serialized);
  Assert.assertEquals(expectedTree, serialized);
}

代码示例来源: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

@Test
public void testDiscoveryMultiFiltering() {
  Request request = Request.newGet();
  request.setURI("coap://localhost/.well-known/core?rt=light-lux&rt=temprature-cel");

  Exchange exchange = new Exchange(request, Origin.REMOTE);
  exchange.setRequest(request);
  exchange.setEndpoint(new DummyEndpoint());
  
  DiscoveryResource discovery = new DiscoveryResource(root);
  
  discovery.handleRequest(exchange);
  System.out.println(exchange.getResponse().getPayloadString());
  Assert.assertEquals(ResponseCode.BAD_OPTION, exchange.getResponse().getCode());
}

相关文章

微信公众号

最新文章

更多