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

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

本文整理了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

  1. public OdlOnem2mCoapRequestPrimitiveBuilder setOperationRetrieve() {
  2. onem2mRequest.coapRequest = Request.newGet();
  3. return this;
  4. }
  5. public OdlOnem2mCoapRequestPrimitiveBuilder setOperationUpdate() {

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

  1. public CL01(String serverURI) {
  2. super(CL01.class.getSimpleName());
  3. // create the request
  4. Request request = Request.newGet();
  5. // set the parameters and execute the request
  6. executeRequest(request, serverURI, RESOURCE_URI);
  7. }

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

  1. /**
  2. * Sends a GET request and invokes the specified handler when a response
  3. * arrives.
  4. *
  5. * @param handler the Response handler
  6. */
  7. public void get(CoapHandler handler) {
  8. asynchronous(Request.newGet().setURI(uri), handler);
  9. }

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

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

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

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

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

  1. /**
  2. * Sends an observe request with the specified Accept option and invokes the
  3. * specified handler each time a notification arrives.
  4. *
  5. * @param handler the Response handler
  6. * @param accept the Accept option
  7. * @return the CoAP observe relation
  8. */
  9. public CoapObserveRelation observe(CoapHandler handler, int accept) {
  10. Request request = Request.newGet().setURI(uri).setObserve();
  11. return observe(accept(request, accept), handler);
  12. }

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

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

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

  1. private Exchange newOutboundRequest() {
  2. Request request = Request.newGet();
  3. request.setURI("coap://127.0.0.1:12000/test");
  4. Exchange exchange = new Exchange(request, Origin.LOCAL);
  5. return exchange;
  6. }
  7. }

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

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

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

  1. @Test
  2. public void testSetURISetsDestinationPortBasedOnUriScheme() {
  3. Request req = Request.newGet().setURI("coap://127.0.0.1");
  4. assertThat(req.getDestinationPort(), is(CoAP.DEFAULT_COAP_PORT));
  5. req = Request.newGet().setURI("coaps://127.0.0.1");
  6. assertThat(req.getDestinationPort(), is(CoAP.DEFAULT_COAP_SECURE_PORT));
  7. req = Request.newGet().setURI("coap+tcp://127.0.0.1");
  8. assertThat(req.getDestinationPort(), is(CoAP.DEFAULT_COAP_PORT));
  9. req = Request.newGet().setURI("coaps+tcp://127.0.0.1");
  10. assertThat(req.getDestinationPort(), is(CoAP.DEFAULT_COAP_SECURE_PORT));
  11. }

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

  1. @Override
  2. public void visit(ReadRequest request) {
  3. coapRequest = Request.newGet();
  4. if (request.getContentFormat() != null)
  5. coapRequest.getOptions().setAccept(request.getContentFormat().getCode());
  6. setTarget(coapRequest, request.getPath());
  7. }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. @Test
  2. public void testDiscoveryMultiFiltering() {
  3. Request request = Request.newGet();
  4. request.setURI("coap://localhost/.well-known/core?rt=light-lux&rt=temprature-cel");
  5. Exchange exchange = new Exchange(request, Origin.REMOTE);
  6. exchange.setRequest(request);
  7. exchange.setEndpoint(new DummyEndpoint());
  8. DiscoveryResource discovery = new DiscoveryResource(root);
  9. discovery.handleRequest(exchange);
  10. System.out.println(exchange.getResponse().getPayloadString());
  11. Assert.assertEquals(ResponseCode.BAD_OPTION, exchange.getResponse().getCode());
  12. }

相关文章