Tuesday May 25, 2010

Thank You!

I was inspired by Jim Weaver and Stephen Chin to start blogging. Jonathan Giles provided the launch pad via his "Java desktop links of the week". Philippe Lhoste (PhiLho in Forums, you cannot miss him!) inspired to write more. In less than one year this blog was made popular by all of you and was added to "Oracle's Java Bloggers" list. Feels great to see the name along with some of the greatest people in industry

None of these would have been possible without your encouragement and support. I would like to say to all of you. It was really nice interacting with you. Google-Analytics shows huge number of unique visitors, I hope this was of help to at-least few of them

Unfortunately today is my last day at Sun-Oracle. I had to take this difficult decision to end a decade long association with Sun. I'll continue to blog at WordPress

http://rakeshmenonp.wordpress.com/

Hope to have your continued encouragement and support


Thursday Jul 02, 2009

JavaFX + Zembly


Zembly application development environment makes it easy to develop, customize and deploy your application. It provides APIs from various providers.

Here we will try to use Zembly services (outside of Zembly) from JavaFX. Zembly provides client libraries for both Java and JavaFX.

<script src="http://dl.javafx.com/1.2/dtfx.js"></script> <script src="/rakeshmenonp/resource/ZemblyIP/ZemblyIP.js"></script>

For Applet mode, click on above image

For standalone mode

Above sample is modified version of InterestingPhotos which now uses Zembly APis to search flickr's photo search based on tags. It uses flickr api - photos.search as shown below.

String result = Zembly.getInstance().callService(
    String.class,                 // Return Type
    "web.flickr.photos.search",   // Service Name
    new String[][] {              // Arguments
        {"machine_tag_mode""any"},
        {"tags""javafx" },
        {"per_page""65"},
        {"page""1"},
        {"format""json"}
    }
);

Class com.zembly.gateway.client.Zembly is available in Zembly Client Library implementation. Download zcl4j.zip here

Now we can easily write a wrapper for zcl in JavaFX using Asynchronous APIs. This will also demonstrate how to use these APIs to invoke Java apis in background thread from JavaFX.

Provide an implementation for javafx.async.RunnableFuture which will invoke the Zembly client APIs - ZemblyRunnableFuture. Next design an interface which bridge the Java and JavaFX - CallbackHandler.

Now we can implement the ZemblyRequest API which extends the JavaFX JavaTaskBase. This will provide an implementation similar to HttpRequest API.

ZemblyRequest can be used in application as shown below

var request = ZemblyRequest {

    // Zembly Service Name
    serviceName: "web.flickr.photos.search"

    // Arguments to be passed to service
    arguments: [
        Pair name: "machine_tag_mode", value: "any" },
        Pair name: "tags", value: "{encodedTags}" },
        Pair name: "per_page", value: "65" },
        Pair name: "page", value: "1" },
        Pair name: "format", value: "json" }     
    ]

    onStart: function() {
        println("ZemblyRequest - start");
    }

    onInput: function(is) {
        // Use PullParser to parse the stream
        is.close();
    }

    onDone: function() {
        println("ZemblyRequest - done");
    }

};
request.start();

Zembly key and secret must be generated and specified in zcl.properties file which must be kept in default package inside jar file. For more information on this, please refer to article - How to Call Data Service from Outside Zembly

I followed articles - Creating a Widget in 5 Minutes and Working with JavaFX so as to deploy above sample as Application

Try it out and let me know feedback

Source:

<script type="text/javascript">var dzone_url = "http://blogs.sun.com/rakeshmenonp/entry/javafx_zembly";</script> <script type="text/javascript">var dzone_style = '2';</script> <script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script>

Wednesday Jun 10, 2009

JavaFX + Yahoo Placemaker + Maps


I have my travel itinerary or a document with list of cities, such as Seven Wonders of the World. I would like to retrieve the list of cities and the location information associated with it. How to do this??

Yahoo! released new Yahoo! Placemaker APIs. These APIs search for name of places in plain text document and returns the latitude and longitude associated with the place. You can either provide a text or a URL as input to the API. The output can be obtained in XML or RSS format.

Combine above information with Yahoo! Maps will return the maps associated with all places mentioned in specified document! Itn't that cool?! :)

May be I must write more applications and publish at Java-Store!

<script src="http://dl.javafx.com/1.2/dtfx.js"></script><script src="/rakeshmenonp/resource/PlaceList/PlaceList.js"></script>

For Applet mode, click on above image

For standalone mode

In above application we provide a URL which the Placemaker API will parse and returns the list of places. This information is given to Map Image API to retrieve the image. Any valid http URL can be provided as input. There is currently a 50 kbs limit for documents processed by Placemaker. Documents above this length are rejected and returns status 413. Please enter a new URL in textfield and press enter to load new places.

Source:

<script type="text/javascript">var dzone_url = "http://blogs.sun.com/rakeshmenonp/entry/javafx_yahoo_placemaker_yahoo_maps";</script> <script type="text/javascript">var dzone_style = '2';</script> <script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script>
<script type="text/javascript"> digg_skin = 'compact'; digg_window = 'new'; </script> <script language="javascript" src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>
<script src="http://slashdot.org/slashdot-it.js" type="text/javascript"></script>

Tuesday Apr 14, 2009

JavaFX - WebServices


JavaFX provides API to perform asynchronous HTTP request and also utilize RESTful webservices. It also provides parsers for XML and JSON data formats.

Related Posts:

HttpRequest class provides way to specify a location (HTTP URL) and transfer data via InputStream and OutputStream.

def httpRequest = HttpRequest {
    
    location: "http://news.google.com/?output=rss"
    method: HttpRequest.GET
    
    onInput: function(in: java.io.InputStream) {
        try {
            // Read the content from this InputStream
            // Pass the InputStream to parser 
        finally {
            in.close();
        }
    }
}
httpRequest.start();

The InputStream obtained from HttpRequest can be parsed using PullParser API. It can parse both XML and JSON data type.

def parser = PullParser {
    
    documentType: PullParser.XML
    input: <InputStream obtained from HttpRequest>
    
    onEvent: function(event: Event) {
        // Handle events triggered for each node
        // and retrieve the data
    }
}
parser.parse();

Now we can utilize these APIs to enhance the existing Image Viewer sample so as to retrieve the photos dynamically from Flickr. Source code for PhotoPullParser.fx and Photo.fx are copied directly from InterestingPhotos sample.

For Applet mode, click on above image

For standalone mode

There are many samples at JavaFX Samples website which uses HttpRequest and PullParser APIs. You can refer to those source code for more information.

Deployment:

About


The views expressed on this blog are my own and do not necessarily reflect that of my organization

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today