/** * Manage proxy uri request. * * @param request * the request * @throws URISyntaxException * the uRI syntax exception */ private void manageProxyUriRequest(Request request) throws URISyntaxException { // check which schema is requested URI proxyUri = new URI(request.getOptions().getProxyUri()); // the local resource that will abstract the client part of the // proxy String clientPath; // switch between the schema requested if (proxyUri.getScheme() != null && proxyUri.getScheme().matches("^http.*")) { // the local resource related to the http client clientPath = PROXY_HTTP_CLIENT; } else { // the local resource related to the http client clientPath = PROXY_COAP_CLIENT; } LOGGER.info("Chose "+clientPath+" as clientPath"); // set the path in the request to be forwarded correctly request.getOptions().setUriPath(clientPath); }
public void set(Request request) { request.getOptions().setUriPath(path); } });
public void set(Response response) { response.getOptions().setUriPath(path); } });
getOptions().setUriPath(path);
@Override public void visit(DeregisterRequest request) { coapRequest = Request.newDelete(); buildRequestSettings(); coapRequest.getOptions().setUriPath(request.getRegistrationId()); }
getOptions().setUriPath(path);
coapRequest.getOptions().setUriPath(uriString);
public Set<WebLink> discover(String query) { Request discover = Request.newGet(); discover.setURI(uri); // for scheme and authority, but then remove path and query discover.getOptions().clearUriPath().clearUriQuery().setUriPath("/.well-known/core"); if (query!=null) { discover.getOptions().setUriQuery(query); } CoapResponse links = synchronous(discover); // if no response, return null (e.g., timeout) if (links == null) { return null; } // check if Link Format if (links.getOptions().getContentFormat()!=MediaTypeRegistry.APPLICATION_LINK_FORMAT) return Collections.emptySet(); // parse and return return LinkFormat.parse(links.getResponseText()); }
public Set<WebLink> discover(String query) { Request discover = newGet(); discover.setURI(uri); // for scheme and authority, but then remove path and query discover.getOptions().clearUriPath().clearUriQuery().setUriPath("/.well-known/core"); if (query!=null) { discover.getOptions().setUriQuery(query); } CoapResponse links = synchronous(discover); // if no response, return null (e.g., timeout) if (links == null) { return null; } // check if Link Format if (links.getOptions().getContentFormat()!=MediaTypeRegistry.APPLICATION_LINK_FORMAT) return Collections.emptySet(); // parse and return return LinkFormat.parse(links.getResponseText()); }
options.setUriHost(uriNextHop.getHost()); options.setUriPort(uriNextHop.getPort()); options.setUriPath(path); if (null != query) { options.setUriQuery(query);
@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()); }
@Test public void testToString() { OptionSet options = new OptionSet(); options.addETag(new byte[] {1, 2, 3}); options.addETag(new byte[] {(byte)0xBE, (byte)0xEF}); options.addLocationPath("abc"); options.setUriPath("/this/is/a/test"); Assert.assertEquals("{\"ETag\":[0x010203,0xbeef], \"Location-Path\":\"abc\", \"Uri-Path\":[\"this\",\"is\",\"a\",\"test\"]}", options.toString()); options.setMaxAge(77); Assert.assertEquals("{\"ETag\":[0x010203,0xbeef], \"Location-Path\":\"abc\", \"Uri-Path\":[\"this\",\"is\",\"a\",\"test\"], \"Max-Age\":77}", options.toString()); } }
@Override public void visit(UpdateRequest request) { coapRequest = Request.newPost(); buildRequestSettings(); coapRequest.getOptions().setUriPath(request.getRegistrationId()); Long lifetime = request.getLifeTimeInSec(); if (lifetime != null) coapRequest.getOptions().addUriQuery("lt=" + lifetime); String smsNumber = request.getSmsNumber(); if (smsNumber != null) coapRequest.getOptions().addUriQuery("sms=" + smsNumber); BindingMode bindingMode = request.getBindingMode(); if (bindingMode != null) coapRequest.getOptions().addUriQuery("b=" + bindingMode.toString()); Link[] linkObjects = request.getObjectLinks(); if (linkObjects != null) { coapRequest.getOptions().setContentFormat(ContentFormat.LINK.getCode()); coapRequest.setPayload(Link.serialize(linkObjects)); } }