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

Comments:

Post a Comment:
Comments are closed for this entry.
About

profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.


Java EE 7 Samples

Stay Connected

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today