Die Intersult liefert die wohl führenden XML- und SOAP-Werkzeuge im Java-Bereich. Das XML-Paket kann unter Maven 2 direkt aus dem Intersult Maven Repository integriert werden.
Simply add the plugin repository to your pom.xml to allow Maven download the plugin:
<project>
...
<pluginRepositories>
...
<pluginRepository>
<id>intersult-repository</id>
<name>Intersult Repository</name>
<url>http://repository.intersult.com/repository</url>
</pluginRepository>
...
</pluginRepositories>
...
</project>
Neben primitiven Datentypen und verschachtelten Typen serialisiert der Marshaller auch Arrays, Lists und Maps.
Der XmlUnmarshaller wandelt serialisierte XML-Dateien zurück in Java-Klassen. Das Unmarshalling ist dabei genauso unkompliziert wie das Marshalling. Pojos sind ausreichend, mit Annotationen können zusätzliche Features gesteuert werden.
Folgendes Code-Beispiel zeigt einen Unmarshal-Marshal-Roundtrip:
String stringInput = IOUtils.toString(getClass().getResourceAsStream("Foo.xml"));
Foo foo = (Foo)MarshalUtils.unmarshall(stringInput);
String stringOutput = MarshalUtils.marshall(foo);
Mit Foo.xml:
<?xml version="1.0" encoding="UTF8"?> <com.intersult.xml.Foo value="Ein Wert"/>
und Foo.java:
package com.intersult.xml;
public class Foo {
private String value;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
Ein weiteres Beispiel für Unmarshalling:
String input = "Test";
String xml = "<java.lang.String>" + input + "</java.lang.String>";
String output = (String)MarshalUtils.unmarshall(xml);
Der WSDL-Generator verwendet intern den Intersult Xsd-Generator.
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>com.intersult</groupId>
<artifactId>com.intersult.maven</artifactId>
<executions>
<execution>
<goals>
<goal>generate-ws</goal>
</goals>
<configuration>
<services>
<service>
<outputPath>${project.build.directory}/generated/weather</outputPath>
<wsdl>http://www.webservicex.net/globalweather.asmx?WSDL</wsdl>
<packageName>net.webservicex.globalweather</packageName>
</service>
</services>
</configuration>
</execution>
</executions>
</plugin>
...
</plugin>
...
</build>
...
</project>
Der Global Weather Service generiert einen Service, der durch folgenden Code ansprechbar ist:
GetWeatherResponse weather = new GlobalWeatherSoap().getWeather("nuernberg", "germany");
System.out.println(weather.getGetWeatherResult());