Tuesday August 25, 2009
TOTD #98: Create a Metro JAX-WS Web service using GlassFish Tools Bundle for Eclipse
Now that you've installed GlassFish Tools Bundle for Eclipse 1.1, lets use this bundle to create a simple Metro/JAX-WS compliant Web service and deploy on GlassFish. These steps will work with either Eclipse 3.4.2 or 3.5 with WTP Java EE support.


public String sayHello(String name) {
return "Hello " + name + "!!";
}










Posted by Arun Gupta in webservices | Comments[2]
|
|
|
|
|
Thursday December 04, 2008
JavaFX 1.0 launched - access services hosted on embedded GlassFish
Today Sun announces the availability of Java
FX 1.0.
JavaFX 1.0 is a rich client platform for creating and delivering Rich
Internet Applications across all screens (desktop, browser,
and mobile) of your life. It consists of the following key components:
![]() |
|
![]() |
This blog shows how to create a simple JavaFX application using NetBeans IDE. The application plays a movie, allows the viewer to cast a vote if they liked it, and see aggregate response from other viewers. The application is developed using NetBeans 6.5, JavaFX 1.0 plugin, and coded using JavaFX Script. The voting engine is deployed as a RESTful Web service using Jersey on GlassFish. |



| Stage { title: "GlassFish Media Player" width: 625 height: 360 resizable: false scene: myScene } |
| var myScene: Scene = Scene { content: MediaView { fitWidth: 625 fitHeight: 360 mediaPlayer: bind myPlayer onMouseEntered: function( e: MouseEvent ):Void { println("mouse entered"); if (voted == false) { insert Vote{} into myScene.content; } else { insert Result{} into myScene.content; } } onMouseExited: function( e: MouseEvent ):Void { delete myScene.content[1] } } } |
| var myPlayer: MediaPlayer = MediaPlayer{ autoPlay: true media: bind myMedia }; |
| var myMedia: Media = Media { source: "http://sun.edgeboss.net/download/sun/media/1460825906/1460825906_2957290001_DayEarth-Bluray.flv" }; |
| class Vote extends CustomNode { override function create():Node { return Group { content: [ Rectangle { fill: Color.GREEN x: 185 y: 145 width: 243 height: 38 arcWidth: 20 arcHeight: 20 }, Text { x: 195 y: 170 fill: Color.WHITE font: Font { size: 18 } content: "I love it" }, Rectangle{ x: 191 y: 148 smooth: false width: 73 height: 32 fill: Color.TRANSPARENT onMouseClicked: function( e: MouseEvent ):Void { println("clicked I love it"); voted = true; wsClient.voteLoveIt(); delete myScene.content[1] } }, Text{ x: 305 y: 170 fill: Color.WHITE font: Font { size: 18 } content: "Not so great" }, Rectangle { x: 301 y: 148 smooth: false width: 118 height: 32 fill: Color.TRANSPARENT onMouseClicked: function( e: MouseEvent ):Void { voted = true; println("clicked Not so great"); wsClient.voteNotSoGreat(); delete myScene.content[1] } } ] } } }; |
| class Result extends CustomNode { override function create():Node { var resultPercent = wsClient.showResults(); var resultString = "{resultPercent} voters liked this clip"; return Group { content: [ Rectangle { fill: Color.BLUE x: 187 y: 145 width: 244 height: 38 arcWidth: 20 arcHeight: 20 onMouseClicked: function( e: MouseEvent ):Void { delete myScene.content[1] } }, Text { x: 199 y: 170 fill: Color.WHITE font: Font { size: 18 } content: resultString } ] } } }; |
| var voted = false; var wsClient = new WebserviceClient; |
| import javafx.scene.*; import javafx.scene.input.MouseEvent; import javafx.scene.media.Media; import javafx.scene.media.MediaPlayer; import javafx.scene.media.MediaView; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.stage.Stage; |
| @javax.xml.bind.annotation.XmlRootElement public class VoteBean { public static enum VOTE { LOVE_IT, NOT_SO_GREAT }; public VOTE vote; public VoteBean() { vote = VOTE.LOVE_IT; } public VoteBean(VOTE vote) { this.vote = vote; } } |

