Thursday January 31, 2008
TOTD #23: JavaFX Client invoking a Metro endpoint
This TOTD is inspired by Learning JavaFX Script - Part 3. The original article explains how to invoke a Web service from a JavaFX client using NetBeans 5.5.1 and GlassFish v1. Newer version of both NetBeans and GlassFish are available since the article was written. This TOTD (tip of the day) explains how to invoke a Metro endpoint deployed on GlassFish v2 from a JavaFX client - all using NetBeans 6.
Java Class Library" as
shown below:
Finish".MetroClientLibrary" as shown
below:
Finish".New",
"Web Service Client...".Browse..." button next to "Project"
radio button and select the deployed Web service from Metro endpoint
project. If the Web service is deployed on a different machine then you
may specify the WSDL URL. Specify the package name "client"
as shown below:
Finish".Build". This generates a JAR file
that will be utilized later. The location of this jar file is shown in
the Output console. In our case, it is C:\workarea\samples\javafx\MetroClientLibrary\dist\MetroClientLibrary.jar.New Project" and entering the values
as shown below:
Next >" and enter the values as shown below:
Finish".Properties",
"Libraries", "Add JAR/Folder" and select the
JAR file created in "MetroClientLibrary" project as shown
below:
OK".metroclient.Main.fx file, replace "// place
your code here" with the following code:import java.lang.*;
import javafx.ui.*;
import client.NewWebServiceService;
import client.NewWebService;
class InputModel {
attribute name: String?;
}
var inputModel = InputModel { };
var nameField = TextField { };
nameField.action = operation() {
inputModel.name = nameField.value;
};
class ButtonClickModel {
attribute result: String;
}
var model = new ButtonClickModel();
Frame {
title: "JavaFX Client -> Metro endpoint"
width: 350
height: 200
content: GridPanel {
rows: 3
vgap: 5
cells:
[SimpleLabel {
text: "Name :
"
},
nameField,
SimpleLabel {
text: "Result
from endpoint : "
},
Label {
text: bind "{model.result}"
},
Button {
text: "Invoke
Web Service!"
action:
operation() {
do {
try {
var service: NewWebServiceService = new NewWebServiceService();
var port: NewWebService = service.getNewWebServicePort();
var name: String = "{nameField.value}";
var result: String = port.sayHello(name);
System.out.println("response: {result}");
model.result = result;
} catch (e:Exception) {
System.out.println("exception: {e}");
}
}
}
}
]
}
visible: true
};MetroClient")
and select "Run Project". The following window is
displayed:
Duke" in the text box and click on "Invoke
Web Service!" button to see the result as shown below:
After following these steps, you have created a JavaFX client that can invoke a Metro endpoint project deployed on GlassFish - all using NetBeans IDE.
Now Metro provides secure, reliable, transactional and .NET 3.0 interoperable Web service. Have you tried/used any of those features in Metro ?
Please leave suggestions on other TOTD that you'd like to see. A complete archive is available here.
Technorati: totdd javafx metro glassfish netbeans webservices
Posted by Arun Gupta in webservices | Comments[13]
|
|
|
|
|
Today's Page Hits: 598
Total # blog entries: 1002
Ugh! That's looking ugly!!! I think my first Swing application looked way better than this!
I thought JavaFX should be comparable to Flash?! Why do you do such ugly examples then? Isn't it easy to do nice looking examples with it? If not, what is it for??
Posted by Christian on January 31, 2008 at 09:50 AM PST #
You certainly can do nicer and fancier UIs with JavaFX but this blog highlights how the configuration would look like. Please feel free to provide an updated UI :)
Posted by Arun Gupta on January 31, 2008 at 04:48 PM PST #
Why You don't do screencasts anymore? I loved them.
Posted by Lucek on February 02, 2008 at 02:14 AM PST #
Arun, i love you . Keep doing the good job
Posted by emeka on February 05, 2008 at 06:34 AM PST #
Hi Sir,
This is uday shankar.I had met with you at sun tech days conference at hyderabad and i felt very happy to attend very extraordinary minds like you.Im very much interested in learning Java Fx, can u help me out in doing so.
Thanks & Regards
Uday Chow
Posted by uday shankar on March 23, 2008 at 02:46 AM PDT #
Uday, you can find all JavaFX related material at: http://openjfx.org.
-Arun
Posted by Arun Gupta on March 23, 2008 at 11:23 PM PDT #
Hi Arun:
I followed the steps you outlined but I get following error. I have posted this on news group but no answer. Can you help?
java.lang.NoClassDefFoundError: [Ljavax/xml/ws/WebServiceFeature;
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
at java.lang.Class.getDeclaredMethods(Class.java:1791)
Posted by Tushar on April 06, 2008 at 06:16 AM PDT #
Tushar,
What version of JDK are you using ? JDK 6u4 has JAX-WS classes built-in otherwise you'll have to explicitly include the classes in your classpath.
-Arun
Posted by Arun Gupta on April 15, 2008 at 10:12 AM PDT #
@Chrisitian
If you want slick, try looking at some of the demos over at OpenJFX:
https://openjfx.dev.java.net/downloads.html#demos
Posted by 76.201.79.40 on April 17, 2008 at 06:26 AM PDT #
Thanks that was a nice example. We have recently implemented all our web services using Metro on tomcat and Glassfish, so this looks like it might make a good graphical front end sometime in the future. Looking fowards to seeing more example along the way.
Posted by Andrew on May 09, 2008 at 02:08 AM PDT #
christian you said in your comment "Ugh! That's looking ugly!!! I think my first Swing application looked way better than this!
I thought JavaFX should be comparable to Flash?! Why do you do such ugly examples then? Isn't it easy to do nice looking examples with it? If not, what is it for??" why dont you put your wing application here! I tihnk It is not good for you. Because you dont have enough courage for it, so stop doing this.
Posted by Disney Pictures on March 08, 2009 at 02:46 PM PDT #
thanks for your article... very nice.
But I had try that JavaFX to call Web Service, is ok.
But when I run as applet, cannot call web service...
It's seems security issue...
I had see one article at IBM website, saying that we can use applet to call web at the same host, and then use web to call web service...
this make applet can call web service.
But, It's dirty. Is there any solution that JavaFX applet can call remote web service directly ?
Posted by Rocky Wang on April 07, 2009 at 09:03 PM PDT #
Rocky, please ask your question on JavaFX forums at: http://forums.sun.com/category.jspa?categoryID=132 for a better response on it.
Posted by Arun Gupta on April 17, 2009 at 04:06 PM PDT #