Skip to content

Commit 8b1f98a

Browse files
author
Devendra
committed
changes to j2me code for new error framework and PAM
1 parent e13fa9d commit 8b1f98a

34 files changed

Lines changed: 247 additions & 148 deletions

‎android/Pubnub-Android-3.5.2.jar‎

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
702 Bytes
Binary file not shown.
-5 Bytes
Binary file not shown.

‎j2me/Pubnub-MicroEdition-3.5.2.jar‎

631 Bytes
Binary file not shown.

‎j2me/src1/com/pubnub/api/HttpClientCore.java‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
import com.tinyline.util.GZIPInputStream;
1313

14+
import org.json.me.*;
15+
1416
public class HttpClientCore extends HttpClient {
1517
private int requestTimeout = 310000;
1618
private int connectionTimeout = 5000;
@@ -89,11 +91,11 @@ public boolean checkResponse(int rc) {
8991
return (rc == HttpConnection.HTTP_OK || isRedirect(rc));
9092
}
9193

92-
public HttpResponse fetch(String url) throws IOException {
94+
public HttpResponse fetch(String url) throws PubnubException, IOException {
9395
return fetch(url, null);
9496
}
9597

96-
public HttpResponse fetch(String url, Hashtable headers) throws IOException {
98+
public HttpResponse fetch(String url, Hashtable headers) throws PubnubException, IOException {
9799
if (url == null)
98100
throw new IOException("Invalid Url");
99101

@@ -159,6 +161,37 @@ public HttpResponse fetch(String url, Hashtable headers) throws IOException {
159161
}
160162

161163
response = readResponse(hc);
164+
switch (rc) {
165+
case HttpUtil.HTTP_FORBIDDEN:
166+
throw new PubnubException(PubnubError.getErrorObject(PubnubError.PNERROBJ_FORBIDDEN, response));
167+
case HttpUtil.HTTP_UNAUTHORIZED:
168+
throw new PubnubException(PubnubError.getErrorObject(PubnubError.PNERROBJ_UNAUTHORIZED, response));
169+
case HttpUtil.HTTP_BAD_REQUEST:
170+
try {
171+
JSONArray jsarr = new JSONArray(response);
172+
String error = jsarr.get(1).toString();
173+
throw new PubnubException(PubnubError.getErrorObject(PubnubError.PNERROBJ_BAD_REQUEST, 1, error));
174+
} catch (JSONException e) {
175+
JSONObject jso;
176+
try {
177+
jso = new JSONObject(response);
178+
throw new PubnubException(PubnubError.getErrorObject(PubnubError.PNERROBJ_BAD_REQUEST, 2, jso.toString()));
179+
} catch (JSONException e1) {
180+
throw new PubnubException(PubnubError.getErrorObject(PubnubError.PNERROBJ_INVALID_JSON, 2));
181+
}
182+
}
183+
case HttpUtil.HTTP_BAD_GATEWAY:
184+
throw new PubnubException(PubnubError.getErrorObject(PubnubError.PNERROBJ_BAD_GATEWAY, url));
185+
case HttpUtil.HTTP_CLIENT_TIMEOUT:
186+
throw new PubnubException(PubnubError.getErrorObject(PubnubError.PNERROBJ_CLIENT_TIMEOUT, url));
187+
case HttpUtil.HTTP_GATEWAY_TIMEOUT:
188+
throw new PubnubException(PubnubError.getErrorObject(PubnubError.PNERROBJ_GATEWAY_TIMEOUT, url));
189+
case HttpUtil.HTTP_INTERNAL_ERROR:
190+
throw new PubnubException(PubnubError.getErrorObject(PubnubError.PNERROBJ_INTERNAL_ERROR, url));
191+
default:
192+
break;
193+
}
194+
162195
hc.close();
163196
return new HttpResponse(rc, response);
164197
}

‎j2me/src1/com/pubnub/api/SubscribeWorker.java‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
class SubscribeWorker extends AbstractSubscribeWorker {
77

8+
private Exception excp = null;
9+
810
SubscribeWorker(Vector _requestQueue, int connectionTimeout,
911
int requestTimeout, int maxRetries, int retryInterval, Hashtable headers) {
1012
super(_requestQueue, connectionTimeout, requestTimeout,
@@ -33,7 +35,22 @@ void process(HttpRequest hreq) {
3335
}
3436
break;
3537
36-
} */catch (Exception e) {
38+
}*/catch (PubnubException e) {
39+
excp = e;
40+
switch (e.getPubnubError().errorCode) {
41+
case PubnubError.PNERR_FORBIDDEN:
42+
case PubnubError.PNERR_UNAUTHORIZED:
43+
log.verbose("Authentication Failure : " + e.toString());
44+
currentRetryAttempt = maxRetries + 1;
45+
break;
46+
default:
47+
log.verbose("Retry Attempt : " + ((currentRetryAttempt == maxRetries)?"last":String.valueOf(currentRetryAttempt))
48+
+ " Exception in Fetch : " + e.toString());
49+
currentRetryAttempt++;
50+
break;
51+
}
52+
53+
} catch (Exception e) {
3754
log.verbose("Retry Attempt : " + ((currentRetryAttempt == maxRetries)?"last":String.valueOf(currentRetryAttempt))
3855
+ " Exception in Fetch : " + e.toString());
3956
currentRetryAttempt++;
105 Bytes
Binary file not shown.

‎java/doc/allclasses-frame.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!--NewPage-->
33
<HTML>
44
<HEAD>
5-
<!-- Generated by javadoc (build 1.6.0_37) on Tue Jul 09 10:04:57 IST 2013 -->
5+
<!-- Generated by javadoc (build 1.6.0_37) on Tue Jul 09 15:10:08 IST 2013 -->
66
<TITLE>
77
All Classes
88
</TITLE>

0 commit comments

Comments
 (0)