Calling a Metro Web Service from Clojure
Posted by haroldcarr on March 27, 2009 at 4:23 PM EDT
Here's how to call a Metro-based web service from Clojure.
- 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 NetBeans or follow section 14 for using Ant.) Just create a vanilla service (i.e., no RM, Security, etc).
- This example assumes the service is deployed at
http://localhost:8080/Test/TestService. - Use
wsimport
to create the client side proxy:
$JAVA_HOME/bin/wsimport -keep -p generated.test http://localhost:8080/Test/TestService?wsdl
- Put the location of
generated.textin your classpath when starting up clojure. - 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))) #'user/hello - Then call it
user> (hello "world") "from SERVICE: world"
That's it! Enjoy
ps: What's the purpose of Lots of Insipid Stupid Parenthesis? MACROS!
Technorati: clojure projectmetro glassfish netbeans wsit
Blog Links >>
- Login or register to post comments
- Printer-friendly version
- haroldcarr's blog
- 1686 reads






Comments
by haroldcarr - 2009-03-30 16:04
I just tried a security example. I created a Mutual Certificates example server: https://metro.dev.java.net/guide/Example_Applications.html#ahiem 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.by haroldcarr - 2009-03-30 12:29
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?by felipegaucho - 2009-03-30 02:22
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 ?