Using Metro to talk to Amazon EC2
Amazon EC2 has a SOAP web service, and I wanted to talk to EC2 from Hudson, so I decided to use Metro for this. The end result is the JAX-WS commons EC2 module, which is a library you can put in your classpath with Metro 1.4 when you need to talk to EC2.
EC2 SOAP API is pretty straight-forward except one caveat — you need to sign the whole request, but their WSDL doesn't say so in a machine readable way (that is, by using WS-Policy.) Had they put a proper policy declaration, tools like Metro would be able to hide the whole thing behind the scene, but because they didn't, I had to manually configure Metro a bit to get this working. Basically, this amounts to manually putting the corresponding policy element in WSDL (which is not a very pleasant experience, I have to say, unless you use NetBeans to have it generated for you.)
I also added JAXB fluent API plugin when compiling WSDL, so that the calling application has an easier type building a tree of JAXB objects when sending a request. I think this is very useful with almost any JAX-WS compilation, so here's the POM snippet you can copy into your POM to do this in any other JAX-WS compilation:
<xmp>
<build>
...
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<extension>true</extension>
...
<target>2.1</target>
<wsdlFiles>
<wsdlFile>ec2.wsdl</wsdlFile>
</wsdlFiles>
<xjcArgs>
<xjcArg>-Xfluent-api</xjcArg>
</xjcArgs>
</configuration>
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>net.java.dev.jaxb2-commons</groupId>
<artifactId>jaxb-fluent-api</artifactId>
<version>2.1.8</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>java.net</id>
<url>http://download.java.net/maven/1</url>
<layout>legacy</layout>
</repository>
<repository>
<id>java.net2</id>
<url>http://download.java.net/maven/2</url>
</repository>
</repositories>
</xmp>
In any case, all these work is done by me and the generated interfaces and JAXB beans are packaged up in a jar file, so you just need to depend on this from your Maven POM or download the jar and put it in your classpath to use this.
- Login or register to post comments
- Printer-friendly version
- kohsuke's blog
- 1403 reads






Comments
by kohsuke - 2008-12-10 12:21
Aron -- your question goes beyond what I can handle in this comment section. Please direct your question to users@jaxb.dev.java.net.krystian_nowak -- Yes.
by krystian_nowak - 2008-12-10 11:30
Does "talking to EC2 from Hudson" means you are planning to release a plugin to fire builds on EC2 instances or maybe launch an instance before starting a build and shut it down when finished? Kind regards, Krystian Nowakby aronolsen - 2008-10-31 22:03
As of 5): It relates to the "interface" problem.. Say: 1) I have a general datamodel, un/marshable, but not in it self. 2) I want to "attach" custom-implementations to my model. 3) It's impossible. I realized. Now adays I have th options: A) Clone my model for each project B) Make provisions for, that every project exists whithin my code-base. Can You see my problem? Respect, Aron,by aronolsen - 2008-10-31 21:40
Dear Sir (Kohsuke), I'm not in the all above. I'm pretty much down to earth, and doing Java all the time. In respect of JAXB I am a "from-java" guy. As such, I want to give some feeed-back (I'm on JAXB 2.1.8 currently), please: 1) Why is it, that I can't control the ordering of XML-attributes? 2) Why is it, that I can't control the default value of XML-attributes? 3) Why is it, that I can't control the "REQUIRED" property of an attribute? 4) Why is it, that JAXB produces <... att=""/> when there is no value for the attribute (i.e. empty string)? 5) Why don't you have any support for "dynamic" binding. At least, you could provide for "out-of-package" package-annotations? Nevertheless, its Great, and I'm strait back into "POJO". Best, Aron. Best, Aron ,