CoapResponse response = client.get ();
private static void getResourceAndAssertPayload(final CoapClient client, final String expectedPayload) { System.out.println(String.format("doing a blockwise GET on: %s", client.getURI())); long start = System.currentTimeMillis(); CoapResponse response = client.get(); long end = System.currentTimeMillis(); assertThat("Blockwise GET timed out after " + (end - start) + "ms", response, is(notNullValue())); System.out.println(String.format("Received %d bytes after %dms", response.getPayload().length, end - start)); assertThat("Did not receive expected resource body", response.getResponseText(), is(expectedPayload)); } }
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."); } }
CoapResponse response = client.get();
@Test public void testAsyncGetTriggersOnLoad() throws Exception { final CountDownLatch latch = new CountDownLatch(1); // Check that we get the right content when calling get() client.get(new TestHandler("Test 1") { @Override public void onLoad(CoapResponse response) { if (CONTENT_1.equals(response.getResponseText())) { latch.countDown(); } } }); assertTrue(latch.await(1, TimeUnit.SECONDS)); }
client.get(new CoapHandler() { @Override public void onLoad(CoapResponse response) {
client.setURI(link.getURI()); System.out.println("---------------\nGET " + link.getURI() + " with ct=40\n---------------"); Set<WebLink> links2 = LinkFormat.parse(client.get(MediaTypeRegistry.APPLICATION_LINK_FORMAT).getResponseText()); System.out.println("Found " + links2.size() + " resource(s)"); for (WebLink link2 : links2) { client.setURI(link2.getURI()); System.out.println("---------------\nGET " + link2.getURI() + "\n---------------"); CoapResponse response = client.get(); System.out.println(response.advanced().getType() + "-" + response.getCode()); System.out.println(response.getResponseText());
@Override public Serializable doSend(Message message, MeasurementUnit measurementUnit) throws Exception { switch (method) { case GET: coapResponse = client.get(); break; case POST: coapResponse = client.post(message.getPayload().toString(), MediaTypeRegistry.TEXT_PLAIN); break; case PUT: coapResponse = client.put(message.getPayload().toString(), MediaTypeRegistry.TEXT_PLAIN); break; case DELETE: coapResponse = client.delete(); break; } return coapResponse.getResponseText(); }
switch (method) { case CoAPConstants.METHOD_GET: response = client.get(); break; case CoAPConstants.METHOD_DELETE:
CoapClient client = new CoapClient(uri); client.setEndpoint(endPoint); CoapResponse response = client.get(); if (response == null) { System.out.println("Connection to Gateway timed out, please check ip address or increase the ACK_TIMEOUT in the Californium.properties file"); CoapClient client = new CoapClient(uri); client.setEndpoint(endPoint); CoapResponse response = client.get(); if (response == null) { System.out.println("Connection to Gateway timed out, please check ip address or increase the ACK_TIMEOUT in the Californium.properties file"); CoapClient client = new CoapClient(sceneURI); client.setEndpoint(endPoint); CoapResponse responseRooms = client.get(); if (responseRooms == null) { System.out.println("Connection to Gateway timed out, please check ip address or increase the ACK_TIMEOUT in the Californium.properties file"); client = new CoapClient(moodUri); client.setEndpoint(endPoint); CoapResponse responseMoods = client.get(); if (responseMoods == null) { System.out.println("Connection to Gateway timed out, please check ip address or increase the ACK_TIMEOUT in the Californium.properties file");
response = client.get(); System.out.println(response.getCode()); System.out.println(response.getResponseText()); response = client.get(); System.out.println(response.getCode()); System.out.println(response.getResponseText()); response = client.get(); System.out.println(response.getCode()); System.out.println(response.getResponseText()); response = client.get(); System.out.println(response.getCode()); System.out.println(response.getResponseText());
@Test public void testAsyncGetUsingBuilder() throws Exception { final CountDownLatch latch = new CountDownLatch(1); // Try to use the builder and add a query new CoapClient.Builder(serverAddress.getHostString(), serverAddress.getPort()) .path(TARGET).query(QUERY_UPPER_CASE).create() .get(new TestHandler("Test 8") { @Override public void onLoad(CoapResponse response) { if (CONTENT_1.toUpperCase().equals(response.getResponseText())) { latch.countDown(); } } } ); assertTrue(latch.await(1, TimeUnit.SECONDS)); }
response = client.get(); System.out.println(response.advanced().getType() + "-" + response.getCode()); System.out.println(response.getResponseText()); response = client.get(); System.out.println(response.advanced().getType() + "-" + response.getCode()); System.out.println(response.getResponseText()); response = client.get(); System.out.println(response.advanced().getType() + "-" + response.getCode()); System.out.println(response.getResponseText()); response = client.get(); System.out.println(response.advanced().getType() + "-" + response.getCode()); System.out.println(response.getResponseText()); response = client.get(); System.out.println(response.advanced().getType() + "-" + response.getCode()); System.out.println(response.getResponseText()); response = client.get(); System.out.println(response.advanced().getType() + "-" + response.getCode()); System.out.println(response.getResponseText()); 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);
private static void testSimpleGet(final Mode mode) throws Exception { String uri = uriOf(URI); LOGGER.log(Level.FINE, "Test simple GET to {0}", uri); String currentResponseText = "simple GET"; resource.setResponse(currentResponseText, mode); CoapClient client = new CoapClient(uri); client.setEndpoint(clientEndpoint); CoapResponse response = client.get(); assertThatResponseContainsValue(response, currentResponseText); }
String resp1 = client.get().getResponseText(); Assert.assertEquals(CONTENT_1, resp1); String resp2 = client.get().getResponseText(); Assert.assertEquals(CONTENT_1, resp2); Assert.assertEquals(CONTENT_1, resp3); String resp4 = client.get().getResponseText(); Assert.assertEquals(CONTENT_2, resp4); .path(TARGET).query(QUERY_UPPER_CASE).create().get().getResponseText(); Assert.assertEquals(CONTENT_4.toUpperCase(), resp8);