Skip to main content

Using Metro to talk to Amazon EC2

Posted by kohsuke on October 31, 2008 at 2:32 PM PDT

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:

<br />  <build><br />    ...<br />    <plugins><br />      <plugin><br />        <groupId>org.codehaus.mojo</groupId><br />        <artifactId>jaxws-maven-plugin</artifactId><br />        <executions><br />          <execution><br />            <goals><br />              <goal>wsimport</goal><br />            </goals><br />          </execution><br />        </executions><br />        <configuration><br />          <extension>true</extension><br />          ...<br />          <target>2.1</target><br />          <wsdlFiles><br />            <wsdlFile>ec2.wsdl</wsdlFile><br />          </wsdlFiles><br />          <xjcArgs><br />            <xjcArg>-Xfluent-api</xjcArg><br />          </xjcArgs><br />        </configuration><br />        <dependencies><br />          <dependency><br />            <groupId></groupId><br />            <artifactId>jaxws-tools</artifactId><br />            <version>2.1.3</version><br />          </dependency><br />          <dependency><br />            <groupId></groupId><br />            <artifactId>jaxb-fluent-api</artifactId><br />            <version>2.1.8</version><br />          </dependency><br />        </dependencies><br />      </plugin><br /><br />      <plugin><br />        <artifactId>maven-compiler-plugin</artifactId><br />        <configuration><br />          <source>1.5</source><br />          <target>1.5</target><br />        </configuration><br />      </plugin><br />    </plugins><br />  </build><br /><br />  <repositories><br />    <repository><br />      <id></id><br />      <url></url><br />      <layout>legacy</layout><br />    </repository><br />    <repository><br />      <id>java.net2</id><br />      <url></url><br />    </repository><br />  </repositories><br />  <br />

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.

Related Topics >>


Aron -- your question goes beyond what I can handle in this comment section. Please direct your question to

krystian_nowak -- Yes.

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 Nowak

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,

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 ,