InetSocketAddress remoteEndpoint){
Set<Long> acceptedContentFormats = coapRequest.getAcceptedContentFormats();
WrappedResourceStatus wrappedResourceStatus = null;
long contentFormat;
//Use default content format if there was no accept option set in the request
if(acceptedContentFormats.isEmpty()){
contentFormat = DEFAULT_CONTENT_FORMAT;
wrappedResourceStatus = getWrappedResourceStatus(contentFormat);
}
//Try all accepted content formats (if accept option was set in the request)
else{
for(long acceptedContentFormat : acceptedContentFormats){
wrappedResourceStatus = getWrappedResourceStatus(acceptedContentFormat);
if(wrappedResourceStatus != null)
break;
}
}
if(wrappedResourceStatus == null){
CoapResponse coapResponse =
new CoapResponse(coapRequest.getMessageTypeName(), MessageCode.Name.BAD_REQUEST_400);
String content = "Resource status is not available in any of the accepted content formats!";
coapResponse.setContent(content.getBytes(CoapMessage.CHARSET), ContentFormat.TEXT_PLAIN_UTF8);
responseFuture.set(coapResponse);
}
else{
CoapResponse coapResponse =
new CoapResponse(coapRequest.getMessageTypeName(), MessageCode.Name.CONTENT_205);
coapResponse.setContent(wrappedResourceStatus.getContent(), wrappedResourceStatus.getContentFormat());
coapResponse.setEtag(wrappedResourceStatus.getEtag());
coapResponse.setMaxAge(wrappedResourceStatus.getMaxAge());
if(coapRequest.getObserve() == 0){
coapResponse.setObserve();
}