diff --git a/android/Pubnub-Android-3.5.2.jar b/android/Pubnub-Android-3.5.2.jar index cd09e9215..ab939dcce 100644 Binary files a/android/Pubnub-Android-3.5.2.jar and b/android/Pubnub-Android-3.5.2.jar differ diff --git a/android/examples/PubnubExample/libs/Pubnub-Android-3.5.2.jar b/android/examples/PubnubExample/libs/Pubnub-Android-3.5.2.jar index cd09e9215..ab939dcce 100644 Binary files a/android/examples/PubnubExample/libs/Pubnub-Android-3.5.2.jar and b/android/examples/PubnubExample/libs/Pubnub-Android-3.5.2.jar differ diff --git a/android/examples/SubscribeAtBoot/libs/Pubnub-Android-3.5.2.jar b/android/examples/SubscribeAtBoot/libs/Pubnub-Android-3.5.2.jar index cd09e9215..ab939dcce 100644 Binary files a/android/examples/SubscribeAtBoot/libs/Pubnub-Android-3.5.2.jar and b/android/examples/SubscribeAtBoot/libs/Pubnub-Android-3.5.2.jar differ diff --git a/blackberry/Pubnub-BlackBerry-3.5.2.jar b/blackberry/Pubnub-BlackBerry-3.5.2.jar index dd8c1a6e8..350a0005a 100644 Binary files a/blackberry/Pubnub-BlackBerry-3.5.2.jar and b/blackberry/Pubnub-BlackBerry-3.5.2.jar differ diff --git a/codenameone/pubnub-codenameone-3.5.2.cn1lib b/codenameone/pubnub-codenameone-3.5.2.cn1lib index e8d2badc5..4f99279af 100644 Binary files a/codenameone/pubnub-codenameone-3.5.2.cn1lib and b/codenameone/pubnub-codenameone-3.5.2.cn1lib differ diff --git a/codenameone/src/com/codename1/io/PubnubCn1Connection.java b/codenameone/src/com/codename1/io/PubnubCn1Connection.java index 4444a06a6..c18faea7e 100644 --- a/codenameone/src/com/codename1/io/PubnubCn1Connection.java +++ b/codenameone/src/com/codename1/io/PubnubCn1Connection.java @@ -7,51 +7,72 @@ import com.codename1.impl.CodenameOneImplementation; import com.pubnub.api.HttpUtil; +import java.io.UnsupportedEncodingException; +//import java.util.logging.Level; +//import java.util.logging.Logger; public class PubnubCn1Connection { - private CodenameOneImplementation impl = Util.getImplementation(); - private Object connection = null; - private InputStream input = null; - private byte[] data = null; - - public PubnubCn1Response fetch(String url, int timeout, Hashtable _headers) throws IOException { - int rc = 0; - String page = null; - int contentLength = 0; - - while (HttpUtil.isRedirect(rc) || rc == 0) { - connection = impl.connect(url, true, false, timeout); - impl.setPostRequest(connection, false); - - if(_headers != null) { - Enumeration e = _headers.keys(); - while(e.hasMoreElements()) { - String k = (String)e.nextElement(); - String value = (String)_headers.get(k); - impl.setHeader(connection, k, value); - } - } - rc = impl.getResponseCode(connection); - if(HttpUtil.isRedirect(rc)) { - String uri = impl.getHeaderField("location", connection); - if(!(uri.startsWith("http://") || uri.startsWith("https://"))) { + private CodenameOneImplementation impl = Util.getImplementation(); + private Object connection = null; + private InputStream input = null; + + private byte[] data = null; + + public PubnubCn1Response fetch(String url, int timeout, Hashtable _headers) throws UnsupportedEncodingException, IOException { + int rc = 0; + String page = null; + int contentLength = 0; + + while (HttpUtil.isRedirect(rc) || rc == 0) { + try { + connection = impl.connect(url, true, false, timeout); + } catch (IOException ex) { + throw ex; + } + impl.setPostRequest(connection, false); + + if (_headers != null) { + Enumeration e = _headers.keys(); + while (e.hasMoreElements()) { + String k = (String) e.nextElement(); + String value = (String) _headers.get(k); + impl.setHeader(connection, k, value); + } + } + try { + rc = impl.getResponseCode(connection); + } catch (IOException ex) { + throw ex; + } + if (HttpUtil.isRedirect(rc)) { + String uri; + try { + uri = impl.getHeaderField("location", connection); + } catch (IOException ex) { + throw ex; + } + if (!(uri.startsWith("http://") || uri.startsWith("https://"))) { url = Util.relativeToAbsolute(url, uri); } else { url = uri; } } - } - contentLength = impl.getContentLength(connection); - input = impl.openInputStream(connection); - data = Util.readInputStream(input); - input.close(); + } + contentLength = impl.getContentLength(connection); + try { + input = impl.openInputStream(connection); + data = Util.readInputStream(input); + input.close(); + } catch (IOException ex) { + return new PubnubCn1Response(rc, ex.getMessage() ); + } + input = null; - return new PubnubCn1Response(rc, new String(data, "UTF-8")); - } - public void disconnect() { - } + return new PubnubCn1Response(rc, new String(data, "UTF-8")); + } + public void disconnect() { + } } - diff --git a/codenameone/src/com/pubnub/api/HttpClientCore.java b/codenameone/src/com/pubnub/api/HttpClientCore.java index 66489ab7b..aa42a92cc 100644 --- a/codenameone/src/com/pubnub/api/HttpClientCore.java +++ b/codenameone/src/com/pubnub/api/HttpClientCore.java @@ -1,6 +1,6 @@ package com.pubnub.api; -import static com.pubnub.api.PubnubError.PNERROBJ_READINPUT; +import static com.pubnub.api.PubnubError.*; import static com.pubnub.api.PubnubError.getErrorObject; import java.io.ByteArrayOutputStream; @@ -11,6 +11,7 @@ import com.codename1.impl.CodenameOneImplementation; import com.codename1.io.*; +import org.json.*; class HttpClientCore extends HttpClient { @@ -55,8 +56,45 @@ public HttpResponse fetch(String url) throws PubnubException, IOException { public synchronized HttpResponse fetch(String url, Hashtable headers) throws PubnubException, IOException { - System.out.println(url); - PubnubCn1Response pcr = connection.fetch(url, requestTimeout, headers); + IOException excp = null; + PubnubCn1Response pcr = null; + try { + pcr = connection.fetch(url, requestTimeout, headers); + } catch (IOException ex) { + excp = ex; + } + String page = pcr.getResponse(); + switch (pcr.getResponseStatusCode()) { + case HttpUtil.HTTP_FORBIDDEN: + throw new PubnubException(getErrorObject(PNERROBJ_FORBIDDEN, page)); + case HttpUtil.HTTP_UNAUTHORIZED: + throw new PubnubException(getErrorObject(PNERROBJ_UNAUTHORIZED, page)); + case HttpUtil.HTTP_BAD_REQUEST: + try { + JSONArray jsarr = new JSONArray(page); + String error = jsarr.get(1).toString(); + throw new PubnubException(getErrorObject(PNERROBJ_BAD_REQUEST, 1, error)); + } catch (JSONException e) { + JSONObject jso; + try { + jso = new JSONObject(page); + throw new PubnubException(getErrorObject(PNERROBJ_BAD_REQUEST, 2, jso.toString())); + } catch (JSONException e1) { + throw new PubnubException(getErrorObject(PNERROBJ_INVALID_JSON, 2)); + } + } + case HttpUtil.HTTP_BAD_GATEWAY: + throw new PubnubException(getErrorObject(PNERROBJ_BAD_GATEWAY, url)); + case HttpUtil.HTTP_CLIENT_TIMEOUT: + throw new PubnubException(getErrorObject(PNERROBJ_CLIENT_TIMEOUT, url)); + case HttpUtil.HTTP_GATEWAY_TIMEOUT: + throw new PubnubException(getErrorObject(PNERROBJ_GATEWAY_TIMEOUT, url)); + case HttpUtil.HTTP_INTERNAL_ERROR: + throw new PubnubException(getErrorObject(PNERROBJ_INTERNAL_ERROR, url)); + default: + if (excp != null) throw excp; + break; + } return new HttpResponse(pcr.getResponseStatusCode(), pcr.getResponse()); } diff --git a/codenameone/src/com/pubnub/api/SubscribeWorker.java b/codenameone/src/com/pubnub/api/SubscribeWorker.java index 7ca1b5df6..98abc93e1 100644 --- a/codenameone/src/com/pubnub/api/SubscribeWorker.java +++ b/codenameone/src/com/pubnub/api/SubscribeWorker.java @@ -6,7 +6,7 @@ import static com.pubnub.api.PubnubError.*; class SubscribeWorker extends AbstractSubscribeWorker { - + private Exception excp = null; SubscribeWorker(Vector _requestQueue, int connectionTimeout, int requestTimeout, int maxRetries, int retryInterval, Hashtable headers) { super(_requestQueue, connectionTimeout, requestTimeout, @@ -48,12 +48,12 @@ void process(HttpRequest hreq) { break; } */catch (PubnubException e) { - + excp = e; switch(e.getPubnubError().errorCode) { case PNERR_FORBIDDEN: case PNERR_UNAUTHORIZED: log.verbose("Authentication Failure : " + e.toString()); - currentRetryAttempt = 1; + currentRetryAttempt++; break; default: log.verbose("Retry Attempt : " + ((currentRetryAttempt == maxRetries)?"last":currentRetryAttempt) @@ -63,6 +63,7 @@ void process(HttpRequest hreq) { } } catch (Exception e) { + excp = e; log.verbose("Retry Attempt : " + ((currentRetryAttempt == maxRetries)?"last":currentRetryAttempt) + " Exception in Fetch : " + e.toString()); currentRetryAttempt++; @@ -80,7 +81,12 @@ void process(HttpRequest hreq) { log.verbose("Exhausted number of retries"); hreq.getResponseHandler().handleTimeout(hreq); } else { - hreq.getResponseHandler().handleError(hreq, getErrorObject(PNERROBJ_HTTP_ERROR, 1)); + + if (excp != null && excp instanceof PubnubException && ((PubnubException) excp).getPubnubError() != null) { + hreq.getResponseHandler().handleError(hreq, ((PubnubException) excp).getPubnubError()); + } else { + hreq.getResponseHandler().handleError(hreq, getErrorObject(PNERROBJ_HTTP_ERROR, 1)); + } } return; } diff --git a/j2me/Pubnub-MicroEdition-3.5.2.jar b/j2me/Pubnub-MicroEdition-3.5.2.jar index 5f2a28ac2..f0102c872 100644 Binary files a/j2me/Pubnub-MicroEdition-3.5.2.jar and b/j2me/Pubnub-MicroEdition-3.5.2.jar differ diff --git a/java/Pubnub-StandardEdition-3.5.2.jar b/java/Pubnub-StandardEdition-3.5.2.jar index 3ecc5112d..63382763f 100644 Binary files a/java/Pubnub-StandardEdition-3.5.2.jar and b/java/Pubnub-StandardEdition-3.5.2.jar differ diff --git a/java/doc/allclasses-frame.html b/java/doc/allclasses-frame.html index 1e0fe879d..03b8f040c 100644 --- a/java/doc/allclasses-frame.html +++ b/java/doc/allclasses-frame.html @@ -2,7 +2,7 @@ - + All Classes diff --git a/java/doc/allclasses-noframe.html b/java/doc/allclasses-noframe.html index 46edaf356..15e5fe98c 100644 --- a/java/doc/allclasses-noframe.html +++ b/java/doc/allclasses-noframe.html @@ -2,7 +2,7 @@ - + All Classes diff --git a/java/doc/com/pubnub/api/Callback.html b/java/doc/com/pubnub/api/Callback.html index e5c37ca5a..e93a15030 100644 --- a/java/doc/com/pubnub/api/Callback.html +++ b/java/doc/com/pubnub/api/Callback.html @@ -2,7 +2,7 @@ - + Callback diff --git a/java/doc/com/pubnub/api/HttpUtil.html b/java/doc/com/pubnub/api/HttpUtil.html index 3c42fa3f6..29391678b 100644 --- a/java/doc/com/pubnub/api/HttpUtil.html +++ b/java/doc/com/pubnub/api/HttpUtil.html @@ -2,7 +2,7 @@ - + HttpUtil @@ -113,6 +113,54 @@

