Asset Replicator - GWT (Google Web Toolkit) + RESTful web service

The Asset Replicator front-end is being re-built using GWT (Google Web Toolkit) and RESTful web service. I tend to agree to GWT's claim that:

Writing web apps today is a tedious and error-prone process. Developers can spend 90% of their time working around browser quirks. In addition, building, reusing, and maintaining large JavaScript code bases and AJAX components can be difficult and fragile. Google Web Toolkit (GWT) eases this burden by allowing developers to quickly build and maintain complex yet highly performant JavaScript front-end applications in the Java programming language.

The front-end (see below) sends the requests to the service provider using RequestBuilder:

String restUrl = "http://www.happywednesday.org:8080/webapps/resources/AssetReplicatorREST?" +
                          "targetAsset=" + targetAsset + "&" +
                          "baseAssets=" + baseAssets + "&" +
                          "startDate=" + startDate + "&" +
                          "endDate=" + endDate + "&" +
                          "lowerbound=" + lowerbound + "&" +
                          "upperbound=" + upperbound + "&" +
                          "periodicity=" + periodicity + "&" +
                          "global=" + global;

RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, restUrl);
Request request = builder.sendRequest(null, new RequestCallback(...));

The result is then passed to the following function, which generates the allocation chart using JFreeChart:

public String generateChart(double[] values, String[] labels, String type) {
        /*
         * Hold our stored chart name, it will be returned to the GWT caller.
         */
        String chartName = "";

        JFreeChart chart = null;
        if(type.equals(ChartGenerator.PORTFOLIO)){
            chart = ChartUtils.createPortfolioChart(values, labels);
        } else {
            chart = ChartUtils.createPortfolioChart(values, labels);
        }
        
        /*
         * Save the chart as an '500px x 250px' jpeg image.
         */
        try {
            HttpSession session = getThreadLocalRequest().getSession();
            chartName = ServletUtilities.saveChartAsJPEG(chart, 500, 250, null, session);
        } catch(Exception e) {
            e.printStackTrace();
        }

        /*
         * Finally, return the chart name to the caller.
         */
        return chartName;
}

JFreeChart actually saves the image into a temporary folder. This image is then picked up and displayed by a servlet, served up by org.jfree.chart.servlet.DisplayChart

public void onSuccess(Object result) {
       String chartName = (String) result;
       String imageUrl = "./displayChart?filename=" + chartName;
       imgChart.setUrl(imageUrl);
       add(imgChart);
}

What did I say then?

Banks: Market Cap (3 years 2 weeks ago):

Theme provided by Danang Probo Sayekti.