return "demo";
}
@Override
public CoapResponse handle(CoapMessage request, IoSession session) {
return new CoapResponse(CoapCode.CONTENT.getCode(), "niah niah niah niah niah\n niah niah niah\n"
.getBytes(), new CoapOption(CoapOptionType.CONTENT_FORMAT, new byte[] { 0 }));
}
@Override
public String getTittle() {
return "Some demo resource";
}
});
reg.register(new AbstractResourceHandler() {
@Override
public CoapResponse handle(CoapMessage request, IoSession session) {
String device = null;
try {
for (CoapOption o : request.getOptions()) {
if (o.getType() == CoapOptionType.URI_QUERY) {
String qr = new String(o.getData(), "UTF-8");
if (qr.startsWith("id=")) {
device = qr.substring(2);
}
}
}
if (device != null) {
registration.put(device, session);
return new CoapResponse(CoapCode.CREATED.getCode(), null);
} else {
return new CoapResponse(CoapCode.BAD_REQUEST.getCode(), "no id=xxx parameter".getBytes("UTF-8"));
}
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("no UTF-8 in the JVM", e);
}
}