Arun Gupta, Miles to go ...

Arun Gupta is a technology enthusiast, a passionate runner, and a community guy who works for Sun Microsystems.
Main | Next page »

http://blogs.sun.com/arungupta/date/20090825 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.

  1. Lets create a simple "Dynamic Web Project" as shown below:


  2. Name the project "HelloMetro" and take all other defaults:



    Click on "Finish" to complete the project creation.
  3. Metro allows to create a Web service from a POJO class. So let's add a POJO to the project by right-clicking on the project and selecting "New", "Class" as shown below:

      

    Specify the package name as "server", class name as "HelloService" and click on "Finish".
  4. Add a simple method to the newly generated class as:

    public String sayHello(String name) {
          return "Hello " + name + "!!";
    }
  5. Expand the project, go to "HelloService.java" in "server" package, right-click, select "Web Services", "Create Web service".
  6. Click on "Web service runtime: Apache Axis" and select "Metro (JAX-WS) Runtime" as the Web service runtime as shown below:

  7. Move the slider on the left to top. This will enable testing of the deployed Web service. The completed configuration looks like:



    and click on "Next >".
  8. Select the checkbox "Copy Metro library jars to the project" to resolve the references correctly as shown below:



    and click on "Next >". This bundles the application and deploys to GlassFish and provides an option to test the deployed Web service as shown below:



    Clicking on the "Launch" button shows the following output in the browser:



    The WSDL is hosted at "http://localhost:8083/HelloMetro/HelloServiceService?wsdl".
  9. Click on "sayHello" method, click on "Add" and enter the value as "Duke" as shown below:



    Click on "Go" and the response is shown as:



    Clicking on "Source" in the response window shows the SOAP request/response messages as shown below:

  10. Alternatively, you can click on "Finish" to complete the dialog. Then click on "Run" menu item, "Launch the Web Services Explorer" to see a screen as:



    Enter the URL of the WSDL in "WSDL URL" box as "http://localhost:8083/HelloMetro/HelloServiceService?wsdl" and click on "Go". Now you are seeing the similar screen to test the Web service within the integrated browser as shown below:


A future blog will cover how to write a database-enabled application using the bundled Dali JPA Tools and MySQL pre-registered JDBC driver.

Please send your questions and comments to users@glassfishplugins.dev.java.net.
Please leave suggestions on other TOTD that you'd like to see. A complete archive of all the tips is available here.

Technorati: totd glassfish eclipse galileo webservices metro jax-ws

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20090218 Wednesday February 18, 2009

Sun Tech Days Hyderabad 2009


India has always had the largest number of attendees of all the Tech Days, and this time is certainly no exception. 10,000+ attendees, the passion for technology, the eagerness to share their work, and everything else makes it certainly one of the most exciting venues for Tech Days.

The Hyderabad International Airport is certainly very impressive - big, clean, and very 21st centurisque with a 8-lane freeway connecting to the main city.

See a short video as the attendees were allowed to enter the Hyderabad International Convention Center (the venue for Tech Days):


I got a chance to talk to the General Manager of the convention center and very happy to know that similar convention centers are planned for Pune (1/2 the size of existing one), Mumbai (4x), and Bangalore (2x) in the near future.

As part of the opening, there was an excellent performance by an 11-year old percussionist, enjoy the video here:


Absolutely stunning performance!

It was funny, I was standing right next to the boy's parents while recording the video. Apparently the boy was allotted 10 minutes and the parents were trying their best to distract the boy right at the beginning of 11th minute :)

I presented on:

  • WSIT: Security, Reliability, Transactional, and .NET-interoperable Web services (slides). The screencast #ws7 is the demo shown during the talk.
  • GlassFish & Future of Java EE (slides)
There were 1000+ attendees in both the sessions and had some very interactive discussions post session. It was a great opportunity to meet lots of local Campus Ambassadors, students using GlassFish for their projects, engineers using GlassFish for their development/deployment, Sun colleagues and lots of other folks!

Here are some of the pictures:


And finally the evolving album:



Technorati: conf suntechdays glassfish metro wsit hyderabad

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20081110 Monday November 10, 2008

GlassFish @ Silicon Valley Code Camp 2008 - Trip Report

CodeCamp at FootHill College. Click Here for Details and Registration 1400 registrations, 112 sessions, free pizza, a barbecue on Saturday night, raffles and lot more - that is Silicon Valley Code Camp.

