Calling SOAP Services from JRuby

This blog post has been published as a chapter in the JRuby Cookbook by O'Reilly.

I have been working on a project which uses the Mule ESB, and a JRubyOnRails app.

Part of this means calling SOAP services from within the JRuby app.

Ola Bini sets out a couple of approaches in his JRuby on Rails book,but I thought I would blog the success I've had using the mule-client libraries.

I am passing "complex" Java objects around in these SOAP services, not just primitives - always more difficult when it comes to SOAP interoperability.

Here is the call:

include_class 'org.mule.extras.client.MuleClient' 
include_class 'org.mule.impl.MuleMessage'
def make_soap_request(soapurl, request) 
    c = 
        message =   
        m = c.send(soapurl, message , nil)   
        return m.getPayload() 
    rescue Exception => e   
        logger.error e 

The return value is the object returned by the soap call. Nice and easy.

Here are the required jars: (add to /lib/java)


Then you can use:

include javaDir["lib/java/*.jar"].each { |jar| require jar } the top of your class, and make SOAP calls until the cows come home! :)

Hope is helpful!