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.
- Following
screencast #ws7, create a plain (without Security or Reliability
enabled) Metro endpoint using NetBeans 6 and GlassFish v2. - In NetBeans 6 IDE, install the JavaFX plugin as described
here. - Create Web service client library - Creating a Web service client in
JavaFX Script Application is causing a NullPointerException (issue
#126352). The workaround I used is to create a separate library with
client-side artifacts and then include it as dependency in the JavaFX client
project.- Create a new project of type "
Java Class Library" as
shown below:

and click on "Finish". - Enter the project name as "
MetroClientLibrary" as shown
below:

and click on "Finish". - Right-click on the newly created project, select "
New",
"Web Service Client...". - Click on "
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:

and click on "Finish". - Once the Web service client-side artifacts are generated (indicated
by expandable Web Service References tree node), right-click on
the project and select "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.
- Create a new project of type "
- Create JavaFX project
- Create a new JavaFX project by right-clicking in the Project
explorer, selecting "New Project" and entering the values
as shown below:

- Click on "
Next >" and enter the values as shown below:

and click on "Finish". - Right-click on the newly created project, "
Properties",
"Libraries", "Add JAR/Folder" and select the
JAR file created in "MetroClientLibrary" project as shown
below:

and click on "OK".
Notice, Java SE 6 U4 is used to compile and run this project. If you are
using an earlier version of Java SE 6, then you need to override JAX-WS
2.1 and JAXB 2.1 jars using endorsed mechanism as explained
here. The classes in these jars are
already bundled in Java SE 6 U4. - In
metroclient.Main.fxfile, replace "
" with the following code:// place
your code here
import java.lang.*;<br>
import javafx.ui.*;<br>
<br>
import client.NewWebServiceService;<br>
import client.NewWebService;<br>
<br>
class InputModel {<br>
attribute name: String?;<br>
}<br>
var inputModel = InputModel { };<br>
var nameField = TextField { };<br>
nameField.action = operation() {<br>
inputModel.name = nameField.value;<br>
};<br>
<br>
class ButtonClickModel {<br>
attribute result: String;<br>
}<br>
var model = new ButtonClickModel();<br>
<br>
Frame {<br>
title: "JavaFX Client -> Metro endpoint"<br>
width: 350<br>
height: 200<br>
content: GridPanel {<br>
rows: 3<br>
vgap: 5<br>
cells:<br>
[SimpleLabel {<br>
text: "Name :
"<br>
},<br>
nameField,<br>
SimpleLabel {<br>
text: "Result
from endpoint : "<br>
},<br>
Label {<br>
text: bind "{model.result}"<br>
},<br>
Button {<br>
text: "Invoke
Web Service!"<br>
action:
operation() {<br>
do {<br>
try {<br>
var service: NewWebServiceService = new NewWebServiceService();<br>
var port: NewWebService = service.getNewWebServicePort();<br>
var name: String = "{nameField.value}";<br>
var result: String = port.sayHello(name);<br>
System.out.println("response: {result}");<br>
model.result = result;<br>
} catch (e:Exception) {<br>
System.out.println("exception: {e}");<br>
}<br>
}<br>
}<br>
}<br>
]<br>
}<br>
visible: true<br>
};
- Create a new JavaFX project by right-clicking in the Project
- Invoke the JavaFX client project
- Right-click on the recently create project ("
MetroClient")
and select "Run Project". The following window is
displayed:

- Enter "
Duke" in the text box and click on "
" button to see the result as shown below:Invoke
Web Service!

- Right-click on the recently create project ("
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
- Login or register to post comments
- Printer-friendly version
- arungupta's blog
- 850 reads





