Skip to content

Commit 63aed56

Browse files
author
Max Presman
committed
adjust pn_other decryption
1 parent 1b046b2 commit 63aed56

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

src/main/java/com/pubnub/api/endpoints/History.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.databind.JsonNode;
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import com.fasterxml.jackson.databind.node.ArrayNode;
6+
import com.fasterxml.jackson.databind.node.ObjectNode;
67
import com.pubnub.api.vendor.Crypto;
78
import com.pubnub.api.PubNub;
89
import com.pubnub.api.PubNubException;
@@ -155,6 +156,13 @@ private JsonNode processMessage(JsonNode message) throws PubNubException {
155156
throw PubNubException.builder().pubnubError(PubNubErrorBuilder.PNERROBJ_PARSING_ERROR).errormsg(e.getMessage()).build();
156157
}
157158

159+
// inject the decoded resposne into the payload
160+
if (message.isObject() && message.has("pn_other")) {
161+
ObjectNode objectNode = (ObjectNode) message;
162+
objectNode.set("pn_other", outputObject);
163+
outputObject = objectNode;
164+
}
165+
158166
return outputObject;
159167
}
160168

src/main/java/com/pubnub/api/workers/SubscribeMessageWorker.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.databind.JsonNode;
44
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import com.fasterxml.jackson.databind.node.ObjectNode;
56
import com.pubnub.api.PubNub;
67
import com.pubnub.api.PubNubException;
78
import com.pubnub.api.enums.PNOperationType;
@@ -100,6 +101,13 @@ private JsonNode processMessage(final JsonNode input) {
100101
return null;
101102
}
102103

104+
// inject the decoded response into the payload
105+
if (input.isObject() && input.has("pn_other")) {
106+
ObjectNode objectNode = (ObjectNode) input;
107+
objectNode.set("pn_other", outputObject);
108+
outputObject = objectNode;
109+
}
110+
103111
return outputObject;
104112
}
105113

src/test/java/com/pubnub/api/endpoints/HistoryEndpointTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public void testSyncEncryptedWithPNOtherSuccess() throws IOException, PubNubExce
177177
Assert.assertEquals(response.getMessages().size(), 1);
178178

179179
Assert.assertEquals(response.getMessages().get(0).getTimetoken(), null);
180-
Assert.assertEquals("hey", response.getMessages().get(0).getEntry().get("text").asText());
180+
Assert.assertEquals("hey", response.getMessages().get(0).getEntry().get("pn_other").get("text").asText());
181181

182182
}
183183

@@ -188,11 +188,11 @@ public void testSyncSuccessWithoutTimeToken() throws IOException, PubNubExceptio
188188
ObjectMapper mapper = new ObjectMapper();
189189

190190

191-
Map<String, Object> historyItem1 = new HashMap<String, Object>();
191+
Map<String, Object> historyItem1 = new HashMap<>();
192192
historyItem1.put("a", 11);
193193
historyItem1.put("b", 22);
194194

195-
Map<String, Object> historyItem2 = new HashMap<String, Object>();
195+
Map<String, Object> historyItem2 = new HashMap<>();
196196
historyItem2.put("a", 33);
197197
historyItem2.put("b", 44);
198198

src/test/java/com/pubnub/api/managers/SubscriptionManagerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ public void status(PubNub pubnub, PNStatus status) {
471471
public void message(PubNub pubnub, PNMessageResult message) {
472472
List<LoggedRequest> requests = findAll(getRequestedFor(urlMatching("/v2/subscribe.*")));
473473
assertTrue(requests.size() > 0);
474-
assertEquals("hey", message.getMessage().get("text").asText());
474+
assertEquals("hey", message.getMessage().get("pn_other").get("text").asText());
475475
atomic.addAndGet(1);
476476
}
477477

0 commit comments

Comments
 (0)