Class HttpBasedMessageMapping
- java.lang.Object
-
- org.eclipse.hono.adapter.mqtt.impl.HttpBasedMessageMapping
-
- All Implemented Interfaces:
MessageMapping<MqttContext>
public final class HttpBasedMessageMapping extends Object implements MessageMapping<MqttContext>
A message mapper that invokes a service implementation via HTTP(S).The headers are overwritten with the result of the mapper (which includes the resourceId). E.g.: when the deviceId is in the payload of the message, the deviceId can be deducted in the custom mapper and the payload can be changed accordingly to the payload originally received by the gateway.
-
-
Constructor Summary
Constructors Constructor Description HttpBasedMessageMapping(io.vertx.ext.web.client.WebClient webClient, MqttProtocolAdapterProperties protocolAdapterConfig)Creates a new service for a web client and configuration properties.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description io.vertx.core.Future<MappedMessage>mapDownstreamMessage(MqttContext ctx, org.eclipse.hono.util.ResourceIdentifier targetAddress, org.eclipse.hono.util.RegistrationAssertion registrationInfo)Maps a message uploaded by a device.io.vertx.core.Future<io.vertx.core.buffer.Buffer>mapUpstreamMessage(org.eclipse.hono.util.RegistrationAssertion registrationInfo, org.eclipse.hono.client.command.Command command)Maps a command to be sent to a device/gateway.
-
-
-
Constructor Detail
-
HttpBasedMessageMapping
public HttpBasedMessageMapping(io.vertx.ext.web.client.WebClient webClient, MqttProtocolAdapterProperties protocolAdapterConfig)Creates a new service for a web client and configuration properties.- Parameters:
webClient- The web client to use for invoking the mapper endpoint.protocolAdapterConfig- The configuration properties of the MQTT protocol adapter used to look up mapper configurations.- Throws:
NullPointerException- if any of the parameters arenull.
-
-
Method Detail
-
mapDownstreamMessage
public io.vertx.core.Future<MappedMessage> mapDownstreamMessage(MqttContext ctx, org.eclipse.hono.util.ResourceIdentifier targetAddress, org.eclipse.hono.util.RegistrationAssertion registrationInfo)
Maps a message uploaded by a device.If a mapping service is not configured for a gateway or a protocol adapter, this method returns a successful future containing the original device payload and target address. If a mapping service is configured for a gateway or a protocol adapter and the mapping service returns a 200 OK HTTP status code, then this method returns a successful future containing the mapped payload.
For all other 2XX HTTP status codes, this method returns a mapped message containing the original device payload and target address. In all other cases, this method returns a failed future with a
ServiceInvocationException.This implementation tries to look up the URL of the service endpoint to invoke in the adapter's mapperEndpoints using the value of the registration assertion's mapper property as the key. If a mapping endpoint configuration is found, an HTTP GET request is sent to the endpoint containing the original message's
- payload in the request body,
- content type in the HTTP content-type header,
- topic name in the "orig_address" header and
- all properties from the registration assertion as headers.
- Specified by:
mapDownstreamMessagein interfaceMessageMapping<MqttContext>- Parameters:
ctx- The context in which the message has been uploaded.targetAddress- The downstream address that the message will be forwarded to.registrationInfo- The information included in the registration assertion for the authenticated device that has uploaded the message.- Returns:
- A future indicating the mapping result.
The future will be succeeded with the original unaltered message if no mapping
URL could be found. The future will be succeeded with the message contained in the
response body if the returned status code is 200.
Otherwise, the future will be failed with a
ServerErrorException.
-
mapUpstreamMessage
public io.vertx.core.Future<io.vertx.core.buffer.Buffer> mapUpstreamMessage(org.eclipse.hono.util.RegistrationAssertion registrationInfo, org.eclipse.hono.client.command.Command command)Description copied from interface:MessageMappingMaps a command to be sent to a device/gateway.If a command mapping service is not configured for a gateway or a protocol adapter, this method returns a successful future containing the original command payload. If a command mapping service is configured for a gateway or a protocol adapter and the mapping service returns a 200 OK HTTP status code, then this method returns a successful future containing the mapped command.
For all other 2XX HTTP status codes, this method returns the original command payload. In all other cases, this method returns a failed future with a
ServiceInvocationException.- Specified by:
mapUpstreamMessagein interfaceMessageMapping<MqttContext>- Parameters:
registrationInfo- The information included in the registration assertion for the gateway/device to which the command needs to be sent.command- The original command to be mapped.- Returns:
- A successful future containing the mapped command.
Otherwise, the future will be failed with a
ServiceInvocationExceptionif the command could not be mapped.
-
-