Sunday, September 30, 2012

Http stuff

the wikipedia article points out that the RFC952 forbids trailing hypens in domain names. Androids browser/webview enforce this, most other browsers (and heck DNS servers do not seem to bother)

The source code for the Apache HttpCore lib is not in the Androd SDK source package, so you need to get it direct from the AOSP git repo.

Tuesday, August 28, 2012

Java Network Timeout handling

So this blog post (via stackoverflow as usual) points out that you need to manually handle timing out reads when using URLConnection and hence also HttpURLConnection.

The post also helpfully provides example code for such a manual timer:

try {
    URLConnection con = urlObj.openConnection();
    con.setConnectTimeout(5000);
    con.setReadTimeout(5000);
    new Thread(new InterruptThread(Thread.currentThread(), con)).start();
    retVal = new Source(con);
} catch (IOException e) {
    System.err.println("aborted parsing due to I/O: " + e.getMessage());
    throw new IndexingException("aborted parsing due to timeout - " + aUrl);
}

public class InterruptThread implements Runnable {
    Thread parent;
    URLConnection con;
    public InterruptThread(Thread parent, URLConnection con) {
        this.parent = parent;
        this.con = con;
    }

    public void run() {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {

        }
        System.out.println("Timer thread forcing parent to quit connection");
        ((HttpURLConnection)con).disconnect();
        System.out.println("Timer thread closed connection held by parent, exiting");
    }
}

Monday, August 13, 2012

latest android sdk bug plus httpd


emulator in r20 segfaulting on a headless box without opengl.

the simple node based http static server to use:
https://github.com/nodeapps/http-server

to not have to use sudo anymore (on my laptop) to install node modules via npm globally (-g flag):

sudo chown -R username:group /usr/local/bin/
sudo chown -R username:group /usr/local/lib/



Monday, July 9, 2012

Android Http NPEs

Lovely...
Search google for a NPE from Androids Http package:
libcore.net.http.HttpConnection$Address.hashCode NPE

leads to bug report, which leads to another which finally points me to looking at my url closely and realising I typoed the protocol scheme. As the comment I left suggests, life would have been much clearer with a slightly more specific exception the a null pointer. Sigh.



Sunday, July 1, 2012

Android Emulator keyboard

Well this was a little time waster today:

Turns out that Android SDK r20  now defaults the hw.keyboard property to no.
This means that you will all of a sudden find that after upgrading to r20, keyboard entry (both physical and onscreen) will stop working in both existing and new AVDs.

So you need to set the property explicitly in each AVD config via the GUI or in:

.android/avd/MY_AVD_NAME.avd/config.ini

Thursday, June 21, 2012

More Bash magic

set to automatically cd into a dir by typing its name:
shopt -s autocd

go back to previous pwd ($OLDPWD):
cd -

rename a path with a new suffix:
mv /var/www/test{,1}

Again all courtesy of my co-worker Ben.M

Tuesday, June 19, 2012

Android SDK Ant bugs

BEWARE: if you are using r15 of the Android SDK and building with a custom Ant post-build target then this bug might bite you! r17 through to r19 is confirmed as working ok.