CoapClient client = new CoapClient(uri + "/obs");
System.out.println("===============\nCO01+06");
System.out.println("---------------\nGET /obs with Observe");
CoapObserveRelation relation1 = client.observe(
new CoapHandler() {
@Override public void onLoad(CoapResponse response) {
String content = response.getResponseText();
System.out.println("-CO01----------");
System.out.println(content);
}
@Override public void onError() {
System.err.println("-Failed--------");
}
});
try { Thread.sleep(6*1000); } catch (InterruptedException e) { }
System.out.println("---------------\nCancel Observe");
relation1.reactiveCancel();
try { Thread.sleep(6*1000); } catch (InterruptedException e) { }
client.setURI(uri + "/obs-non").useNONs();
System.out.println("===============\nCO02+06");
System.out.println("---------------\nNON-GET /obs-non with Observe");
CoapObserveRelation relation2 = client.observe(
new CoapHandler() {
@Override public void onLoad(CoapResponse response) {
String content = response.getResponseText();
System.out.println("-CO02----------");
System.out.println(content);
}
@Override public void onError() {
System.err.println("-Failed--------");
}
});
try { Thread.sleep(6*1000); } catch (InterruptedException e) { }
System.out.println("---------------\nCancel Observe");
relation2.proactiveCancel();
try { Thread.sleep(2*1000); } catch (InterruptedException e) { }
client.setURI(uri + "/obs").useCONs();
System.out.println("===============\nCO04");
System.out.println("---------------\nGET /obs with Observe");
CoapObserveRelation relation4 = client.observeAndWait(
new CoapHandler() {
@Override public void onLoad(CoapResponse response) {
String content = response.getResponseText();
System.out.println("-CO04----------");
System.out.println(content);
}
@Override public void onError() {
System.err.println("-Failed--------");
}
});
long timeout = relation4.getCurrent().getOptions().getMaxAge();
try { Thread.sleep(6*1000); } catch (InterruptedException e) { }
System.out.println("---------------\nReboot Server");
CoapClient clientStimulus = new CoapClient(uri + "/obs-reset");
clientStimulus.post("sesame", MediaTypeRegistry.TEXT_PLAIN);
try { Thread.sleep((timeout+6)*1000); } catch (InterruptedException e) { }
relation4.proactiveCancel();
try { Thread.sleep(2*1000); } catch (InterruptedException e) { }
client.setURI(uri + "/obs-large");
System.out.println("===============\nCO13");
System.out.println("---------------\nGET /obs-large with Observe");
CoapObserveRelation relation13 = client.observe(
new CoapHandler() {
@Override public void onLoad(CoapResponse response) {
String content = response.getResponseText();
System.out.println("-CO13----------");
System.out.println(content);
}
@Override public void onError() {
System.err.println("-Failed--------");
}
});
try { Thread.sleep(11*1000); } catch (InterruptedException e) { }
System.out.println("---------------\nCancel Observe");
relation13.proactiveCancel();
try { Thread.sleep(6*1000); } catch (InterruptedException e) { }
client.setURI(uri + "/obs-pumping");
System.out.println("===============\nCO14");
System.out.println("---------------\nGET /obs-pumping with Observe");
CoapObserveRelation relation14 = client.observe(
new CoapHandler() {
@Override public void onLoad(CoapResponse response) {
String content = response.getResponseText();
System.out.println("-CO14----------");
System.out.println(content);
}
@Override public void onError() {
System.err.println("-Failed--------");
}
});
try { Thread.sleep(21*1000); } catch (InterruptedException e) { }
System.out.println("---------------\nCancel Observe");
relation14.proactiveCancel();
try { Thread.sleep(6*1000); } catch (InterruptedException e) { }
}