Skip to content

Commit

Permalink
working version of cn1lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Devendra committed Jul 4, 2013
1 parent 6ef1e82 commit 1b5b802
Show file tree
Hide file tree
Showing 40 changed files with 640 additions and 86 deletions.
Binary file modified android/Pubnub-Android-3.5.2.jar
Binary file not shown.
Binary file modified android/examples/PubnubExample/libs/Pubnub-Android-3.5.2.jar
Binary file not shown.
Binary file modified android/examples/SubscribeAtBoot/libs/Pubnub-Android-3.5.2.jar
Binary file not shown.
Binary file modified blackberry/Pubnub-BlackBerry-3.5.2.jar
Binary file not shown.
16 changes: 10 additions & 6 deletions codenameone/PubnubClientSDK/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<project name="PubnubClientSDK" default="build" basedir=".">
<description>Builds, tests, and runs the project PubnubClientSDK.</description>
<import file="nbproject/build-impl.xml"/>
<loadfile property="VERSION" srcFile="../../VERSION"><filterchain><striplinebreaks/></filterchain></loadfile>
<property file="codenameone_settings.properties"/>

<target name="create-src">
Expand All @@ -13,6 +14,9 @@
<fileset dir="../srcJson"/>
<fileset dir="../../java/srcPubnubApi"/>
</copy>
<copy includeemptydirs="true" todir="src/com/codename1">
<fileset dir="../src/com/codename1"/>
</copy>
<copy includeemptydirs="true" todir="src/com/pubnub/api">
<fileset dir="../src/com/pubnub/api/"/>
</copy>
Expand All @@ -21,11 +25,11 @@
<delete dir="src"/>
</target>
<target name="copy-lib">
<copy file="dist/PubnubClientSDK.cn1lib" tofile="../pubnub.cn1lib"/>
<copy file="dist/PubnubClientSDK.cn1lib" tofile="../pubnub-codenameone-${VERSION}.cn1lib"/>
</target>


<target depends="default, delete-src, copy-lib, clean" name="build">
<target depends="create-src, default, delete-src, copy-lib, clean" name="build">
</target>

<target depends="init,compile,jar" name="compile-test">
Expand Down Expand Up @@ -68,7 +72,7 @@
<target name="Stubs">
<delete dir="build/stubs"/>
<javadoc sourcepath="src"
classpath="lib/CodenameOne.jar:lib/CLDC11.jar"
classpath="lib/CodenameOne.jar:lib/CLDC11.jar:lib/bccn1/main.zip"
docletpath="Stubber.jar"
doclet="com.codename1.build.client.StubGenerator">
<fileset dir="${src.dir}" excludes="*.java,${excludes}" includes="${includes}">
Expand All @@ -77,16 +81,16 @@
</javadoc>
</target>

<target name="jar" depends="compile,Stubs">
<target name="jar" depends="compile, Stubs">
<mkdir dir="build/lib" />
<zip basedir="${build.classes.dir}" compress="false" destfile="build/lib/main.zip" />
<zip basedir="build/stubs" compress="false" destfile="build/lib/stubs.zip" />
<copy file="manifest.properties" todir="build/lib" />
<antcall target="buildNativeIOS" />
<!--<antcall target="buildNativeIOS" />
<antcall target="buildNativeRIM" />
<antcall target="buildNativeAND" />
<antcall target="buildNativeWIN" />
<antcall target="buildNativeME" />
<antcall target="buildNativeME" /> -->
<mkdir dir="dist" />
<zip basedir="build/lib" compress="true" destfile="dist/${application.title}.cn1lib" />
</target>
Expand Down
Binary file added codenameone/pubnub-codenameone-3.5.2.cn1lib
Binary file not shown.
Binary file modified codenameone/pubnub.cn1lib
Binary file not shown.
57 changes: 57 additions & 0 deletions codenameone/src/com/codename1/io/PubnubCn1Connection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.codename1.io;

import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Hashtable;

import com.codename1.impl.CodenameOneImplementation;
import com.pubnub.api.HttpUtil;

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://"))) {
url = Util.relativeToAbsolute(url, uri);
} else {
url = uri;
}
}
}
contentLength = impl.getContentLength(connection);
input = impl.openInputStream(connection);
data = Util.readInputStream(input);
input.close();
input = null;
return new PubnubCn1Response(rc, new String(data, "UTF-8"));
}
public void disconnect() {

}

}

