Friday, August 17, 2012

XJC XmlRootElement and SOAPAction, WebServiceTemplate spring-ws

If you want to create client stubs by means of spring-ws and you do not have the notation of the @Endpoint and @Payload definitions it is sometimes problematic getting the right SOAPAction and XmlRootElement defined.

The first try you can generate with the xjc:simple binding
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
version="2.0" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:annox="http://annox.dev.java.net"
jaxb:extensionBindingPrefixes="xjc annox">
<jaxb:globalBindings>
 <xjc:simple />
</jaxb:globalBindings>
 
<!-- FILE: PickupAudit.xsd --> 

 <jaxb:bindings schemaLocation="PickupAudit.xsd" node="/xs:schema">
   <jaxb:bindings node="xs:complexType[@name='PickupAudit']">
      <annox:annotate>
    <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="PickupAudit" />
      </annox:annotate>
    </jaxb:bindings>
   <jaxb:bindings node="xs:complexType[@name='PickupAuditType']">
      <annox:annotate>
    <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="PickupAudit" />
      </annox:annotate>
    </jaxb:bindings>
  </jaxb:bindings>

</jaxb:bindings>


Generating the @XmlRootElement("something")
<plugin>
 <groupId>org.jvnet.jaxb2.maven2</groupId>
 <artifactId>maven-jaxb2-plugin</artifactId>
 <version>0.7.4</version>
 <executions>
  <execution>
   <id>generate-domain1</id>
   <goals>
    <goal>generate</goal>
   </goals>
   <configuration>
    <strict>true</strict>
    <schemaDirectory>src/main/schema</schemaDirectory>
    <schemaIncludes>
     <value>*.xsd</value>
    </schemaIncludes>
    <bindingIncludes>
     <include>bindings.xjb</include>
    </bindingIncludes>
    <verbose>true</verbose>
    <extension>true</extension>
    <args>
     <arg>-Xannotate</arg>
    </args>
    <generateDirectory>${project.build.directory}/generated-sources/xjc</generateDirectory>
    <plugins>
     <plugin>
      <groupId>org.jvnet.jaxb2_commons</groupId>
      <artifactId>jaxb2-basics</artifactId>
      <version>0.6.0</version>
     </plugin>
     <plugin>
      <groupId>org.jvnet.jaxb2_commons</groupId>
      <artifactId>jaxb2-basics-annotate</artifactId>
      <version>0.6.0</version>
     </plugin>
    </plugins>
   </configuration>
  </execution>
 </executions>
</plugin>

No comments:

Post a Comment