| public
class WebserviceClient { private static com.sun.jersey.api.client.WebResource createWebResource() { return com.sun.jersey.api.client.Client.create(). resource("http://localhost:8080/movie-feedback-webapp/webresources/myresource"); } public static void voteLoveIt() { createWebResource().type("application/json"). post(new VoteBean(VoteBean.VOTE.LOVE_IT)); } public static void voteNotSoGreat() { createWebResource().type("application/json"). post(new VoteBean(VoteBean.VOTE.NOT_SO_GREAT)); } public static String showResults() { return createWebResource().get(String.class); } } |
| @javax.xml.bind.annotation.XmlRootElement public class VoteBean { public static enum VOTE { LOVE_IT, NOT_SO_GREAT }; public VOTE vote; public VoteBean() { vote = VOTE.LOVE_IT; } public VoteBean(VOTE vote) { this.vote = vote; } } |
| int loveIt; int noSoGreat; |
| @POST public void postOneVote(VoteBean bean) { if (bean.vote == VoteBean.VOTE.LOVE_IT) { loveIt++; } else { noSoGreat++; } System.out.println("In POST: " + bean.vote); } |
| @GET @Produces("text/plain") public String getOpinion() { if (loveIt == 0 && noSoGreat == 0) return "No votes cast yet!"; return (loveIt * 100) / (loveIt + noSoGreat) + "%"; } |
Posted by Arun Gupta in webservices | Comments[13]
|
|
|
|
|
Monday December 01, 2008
TOTD #58: Jersey and GlassFish - how to process POST requests ?
Lets extend the Jersey endpoint (TOTD#
56) and client (TOTD#
57) such that it can accept a POST request and then invoke it.
| @POST @Consumes("application/json") @Produces("application/json") public Greeting postIt(Greeting greeting) { System.out.println("In POST: " + greeting.greeting); return greeting; } |
| public void
testPost() { Greeting result = createResource(). type("application/json"). post(Greeting.class, new Greeting("yo!")); assertTrue(result.greeting.equals("yo!")); } |
| Running org.glassfish.samples.AppTest 1 * Out-bound request 1 > GET http://localhost:8080/helloworld-webapp/webresources/myresource 1 > 1 < 200 1 < X-Powered-By: Servlet/2.5 1 < Transfer-Encoding: chunked 1 < Content-Type: text/plain 1 < Server: GlassFish/v3 1 < Date: Tue, 25 Nov 2008 20:19:34 GMT 1 < <?xml version="1.0" encoding="UTF-8" standalone="yes"?><greeting><greeting>Hi there!</greeting></greeting> 1 * In-bound response 1 * Out-bound request 1 > POST http://localhost:8080/helloworld-webapp/webresources/myresource 1 > Content-Type: application/json 1 > {"greeting":"yo!"} 1 < 200 1 < X-Powered-By: Servlet/2.5 1 < Transfer-Encoding: chunked 1 < Content-Type: application/json 1 < Server: GlassFish/v3 1 < Date: Tue, 25 Nov 2008 20:19:34 GMT 1 < {"greeting":"yo!"} 1 * In-bound response Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.191 sec |
Posted by Arun Gupta in webservices | Comments[6]
|
|
|
|
|
Tuesday November 25, 2008
TOTD #56: Simple RESTful Web service using Jersey and Embeddable GlassFish - Text and JSON output
![]() |
Jersey is the open source, production quality, JAX-RS (JSR 311) Reference Implementation for building RESTful Web services in the GlassFish community. It also provides an API that allows developers to extend Jersey to suite their requirements. |
| ~/samples/jersey >mvn archetype:generate
-DarchetypeCatalog=http://download.java.net/maven/2 [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'archetype'. [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Default Project [INFO] task-segment: [archetype:generate] (aggregator-style) [INFO] ------------------------------------------------------------------------ [INFO] Preparing archetype:generate [INFO] No goals needed for project - skipping [INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'. [INFO] Setting property: velocimacro.messages.on => 'false'. [INFO] Setting property: resource.loader => 'classpath'. [INFO] Setting property: resource.manager.logwhenfound => 'false'. [INFO] [archetype:generate] [INFO] Generating project in Interactive mode [INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0) Choose archetype: 1: remote -> jersey-quickstart-grizzly (Archetype for creating a RESTful web application with Jersey and Grizzly) 2: remote -> jersey-quickstart-webapp (Archetype for creating a Jersey based RESTful web application WAR packaging) Choose a number: (1/2): 2 [INFO] snapshot com.sun.jersey.archetypes:jersey-quickstart-webapp:1.0.1-SNAPSHOT: checking for updates from jersey-quickstart-webapp-repo Define value for groupId: : org.glassfish.samples Define value for artifactId: : helloworld-webapp Define value for version: 1.0-SNAPSHOT: : Define value for package: : org.glassfish.samples Confirm properties configuration: groupId: org.glassfish.samples artifactId: helloworld-webapp version: 1.0-SNAPSHOT package: org.glassfish.samples Y: : [INFO] ---------------------------------------------------------------------------- [INFO] Using following parameters for creating OldArchetype: jersey-quickstart-webapp:1.0.1-SNAPSHOT [INFO] ---------------------------------------------------------------------------- [INFO] Parameter: groupId, Value: org.glassfish.samples [INFO] Parameter: packageName, Value: org.glassfish.samples [INFO] Parameter: package, Value: org.glassfish.samples [INFO] Parameter: artifactId, Value: helloworld-webapp [INFO] Parameter: basedir, Value: /Users/arungupta/samples/jersey [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] ********************* End of debug info from resources from generated POM *********************** [INFO] OldArchetype created in dir: /Users/arungupta/samples/jersey/helloworld-webapp [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 21 seconds [INFO] Finished at: Mon Nov 24 14:09:27 PST 2008 [INFO] Final Memory: 12M/30M [INFO] ------------------------------------------------------------------------ |
|
<plugin> <groupId>org.glassfish</groupId> <artifactId>maven-glassfish-plugin</artifactId> </plugin> |
|
<pluginRepositories> <pluginRepository> <id>maven2-repository.dev.java.net</id> <name>Java.net Repository for Maven</name> <url>http://download.java.net/maven/2/</url> <layout>default</layout> </pluginRepository> <pluginRepository> <id>maven-repository.dev.java.net</id> <name>Java.net Maven 1 Repository (legacy)</name> <url>http://download.java.net/maven/1</url> <layout>legacy</layout> </pluginRepository> </pluginRepositories> |
|
<dependency> <groupId>org.glassfish.distributions</groupId> <artifactId>web-all</artifactId> <version>10.0-build-20080430</version> <scope>test</scope> </dependency> <dependency> <groupId>org.glassfish.embedded</groupId> <artifactId>gf-embedded-api</artifactId> <version>1.0-alpha-4</version> <scope>test</scope> </dependency> |
|
<dependency> <groupId>org.glassfish.distributions</groupId> <artifactId>web-all</artifactId> <version>10.0-SNAPSHOT</version> <scope>test</scope> </dependency> <dependency> <groupId>org.glassfish.embedded</groupId> <artifactId>glassfish-embedded-all</artifactId> <version>3.0-Prelude-SNAPSHOT</version> </dependency> |
|
<properties> <jersey-version>1.0</jersey-version> </properties> |
| package org.glassfish.samples; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; // The Java class will be hosted at the URI path "/helloworld" @Path("/myresource") public class MyResource { // The Java method will process HTTP GET requests @GET // The Java method will produce content identified by the MIME Media // type "text/plain" @Produces("text/plain") public String getIt() { return "Hi there!"; } } |
| ~/samples/jersey/helloworld-webapp >mvn glassfish:run [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'glassfish'. [INFO] ------------------------------------------------------------------------ [INFO] Building helloworld-webapp Jersey Webapp [INFO] task-segment: [glassfish:run] [INFO] ------------------------------------------------------------------------ [INFO] Preparing glassfish:run [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:compile] [INFO] Compiling 1 source file to /Users/arungupta/samples/jersey/helloworld-webapp/target/classes [INFO] [glassfish:run] Nov 24, 2008 2:36:05 PM com.sun.enterprise.v3.server.AppServerStartup run INFO: HK2 initialized in 229 ms Nov 24, 2008 2:36:05 PM com.sun.enterprise.v3.server.AppServerStartup run INFO: com.sun.enterprise.naming.impl.ServicesHookup@2470b02c Init done in 237 ms Nov 24, 2008 2:36:05 PM com.sun.enterprise.v3.server.AppServerStartup run INFO: com.sun.enterprise.v3.server.Globals@13b3d787 Init done in 239 ms Nov 24, 2008 2:36:05 PM com.sun.enterprise.v3.server.AppServerStartup run INFO: com.sun.enterprise.v3.server.SystemTasks@61bedd7d Init done in 244 ms Nov 24, 2008 2:36:05 PM com.sun.enterprise.v3.server.AppServerStartup run INFO: com.sun.enterprise.v3.services.impl.HouseKeeper@2b9f7952 Init done in 245 ms Nov 24, 2008 2:36:05 PM com.sun.enterprise.v3.server.AppServerStartup run INFO: com.sun.enterprise.v3.services.impl.CmdLineParamProcessor@5249d560 Init done in 248 ms JMXMP connector server URL = service:jmx:jmxmp://localhost:8888 Nov 24, 2008 2:36:05 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start INFO: Listening on port 8080 Nov 24, 2008 2:36:06 PM com.sun.enterprise.v3.server.AppServerStartup run INFO: com.sun.enterprise.v3.services.impl.GrizzlyService@1baa56a2 startup done in 551 ms Nov 24, 2008 2:36:06 PM com.sun.enterprise.v3.services.impl.ApplicationLoaderService postConstruct INFO: loader service postConstruct started at 1227566166208 Nov 24, 2008 2:36:06 PM com.sun.enterprise.v3.server.AppServerStartup run INFO: Application Loader startup done in 740 ms Nov 24, 2008 2:36:06 PM com.sun.enterprise.v3.server.AppServerStartup run INFO: Glassfish v3 started in 740 ms Nov 24, 2008 2:36:07 PM com.sun.enterprise.web.WebModuleContextConfig authenticatorConfig SEVERE: webModuleContextConfig.missingRealm Nov 24, 2008 2:36:07 PM com.sun.jersey.api.core.PackagesResourceConfig init INFO: Scanning for root resource and provider classes in the packages: org.glassfish.samples Nov 24, 2008 2:36:07 PM com.sun.jersey.api.core.PackagesResourceConfig init INFO: Root resource classes found: class org.glassfish.samples.MyResource Nov 24, 2008 2:36:07 PM com.sun.jersey.api.core.PackagesResourceConfig init INFO: Provider classes found: Hit ENTER for redeploy |


| package org.glassfish.samples; import javax.xml.bind.annotation.XmlRootElement; /** * @author arungupta */ @XmlRootElement public class Greeting { public String greeting; public Greeting() { } public Greeting(String greeting) { this.greeting = greeting; } } |
| //
@Produces("text/plain") @Produces("application/json") public Greeting getIt() { return new Greeting("Hi there!"); } |

| mvn clean package |
Posted by Arun Gupta in webservices | Comments[16]
|
|
|
|
|
Friday October 17, 2008
SOAP and REST - both equally important to Sun
"Sun moving away from SOAP to embrace REST" is the misleading title
of an article recently published in SD
Times. The article provides a good introduction to JAX-RS and
Jersey. But I really wonder what motivated the author of this
article to use this title. This blog, hopefully, provides a better
context.
Jersey is
the Reference Implementation of Java API for RESTful Web Services
(JAX-RS, JSR
311)
and was released earlier this week. The headline indicates that Sun is
leaving SOAP and will support REST. The debate between
REST and SOAP is not new and there are religious camps on both sides
(even within Sun).
And that's completely understandable because each technology has its
own merits and demerits. But just because a new JSR aimed to make
RESTful Web services easy in
the Java platform is released, it does not mean Sun Microsystems is
leaving existing technology in trenches.
The addition of Jersey to Sun's software portfolio makes the Web
services stack from GlassFish community a more compelling and
comprehensive offering. This is in contrast to "moving away"
from SOAP as indicated by the title. As a matter of fact, Jersey will
be included as part of Metro
soon,
the Web Services stack of GlassFish. And then you can use JAX-WS (or
Metro) if you like to use SOAP or JAX-RS (or Jersey) if you prefer
RESTful Web
services. It's all about a offering choice to the community instead of
showing a direction.
Here are some data points for JAX-WS:
Posted by Arun Gupta in webservices | Comments[9]
|
|
|
|
|
Tuesday August 12, 2008
LOTD #1: Using Silverlight to access GlassFish Metro and JAX-WS Web service endpoints
Following TOTD
(Tip Of The Day) pattern, I'm
starting LOTD (Link
Of The
Day) series
today. These are light-weight entries with generally a single line
description and links to other
blogs/articles/tips/whitepapers/screencasts/etc.
Let's start with three recent entries on MSDN that describe how to
invoke Metro
and JAX-WS
Web service endpoints from Microsoft
Silverlight and .NET:
Posted by Arun Gupta in webservices | Comments[2]
|
|
|
|
|
Thursday July 31, 2008
Why GlassFish Metro over Axis ?
Metro (Web
services stack from GlassFish)
is kicking strong these days - here are two instances!
Posted by Arun Gupta in webservices | Comments[0]
|
|
|
|
|
Thursday July 10, 2008
Getting Started with GlassFish in IntelliJ IDEA
IntelliJ IDEA
7.0.x include plugins
that provide support for configuring GlassFish.
This blog provides clear instructions on how to get started by
developing and deploying a JSP, Servlet and Web services using
GlassFish in IntelliJ. The instructions are using IntelliJ 7.0.3 Build
#7757 (with no additional plugins).


















|
java.io.PrintWriter out = response.getWriter(); try { out.println("<html>"); out.println("<head>"); out.println("<title>Servlet NewServlet</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet NewServlet at " + request.getContextPath () + "</h1>"); out.println("</body>"); out.println("</html>"); } finally { out.close(); } |
| doGet(request, response); |







|
client.HelloWorld service = new
client.HelloWorldService().getHelloWorldPort(); //invoke business method System.out.println(service.sayHelloWorldFrom("Duke")); |

Posted by Arun Gupta in webservices | Comments[10]
|
|
|
|
|
Saturday April 05, 2008
GlassFish Metro Web Services Training Course
Interested
in understanding the nitty gritty details of how Metro in GlassFish
provides Secure, Reliable, Transactional and .NET 3.0 interoperable Web
services ? You can certainly read all about it in Metro Users Guide,
post questions to Metro
Forum, subscribe to Metro Blogs
or The
Aquarium.
![]() |
But now there is a new 5 hours Web-based course, WTMB-SAS-1500,
from Sun Training.
The course content is organized in 5 different modules:
|
Posted by Arun Gupta in webservices | Comments[7]
|
|
|
|
|
Tuesday April 01, 2008
BizTalk Services SDK, GlassFish and Metro
Microsoft BizTalk R11
CTP was released last week and now contains a sample that is
based on GlassFish,
Metro and NetBeans. Even though
today is April 1st, this is not intended to be an April
Fool's Day joke. Read more about the sample in this blog
entry. The relevant bits from the entry are quoted below:
The sample shows how to
use the BizTalk Services Identity Security Token Service (STS) to
secure the communication between a Java client and a Java service
providing federated authentication and claims-based authorization. The
sample, which you can find in
./Samples/OtherPlatforms/StandaloneAccessControl/JavaEE5 once you
installed the SDK, is a pure
Java sample not requiring any of our bits on either the
service or client side. The interaction
with our services is purely happening on the wire.
The Metro team over at
Sun Microsystems has made
a very significant contribution to making this all work.
Before we started making changes to accommodate Java, there would have
been very little hope for anyone to get this seemingly simple scenario
to work. We had to make quite a few changes even though our service did
follow the specs.
As a result of this
collaboration, Metro
1.2 is going to
be a better and more interoperable release for the Sun's customers and
the greater Java community and BizTalk Services as well as
our future identity products will be better and more interoperable,
too. Win-Win. Thank you,
Sun.
Thank you Microsoft for adding this sample to the BizTalk Services SDK.
Metro team demonstrated a similar
demo at JavaOne
2007. The demo shows how an Excel 2007 client can invoke a
secure and reliable endpoint deployed on GlassFish. The entire source
code for the sample, along with instructions to build, are available here.
This is possible today because of our participation in previous 6
plugfests (Mar
2008, Nov
2007, Jul
2007, Oct
2006, Mar
2006, Nov
2005) hosted by Microsoft.
Technorati: glassfish netbeans
metro webservices
biztalk
microsoft
interoperability
Posted by Arun Gupta in webservices | Comments[3]
|
|
|
|
|
Monday March 31, 2008
Slides for St Louis & Kansas City Developer Update Meetings
I presented on GlassFish
and Metro
in Developer Update meetings in St
Louis & Kansas
City. The slides are available here.
The demos shown in the talk can be seen at:
| Event | City | Date |
| The Server Side Java Symposium | Las Vegas | Mar 26, 2008 |
| Ajax World East 2008 Day 2, Day 1 | New York | Mar 18-19, 2008 |
| SD West 2008 | Santa Clara | Mar 6, 2008 |
| GlassFish Day | Hyderabad, India | Feb 29, 2008 |
| Sun Tech Days - Day 2, Talent Show, Day 1 | Hyderabad, India | Feb 27-28, 2008 |
| acts_as conference - Day 2, Day 1 | Orlando | Feb 8-9, 2008 |
| South Bay Ruby Meetup | Mountain View | Jan 30, 2008 |
Posted by Arun Gupta in webservices | Comments[3]
|
|
|
|
|
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]
|
|
|
|
|
Friday January 25, 2008
TOTD #22: Java SE client for a Metro endpoint
Metro is the Web services stack in GlassFish. It is your one-stop shop from a simple Hello World to Secure, Reliable, Transactional and .NET 3.0 interoperable endpoint. Metro Tooling is provided by NetBeans and other options are explained here.
Screencast #ws7 describes how a Metro endpoint can be easily created and deployed on GlassFish and invoked from a Web client using NetBeans IDE. This TOTD (as requested here and here) describes how a Secure and Reliable Metro endpoint can be invoked using a Java SE client.
Here is my environment:
Let's get started.
Java/Java
Application. Name the project as "SEClient" and take all other
defaults.New", "Web Service
Client...".Browse..." button next to "Project" radio button and
select the deployed Web service endpoint.client" and click on "Finish".Properties", "Libraries", "Add
JAR/Folder" and add "webservices-rt.jar" from the "lib" directory of GlassFish
installation. Click on "OK".Web Service References" node in the project and drag the
leaf node in the "main" method of "Main.java" of the client project.name" to "Duke".Run". This will build the
project, invoke the endpoint and show the results in Output window as
"Hello Duke".====[com.sun.xml.ws.assembler.server:request]====
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:sayHello xmlns:ns2="http://server/">
<name>Duke</name>
</ns2:sayHello>
</S:Body>
</S:Envelope>
============
====[com.sun.xml.ws.assembler.server:response]====
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:sayHelloResponse xmlns:ns2="http://server/">
<return>Hello Duke</return>
</ns2:sayHelloResponse>
</S:Body>
</S:Envelope>
============Web
Service References", right-click and select "Refresh Client".Confirm Client Refresh" window, select "Also
replace local wsdl file with original WSDLs located at:" checkbox
and click on "Yes".Run". This will build the
project, invoke the endpoint and show the results in Output window as
"Hello Duke".====[com.sun.xml.ws.assembler.server:request]====
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header>
<To xmlns="http://www.w3.org/2005/08/addressing">http://localhost:8080/SEEndpoint/HelloServiceService</To>
<Action xmlns="http://www.w3.org/2005/08/addressing">http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence</Action>
<ReplyTo xmlns="http://www.w3.org/2005/08/addressing">
<Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
</ReplyTo>
...Web
Service References", right-click and select "Refresh Client".Confirm Client Refresh" window, select "Also
replace local wsdl file with original WSDLs located at:" checkbox
and click on "Yes".Web Service References"
node, select "Edit Web Service Attributes" and select "Use
development defaults". This will ensure that client and endpoint
security credentials match.Source Packages", "META-INF" and
open "HelloServiceService.xml". The name of this file is
derived from the service name at the endpoint and may be different.
Specify the location of trust store by adding the following attributes
to "sc:KeyStore" element:location="C:\testbed\glassfish\final\glassfish\domains\domain1\config\cacerts.jks"
type="JKS" storepass="changeit"<sc:TrustStore wspp:visibility="private" peeralias="xws-security-server"
location="C:\testbed\glassfish\final\glassfish\domains\domain1\config\cacerts.jks"
type="JKS" storepass="changeit"/>Run". This will build the
project, invoke the endpoint and show the results in Output window as
"Hello Duke".====[com.sun.xml.ws.assembler.server:request]====
<?xml version="1.0" ?>
<S:Envelope
xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
xmlns:exc14n="http://www.w3.org/2001/10/xml-exc-c14n#">
<S:Header>
<To xmlns="http://www.w3.org/2005/08/addressing" wsu:Id="5006">http://localhost:8080/SEEndpoint/HelloServiceService</To>
<Action xmlns="http://www.w3.org/2005/08/addressing" wsu:Id="5005">http://server/HelloService/sayHelloRequest</Action>
<ReplyTo xmlns="http://www.w3.org/2005/08/addressing" wsu:Id="5004">
<Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
</ReplyTo>
<MessageID xmlns="http://www.w3.org/2005/08/addressing"
wsu:Id="5003">uuid:bb0e9571-a773-49bb-bad0-20a01d3af9f1</MessageID>
<wsse:Security S:mustUnderstand="1">
<wsu:Timestamp
xmlns:ns10="http://www.w3.org/2003/05/soap-envelope" wsu:Id="3">
<wsu:Created>2008-01-23T20:13:28Z</wsu:Created>
...If you are using JDK version prior to Java SE 6 U4, then need to override the JAX-WS and JAXB API as described here. Java SE 6 U4 already includes JAX-WS and JAXB 2.1 APIs which are required for the Metro client to work.
Please leave suggestions on other TOTD that you'd like to see. A complete archive is available here.
Technorati: totd webservices metro glassfish netbeans javase
Posted by Arun Gupta in webservices | Comments[18]
|
|
|
|
|
Thursday January 24, 2008
RESTful representation of "sakila" using GlassFish and NetBeans IDE
"sakila" is the sample database shipped with MySQL (pronounced as my ess-kew-ell). In the context of Sun Microsystems announcing the agreement to acquire MySQL, I'd like to dedicate this entry to show how this sample database can be exposed as a RESTful Web service endpoint and deployed on GlassFish using Jersey Tooling Plugin (0.4.1 with Jersey 0.4) in NetBeans IDE.
Lets get started!
sakila".mysqld-nt --user root
--console' in bin directory on Windows or './bin/mysqld_safe'
from MySQL directory on Unix flavors.sakila".
Choose "GlassFish v2" as the "Server:".Services" tab of NetBeans IDE, expand "Drivers" and add
MySQL
Connector/J driver if it does not exist already.
New", "Entity Classes from
Database...". In "Data Source", select "New Data Source..." and specify the
values as shown below:
film" in "Available Tables" and click on "Add >" as shown
below:
Next >".Create Persistence Unit..." and take all the defaults as shown
below:
Create".sakila" as shown below:
Finish".Configuration Files"
and open "persistence.xml". Specify the username and password
by replacing <properties/> with the following fragment:<properties>
<property name="toplink.jdbc.user" value="root"/>
<property name="toplink.jdbc.password" value=""/>
</properties>Tools", "Plugins", "Available Plugins", "RESTful
Web Services" and then click on "Install". This installs the
Jersey Tooling
Plugin in the IDE.New", "RESTful Web Services from
Entity Classes...".Add >>", take all other defaults as shown
below:
Next >", take all defaults and then "Finish".Test RESTful Web Services".
The following web page is presented in the browser:
films" and then on "Test" as shown
below:
Test" button or the URL "http://localhost:8080/sakila/resources/films/"
shows the RESTful representation of the "Film" table. The
default representation shows 10 records from the table where each entry
returns the "id" of the film and a reference to the detailed
entry.http://localhost:8080/sakila/resources/films/?max=40".
Additional fields from the table can be displayed by adding getter methods
to "converter.FilmRefConverter" class such as:@XmlElement
public String getTitle() {
return entity.getTitle();
}

Here are few more ideas for you to explore:
A JRuby-on-Rails application using MySQL is explained here. TOTD #9 explains how JDBC connection pooling in GlassFish can be used for a JRuby-on-Rails application using MySQL.
The key message here is MySQL can be very easily used with GlassFish and NetBeans IDE makes it possible! Once MySQL becomes part of Sun, this integration is going to be much more seamless for the betterment of community.
All the entries on this blog using MySQL can be found here. And last but not the least, Welcome aboard MySQL!
A NetBeans project with all the source code can be downloaded from here. You will still need to setup the database connection and need to make sure the correct version of Jersey plug-in as well :)
Technorati: glassfish netbeans jersey mysql sakila jpa jmaki rubyonrails
Posted by Arun Gupta in webservices | Comments[28]
|
|
|
|
|
Tuesday January 22, 2008
Hold the Date - Feb 29, 2008, GlassFish Day is coming to India
|
|
What is GlassFish and
Why GlassFish ? How community is an important aspect ? How is it different and better than other alternatives ? |
If you would like any (or more) of these questions answered, then the upcoming GlassFish Day in Hyderabad, India will provide answers to all of them. This is our first such event in India and we are excited! There will be presentations and demos highlighting different aspects of GlassFish.
Date: Feb 29, 2008
Venue: Hyderabad International Convention
Center, Hyderabad, India
All you need to do is Register for the Tech Days and then you get to attend GlassFish Day as an extra bonus day. The Tech Days Session also provide a wealth of information ranging from Java SE 6, Java Scripting, Project Metro, Java ME and many others.
Community is an overarching aspect of GlassFish. Let us know if you have been using GlassFish and would like to talk in front of audience. Just leave a comment on this blog to get in touch.
Read about success stories, see how GlassFish is used in your geography and how it has been gaining adoption. You can also subscribe to the weekly highlights.
I'll be there, will you ?
Technorati: glassfish glassfishday suntechdays india hyderabad
Posted by Arun Gupta in webservices | Comments[0]
|
|
|
|
|
Today's Page Hits: 2707
Total # blog entries: 1002