17 changes: 17 additions & 0 deletions codenameone/src/com/codename1/io/PubnubCn1Response.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.codename1.io;

public class PubnubCn1Response {
private String response;
private int responseStatusCode;
public String getResponse() {
return response;
}
public int getResponseStatusCode() {
return responseStatusCode;
}
public PubnubCn1Response(int responseStatusCode, String response) {
this.response = response;
this.responseStatusCode = responseStatusCode;
}
}

38 changes: 13 additions & 25 deletions codenameone/src/com/pubnub/api/HttpClientCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@
import java.util.Hashtable;

import com.codename1.impl.CodenameOneImplementation;
import com.codename1.io.Util;
import com.codename1.io.*;

class HttpClientCore extends HttpClient {


PubnubCn1Connection connection;
private int requestTimeout = 310000;
private int connectionTimeout = 5000;
//HttpURLConnection connection;


protected static Logger log = new Logger(Worker.class);

private void init() {
//HttpURLConnection.setFollowRedirects(true);
connection = new PubnubCn1Connection();
}

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

public boolean isRedirect(int rc) {
/* return (rc == HttpURLConnection.HTTP_MOVED_PERM
|| rc == HttpURLConnection.HTTP_MOVED_TEMP || rc == HttpURLConnection.HTTP_SEE_OTHER);
*/
return true;
}

public boolean checkResponse(int rc) {
return true; //return (rc == HttpURLConnection.HTTP_OK || isRedirect(rc));
}

public boolean checkResponseSuccess(int rc) {
return true; //return (rc == HttpURLConnection.HTTP_OK);
}
public HttpResponse fetch(String url) throws PubnubException { //, SocketTimeoutException {
public HttpResponse fetch(String url) throws PubnubException, IOException {
return fetch(url, null);
}

public synchronized HttpResponse fetch(String url, Hashtable headers)
throws PubnubException { // log.verbose("URL = " + url + " : RESPONSE = " + page);
return null;//new HttpResponse(rc, page);
}

public boolean isOk(int rc) {
//return (rc == HttpURLConnection.HTTP_OK);
return true;
throws PubnubException, IOException {
System.out.println(url);
PubnubCn1Response pcr = connection.fetch(url, requestTimeout, headers);
return new HttpResponse(pcr.getResponseStatusCode(), pcr.getResponse());//new HttpResponse(rc, page);
}

public void shutdown() {
//if (connection != null) connection.disconnect();
if (connection != null) connection.disconnect();
}
}

32 changes: 16 additions & 16 deletions codenameone/src/com/pubnub/api/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
//import org.slf4j.LoggerFactory;

class Cn1Logger {

public Cn1Logger(Class c) {

}
public void debug(String s) {

}
public void trace(String s) {

}
public void error(String s) {

}
public void info(String s) {

}
public Cn1Logger(Class c) {
}
public void debug(String s) {
}
public void trace(String s) {
}
public void error(String s) {
}
public void info(String s) {
}
}


Expand Down
5 changes: 2 additions & 3 deletions codenameone/src/com/pubnub/api/PubnubUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pubnub.api;


import com.codename1.io.Util;
/**
* PubnubUtil class provides utility methods like urlEncode etc
* @author Pubnub
Expand All @@ -16,7 +16,6 @@ public class PubnubUtil extends PubnubUtilCore {
* @return , encoded string
*/
public static String urlEncode(String sUrl) {
// TODO
return null;
return Util.encodeUrl(sUrl);
}
}
2 changes: 1 addition & 1 deletion codenameone/src/com/pubnub/api/SubscribeWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void process(HttpRequest hreq) {
log.debug(hreq.getUrl());
hresp = httpclient.fetch(hreq.getUrl(), hreq.getHeaders());
if (hresp != null
&& httpclient.checkResponseSuccess(hresp
&& HttpUtil.checkResponseSuccess(hresp
.getStatusCode())) {
currentRetryAttempt = 1;
break;
Expand Down
Binary file modified j2me/Pubnub-MicroEdition-3.5.2.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion j2me/src1/com/pubnub/api/SubscribeWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void process(HttpRequest hreq) {
log.debug(hreq.getUrl());
hresp = httpclient.fetch(hreq.getUrl(), hreq.getHeaders());
if (hresp != null
&& httpclient.checkResponseSuccess(hresp
&& HttpUtil.checkResponseSuccess(hresp
.getStatusCode())) {
currentRetryAttempt = 1;
break;
Expand Down
Binary file modified java/Pubnub-StandardEdition-3.5.2.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion java/doc/allclasses-frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc (build 1.6.0_37) on Thu Jul 04 14:38:08 IST 2013 -->
<!-- Generated by javadoc (build 1.6.0_37) on Thu Jul 04 17:15:29 IST 2013 -->
<TITLE>
All Classes
</TITLE>
Expand All @@ -23,6 +23,8 @@
<TR>
<TD NOWRAP><FONT CLASS="FrameItemFont"><A HREF="com/pubnub/api/Callback.html" title="class in com.pubnub.api" target="classFrame">Callback</A>
<BR>
<A HREF="com/pubnub/api/HttpUtil.html" title="class in com.pubnub.api" target="classFrame">HttpUtil</A>
<BR>
<A HREF="com/pubnub/api/Pubnub.html" title="class in com.pubnub.api" target="classFrame">Pubnub</A>
<BR>
<A HREF="com/pubnub/api/PubnubError.html" title="class in com.pubnub.api" target="classFrame">PubnubError</A>
Expand Down
4 changes: 3 additions & 1 deletion java/doc/allclasses-noframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc (build 1.6.0_37) on Thu Jul 04 14:38:08 IST 2013 -->
<!-- Generated by javadoc (build 1.6.0_37) on Thu Jul 04 17:15:29 IST 2013 -->
<TITLE>
All Classes
</TITLE>
Expand All @@ -23,6 +23,8 @@
<TR>
<TD NOWRAP><FONT CLASS="FrameItemFont"><A HREF="com/pubnub/api/Callback.html" title="class in com.pubnub.api">Callback</A>
<BR>
<A HREF="com/pubnub/api/HttpUtil.html" title="class in com.pubnub.api">HttpUtil</A>
<BR>
<A HREF="com/pubnub/api/Pubnub.html" title="class in com.pubnub.api">Pubnub</A>
<BR>
<A HREF="com/pubnub/api/PubnubError.html" title="class in com.pubnub.api">PubnubError</A>
Expand Down
6 changes: 3 additions & 3 deletions java/doc/com/pubnub/api/Callback.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc (build 1.6.0_37) on Thu Jul 04 14:38:06 IST 2013 -->
<!-- Generated by javadoc (build 1.6.0_37) on Thu Jul 04 17:15:28 IST 2013 -->
<TITLE>
Callback
</TITLE>
Expand Down Expand Up @@ -54,7 +54,7 @@
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;PREV CLASS&nbsp;
&nbsp;<A HREF="../../../com/pubnub/api/Pubnub.html" title="class in com.pubnub.api"><B>NEXT CLASS</B></A></FONT></TD>
&nbsp;<A HREF="../../../com/pubnub/api/HttpUtil.html" title="class in com.pubnub.api"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../index.html?com/pubnub/api/Callback.html" target="_top"><B>FRAMES</B></A> &nbsp;
&nbsp;<A HREF="Callback.html" target="_top"><B>NO FRAMES</B></A> &nbsp;
Expand Down Expand Up @@ -348,7 +348,7 @@ <H2>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;PREV CLASS&nbsp;
&nbsp;<A HREF="../../../com/pubnub/api/Pubnub.html" title="class in com.pubnub.api"><B>NEXT CLASS</B></A></FONT></TD>
&nbsp;<A HREF="../../../com/pubnub/api/HttpUtil.html" title="class in com.pubnub.api"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../index.html?com/pubnub/api/Callback.html" target="_top"><B>FRAMES</B></A> &nbsp;
&nbsp;<A HREF="Callback.html" target="_top"><B>NO FRAMES</B></A> &nbsp;
Expand Down
Loading

0 comments on commit 1b5b802

Please sign in to comment.