Jitu, Jiandong, Jacob, and I presented on GlassFish at Silicon Valley Code Camp over the weekend. The event had higher attendance (close to 500) than last year and certainly is a great networking event for the local community.

The venue at Foothill College is literally in foot of the hills and the campus is beautiful. The barebecue reception in the evening was certainly a pleasant relief to the attendees who did not get a pizza slice at lunch ;-)

If you could not attend any of our sessions hen you can read through the slides for GlassFish: The Best Open Source Application Server and Rails powered by GlassFish. The demos shown in the talk are available at:
Feel free to send any comments to users@glassfish.dev.java.net.

Check out some pictures:


And the complete album at:



Technorati: conf siliconvalleycodecamp glassfish netbeans rubyonrails metro webservices

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20081017 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:

  • The JAX-WS 2.0 specification was released on May 11, 2006. There have been couple of maintenance releases since then and another one brewing.
  • Parts of Metro, the implementation of JAX-WS, are currently baked into GlassFish, embeddable in JBoss WS Stack, and also part of Oracle Weblogic and IBM Websphere.
  • The implementation stack is mature and used in several key customer deployments. 
  • JAX-WS is already included in Java SE 6 and hence available to a much wider audience.
  • As opposed to "moving away", JAX-WS 2.2 (currently being worked upon) will be included in Java EE 6 platform, as will Jersey be.
So I believe both SOAP and REST are here to stay, at least in the near future. And Sun Microsystems is committed to support them!

You still think Sun is moving away from SOAP ?

It seems a personal preference is interpreted as Sun's disinvestment in SOAP. It's good to have increased readership but not at the cost of misleading headlines :)

Technorati: jax-ws rest webservices metro sdtimes glassfish

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20080812 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:

All entries will be archived at LOTD.

Technorati: lotd webservices metro jax-ws glassfish msdn

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20080731 Thursday July 31, 2008

Why GlassFish Metro over Axis ?


Metro (Web services stack from GlassFish) is kicking strong these days - here are two instances!

  1. ArcGIS SOAP stack gains 90% performance improvement using Metro

    An intern in the Web services team for performance enhancement of ArcGIS SOAP SDK reported:

    "With Axis 1.x based tool kits XML parsing was identified as a bottleneck and therefore we wanted to make a switch to a tool kit that uses the Streaming API for XML Parsing (StAX). We identified that Metro (Glassfish's SOAP Stack) was the way to go and i generated the new Metro based SDK for accessing Web-Services."

    And the conclusion is ...

    "The result of this project is an increased performance of the ArcGIS Server's SOAP stack (by about 90%)."

    Pretty cool - Metro (Web services stack baked in GlassFish) gave about 90% improvement over Axis! Read more details about the study here.
  2. Change of the guard: AXIS out, JAX-WS in

    Here are some relevant points:

    "I have come to a conclusion: I no longer want to deal with the hassle that has become Apache AXIS."

    "AXIS2 is current, but has become very large, the doc is poor, the support is invisible, the generated code smells, and the seams are everywhere.  Fifty nine jar files?  Really?   Do I need this hassle?  With JAX-WS, do I need AXIS any longer? I think not."

    "But I honestly cannot believe customers will continue to put up with the furball that AXIS2 has become. And if I am in a position to make a recommendation, I will recommend JAX-WS. It works."
And you can also connect to Microsoft Exchange Server using JAX-WS.

And here are some other endorsements for Metro.

