" /> Davanum Srinivas' weblog: December 2006 Archives

« November 2006 | Main | January 2007 »

December 20, 2006

Calling Google AJAX Search API from Java

Without much ado, here's the code:

import java.io.*;
import java.net.*;

public class GoogleAJAXSearchAPI {
    private static String endpointURL = "http://www.google.com/uds/GwebSearch?"+
          "callback=GwebSearch.Raw" +
          "Completion&context=0&lstkp=0&rsz=small&hl=en&" +
          "sig=8656f49c146c5220e273d16b4b6978b2&q=Axis2&key=xxxxxxxxxxxxxxxxxx&v=1.0";

    public static void main(String[] args) throws Exception {
        URLConnection uc = new URL(endpointURL).openConnection();
        HttpURLConnection connection = (HttpURLConnection) uc;
        connection.setDoOutput(true);
        connection.setRequestMethod("GET");
        connection.connect();
        
        String line;
        InputStream inputStream = null;
        try {
            inputStream = connection.getInputStream();
        } catch (IOException e) {
            inputStream = connection.getErrorStream();
        }
        BufferedReader rd = new BufferedReader(new InputStreamReader(inputStream));
        while ((line = rd.readLine()) != null) {
            System.out.println(line);
        }
    }
}

Where xxxxxxxxxxxxxxxxxx is your Google AJAX Search API key. No clue what the other parameters means in the URL. I used Firefox / Live HTTP Headers / TCPMON's proxy support to come up with this snippet.

December 13, 2006

Why bundling JAX-WS in Java6 was a bad idea!

First of all, congrats to Vivek, Arun and team on the release!. See what you have to do when you ship it? First thing is to tell people how to override the release with the latest code using endorsed mechanism. Second thing is how to deal with people who ask, I can't really do anything much other than a getQuote application with the actual bits in Java6, what do i need when i have to do something non-trivial like WS-Security (see the first comment on the link above!).

Welcome to the real world!