static int +HTTP_BAD_GATEWAY + +
+            + + + +static int +HTTP_BAD_REQUEST + +
+            + + + +static int +HTTP_CLIENT_TIMEOUT + +
+            + + + +static int +HTTP_FORBIDDEN + +
+            + + + +static int +HTTP_GATEWAY_TIMEOUT + +
+            + + + +static int +HTTP_INTERNAL_ERROR + +
+            + + + +static int HTTP_MOVED_PERM
@@ -139,6 +187,14 @@

static int HTTP_SEE_OTHER +
+            + + + +static int +HTTP_UNAUTHORIZED +
            @@ -261,6 +317,76 @@

See Also:
Constant Field Values
+
+ +

+HTTP_FORBIDDEN

+
+public static final int HTTP_FORBIDDEN
+
+
+
See Also:
Constant Field Values
+
+
+ +

+HTTP_UNAUTHORIZED

+
+public static final int HTTP_UNAUTHORIZED
+
+
+
See Also:
Constant Field Values
+
+
+ +

+HTTP_BAD_REQUEST

+
+public static final int HTTP_BAD_REQUEST
+
+
+
See Also:
Constant Field Values
+
+
+ +

+HTTP_BAD_GATEWAY

+
+public static final int HTTP_BAD_GATEWAY
+
+
+
See Also:
Constant Field Values
+
+
+ +

