use of org.thingsboard.server.common.data.TransportPayloadType in project thingsboard by thingsboard.
the class CoapTransportResource method processProvision.
private void processProvision(CoapExchange exchange) {
exchange.accept();
try {
UUID sessionId = UUID.randomUUID();
log.trace("[{}] Processing provision publish msg [{}]!", sessionId, exchange.advanced().getRequest());
TransportProtos.ProvisionDeviceRequestMsg provisionRequestMsg;
TransportPayloadType payloadType;
try {
provisionRequestMsg = transportContext.getJsonCoapAdaptor().convertToProvisionRequestMsg(sessionId, exchange.advanced().getRequest());
payloadType = TransportPayloadType.JSON;
} catch (Exception e) {
if (e instanceof JsonParseException || (e.getCause() != null && e.getCause() instanceof JsonParseException)) {
provisionRequestMsg = transportContext.getProtoCoapAdaptor().convertToProvisionRequestMsg(sessionId, exchange.advanced().getRequest());
payloadType = TransportPayloadType.PROTOBUF;
} else {
throw new AdaptorException(e);
}
}
transportService.process(provisionRequestMsg, new DeviceProvisionCallback(exchange, payloadType));
} catch (AdaptorException e) {
log.trace("Failed to decode message: ", e);
exchange.respond(CoAP.ResponseCode.BAD_REQUEST);
}
}
Aggregations