public OdlOnem2mCoapRequestPrimitiveBuilder setTo(String value) { onem2mRequest.optionsSet.addUriPath(value); // M3 onem2mRequest.optionsSet.addUriPath(value); return this; } public OdlOnem2mCoapRequestPrimitiveBuilder setFrom(String value) {
@Override public void accept(final Request coapRequest) { final String[] locationPaths = location.split("/"); for (final String location : locationPaths) { if (location.length() != 0) { coapRequest.getOptions().addUriPath(location); } } }
@Override public void accept(final Request coapRequest) { final String[] locationPaths = location.split("/"); for (final String location : locationPaths) { if (location.length() != 0) { coapRequest.getOptions().addUriPath(location); } } }
/** * Sets the complete relative Uri-Path. * Returns the current OptionSet object for a fluent API. * @param path the Uri-Path to set * @return this OptionSet */ public OptionSet setUriPath(String path) { final String slash = "/"; // remove leading slash if (path.startsWith(slash)) { path = path.substring(slash.length()); } clearUriPath(); for (String segment : path.split(slash)) { // empty path segments are allowed (e.g., /test vs /test/) addUriPath(segment); } return this; }
/** * Sets the complete relative Uri-Path. * Returns the current OptionSet object for a fluent API. * @param path the Uri-Path to set * @return this OptionSet */ public OptionSet setUriPath(String path) { final String slash = "/"; // remove leading slash if (path.startsWith(slash)) { path = path.substring(slash.length()); } clearUriPath(); for (String segment : path.split(slash)) { // empty path segments are allowed (e.g., /test vs /test/) addUriPath(segment); } return this; }
@Override public void visit(BootstrapFinishRequest request) { coapRequest = Request.newPost(); coapRequest.setConfirmable(true); EndpointContext context = EndpointContextUtil.extractContext(destination); coapRequest.setDestinationContext(context); // root path if (rootPath != null) { for (String rootPathPart : rootPath.split("/")) { if (!StringUtils.isEmpty(rootPathPart)) { coapRequest.getOptions().addUriPath(rootPathPart); } } } coapRequest.getOptions().addUriPath("bs"); }
private final void setTarget(Request coapRequest, LwM2mPath path) { EndpointContext context = EndpointContextUtil.extractContext(destination); coapRequest.setDestinationContext(context); // root path if (rootPath != null) { for (String rootPathPart : rootPath.split("/")) { if (!StringUtils.isEmpty(rootPathPart)) { coapRequest.getOptions().addUriPath(rootPathPart); } } } // objectId if (path.getObjectId() != null) { coapRequest.getOptions().addUriPath(Integer.toString(path.getObjectId())); } // objectInstanceId if (path.getObjectInstanceId() == null) { if (path.getResourceId() != null) { coapRequest.getOptions().addUriPath("0"); // default instanceId } } else { coapRequest.getOptions().addUriPath(Integer.toString(path.getObjectInstanceId())); } // resourceId if (path.getResourceId() != null) { coapRequest.getOptions().addUriPath(Integer.toString(path.getResourceId())); } }
private final void setTarget(Request coapRequest, Client client, LwM2mPath path) { coapRequest.setDestination(client.getAddress()); coapRequest.setDestinationPort(client.getPort()); // root path if (client.getRootPath() != null) { for (String rootPath : client.getRootPath().split("/")) { if (!StringUtils.isEmpty(rootPath)) { coapRequest.getOptions().addUriPath(rootPath); } } } // objectId coapRequest.getOptions().addUriPath(Integer.toString(path.getObjectId())); // objectInstanceId if (path.getObjectInstanceId() == null) { if (path.getResourceId() != null) { coapRequest.getOptions().addUriPath("0"); // default instanceId } } else { coapRequest.getOptions().addUriPath(Integer.toString(path.getObjectInstanceId())); } // resourceId if (path.getResourceId() != null) { coapRequest.getOptions().addUriPath(Integer.toString(path.getResourceId())); } }
@Override public void visit(RegisterRequest request) { coapRequest = Request.newPost(); buildRequestSettings(); coapRequest.getOptions().setContentFormat(ContentFormat.LINK.getCode()); coapRequest.getOptions().addUriPath("rd"); HashMap<String, String> attributes = new HashMap<>(); attributes.putAll(request.getAdditionalAttributes()); attributes.put("ep", request.getEndpointName()); Long lifetime = request.getLifetime(); if (lifetime != null) attributes.put("lt", lifetime.toString()); String smsNumber = request.getSmsNumber(); if (smsNumber != null) attributes.put("sms", smsNumber); String lwVersion = request.getLwVersion(); if (lwVersion != null) attributes.put("lwm2m", lwVersion); BindingMode bindingMode = request.getBindingMode(); if (bindingMode != null) attributes.put("b", bindingMode.toString()); for (Entry<String, String> attr : attributes.entrySet()) { coapRequest.getOptions().addUriQuery(attr.getKey() + "=" + attr.getValue()); } Link[] objectLinks = request.getObjectLinks(); if (objectLinks != null) coapRequest.setPayload(Link.serialize(objectLinks)); }
postServer.getOptions().addUriPath("1"); postServer.getOptions().addUriPath(key.toString()); postServer.setConfirmable(true); postServer.setDestination(targetAddress);
@Override public void visit(final BootstrapRequest request) { coapRequest = Request.newPost(); buildRequestSettings(request); coapRequest.getOptions().addUriPath("bs"); coapRequest.getOptions().addUriQuery("ep=" + request.getClientEndpointIdentifier()); parametersValid = true; }
@Override public void visit(final BootstrapRequest request) { coapRequest = Request.newPost(); buildRequestSettings(request); coapRequest.getOptions().addUriPath("bs"); coapRequest.getOptions().addUriQuery("ep=" + request.getClientEndpointIdentifier()); parametersValid = true; }
@Override public void visit(BootstrapRequest request) { coapRequest = Request.newPost(); buildRequestSettings(); coapRequest.getOptions().addUriPath("bs"); coapRequest.getOptions().addUriQuery("ep=" + request.getEndpointName()); }
/** * Verifies that the getURI method escapes non-ASCII characters contained in path and query. * @throws UnknownHostException */ @Test public void testGetURIEscapesNonAsciiCharacters() throws UnknownHostException { Request req = Request.newGet().setURI("coap://192.168.0.1"); req.getOptions().addUriPath("non-ascii-path-äöü").addUriQuery("non-ascii-query=äöü"); String derivedUri = req.getURI(); System.out.println(derivedUri); URI uri = URI.create(derivedUri); assertThat(uri.getRawPath(), is("/non-ascii-path-%C3%A4%C3%B6%C3%BC")); assertThat(uri.getRawQuery(), is("non-ascii-query=%C3%A4%C3%B6%C3%BC")); }
@Override public void visit(final RegisterRequest request) { if (!areParametersValid(request.getClientParameters())) { return; } coapRequest = Request.newPost(); buildRequestSettings(request); coapRequest.getOptions().addUriPath("rd"); coapRequest.getOptions().addUriQuery("ep=" + request.getClientEndpointIdentifier()); buildRequestContent(request); parametersValid = true; }
@Override public void visit(final RegisterRequest request) { if (!areParametersValid(request.getClientParameters())) { return; } coapRequest = Request.newPost(); buildRequestSettings(request); coapRequest.getOptions().addUriPath("rd"); coapRequest.getOptions().addUriQuery("ep=" + request.getClientEndpointIdentifier()); buildRequestContent(request); parametersValid = true; }
@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()); }
deleteAll.getOptions().addUriPath("/"); deleteAll.setConfirmable(true); deleteAll.setDestination(exchange.getSourceAddress());
case OptionNumberRegistry.URI_PORT: setUriPort(option.getIntegerValue()); break; case OptionNumberRegistry.LOCATION_PATH: addLocationPath(option.getStringValue()); break; case OptionNumberRegistry.URI_PATH: addUriPath(option.getStringValue()); break; case OptionNumberRegistry.CONTENT_FORMAT: setContentFormat(option.getIntegerValue()); break; case OptionNumberRegistry.MAX_AGE: setMaxAge(option.getLongValue()); break;
case OptionNumberRegistry.URI_PORT: setUriPort(option.getIntegerValue()); break; case OptionNumberRegistry.LOCATION_PATH: addLocationPath(option.getStringValue()); break; case OptionNumberRegistry.URI_PATH: addUriPath(option.getStringValue()); break; case OptionNumberRegistry.CONTENT_FORMAT: setContentFormat(option.getIntegerValue()); break; case OptionNumberRegistry.MAX_AGE: setMaxAge(option.getLongValue()); break;