A CoAP server is defined in the Mule application bij adding the global element
<coap-server:config name="my_CoAP_Server"/>
. The configuration defines a
CoAP Endpoint that listens by default on the standard CoAP port 5683, or 5684 when it is made secure.
The server CoAP endpoint has a number of configuration parameters that can be set to
tune the behavior of the server. These parameters have sensible defaults and need only
to be set for specific needs. See the reference documentation for a complete list of the
parameters.
The CoAP server makes a set resources available to client, on which they can do
requests. The resources are configured by adding
<coap-server:resources/>
child element, containing one or more
resource configuration elements: <coap-server:resource
name="my_resource"/>
. Resources can be nested by adding another resources
element to a resource. This can repeated an arbitrary number of times to create a tree
of resources. This hierarchy of resources defines the CoAP ReST interface. Every
resource element defines its name and the operations that are available on it. Clients
can refer to resources by their path in the hierarchy e.g. "/root/child", where the
resource named "root" contains the resource named "child".
Clients can issue Get, Post, Put, Delete or Observe requests on these resources, when the corresponding attribute on the resource is set to true. Below an example where communication between client and server is secured using DTLS. The earlyAck attribute is set to true on resources where processing requests can take longer than the Acknowledgement time-out used by clients. The type attribute is used to inform clients about the response payload type, whereas size is maximum expected size of it. The resources and size and type attributes will be reported to clients when they issue a Discovery request.
<coap-server:config name="my_CoAP_Server" secure="true" keyStoreLocation="keyStore.jks" keyStorePassword="endPass" privateKeyAlias="server" trustStoreLocation="trustStore.jks" trustStorePassword="rootPass" trustedRootCertificateAlias="root" > <coap-server:resources> <coap-server:resource name="large" get="true" earlyAck="true" size="2345345" type="application/json"/> <coap-server:resource name="slow" get="true" earlyAck="true"/> <coap-server:resource name="alphabet" get="true" post="true" observe="true"> <coap-server:resources> <coap-server:resource name="a" get="true" post="true" put="true" delete="true" observe="true" earlyAck="true" > <coap-server:resource name="b" get="true"/> <coap-server:resource name="c" get="true"/> </coap-server:resources> </coap-server:resource> <coap-server:resource name="hello" get="true" observe="true"> <coap-server:resources> <coap-server:resource name="there" get="true"/> <coap-server:resource name="changeme" get="true" put="true" observe="true"/> <coap-server:resource name="deleteme" get="true" delete="true"/> <coap-server:resource name="collect" post="true" type="text/plain"/> </coap-server:resources> </coap-server:resource> </coap-server:resources> </coap-server:config>