public OdlOnem2mCoapRequestPrimitiveBuilder setOperationRetrieve() { onem2mRequest.coapRequest = Request.newGet(); return this; } public OdlOnem2mCoapRequestPrimitiveBuilder setOperationUpdate() {
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); }
/** * 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); }
@Override public void visit(ReadRequest request) { coapRequest = Request.newGet(); setTarget(coapRequest, destination, request.getPath()); }
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"); }
/** * 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); }
@Override public void visit(DiscoverRequest request) { coapRequest = Request.newGet(); setTarget(coapRequest, request.getPath()); coapRequest.getOptions().setAccept(MediaTypeRegistry.APPLICATION_LINK_FORMAT); }
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; } }
@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())); }
@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)); }
@Override public void visit(ReadRequest request) { coapRequest = Request.newGet(); if (request.getContentFormat() != null) coapRequest.getOptions().setAccept(request.getContentFormat().getCode()); setTarget(coapRequest, request.getPath()); }
/** * 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")); }
/** * 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")); }
/** * 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/")); }
@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")); }
@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)); }
@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()); }
@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); }
@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")); }
@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()); }