A CoAP client endpoint is defined in the Mule application by adding the global element
<coap-client:config name="my_CoAP_Client"/>
. The configuration
defines the CoAP Endpoint that is used to issue request to a CoAP server. By default the
standard CoAP port 5683, or 5684 when communication is secure, is used. The CoAP endpoint has a
number of configuration parameters that can be set to tune the behavior of the client.
These parameters have sensible defaults and need only to be set for specific needs.
A CoAP server makes a set resources available for a client to issue requests on.
Clients can issue Get, Post, Put, Delete or Observe requests on these. The connectors
message-processors and message-sources issue these requests using the CoAP endpoint by
referencing the <coap-client:config/>
element.
Below an example of a client configuration. The host and port define the location of the CoAP server (in the example the default port is used). These can be overruled by individual message-processors. In this way the CoAP endpoint can be used to access multiple servers. In the example the acknowledgement timeout is set to one second. See the reference documentation for a complete list of the parameters.
Example 1. Simple coap-client configuration
<mule ... > <coap-client:config name="my_CoAP_Client" host="californium.eclipse.org" ackTimeout="1000"/> ... </mule>
The CoAP communication can be made secure using DTLS by setting the
secure
attribute to true. Below an
example where communication between client and server is secured using DTLS. When the
client is secure the keystore, truststore, key and certificate to use need to be
provided.
Example 2. Secured client example
<mule ... > <coap-client:config name="my_Secured_Client" host="127.0.0.1" secure="true" keyStoreLocation="keyStore.jks" keyStorePassword="endPass" privateKeyAlias="client" trustStoreLocation="trustStore.jks" trustStorePassword="rootPass" trustedRootCertificateAlias="root" /> ... </mule>