/* * Sends a GET request to itself */ public static void selfTest() { try { Request request = Request.newGet(); request.setURI("localhost:5683/benchmark"); request.send(); Response response = request.waitForResponse(1000); System.out.println("received " + response); } catch (Exception e) { e.printStackTrace(); } }
@Override public void run() { LOGGER.info("Validating endpoint: " + getContext()); Request validationRequest = Request.newGet(); validationRequest.setURI(getContext() + "/.well-known/core"); if (etag != null) { validationRequest.getOptions().addETag(etag); } Response response = null; try { validationRequest.send(); response = validationRequest.waitForResponse(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (response == null) { delete(); } else if (response.getCode() == ResponseCode.VALID) { LOGGER.fine("Resources up-to-date: " + getContext()); } else if (response.getCode() == ResponseCode.CONTENT) { List<byte[]> etags = response.getOptions().getETags(); if (!etags.isEmpty()) { etag = etags.get(0); } updateEndpointResources(response.getPayloadString()); setLifeTime(lifeTime); LOGGER.fine("Updated Resources: " + getContext()); } }