+HTTP_CLIENT_TIMEOUT

+
+public static final int HTTP_CLIENT_TIMEOUT
+
+
+
See Also:
Constant Field Values
+
+
+ +

+HTTP_GATEWAY_TIMEOUT

+
+public static final int HTTP_GATEWAY_TIMEOUT
+
+
+
See Also:
Constant Field Values
+
+
+ +

+HTTP_INTERNAL_ERROR

+
+public static final int HTTP_INTERNAL_ERROR
+
+
+
See Also:
Constant Field Values
+
diff --git a/java/doc/com/pubnub/api/Pubnub.html b/java/doc/com/pubnub/api/Pubnub.html index fbe043777..279ecf2a5 100644 --- a/java/doc/com/pubnub/api/Pubnub.html +++ b/java/doc/com/pubnub/api/Pubnub.html @@ -2,7 +2,7 @@ - + Pubnub diff --git a/java/doc/com/pubnub/api/PubnubError.html b/java/doc/com/pubnub/api/PubnubError.html index 8992e5bce..f96ee9a9c 100644 --- a/java/doc/com/pubnub/api/PubnubError.html +++ b/java/doc/com/pubnub/api/PubnubError.html @@ -2,7 +2,7 @@ - + PubnubError diff --git a/java/doc/com/pubnub/api/PubnubException.html b/java/doc/com/pubnub/api/PubnubException.html index 35a778552..46b29b2bd 100644 --- a/java/doc/com/pubnub/api/PubnubException.html +++ b/java/doc/com/pubnub/api/PubnubException.html @@ -2,7 +2,7 @@ - + PubnubException diff --git a/java/doc/com/pubnub/api/PubnubUtil.html b/java/doc/com/pubnub/api/PubnubUtil.html index 0ac619879..57ab2b4e9 100644 --- a/java/doc/com/pubnub/api/PubnubUtil.html +++ b/java/doc/com/pubnub/api/PubnubUtil.html @@ -2,7 +2,7 @@ - + PubnubUtil diff --git a/java/doc/com/pubnub/api/package-frame.html b/java/doc/com/pubnub/api/package-frame.html index 7421eaf39..0d31be332 100644 --- a/java/doc/com/pubnub/api/package-frame.html +++ b/java/doc/com/pubnub/api/package-frame.html @@ -2,7 +2,7 @@ - + com.pubnub.api diff --git a/java/doc/com/pubnub/api/package-summary.html b/java/doc/com/pubnub/api/package-summary.html index e46db92c4..1b9654186 100644 --- a/java/doc/com/pubnub/api/package-summary.html +++ b/java/doc/com/pubnub/api/package-summary.html @@ -2,7 +2,7 @@ - + com.pubnub.api diff --git a/java/doc/com/pubnub/api/package-tree.html b/java/doc/com/pubnub/api/package-tree.html index 1f4ccb8d4..548d178ea 100644 --- a/java/doc/com/pubnub/api/package-tree.html +++ b/java/doc/com/pubnub/api/package-tree.html @@ -2,7 +2,7 @@ - + com.pubnub.api Class Hierarchy diff --git a/java/doc/constant-values.html b/java/doc/constant-values.html index 466f57c68..a6f886f0d 100644 --- a/java/doc/constant-values.html +++ b/java/doc/constant-values.html @@ -2,7 +2,7 @@ - + Constant Field Values @@ -101,6 +101,42 @@