Technorati: webservices adoption glassfish metro axis

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20080710 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).

  1. Create a new project
    1. Clicking on "Create New Project" or "File", "New Project". Take the default as shown below:



      and click on "Next >".
    2. Enter the project name as "GlassFishRocks" and take all defaults as shown:



      and click on "Next >".
    3. Take another default for the source directory as shown:



      and click on "Next >".
    4. For the first time use, JDK needs to be specified. Click on "+" in top-left corner as shown here:



      Take the default option of "JSDK" and specify the Home Directory as shown:



      Click on "OK" and then click on "Next >".
    5. Let's create a Web application. Select the list of technologies as shown:



      and finally (phew!) click on "Finish". The expanded project looks like:

  2. Create a GlassFish configuration
    1. Select "Run", "Edit Configurations" as shown:


    2. Click on "+" on top-left corner and select GlassFish as shown below:


    3. Specify the location of GlassFish Application server at:



      by clicking on "Configure" button and enter the values as shown:



      and click on "OK". You can download and install GlassFish v2 UR2 from here.
    4. Enter the "Name" and select the "Server Domain" as shown:



      and click on "OK".
  3. Deploy the Web application
    1. Click on the green button in the toolbar:


    2. Click on the "Fix" button on the bottom and then click "Run". The recently created Web module is selected to be deployed as shown:

    3. This starts the GlassFish v2 UR2 Application Server and deploys the Web application showing the console as:



      and also shows the default page at "http://localhost:8080/GlassFishRocksWeb/". You can edit "index.jsp", re-deploy the Web facet and refresh the page to see the updated message.

      Notice, even though project's name is "GlassFishRocks", the application context root is "GlassFishRocksWeb".
  4. Now lets create/deploy a new Servlet.
    1. Create a new project as described above and name it "KillerServlet".
    2. Right-click on the project and select "New", "Servlet" as shown:

    3. Enter the values as shown:



      and click on "OK".
    4. The "Java EE: Structure" shows the project as:


    5. Double-click on "HelloServlet" (nested one) and add the following fragment to "doGet" method:

              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();
              }

      NetBeans IDE auto-generates this code for a Servlet ;-) And add the following to "doPost" method:

             doGet(request, response);
    6. Double-click on "web.xml" and then select "Assembly Descriptor" tab.
    7. Click on "+" in Servlet Mappings and specify the values as:


    8. Deploy the project (as described above) and output from Servlet is displayed at "http://localhost:8080/KillerServletWeb/hello". Read more details in Creating Java EE Apps and Servlets with IntelliJ IDEA.

      Remember the weird context root, it's "KillerServletWeb" instead of "KillerServlet". Now there may be a good reason to do so but nothing obvious.
  5. Now lets create a simple Web service using the Metro Web services stack (the stack baked into GlassFish)
    1. Create a new project with name "GlassFishWS" following the instructions given above.
    2. Select the list of technologies as shown:

    3. The default generated Web service looks like:

    4. The default generated Web service uses light-weight Endpoint API to host the endpoint. Run the Web service by right-clicking in the editor pane and selecting "Run" as shown or default shortcut of Ctrl+Shift+F10:

    5. The WSDL is now available at "http://localhost:9000/HelloWorld?wsdl".
    6. Right-click on the project and select "New", "Web Service Client" as shown:



      enter the value as "WSClient" and click on "OK".
    7. In the next dialog, enter the values as shown:

    8. The generated client code has some errors as shown:



      Change the code to:

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

      and run WSClient.main to see the result as:



      Now you deployed a Metro Web service using light-weight Endpoint API.  The bundled plugin version is 0.9 build 2 and the steps are so much cleaner from 0.7 version of the plugin.

      Read more about Web Services support in IntelliJ IDEA.
    9. Deploying this Web service on GlassFish is really simple.
      1. Create a new GlassFish configuration as explained above.
      2. Run the project using this configuration and the Web service is now hosted at "http://localhost:8080/GlassFishWSWeb/services/HelloWorld?wsdl".
      3. Generate a client using the steps described above.
Here are few issues filed:
  • JEEAS-180 does not allow an application to be re-deployed to GlassFish and that's why the examples above use different projects.
  • JEEAS-181  asks for better integration of GlassFish logs in the IDE.
  • JEEAS-182 require support for GlassFish v3 in the GlassFish plugin. Please help by voting for this issue.
  • WSVC-61 reports the errors generated in Web services client code
So whether you are using Eclipse, IntelliJ or NetBeans - you can easily configure GlassFish and deploy your applications directly from within the IDE. Here are some related links:
However of all the IDEs, NetBeans IDE still provides the most comprehensive coverage in terms of development and deployment of Java EE applications (JSP, Servles, Java Server Faces, SOAP-based .NET 3.0-interoperable Web service, RESTful Web services, JPA, EJBs) and server plug-ins (GlassFish, Tomcat, JBoss, WebLogic, WebSphere, OC4J, SAP BusinessOne and JOnAS).


Technorati: glassfish intellij idea jsp servlets metro webservices

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20080709 Wednesday July 09, 2008

GlassFish Family in Readers Choice Awards 2008 Finalists


2008 Readers Choice Awards from SYS-CON SOA World Magazine are announced. There are quite a few projects from GlassFish and sister communities. The nominations are:

GlassFish Best App Server
Hudson Best Automation Tool
Metro Best Framework
NetBeans Best IDE
Java CAPS Best Integration Tool
Project OpenESB Best Open Source SOA Tool
Metro: XML and Web Services SecuritySun Access Manager/OpenSSO Best Security Solution
Sun Java CAPS Best SOA Platform
Sun Java CAPS Best SOA Tool
Java API for XML Processing (JAXP) Best Web Services Utility
Java API for XML Processing (JAXP) Best XML Parser

Even though voting startd on Jun 23 and finishes, after a looong voting period, on Nov 15 the voting process is still not intuitive. Trying different browsers on different machines didn't help either. Anyway, I sent an email using their "Contact Us" link and hopefully will hear from them soon :)

In the meanwhile, each of the nominated products above can brag with the logo on their website.

Technorati: syscon awards glassfish hudson javacaps metro jaxp

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20080405 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:
  • WMT-SAS-1543:Adding Quality of Service and .NET Interoperability to Web Services
  • WMT-SAS-2544: Creating Reliable and Secure Interoperable Web Services
  • WMT-SAS-2545: Creating Transactional Web Services
  • WMT-SAS-2546: Working With the Web Services Policy
  • WMT-SAS-2547: Brokered Trust
Each module explains What/Why/How of each technology and then shows a complete demo using NetBeans on how to use that feature. The course can be taken within 365 days after the purchase. Read more details here.

Here are some other related courses:
Technorati: sun training course metro webservices glassfish netbeans

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20080401 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

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20080331 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:

The healthcare scenario explained in the talk can be seen as a demo here and the associated source code can be downloaded here.

The flight out of Kansas City got cancelled because of a hydraulic pump failure and finally reached home around mid night :( I was at least glad to come back home the same night!

The travel calendar so far this year is:

Event City Date
The Server Side Java Symposium Las Vegas Mar 26, 2008
Ajax World East 2008 Day 2Day 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

Next stop, FISL in Brazil.

Technorati: conf glassfish netbeans metro webservices stlouis kansascity

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20080325 Tuesday March 25, 2008

Rails powered by GlassFish & jMaki @ The Server Side Java Symposium, Las Vegas - Mar 26, 2008

If you want to learn more about:

  • How to use GlassFish as development & deployment platform for Rails applications ?
  • How GlassFish v3 Gem provides a "green" alternative to WEBrick & Mongrel ?
  • How to use NetBeans & jMaki plug-in to embed rich widgets in your Rails applications ?
Then you can learn all about it in The Server Side Java Symposium, Las Vegas. Here are the coordinates:

Date: Mar 26, 2008
Time: 2:30 - 3:30pm
Track: Language & Coding
Title: Rails powered by GlassFish & jMaki

A popular statement for Las Vegas is What happens in Vegas, Stays in Vegas! But I promise to share all the slides & demos with you so that you can enjoy at least the technical part of it ;-)

Another interesting session worth attending is How to use the Metro Web services stack to Build Fast, Scalable Services by Kohsuke on Mar 26 (Wed) from 4:10 - 5:15pm.

Technorati: conf theserverside tssjs lasvegas rubyonrails glassfish jmaki netbeans metro webservices

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20080316 Sunday March 16, 2008

Travel Schedule - Next 5 weeks

Here is my travel schedule for next 5 weeks:

Mar 17-21 Ajax World, New York Web Application Development using jMaki
Mar 25-26 The Server Side Java Symposium, Las Vegas Rails powered by GlassFish & jMaki
Mar 27 Developer Update, St Louis Westport DoubleTree, FREE event Open Source Web Services stack in GlassFish
Mar 28 Developer Update, Kansas City, FREE event Rich Internet Applications and GlassFish
Apr 16-19 FISL, Brazil Web 2.0 Application Development using jMaki and
Asynchronous Ajax for Revolutionary Web Applications

Stop by and say hello if you are present at any of the events. You'll hear about different GlassFish technologies:
  • How Metro provides enterprise-grade open source Web services stack for meeting all your needs
  • How jMaki allows you to create Rich Internet Applications
  • How Rails applications can be powered by GlassFish & jMaki
  • Asynchronous Ajax that allows you to scale your applications tremendously
  • And any other topic that you are interested in :)
