Commit de1a56a4889f211894f5b62348e3ef18e675ac34
Committed by
Andrew Shvayka
1 parent
4c275888
CoAP ack/confirmable mess fixing
Showing
8 changed files
with
27 additions
and
38 deletions
common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/CoapTransportResource.java
@@ -223,9 +223,7 @@ public class CoapTransportResource extends AbstractCoapTransportResource { | @@ -223,9 +223,7 @@ public class CoapTransportResource extends AbstractCoapTransportResource { | ||
223 | return; | 223 | return; |
224 | } | 224 | } |
225 | transportService.process(DeviceTransportType.COAP, TransportProtos.ValidateDeviceTokenRequestMsg.newBuilder().setToken(credentials.get().getCredentialsId()).build(), | 225 | transportService.process(DeviceTransportType.COAP, TransportProtos.ValidateDeviceTokenRequestMsg.newBuilder().setToken(credentials.get().getCredentialsId()).build(), |
226 | - new CoapDeviceAuthCallback(exchange, (deviceCredentials, deviceProfile) -> { | ||
227 | - processRequest(exchange, type, request, deviceCredentials, deviceProfile); | ||
228 | - })); | 226 | + new CoapDeviceAuthCallback(exchange, (deviceCredentials, deviceProfile) -> processRequest(exchange, type, request, deviceCredentials, deviceProfile))); |
229 | } | 227 | } |
230 | 228 | ||
231 | private void processRequest(CoapExchange exchange, SessionMsgType type, Request request, ValidateDeviceCredentialsResponse deviceCredentials, DeviceProfile deviceProfile) { | 229 | private void processRequest(CoapExchange exchange, SessionMsgType type, Request request, ValidateDeviceCredentialsResponse deviceCredentials, DeviceProfile deviceProfile) { |
@@ -39,13 +39,13 @@ public interface CoapTransportAdaptor { | @@ -39,13 +39,13 @@ public interface CoapTransportAdaptor { | ||
39 | 39 | ||
40 | TransportProtos.ClaimDeviceMsg convertToClaimDevice(UUID sessionId, Request inbound, TransportProtos.SessionInfoProto sessionInfo) throws AdaptorException; | 40 | TransportProtos.ClaimDeviceMsg convertToClaimDevice(UUID sessionId, Request inbound, TransportProtos.SessionInfoProto sessionInfo) throws AdaptorException; |
41 | 41 | ||
42 | - Response convertToPublish(boolean isConfirmable, TransportProtos.GetAttributeResponseMsg responseMsg) throws AdaptorException; | 42 | + Response convertToPublish(TransportProtos.GetAttributeResponseMsg responseMsg) throws AdaptorException; |
43 | 43 | ||
44 | - Response convertToPublish(boolean isConfirmable, TransportProtos.AttributeUpdateNotificationMsg notificationMsg) throws AdaptorException; | 44 | + Response convertToPublish(TransportProtos.AttributeUpdateNotificationMsg notificationMsg) throws AdaptorException; |
45 | 45 | ||
46 | - Response convertToPublish(boolean isConfirmable, TransportProtos.ToDeviceRpcRequestMsg rpcRequest, DynamicMessage.Builder rpcRequestDynamicMessageBuilder) throws AdaptorException; | 46 | + Response convertToPublish(TransportProtos.ToDeviceRpcRequestMsg rpcRequest, DynamicMessage.Builder rpcRequestDynamicMessageBuilder) throws AdaptorException; |
47 | 47 | ||
48 | - Response convertToPublish(boolean isConfirmable, TransportProtos.ToServerRpcResponseMsg msg) throws AdaptorException; | 48 | + Response convertToPublish(TransportProtos.ToServerRpcResponseMsg msg) throws AdaptorException; |
49 | 49 | ||
50 | ProvisionDeviceRequestMsg convertToProvisionRequestMsg(UUID sessionId, Request inbound) throws AdaptorException; | 50 | ProvisionDeviceRequestMsg convertToProvisionRequestMsg(UUID sessionId, Request inbound) throws AdaptorException; |
51 | 51 |
@@ -93,21 +93,20 @@ public class JsonCoapAdaptor implements CoapTransportAdaptor { | @@ -93,21 +93,20 @@ public class JsonCoapAdaptor implements CoapTransportAdaptor { | ||
93 | } | 93 | } |
94 | 94 | ||
95 | @Override | 95 | @Override |
96 | - public Response convertToPublish(boolean isConfirmable, TransportProtos.AttributeUpdateNotificationMsg msg) throws AdaptorException { | ||
97 | - return getObserveNotification(isConfirmable, JsonConverter.toJson(msg)); | 96 | + public Response convertToPublish(TransportProtos.AttributeUpdateNotificationMsg msg) throws AdaptorException { |
97 | + return getObserveNotification(JsonConverter.toJson(msg)); | ||
98 | } | 98 | } |
99 | 99 | ||
100 | @Override | 100 | @Override |
101 | - public Response convertToPublish(boolean isConfirmable, TransportProtos.ToDeviceRpcRequestMsg msg, DynamicMessage.Builder rpcRequestDynamicMessageBuilder) throws AdaptorException { | ||
102 | - return getObserveNotification(isConfirmable, JsonConverter.toJson(msg, true)); | 101 | + public Response convertToPublish(TransportProtos.ToDeviceRpcRequestMsg msg, DynamicMessage.Builder rpcRequestDynamicMessageBuilder) throws AdaptorException { |
102 | + return getObserveNotification(JsonConverter.toJson(msg, true)); | ||
103 | } | 103 | } |
104 | 104 | ||
105 | @Override | 105 | @Override |
106 | - public Response convertToPublish(boolean isConfirmable, TransportProtos.ToServerRpcResponseMsg msg) throws AdaptorException { | 106 | + public Response convertToPublish(TransportProtos.ToServerRpcResponseMsg msg) throws AdaptorException { |
107 | Response response = new Response(CoAP.ResponseCode.CONTENT); | 107 | Response response = new Response(CoAP.ResponseCode.CONTENT); |
108 | JsonElement result = JsonConverter.toJson(msg); | 108 | JsonElement result = JsonConverter.toJson(msg); |
109 | response.setPayload(result.toString()); | 109 | response.setPayload(result.toString()); |
110 | - response.setConfirmable(isConfirmable); | ||
111 | return response; | 110 | return response; |
112 | } | 111 | } |
113 | 112 | ||
@@ -122,11 +121,10 @@ public class JsonCoapAdaptor implements CoapTransportAdaptor { | @@ -122,11 +121,10 @@ public class JsonCoapAdaptor implements CoapTransportAdaptor { | ||
122 | } | 121 | } |
123 | 122 | ||
124 | @Override | 123 | @Override |
125 | - public Response convertToPublish(boolean isConfirmable, TransportProtos.GetAttributeResponseMsg msg) throws AdaptorException { | 124 | + public Response convertToPublish(TransportProtos.GetAttributeResponseMsg msg) throws AdaptorException { |
126 | if (msg.getSharedStateMsg()) { | 125 | if (msg.getSharedStateMsg()) { |
127 | if (StringUtils.isEmpty(msg.getError())) { | 126 | if (StringUtils.isEmpty(msg.getError())) { |
128 | Response response = new Response(CoAP.ResponseCode.CONTENT); | 127 | Response response = new Response(CoAP.ResponseCode.CONTENT); |
129 | - response.setConfirmable(isConfirmable); | ||
130 | TransportProtos.AttributeUpdateNotificationMsg notificationMsg = TransportProtos.AttributeUpdateNotificationMsg.newBuilder().addAllSharedUpdated(msg.getSharedAttributeListList()).build(); | 128 | TransportProtos.AttributeUpdateNotificationMsg notificationMsg = TransportProtos.AttributeUpdateNotificationMsg.newBuilder().addAllSharedUpdated(msg.getSharedAttributeListList()).build(); |
131 | JsonObject result = JsonConverter.toJson(notificationMsg); | 129 | JsonObject result = JsonConverter.toJson(notificationMsg); |
132 | response.setPayload(result.toString()); | 130 | response.setPayload(result.toString()); |
@@ -139,7 +137,6 @@ public class JsonCoapAdaptor implements CoapTransportAdaptor { | @@ -139,7 +137,6 @@ public class JsonCoapAdaptor implements CoapTransportAdaptor { | ||
139 | return new Response(CoAP.ResponseCode.NOT_FOUND); | 137 | return new Response(CoAP.ResponseCode.NOT_FOUND); |
140 | } else { | 138 | } else { |
141 | Response response = new Response(CoAP.ResponseCode.CONTENT); | 139 | Response response = new Response(CoAP.ResponseCode.CONTENT); |
142 | - response.setConfirmable(isConfirmable); | ||
143 | JsonObject result = JsonConverter.toJson(msg); | 140 | JsonObject result = JsonConverter.toJson(msg); |
144 | response.setPayload(result.toString()); | 141 | response.setPayload(result.toString()); |
145 | return response; | 142 | return response; |
@@ -147,10 +144,9 @@ public class JsonCoapAdaptor implements CoapTransportAdaptor { | @@ -147,10 +144,9 @@ public class JsonCoapAdaptor implements CoapTransportAdaptor { | ||
147 | } | 144 | } |
148 | } | 145 | } |
149 | 146 | ||
150 | - private Response getObserveNotification(boolean confirmable, JsonElement json) { | 147 | + private Response getObserveNotification(JsonElement json) { |
151 | Response response = new Response(CoAP.ResponseCode.CONTENT); | 148 | Response response = new Response(CoAP.ResponseCode.CONTENT); |
152 | response.setPayload(json.toString()); | 149 | response.setPayload(json.toString()); |
153 | - response.setConfirmable(confirmable); | ||
154 | return response; | 150 | return response; |
155 | } | 151 | } |
156 | 152 |
@@ -113,29 +113,27 @@ public class ProtoCoapAdaptor implements CoapTransportAdaptor { | @@ -113,29 +113,27 @@ public class ProtoCoapAdaptor implements CoapTransportAdaptor { | ||
113 | } | 113 | } |
114 | 114 | ||
115 | @Override | 115 | @Override |
116 | - public Response convertToPublish(boolean isConfirmable, TransportProtos.AttributeUpdateNotificationMsg msg) throws AdaptorException { | ||
117 | - return getObserveNotification(isConfirmable, msg.toByteArray()); | 116 | + public Response convertToPublish(TransportProtos.AttributeUpdateNotificationMsg msg) throws AdaptorException { |
117 | + return getObserveNotification(msg.toByteArray()); | ||
118 | } | 118 | } |
119 | 119 | ||
120 | @Override | 120 | @Override |
121 | - public Response convertToPublish(boolean isConfirmable, TransportProtos.ToDeviceRpcRequestMsg rpcRequest, DynamicMessage.Builder rpcRequestDynamicMessageBuilder) throws AdaptorException { | ||
122 | - return getObserveNotification(isConfirmable, ProtoConverter.convertToRpcRequest(rpcRequest, rpcRequestDynamicMessageBuilder)); | 121 | + public Response convertToPublish(TransportProtos.ToDeviceRpcRequestMsg rpcRequest, DynamicMessage.Builder rpcRequestDynamicMessageBuilder) throws AdaptorException { |
122 | + return getObserveNotification(ProtoConverter.convertToRpcRequest(rpcRequest, rpcRequestDynamicMessageBuilder)); | ||
123 | } | 123 | } |
124 | 124 | ||
125 | @Override | 125 | @Override |
126 | - public Response convertToPublish(boolean isConfirmable, TransportProtos.ToServerRpcResponseMsg msg) throws AdaptorException { | 126 | + public Response convertToPublish(TransportProtos.ToServerRpcResponseMsg msg) throws AdaptorException { |
127 | Response response = new Response(CoAP.ResponseCode.CONTENT); | 127 | Response response = new Response(CoAP.ResponseCode.CONTENT); |
128 | - response.setConfirmable(isConfirmable); | ||
129 | response.setPayload(msg.toByteArray()); | 128 | response.setPayload(msg.toByteArray()); |
130 | return response; | 129 | return response; |
131 | } | 130 | } |
132 | 131 | ||
133 | @Override | 132 | @Override |
134 | - public Response convertToPublish(boolean isConfirmable, TransportProtos.GetAttributeResponseMsg msg) throws AdaptorException { | 133 | + public Response convertToPublish(TransportProtos.GetAttributeResponseMsg msg) throws AdaptorException { |
135 | if (msg.getSharedStateMsg()) { | 134 | if (msg.getSharedStateMsg()) { |
136 | if (StringUtils.isEmpty(msg.getError())) { | 135 | if (StringUtils.isEmpty(msg.getError())) { |
137 | Response response = new Response(CoAP.ResponseCode.CONTENT); | 136 | Response response = new Response(CoAP.ResponseCode.CONTENT); |
138 | - response.setConfirmable(isConfirmable); | ||
139 | TransportProtos.AttributeUpdateNotificationMsg notificationMsg = TransportProtos.AttributeUpdateNotificationMsg.newBuilder().addAllSharedUpdated(msg.getSharedAttributeListList()).build(); | 137 | TransportProtos.AttributeUpdateNotificationMsg notificationMsg = TransportProtos.AttributeUpdateNotificationMsg.newBuilder().addAllSharedUpdated(msg.getSharedAttributeListList()).build(); |
140 | response.setPayload(notificationMsg.toByteArray()); | 138 | response.setPayload(notificationMsg.toByteArray()); |
141 | return response; | 139 | return response; |
@@ -147,17 +145,15 @@ public class ProtoCoapAdaptor implements CoapTransportAdaptor { | @@ -147,17 +145,15 @@ public class ProtoCoapAdaptor implements CoapTransportAdaptor { | ||
147 | return new Response(CoAP.ResponseCode.NOT_FOUND); | 145 | return new Response(CoAP.ResponseCode.NOT_FOUND); |
148 | } else { | 146 | } else { |
149 | Response response = new Response(CoAP.ResponseCode.CONTENT); | 147 | Response response = new Response(CoAP.ResponseCode.CONTENT); |
150 | - response.setConfirmable(isConfirmable); | ||
151 | response.setPayload(msg.toByteArray()); | 148 | response.setPayload(msg.toByteArray()); |
152 | return response; | 149 | return response; |
153 | } | 150 | } |
154 | } | 151 | } |
155 | } | 152 | } |
156 | 153 | ||
157 | - private Response getObserveNotification(boolean confirmable, byte[] notification) { | 154 | + private Response getObserveNotification(byte[] notification) { |
158 | Response response = new Response(CoAP.ResponseCode.CONTENT); | 155 | Response response = new Response(CoAP.ResponseCode.CONTENT); |
159 | response.setPayload(notification); | 156 | response.setPayload(notification); |
160 | - response.setConfirmable(confirmable); | ||
161 | return response; | 157 | return response; |
162 | } | 158 | } |
163 | 159 |
@@ -34,9 +34,7 @@ public class CoapOkCallback implements TransportServiceCallback<Void> { | @@ -34,9 +34,7 @@ public class CoapOkCallback implements TransportServiceCallback<Void> { | ||
34 | 34 | ||
35 | @Override | 35 | @Override |
36 | public void onSuccess(Void msg) { | 36 | public void onSuccess(Void msg) { |
37 | - Response response = new Response(onSuccessResponse); | ||
38 | - response.setConfirmable(isConRequest()); | ||
39 | - exchange.respond(response); | 37 | + exchange.respond(new Response(onSuccessResponse)); |
40 | } | 38 | } |
41 | 39 | ||
42 | @Override | 40 | @Override |
@@ -34,7 +34,7 @@ public class GetAttributesSyncSessionCallback extends AbstractSyncSessionCallbac | @@ -34,7 +34,7 @@ public class GetAttributesSyncSessionCallback extends AbstractSyncSessionCallbac | ||
34 | @Override | 34 | @Override |
35 | public void onGetAttributesResponse(TransportProtos.GetAttributeResponseMsg msg) { | 35 | public void onGetAttributesResponse(TransportProtos.GetAttributeResponseMsg msg) { |
36 | try { | 36 | try { |
37 | - respond(state.getAdaptor().convertToPublish(request.isConfirmable(), msg)); | 37 | + respond(state.getAdaptor().convertToPublish(msg)); |
38 | } catch (AdaptorException e) { | 38 | } catch (AdaptorException e) { |
39 | log.trace("[{}] Failed to reply due to error", state.getDeviceId(), e); | 39 | log.trace("[{}] Failed to reply due to error", state.getDeviceId(), e); |
40 | exchange.respond(new Response(CoAP.ResponseCode.INTERNAL_SERVER_ERROR)); | 40 | exchange.respond(new Response(CoAP.ResponseCode.INTERNAL_SERVER_ERROR)); |
@@ -33,7 +33,7 @@ public class ToServerRpcSyncSessionCallback extends AbstractSyncSessionCallback | @@ -33,7 +33,7 @@ public class ToServerRpcSyncSessionCallback extends AbstractSyncSessionCallback | ||
33 | @Override | 33 | @Override |
34 | public void onToServerRpcResponse(TransportProtos.ToServerRpcResponseMsg toServerResponse) { | 34 | public void onToServerRpcResponse(TransportProtos.ToServerRpcResponseMsg toServerResponse) { |
35 | try { | 35 | try { |
36 | - respond(state.getAdaptor().convertToPublish(request.isConfirmable(), toServerResponse)); | 36 | + respond(state.getAdaptor().convertToPublish(toServerResponse)); |
37 | } catch (AdaptorException e) { | 37 | } catch (AdaptorException e) { |
38 | log.trace("Failed to reply due to error", e); | 38 | log.trace("Failed to reply due to error", e); |
39 | exchange.respond(CoAP.ResponseCode.INTERNAL_SERVER_ERROR); | 39 | exchange.respond(CoAP.ResponseCode.INTERNAL_SERVER_ERROR); |
@@ -435,8 +435,7 @@ public class DefaultCoapClientContext implements CoapClientContext { | @@ -435,8 +435,7 @@ public class DefaultCoapClientContext implements CoapClientContext { | ||
435 | TbCoapObservationState attrs = state.getAttrs(); | 435 | TbCoapObservationState attrs = state.getAttrs(); |
436 | if (attrs != null) { | 436 | if (attrs != null) { |
437 | try { | 437 | try { |
438 | - boolean conRequest = AbstractSyncSessionCallback.isConRequest(state.getAttrs()); | ||
439 | - Response response = state.getAdaptor().convertToPublish(conRequest, msg); | 438 | + Response response = state.getAdaptor().convertToPublish(msg); |
440 | respond(attrs.getExchange(), response, state.getContentFormat()); | 439 | respond(attrs.getExchange(), response, state.getContentFormat()); |
441 | } catch (AdaptorException e) { | 440 | } catch (AdaptorException e) { |
442 | log.trace("Failed to reply due to error", e); | 441 | log.trace("Failed to reply due to error", e); |
@@ -466,7 +465,8 @@ public class DefaultCoapClientContext implements CoapClientContext { | @@ -466,7 +465,8 @@ public class DefaultCoapClientContext implements CoapClientContext { | ||
466 | try { | 465 | try { |
467 | boolean conRequest = AbstractSyncSessionCallback.isConRequest(state.getAttrs()); | 466 | boolean conRequest = AbstractSyncSessionCallback.isConRequest(state.getAttrs()); |
468 | int requestId = getNextMsgId(); | 467 | int requestId = getNextMsgId(); |
469 | - Response response = state.getAdaptor().convertToPublish(conRequest, msg); | 468 | + Response response = state.getAdaptor().convertToPublish(msg); |
469 | + response.setConfirmable(conRequest); | ||
470 | response.setMID(requestId); | 470 | response.setMID(requestId); |
471 | if (conRequest) { | 471 | if (conRequest) { |
472 | response.addMessageObserver(new TbCoapMessageObserver(requestId, id -> awake(state), id -> asleep(state))); | 472 | response.addMessageObserver(new TbCoapMessageObserver(requestId, id -> awake(state), id -> asleep(state))); |
@@ -527,7 +527,8 @@ public class DefaultCoapClientContext implements CoapClientContext { | @@ -527,7 +527,8 @@ public class DefaultCoapClientContext implements CoapClientContext { | ||
527 | String error = null; | 527 | String error = null; |
528 | boolean conRequest = AbstractSyncSessionCallback.isConRequest(state.getRpc()); | 528 | boolean conRequest = AbstractSyncSessionCallback.isConRequest(state.getRpc()); |
529 | try { | 529 | try { |
530 | - Response response = state.getAdaptor().convertToPublish(conRequest, msg, state.getConfiguration().getRpcRequestDynamicMessageBuilder()); | 530 | + Response response = state.getAdaptor().convertToPublish(msg, state.getConfiguration().getRpcRequestDynamicMessageBuilder()); |
531 | + response.setConfirmable(conRequest); | ||
531 | int requestId = getNextMsgId(); | 532 | int requestId = getNextMsgId(); |
532 | response.setMID(requestId); | 533 | response.setMID(requestId); |
533 | if (conRequest) { | 534 | if (conRequest) { |