From 4aa674ec13a353834249c530537d13db1fa7eaf6 Mon Sep 17 00:00:00 2001 From: Devendra Date: Tue, 9 Jul 2013 22:15:25 +0530 Subject: [PATCH] PAM changes for j2me/bb --- .../com/pubnub/examples/me/AuthKeyConfig.java | 39 +++++++++++++++++++ .../src/com/pubnub/examples/me/HereNow.java | 2 +- .../com/pubnub/examples/me/PubnubMenu.java | 9 +++++ j2me/src1/com/pubnub/api/SubscribeWorker.java | 6 ++- 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 j2me/examples/PubnubExample/src/com/pubnub/examples/me/AuthKeyConfig.java diff --git a/j2me/examples/PubnubExample/src/com/pubnub/examples/me/AuthKeyConfig.java b/j2me/examples/PubnubExample/src/com/pubnub/examples/me/AuthKeyConfig.java new file mode 100644 index 000000000..521d05cd1 --- /dev/null +++ b/j2me/examples/PubnubExample/src/com/pubnub/examples/me/AuthKeyConfig.java @@ -0,0 +1,39 @@ +package com.pubnub.examples.me; + +import java.util.Hashtable; + +import javax.microedition.lcdui.ChoiceGroup; +import javax.microedition.lcdui.Command; +import javax.microedition.lcdui.CommandListener; +import javax.microedition.lcdui.Display; +import javax.microedition.lcdui.Displayable; +import javax.microedition.lcdui.Form; +import javax.microedition.lcdui.TextField; + +import com.pubnub.api.Callback; +import com.pubnub.api.Pubnub; +import com.pubnub.api.PubnubError; + +public class AuthKeyConfig extends PubnubCommand { + + public AuthKeyConfig(Pubnub pubnub, Display display, Form menu) { + super(pubnub, display, menu, "Set Auth Keys"); + } + + protected void initForm() { + final TextField txtAuthKey = new TextField("Auth Key : ", "", 255, TextField.ANY); + + form = new Form("History"); + form.append(txtAuthKey); + form.addCommand(new Command("Set Auth Key", Command.OK, 2)); + + form.setCommandListener(new CommandListener() { + public void commandAction(Command arg0, Displayable arg1) { + _pubnub.setAuthKey(txtAuthKey.getString()); + display.setCurrent(menu); + } + }); + + } + +} diff --git a/j2me/examples/PubnubExample/src/com/pubnub/examples/me/HereNow.java b/j2me/examples/PubnubExample/src/com/pubnub/examples/me/HereNow.java index e02f3bb5a..ab65b686e 100644 --- a/j2me/examples/PubnubExample/src/com/pubnub/examples/me/HereNow.java +++ b/j2me/examples/PubnubExample/src/com/pubnub/examples/me/HereNow.java @@ -30,7 +30,7 @@ public void successCallback(String channel, Object message) { notifyUser(message.toString()); } - public void errorCallback(String channel, PubnubError message) { + public void errorCallback(String channel, PubnubError error) { notifyUser(channel + " : " + error.toString()); } }); diff --git a/j2me/examples/PubnubExample/src/com/pubnub/examples/me/PubnubMenu.java b/j2me/examples/PubnubExample/src/com/pubnub/examples/me/PubnubMenu.java index 07a20e119..67941f087 100644 --- a/j2me/examples/PubnubExample/src/com/pubnub/examples/me/PubnubMenu.java +++ b/j2me/examples/PubnubExample/src/com/pubnub/examples/me/PubnubMenu.java @@ -31,6 +31,7 @@ public Form getMenu() { final ToggleResumeOnReconnect toggleResumeOnReconnect; final Time time; final DisconnectAndResubscribe disconnectAndResubscribe; + final AuthKeyConfig authKeyConfig; if (menu == null) { final Command exitCommand; final Command publishCommand; @@ -45,6 +46,7 @@ public Form getMenu() { final Command detailedHistoryCommand; final Command disconnectAndResubscribeCommand; final Command toggleResumeOnReconnectCommand; + final Command authKeyConfigCommand; menu = new Form("Pubnub Demo Console"); publish = new Publish(pubnub, display, menu); @@ -56,6 +58,7 @@ public Form getMenu() { unsubscribe = new Unsubscribe(pubnub,display,menu); toggleResumeOnReconnect = new ToggleResumeOnReconnect(pubnub,display,menu); disconnectAndResubscribe = new DisconnectAndResubscribe(pubnub,display,menu); + authKeyConfig = new AuthKeyConfig(pubnub,display,menu); time = new Time(pubnub,display,menu); @@ -82,6 +85,9 @@ public Form getMenu() { menu.addCommand(hereNowCommand); exitCommand = new Command("Exit", Command.EXIT, 0); menu.addCommand(exitCommand); + authKeyConfigCommand = new Command("Set Auth Key", Command.ITEM, 0); + menu.addCommand(authKeyConfigCommand); + menu.setCommandListener(new CommandListener() { public void commandAction(Command command, Displayable displayable) { @@ -107,8 +113,11 @@ public void commandAction(Command command, Displayable displayable) { disconnectAndResubscribe.handler(); } else if (command == toggleResumeOnReconnectCommand) { toggleResumeOnReconnect.handler(); + } else if (command == authKeyConfigCommand) { + authKeyConfig.handler(); } + } }); } diff --git a/j2me/src1/com/pubnub/api/SubscribeWorker.java b/j2me/src1/com/pubnub/api/SubscribeWorker.java index ffde6b11d..ee2ab4509 100644 --- a/j2me/src1/com/pubnub/api/SubscribeWorker.java +++ b/j2me/src1/com/pubnub/api/SubscribeWorker.java @@ -68,7 +68,11 @@ void process(HttpRequest hreq) { log.verbose("Exhausted number of retries"); hreq.getResponseHandler().handleTimeout(hreq); } else { - hreq.getResponseHandler().handleError(hreq, PubnubError.PNERROBJ_CLIENT_TIMEOUT); + if (excp != null && excp instanceof PubnubException && ((PubnubException) excp).getPubnubError() != null) { + hreq.getResponseHandler().handleError(hreq, ((PubnubException) excp).getPubnubError()); + } else { + hreq.getResponseHandler().handleError(hreq, PubnubError.getErrorObject(PubnubError.PNERROBJ_HTTP_ERROR, 1)); + } } return; }