Miles to go ...

Arun Gupta is a GlassFish Evangelist focusing on Web Tier at Sun. He was the spec lead for APIs in the Java platform, committer in multiple Open Source projects, participated in standard bodies and contributed to Java EE and SE releases.
« TOTD #11: Setup... | Main | TOTD #13: Setup... »

http://blogs.sun.com/arungupta/date/20071011 Thursday October 11, 2007

TOTD #12: Invoking a Java EE 5 Web service endpoint from JRuby

A user asked how to invoke a Java EE 5 Web service from JRuby. This TOTD explains how a simple Metro Web service deployed on GlassFish V2 can be easily invoked from JRuby.

  1. Create a simple Web service using NetBeans IDE and deploy it on GlassFish V2 following the screencast #ws7.
  2. Generate the client-side artifacts using wsimport as shown below:

    C:\workarea\samples\jruby\ws>\testbed\glassfish\final\glassfish\bin\wsimport.bat -keep http://localhost:8080/WebApplication32/HelloService?wsdl
    parsing WSDL...


    generating code...


    compiling code...
  3. Set the CLASSPATH in the command prompt as shown below:

    C:\workarea\samples\jruby\ws>set CLASSPATH=.;\testbed\glassfish\final\glassfish\lib\webservices-rt.jar;\testbed\glassfish\final\glassfish\lib\endorsed\webservices-api.jar;C:\testbed\glassfish\final\gl
    assfish\lib\activation.jar
  4. Use the JRuby code to invoke the Web service endpoint as shown below:

    include Java

    service = Java::server.HelloService.new();
    port = service.getHelloPort();

    result = port.sayHello("Duke");
    java.lang.System.out.println(result);
  5. Invoke the JRuby code as shown below:

    C:\workarea\samples\jruby\ws>\testbed\ruby\jruby-1.0.1\bin\jruby simple.rb
    Hello Duke

That's it! Read more about Tooling Options in Metro.

Using Java classes in JRuby explain the issues that you may encounter in invoking Java classes from JRuby.

Please leave suggestions on other TOTD that you'd like to see. A complete archive is available here.

Technorati: totd jruby jrubyonglassfish glassfish netbeans metro webservices ruby

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

Post a Comment:
  • HTML Syntax: NOT allowed
« TOTD #11: Setup... | Main | TOTD #13: Setup... »

Valid HTML! Valid CSS!

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