Skip to main content

Calling a Metro Web Service from Clojure

Posted by haroldcarr on March 27, 2009 at 1:23 PM PDT

Here's how to call a
web service from

  1. Create and deploy a web service called "Test" with one "hello"
    method that takes and echoes a string (follow section 7 in the

    Metro Users Guide

    for creating a web service using
    or follow section 14 for using Ant.) Just create
    a vanilla service (i.e., no RM, Security, etc).
  2. This example assumes the service is deployed at
  3. Use


    to create the client side proxy:
    $JAVA_HOME/bin/wsimport -keep -p generated.test http://localhost:8080/Test/TestService?wsdl
  4. Put the location of generated.text in your classpath
    when starting up clojure.
  5. Start up clojure and enter this function definition
    after its prompt
    user> (defn hello [x]
            (let [service (generated.test.TestService.)
          port (. service getTestPort)]
      (. port hello x)))

  6. Then call it
    user> (hello "world")
    "from SERVICE: world"

That's it! Enjoy

ps: What's the purpose of Lots of Insipid Stupid Parenthesis?



I just tried a security example. I created a Mutual Certificates example server: Then I used NetBeans to create a web service client from the server's wsdl. I click on "Use Developer Defaults" in the "Edit Web Services" panel. Then I copied the results wsit-client.xml into the path for my client. The EXACT same code as my original entry worked. If I remove the wsit-client.xml from my classpath then I get an error from the security side saying the request is missing security headers - as it should. Bottom line: I can invoke a secure web service from a Clojure client.

I'm just starting to use Clojure, so don't know about any specific about Clojure + security. But Clojure, like other JVM-based languages, enables one to utilize existing Java code, so I don't anticipate there would be problems. Calling a secure web service from Clojure should work. What specific problems did you have?

I remember my joy calling web-services with Groovy few months ago.. pure pleasure until we decided to enable security on the service side .. Https in Groovy converted our "simple" code in a hell experiment.. how about clojure ? does it support secure (realistic) environments ?