Home > javafx > JavaFX – WebServices

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 {

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

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.




Categories: javafx Tags: ,
  1. April 14, 2009 at 7:46 AM

    Very cool sample !

  2. banita
    June 15, 2009 at 2:39 AM

    i have created a javafx widget which uses rss feed and show the news,
    now i want to use it in our website or i want to be embedded with my website.. can you please tell me the procedure in detail how to run widget from my website, please rply

  3. June 15, 2009 at 3:13 AM

    @banita You can refer to this tutorial
    http://javafx.com/docs/tutorials/deployment/ I have also uploaded the html and jnlp files for reference

  4. Mohammed Sanaulla
    June 24, 2009 at 1:27 AM

    Cool sample!!!!!

  5. Maximilian Stempfhuber
    July 6, 2009 at 4:13 PM

    Could you please check the availability of the Image Viewer sample? I’m getting an error message and an exception:
    java.io.IOException: Cannot find cached resource for URL: http://blogs.sun.com/rakeshmenonp/resource/WebServices/JavaFX_Flickr_Image_Viewer.jar
    also starting in standalone mode doesn’t work here. But still you can download the and locally save the jar. Don’t know what happens here.

  6. Maximilian Stempfhuber
    July 6, 2009 at 4:15 PM

    Follow up:
    Java Web Start shows an encapsulated exception:
    java.io.IOException: Not in GZIP format
    at java.util.zip.GZIPInputStream.readHeader(Unknown Source)
    at java.util.zip.GZIPInputStream.<init>(Unknown Source)
    at java.util.zip.GZIPInputStream.<init>(Unknown Source)
    at com.sun.deploy.net.HttpDownloadHelper.download(Unknown Source)
    at com.sun.deploy.cache.Cache.downloadResourceToTempFile(Unknown Source)

  7. July 6, 2009 at 9:38 PM

    @Maximilian Stempfhuber I’m not sure about exact reason, it may be due to network outage. Anyway I have updated the sample to use JavaFX 1.2 runtime.

  8. leonardo gomez
    October 17, 2009 at 8:37 PM

    Por favor me mandan una erl de sun en español gracias soy novato en lo ke respecta a todo esto de la programacion y me gustaria leer sus blogs y participar y capacitarme. Gracias

  9. Rakesh Menon
    October 23, 2009 at 3:57 AM

    @leonardo gomez Sorry, I’m not aware of any site. For now http://translate.google.com/# may be best bet for technical articles.

  10. Dmitry Anosov
    November 2, 2009 at 2:39 AM

    I’m trying to run this application in eclipse, but i get the following error:
    C:\MyWebProjects\WebServices\src\carousel\Carousel.fx:152: cannot find symbol
    symbol : function enqueue()
    location: class javafx.io.http.HttpRequest
    What could that be?

  11. Rakesh Menon
    November 2, 2009 at 4:24 AM

    @Dmitry Anosov Thanks for pointing out. I have not updated the sample source to JavaFX 1.2. The name of method is changed from enqueue() to start(). I’ll update the source. You may also refer to sample in doc – http://java.sun.com/javafx/1.2/docs/api/javafx.io.http/javafx.io.http.HttpRequest.html

  12. Rakesh Menon
    November 2, 2009 at 4:40 AM

    @Dmitry Anosov I have putback the latest source to http://code.google.com/p/javafxdemos/source/browse/#hg/Carousel/src/carousel

  13. Dmitry Anosov
    November 2, 2009 at 9:20 AM

    Тhanks for your reply, Rakesh. I just couldn’t think of any reason for that error.

  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: