@Override public boolean accept(ObserveRelation relation) { String relationURI = relation.getExchange().getRequest().getOptions().getUriPathString(); boolean result = relationURI.equals(notifyURI); if (LOG.isTraceEnabled()) { LOG.trace("observe " + relationURI + " / " + notifyURI + ": " + result); } return result; }
public void check(Request request) { assertEquals(path, request.getOptions().getUriPathString()); print("Correct URI path: " + path); } });
protected final void appendRequestDetails(final Request request) { if (request.isCanceled()) { buffer.append("CANCELED "); } buffer.append(request.getType()).append(" [MID=").append(request.getMID()) .append(", T=").append(request.getTokenString()).append("], ") .append(request.getCode()).append(", /").append(request.getOptions().getUriPathString()); appendBlockOption(1, request.getOptions().getBlock1()); appendBlockOption(2, request.getOptions().getBlock2()); appendObserveOption(request.getOptions()); appendSize1(request.getOptions()); appendEtags(request.getOptions()); }
@Override public void handleDELETE(CoapExchange exchange) { if (!StringUtils.isEmpty(exchange.getRequestOptions().getUriPathString())) { exchange.respond(ResponseCode.METHOD_NOT_ALLOWED); return; } ServerIdentity identity = ResourceUtil.extractServerIdentity(exchange, bootstrapHandler); BootstrapDeleteResponse response = bootstrapHandler.delete(identity, new BootstrapDeleteRequest()); exchange.respond(toCoapResponseCode(response.getCode()), response.getErrorMessage()); } }
@Test public void testUriOptions() { OptionSet options = new OptionSet(); options.setUriPath("/foo/bar"); Assert.assertEquals("Uri-Path", "foo/bar", options.getUriPathString()); options.setUriPath("foo/bar"); Assert.assertEquals("Uri-Path", "foo/bar", options.getUriPathString()); options.setUriPath("//foo/bar"); Assert.assertEquals("Uri-Path", "/foo/bar", options.getUriPathString()); options.setUriPath("/foo//bar"); Assert.assertEquals("Uri-Path", "foo//bar", options.getUriPathString()); options.clearUriPath(); options.addUriPath("foo"); options.addUriPath("bar"); Assert.assertEquals("Uri-Path", "foo/bar", options.getUriPathString()); options.clearUriPath(); options.addUriPath("foo"); options.addUriPath(""); options.addUriPath("bar"); Assert.assertEquals("Uri-Path", "foo//bar", options.getUriPathString()); }
String path = "/" + getOptions().getUriPathString(); String query = getOptions().getURIQueryCount() > 0 ? getOptions().getUriQueryString() : null; try {
String path = "/" + getOptions().getUriPathString(); String query = getOptions().getURIQueryCount() > 0 ? getOptions().getUriQueryString() : null; try {
/** * 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")); } }
String tmpUrl = options.getUriPathString(); LOG.info("Processed URL", tmpUrl); request.setUrl(tmpUrl);
ResourceIdentifier.from(endpointName, device.getTenantId(), device.getDeviceId()), sender.isRegistrationAssertionRequired(), "/" + exchange.getRequestOptions().getUriPathString(), contentType, payload,
@Override public void handleDELETE(CoapExchange coapExchange) { // Manage Delete Request String URI = coapExchange.getRequestOptions().getUriPathString(); ServerIdentity identity = extractServerIdentity(coapExchange, bootstrapHandler); if (identity.isLwm2mBootstrapServer()) { BootstrapDeleteResponse response = nodeEnabler.delete(identity, new BootstrapDeleteRequest(URI)); if (response.getCode().isError()) { coapExchange.respond(toCoapResponseCode(response.getCode()), response.getErrorMessage()); } else { coapExchange.respond(toCoapResponseCode(response.getCode())); } } else { DeleteResponse response = nodeEnabler.delete(identity, new DeleteRequest(URI)); if (response.getCode().isError()) { coapExchange.respond(toCoapResponseCode(response.getCode()), response.getErrorMessage()); } else { coapExchange.respond(toCoapResponseCode(response.getCode())); } } }
@Override public void handlePOST(CoapExchange exchange) { ServerIdentity identity = extractServerIdentity(exchange, bootstrapHandler); String URI = exchange.getRequestOptions().getUriPathString();
clientBuilder.setTo(Onem2m.translateUriToOnem2m(options.getUriPathString())); // To/TargetURI
@Override public void handlePUT(CoapExchange coapExchange) { ServerIdentity identity = extractServerIdentity(coapExchange, bootstrapHandler); String URI = coapExchange.getRequestOptions().getUriPathString();
@Override public void handleGET(CoapExchange exchange) { ServerIdentity identity = extractServerIdentity(exchange, bootstrapHandler); String URI = exchange.getRequestOptions().getUriPathString();