com.pubnub.api.HttpUtil + +public static final int +HTTP_BAD_GATEWAY +502 + + + +public static final int +HTTP_BAD_REQUEST +400 + + + +public static final int +HTTP_CLIENT_TIMEOUT +408 + + + +public static final int +HTTP_FORBIDDEN +403 + + + +public static final int +HTTP_GATEWAY_TIMEOUT +504 + + + +public static final int +HTTP_INTERNAL_ERROR +500 + + public static final int HTTP_MOVED_PERM @@ -124,6 +160,12 @@

HTTP_SEE_OTHER 303 + + +public static final int +HTTP_UNAUTHORIZED +401 + diff --git a/java/doc/deprecated-list.html b/java/doc/deprecated-list.html index 441f910ad..f67e6f6f6 100644 --- a/java/doc/deprecated-list.html +++ b/java/doc/deprecated-list.html @@ -2,7 +2,7 @@ - + Deprecated List diff --git a/java/doc/help-doc.html b/java/doc/help-doc.html index 607d5e082..5ba4bf615 100644 --- a/java/doc/help-doc.html +++ b/java/doc/help-doc.html @@ -2,7 +2,7 @@ - + API Help diff --git a/java/doc/index-all.html b/java/doc/index-all.html index 3ccbf2821..23dce4a4e 100644 --- a/java/doc/index-all.html +++ b/java/doc/index-all.html @@ -2,7 +2,7 @@ - + Index @@ -197,6 +197,24 @@
history(String, int, Callback) - Method in class com.pubnub.api.Pubnub
Read History for a channel. +
HTTP_BAD_GATEWAY - +Static variable in class com.pubnub.api.HttpUtil +
  +
