Mule CoAP connector - CoapServer. The CoapServer Connector can be used in Mule applications to implement CoAP servers. A CoAP server is defined by means of a set resources on which requests can be done like GET, POST, PUT etc. . The server CoAP endpoint has a number of configuration parameters that can be used to tune behavior of the server. These parameters have sensible defaults and need only to be set for specific needs.
Additional Info
Requires Mule Enterprise License |
No |
Requires Entitlement |
No |
Mule Version |
3.8.0 or higher |
Configs
Server Configuration
<coap-server:config>
Configuration
The CoAP server configuration contains attributes defining the CoAP endpoint and child elements that define CoAP
resources that will be served. Add resources by adding "<coap-server:resource>" child-elements to the "<coap-server:config>" element.
The resources can - in turn - contain other resources. This hierarchy of resources defines the CoAP ReST interface.
Every resource element defines its name and the operations that are available on it. The operations on resources possible are Get, Post, Put, Delete and Observe.
When the EarlyAck flag is set an acknowledgement is immediately sent back to the client, before processing the request and returning the response.
Use this when processing takes longer than the acknowledgment-timeout of the client.
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".
The size and type attributes can be added to resources which will be reported to clients when they issue a Discovery request.
Example:
<coap-server:config name="CoAP_Server_Configuration"
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>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
name |
The name of this configuration. With this name can be later referenced. |
x |
||
secure |
boolean |
When true DTLS is used to secure CoAP communication. Key and certificate must then be configured. |
false |
|
logMessages |
boolean |
When true each CoAP message will be logged. |
false |
|
bindToHost |
The hostname or IP address the CoAP server binds to. If none is given anyLocalAddress is used (typically 0.0.0.0 or ::0) |
|
||
bindToPort |
The port the CoAP server will listen on when secure == false. |
5683 |
|
|
bindToSecurePort |
The port the CoAP server will listen on when secure == true. |
5684 |
|
|
ackTimeout |
The acknowledgment timeout in milliseconds [ms]) |
2000 |
|
|
ackRandomFactor |
|
|||
ackTimeoutScale |
|
|||
maxRetransmit |
|
|||
exchangeLifetime |
|
|||
nonLifetime |
|
|||
maxTransmitWait |
|
|||
nstart |
|
|||
leisure |
|
|||
probingRate |
|
|||
keyStoreLocation |
|
|||
keyStorePassword |
|
|||
privateKeyAlias |
|
|||
trustStoreLocation |
|
|||
trustStorePassword |
|
|||
trustedRootCertificateAlias |
|
|||
useRandomMidStart |
|
|||
tokenSizeLimit |
|
|||
preferredBlockSize |
|
|||
maxMessageSize |
|
|||
blockwiseStatusLifetime |
|
|||
notificationCheckIntervalTime |
|
|||
notificationCheckIntervalCount |
|
|||
notificationReregistrationBackoff |
|
|||
useCongestionControl |
|
|||
congestionControlAlgorithm |
|
|||
protocolStageThreadCount |
|
|||
networkStageReceiverThreadCount |
|
|||
networkStageSenderThreadCount |
|
|||
udpConnectorDatagramSize |
|
|||
udpConnectorReceiveBuffer |
|
|||
udpConnectorSendBuffer |
|
|||
udpConnectorOutCapacity |
|
|||
deduplicator |
|
|||
deduplicatorMarkAndSweep |
|
|||
markAndSweepInterval |
|
|||
deduplicatorCropRotation |
|
|||
cropRotationPeriod |
|
|||
noDeduplicator |
|
|||
healthStatusPrintLevel |
|
|||
healthStatusInterval |
|
Processors
Resource changed
<coap-server:resource-changed>
The Resource Changed messageprocessor is used to trigger a notification to clients that observe the specified resource.
The uri needs to be an existing resource defined in the coap-server configuration or a dynamically created resource.
Wildcards can also be used, like "/*" or "/some/deeper/resources/*".
The observing clients are notified by issuing an internal get-request for every client that gets processed by the listener on the resource concerned.
Example:
<coap-server:resource-changed config-ref="CoAP_Server_Configuration" uri="/hello/changeme"/>
Add resource
<coap-server:add-resource>
The Add Resource messageprocessor is used to dynamically add a resource to the CoAP server.
The uri needs to be a complete resource-path, including all parent resource(s).
All parent resources in the path need to exist already.
Requests on the resource can be done immediately, provided there is a listener configured for it,
e.g. by means of a listener that has a wildcard uri (for the example below a listener with uri="/alphabet/*" would do).
Example:
<coap-server:add-resource config-ref="CoAP_Server_Configuration" uri="/alphabet/z" get="true" delete="true"/>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
uri |
The uri (without scheme/host part) of the resource to add. |
x |
||
get |
boolean |
When true the resource accepts get-requests. |
false |
|
put |
boolean |
When true the resource accepts put-requests. |
false |
|
post |
boolean |
When true the resource accepts post-requests. |
false |
|
delete |
boolean |
When true the resource accepts delete-requests. |
false |
|
observable |
boolean |
When true the resource accepts observe-requests. |
false |
|
earlyAck |
boolean |
An immediate acknowledgement is sent tot the client before processing the request. |
false |
|
title |
The readable title of the resource. |
|
||
ifdesc |
The interface ( if ) indicates interfaces-name the resource implements. |
|
||
rt |
The defines the resource type. |
|
||
sz |
|
|||
ct |
The type of the resources content, specified as CoAP type number. |
|
Remove resource
<coap-server:remove-resource>
The Remove Resource messageprocessor removes one or more resources from the server.
A wildcard can be used, e.g. "/tobefound/*". All resources that apply to the uri will be removed.
Clients that observe a resource that is removed will be notified.
Example:
<coap-server:remove-resource config-ref="CoAP_Server_Configuration" uri="/alphabet/z" />
Resource exists
<coap-server:resource-exists>
The <coap-server:resource-exists/>
messageprocessor returns 'true' when a resource on
the given uri is active, otherwise false.
A wildcard can be used, e.g. "/tobefound/*". When at least one resource is found that applies to the uri, the Boolean 'true' is returned.
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
uri |
The uri (without scheme/host part) of the resource(s) to be deleted. |
x |
Returns
Return Java Type | Description |
---|---|
true when at least one resource is found. |
Sources
Listen
<coap-server:listen>
The Listen messageprocessor receives all incoming requests on the specified uri.
The uri needs to be an existing resource defined in de coap-server configuration.
Wildcards can also be used, like "/*" or "/some/deeper/resources/*".
When multiple listeners apply for a resource, the listener with the most specific uri will get the requests on it.
CoAP options of the request are added to the inbound-scope of the MuleMessage.
Example:
<flow name="coap-serverFlow1">
<coap-server:listen uri="/alphabet/*" config-ref="CoAP_Server_Configuration"/>
<set-variable variableName="method" value="#[ message.inboundProperties['coap.request.code']]"/>
<set-variable variableName="uri" value="#[message.inboundProperties['coap.request.uri'] ]"/>
<byte-array-to-string-transformer/>
<logger level="INFO" message="#[payload]"/>
<set-payload value="<my_response>Hi!</my_response>" encoding="UTF-8" mimeType="application/xml"/>
<set-property propertyName="coap.response.code" value="CONTENT" />
</flow>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
callback |
SourceCallback |
Set by Mule, not visible in xml. |
x |
|
uri |
The uri (without scheme/host part) of the resource the listener get the requests to process. |
x |
Returns
Return Java Type | Description |
---|---|
byte[] |
The payload of the CoAP request. |