Home > Uncategorized > Extending the Grizzly HTTP Runtime part VI: Writting A GrizzlyAdapter customized to run on an iPhone/IPod Touch

Extending the Grizzly HTTP Runtime part VI: Writting A GrizzlyAdapter customized to run on an iPhone/IPod Touch

To support the Mozilla foundation (and others) against Apple, I’ve decided to follow Bruno Ghisi’s how to and install Java on my iPhone. I wasn’t able to resist to try Grizzly and set the bar high by trying to run my Twitter like application, which is powered by the Grizzly Comet Framework. Wow it works…but wait, let’s write a GrizzlyAdapter that’s snoop some iPhone info :-).

More info about what is a GrizzlyAdapter ->(I,II,II,IV, V)

First, download Grizzly from here (pick the Grizzly Comet or WebServer bundle), and then the sample from here. Next ssh those 2 files to your iPhone. Et voila!:


Now lauch your favorite browser and boom:


OK, that’s too easy. Now let’s use SQLLite to display my current set of contacts by writing our own GrizzlyAdapter:

        GrizzlyWebServer ws = new GrizzlyWebServer(path);
        ServletAdapter adapter = new ServletAdapter(new HttpServlet() {
            private ArrayList contacts;

            protected void doGet( HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
                contacts = new ArrayList();

                    SQLite.Database ab = new SQLite.Database();
                    ab.open("/private/var/mobile/Library/AddressBook/AddressBook.sqlitedb", 0666); try {
                        SQLite.Stmt st = ab.prepare("select first, last from ABPerson where first is not null order by first");
                        try {
                            while (st.step())
                                contacts.add(st.column_string(0) + " "+ st.column_string(1));
                        } finally { st.close(); }
                    } finally { ab.close(); }

                    for (int i=0; i < contacts.size(); i++){
                        resp.getWriter().write("Contact: " + contacts.get(i) + "\n");
                } catch (Throwable t){

        ws.addGrizzlyAdapter(adapter new String[]{"/"});
        System.out.println("Grizzly iPhoneServer listening on port 8080");

Naaa you whispered I will show you my contacts! Naaa just cut & paste the above and compile…and see by yourself!! Need help: ping us on users@grizzly.dev.java.net, or Tweet us on Twitter.

_uacct = “UA-3111670-1”;


Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: