System.out.println (response.getOptions ()); System.out.println (response.getResponseText ());
private void prepareReregistration(CoapResponse response, long backoff) { if (!isCanceled()) { long timeout = response.getOptions().getMaxAge() * 1000 + backoff; ScheduledFuture<?> f = scheduler.schedule(new Runnable() { @Override public void run() { reregister(); } }, timeout, TimeUnit.MILLISECONDS); setReregistrationHandle(f); } } }
@Override public void onLoad(CoapResponse response) { OptionSet os = response.getOptions(); nextExpectedMessage = os.getMaxAge() * 2 + (System.currentTimeMillis() / 1000); postStreamElement(new Serializable[]{response.getPayload()}); }
private void prepareReregistration(CoapResponse response, long backoff) { if (!isCanceled()) { long timeout = response.getOptions().getMaxAge() * 1000 + backoff; ScheduledFuture<?> f = scheduler.schedule(new Runnable() { @Override public void run() { reregister(); } }, timeout, TimeUnit.MILLISECONDS); setReregistrationHandle(f); } } }
System.out.println(response.getOptions()); if (args.length > 1) { try (FileOutputStream out = new FileOutputStream(args[1])) {
public void test() { CoapResponse response = null; try { URI uri = new URI(SERVER_URI); CoapClient client = new CoapClient(uri); client.setEndpoint(new CoapEndpoint(dtlsConnector, NetworkConfig.getStandard())); response = client.get(); } catch (URISyntaxException e) { System.err.println("Invalid URI: " + e.getMessage()); System.exit(-1); } if (response != null) { System.out.println(response.getCode()); System.out.println(response.getOptions()); System.out.println(response.getResponseText()); System.out.println("\nADVANCED\n"); System.out.println(Utils.prettyPrint(response)); } else { System.out.println("No response received."); } }
/** * Handle a CoAP response. * * @param response * @throws Exception */ private static void handleResponse(CoapResponse response) throws Exception { if (response != null) { System.out.println(response.getCode()); System.out.println(response.getOptions()); System.out.println(response.getResponseText()); } else { throw new Exception("Response was null."); } } }
String mt = MediaTypeRegistry.toString(response.getOptions().getContentFormat()); resp.setHeader(org.apache.camel.Exchange.CONTENT_TYPE, mt); resp.setHeader(CoAPConstants.COAP_RESPONSE_CODE, response.getCode().toString());
System.out.println("---------------\nPOST /large-create\n---------------"); response = client.post(getLargeRequestPayload(), MediaTypeRegistry.TEXT_PLAIN); System.out.println(response.getCode() + " - " + response.getOptions().getLocationString()); System.out.println(response.getResponseText()); client.setURI(uri + response.getOptions().getLocationString()); System.out.println("---------------\nGET " + response.getOptions().getLocationString() + "\n---------------"); response = client.get(); System.out.println(response.getCode());
long timeout = relation4.getCurrent().getOptions().getMaxAge(); try { Thread.sleep(6*1000); } catch (InterruptedException e) { } System.out.println("---------------\nReboot Server");
System.out.println("---------------\nPOST /test for Location-Path\n---------------"); response = client.post("TD_COAP_CORE_18", MediaTypeRegistry.TEXT_PLAIN); System.out.println(response.getCode() + "-" + response.getOptions().getLocationString()); System.out.println(response.getResponseText()); System.out.println("---------------\nGET /location-query\n---------------"); response = client.post("query", MediaTypeRegistry.TEXT_PLAIN); System.out.println(response.getCode() + "-" + response.getOptions().getLocationString()); System.out.println(response.getResponseText()); System.out.println("---------------\nGET /multi-format text/plain\n---------------"); response = client.get(MediaTypeRegistry.TEXT_PLAIN); System.out.println(response.getCode() + "-" + MediaTypeRegistry.toString(response.getOptions().getContentFormat())); System.out.println(response.getResponseText()); System.out.println("---------------\nGET /multi-format application/xml\n---------------"); response = client.get(MediaTypeRegistry.APPLICATION_XML); System.out.println(response.getCode() + "-" + MediaTypeRegistry.toString(response.getOptions().getContentFormat())); System.out.println(response.getResponseText()); System.out.println("---------------\nGET /validate\n---------------"); response = client.get(); if (response.getOptions().getETagCount()==1) { etag = response.getOptions().getETags().get(0); System.out.println(response.getCode() + " - ETag [" + Utils.toHexString(etag) + "]"); System.out.println(response.getResponseText()); etag = response.getOptions().getETags().get(0); System.out.println(response.getCode() + " - ETag [" + Utils.toHexString(etag) + "]"); System.out.println(response.getResponseText());
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()); }
if (response != null && !response.getOptions().hasObserve()) { throw new IllegalStateException("observe not supported by CoAP server!");
if (response != null && !response.getOptions().hasObserve()) { throw new IllegalStateException("observe not supported by CoAP server!");