HTTP_BAD_REQUEST - +Static variable in class com.pubnub.api.HttpUtil +
  +
HTTP_CLIENT_TIMEOUT - +Static variable in class com.pubnub.api.HttpUtil +
  +
HTTP_FORBIDDEN - +Static variable in class com.pubnub.api.HttpUtil +
  +
HTTP_GATEWAY_TIMEOUT - +Static variable in class com.pubnub.api.HttpUtil +
  +
HTTP_INTERNAL_ERROR - +Static variable in class com.pubnub.api.HttpUtil +
 
HTTP_MOVED_PERM - Static variable in class com.pubnub.api.HttpUtil
  @@ -209,6 +227,9 @@
HTTP_SEE_OTHER - Static variable in class com.pubnub.api.HttpUtil
  +
HTTP_UNAUTHORIZED - +Static variable in class com.pubnub.api.HttpUtil +
 
HttpUtil - Class in com.pubnub.api
 
HttpUtil() - Constructor for class com.pubnub.api.HttpUtil
  diff --git a/java/doc/index.html b/java/doc/index.html index ff552c5f6..554526ef1 100644 --- a/java/doc/index.html +++ b/java/doc/index.html @@ -2,7 +2,7 @@ - + Generated Documentation (Untitled) diff --git a/java/doc/overview-tree.html b/java/doc/overview-tree.html index b30903436..2bc3a80a2 100644 --- a/java/doc/overview-tree.html +++ b/java/doc/overview-tree.html @@ -2,7 +2,7 @@ - + Class Hierarchy diff --git a/java/doc/serialized-form.html b/java/doc/serialized-form.html index 82566bee2..722ea4503 100644 --- a/java/doc/serialized-form.html +++ b/java/doc/serialized-form.html @@ -2,7 +2,7 @@ - + Serialized Form diff --git a/java/jars/Pubnub-UnitTests-3.5.2.jar b/java/jars/Pubnub-UnitTests-3.5.2.jar index 16ee5aa91..aa08af3b9 100644 Binary files a/java/jars/Pubnub-UnitTests-3.5.2.jar and b/java/jars/Pubnub-UnitTests-3.5.2.jar differ diff --git a/java/jars/PubnubDemoConsole.jar b/java/jars/PubnubDemoConsole.jar index c8e67fa74..4d11a6721 100644 Binary files a/java/jars/PubnubDemoConsole.jar and b/java/jars/PubnubDemoConsole.jar differ diff --git a/java/jars/PubnubExample.jar b/java/jars/PubnubExample.jar index 2cf423de1..16b10c9e5 100644 Binary files a/java/jars/PubnubExample.jar and b/java/jars/PubnubExample.jar differ diff --git a/java/srcPubnubApi/com/pubnub/api/HttpUtil.java b/java/srcPubnubApi/com/pubnub/api/HttpUtil.java index 518ce7569..d27f5b0a6 100644 --- a/java/srcPubnubApi/com/pubnub/api/HttpUtil.java +++ b/java/srcPubnubApi/com/pubnub/api/HttpUtil.java @@ -1,10 +1,17 @@ package com.pubnub.api; public class HttpUtil { - public static final int HTTP_MOVED_PERM = 301; - public static final int HTTP_MOVED_TEMP = 302; - public static final int HTTP_SEE_OTHER = 303; - public static final int HTTP_OK = 200; + public static final int HTTP_MOVED_PERM = 301; + public static final int HTTP_MOVED_TEMP = 302; + public static final int HTTP_SEE_OTHER = 303; + public static final int HTTP_OK = 200; + public static final int HTTP_FORBIDDEN = 403; + public static final int HTTP_UNAUTHORIZED = 401; + public static final int HTTP_BAD_REQUEST = 400; + public static final int HTTP_BAD_GATEWAY = 502; + public static final int HTTP_CLIENT_TIMEOUT = 408; + public static final int HTTP_GATEWAY_TIMEOUT = 504; + public static final int HTTP_INTERNAL_ERROR = 500; public static boolean isRedirect(int rc) { return (rc == HttpUtil.HTTP_MOVED_PERM diff --git a/java/srcPubnubApi/com/pubnub/api/PubnubCore.java b/java/srcPubnubApi/com/pubnub/api/PubnubCore.java index d143bc381..dda8e80f8 100644 --- a/java/srcPubnubApi/com/pubnub/api/PubnubCore.java +++ b/java/srcPubnubApi/com/pubnub/api/PubnubCore.java @@ -1475,7 +1475,7 @@ public void handleBackFromDar(HttpRequest hreq) { } public void handleError(HttpRequest hreq, PubnubError error) { - disconnectAndResubscribe(); + disconnectAndResubscribe(error); } public void handleTimeout(HttpRequest hreq) {