Drop a comment if you are interested in a run or meal together ?

Technorati: conf glassfish metro webservices netbeans jmaki ajax newyork lasvegas stlouis kansascity brazil fisl ajaxworld tssjs

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20080131 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.

  1. Following screencast #ws7, create a plain (without Security or Reliability enabled) Metro endpoint using NetBeans 6 and GlassFish v2.
  2. In NetBeans 6 IDE, install the JavaFX plugin as described here.
  3. 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.
    1. Create a new project of type "Java Class Library" as shown below:



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



      and click on "Finish".
    3. Right-click on the newly created project, select "New", "Web Service Client...".
    4. 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".
    5. 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.
  4. Create JavaFX project
    1. Create a new JavaFX project by right-clicking in the Project explorer, selecting "New Project" and entering the values as shown below:

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



      and click on "Finish".
    3. 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.
    4. In 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
      };
  5. Invoke the JavaFX client project
    1. Right-click on the recently create project ("MetroClient") and select "Run Project". The following window is displayed:

    2. Enter "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

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20080125 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.

  1. Following screencast #ws7 create a plain (without Reliability and Security enabled) Metro endpoint.
  2. Create the Java SE client project
    1. In NetBeans IDE, create a new project of the type Java/Java Application. Name the project as "SEClient" and take all other defaults.
    2. Right-click on the newly created project, select "New", "Web Service Client...".
    3. Click on the "Browse..." button next to "Project" radio button and select the deployed Web service endpoint.
    4. Enter the package name as "client" and click on "Finish".
  3. Invoke the plain Metro endpoint
    1. Right-click on the project, select "Properties", "Libraries", "Add JAR/Folder" and add "webservices-rt.jar" from the "lib" directory of GlassFish installation. Click on "OK".
    2. Expand the "Web Service References" node in the project and drag the leaf node in the "main" method of "Main.java" of the client project.
    3. Change the value of parameter "name" to "Duke".
    4. Right-click the project and select "Run". This will build the project, invoke the endpoint and show the results in Output window as "Hello Duke".
    5. If your GlassFish instance is configured to show SOAP messages then the following SOAP messages will be shown in the output window:

      ====[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>
      ============
  4. Invoke the Reliable Metro endpoint
    1. Following the instructions in screencast #ws7, enable Reliability on Metro endpoint and re-deploy.
    2. In the client project, select the first child node of "Web Service References", right-click and select "Refresh Client".
    3. In the "Confirm Client Refresh" window, select "Also replace local wsdl file with original WSDLs located at:" checkbox and click on "Yes".
    4. Right-click the client project and select "Run". This will build the project, invoke the endpoint and show the results in Output window as "Hello Duke".
    5. The SOAP messages during this run will now contain Reliable Messaging protocol messages and resemble as shown below:

      ====[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>
          ...
  5. Invoke the Secure Metro endpoint
    1. Following the instructions in screencast #ws7, disable Reliability and enable Security on Metro endpoint and re-deploy.
    2. In the client project, select the first child node of "Web Service References", right-click and select "Refresh Client".
    3. In the "Confirm Client Refresh" window, select "Also replace local wsdl file with original WSDLs located at:" checkbox and click on "Yes".
    4. Right-click on the first child of "Web Service References" node, select "Edit Web Service Attributes" and select "Use development defaults". This will ensure that client and endpoint security credentials match.
    5. Expand "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"

      The updated element looks like:

      <sc:TrustStore wspp:visibility="private" peeralias="xws-security-server" location="C:\testbed\glassfish\final\glassfish\domains\domain1\config\cacerts.jks" type="JKS" storepass="changeit"/>

      Make sure to match the value of location and password of the trust store in your environment.
    6. Right-click the client project and select "Run". This will build the project, invoke the endpoint and show the results in Output window as "Hello Duke".
    7. The SOAP messages during this run are now secured using the default security profile in NetBeans. The SOAP messages resemble as shown below:

      ====[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

del.icio.us | furl | simpy | slashdot | technorati | digg |
|
Main | Next page »

Valid HTML! Valid CSS!

This is a personal weblog, I do not speak for my employer.