本文整理了Java中org.eclipse.californium.core.coap.Request.setURI
方法的一些代码示例,展示了Request.setURI
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.setURI
方法的具体详情如下:
包路径:org.eclipse.californium.core.coap.Request
类名称:Request
方法名:setURI
[英]Sets this request's CoAP URI.
[中]设置此请求的CoAP URI。
代码示例来源:origin: eclipse/californium
private void assignClientUriIfEmpty(Request request) {
// request.getUri() is a computed getter and never returns null so checking destination
if (request.getDestination() == null) {
request.setURI(uri);
}
}
代码示例来源:origin: eclipse/californium
/**
* Sends a GET request and blocks until the response is available.
*
* @return the CoAP response
*/
public CoapResponse get() {
return synchronous(newGet().setURI(uri));
}
代码示例来源:origin: eclipse/californium
/**
* Sends a GET request and invokes the specified handler when a response
* arrives.
*
* @param handler the Response handler
*/
public void get(CoapHandler handler) {
asynchronous(newGet().setURI(uri), handler);
}
代码示例来源:origin: eclipse/californium
/**
* Sends a DELETE request and waits for the response.
*
* @return the CoAP response
*/
public CoapResponse delete() {
return synchronous(newDelete().setURI(uri));
}
代码示例来源:origin: eclipse/californium
/**
* Sends a DELETE request and invokes the specified handler when a response
* arrives.
*
* @param handler the response handler
*/
public void delete(CoapHandler handler) {
asynchronous(newDelete().setURI(uri), handler);
}
代码示例来源:origin: eclipse/californium
/**
* Sends an observe request and invokes the specified handler each time
* a notification arrives.
*
* @param handler the Response handler
* @return the CoAP observe relation
*/
public CoapObserveRelation observe(CoapHandler handler) {
Request request = newGet().setURI(uri).setObserve();
return observe(request, handler);
}
代码示例来源:origin: eclipse/californium
/**
* Sends a PUT request with payload and required Content-Format and blocks
* until the response is available.
*
* @param payload the payload
* @param format the Content-Format
* @return the CoAP response
*/
public CoapResponse put(byte[] payload, int format) {
return synchronous(format(newPut().setURI(uri).setPayload(payload), format));
}
代码示例来源:origin: eclipse/californium
/**
* 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 = newGet().setURI(uri).setObserve();
return observe(accept(request, accept), handler);
}
代码示例来源:origin: eclipse/californium
/**
* Sends a PUT request with the specified payload and the specified content
* format and invokes the specified handler when a response arrives.
*
* @param handler the Response handler
* @param payload the payload
* @param format the Content-Format
*/
public void put(CoapHandler handler, String payload, int format) {
asynchronous(format(newPut().setURI(uri).setPayload(payload), format), handler);
}
代码示例来源:origin: eclipse/californium
/**
* Sends a POST request with the specified payload and the specified content
* format and invokes the specified handler when a response arrives.
*
* @param handler the Response handler
* @param payload the payload
* @param format the Content-Format
*/
public void post(CoapHandler handler, String payload, int format) {
asynchronous(format(newPost().setURI(uri).setPayload(payload), format), handler);
}
代码示例来源:origin: eclipse/californium
/**
* Sends a PUT request with the specified payload and the specified content
* format and invokes the specified handler when a response arrives.
*
* @param handler the Response handler
* @param payload the payload
* @param format the Content-Format
*/
public void put(CoapHandler handler, byte[] payload, int format) {
asynchronous(format(newPut().setURI(uri).setPayload(payload), format), handler);
}
代码示例来源:origin: eclipse/californium
public static Request createRequest(Code code, String path, LockstepEndpoint server) throws Exception {
Request request = new Request(code);
String uri = String.format("coap://%s:%d/%s", server.getAddress().getHostAddress(), server.getPort(), path);
request.setURI(uri);
return request;
}
代码示例来源:origin: eclipse/californium
/**
* Sends a PUT request with the If-None-Match option set and blocks until
* the response is available.
*
* @param payload the payload string
* @param format the Content-Format
* @return the CoAP response
*/
public CoapResponse putIfNoneMatch(String payload, int format) {
return synchronous(ifNoneMatch(format(newPut().setURI(uri).setPayload(payload), format)));
}
代码示例来源:origin: eclipse/californium
/**
*
* @param handler the Response handler
* @param payload the payload
* @param format the Content-Format
* @param etags the ETags for the If-Match option
*/
public void putIfMatch(CoapHandler handler, String payload, int format, byte[] ... etags) {
asynchronous(ifMatch(format(newPut().setURI(uri).setPayload(payload), format), etags), handler);
}
代码示例来源: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/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 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());
}
代码示例来源:origin: eclipse/californium
@Test
public void testAdvancedUsesUriFromRequest() throws Exception {
String nonExistingUri = TestTools.getUri(serverEndpoint, "non-existing");
CoapClient client = new CoapClient(nonExistingUri).useExecutor();
Request request = new Request(Code.GET, Type.CON);
String uri = TestTools.getUri(serverEndpoint, TARGET);
request.setURI(uri);
CoapResponse resp = client.advanced(request);
Assert.assertEquals(Type.ACK, resp.advanced().getType());
Assert.assertEquals(CONTENT_1, resp.getResponseText());
}
内容来源于网络,如有侵权,请联系作者删除!