Skip to content

Commit 232f43d

Browse files
author
Devendra
committed
decryption for history/detailedHistory
1 parent 1a8a878 commit 232f43d

11 files changed

Lines changed: 81 additions & 47 deletions

File tree

149 Bytes
Binary file not shown.

‎android/3.4/Pubnub-Android-3.4.jar‎

168 Bytes
Binary file not shown.
Binary file not shown.

‎java/3.3/test/PubnubExample.jar‎

0 Bytes
Binary file not shown.

‎java/3.3/test/PubnubUnitTest.jar‎

0 Bytes
Binary file not shown.
1.97 KB
Binary file not shown.

‎java/3.4/examples/src/com/pubnub/examples/PubnubPublishTest.java‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public static void main(String[] params) {
5353
} catch (InterruptedException e) {
5454
}
5555
ppt.runPublish();
56+
ppt.runHistory();
57+
ppt.runDetailedHistory();
5658
try {
5759
Thread.sleep(20000);
5860
} catch (InterruptedException e) {
@@ -95,6 +97,16 @@ public void runPublish() {
9597
publish(_pubnub_enc, channel_enc, messages[i]);
9698
}
9799
}
100+
101+
public void runHistory() {
102+
history(_pubnub, channel);
103+
history(_pubnub_enc, channel_enc);
104+
}
105+
public void runDetailedHistory() {
106+
detailedHistory(_pubnub, channel);
107+
detailedHistory(_pubnub_enc, channel_enc);
108+
}
109+
98110

99111
private static void notifyUser(Object message) {
100112
System.out.println(message.toString());
@@ -114,4 +126,28 @@ public void errorCallback(String channel, Object message) {
114126
}
115127
});
116128
}
129+
public void history(Pubnub pubnub, String channel) {
130+
131+
pubnub.history(channel, 10, new Callback() {
132+
public void successCallback(String channel, Object message) {
133+
notifyUser("HISTORY : " + channel + " : " + message.getClass() + " : " + message.toString());
134+
}
135+
136+
public void errorCallback(String channel, Object message) {
137+
notifyUser("HISTORY : " + channel + " : " + message.getClass() + " : " + message.toString());
138+
}
139+
});
140+
}
141+
public void detailedHistory(Pubnub pubnub, String channel) {
142+
143+
pubnub.detailedHistory(channel, 10, new Callback() {
144+
public void successCallback(String channel, Object message) {
145+
notifyUser("DETAILED HISTORY : " + channel + " : " + message.getClass() + " : " + message.toString());
146+
}
147+
148+
public void errorCallback(String channel, Object message) {
149+
notifyUser("DETAILED HISTORY : " + channel + " : " + message.getClass() + " : " + message.toString());
150+
}
151+
});
152+
}
117153
}
1.97 KB
Binary file not shown.

‎java/3.4/jars/PubnubExample.jar‎

1.97 KB
Binary file not shown.

‎java/3.4/srcPubnubApi/com/pubnub/api/PubnubCore.java‎

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ private String getOrigin() {
7676
return ORIGIN_STR;
7777
}
7878

79-
public String getCurrentlySubscribedChannelNames() {
80-
String currentChannels = subscriptions.getChannelString();
81-
return currentChannels.equals("") ? "no channels." : currentChannels;
82-
}
79+
public String getCurrentlySubscribedChannelNames() {
80+
String currentChannels = subscriptions.getChannelString();
81+
return currentChannels.equals("") ? "no channels." : currentChannels;
82+
}
8383

