Skip to content

Commit 1b5b802

Browse files
author
Devendra
committed
working version of cn1lib
1 parent 6ef1e82 commit 1b5b802

40 files changed

Lines changed: 640 additions & 86 deletions

‎android/Pubnub-Android-3.5.2.jar‎

439 Bytes
Binary file not shown.
439 Bytes
Binary file not shown.
439 Bytes
Binary file not shown.
501 Bytes
Binary file not shown.

‎codenameone/PubnubClientSDK/build.xml‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<project name="PubnubClientSDK" default="build" basedir=".">
66
<description>Builds, tests, and runs the project PubnubClientSDK.</description>
77
<import file="nbproject/build-impl.xml"/>
8+
<loadfile property="VERSION" srcFile="../../VERSION"><filterchain><striplinebreaks/></filterchain></loadfile>
89
<property file="codenameone_settings.properties"/>
910

1011
<target name="create-src">
@@ -13,6 +14,9 @@
1314
<fileset dir="../srcJson"/>
1415
<fileset dir="../../java/srcPubnubApi"/>
1516
</copy>
17+
<copy includeemptydirs="true" todir="src/com/codename1">
18+
<fileset dir="../src/com/codename1"/>
19+
</copy>
1620
<copy includeemptydirs="true" todir="src/com/pubnub/api">
1721
<fileset dir="../src/com/pubnub/api/"/>
1822
</copy>
@@ -21,11 +25,11 @@
2125
<delete dir="src"/>
2226
</target>
2327
<target name="copy-lib">
24-
<copy file="dist/PubnubClientSDK.cn1lib" tofile="../pubnub.cn1lib"/>
28+
<copy file="dist/PubnubClientSDK.cn1lib" tofile="../pubnub-codenameone-${VERSION}.cn1lib"/>
2529
</target>
2630

2731

28-
<target depends="default, delete-src, copy-lib, clean" name="build">
32+
<target depends="create-src, default, delete-src, copy-lib, clean" name="build">
2933
</target>
3034

3135
<target depends="init,compile,jar" name="compile-test">
@@ -68,7 +72,7 @@
6872
<target name="Stubs">
6973
<delete dir="build/stubs"/>
7074
<javadoc sourcepath="src"
71-
classpath="lib/CodenameOne.jar:lib/CLDC11.jar"
75+
classpath="lib/CodenameOne.jar:lib/CLDC11.jar:lib/bccn1/main.zip"
7276
docletpath="Stubber.jar"
7377
doclet="com.codename1.build.client.StubGenerator">
7478
<fileset dir="${src.dir}" excludes="*.java,${excludes}" includes="${includes}">
@@ -77,16 +81,16 @@
7781
</javadoc>
7882
</target>
7983

80-
<target name="jar" depends="compile,Stubs">
84+
<target name="jar" depends="compile, Stubs">
8185
<mkdir dir="build/lib" />
8286
<zip basedir="${build.classes.dir}" compress="false" destfile="build/lib/main.zip" />
8387
<zip basedir="build/stubs" compress="false" destfile="build/lib/stubs.zip" />
8488
<copy file="manifest.properties" todir="build/lib" />
85-
<antcall target="buildNativeIOS" />
89+
<!--<antcall target="buildNativeIOS" />
8690
<antcall target="buildNativeRIM" />
8791
<antcall target="buildNativeAND" />
8892
<antcall target="buildNativeWIN" />
89-
<antcall target="buildNativeME" />
93+
<antcall target="buildNativeME" /> -->
9094
<mkdir dir="dist" />
9195
<zip basedir="build/lib" compress="true" destfile="dist/${application.title}.cn1lib" />
9296
</target>
68.4 KB
Binary file not shown.

‎codenameone/pubnub.cn1lib‎

