Skip to main content

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

Posted by arungupta on October 12, 2007 at 12:36 PM EDT

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 projectmetro webservices

Related Topics >>