8484
public void setResumeOnReconnect(boolean resumeOnReconnect) {
8585
this.resumeOnReconnect = resumeOnReconnect;
@@ -414,13 +414,8 @@ public void handleResponse(String response) {
414414

415415
public void handleError(String response) {
416416
JSONArray jsarr;
417-
try {
418-
jsarr = new JSONArray(response);
419-
} catch (JSONException e) {
420-
jsarr = new JSONArray();
421-
jsarr.put("0").put(
422-
"Error: Failed JSON HTTP PubnubRequest");
423-
}
417+
jsarr = new JSONArray();
418+
jsarr.put("0").put(response);
424419
callback.errorCallback(channel, jsarr);
425420
return;
426421
}
@@ -478,13 +473,9 @@ public void handleResponse(String response) {
478473

479474
public void handleError(String response) {
480475
JSONArray jsarr;
481-
try {
482-
jsarr = new JSONArray(response);
483-
} catch (JSONException e) {
484-
jsarr = new JSONArray();
485-
jsarr.put("0").put(
486-
"Error: Failed JSON HTTP PubnubRequest");
487-
}
476+
jsarr = new JSONArray();
477+
jsarr.put("0").put(response);
478+
488479
callback.errorCallback(channel, jsarr);
489480
return;
490481
}
@@ -536,25 +527,20 @@ private void history(Hashtable args) {
536527
HttpRequest hreq = new HttpRequest(urlargs, new ResponseHandler() {
537528

538529
public void handleResponse(String response) {
539-
JSONArray jsarr;
530+
JSONArray respArr;
540531
try {
541-
jsarr = new JSONArray(response);
542-
} catch (JSONException e) {
543-
handleError(response);
544-
return;
532+
respArr = new JSONArray(response);
533+
decryptJSONArray(respArr);
534+
callback.successCallback(channel, respArr);
535+
} catch (Exception e) {
536+
callback.errorCallback(channel, "JSON processing/Decryption Error");
545537
}
546-
callback.successCallback(channel, jsarr);
547538
}
548539

549540
public void handleError(String response) {
550541
JSONArray jsarr;
551-
try {
552-
jsarr = new JSONArray(response);
553-
} catch (JSONException e) {
554-
jsarr = new JSONArray();
555-
jsarr.put("0").put(
556-
"Error: Failed JSON HTTP PubnubRequest");
557-
}
542+
jsarr = new JSONArray();
543+
jsarr.put("0").put(response);
558544
callback.errorCallback(channel, jsarr);
559545
return;
560546
}
@@ -601,25 +587,22 @@ public void detailedHistory(final String channel, long start, long end,
601587
new ResponseHandler() {
602588

603589
public void handleResponse(String response) {
604-
JSONArray jsarr;
590+
JSONArray respArr;
605591
try {
606-
jsarr = new JSONArray(response);
607-
} catch (JSONException e) {
608-
handleError(response);
609-
return;
592+
respArr = new JSONArray(response);
593+
decryptJSONArray((JSONArray) respArr.get(0));
594+
callback.successCallback(channel, respArr);
595+
} catch (Exception e) {
596+
callback.errorCallback(channel, "JSON processing/Decryption Error");
610597
}
611-
callback.successCallback(channel, jsarr);
598+
612599
}
613600

614601
public void handleError(String response) {
615602
JSONArray jsarr;
616-
try {
617-
jsarr = new JSONArray(response);
618-
} catch (JSONException e) {
619-
jsarr = new JSONArray();
620-
jsarr.put("0").put(
621-
"Error: Failed JSON HTTP PubnubRequest");
622-
}
603+
jsarr = new JSONArray();
604+
jsarr.put("0").put(response);
605+
623606
callback.errorCallback(channel, jsarr);
624607
return;
625608
}
@@ -890,6 +873,21 @@ private void callErrorCallbacks(String[] channelList, String message) {
890873
}
891874
}
892875

876+
private void decryptJSONArray(JSONArray messages) throws JSONException {
877+
878+
if (CIPHER_KEY.length() > 0) {
879+
for (int i = 0; i < messages.length(); i++) {
880+
PubnubCrypto pc = new PubnubCrypto(CIPHER_KEY);
881+
try {
882+
String message = pc.decrypt(messages.get(i).toString());
883+
messages.put(i, stringToJSON(message));
884+
} catch (Exception e) {
885+
messages.put(i,messages.get(i).toString());
886+
}
887+
}
888+
}
889+
}
890+
893891
/**
894892
* @param args
895893
* Hashtable
@@ -1107,12 +1105,12 @@ private void resubscribe() {
11071105
_timetoken = "0";
11081106
_subscribe_base(true);
11091107
}
1110-
1108+
11111109
public void disconnectAndResubscribe() {
11121110
log.verbose("Received disconnectAndResubscribe");
11131111
subscriptions.invokeDisconnectCallbackOnChannels();
11141112
resubscribe();
1115-
1113+
11161114
}
11171115
public String[] getSubscribedChannelsArray() {
11181116
return subscriptions.getChannelNames();

0 commit comments

Comments
 (0)