This is my Blog.

It's full of opinions on a wide range of stuff.

How To Fix Generating XMPie API Java Stubs With Metro

As a number of you are aware, I have spent quite a bit of time wrestling with XMPie uProduce SOAP API with the CXF service framework in Java. I finally (and with quite a lot of disappointment on my part) gave up trying to get that to work. CXF just does not want to play nice and I cant seem to make the XJB bindings work correctly with it and the mish-mash WSDL coming from uProduce

Anyway... with that rant over, I tried to be objective and switched to using Metro - ok, out of the box I still had a whole heap of problems, exactly as I did with CXF. However, I have managed to wangle it!

Step 1

You will need access to an XMPie server with the API's installed and working. For the sake of this example i just wget'd the WSDL file so the generation code was not so bloated.

Step 2

You'll need an XSD XJB binding file which looks like this:

<bindings xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="2.0">

  <globalbindings>
    <xjc:simple></xjc:simple>
  </globalbindings>

  <bindings scd="~xsd:complexType">
    <class name="ComplexTypeType"></class>
  </bindings>

  <bindings scd="~xsd:simpleType">
    <class name="SimpleTypeType"></class>
  </bindings>

  <bindings scd="~xsd:group">
    <class name="GroupType"></class>
  </bindings>

  <bindings scd="~xsd:attributeGroup">
    <class name="AttributeGroupType"></class>
  </bindings>

  <bindings scd="~xsd:element">
    <class name="ElementType"></class>
  </bindings>

  <bindings scd="~xsd:attribute">
    <class name="attributeType"></class>
  </bindings>
</bindings>

Save this as xsd.xjb (or whatever you like, just make sure the name is reflected in the command below)

Step 3

Actually generate the code! Your command might look different, but heres mine:

  wsimport -b http://www.w3.org/2001/XMLSchema.xsd \
    -b src/xjb/xsd.xjb \
    -keep \
    -s src/java \
    -d target \
    -p com.xmpie.wsapi.icp \
    src/wsdl/InteractiveCampaign_SSP.wsdl

You should then see something like the following in your finder (or other OS file browser if not on mac):

These are the class files created for the InteractiveCampaign WSDL - all 128 of them!

Anyway, I have run out of time for today, but will try and get another blog up soon about how to use this in a client application from a java CLI.

blog comments powered by Disqus