Migrate Axis client to Axis2

This commit migrates the Airline client to Axis2.

The biggest problem was that Axis2 parses date differently and always
adds a timezone. As a result, the input string is no longer compliant
with ISO 8601. The server has been updated to tolerate both that format
and the one with a timezone attached.

The build is also simpler as it leverages the Axis2 wsdl2code maven
plugin, rather than calling wsdl2java via ant.

Closes gh-16
This commit is contained in:
Stéphane Nicoll
2025-03-14 16:16:40 +01:00
parent 50d79ccac1
commit e22a7833d6
11 changed files with 182 additions and 166 deletions

View File

@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-samples</artifactId>
<version>2.1.0-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<artifactId>airline-client-axis</artifactId>
<name>Spring Web Services Samples - Airline - Client - Axis</name>
<properties>
<generated-sources>${project.basedir}/target/generated-sources/axis</generated-sources>
<wsdl>${project.basedir}/../airline.wsdl</wsdl>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<executions>
<execution>
<id>wsdl2code</id>
<goals>
<goal>wsdl2code</goal>
</goals>
</execution>
</executions>
<configuration>
<generateServerSideInterface>true</generateServerSideInterface>
<namespaceURIs>
<namespaceURI>
<uri>http://www.springframework.org/spring-ws/samples/airline/definitions</uri>
<packageName>org.springframework.ws.samples.airline.client.axis</packageName>
</namespaceURI>
<namespaceURI>
<uri>http://www.springframework.org/spring-ws/samples/airline/schemas/messages</uri>
<packageName>org.springframework.ws.samples.airline.client.axis</packageName>
</namespaceURI>
<namespaceURI>
<uri>http://www.springframework.org/spring-ws/samples/airline/schemas/types</uri>
<packageName>org.springframework.ws.samples.airline.client.axis</packageName>
</namespaceURI>
</namespaceURIs>
<outputDirectory>${generated-sources}</outputDirectory>
<wsdlFile>${wsdl}</wsdlFile>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>process-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${generated-sources}/src</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -14,35 +14,39 @@
* limitations under the License.
*/
package org.springframework.ws.samples.airline.client.axis1;
package org.springframework.ws.samples.airline.client.axis;
import java.rmi.RemoteException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.xml.rpc.ServiceException;
import org.springframework.ws.samples.airline.client.axis.AirlineServiceStub.AirportCode;
import org.springframework.ws.samples.airline.client.axis.AirlineServiceStub.BookFlightRequest;
import org.springframework.ws.samples.airline.client.axis.AirlineServiceStub.BookFlightResponse;
import org.springframework.ws.samples.airline.client.axis.AirlineServiceStub.Flight;
import org.springframework.ws.samples.airline.client.axis.AirlineServiceStub.FrequentFlyerUsername;
import org.springframework.ws.samples.airline.client.axis.AirlineServiceStub.GetFlightsRequest;
import org.springframework.ws.samples.airline.client.axis.AirlineServiceStub.GetFlightsResponse;
import org.springframework.ws.samples.airline.client.axis.AirlineServiceStub.Name;
import org.springframework.ws.samples.airline.client.axis.AirlineServiceStub.PassengersChoice;
import org.springframework.ws.samples.airline.client.axis.AirlineServiceStub.Passengers_type0;
import org.springframework.ws.samples.airline.client.axis.AirlineServiceStub.Ticket;
/**
* Simple client that calls the <code>GetFlights</code> and <code>BookFlight</code>
* operations using JAX-RPC (Axis 1).
* operations using Axis 2 and HTTP.
*
* @author Arjen Poutsma
* @author Stephane Nicoll
*/
public class AxisMain {
public static void main(String[] args) throws ServiceException, RemoteException {
AirlineServiceLocator service = new AirlineServiceLocator();
if (args.length > 0) {
service.setAirlineSoap11EndpointAddress(args[0]);
}
Airline airline = service.getAirlineSoap11();
public static void main(String[] args) throws RemoteException {
AirlineServiceStub airline = (args.length > 0) ? new AirlineServiceStub(args[0]) : new AirlineServiceStub();
GetFlightsRequest request = new GetFlightsRequest();
request.setFrom("AMS");
request.setTo("VCE");
request.setFrom(createAirportCode("AMS"));
request.setTo(createAirportCode("VCE"));
Calendar departureCalendar = Calendar.getInstance();
departureCalendar.set(Calendar.YEAR, 2006);
departureCalendar.set(Calendar.MONTH, Calendar.JANUARY);
@@ -52,7 +56,8 @@ public class AxisMain {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
System.out.println("Requesting flights on " + dateFormat.format(departureDate));
Flight[] flights = airline.getFlights(request);
GetFlightsResponse flightsResponse = airline.getFlights(request);
Flight[] flights = flightsResponse.getFlight();
System.out.println("Got " + flights.length + " results");
@@ -61,23 +66,24 @@ public class AxisMain {
BookFlightRequest bookFlightRequest = new BookFlightRequest();
bookFlightRequest.setFlightNumber(flights[0].getNumber());
bookFlightRequest.setDepartureTime(flights[0].getDepartureTime());
BookFlightRequestPassengers passengers = new BookFlightRequestPassengers();
passengers.setUsername("john");
Passengers_type0 passengers = new Passengers_type0();
passengers.addPassengersChoice(createPassenger("john"));
bookFlightRequest.setPassengers(passengers);
Ticket ticket = airline.bookFlight(bookFlightRequest);
BookFlightResponse bookFlightResponse = airline.bookFlight(bookFlightRequest);
Ticket ticket = bookFlightResponse.getBookFlightResponse();
writeTicket(ticket);
}
}
private static void writeTicket(Ticket ticket) {
System.out.println("Ticket " + ticket.getId());
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
System.out.println("Ticket issue date:\t" + dateFormat.format(ticket.getIssueDate()));
for (int i = 0; i < ticket.getPassengers().length; i++) {
writeName(ticket.getPassengers()[i]);
Name[] passengers = ticket.getPassengers().getPassenger();
for (Name passenger : passengers) {
writeName(passenger);
}
writeFlight(ticket.getFlight());
}
@@ -103,4 +109,18 @@ public class AxisMain {
System.out.println("\t" + flight.getTo().getCity());
}
private static AirportCode createAirportCode(String code) {
AirportCode airportCode = new AirportCode();
airportCode.setAirportCode(code);
return airportCode;
}
private static PassengersChoice createPassenger(String username) {
PassengersChoice passenger = new PassengersChoice();
FrequentFlyerUsername frequentFlyerUsername = new FrequentFlyerUsername();
frequentFlyerUsername.setFrequentFlyerUsername(username);
passenger.setUsername(frequentFlyerUsername);
return passenger;
}
}

View File

@@ -1,121 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-samples</artifactId>
<version>2.1.0-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<artifactId>airline-client-axis1</artifactId>
<name>Spring Web Services Samples - Airline - Client - Axis1</name>
<properties>
<sourcesDir>${project.basedir}/target/generated-sources/axis</sourcesDir>
<classesDir>${project.basedir}/target/classes</classesDir>
<wsdl>${project.basedir}/../airline.wsdl</wsdl>
</properties>
<dependencies>
<dependency>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-jaxrpc</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<version>${axis.version}</version>
</dependency>
<dependency>
<groupId>axis</groupId>
<artifactId>axis-ant</artifactId>
<version>${axis.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>generate-sources</phase>
<configuration>
<target>
<taskdef name="axis-wsdl2java"
classname="org.apache.axis.tools.ant.wsdl.Wsdl2javaAntTask">
<classpath refid="maven.compile.classpath"/>
</taskdef>
<mkdir dir="${sourcesDir}"/>
<mkdir dir="${classesDir}"/>
<axis-wsdl2java
output="${sourcesDir}"
url="${wsdl}">
<mapping
namespace="http://www.springframework.org/spring-ws/samples/airline/definitions"
package="org.springframework.ws.samples.airline.client.axis1"/>
<mapping
namespace="http://www.springframework.org/spring-ws/samples/airline/schemas/messages"
package="org.springframework.ws.samples.airline.client.axis1"/>
<mapping
namespace="http://www.springframework.org/spring-ws/samples/airline/schemas/types"
package="org.springframework.ws.samples.airline.client.axis1"/>
</axis-wsdl2java>
<javac fork="true"
destdir="${classesDir}"
source="8" target="8" debug="true"
debugLevel="lines,vars,source">
<classpath refid="maven.compile.classpath"/>
<src path="${sourcesDir}"/>
<include name="**/*.java"/>
<include name="*.java"/>
</javac>
<copy todir="${classesDir}">
<fileset dir="${sourcesDir}"
erroronmissingdir="false">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>process-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${sourcesDir}</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -16,38 +16,52 @@
package org.springframework.ws.samples.airline.ws;
import static org.springframework.ws.samples.airline.ws.AirlineWebServiceConstants.*;
import jakarta.xml.bind.JAXBElement;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import jakarta.xml.bind.JAXBElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.ws.samples.airline.domain.FrequentFlyer;
import org.springframework.ws.samples.airline.domain.Passenger;
import org.springframework.ws.samples.airline.domain.ServiceClass;
import org.springframework.ws.samples.airline.schema.*;
import org.springframework.ws.samples.airline.schema.BookFlightRequest;
import org.springframework.ws.samples.airline.schema.GetFlightsResponse;
import org.springframework.ws.samples.airline.schema.Name;
import org.springframework.ws.samples.airline.schema.ObjectFactory;
import org.springframework.ws.samples.airline.schema.Ticket;
import org.springframework.ws.samples.airline.schema.support.SchemaConversionUtils;
import org.springframework.ws.samples.airline.service.AirlineService;
import org.springframework.ws.samples.airline.service.NoSeatAvailableException;
import org.springframework.ws.samples.airline.service.NoSuchFlightException;
import org.springframework.ws.samples.airline.service.NoSuchFrequentFlyerException;
import org.springframework.ws.server.endpoint.annotation.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.Namespace;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
import org.springframework.ws.server.endpoint.annotation.XPathParam;
import static org.springframework.ws.samples.airline.ws.AirlineWebServiceConstants.BOOK_FLIGHT_REQUEST;
import static org.springframework.ws.samples.airline.ws.AirlineWebServiceConstants.GET_FLIGHTS_REQUEST;
import static org.springframework.ws.samples.airline.ws.AirlineWebServiceConstants.GET_FREQUENT_FLYER_MILEAGE_REQUEST;
import static org.springframework.ws.samples.airline.ws.AirlineWebServiceConstants.GET_FREQUENT_FLYER_MILEAGE_RESPONSE;
import static org.springframework.ws.samples.airline.ws.AirlineWebServiceConstants.MESSAGES_NAMESPACE;
/**
* Endpoint that handles the Airline Web Service messages using a combination of JAXB2
@@ -60,6 +74,8 @@ public class AirlineEndpoint {
private static final Logger logger = LoggerFactory.getLogger(AirlineEndpoint.class);
private static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd[XXX][X]");
private final ObjectFactory objectFactory = new ObjectFactory();
private final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
@@ -91,7 +107,8 @@ public class AirlineEndpoint {
logger.debug("Received GetFlightsRequest '" + from + "' to '" + to + "' on " + departureDateString);
}
ZonedDateTime departureDate = LocalDate.parse(departureDateString).atStartOfDay(ZoneId.systemDefault());
ZonedDateTime departureDate = LocalDate.parse(departureDateString, dateFormatter)
.atStartOfDay(ZoneId.systemDefault());
ServiceClass serviceClass = null;
if (StringUtils.hasLength(serviceClassString)) {

29
pom.xml
View File

@@ -32,7 +32,8 @@
<classesDir>${project.basedir}/target/classes</classesDir>
<wsdl>${project.basedir}/airline/client/airline.wsdl</wsdl>
<axis.version>1.4</axis.version>
<axis.version>2.0.0</axis.version>
<axis2-wsdl2code-maven-plugin>1.7.9</axis2-wsdl2code-maven-plugin>
<jaxb2-maven-plugin.version>3.2.0</jaxb2-maven-plugin.version>
<jaxb30-maven-plugin.version>0.15.0</jaxb30-maven-plugin.version>
<jaxen.version>1.2.0</jaxen.version>
@@ -46,7 +47,7 @@
</properties>
<modules>
<module>airline/client/axis1</module>
<module>airline/client/axis</module>
<module>airline/client/jax-ws</module>
<module>airline/client/jms</module>
<module>airline/client/saaj</module>
@@ -62,11 +63,6 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<version>${axis.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-tools</artifactId>
@@ -83,8 +79,18 @@
<version>${jaxen.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-jaxrpc</artifactId>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
<version>${axis.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>${axis.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>${axis.version}</version>
</dependency>
<dependency>
@@ -118,6 +124,11 @@
<artifactId>jaxws-maven-plugin</artifactId>
<version>${jaxws-maven-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>${axis2-wsdl2code-maven-plugin}</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>