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 | 223 | return; |
224 | 224 | } |
225 | 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 | 229 | private void processRequest(CoapExchange exchange, SessionMsgType type, Request request, ValidateDeviceCredentialsResponse deviceCredentials, DeviceProfile deviceProfile) { | ... | ... |
... | ... | @@ -39,13 +39,13 @@ public interface CoapTransportAdaptor { |
39 | 39 | |
40 | 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 | 50 | ProvisionDeviceRequestMsg convertToProvisionRequestMsg(UUID sessionId, Request inbound) throws AdaptorException; |
51 | 51 | ... | ... |
... | ... | @@ -93,21 +93,20 @@ public class JsonCoapAdaptor implements CoapTransportAdaptor { |
93 | 93 | } |
94 | 94 | |
95 | 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 | 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 | 105 | @Override |
106 | - public Response convertToPublish(boolean isConfirmable, TransportProtos.ToServerRpcResponseMsg msg) throws AdaptorException { | |
106 | + public Response convertToPublish(TransportProtos.ToServerRpcResponseMsg msg) throws AdaptorException { | |
107 | 107 | Response response = new Response(CoAP.ResponseCode.CONTENT); |
108 | 108 | JsonElement result = JsonConverter.toJson(msg); |
109 | 109 | response.setPayload(result.toString()); |
110 | - response.setConfirmable(isConfirmable); | |
111 | 110 | return response; |
112 | 111 | } |
113 | 112 | |
... | ... | @@ -122,11 +121,10 @@ public class JsonCoapAdaptor implements CoapTransportAdaptor { |
122 | 121 | } |
123 | 122 | |
124 | 123 | @Override |
125 | - public Response convertToPublish(boolean isConfirmable, TransportProtos.GetAttributeResponseMsg msg) throws AdaptorException { | |
124 | + public Response convertToPublish(TransportProtos.GetAttributeResponseMsg msg) throws AdaptorException { | |
126 | 125 | if (msg.getSharedStateMsg()) { |
127 | 126 | if (StringUtils.isEmpty(msg.getError())) { |
128 | 127 | Response response = new Response(CoAP.ResponseCode.CONTENT); |
129 | - response.setConfirmable(isConfirmable); | |
130 | 128 | TransportProtos.AttributeUpdateNotificationMsg notificationMsg = TransportProtos.AttributeUpdateNotificationMsg.newBuilder().addAllSharedUpdated(msg.getSharedAttributeListList()).build(); |
131 | 129 | JsonObject result = JsonConverter.toJson(notificationMsg); |
132 | 130 | response.setPayload(result.toString()); |
... | ... | @@ -139,7 +137,6 @@ public class JsonCoapAdaptor implements CoapTransportAdaptor { |
139 | 137 | return new Response(CoAP.ResponseCode.NOT_FOUND); |
140 | 138 | } else { |
141 | 139 | Response response = new Response(CoAP.ResponseCode.CONTENT); |
142 | - response.setConfirmable(isConfirmable); | |
143 | 140 | JsonObject result = JsonConverter.toJson(msg); |
144 | 141 | response.setPayload(result.toString()); |
145 | 142 | return response; |
... | ... | @@ -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 | 148 | Response response = new Response(CoAP.ResponseCode.CONTENT); |
152 | 149 | response.setPayload(json.toString()); |
153 | - response.setConfirmable(confirmable); | |
154 | 150 | return response; |
155 | 151 | } |
156 | 152 | ... | ... |
... | ... | @@ -113,29 +113,27 @@ public class ProtoCoapAdaptor implements CoapTransportAdaptor { |
113 | 113 | } |
114 | 114 | |
115 | 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 | 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 | 125 | @Override |
126 | - public Response convertToPublish(boolean isConfirmable, TransportProtos.ToServerRpcResponseMsg msg) throws AdaptorException { | |
126 | + public Response convertToPublish(TransportProtos.ToServerRpcResponseMsg msg) throws AdaptorException { | |
127 | 127 | Response response = new Response(CoAP.ResponseCode.CONTENT); |
128 | - response.setConfirmable(isConfirmable); | |
129 | 128 | response.setPayload(msg.toByteArray()); |
130 | 129 | return response; |
131 | 130 | } |
132 | 131 | |
133 | 132 | @Override |
134 | - public Response convertToPublish(boolean isConfirmable, TransportProtos.GetAttributeResponseMsg msg) throws AdaptorException { | |
133 | + public Response convertToPublish(TransportProtos.GetAttributeResponseMsg msg) throws AdaptorException { | |
135 | 134 | if (msg.getSharedStateMsg()) { |
136 | 135 | if (StringUtils.isEmpty(msg.getError())) { |
137 | 136 | Response response = new Response(CoAP.ResponseCode.CONTENT); |
138 | - response.setConfirmable(isConfirmable); | |
139 | 137 | TransportProtos.AttributeUpdateNotificationMsg notificationMsg = TransportProtos.AttributeUpdateNotificationMsg.newBuilder().addAllSharedUpdated(msg.getSharedAttributeListList()).build(); |
140 | 138 | response.setPayload(notificationMsg.toByteArray()); |
141 | 139 | return response; |
... | ... | @@ -147,17 +145,15 @@ public class ProtoCoapAdaptor implements CoapTransportAdaptor { |
147 | 145 | return new Response(CoAP.ResponseCode.NOT_FOUND); |
148 | 146 | } else { |
149 | 147 | Response response = new Response(CoAP.ResponseCode.CONTENT); |
150 | - response.setConfirmable(isConfirmable); | |
151 | 148 | response.setPayload(msg.toByteArray()); |
152 | 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 | 155 | Response response = new Response(CoAP.ResponseCode.CONTENT); |
159 | 156 | response.setPayload(notification); |
160 | - response.setConfirmable(confirmable); | |
161 | 157 | return response; |
162 | 158 | } |
163 | 159 | ... | ... |
... | ... | @@ -34,9 +34,7 @@ public class CoapOkCallback implements TransportServiceCallback<Void> { |
34 | 34 | |
35 | 35 | @Override |
36 | 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 | 40 | @Override | ... | ... |
... | ... | @@ -34,7 +34,7 @@ public class GetAttributesSyncSessionCallback extends AbstractSyncSessionCallbac |
34 | 34 | @Override |
35 | 35 | public void onGetAttributesResponse(TransportProtos.GetAttributeResponseMsg msg) { |
36 | 36 | try { |
37 | - respond(state.getAdaptor().convertToPublish(request.isConfirmable(), msg)); | |
37 | + respond(state.getAdaptor().convertToPublish(msg)); | |
38 | 38 | } catch (AdaptorException e) { |
39 | 39 | log.trace("[{}] Failed to reply due to error", state.getDeviceId(), e); |
40 | 40 | exchange.respond(new Response(CoAP.ResponseCode.INTERNAL_SERVER_ERROR)); | ... | ... |
... | ... | @@ -33,7 +33,7 @@ public class ToServerRpcSyncSessionCallback extends AbstractSyncSessionCallback |
33 | 33 | @Override |
34 | 34 | public void onToServerRpcResponse(TransportProtos.ToServerRpcResponseMsg toServerResponse) { |
35 | 35 | try { |
36 | - respond(state.getAdaptor().convertToPublish(request.isConfirmable(), toServerResponse)); | |
36 | + respond(state.getAdaptor().convertToPublish(toServerResponse)); | |
37 | 37 | } catch (AdaptorException e) { |
38 | 38 | log.trace("Failed to reply due to error", e); |
39 | 39 | exchange.respond(CoAP.ResponseCode.INTERNAL_SERVER_ERROR); | ... | ... |
... | ... | @@ -435,8 +435,7 @@ public class DefaultCoapClientContext implements CoapClientContext { |
435 | 435 | TbCoapObservationState attrs = state.getAttrs(); |
436 | 436 | if (attrs != null) { |
437 | 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 | 439 | respond(attrs.getExchange(), response, state.getContentFormat()); |
441 | 440 | } catch (AdaptorException e) { |
442 | 441 | log.trace("Failed to reply due to error", e); |
... | ... | @@ -466,7 +465,8 @@ public class DefaultCoapClientContext implements CoapClientContext { |
466 | 465 | try { |
467 | 466 | boolean conRequest = AbstractSyncSessionCallback.isConRequest(state.getAttrs()); |
468 | 467 | int requestId = getNextMsgId(); |
469 | - Response response = state.getAdaptor().convertToPublish(conRequest, msg); | |
468 | + Response response = state.getAdaptor().convertToPublish(msg); | |
469 | + response.setConfirmable(conRequest); | |
470 | 470 | response.setMID(requestId); |
471 | 471 | if (conRequest) { |
472 | 472 | response.addMessageObserver(new TbCoapMessageObserver(requestId, id -> awake(state), id -> asleep(state))); |
... | ... | @@ -527,7 +527,8 @@ public class DefaultCoapClientContext implements CoapClientContext { |
527 | 527 | String error = null; |
528 | 528 | boolean conRequest = AbstractSyncSessionCallback.isConRequest(state.getRpc()); |
529 | 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 | 532 | int requestId = getNextMsgId(); |
532 | 533 | response.setMID(requestId); |
533 | 534 | if (conRequest) { | ... | ... |