-54 KB
Binary file not shown.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.codename1.io;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.util.Enumeration;
6+
import java.util.Hashtable;
7+
8+
import com.codename1.impl.CodenameOneImplementation;
9+
import com.pubnub.api.HttpUtil;
10+
11+
public class PubnubCn1Connection {
12+
13+
private CodenameOneImplementation impl = Util.getImplementation();
14+
private Object connection = null;
15+
private InputStream input = null;
16+
private byte[] data = null;
17+
18+
public PubnubCn1Response fetch(String url, int timeout, Hashtable _headers) throws IOException {
19+
int rc = 0;
20+
String page = null;
21+
int contentLength = 0;
22+
23+
while (HttpUtil.isRedirect(rc) || rc == 0) {
24+
connection = impl.connect(url, true, false, timeout);
25+
impl.setPostRequest(connection, false);
26+
27+
if(_headers != null) {
28+
Enumeration e = _headers.keys();
29+
while(e.hasMoreElements()) {
30+
String k = (String)e.nextElement();
31+
String value = (String)_headers.get(k);
32+
impl.setHeader(connection, k, value);
33+
}
34+
}
35+
rc = impl.getResponseCode(connection);
36+
if(HttpUtil.isRedirect(rc)) {
37+
String uri = impl.getHeaderField("location", connection);
38+
if(!(uri.startsWith("http://") || uri.startsWith("https://"))) {
39+
url = Util.relativeToAbsolute(url, uri);
40+
} else {
41+
url = uri;
42+
}
43+
}
44+
}
45+
contentLength = impl.getContentLength(connection);
46+
input = impl.openInputStream(connection);
47+
data = Util.readInputStream(input);
48+
input.close();
49+
input = null;
50+
return new PubnubCn1Response(rc, new String(data, "UTF-8"));
51+
}
52+
public void disconnect() {
53+
54+
}
55+
56+
}
57+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.codename1.io;
2+
3+
public class PubnubCn1Response {
4+
private String response;
5+
private int responseStatusCode;
6+
public String getResponse() {
7+
return response;
8+
}
9+
public int getResponseStatusCode() {
10+
return responseStatusCode;
11+
}
12+
public PubnubCn1Response(int responseStatusCode, String response) {
13+
this.response = response;
14+
this.responseStatusCode = responseStatusCode;
15+
}
16+
}
17+

‎codenameone/src/com/pubnub/api/HttpClientCore.java‎

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,21 @@
1010
import java.util.Hashtable;
1111

1212
import com.codename1.impl.CodenameOneImplementation;
13-
import com.codename1.io.Util;
13+
import com.codename1.io.*;
1414

1515
class HttpClientCore extends HttpClient {
16+
17+
18+
PubnubCn1Connection connection;
1619
private int requestTimeout = 310000;
1720
private int connectionTimeout = 5000;
18-
//HttpURLConnection connection;
21+
22+
1923
protected static Logger log = new Logger(Worker.class);
2024

2125
private void init() {
2226
//HttpURLConnection.setFollowRedirects(true);
27+
connection = new PubnubCn1Connection();
2328
}
2429

2530
public HttpClientCore(int connectionTimeout, int requestTimeout, Hashtable headers) {
@@ -45,36 +50,19 @@ public void setConnectionTimeout(int connectionTimeout) {
4550
this.connectionTimeout = connectionTimeout;
4651
}
4752

48-
public boolean isRedirect(int rc) {
49-
/* return (rc == HttpURLConnection.HTTP_MOVED_PERM
50-
|| rc == HttpURLConnection.HTTP_MOVED_TEMP || rc == HttpURLConnection.HTTP_SEE_OTHER);
51-
*/
52-
return true;
53-
}
54-
55-
public boolean checkResponse(int rc) {
56-
return true; //return (rc == HttpURLConnection.HTTP_OK || isRedirect(rc));
57-
}
58-
59-
public boolean checkResponseSuccess(int rc) {
60-
return true; //return (rc == HttpURLConnection.HTTP_OK);
61-
}
62-
public HttpResponse fetch(String url) throws PubnubException { //, SocketTimeoutException {
53+
public HttpResponse fetch(String url) throws PubnubException, IOException {
6354
return fetch(url, null);
6455
}
6556

6657
public synchronized HttpResponse fetch(String url, Hashtable headers)
67-
throws PubnubException { // log.verbose("URL = " + url + " : RESPONSE = " + page);
68-
return null;//new HttpResponse(rc, page);
69-
}
70-
71-
public boolean isOk(int rc) {
72-
//return (rc == HttpURLConnection.HTTP_OK);
73-
return true;
58+
throws PubnubException, IOException {
59+
System.out.println(url);
60+
PubnubCn1Response pcr = connection.fetch(url, requestTimeout, headers);
61+
return new HttpResponse(pcr.getResponseStatusCode(), pcr.getResponse());//new HttpResponse(rc, page);
7462
}
7563

7664
public void shutdown() {
77-
//if (connection != null) connection.disconnect();
65+
if (connection != null) connection.disconnect();
7866
}
7967
}
8068

0 commit comments

Comments
 (0)