Updating Airline sample.
This commit is contained in:
@@ -122,7 +122,7 @@ public abstract class WebServiceGatewaySupport implements InitializingBean {
|
|||||||
*
|
*
|
||||||
* @see org.springframework.ws.client.core.WebServiceTemplate#marshalSendAndReceive
|
* @see org.springframework.ws.client.core.WebServiceTemplate#marshalSendAndReceive
|
||||||
*/
|
*/
|
||||||
public void setMarshaller(Marshaller marshaller) {
|
public final void setMarshaller(Marshaller marshaller) {
|
||||||
webServiceTemplate.setMarshaller(marshaller);
|
webServiceTemplate.setMarshaller(marshaller);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
11
samples/airline/client/build.xml
Normal file
11
samples/airline/client/build.xml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<project name="spring-ws-airline-sample-clients" default="run-all">
|
||||||
|
|
||||||
|
<target name="run-all">
|
||||||
|
<ant dir="axis1" target="run"/>
|
||||||
|
<ant dir="jax-ws" target="run"/>
|
||||||
|
<ant dir="saaj" target="run"/>
|
||||||
|
<ant dir="spring-ws" target="run"/>
|
||||||
|
</target>
|
||||||
|
</project>
|
||||||
|
|
||||||
Binary file not shown.
@@ -13,6 +13,7 @@
|
|||||||
//
|
//
|
||||||
namespace Spring.Ws.Samples.Airline.Client.CSharp {
|
namespace Spring.Ws.Samples.Airline.Client.CSharp {
|
||||||
|
|
||||||
|
|
||||||
/// <remarks/>
|
/// <remarks/>
|
||||||
[System.Web.Services.WebServiceBinding(Name="AirlinePort", Namespace="http://www.springframework.org/spring-ws/samples/airline/definitions")]
|
[System.Web.Services.WebServiceBinding(Name="AirlinePort", Namespace="http://www.springframework.org/spring-ws/samples/airline/definitions")]
|
||||||
[System.Diagnostics.DebuggerStepThroughAttribute()]
|
[System.Diagnostics.DebuggerStepThroughAttribute()]
|
||||||
@@ -26,7 +27,7 @@ namespace Spring.Ws.Samples.Airline.Client.CSharp {
|
|||||||
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.springframework.org/spring-ws/samples/airline/GetFlights", ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare, Use=System.Web.Services.Description.SoapBindingUse.Literal)]
|
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.springframework.org/spring-ws/samples/airline/GetFlights", ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare, Use=System.Web.Services.Description.SoapBindingUse.Literal)]
|
||||||
[return: System.Xml.Serialization.XmlArray(ElementName="GetFlightsResponse", Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
[return: System.Xml.Serialization.XmlArray(ElementName="GetFlightsResponse", Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
||||||
[return: System.Xml.Serialization.XmlArrayItem(ElementName="flight", IsNullable=false)]
|
[return: System.Xml.Serialization.XmlArrayItem(ElementName="flight", IsNullable=false)]
|
||||||
public Flight[] GetFlights([System.Xml.Serialization.XmlElement(Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")] MessageGetFlightsRequest GetFlightsRequest) {
|
public Flight[] GetFlights([System.Xml.Serialization.XmlElementAttribute(Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")] MessageGetFlightsRequest GetFlightsRequest) {
|
||||||
object[] results = this.Invoke("GetFlights", new object[] {
|
object[] results = this.Invoke("GetFlights", new object[] {
|
||||||
GetFlightsRequest});
|
GetFlightsRequest});
|
||||||
return ((Flight[])(results[0]));
|
return ((Flight[])(results[0]));
|
||||||
@@ -43,8 +44,8 @@ namespace Spring.Ws.Samples.Airline.Client.CSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.springframework.org/spring-ws/samples/airline/BookFlight", ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare, Use=System.Web.Services.Description.SoapBindingUse.Literal)]
|
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.springframework.org/spring-ws/samples/airline/BookFlight", ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare, Use=System.Web.Services.Description.SoapBindingUse.Literal)]
|
||||||
[return: System.Xml.Serialization.XmlElement("BookFlightResponse", Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
[return: System.Xml.Serialization.XmlElementAttribute("BookFlightResponse", Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
||||||
public Ticket BookFlight([System.Xml.Serialization.XmlElement(Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")] MessageBookFlightRequest BookFlightRequest) {
|
public Ticket BookFlight([System.Xml.Serialization.XmlElementAttribute(Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")] MessageBookFlightRequest BookFlightRequest) {
|
||||||
object[] results = this.Invoke("BookFlight", new object[] {
|
object[] results = this.Invoke("BookFlight", new object[] {
|
||||||
BookFlightRequest});
|
BookFlightRequest});
|
||||||
return ((Ticket)(results[0]));
|
return ((Ticket)(results[0]));
|
||||||
@@ -61,8 +62,8 @@ namespace Spring.Ws.Samples.Airline.Client.CSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.springframework.org/spring-ws/samples/airline/GetFrequentFlyerMileage", ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare, Use=System.Web.Services.Description.SoapBindingUse.Literal)]
|
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.springframework.org/spring-ws/samples/airline/GetFrequentFlyerMileage", ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare, Use=System.Web.Services.Description.SoapBindingUse.Literal)]
|
||||||
[return: System.Xml.Serialization.XmlElement("GetFrequentFlyerMileageResponse", Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
[return: System.Xml.Serialization.XmlElementAttribute("GetFrequentFlyerMileageResponse", Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
||||||
public int GetFrequentFlyerMileage([System.Xml.Serialization.XmlElement(Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")] object GetFrequentFlyerMileageRequest) {
|
public int GetFrequentFlyerMileage([System.Xml.Serialization.XmlElementAttribute(Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")] object GetFrequentFlyerMileageRequest) {
|
||||||
object[] results = this.Invoke("GetFrequentFlyerMileage", new object[] {
|
object[] results = this.Invoke("GetFrequentFlyerMileage", new object[] {
|
||||||
GetFrequentFlyerMileageRequest});
|
GetFrequentFlyerMileageRequest});
|
||||||
return ((int)(results[0]));
|
return ((int)(results[0]));
|
||||||
@@ -80,8 +81,8 @@ namespace Spring.Ws.Samples.Airline.Client.CSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <remarks/>
|
/// <remarks/>
|
||||||
[System.Xml.Serialization.XmlType(Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
||||||
[System.Xml.Serialization.XmlRoot("GetFlightsRequest", Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
[System.Xml.Serialization.XmlRootAttribute("GetFlightsRequest", Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
||||||
public class MessageGetFlightsRequest {
|
public class MessageGetFlightsRequest {
|
||||||
|
|
||||||
/// <remarks/>
|
/// <remarks/>
|
||||||
@@ -91,7 +92,7 @@ namespace Spring.Ws.Samples.Airline.Client.CSharp {
|
|||||||
public string to;
|
public string to;
|
||||||
|
|
||||||
/// <remarks/>
|
/// <remarks/>
|
||||||
[System.Xml.Serialization.XmlElement(DataType="date")]
|
[System.Xml.Serialization.XmlElementAttribute(DataType="date")]
|
||||||
public System.DateTime departureDate;
|
public System.DateTime departureDate;
|
||||||
|
|
||||||
/// <remarks/>
|
/// <remarks/>
|
||||||
@@ -117,7 +118,7 @@ namespace Spring.Ws.Samples.Airline.Client.CSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <remarks/>
|
/// <remarks/>
|
||||||
[System.Xml.Serialization.XmlType(Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
||||||
public class Flight {
|
public class Flight {
|
||||||
|
|
||||||
/// <remarks/>
|
/// <remarks/>
|
||||||
@@ -140,7 +141,7 @@ namespace Spring.Ws.Samples.Airline.Client.CSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <remarks/>
|
/// <remarks/>
|
||||||
[System.Xml.Serialization.XmlType(Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
||||||
public class Airport {
|
public class Airport {
|
||||||
|
|
||||||
/// <remarks/>
|
/// <remarks/>
|
||||||
@@ -154,8 +155,8 @@ namespace Spring.Ws.Samples.Airline.Client.CSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <remarks/>
|
/// <remarks/>
|
||||||
[System.Xml.Serialization.XmlType(Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
||||||
[System.Xml.Serialization.XmlRoot("BookFlightRequest", Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
[System.Xml.Serialization.XmlRootAttribute("BookFlightRequest", Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
||||||
public class MessageBookFlightRequest {
|
public class MessageBookFlightRequest {
|
||||||
|
|
||||||
/// <remarks/>
|
/// <remarks/>
|
||||||
@@ -171,7 +172,7 @@ namespace Spring.Ws.Samples.Airline.Client.CSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <remarks/>
|
/// <remarks/>
|
||||||
[System.Xml.Serialization.XmlType(Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
||||||
public class Name {
|
public class Name {
|
||||||
|
|
||||||
/// <remarks/>
|
/// <remarks/>
|
||||||
@@ -182,15 +183,15 @@ namespace Spring.Ws.Samples.Airline.Client.CSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <remarks/>
|
/// <remarks/>
|
||||||
[System.Xml.Serialization.XmlType(Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
||||||
[System.Xml.Serialization.XmlRoot("BookFlightResponse", Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
[System.Xml.Serialization.XmlRootAttribute("BookFlightResponse", Namespace="http://www.springframework.org/spring-ws/samples/airline/schemas")]
|
||||||
public class Ticket {
|
public class Ticket {
|
||||||
|
|
||||||
/// <remarks/>
|
/// <remarks/>
|
||||||
public long id;
|
public long id;
|
||||||
|
|
||||||
/// <remarks/>
|
/// <remarks/>
|
||||||
[System.Xml.Serialization.XmlElement(DataType="date")]
|
[System.Xml.Serialization.XmlElementAttribute(DataType="date")]
|
||||||
public System.DateTime issueDate;
|
public System.DateTime issueDate;
|
||||||
|
|
||||||
/// <remarks/>
|
/// <remarks/>
|
||||||
@@ -200,5 +201,4 @@ namespace Spring.Ws.Samples.Airline.Client.CSharp {
|
|||||||
/// <remarks/>
|
/// <remarks/>
|
||||||
public Flight flight;
|
public Flight flight;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace Spring.Ws.Samples.Airline.Client.CSharp {
|
|||||||
if (args.Length > 0) {
|
if (args.Length > 0) {
|
||||||
service.Url = args[0];
|
service.Url = args[0];
|
||||||
} else {
|
} else {
|
||||||
service.Url = "http://localhost:8080/airline/Airline";
|
service.Url = "http://localhost:8080/airline/services";
|
||||||
}
|
}
|
||||||
// Get all flights on 31st Januari, 2006 from Amsterdam to Venice
|
// Get all flights on 31st Januari, 2006 from Amsterdam to Venice
|
||||||
MessageGetFlightsRequest getFlightsRequest = new MessageGetFlightsRequest();
|
MessageGetFlightsRequest getFlightsRequest = new MessageGetFlightsRequest();
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
SPRING WEB SERVICES
|
SPRING WEB SERVICES
|
||||||
|
|
||||||
|
All clients can be run from the provided ant file, by calling "ant run-all".
|
||||||
|
|
||||||
Client table of contents
|
Client table of contents
|
||||||
---------------------------------------------------
|
---------------------------------------------------
|
||||||
|
* build.xml - Ant build file with a 'run-all' target
|
||||||
* axis1 - A client for the airline service written in Java using JAX-RPC (Axis 1).
|
* axis1 - A client for the airline service written in Java using JAX-RPC (Axis 1).
|
||||||
* cs - A client for the airline service written in C#.
|
* cs - A client for the airline service written in C#.
|
||||||
* jax-ws - A client for the airline service written in Java using JAX-WS.
|
* jax-ws - A client for the airline service written in Java using JAX-WS.
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ public class GetFlights {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
String url = "http://localhost:8080/airline/Airline";
|
String url = "http://localhost:8080/airline/services";
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
url = args[0];
|
url = args[0];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,10 +69,8 @@ public class GetFrequentFlyerMileage {
|
|||||||
|
|
||||||
private SOAPMessage createGetMileageRequest() throws SOAPException {
|
private SOAPMessage createGetMileageRequest() throws SOAPException {
|
||||||
SOAPMessage message = messageFactory.createMessage();
|
SOAPMessage message = messageFactory.createMessage();
|
||||||
message.getMimeHeaders().addHeader("SOAPAction",
|
|
||||||
"\"http://www.springframework.org/spring-ws/samples/airline/GetFrequentFlyerMileage\"");
|
|
||||||
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
|
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
|
||||||
Name getFlightsRequestName = envelope.createName("GetFrequentFlyerMileage", GetFrequentFlyerMileage.PREFIX,
|
Name getFlightsRequestName = envelope.createName("GetFrequentFlyerMileageRequest", GetFrequentFlyerMileage.PREFIX,
|
||||||
GetFrequentFlyerMileage.NAMESPACE_URI);
|
GetFrequentFlyerMileage.NAMESPACE_URI);
|
||||||
message.getSOAPBody().addBodyElement(getFlightsRequestName);
|
message.getSOAPBody().addBodyElement(getFlightsRequestName);
|
||||||
return message;
|
return message;
|
||||||
@@ -130,7 +128,7 @@ public class GetFrequentFlyerMileage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
String url = "http://localhost:8080/airline/Airline";
|
String url = "http://localhost:8080/airline/services";
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
System.err.println(
|
System.err.println(
|
||||||
"Usage: java org.springframework.ws.samples.airline.client.saaj.GetFrequentFlyerMileage " +
|
"Usage: java org.springframework.ws.samples.airline.client.saaj.GetFrequentFlyerMileage " +
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<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/maven-v4_0_0.xsd">
|
<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/maven-v4_0_0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>spring-ws-samples</artifactId>
|
<artifactId>spring-ws-samples</artifactId>
|
||||||
<groupId>org.springframework.ws</groupId>
|
<groupId>org.springframework.ws</groupId>
|
||||||
@@ -8,7 +10,19 @@
|
|||||||
<artifactId>airline</artifactId>
|
<artifactId>airline</artifactId>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<name>Spring WS Airline Sample</name>
|
<name>Spring WS Airline Sample</name>
|
||||||
|
<reporting>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<stylesheetfile>${basedir}/../../src/main/javadoc/javadoc.css</stylesheetfile>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</reporting>
|
||||||
<profiles>
|
<profiles>
|
||||||
|
<!-- These three profiles represent the three databases supported by this sample. Refer to the readme.txt
|
||||||
|
to see how to use them -->
|
||||||
<profile>
|
<profile>
|
||||||
<id>hsqldb</id>
|
<id>hsqldb</id>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -23,10 +37,10 @@
|
|||||||
<!-- Change these properties to reflect your HSQLDB connection settings -->
|
<!-- Change these properties to reflect your HSQLDB connection settings -->
|
||||||
<jdbc.driverClassName>org.hsqldb.jdbcDriver</jdbc.driverClassName>
|
<jdbc.driverClassName>org.hsqldb.jdbcDriver</jdbc.driverClassName>
|
||||||
<jdbc.username>sa</jdbc.username>
|
<jdbc.username>sa</jdbc.username>
|
||||||
<jdbc.password />
|
<jdbc.password/>
|
||||||
<jdbc.url>jdbc:hsqldb:hsql://localhost/airline</jdbc.url>
|
<jdbc.url>jdbc:hsqldb:hsql://localhost/airline</jdbc.url>
|
||||||
<hibernate.dialect>org.hibernate.dialect.HSQLDialect</hibernate.dialect>
|
<hibernate.dialect>org.hibernate.dialect.HSQLDialect</hibernate.dialect>
|
||||||
<hibernate.hbm2ddl.auto />
|
<hibernate.hbm2ddl.auto/>
|
||||||
</properties>
|
</properties>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
@@ -70,7 +84,7 @@
|
|||||||
<jdbc.password>airline</jdbc.password>
|
<jdbc.password>airline</jdbc.password>
|
||||||
<jdbc.url>jdbc:mysql://localhost/airline</jdbc.url>
|
<jdbc.url>jdbc:mysql://localhost/airline</jdbc.url>
|
||||||
<hibernate.dialect>org.hibernate.dialect.MySQLInnoDBDialect</hibernate.dialect>
|
<hibernate.dialect>org.hibernate.dialect.MySQLInnoDBDialect</hibernate.dialect>
|
||||||
<hibernate.hbm2ddl.auto />
|
<hibernate.hbm2ddl.auto/>
|
||||||
</properties>
|
</properties>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
@@ -114,7 +128,7 @@
|
|||||||
<jdbc.password>airline</jdbc.password>
|
<jdbc.password>airline</jdbc.password>
|
||||||
<jdbc.url>jdbc:postgresql://localhost/airline</jdbc.url>
|
<jdbc.url>jdbc:postgresql://localhost/airline</jdbc.url>
|
||||||
<hibernate.dialect>org.hibernate.dialect.PostgreSQLDialect</hibernate.dialect>
|
<hibernate.dialect>org.hibernate.dialect.PostgreSQLDialect</hibernate.dialect>
|
||||||
<hibernate.hbm2ddl.auto />
|
<hibernate.hbm2ddl.auto/>
|
||||||
</properties>
|
</properties>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
@@ -148,11 +162,19 @@
|
|||||||
The following values are for using an in-memory database, which is used for testing -->
|
The following values are for using an in-memory database, which is used for testing -->
|
||||||
<jdbc.driverClassName>org.hsqldb.jdbcDriver</jdbc.driverClassName>
|
<jdbc.driverClassName>org.hsqldb.jdbcDriver</jdbc.driverClassName>
|
||||||
<jdbc.username>sa</jdbc.username>
|
<jdbc.username>sa</jdbc.username>
|
||||||
<jdbc.password />
|
<jdbc.password/>
|
||||||
<jdbc.url>jdbc:hsqldb:mem:airline</jdbc.url>
|
<jdbc.url>jdbc:hsqldb:mem:airline</jdbc.url>
|
||||||
<hibernate.dialect>org.hibernate.dialect.HSQLDialect</hibernate.dialect>
|
<hibernate.dialect>org.hibernate.dialect.HSQLDialect</hibernate.dialect>
|
||||||
<hibernate.hbm2ddl.auto>create-drop</hibernate.hbm2ddl.auto>
|
<hibernate.hbm2ddl.auto>create-drop</hibernate.hbm2ddl.auto>
|
||||||
</properties>
|
</properties>
|
||||||
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>java.net</id>
|
||||||
|
<name>Java.net Repository for Maven2</name>
|
||||||
|
<url>http://download.java.net/maven/1/</url>
|
||||||
|
<layout>legacy</layout>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
<build>
|
<build>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
@@ -173,23 +195,27 @@
|
|||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-antrun-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>1.5</source>
|
||||||
|
<target>1.5</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.sun.tools.xjc.maven2</groupId>
|
||||||
|
<artifactId>maven-jaxb-plugin</artifactId>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>generate-sources</phase>
|
<phase>generate-sources</phase>
|
||||||
<configuration>
|
|
||||||
<tasks>
|
|
||||||
<ant antfile="${basedir}/build-maven2.xml" inheritRefs="true">
|
|
||||||
<target name="generate-sources" />
|
|
||||||
</ant>
|
|
||||||
</tasks>
|
|
||||||
<sourceRoot>${project.build.directory}/generated-sources/main/java</sourceRoot>
|
|
||||||
</configuration>
|
|
||||||
<goals>
|
<goals>
|
||||||
<goal>run</goal>
|
<goal>generate</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<generatePackage>org.springframework.ws.samples.airline.schema</generatePackage>
|
||||||
|
<schemaDirectory>src/main/webapp/WEB-INF/xsd</schemaDirectory>
|
||||||
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
@@ -201,11 +227,11 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.ws</groupId>
|
<groupId>org.springframework.ws</groupId>
|
||||||
<artifactId>spring-ws-core</artifactId>
|
<artifactId>spring-ws-core-tiger</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.ws</groupId>
|
<groupId>org.springframework.ws</groupId>
|
||||||
<artifactId>spring-oxm</artifactId>
|
<artifactId>spring-oxm-tiger</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.ws</groupId>
|
<groupId>org.springframework.ws</groupId>
|
||||||
@@ -224,7 +250,8 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-hibernate3</artifactId>
|
<artifactId>spring-jpa</artifactId>
|
||||||
|
<version>${spring.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
@@ -238,6 +265,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-mock</artifactId>
|
<artifactId>spring-mock</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- XML handling dependencies -->
|
<!-- XML handling dependencies -->
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -276,37 +304,34 @@
|
|||||||
<artifactId>xalan</artifactId>
|
<artifactId>xalan</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- JEE dependencies -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>servlet-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>taglibs</groupId>
|
||||||
|
<artifactId>standard</artifactId>
|
||||||
|
<version>1.1.2</version>
|
||||||
|
</dependency>
|
||||||
<!-- O/X Mapping dependencies -->
|
<!-- O/X Mapping dependencies -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.xml.bind</groupId>
|
<groupId>javax.xml.bind</groupId>
|
||||||
<artifactId>jaxb-api</artifactId>
|
<artifactId>jaxb-api</artifactId>
|
||||||
<version>1.0</version>
|
<version>2.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sun.xml.bind</groupId>
|
<groupId>com.sun.xml.bind</groupId>
|
||||||
<artifactId>jaxb-impl</artifactId>
|
<artifactId>jaxb-impl</artifactId>
|
||||||
<version>1.0.6</version>
|
<version>2.1.3</version>
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.sun.xml.bind</groupId>
|
|
||||||
<artifactId>jaxb-libs</artifactId>
|
|
||||||
<version>1.0.6</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.sun.xml.bind</groupId>
|
|
||||||
<artifactId>jaxb-xjc</artifactId>
|
|
||||||
<version>1.0.6</version>
|
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.sun.msv.datatype.xsd</groupId>
|
|
||||||
<artifactId>xsdlib</artifactId>
|
|
||||||
<version>20060615</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<!-- DAO dependencies -->
|
<!-- DAO dependencies -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate</groupId>
|
||||||
|
<artifactId>hibernate-entitymanager</artifactId>
|
||||||
|
<version>3.2.1.ga</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate</groupId>
|
||||||
<artifactId>hibernate</artifactId>
|
<artifactId>hibernate</artifactId>
|
||||||
@@ -340,6 +365,12 @@
|
|||||||
<artifactId>joda-time</artifactId>
|
<artifactId>joda-time</artifactId>
|
||||||
<version>1.4</version>
|
<version>1.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>joda-time</groupId>
|
||||||
|
<artifactId>joda-time-jsptags</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.acegisecurity</groupId>
|
<groupId>org.acegisecurity</groupId>
|
||||||
<artifactId>acegi-security</artifactId>
|
<artifactId>acegi-security</artifactId>
|
||||||
@@ -375,10 +406,22 @@
|
|||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>joda-time</groupId>
|
<groupId>org.acegisecurity</groupId>
|
||||||
<artifactId>joda-time-hibernate</artifactId>
|
<artifactId>acegi-security-tiger</artifactId>
|
||||||
<version>0.8</version>
|
<version>1.0.3</version>
|
||||||
<scope>runtime</scope>
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-aop</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<!-- Test dependencies -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.easymock</groupId>
|
||||||
|
<artifactId>easymock</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
<version>2.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Test dependencies -->
|
<!-- Test dependencies -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -25,10 +25,12 @@ import org.springframework.ws.samples.airline.domain.ServiceClass;
|
|||||||
|
|
||||||
public interface FlightDao {
|
public interface FlightDao {
|
||||||
|
|
||||||
List findFlights(String fromAirportCode, String toAirportCode, Interval interval, ServiceClass serviceClass)
|
List<Flight> findFlights(String fromAirportCode, String toAirportCode, Interval interval, ServiceClass serviceClass)
|
||||||
throws DataAccessException;
|
throws DataAccessException;
|
||||||
|
|
||||||
|
Flight getFlight(Long id);
|
||||||
|
|
||||||
Flight getFlight(String flightNumber, DateTime departureTime);
|
Flight getFlight(String flightNumber, DateTime departureTime);
|
||||||
|
|
||||||
void update(Flight flight);
|
Flight update(Flight flight);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,4 @@ public interface FrequentFlyerDao {
|
|||||||
|
|
||||||
FrequentFlyer get(String username) throws DataAccessException;
|
FrequentFlyer get(String username) throws DataAccessException;
|
||||||
|
|
||||||
void update(FrequentFlyer frequentFlyer) throws DataAccessException;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,6 @@ import org.springframework.ws.samples.airline.domain.Ticket;
|
|||||||
|
|
||||||
public interface TicketDao {
|
public interface TicketDao {
|
||||||
|
|
||||||
void save(Ticket ticket) throws DataAccessException;
|
Ticket save(Ticket ticket) throws DataAccessException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.ws.samples.airline.dao.jpa;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.PersistenceContext;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
|
||||||
|
import org.joda.time.DateTime;
|
||||||
|
import org.joda.time.Interval;
|
||||||
|
import org.springframework.dao.DataAccessException;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
import org.springframework.ws.samples.airline.dao.FlightDao;
|
||||||
|
import org.springframework.ws.samples.airline.domain.Flight;
|
||||||
|
import org.springframework.ws.samples.airline.domain.ServiceClass;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class JpaFlightDao implements FlightDao {
|
||||||
|
|
||||||
|
@PersistenceContext
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
public List<Flight> findFlights(String fromAirportCode,
|
||||||
|
String toAirportCode,
|
||||||
|
Interval interval,
|
||||||
|
ServiceClass serviceClass) throws DataAccessException {
|
||||||
|
Query query = entityManager.createQuery("FROM Flight f WHERE f.from.code = :from " +
|
||||||
|
"AND f.to.code = :to AND f.departureTime >= :start AND f.departureTime <= :end AND " +
|
||||||
|
"f.serviceClass = :class");
|
||||||
|
query.setParameter("from", fromAirportCode);
|
||||||
|
query.setParameter("to", toAirportCode);
|
||||||
|
query.setParameter("start", interval.getStart());
|
||||||
|
query.setParameter("end", interval.getEnd());
|
||||||
|
query.setParameter("class", serviceClass);
|
||||||
|
return query.getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Flight getFlight(Long id) {
|
||||||
|
return entityManager.find(Flight.class, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Flight getFlight(String flightNumber, DateTime departureTime) {
|
||||||
|
Query query = entityManager
|
||||||
|
.createQuery("FROM Flight f WHERE f.number = :number AND f.departureTime = :departureTime");
|
||||||
|
query.setParameter("number", flightNumber);
|
||||||
|
query.setParameter("departureTime", departureTime);
|
||||||
|
return (Flight) query.getSingleResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Flight update(Flight flight) {
|
||||||
|
return entityManager.merge(flight);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.ws.samples.airline.dao.jpa;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.PersistenceContext;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
|
||||||
|
import org.springframework.dao.DataAccessException;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
import org.springframework.ws.samples.airline.dao.FrequentFlyerDao;
|
||||||
|
import org.springframework.ws.samples.airline.domain.FrequentFlyer;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class JpaFrequentFlyerDao implements FrequentFlyerDao {
|
||||||
|
|
||||||
|
@PersistenceContext
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
public FrequentFlyer get(String username) throws DataAccessException {
|
||||||
|
Query query = entityManager.createQuery("FROM FrequentFlyer f WHERE f.username = :username");
|
||||||
|
query.setParameter("username", username);
|
||||||
|
return (FrequentFlyer) query.getSingleResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.ws.samples.airline.dao.jpa;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.PersistenceContext;
|
||||||
|
|
||||||
|
import org.springframework.dao.DataAccessException;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
import org.springframework.ws.samples.airline.dao.TicketDao;
|
||||||
|
import org.springframework.ws.samples.airline.domain.Ticket;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class JpaTicketDao implements TicketDao {
|
||||||
|
|
||||||
|
@PersistenceContext
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
public Ticket save(Ticket ticket) throws DataAccessException {
|
||||||
|
return entityManager.merge(ticket);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,13 +17,23 @@
|
|||||||
package org.springframework.ws.samples.airline.domain;
|
package org.springframework.ws.samples.airline.domain;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "AIRPORT")
|
||||||
public class Airport implements Serializable {
|
public class Airport implements Serializable {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "CODE")
|
||||||
private String code;
|
private String code;
|
||||||
|
|
||||||
|
@Column(name = "NAME")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@Column(name = "CITY")
|
||||||
private String city;
|
private String city;
|
||||||
|
|
||||||
public Airport() {
|
public Airport() {
|
||||||
@@ -39,26 +49,14 @@ public class Airport implements Serializable {
|
|||||||
return city;
|
return city;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCity(String city) {
|
|
||||||
this.city = city;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCode() {
|
public String getCode() {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCode(String code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
if (this == other) {
|
if (this == other) {
|
||||||
return true;
|
return true;
|
||||||
@@ -67,7 +65,7 @@ public class Airport implements Serializable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Airport that = (Airport) other;
|
final Airport that = (Airport) other;
|
||||||
return this.code.equals(that.code);
|
return code.equals(that.code);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
|
|||||||
@@ -15,26 +15,69 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.ws.samples.airline.domain;
|
package org.springframework.ws.samples.airline.domain;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.EnumType;
|
||||||
|
import javax.persistence.Enumerated;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.ManyToOne;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.Type;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
public class Flight extends Entity {
|
@Entity
|
||||||
|
@Table(name = "FLIGHT")
|
||||||
|
public class Flight implements Serializable {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "ID")
|
||||||
|
@GeneratedValue
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "NUMBER")
|
||||||
private String number;
|
private String number;
|
||||||
|
|
||||||
|
@Column(name = "DEPARTURE_TIME")
|
||||||
|
@Type(type = "org.springframework.ws.samples.airline.domain.hibernate.DateTimeUserType")
|
||||||
private DateTime departureTime;
|
private DateTime departureTime;
|
||||||
|
|
||||||
private DateTime arrivalTime;
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "FROM_AIRPORT_CODE", nullable = false)
|
||||||
private Airport to;
|
|
||||||
|
|
||||||
private Airport from;
|
private Airport from;
|
||||||
|
|
||||||
|
@Column(name = "ARRIVAL_TIME")
|
||||||
|
@Type(type = "org.springframework.ws.samples.airline.domain.hibernate.DateTimeUserType")
|
||||||
|
private DateTime arrivalTime;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "TO_AIRPORT_CODE", nullable = false)
|
||||||
|
private Airport to;
|
||||||
|
|
||||||
|
@Column(name = "SERVICE_CLASS")
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
private ServiceClass serviceClass;
|
private ServiceClass serviceClass;
|
||||||
|
|
||||||
|
@Column(name = "SEATS_AVAILABLE")
|
||||||
private int seatsAvailable;
|
private int seatsAvailable;
|
||||||
|
|
||||||
|
@Column(name = "MILES")
|
||||||
private int miles;
|
private int miles;
|
||||||
|
|
||||||
|
public Flight() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Flight(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
public DateTime getArrivalTime() {
|
public DateTime getArrivalTime() {
|
||||||
return arrivalTime;
|
return arrivalTime;
|
||||||
}
|
}
|
||||||
@@ -99,6 +142,10 @@ public class Flight extends Entity {
|
|||||||
this.to = to;
|
this.to = to;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void substractSeats(int count) {
|
||||||
|
seatsAvailable -= count;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) {
|
if (this == o) {
|
||||||
return true;
|
return true;
|
||||||
@@ -120,8 +167,7 @@ public class Flight extends Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result;
|
int result = number.hashCode();
|
||||||
result = number.hashCode();
|
|
||||||
result = 29 * result + departureTime.hashCode();
|
result = 29 * result + departureTime.hashCode();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -130,11 +176,7 @@ public class Flight extends Entity {
|
|||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
buffer.append(getNumber());
|
buffer.append(getNumber());
|
||||||
buffer.append(' ');
|
buffer.append(' ');
|
||||||
buffer.append(getDepartureTime());
|
buffer.append(getDepartureTime().toString());
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void substractSeats(int count) {
|
|
||||||
this.seatsAvailable -= count;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,12 +16,23 @@
|
|||||||
|
|
||||||
package org.springframework.ws.samples.airline.domain;
|
package org.springframework.ws.samples.airline.domain;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.PrimaryKeyJoinColumn;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "FREQUENT_FLYER")
|
||||||
|
@PrimaryKeyJoinColumn(name = "PASSENGER_ID")
|
||||||
public class FrequentFlyer extends Passenger {
|
public class FrequentFlyer extends Passenger {
|
||||||
|
|
||||||
|
@Column(name = "USERNAME")
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
|
@Column(name = "PASSWORD")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
@Column(name = "MILES")
|
||||||
private int miles;
|
private int miles;
|
||||||
|
|
||||||
public FrequentFlyer() {
|
public FrequentFlyer() {
|
||||||
@@ -31,7 +42,7 @@ public class FrequentFlyer extends Passenger {
|
|||||||
this.username = username;
|
this.username = username;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FrequentFlyer(String username, String password, String firstName, String lastName) {
|
public FrequentFlyer(String firstName, String lastName, String username, String password) {
|
||||||
super(firstName, lastName);
|
super(firstName, lastName);
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
@@ -69,13 +80,17 @@ public class FrequentFlyer extends Passenger {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final FrequentFlyer that = (FrequentFlyer) other;
|
final FrequentFlyer that = (FrequentFlyer) other;
|
||||||
return this.username.equals(that.username);
|
return username.equals(that.username);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return username.hashCode();
|
return username.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
public void addMiles(int miles) {
|
public void addMiles(int miles) {
|
||||||
this.miles += miles;
|
this.miles += miles;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,24 +15,61 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.ws.samples.airline.domain;
|
package org.springframework.ws.samples.airline.domain;
|
||||||
|
|
||||||
import org.springframework.util.Assert;
|
import java.io.Serializable;
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Inheritance;
|
||||||
|
import javax.persistence.InheritanceType;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
public class Passenger extends Entity {
|
@Entity
|
||||||
|
@Table(name = "PASSENGER")
|
||||||
|
@Inheritance(strategy = InheritanceType.JOINED)
|
||||||
|
public class Passenger implements Serializable {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
@Column(name = "ID")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "FIRST_NAME")
|
||||||
private String firstName;
|
private String firstName;
|
||||||
|
|
||||||
|
@Column(name = "LAST_NAME")
|
||||||
private String lastName;
|
private String lastName;
|
||||||
|
|
||||||
public Passenger() {
|
public Passenger() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Passenger(String firstName, String lastName) {
|
public Passenger(String firstName, String lastName) {
|
||||||
Assert.hasLength(firstName);
|
|
||||||
Assert.hasLength(lastName);
|
|
||||||
this.firstName = firstName;
|
this.firstName = firstName;
|
||||||
this.lastName = lastName;
|
this.lastName = lastName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Passenger(Long id, String firstName, String lastName) {
|
||||||
|
this.id = id;
|
||||||
|
this.firstName = firstName;
|
||||||
|
this.lastName = lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFirstName() {
|
||||||
|
return firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastName() {
|
||||||
|
return lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return firstName + " " + lastName;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) {
|
if (this == o) {
|
||||||
return true;
|
return true;
|
||||||
@@ -58,24 +95,4 @@ public class Passenger extends Entity {
|
|||||||
result = 29 * result + getLastName().hashCode();
|
result = 29 * result + getLastName().hashCode();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFirstName() {
|
|
||||||
return firstName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFirstName(String firstName) {
|
|
||||||
this.firstName = firstName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLastName() {
|
|
||||||
return lastName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastName(String lastName) {
|
|
||||||
this.lastName = lastName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return firstName + " " + lastName;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,41 +16,11 @@
|
|||||||
|
|
||||||
package org.springframework.ws.samples.airline.domain;
|
package org.springframework.ws.samples.airline.domain;
|
||||||
|
|
||||||
import java.io.Serializable;
|
public enum ServiceClass {
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class ServiceClass implements Serializable {
|
ECONOMY,
|
||||||
|
|
||||||
private String name;
|
BUSINESS,
|
||||||
|
|
||||||
public static final ServiceClass ECONOMY = new ServiceClass("economy");
|
FIRST
|
||||||
|
|
||||||
public static final ServiceClass BUSINESS = new ServiceClass("business");
|
|
||||||
|
|
||||||
public static final ServiceClass FIRST = new ServiceClass("first");
|
|
||||||
|
|
||||||
private static final Map INSTANCES = new HashMap();
|
|
||||||
|
|
||||||
static {
|
|
||||||
INSTANCES.put(ECONOMY.toString(), ECONOMY);
|
|
||||||
INSTANCES.put(BUSINESS.toString(), BUSINESS);
|
|
||||||
INSTANCES.put(FIRST.toString(), FIRST);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ServiceClass(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
Object readResolve() {
|
|
||||||
return getInstance(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ServiceClass getInstance(String name) {
|
|
||||||
return (ServiceClass) INSTANCES.get(name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,19 +16,56 @@
|
|||||||
|
|
||||||
package org.springframework.ws.samples.airline.domain;
|
package org.springframework.ws.samples.airline.domain;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import javax.persistence.CascadeType;
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.JoinTable;
|
||||||
|
import javax.persistence.ManyToMany;
|
||||||
|
import javax.persistence.ManyToOne;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import org.joda.time.YearMonthDay;
|
import org.hibernate.annotations.Type;
|
||||||
|
import org.joda.time.LocalDate;
|
||||||
|
|
||||||
public class Ticket extends Entity {
|
@Entity
|
||||||
|
@Table(name = "TICKET")
|
||||||
|
public class Ticket implements Serializable {
|
||||||
|
|
||||||
private YearMonthDay issueDate;
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Long id;
|
||||||
|
|
||||||
private Set passengers = new HashSet();
|
@Column(name = "ISSUE_DATE")
|
||||||
|
@Type(type = "org.springframework.ws.samples.airline.domain.hibernate.LocalDateUserType")
|
||||||
|
private LocalDate issueDate;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "FLIGHT_ID", nullable = false)
|
||||||
private Flight flight;
|
private Flight flight;
|
||||||
|
|
||||||
|
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
|
||||||
|
@JoinTable(name = "PASSENGER_TICKET",
|
||||||
|
joinColumns = @JoinColumn(name = "TICKET_ID"),
|
||||||
|
inverseJoinColumns = @JoinColumn(name = "PASSENGER_ID"))
|
||||||
|
private Set<Passenger> passengers = new HashSet<Passenger>();
|
||||||
|
|
||||||
|
public Ticket() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Ticket(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
public Flight getFlight() {
|
public Flight getFlight() {
|
||||||
return flight;
|
return flight;
|
||||||
}
|
}
|
||||||
@@ -37,19 +74,19 @@ public class Ticket extends Entity {
|
|||||||
this.flight = flight;
|
this.flight = flight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public YearMonthDay getIssueDate() {
|
public LocalDate getIssueDate() {
|
||||||
return issueDate;
|
return issueDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIssueDate(YearMonthDay issueDate) {
|
public void setIssueDate(LocalDate issueDate) {
|
||||||
this.issueDate = issueDate;
|
this.issueDate = issueDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set getPassengers() {
|
public Set<Passenger> getPassengers() {
|
||||||
return passengers;
|
return passengers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPassengers(Set passengers) {
|
public void setPassengers(Set<Passenger> passengers) {
|
||||||
this.passengers = passengers;
|
this.passengers = passengers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.ws.samples.airline.domain.hibernate;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.sql.Types;
|
||||||
|
|
||||||
|
import org.hibernate.HibernateException;
|
||||||
|
import org.hibernate.usertype.UserType;
|
||||||
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
|
/** @author Arjen Poutsma */
|
||||||
|
public class DateTimeUserType implements UserType {
|
||||||
|
|
||||||
|
public int[] sqlTypes() {
|
||||||
|
return new int[]{Types.TIMESTAMP};
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class returnedClass() {
|
||||||
|
return DateTime.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMutable() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object deepCopy(Object value) throws HibernateException {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Serializable disassemble(Object value) throws HibernateException {
|
||||||
|
return (Serializable) value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object assemble(Serializable cached, Object owner) throws HibernateException {
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object replace(Object original, Object target, Object owner) throws HibernateException {
|
||||||
|
return original;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object x, Object y) throws HibernateException {
|
||||||
|
return x == y || !(x == null || y == null) && x.equals(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode(Object x) throws HibernateException {
|
||||||
|
return x.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
|
||||||
|
Timestamp timestamp = rs.getTimestamp(names[0]);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new DateTime(timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
|
||||||
|
if (value == null) {
|
||||||
|
st.setNull(index, Types.TIMESTAMP);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DateTime dateTime = (DateTime) value;
|
||||||
|
Timestamp timestamp = new Timestamp(dateTime.getMillis());
|
||||||
|
st.setTimestamp(index, timestamp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.ws.samples.airline.domain.hibernate;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.sql.Date;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Types;
|
||||||
|
|
||||||
|
import org.hibernate.HibernateException;
|
||||||
|
import org.hibernate.dialect.Dialect;
|
||||||
|
import org.hibernate.type.LiteralType;
|
||||||
|
import org.hibernate.usertype.UserType;
|
||||||
|
import org.joda.time.LocalDate;
|
||||||
|
|
||||||
|
public class LocalDateUserType implements UserType, LiteralType {
|
||||||
|
|
||||||
|
public int[] sqlTypes() {
|
||||||
|
return new int[]{Types.DATE};
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class returnedClass() {
|
||||||
|
return LocalDate.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMutable() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object deepCopy(Object value) throws HibernateException {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Serializable disassemble(Object value) throws HibernateException {
|
||||||
|
return (Serializable) value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object assemble(Serializable cached, Object owner) throws HibernateException {
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object replace(Object original, Object target, Object owner) throws HibernateException {
|
||||||
|
return original;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object x, Object y) throws HibernateException {
|
||||||
|
return x == y || !(x == null || y == null) && x.equals(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode(Object x) throws HibernateException {
|
||||||
|
return x.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
|
||||||
|
Date sqlDate = rs.getDate(names[0]);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new LocalDate(sqlDate.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
|
||||||
|
if (value == null) {
|
||||||
|
st.setNull(index, Types.DATE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LocalDate localDate = (LocalDate) value;
|
||||||
|
Date sqlDate = new Date(localDate.toDateMidnight().getMillis());
|
||||||
|
st.setDate(index, sqlDate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String objectToSQLString(Object value, Dialect dialect) throws Exception {
|
||||||
|
LocalDate localDate = (LocalDate) value;
|
||||||
|
return localDate.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,7 +19,11 @@ package org.springframework.ws.samples.airline.security;
|
|||||||
import org.acegisecurity.Authentication;
|
import org.acegisecurity.Authentication;
|
||||||
import org.acegisecurity.context.SecurityContext;
|
import org.acegisecurity.context.SecurityContext;
|
||||||
import org.acegisecurity.context.SecurityContextHolder;
|
import org.acegisecurity.context.SecurityContextHolder;
|
||||||
|
import org.acegisecurity.userdetails.UserDetails;
|
||||||
|
import org.acegisecurity.userdetails.UserDetailsService;
|
||||||
|
import org.acegisecurity.userdetails.UsernameNotFoundException;
|
||||||
|
import org.springframework.dao.DataAccessException;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.ws.samples.airline.dao.FrequentFlyerDao;
|
import org.springframework.ws.samples.airline.dao.FrequentFlyerDao;
|
||||||
import org.springframework.ws.samples.airline.domain.FrequentFlyer;
|
import org.springframework.ws.samples.airline.domain.FrequentFlyer;
|
||||||
|
|
||||||
@@ -28,14 +32,15 @@ import org.springframework.ws.samples.airline.domain.FrequentFlyer;
|
|||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
*/
|
*/
|
||||||
public class AcegiFrequentFlyerSecurityService implements FrequentFlyerSecurityService {
|
public class AcegiFrequentFlyerSecurityService implements FrequentFlyerSecurityService, UserDetailsService {
|
||||||
|
|
||||||
private FrequentFlyerDao frequentFlyerDao;
|
private FrequentFlyerDao frequentFlyerDao;
|
||||||
|
|
||||||
public void setFrequentFlyerDao(FrequentFlyerDao frequentFlyerDao) {
|
public AcegiFrequentFlyerSecurityService(FrequentFlyerDao frequentFlyerDao) {
|
||||||
this.frequentFlyerDao = frequentFlyerDao;
|
this.frequentFlyerDao = frequentFlyerDao;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public FrequentFlyer getCurrentlyAuthenticatedFrequentFlyer() {
|
public FrequentFlyer getCurrentlyAuthenticatedFrequentFlyer() {
|
||||||
SecurityContext context = SecurityContextHolder.getContext();
|
SecurityContext context = SecurityContextHolder.getContext();
|
||||||
Authentication authentication = context.getAuthentication();
|
Authentication authentication = context.getAuthentication();
|
||||||
@@ -53,7 +58,20 @@ public class AcegiFrequentFlyerSecurityService implements FrequentFlyerSecurityS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public FrequentFlyer getFrequentFlyer(String username) {
|
public FrequentFlyer getFrequentFlyer(String username) {
|
||||||
return frequentFlyerDao.get(username);
|
return frequentFlyerDao.get(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
|
||||||
|
FrequentFlyer frequentFlyer = frequentFlyerDao.get(username);
|
||||||
|
if (frequentFlyer != null) {
|
||||||
|
return new FrequentFlyerDetails(frequentFlyer);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new UsernameNotFoundException("Frequent flyer '" + username + "' not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,11 +30,7 @@ public class StubFrequentFlyerSecurityService implements FrequentFlyerSecuritySe
|
|||||||
private FrequentFlyer john;
|
private FrequentFlyer john;
|
||||||
|
|
||||||
public StubFrequentFlyerSecurityService() {
|
public StubFrequentFlyerSecurityService() {
|
||||||
john = new FrequentFlyer();
|
john = new FrequentFlyer("John", "Doe", "john", "changeme");
|
||||||
john.setUsername("john");
|
|
||||||
john.setFirstName("John");
|
|
||||||
john.setLastName("Doe");
|
|
||||||
john.setPassword("changeme");
|
|
||||||
john.setMiles(10);
|
john.setMiles(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
|
import org.springframework.ws.samples.airline.domain.Flight;
|
||||||
|
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.domain.ServiceClass;
|
||||||
import org.springframework.ws.samples.airline.domain.Ticket;
|
import org.springframework.ws.samples.airline.domain.Ticket;
|
||||||
|
|
||||||
@@ -29,6 +32,15 @@ import org.springframework.ws.samples.airline.domain.Ticket;
|
|||||||
*/
|
*/
|
||||||
public interface AirlineService {
|
public interface AirlineService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a single <code>Flight</code> with the given id.
|
||||||
|
*
|
||||||
|
* @param id the flight identifier
|
||||||
|
* @return the flight
|
||||||
|
* @throws NoSuchFlightException if a flight with the specified flight iddoes not exist
|
||||||
|
*/
|
||||||
|
Flight getFlight(Long id) throws NoSuchFlightException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of <code>Flight</code> objects that fall within the specified criteria.
|
* Returns a list of <code>Flight</code> objects that fall within the specified criteria.
|
||||||
*
|
*
|
||||||
@@ -37,25 +49,27 @@ public interface AirlineService {
|
|||||||
* @param departureDate the date of the flights
|
* @param departureDate the date of the flights
|
||||||
* @param serviceClass the desired service class level. May be <code>null</code>
|
* @param serviceClass the desired service class level. May be <code>null</code>
|
||||||
* @return a list of flights
|
* @return a list of flights
|
||||||
* @see org.springframework.ws.samples.airline.domain.Flight
|
|
||||||
*/
|
*/
|
||||||
List getFlights(String fromAirportCode, String toAirportCode, LocalDate departureDate, ServiceClass serviceClass);
|
List<Flight> getFlights(String fromAirportCode,
|
||||||
|
String toAirportCode,
|
||||||
|
LocalDate departureDate,
|
||||||
|
ServiceClass serviceClass);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Books a single flight for a number of passengers. Passengers can be either specified by name or by frequent flyer
|
* Books a single flight for a number of passengers. Passengers can be either specified by name or by frequent flyer
|
||||||
* username. If a <code>FrequentFlyer</code> is specified, the first and last name are looked up in the database.
|
* username. If a {@link FrequentFlyer} is specified, the first and last name are looked up in the database.
|
||||||
*
|
*
|
||||||
* @param flightNumber the number of the flight to book
|
* @param flightNumber the number of the flight to book
|
||||||
* @param departureTime the departure time of the flight to book
|
* @param departureTime the departure time of the flight to book
|
||||||
* @param passengers the list of passengers for the flight to book. Can be either <code>Passenger</code>s with a
|
* @param passengers the list of passengers for the flight to book. Can be either {@link Passenger} objects with
|
||||||
* first and last name, or <code>FrequentFlyer</code>s with a username.
|
* a first and last name, or {@link FrequentFlyer} objects with a username.
|
||||||
* @return the created ticket
|
* @return the created ticket
|
||||||
* @throws NoSuchFlightException if a flight with the specified flight number and departure time does not exist
|
* @throws NoSuchFlightException if a flight with the specified flight number and departure time does not exist
|
||||||
* @throws NoSeatAvailableException if not enough seats are available for the flight
|
* @throws NoSeatAvailableException if not enough seats are available for the flight
|
||||||
* @see org.springframework.ws.samples.airline.domain.Passenger
|
* @see org.springframework.ws.samples.airline.domain.Passenger
|
||||||
* @see org.springframework.ws.samples.airline.domain.FrequentFlyer
|
* @see org.springframework.ws.samples.airline.domain.FrequentFlyer
|
||||||
*/
|
*/
|
||||||
Ticket bookFlight(String flightNumber, DateTime departureTime, List passengers)
|
Ticket bookFlight(String flightNumber, DateTime departureTime, List<Passenger> passengers)
|
||||||
throws NoSuchFlightException, NoSeatAvailableException;
|
throws NoSuchFlightException, NoSeatAvailableException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -17,12 +17,15 @@
|
|||||||
package org.springframework.ws.samples.airline.service;
|
package org.springframework.ws.samples.airline.service;
|
||||||
|
|
||||||
import org.springframework.ws.samples.airline.domain.Flight;
|
import org.springframework.ws.samples.airline.domain.Flight;
|
||||||
|
import org.springframework.ws.soap.server.endpoint.annotation.FaultCode;
|
||||||
|
import org.springframework.ws.soap.server.endpoint.annotation.SoapFault;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception thrown when not enough seats are available for a flight.
|
* Exception thrown when not enough seats are available for a flight.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
*/
|
*/
|
||||||
|
@SoapFault(faultCode = FaultCode.SERVER)
|
||||||
public class NoSeatAvailableException extends Exception {
|
public class NoSeatAvailableException extends Exception {
|
||||||
|
|
||||||
private Flight flight;
|
private Flight flight;
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ public class NoSuchFlightException extends Exception {
|
|||||||
this.departureTime = departureTime;
|
this.departureTime = departureTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NoSuchFlightException(Long id) {
|
||||||
|
super("No flight with id [" + id + "]");
|
||||||
|
}
|
||||||
|
|
||||||
public String getFlightNumber() {
|
public String getFlightNumber() {
|
||||||
return flightNumber;
|
return flightNumber;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,14 +15,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.ws.samples.airline.service.impl;
|
package org.springframework.ws.samples.airline.service.impl;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.acegisecurity.annotation.Secured;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.joda.time.YearMonthDay;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.ws.samples.airline.dao.FlightDao;
|
import org.springframework.ws.samples.airline.dao.FlightDao;
|
||||||
import org.springframework.ws.samples.airline.dao.TicketDao;
|
import org.springframework.ws.samples.airline.dao.TicketDao;
|
||||||
@@ -52,24 +52,21 @@ public class AirlineServiceImpl implements AirlineService {
|
|||||||
|
|
||||||
private FrequentFlyerSecurityService frequentFlyerSecurityService = new StubFrequentFlyerSecurityService();
|
private FrequentFlyerSecurityService frequentFlyerSecurityService = new StubFrequentFlyerSecurityService();
|
||||||
|
|
||||||
public void setFlightDao(FlightDao flightDao) {
|
public AirlineServiceImpl(FlightDao flightDao, TicketDao ticketDao) {
|
||||||
this.flightDao = flightDao;
|
this.flightDao = flightDao;
|
||||||
|
this.ticketDao = ticketDao;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFrequentFlyerSecurityService(FrequentFlyerSecurityService frequentFlyerSecurityService) {
|
public void setFrequentFlyerSecurityService(FrequentFlyerSecurityService frequentFlyerSecurityService) {
|
||||||
this.frequentFlyerSecurityService = frequentFlyerSecurityService;
|
this.frequentFlyerSecurityService = frequentFlyerSecurityService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTicketDao(TicketDao ticketDao) {
|
@Transactional(rollbackFor = {NoSuchFlightException.class, NoSeatAvailableException.class})
|
||||||
this.ticketDao = ticketDao;
|
public Ticket bookFlight(String flightNumber, DateTime departureTime, List<Passenger> passengers)
|
||||||
}
|
|
||||||
|
|
||||||
public Ticket bookFlight(String flightNumber, DateTime departureTime, List passengers)
|
|
||||||
throws NoSuchFlightException, NoSeatAvailableException {
|
throws NoSuchFlightException, NoSeatAvailableException {
|
||||||
Assert.notEmpty(passengers, "No passengers given");
|
Assert.notEmpty(passengers, "No passengers given");
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Booking flight '" + flightNumber + "' on '" + departureTime + "' for " + passengers.size() +
|
logger.debug("Booking flight '" + flightNumber + "' on '" + departureTime + "' for " + passengers);
|
||||||
" passengers");
|
|
||||||
}
|
}
|
||||||
Flight flight = flightDao.getFlight(flightNumber, departureTime);
|
Flight flight = flightDao.getFlight(flightNumber, departureTime);
|
||||||
if (flight == null) {
|
if (flight == null) {
|
||||||
@@ -79,10 +76,9 @@ public class AirlineServiceImpl implements AirlineService {
|
|||||||
throw new NoSeatAvailableException(flight);
|
throw new NoSeatAvailableException(flight);
|
||||||
}
|
}
|
||||||
Ticket ticket = new Ticket();
|
Ticket ticket = new Ticket();
|
||||||
ticket.setIssueDate(new YearMonthDay());
|
ticket.setIssueDate(new LocalDate());
|
||||||
ticket.setFlight(flight);
|
ticket.setFlight(flight);
|
||||||
for (Iterator iterator = passengers.iterator(); iterator.hasNext();) {
|
for (Passenger passenger : passengers) {
|
||||||
Passenger passenger = (Passenger) iterator.next();
|
|
||||||
// frequent flyer service is not required
|
// frequent flyer service is not required
|
||||||
if (passenger instanceof FrequentFlyer && frequentFlyerSecurityService != null) {
|
if (passenger instanceof FrequentFlyer && frequentFlyerSecurityService != null) {
|
||||||
String username = ((FrequentFlyer) passenger).getUsername();
|
String username = ((FrequentFlyer) passenger).getUsername();
|
||||||
@@ -97,19 +93,25 @@ public class AirlineServiceImpl implements AirlineService {
|
|||||||
}
|
}
|
||||||
flight.substractSeats(passengers.size());
|
flight.substractSeats(passengers.size());
|
||||||
flightDao.update(flight);
|
flightDao.update(flight);
|
||||||
ticketDao.save(ticket);
|
return ticketDao.save(ticket);
|
||||||
return ticket;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFrequentFlyerMileage() {
|
@Transactional(readOnly = true)
|
||||||
FrequentFlyer frequentFlyer = frequentFlyerSecurityService.getCurrentlyAuthenticatedFrequentFlyer();
|
public Flight getFlight(Long id) throws NoSuchFlightException {
|
||||||
return frequentFlyer.getMiles();
|
Flight flight = flightDao.getFlight(id);
|
||||||
|
if (flight != null) {
|
||||||
|
return flight;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new NoSuchFlightException(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List getFlights(String fromAirportCode,
|
@Transactional(readOnly = true)
|
||||||
String toAirportCode,
|
public List<Flight> getFlights(String fromAirportCode,
|
||||||
LocalDate departureDate,
|
String toAirportCode,
|
||||||
ServiceClass serviceClass) {
|
LocalDate departureDate,
|
||||||
|
ServiceClass serviceClass) {
|
||||||
if (serviceClass == null) {
|
if (serviceClass == null) {
|
||||||
serviceClass = ServiceClass.ECONOMY;
|
serviceClass = ServiceClass.ECONOMY;
|
||||||
}
|
}
|
||||||
@@ -117,6 +119,18 @@ public class AirlineServiceImpl implements AirlineService {
|
|||||||
logger.debug(
|
logger.debug(
|
||||||
"Getting flights from '" + fromAirportCode + "' to '" + toAirportCode + "' on " + departureDate);
|
"Getting flights from '" + fromAirportCode + "' to '" + toAirportCode + "' on " + departureDate);
|
||||||
}
|
}
|
||||||
return flightDao.findFlights(fromAirportCode, toAirportCode, departureDate.toInterval(), serviceClass);
|
List<Flight> flights =
|
||||||
|
flightDao.findFlights(fromAirportCode, toAirportCode, departureDate.toInterval(), serviceClass);
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("Returning " + flights.size() + " flights");
|
||||||
|
}
|
||||||
|
return flights;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
@Secured({"ROLE_FREQUENT_FLYER"})
|
||||||
|
public int getFrequentFlyerMileage() {
|
||||||
|
FrequentFlyer frequentFlyer = frequentFlyerSecurityService.getCurrentlyAuthenticatedFrequentFlyer();
|
||||||
|
return frequentFlyer != null ? frequentFlyer.getMiles() : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.ws.samples.airline.web;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.joda.time.LocalDate;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.web.bind.ServletRequestUtils;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
|
||||||
|
import org.springframework.ws.samples.airline.domain.Flight;
|
||||||
|
import org.springframework.ws.samples.airline.domain.ServiceClass;
|
||||||
|
import org.springframework.ws.samples.airline.service.AirlineService;
|
||||||
|
|
||||||
|
/** @author Arjen Poutsma */
|
||||||
|
public class FlightsController extends MultiActionController {
|
||||||
|
|
||||||
|
private AirlineService airlineService;
|
||||||
|
|
||||||
|
public FlightsController(AirlineService airlineService) {
|
||||||
|
Assert.notNull(airlineService, "'airlineService' must not be null");
|
||||||
|
this.airlineService = airlineService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModelAndView flightList(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||||
|
String fromAirportCode = ServletRequestUtils.getStringParameter(request, "from");
|
||||||
|
String toAirportCode = ServletRequestUtils.getStringParameter(request, "to");
|
||||||
|
String departureDateString =
|
||||||
|
ServletRequestUtils.getStringParameter(request, "departureDate", new LocalDate().toString());
|
||||||
|
String serviceClassString = ServletRequestUtils.getStringParameter(request, "serviceClass", "ECONOMY");
|
||||||
|
|
||||||
|
ServiceClass serviceClass = ServiceClass.valueOf(serviceClassString);
|
||||||
|
LocalDate departureDate = new LocalDate(departureDateString);
|
||||||
|
|
||||||
|
ModelAndView mav = new ModelAndView("flights");
|
||||||
|
if (StringUtils.hasLength(fromAirportCode) && StringUtils.hasLength(toAirportCode)) {
|
||||||
|
mav.addObject("from", fromAirportCode);
|
||||||
|
mav.addObject("to", toAirportCode);
|
||||||
|
mav.addObject("departureDate", departureDateString);
|
||||||
|
mav.addObject("serviceClass", serviceClassString);
|
||||||
|
mav.addObject("flights",
|
||||||
|
airlineService.getFlights(fromAirportCode, toAirportCode, departureDate, serviceClass));
|
||||||
|
}
|
||||||
|
return mav;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModelAndView singleFlight(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||||
|
String uri = request.getRequestURI();
|
||||||
|
int pos = uri.lastIndexOf('/') + 1;
|
||||||
|
long id = Long.parseLong(uri.substring(pos));
|
||||||
|
Flight flight = airlineService.getFlight(id);
|
||||||
|
return new ModelAndView("flight", "flight", flight);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.ws.samples.airline.ws;
|
||||||
|
|
||||||
|
/** @author Arjen Poutsma */
|
||||||
|
public interface AirlineWebServiceConstants {
|
||||||
|
|
||||||
|
String NAMESPACE = "http://www.springframework.org/spring-ws/samples/airline/schemas";
|
||||||
|
}
|
||||||
@@ -1,166 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2006 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.ws.samples.airline.ws;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.jdom.Element;
|
|
||||||
import org.jdom.Namespace;
|
|
||||||
import org.jdom.xpath.XPath;
|
|
||||||
import org.joda.time.DateTime;
|
|
||||||
import org.joda.time.DateTimeZone;
|
|
||||||
import org.joda.time.YearMonthDay;
|
|
||||||
import org.joda.time.format.DateTimeFormatter;
|
|
||||||
import org.joda.time.format.ISODateTimeFormat;
|
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
|
||||||
import org.springframework.ws.samples.airline.domain.Airport;
|
|
||||||
import org.springframework.ws.samples.airline.domain.Flight;
|
|
||||||
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.domain.Ticket;
|
|
||||||
import org.springframework.ws.samples.airline.service.AirlineService;
|
|
||||||
import org.springframework.ws.server.endpoint.AbstractJDomPayloadEndpoint;
|
|
||||||
|
|
||||||
public class BookFlightEndpoint extends AbstractJDomPayloadEndpoint implements InitializingBean {
|
|
||||||
|
|
||||||
private AirlineService airlineService;
|
|
||||||
|
|
||||||
private XPath flightNumberXPath;
|
|
||||||
|
|
||||||
private XPath departureTimeXPath;
|
|
||||||
|
|
||||||
private Namespace namespace;
|
|
||||||
|
|
||||||
private DateTimeFormatter dateFormatter;
|
|
||||||
|
|
||||||
private DateTimeFormatter dateTimeFormatter;
|
|
||||||
|
|
||||||
private DateTimeFormatter parser;
|
|
||||||
|
|
||||||
private XPath passengersXPath;
|
|
||||||
|
|
||||||
public void setAirlineService(AirlineService airlineService) {
|
|
||||||
this.airlineService = airlineService;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Element invokeInternal(Element requestElement) throws Exception {
|
|
||||||
String flightNumber = flightNumberXPath.valueOf(requestElement);
|
|
||||||
String departureTimeString = departureTimeXPath.valueOf(requestElement);
|
|
||||||
DateTime departureTime = parser.parseDateTime(departureTimeString);
|
|
||||||
if (logger.isDebugEnabled()) {
|
|
||||||
logger.debug("BookFlight request for flight number [" + flightNumber + "] at [" + departureTime + "]");
|
|
||||||
}
|
|
||||||
List passengerElements = passengersXPath.selectNodes(requestElement);
|
|
||||||
List passengers = new ArrayList();
|
|
||||||
for (Iterator iterator = passengerElements.iterator(); iterator.hasNext();) {
|
|
||||||
Element passengerElement = (Element) iterator.next();
|
|
||||||
if ("passenger".equals(passengerElement.getName()) && namespace.equals(passengerElement.getNamespace())) {
|
|
||||||
Passenger passenger = new Passenger(passengerElement.getChildTextNormalize("first", namespace),
|
|
||||||
passengerElement.getChildTextNormalize("last", namespace));
|
|
||||||
passengers.add(passenger);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if ("username".equals(passengerElement.getName()) && namespace.equals(passengerElement.getNamespace())) {
|
|
||||||
FrequentFlyer frequentFlyer = new FrequentFlyer(passengerElement.getTextNormalize());
|
|
||||||
passengers.add(frequentFlyer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ticket ticket = airlineService.bookFlight(flightNumber, departureTime, passengers);
|
|
||||||
return createResponse(ticket);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Element createResponse(Ticket ticket) {
|
|
||||||
Element responseElement = new Element("BookFlightResponse", namespace);
|
|
||||||
responseElement.addContent(new Element("id", namespace).setText(ticket.getId().toString()));
|
|
||||||
responseElement.addContent(createIssueDateElement(ticket.getIssueDate()));
|
|
||||||
responseElement.addContent(createPassengersElement(ticket.getPassengers()));
|
|
||||||
responseElement.addContent(createFlightElement(ticket.getFlight()));
|
|
||||||
return responseElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Element createIssueDateElement(YearMonthDay issueDate) {
|
|
||||||
Element issueDateElement = new Element("issueDate", namespace);
|
|
||||||
issueDateElement.setText(dateFormatter.print(issueDate));
|
|
||||||
return issueDateElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Element createPassengersElement(Set passengers) {
|
|
||||||
Element passengersElement = new Element("passengers", namespace);
|
|
||||||
for (Iterator iterator = passengers.iterator(); iterator.hasNext();) {
|
|
||||||
Passenger passenger = (Passenger) iterator.next();
|
|
||||||
Element passengerElement = new Element("passenger", namespace);
|
|
||||||
passengersElement.addContent(passengerElement);
|
|
||||||
passengerElement.addContent(new Element("first", namespace).setText(passenger.getFirstName()));
|
|
||||||
passengerElement.addContent(new Element("last", namespace).setText(passenger.getLastName()));
|
|
||||||
}
|
|
||||||
return passengersElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Element createFlightElement(Flight flight) {
|
|
||||||
Element flightElement = new Element("flight", namespace);
|
|
||||||
flightElement.addContent(new Element("number", namespace).setText(flight.getNumber()));
|
|
||||||
flightElement.addContent(
|
|
||||||
new Element("departureTime", namespace).setText(dateTimeFormatter.print(flight.getDepartureTime())));
|
|
||||||
flightElement.addContent(createAirportElement("from", flight.getFrom()));
|
|
||||||
flightElement
|
|
||||||
.addContent(new Element("arrivalTime", namespace).setText(
|
|
||||||
dateTimeFormatter.print(flight.getArrivalTime())));
|
|
||||||
flightElement.addContent(createAirportElement("to", flight.getTo()));
|
|
||||||
flightElement.addContent(createServiceClassElement(flight.getServiceClass()));
|
|
||||||
return flightElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Element createAirportElement(String localName, Airport airport) {
|
|
||||||
Element airportElement = new Element(localName, namespace);
|
|
||||||
airportElement.addContent(new Element("code", namespace).setText(airport.getCode()));
|
|
||||||
airportElement.addContent(new Element("name", namespace).setText(airport.getName()));
|
|
||||||
airportElement.addContent(new Element("city", namespace).setText(airport.getCity()));
|
|
||||||
return airportElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Element createServiceClassElement(ServiceClass serviceClass) {
|
|
||||||
Element serviceClassElement = new Element("serviceClass", namespace);
|
|
||||||
if (ServiceClass.BUSINESS.equals(serviceClass)) {
|
|
||||||
serviceClassElement.setText("business");
|
|
||||||
}
|
|
||||||
else if (ServiceClass.ECONOMY.equals(serviceClass)) {
|
|
||||||
serviceClassElement.setText("economy");
|
|
||||||
}
|
|
||||||
else if (ServiceClass.FIRST.equals(serviceClass)) {
|
|
||||||
serviceClassElement.setText("first");
|
|
||||||
}
|
|
||||||
return serviceClassElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void afterPropertiesSet() throws Exception {
|
|
||||||
namespace = Namespace.getNamespace("tns", "http://www.springframework.org/spring-ws/samples/airline/schemas");
|
|
||||||
flightNumberXPath = XPath.newInstance("/tns:BookFlightRequest/tns:flightNumber/text()");
|
|
||||||
flightNumberXPath.addNamespace(namespace);
|
|
||||||
departureTimeXPath = XPath.newInstance("/tns:BookFlightRequest/tns:departureTime/text()");
|
|
||||||
departureTimeXPath.addNamespace(namespace);
|
|
||||||
passengersXPath = XPath.newInstance("/tns:BookFlightRequest/tns:passengers/*");
|
|
||||||
passengersXPath.addNamespace(namespace);
|
|
||||||
parser = ISODateTimeFormat.dateTimeParser().withZone(DateTimeZone.UTC);
|
|
||||||
dateTimeFormatter = ISODateTimeFormat.dateTimeNoMillis();
|
|
||||||
dateFormatter = ISODateTimeFormat.date();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,135 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2006 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.ws.samples.airline.ws;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.joda.time.Chronology;
|
|
||||||
import org.joda.time.DateTimeZone;
|
|
||||||
import org.joda.time.LocalDate;
|
|
||||||
import org.joda.time.chrono.ISOChronology;
|
|
||||||
import org.springframework.ws.samples.airline.schema.Airport;
|
|
||||||
import org.springframework.ws.samples.airline.schema.Flight;
|
|
||||||
import org.springframework.ws.samples.airline.schema.GetFlightsRequest;
|
|
||||||
import org.springframework.ws.samples.airline.schema.GetFlightsResponse;
|
|
||||||
import org.springframework.ws.samples.airline.schema.ServiceClass;
|
|
||||||
import org.springframework.ws.samples.airline.schema.impl.AirportImpl;
|
|
||||||
import org.springframework.ws.samples.airline.schema.impl.FlightImpl;
|
|
||||||
import org.springframework.ws.samples.airline.schema.impl.GetFlightsResponseImpl;
|
|
||||||
import org.springframework.ws.samples.airline.service.AirlineService;
|
|
||||||
import org.springframework.ws.server.endpoint.AbstractMarshallingPayloadEndpoint;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Endpoint that returns a list of flights with a given number, and that lie between a given start and end date. It uses
|
|
||||||
* JAXB-based marshalling for both request and response objects. Because we use separate POJOs for our schema and our
|
|
||||||
* domain objects, we need to convert the response domain objects to schema-based objects.
|
|
||||||
*
|
|
||||||
* @author Arjen Poutsma
|
|
||||||
*/
|
|
||||||
public class GetFlightsEndpoint extends AbstractMarshallingPayloadEndpoint {
|
|
||||||
|
|
||||||
private AirlineService airlineService;
|
|
||||||
|
|
||||||
public void setAirlineService(AirlineService airlineService) {
|
|
||||||
this.airlineService = airlineService;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Object invokeInternal(Object requestObject) throws Exception {
|
|
||||||
GetFlightsRequest request = (GetFlightsRequest) requestObject;
|
|
||||||
|
|
||||||
DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(request.getDepartureDate().getTimeZone());
|
|
||||||
Chronology chronology = ISOChronology.getInstance(dateTimeZone);
|
|
||||||
LocalDate departureDate = new LocalDate(request.getDepartureDate(), chronology);
|
|
||||||
if (logger.isDebugEnabled()) {
|
|
||||||
logger.debug("Request for flights from '" + request.getFrom() + "' to '" + request.getTo() + "' on " +
|
|
||||||
departureDate);
|
|
||||||
}
|
|
||||||
List flights = airlineService.getFlights(request.getFrom(), request.getTo(), departureDate,
|
|
||||||
convertToDomainType(request.getServiceClass()));
|
|
||||||
if (logger.isDebugEnabled()) {
|
|
||||||
logger.debug("Marshalling " + flights.size() + " flight results");
|
|
||||||
}
|
|
||||||
GetFlightsResponse response = new GetFlightsResponseImpl();
|
|
||||||
for (Iterator iter = flights.iterator(); iter.hasNext();) {
|
|
||||||
org.springframework.ws.samples.airline.domain.Flight domainFlight =
|
|
||||||
(org.springframework.ws.samples.airline.domain.Flight) iter.next();
|
|
||||||
Flight schemaFlight = convertToSchemaType(domainFlight);
|
|
||||||
response.getFlight().add(schemaFlight);
|
|
||||||
}
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Flight convertToSchemaType(org.springframework.ws.samples.airline.domain.Flight domainFlight) {
|
|
||||||
Flight schemaFlight = new FlightImpl();
|
|
||||||
schemaFlight.setNumber(domainFlight.getNumber());
|
|
||||||
schemaFlight.setDepartureTime(domainFlight.getDepartureTime().toGregorianCalendar());
|
|
||||||
schemaFlight.setFrom(convertToSchemaType(domainFlight.getFrom()));
|
|
||||||
schemaFlight.setArrivalTime(domainFlight.getArrivalTime().toGregorianCalendar());
|
|
||||||
schemaFlight.setTo(convertToSchemaType(domainFlight.getTo()));
|
|
||||||
schemaFlight.setServiceClass(convertToSchemaType(domainFlight.getServiceClass()));
|
|
||||||
return schemaFlight;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Airport convertToSchemaType(org.springframework.ws.samples.airline.domain.Airport domainAirport) {
|
|
||||||
if (domainAirport == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Airport schemaAirport = new AirportImpl();
|
|
||||||
schemaAirport.setCode(domainAirport.getCode());
|
|
||||||
schemaAirport.setName(domainAirport.getName());
|
|
||||||
schemaAirport.setCity(domainAirport.getCity());
|
|
||||||
return schemaAirport;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ServiceClass convertToSchemaType(org.springframework.ws.samples.airline.domain.ServiceClass domainServiceClass) {
|
|
||||||
if (domainServiceClass == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else if (domainServiceClass.equals(org.springframework.ws.samples.airline.domain.ServiceClass.BUSINESS)) {
|
|
||||||
return ServiceClass.BUSINESS;
|
|
||||||
}
|
|
||||||
else if (domainServiceClass.equals(org.springframework.ws.samples.airline.domain.ServiceClass.ECONOMY)) {
|
|
||||||
return ServiceClass.ECONOMY;
|
|
||||||
}
|
|
||||||
else if (domainServiceClass.equals(org.springframework.ws.samples.airline.domain.ServiceClass.FIRST)) {
|
|
||||||
return ServiceClass.FIRST;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new IllegalArgumentException("Invalid domain service class: [" + domainServiceClass + "]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private org.springframework.ws.samples.airline.domain.ServiceClass convertToDomainType(ServiceClass schemaServiceClass) {
|
|
||||||
if (schemaServiceClass == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else if (schemaServiceClass.equals(ServiceClass.BUSINESS)) {
|
|
||||||
return org.springframework.ws.samples.airline.domain.ServiceClass.BUSINESS;
|
|
||||||
}
|
|
||||||
else if (schemaServiceClass.equals(ServiceClass.ECONOMY)) {
|
|
||||||
return org.springframework.ws.samples.airline.domain.ServiceClass.ECONOMY;
|
|
||||||
}
|
|
||||||
else if (schemaServiceClass.equals(ServiceClass.FIRST)) {
|
|
||||||
return org.springframework.ws.samples.airline.domain.ServiceClass.FIRST;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new IllegalArgumentException("Invalid schema service class: [" + schemaServiceClass + "]");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.ws.samples.airline.ws;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.xml.bind.JAXBElement;
|
||||||
|
import javax.xml.datatype.DatatypeConfigurationException;
|
||||||
|
import javax.xml.datatype.XMLGregorianCalendar;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.joda.time.DateTime;
|
||||||
|
import org.joda.time.LocalDate;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.ws.samples.airline.domain.FrequentFlyer;
|
||||||
|
import org.springframework.ws.samples.airline.domain.Passenger;
|
||||||
|
import org.springframework.ws.samples.airline.schema.BookFlightRequest;
|
||||||
|
import org.springframework.ws.samples.airline.schema.Flight;
|
||||||
|
import org.springframework.ws.samples.airline.schema.GetFlightsRequest;
|
||||||
|
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.ServiceClass;
|
||||||
|
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.server.endpoint.annotation.Endpoint;
|
||||||
|
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Endpoint that handles the Airline Web Service messages using JAXB2 marshalling.
|
||||||
|
* <p/>
|
||||||
|
* This endpoint contains exactly the same logic as the {@link XPathAirlineEndpoint}, and is only provided as an
|
||||||
|
* example. Typically, you will not have two endpoints with the same logic.
|
||||||
|
*
|
||||||
|
* @author Arjen Poutsma
|
||||||
|
*/
|
||||||
|
@Endpoint
|
||||||
|
public class MarshallingAirlineEndpoint implements AirlineWebServiceConstants {
|
||||||
|
|
||||||
|
private static final Log logger = LogFactory.getLog(MarshallingAirlineEndpoint.class);
|
||||||
|
|
||||||
|
private AirlineService airlineService;
|
||||||
|
|
||||||
|
private ObjectFactory objectFactory = new ObjectFactory();
|
||||||
|
|
||||||
|
public MarshallingAirlineEndpoint(AirlineService airlineService) {
|
||||||
|
Assert.notNull(airlineService, "airlineService must not be null");
|
||||||
|
this.airlineService = airlineService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This endpoint method uses marshalling to handle message with a <code><GetFlightsRequest></code> payload.
|
||||||
|
*
|
||||||
|
* @param request the JAXB2 representation of a <code><GetFlightsRequest></code>
|
||||||
|
*/
|
||||||
|
@PayloadRoot(localPart = "GetFlightsRequest", namespace = NAMESPACE)
|
||||||
|
public GetFlightsResponse getFlights(GetFlightsRequest request) throws DatatypeConfigurationException {
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("Received GetFlightsRequest '" + request.getFrom() + "' to '" + request.getTo() + "' on " +
|
||||||
|
request.getDepartureDate());
|
||||||
|
}
|
||||||
|
List<Flight> flights = getSchemaFlights(request.getFrom(), request.getTo(), request.getDepartureDate(),
|
||||||
|
request.getServiceClass());
|
||||||
|
GetFlightsResponse response = new GetFlightsResponse();
|
||||||
|
for (Flight flight : flights) {
|
||||||
|
response.getFlight().add(flight);
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Converts between the domain and schema types. */
|
||||||
|
private List<Flight> getSchemaFlights(String from,
|
||||||
|
String to,
|
||||||
|
XMLGregorianCalendar xmlDepartureDate,
|
||||||
|
ServiceClass xmlServiceClass) throws DatatypeConfigurationException {
|
||||||
|
LocalDate domainDepartureDate = SchemaConversionUtils.toLocalDate(xmlDepartureDate);
|
||||||
|
org.springframework.ws.samples.airline.domain.ServiceClass domainServiceClass =
|
||||||
|
SchemaConversionUtils.toDomainType(xmlServiceClass);
|
||||||
|
List<org.springframework.ws.samples.airline.domain.Flight> domainFlights =
|
||||||
|
airlineService.getFlights(from, to, domainDepartureDate, domainServiceClass);
|
||||||
|
return SchemaConversionUtils.toSchemaType(domainFlights);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This endpoint method uses marshalling to handle message with a <code><BookFlightRequest></code> payload.
|
||||||
|
*
|
||||||
|
* @param request the JAXB2 representation of a <code><BookFlightRequest></code>
|
||||||
|
* @return the JAXB2 representation of a <code><BookFlightResponse></code>
|
||||||
|
*/
|
||||||
|
@PayloadRoot(localPart = "BookFlightRequest", namespace = NAMESPACE)
|
||||||
|
public JAXBElement<Ticket> bookFlight(BookFlightRequest request)
|
||||||
|
throws NoSeatAvailableException, DatatypeConfigurationException, NoSuchFlightException {
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("Received BookingFlightRequest '" + request.getFlightNumber() + "' on '" +
|
||||||
|
request.getDepartureTime() + "' for " + request.getPassengers().getPassengerOrUsername());
|
||||||
|
}
|
||||||
|
Ticket ticket = bookSchemaFlight(request.getFlightNumber(), request.getDepartureTime(),
|
||||||
|
request.getPassengers().getPassengerOrUsername());
|
||||||
|
return objectFactory.createBookFlightResponse(ticket);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Converts between the domain and schema types. */
|
||||||
|
private Ticket bookSchemaFlight(String flightNumber,
|
||||||
|
XMLGregorianCalendar xmlDepartureTime,
|
||||||
|
List<Object> passengerOrUsernameList)
|
||||||
|
throws NoSeatAvailableException, NoSuchFlightException, DatatypeConfigurationException {
|
||||||
|
DateTime departureTime = SchemaConversionUtils.toDateTime(xmlDepartureTime);
|
||||||
|
List<Passenger> passengers = new ArrayList<Passenger>(passengerOrUsernameList.size());
|
||||||
|
for (Iterator<Object> iterator = passengerOrUsernameList.iterator(); iterator.hasNext();) {
|
||||||
|
Object passengerOrUsername = iterator.next();
|
||||||
|
if (passengerOrUsername instanceof Name) {
|
||||||
|
Name passengerName = (Name) passengerOrUsername;
|
||||||
|
Passenger passenger = new Passenger(passengerName.getFirst(), passengerName.getLast());
|
||||||
|
passengers.add(passenger);
|
||||||
|
}
|
||||||
|
else if (passengerOrUsername instanceof String) {
|
||||||
|
String frequentFlyerUsername = (String) passengerOrUsername;
|
||||||
|
FrequentFlyer frequentFlyer = new FrequentFlyer(frequentFlyerUsername);
|
||||||
|
passengers.add(frequentFlyer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
org.springframework.ws.samples.airline.domain.Ticket domainTicket =
|
||||||
|
airlineService.bookFlight(flightNumber, departureTime, passengers);
|
||||||
|
return SchemaConversionUtils.toSchemaType(domainTicket);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This endpoint method uses marshalling to handle message with a <code><GetFrequentFlyerMileageRequest></code>
|
||||||
|
* payload.
|
||||||
|
*
|
||||||
|
* @param ignored is ignored
|
||||||
|
* @return the JAXB2 representation of a <code><GetFrequentFlyerMileageResponse></code>
|
||||||
|
*/
|
||||||
|
@PayloadRoot(localPart = "GetFrequentFlyerMileageRequest", namespace = NAMESPACE)
|
||||||
|
public JAXBElement<Integer> getFrequentFlyerMileage(JAXBElement<String> ignored) {
|
||||||
|
logger.debug("Received GetFrequentFlyerMileageRequest request");
|
||||||
|
int result = airlineService.getFrequentFlyerMileage();
|
||||||
|
return objectFactory.createGetFrequentFlyerMileageResponse(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,177 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.ws.samples.airline.ws;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.xml.bind.JAXBElement;
|
||||||
|
import javax.xml.bind.JAXBException;
|
||||||
|
import javax.xml.datatype.DatatypeConfigurationException;
|
||||||
|
import javax.xml.transform.Source;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.joda.time.DateTime;
|
||||||
|
import org.joda.time.LocalDate;
|
||||||
|
import org.springframework.oxm.Marshaller;
|
||||||
|
import org.springframework.oxm.support.MarshallingSource;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.ws.samples.airline.domain.Flight;
|
||||||
|
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.domain.Ticket;
|
||||||
|
import org.springframework.ws.samples.airline.schema.GetFlightsResponse;
|
||||||
|
import org.springframework.ws.samples.airline.schema.ObjectFactory;
|
||||||
|
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.server.endpoint.annotation.Endpoint;
|
||||||
|
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
|
||||||
|
import org.springframework.ws.server.endpoint.annotation.XPathParam;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Endpoint that handles the Airline Web Service request messages using XPath expressions, and creates response messages
|
||||||
|
* using JAXB2.
|
||||||
|
* <p/>
|
||||||
|
* This endpoint contains exactly the same logic as the {@link MarshallingAirlineEndpoint}, and is only provided as an
|
||||||
|
* example. Typically, you will not have two endpoints with the same logic.
|
||||||
|
*
|
||||||
|
* @author Arjen Poutsma
|
||||||
|
*/
|
||||||
|
@Endpoint
|
||||||
|
public class XPathAirlineEndpoint implements AirlineWebServiceConstants {
|
||||||
|
|
||||||
|
private static final Log logger = LogFactory.getLog(XPathAirlineEndpoint.class);
|
||||||
|
|
||||||
|
private AirlineService airlineService;
|
||||||
|
|
||||||
|
private ObjectFactory objectFactory = new ObjectFactory();
|
||||||
|
|
||||||
|
private Marshaller marshaller;
|
||||||
|
|
||||||
|
public XPathAirlineEndpoint(AirlineService airlineService, Marshaller marshaller) {
|
||||||
|
Assert.notNull(airlineService, "airlineService must not be null");
|
||||||
|
Assert.notNull(marshaller, "'marshaller' must not be null");
|
||||||
|
this.airlineService = airlineService;
|
||||||
|
this.marshaller = marshaller;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This endpoint method uses XPath to handle message with a <code><GetFlightsRequest></code> payload.
|
||||||
|
*
|
||||||
|
* @param from the from airport
|
||||||
|
* @param to the to airport
|
||||||
|
* @param departureDateString the string representation of the departure date
|
||||||
|
* @param serviceClassString the string representation of the service class
|
||||||
|
*/
|
||||||
|
@PayloadRoot(localPart = "GetFlightsRequest", namespace = NAMESPACE)
|
||||||
|
public Source getFlights(@XPathParam("//tns:from")String from,
|
||||||
|
@XPathParam("//tns:to")String to,
|
||||||
|
@XPathParam("//tns:departureDate")String departureDateString,
|
||||||
|
@XPathParam("//tns:serviceClass")String serviceClassString)
|
||||||
|
throws DatatypeConfigurationException {
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("Received GetFlightsRequest '" + from + "' to '" + to + "' on " + departureDateString);
|
||||||
|
}
|
||||||
|
LocalDate departureDate = new LocalDate(departureDateString);
|
||||||
|
ServiceClass serviceClass = null;
|
||||||
|
if (StringUtils.hasLength(serviceClassString)) {
|
||||||
|
serviceClass = ServiceClass.valueOf(serviceClassString);
|
||||||
|
}
|
||||||
|
List<Flight> flights = airlineService.getFlights(from, to, departureDate, serviceClass);
|
||||||
|
|
||||||
|
GetFlightsResponse response = objectFactory.createGetFlightsResponse();
|
||||||
|
for (Flight domainFlight : flights) {
|
||||||
|
response.getFlight().add(SchemaConversionUtils.toSchemaType(domainFlight));
|
||||||
|
}
|
||||||
|
return new MarshallingSource(marshaller, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This endpoint method uses XPath to handle message with a <code><BookFlightRequest></code> payload.
|
||||||
|
*
|
||||||
|
* @param flightNumber the flight number
|
||||||
|
* @param departureTimeString the string representation of the departure time
|
||||||
|
* @param passengerNodes the passenger nodes
|
||||||
|
* @param frequentFlyerNodes the frequent flyer nodes
|
||||||
|
*/
|
||||||
|
@PayloadRoot(localPart = "BookFlightRequest", namespace = NAMESPACE)
|
||||||
|
public Source bookFlight(@XPathParam("//tns:flightNumber")String flightNumber,
|
||||||
|
@XPathParam("//tns:departureTime")String departureTimeString,
|
||||||
|
@XPathParam("//tns:passengers/tns:passenger")NodeList passengerNodes,
|
||||||
|
@XPathParam("//tns:passengers/tns:username")NodeList frequentFlyerNodes)
|
||||||
|
throws NoSeatAvailableException, NoSuchFlightException, DatatypeConfigurationException, JAXBException {
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("Received BookingFlightRequest '" + flightNumber + "' on '" + departureTimeString + "' for " +
|
||||||
|
passengerNodes.getLength() + " passengers and " + frequentFlyerNodes.getLength() +
|
||||||
|
" frequent flyers");
|
||||||
|
}
|
||||||
|
DateTime departureTime = new DateTime(departureTimeString);
|
||||||
|
List<Passenger> passengers = new ArrayList<Passenger>();
|
||||||
|
parsePassengers(passengerNodes, passengers);
|
||||||
|
parseFrequentFlyers(frequentFlyerNodes, passengers);
|
||||||
|
Ticket domainTicket = airlineService.bookFlight(flightNumber, departureTime, passengers);
|
||||||
|
|
||||||
|
JAXBElement<org.springframework.ws.samples.airline.schema.Ticket> response =
|
||||||
|
objectFactory.createBookFlightResponse(SchemaConversionUtils.toSchemaType(domainTicket));
|
||||||
|
return new MarshallingSource(marshaller, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void parsePassengers(NodeList passengerNodes, List<Passenger> passengers) {
|
||||||
|
for (int i = 0; i < passengerNodes.getLength(); i++) {
|
||||||
|
if (passengerNodes.item(i).getNodeType() != Node.ELEMENT_NODE) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Element passengerElement = (Element) passengerNodes.item(i);
|
||||||
|
Element firstNameElement = (Element) passengerElement.getElementsByTagNameNS(NAMESPACE, "first").item(0);
|
||||||
|
Element lastNameElement = (Element) passengerElement.getElementsByTagNameNS(NAMESPACE, "last").item(0);
|
||||||
|
Passenger passenger = new Passenger(firstNameElement.getTextContent(), lastNameElement.getTextContent());
|
||||||
|
passengers.add(passenger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void parseFrequentFlyers(NodeList frequentFlyerNodes, List<Passenger> passengers) {
|
||||||
|
for (int i = 0; i < frequentFlyerNodes.getLength(); i++) {
|
||||||
|
if (frequentFlyerNodes.item(i).getNodeType() != Node.ELEMENT_NODE) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Element frequentFlyerElement = (Element) frequentFlyerNodes.item(i);
|
||||||
|
FrequentFlyer frequentFlyer = new FrequentFlyer(frequentFlyerElement.getTextContent());
|
||||||
|
passengers.add(frequentFlyer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This endpoint method uses XPath to handle message with a <code><GetFrequentFlyerMileageRequest></code>
|
||||||
|
* payload.
|
||||||
|
*/
|
||||||
|
@PayloadRoot(localPart = "GetFrequentFlyerMileageRequest", namespace = NAMESPACE)
|
||||||
|
public Source getFrequentFlyerMileage() {
|
||||||
|
logger.debug("Received GetFrequentFlyerMileageRequest request");
|
||||||
|
int result = airlineService.getFrequentFlyerMileage();
|
||||||
|
JAXBElement<Integer> response = objectFactory.createGetFrequentFlyerMileageResponse(result);
|
||||||
|
return new MarshallingSource(marshaller, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
14
samples/airline/src/main/resources/META-INF/persistence.xml
Normal file
14
samples/airline/src/main/resources/META-INF/persistence.xml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
|
||||||
|
version="1.0">
|
||||||
|
<persistence-unit name="airline">
|
||||||
|
<class>org.springframework.ws.samples.airline.domain.Airport</class>
|
||||||
|
<class>org.springframework.ws.samples.airline.domain.Flight</class>
|
||||||
|
<class>org.springframework.ws.samples.airline.domain.FrequentFlyer</class>
|
||||||
|
<class>org.springframework.ws.samples.airline.domain.Passenger</class>
|
||||||
|
<class>org.springframework.ws.samples.airline.domain.Ticket</class>
|
||||||
|
</persistence-unit>
|
||||||
|
|
||||||
|
</persistence>
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:util="http://www.springframework.org/schema/util"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||||
|
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
|
||||||
|
|
||||||
|
|
||||||
|
<bean id="flightDao" class="org.springframework.ws.samples.airline.dao.jpa.JpaFlightDao">
|
||||||
|
<description>
|
||||||
|
A DAO for Flights.
|
||||||
|
</description>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean id="ticketDao" class="org.springframework.ws.samples.airline.dao.jpa.JpaTicketDao">
|
||||||
|
<description>
|
||||||
|
A DAO for Tickets.
|
||||||
|
</description>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
|
<bean id="frequentFlyerDao" class="org.springframework.ws.samples.airline.dao.jpa.JpaFrequentFlyerDao">
|
||||||
|
<description>
|
||||||
|
A DAO for FrequentFlyers.
|
||||||
|
</description>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
|
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
|
||||||
|
<property name="dataSource" ref="dataSource"/>
|
||||||
|
<property name="jpaVendorAdapter">
|
||||||
|
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
|
||||||
|
</property>
|
||||||
|
<property name="jpaProperties">
|
||||||
|
<util:properties location="classpath:org/springframework/ws/samples/airline/dao/jpa/hibernate.properties"/>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
|
||||||
|
<property name="entityManagerFactory" ref="entityManagerFactory"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
|
||||||
|
<property name="driverClassName" value="${jdbc.driverClassName}"/>
|
||||||
|
<property name="url" value="${jdbc.url}"/>
|
||||||
|
<property name="username" value="${jdbc.username}"/>
|
||||||
|
<property name="password" value="${jdbc.password}"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||||
|
<property name="locations" value="classpath:org/springframework/ws/samples/airline/dao/jdbc.properties"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor">
|
||||||
|
<description>
|
||||||
|
Handles the @Repository annotation used on the JPA Dao's, and translates from the JPA
|
||||||
|
exceptions to Spring's richer DataAccessException hierarchy.
|
||||||
|
</description>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor">
|
||||||
|
<description>
|
||||||
|
Injects the JPA PersistenceContext into the JPA Dao's.
|
||||||
|
</description>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
|
</beans>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2007 the original author or authors.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
# Properties file with hibernate-related settings.
|
||||||
|
|
||||||
|
hibernate.dialect=${hibernate.dialect}
|
||||||
|
hibernate.hbm2ddl.auto=${hibernate.hbm2ddl.auto}
|
||||||
|
hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider
|
||||||
@@ -1,26 +1,18 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
This application context contains the WS-Security and Acegi beans.
|
This application context contains the WS-Security and Acegi beans.
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<bean id="securityService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
|
<bean id="securityService"
|
||||||
|
class="org.springframework.ws.samples.airline.security.AcegiFrequentFlyerSecurityService">
|
||||||
<description>
|
<description>
|
||||||
A transactional security service used to obtain Frequent Flyer information.
|
A transactional security service used to obtain Frequent Flyer information.
|
||||||
</description>
|
</description>
|
||||||
<property name="target">
|
<property name="frequentFlyerDao" ref="frequentFlyerDao"/>
|
||||||
<bean class="org.springframework.ws.samples.airline.security.AcegiFrequentFlyerSecurityService">
|
|
||||||
<property name="frequentFlyerDao" ref="frequentFlyerDao"/>
|
|
||||||
</bean>
|
|
||||||
</property>
|
|
||||||
<property name="transactionManager" ref="transactionManager"/>
|
|
||||||
<property name="transactionAttributes">
|
|
||||||
<props>
|
|
||||||
<prop key="get*">PROPAGATION_REQUIRED</prop>
|
|
||||||
</props>
|
|
||||||
</property>
|
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- ===================== WS-SECURITY ============================== -->
|
<!-- ===================== WS-SECURITY ============================== -->
|
||||||
@@ -56,19 +48,11 @@
|
|||||||
value="classpath:org/springframework/ws/samples/airline/security/securityPolicy.xml"/>
|
value="classpath:org/springframework/ws/samples/airline/security/securityPolicy.xml"/>
|
||||||
<property name="callbackHandler">
|
<property name="callbackHandler">
|
||||||
<bean class="org.springframework.ws.soap.security.xwss.callback.acegi.AcegiDigestPasswordValidationCallbackHandler">
|
<bean class="org.springframework.ws.soap.security.xwss.callback.acegi.AcegiDigestPasswordValidationCallbackHandler">
|
||||||
<property name="userDetailsService" ref="userDetailsService"/>
|
<property name="userDetailsService" ref="securityService"/>
|
||||||
</bean>
|
</bean>
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="getFrequentFlyerMileageEndpoint"
|
|
||||||
class="org.springframework.ws.samples.airline.security.GetFrequentFlyerMileageEndpoint">
|
|
||||||
<description>
|
|
||||||
This endpoint handles get frequent flier mileage requests.
|
|
||||||
</description>
|
|
||||||
<property name="airlineService" ref="airlineService"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<!-- ======================== ACEGI AUTHENTICATION ======================= -->
|
<!-- ======================== ACEGI AUTHENTICATION ======================= -->
|
||||||
|
|
||||||
<bean id="authenticationManager" class="org.acegisecurity.providers.ProviderManager">
|
<bean id="authenticationManager" class="org.acegisecurity.providers.ProviderManager">
|
||||||
@@ -77,15 +61,11 @@
|
|||||||
</description>
|
</description>
|
||||||
<property name="providers">
|
<property name="providers">
|
||||||
<bean class="org.acegisecurity.providers.dao.DaoAuthenticationProvider">
|
<bean class="org.acegisecurity.providers.dao.DaoAuthenticationProvider">
|
||||||
<property name="userDetailsService" ref="userDetailsService"/>
|
<property name="userDetailsService" ref="securityService"/>
|
||||||
</bean>
|
</bean>
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="userDetailsService" class="org.springframework.ws.samples.airline.security.FrequentFlyerDetailsService">
|
|
||||||
<property name="frequentFlyerDao" ref="frequentFlyerDao"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<bean id="loggerListener" class="org.acegisecurity.event.authentication.LoggerListener"/>
|
<bean id="loggerListener" class="org.acegisecurity.event.authentication.LoggerListener"/>
|
||||||
|
|
||||||
<!-- ======================== ACEGI AUTHORIZATION =========================== -->
|
<!-- ======================== ACEGI AUTHORIZATION =========================== -->
|
||||||
@@ -103,9 +83,11 @@
|
|||||||
</bean>
|
</bean>
|
||||||
</property>
|
</property>
|
||||||
<property name="objectDefinitionSource">
|
<property name="objectDefinitionSource">
|
||||||
<value>
|
<bean class="org.acegisecurity.intercept.method.MethodDefinitionAttributes">
|
||||||
org.springframework.ws.samples.airline.service.AirlineService.getFrequentFlyerMileage=ROLE_FREQUENT_FLYER
|
<property name="attributes">
|
||||||
</value>
|
<bean class="org.acegisecurity.annotation.SecurityAnnotationAttributes"/>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,53 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?><!--
|
||||||
|
~ Copyright 2007 the original author or authors.
|
||||||
|
~
|
||||||
|
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
~ you may not use this file except in compliance with the License.
|
||||||
|
~ You may obtain a copy of the License at
|
||||||
|
~
|
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~
|
||||||
|
~ Unless required by applicable law or agreed to in writing, software
|
||||||
|
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
~ See the License for the specific language governing permissions and
|
||||||
|
~ limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||||
|
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
|
||||||
|
|
||||||
<bean id="airlineServiceTarget" class="org.springframework.ws.samples.airline.service.impl.AirlineServiceImpl">
|
<tx:annotation-driven/>
|
||||||
<property name="flightDao" ref="flightDao"/>
|
|
||||||
<property name="ticketDao" ref="ticketDao"/>
|
<bean id="airlineService" class="org.springframework.ws.samples.airline.service.impl.AirlineServiceImpl">
|
||||||
<!-- Remove the following line if you want to disable WS-Security and Acegi -->
|
<constructor-arg ref="flightDao"/>
|
||||||
<property name="frequentFlyerSecurityService" ref="securityService"/>
|
<constructor-arg ref="ticketDao"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="airlineService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
|
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
|
||||||
<property name="target" ref="airlineServiceTarget"/>
|
<description>
|
||||||
<property name="transactionManager" ref="transactionManager"/>
|
The MessageFactory is used to create new SOAP messages from incoming requests. It is referenced to in
|
||||||
<property name="transactionAttributes">
|
airline-servlet.xml.
|
||||||
<props>
|
</description>
|
||||||
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
|
|
||||||
<prop key="book*">PROPAGATION_REQUIRED</prop>
|
|
||||||
</props>
|
|
||||||
</property>
|
|
||||||
<!-- Remove the following line if you want to disable WS-Security and Acegi -->
|
|
||||||
<property name="postInterceptors" ref="methodSecurityInterceptor"/>
|
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<bean id="airlineService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
|
||||||
|
<property name="target" ref="airlineServiceTarget"/>
|
||||||
|
<property name="transactionManager" ref="transactionManager"/>
|
||||||
|
<property name="transactionAttributes">
|
||||||
|
<props>
|
||||||
|
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
|
||||||
|
<prop key="book*">PROPAGATION_REQUIRED</prop>
|
||||||
|
</props>
|
||||||
|
</property>
|
||||||
|
-->
|
||||||
|
<!-- Remove the following line if you want to disable WS-Security and Acegi -->
|
||||||
|
<!--
|
||||||
|
<property name="postInterceptors" ref="methodSecurityInterceptor"/>
|
||||||
|
</bean>
|
||||||
|
-->
|
||||||
</beans>
|
</beans>
|
||||||
@@ -1,153 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
|
||||||
<description>
|
|
||||||
This application context contains the Spring-WS beans.
|
|
||||||
</description>
|
|
||||||
|
|
||||||
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
|
|
||||||
<description>
|
|
||||||
The MessageFactory is used to create new SOAP messages from incoming requests. It is referenced in
|
|
||||||
airline-servlet.xml and applicationContext-ws-jms.xml.
|
|
||||||
</description>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<bean id="messageDispatcher" class="org.springframework.ws.soap.server.SoapMessageDispatcher">
|
|
||||||
<description>
|
|
||||||
The MessageDispatcher is responsible for routing messages to endpoints. It uses three endpoint mappings to
|
|
||||||
determine the endpoint suitable for handling a particular incoming request. Having three mappings is not a
|
|
||||||
recommended approach, it's done here only for illustration purposes.
|
|
||||||
</description>
|
|
||||||
<property name="endpointMappings">
|
|
||||||
<list>
|
|
||||||
<ref local="payloadMapping"/>
|
|
||||||
<ref local="soapActionMapping"/>
|
|
||||||
<!-- Remove the following line if you want to disable WS-Security and Acegi -->
|
|
||||||
<ref bean="secureMapping"/>
|
|
||||||
</list>
|
|
||||||
</property>
|
|
||||||
<property name="endpointExceptionResolvers">
|
|
||||||
<list>
|
|
||||||
<ref local="endpointExceptionResolver"/>
|
|
||||||
</list>
|
|
||||||
</property>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<bean id="airlineWsdl" class="org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition">
|
|
||||||
<description>
|
|
||||||
This bean definition represents the airline.wsdl file found in the root of the web application. It is used
|
|
||||||
by the WsdlDefinitionHandlerAdapter in airline-servlet.xml.
|
|
||||||
</description>
|
|
||||||
<property name="wsdl" value="/airline.wsdl"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<bean id="payloadMapping" class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
|
|
||||||
<description>
|
|
||||||
This endpoint mapping uses the qualified name of the payload (body contents) to determine the endpoint for
|
|
||||||
an incoming message. The name GetFlightsRequest with namespace
|
|
||||||
http://www.springframework.org/spring-ws/samples/airline/schemas is mapped to the getFlightsEndpoint.
|
|
||||||
Additionally, messages are logged using the logging interceptor.
|
|
||||||
</description>
|
|
||||||
<property name="mappings">
|
|
||||||
<props>
|
|
||||||
<prop key="{http://www.springframework.org/spring-ws/samples/airline/schemas}GetFlightsRequest">
|
|
||||||
getFlightsEndpoint
|
|
||||||
</prop>
|
|
||||||
</props>
|
|
||||||
</property>
|
|
||||||
<property name="interceptors">
|
|
||||||
<ref local="loggingInterceptor"/>
|
|
||||||
</property>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<bean id="soapActionMapping" class="org.springframework.ws.soap.server.endpoint.mapping.SoapActionEndpointMapping">
|
|
||||||
<description>
|
|
||||||
This endpoint mapping uses SOAP Actions to determine the endpoint for an incoming message. The key
|
|
||||||
http://www.springframework.org/spring-ws/samples/airline/BookFlight is mapped to the bookFlightEndpoint.
|
|
||||||
Additionally, message are logged and validated.
|
|
||||||
</description>
|
|
||||||
<property name="mappings">
|
|
||||||
<props>
|
|
||||||
<prop key="http://www.springframework.org/spring-ws/samples/airline/BookFlight">
|
|
||||||
bookFlightEndpoint
|
|
||||||
</prop>
|
|
||||||
</props>
|
|
||||||
</property>
|
|
||||||
<property name="interceptors">
|
|
||||||
<list>
|
|
||||||
<ref local="loggingInterceptor"/>
|
|
||||||
<ref local="validatingInterceptor"/>
|
|
||||||
</list>
|
|
||||||
</property>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<bean id="validatingInterceptor"
|
|
||||||
class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
|
|
||||||
<description>
|
|
||||||
This interceptor validates both incoming and outgoing message contents according to the 'airline.xsd' XML
|
|
||||||
Schema file.
|
|
||||||
</description>
|
|
||||||
<property name="schema" value="airline.xsd"/>
|
|
||||||
<property name="validateRequest" value="true"/>
|
|
||||||
<property name="validateResponse" value="true"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<bean id="loggingInterceptor" class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor">
|
|
||||||
<description>
|
|
||||||
This interceptor logs the message payload.
|
|
||||||
</description>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<bean id="bookFlightEndpoint" class="org.springframework.ws.samples.airline.ws.BookFlightEndpoint">
|
|
||||||
<description>
|
|
||||||
This endpoint handles book flight request.
|
|
||||||
</description>
|
|
||||||
<property name="airlineService" ref="airlineService"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<bean id="getFlightsEndpoint" class="org.springframework.ws.samples.airline.ws.GetFlightsEndpoint">
|
|
||||||
<description>
|
|
||||||
This endpoint handles get flights request.
|
|
||||||
</description>
|
|
||||||
<property name="airlineService" ref="airlineService"/>
|
|
||||||
<property name="marshaller" ref="jaxbMarshaller"/>
|
|
||||||
<property name="unmarshaller" ref="jaxbMarshaller"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb1Marshaller">
|
|
||||||
<description>
|
|
||||||
The validating JAXB Marshaller is used by the getFlightsEndpoint to unmarshal XML to objects and
|
|
||||||
vice-versa.
|
|
||||||
</description>
|
|
||||||
<property name="contextPath" value="org.springframework.ws.samples.airline.schema"/>
|
|
||||||
<property name="validating" value="true"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<bean id="endpointExceptionResolver"
|
|
||||||
class="org.springframework.ws.soap.server.endpoint.SoapFaultMappingExceptionResolver">
|
|
||||||
<description>
|
|
||||||
This exception resolver maps exceptions to SOAP Faults. The business logic exceptions
|
|
||||||
NoSeatAvailableException and NoSuchFlightException are mapped to custom SOAP Fault. Both
|
|
||||||
UnmarshallingException andValidationFailureException are mapped to a SOAP Fault with a "Sender" fault code.
|
|
||||||
All other exceptions are mapped to a "Receiver" error code, the default.
|
|
||||||
</description>
|
|
||||||
<property name="defaultFault">
|
|
||||||
<value>RECEIVER,Server error</value>
|
|
||||||
</property>
|
|
||||||
<property name="exceptionMappings">
|
|
||||||
<props>
|
|
||||||
<prop key="org.springframework.ws.samples.airline.service.NoSeatAvailableException">
|
|
||||||
{http://www.springframework.org/spring-ws/samples/airline}airline:NoMoreSeats, No more seats
|
|
||||||
available
|
|
||||||
</prop>
|
|
||||||
<prop key="org.springframework.ws.samples.airline.service.NoSuchFlightException">
|
|
||||||
{http://www.springframework.org/spring-ws/samples/airline}airline:NoSuchFlight, No such flight
|
|
||||||
exists
|
|
||||||
</prop>
|
|
||||||
<prop key="org.springframework.oxm.UnmarshallingFailureException">SENDER,Invalid request</prop>
|
|
||||||
<prop key="org.springframework.oxm.ValidationFailureException">SENDER,Invalid request</prop>
|
|
||||||
</props>
|
|
||||||
</property>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
</beans>
|
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
INSERT INTO AIRPORT(CODE, NAME, CITY) VALUES('AMS', 'Schiphol Airport', 'Amsterdam');
|
INSERT INTO AIRPORT(CODE, NAME, CITY) VALUES('AMS', 'Schiphol Airport', 'Amsterdam');
|
||||||
INSERT INTO AIRPORT(CODE, NAME, CITY) VALUES('VCE', 'Marco Polo Airport', 'Venice');
|
INSERT INTO AIRPORT(CODE, NAME, CITY) VALUES('VCE', 'Marco Polo Airport', 'Venice');
|
||||||
|
|
||||||
INSERT INTO FLIGHT(ID, NUMBER, DEPARTURE_TIME, FROM_AIRPORT_CODE, ARRIVAL_TIME, TO_AIRPORT_CODE, SERVICE_CLASS, SEATS_AVAILABLE, MILES) VALUES (1,'KL1653','2006-01-31 10:05:00', 'AMS', '2006-01-31 12:25:00', 'VCE', 'economy', 5, 200);
|
INSERT INTO FLIGHT(ID, NUMBER, DEPARTURE_TIME, FROM_AIRPORT_CODE, ARRIVAL_TIME, TO_AIRPORT_CODE, SERVICE_CLASS, SEATS_AVAILABLE, MILES) VALUES (1,'KL1653','2006-01-31 10:05:00', 'AMS', '2006-01-31 12:25:00', 'VCE', 'ECONOMY', 5, 200);
|
||||||
INSERT INTO FLIGHT(ID, NUMBER, DEPARTURE_TIME, FROM_AIRPORT_CODE, ARRIVAL_TIME, TO_AIRPORT_CODE, SERVICE_CLASS, SEATS_AVAILABLE, MILES) VALUES (2,'KL1654','2006-02-05 12:40:00', 'VCE', '2006-02-05 14:15:00', 'AMS', 'economy', 5, 200);
|
|
||||||
|
INSERT INTO FLIGHT(ID, NUMBER, DEPARTURE_TIME, FROM_AIRPORT_CODE, ARRIVAL_TIME, TO_AIRPORT_CODE, SERVICE_CLASS, SEATS_AVAILABLE, MILES) VALUES (2,'KL1654','2006-02-05 12:40:00', 'VCE', '2006-02-05 14:15:00', 'AMS', 'ECONOMY', 5, 200);
|
||||||
|
|
||||||
INSERT INTO PASSENGER(ID, FIRST_NAME, LAST_NAME) VALUES (1, 'John', 'Doe');
|
INSERT INTO PASSENGER(ID, FIRST_NAME, LAST_NAME) VALUES (1, 'John', 'Doe');
|
||||||
INSERT INTO FREQUENT_FLYER(PASSENGER_ID, USERNAME, PASSWORD, MILES) VALUES (1, 'john', 'changeme', 10);
|
INSERT INTO FREQUENT_FLYER(PASSENGER_ID, USERNAME, PASSWORD, MILES) VALUES (1, 'john', 'changeme', 10);
|
||||||
13
samples/airline/src/main/webapp/WEB-INF/jsp/error.jsp
Normal file
13
samples/airline/src/main/webapp/WEB-INF/jsp/error.jsp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||||
|
<html>
|
||||||
|
<%
|
||||||
|
Exception ex = (Exception) request.getAttribute("exception");
|
||||||
|
%>
|
||||||
|
<head><title><%= ex.getMessage() %>
|
||||||
|
</title></head>
|
||||||
|
<body>
|
||||||
|
<h2><%= ex.getMessage() %>
|
||||||
|
</h2>
|
||||||
|
<a href='<c:url value="/flights"/>'>Flights</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
47
samples/airline/src/main/webapp/WEB-INF/jsp/flight.jsp
Normal file
47
samples/airline/src/main/webapp/WEB-INF/jsp/flight.jsp
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||||
|
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||||
|
<%@ taglib prefix="joda" uri="http://www.joda.org/joda/time/tags" %>
|
||||||
|
<html>
|
||||||
|
<head><title>Flights</title></head>
|
||||||
|
<body>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>Number:</td>
|
||||||
|
<td>
|
||||||
|
<c:out value="${flight.number}"/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>From:</td>
|
||||||
|
<td>
|
||||||
|
<c:out value="${flight.from.city}"/>
|
||||||
|
(
|
||||||
|
<c:out value="${flight.from.code}"/>
|
||||||
|
)
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Departure:</td>
|
||||||
|
<td>
|
||||||
|
<joda:format value="${flight.departureTime}" style="MM"/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>To:</td>
|
||||||
|
<td>
|
||||||
|
<c:out value="${flight.to.city}"/>
|
||||||
|
(
|
||||||
|
<c:out value="${flight.to.code}"/>
|
||||||
|
)
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Departure:</td>
|
||||||
|
<td>
|
||||||
|
<joda:format value="${flight.arrivalTime}" style="MM"/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<a href='<c:url value="/flights"/>'>Flights</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
71
samples/airline/src/main/webapp/WEB-INF/jsp/flights.jsp
Normal file
71
samples/airline/src/main/webapp/WEB-INF/jsp/flights.jsp
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||||
|
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||||
|
<%@ taglib prefix="joda" uri="http://www.joda.org/joda/time/tags" %>
|
||||||
|
<html>
|
||||||
|
<head><title>Flights</title></head>
|
||||||
|
<body>
|
||||||
|
<form a method="get" action='<c:url value="/flights"/>'>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>From:</td>
|
||||||
|
<td><input name="from" value='<c:out value="${from}" default="AMS"/>'/></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>To:</td>
|
||||||
|
<td><input name="to" value="<c:out value="${to}" default="VCE"/>"/></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Departure Date:</td>
|
||||||
|
<td><input name="departureDate" value="<c:out value="${departureDate}" default="2006-01-31"/>"/></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Service Class:</td>
|
||||||
|
<td>
|
||||||
|
<select name="serviceClass">
|
||||||
|
<option value="ECONOMY" selected="selected">Economy</option>
|
||||||
|
<option value="BUSINESS">Business</option>
|
||||||
|
<option value="FIRST">First</option>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<input type="submit" value="Submit"/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<c:if test="${!empty flights}">
|
||||||
|
<table border="1px">
|
||||||
|
<tr>
|
||||||
|
<th>Number</th>
|
||||||
|
<th>Departs</th>
|
||||||
|
<th>Arrives</th>
|
||||||
|
</tr>
|
||||||
|
<c:forEach var="flight" items="${flights}">
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<a href='<c:url value="flights/${flight.id}"/>'>
|
||||||
|
<c:out value="${flight.number}"/>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<c:out value="${flight.from.city}"/>
|
||||||
|
(
|
||||||
|
<c:out value="${flight.from.code}"/>
|
||||||
|
)
|
||||||
|
<joda:format value="${flight.departureTime}" style="SS"/>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<c:out value="${flight.to.city}"/>
|
||||||
|
(
|
||||||
|
<c:out value="${flight.to.code}"/>
|
||||||
|
)
|
||||||
|
<joda:format value="${flight.arrivalTime}" style="SS"/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</c:forEach>
|
||||||
|
</table>
|
||||||
|
</c:if>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
13
samples/airline/src/main/webapp/WEB-INF/jsp/noSuchFlight.jsp
Normal file
13
samples/airline/src/main/webapp/WEB-INF/jsp/noSuchFlight.jsp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||||
|
<html>
|
||||||
|
<head><title>No Such Flight</title></head>
|
||||||
|
<body>
|
||||||
|
<%
|
||||||
|
Exception ex = (Exception) request.getAttribute("exception");
|
||||||
|
%>
|
||||||
|
<h2>No such flight: <%= ex.getMessage() %>
|
||||||
|
</h2>
|
||||||
|
<a href='<c:url value="/flights"/>'>Flights</a>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
54
samples/airline/src/main/webapp/WEB-INF/mvc-servlet.xml
Normal file
54
samples/airline/src/main/webapp/WEB-INF/mvc-servlet.xml
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||||
|
|
||||||
|
<description>
|
||||||
|
This web application context contains a simple Spring Web MVC web application that shows flights
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<!-- ===================== HANDLER MAPPINGS ============================== -->
|
||||||
|
|
||||||
|
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
|
||||||
|
<property name="mappings">
|
||||||
|
<props>
|
||||||
|
<prop key="/flights">flightController</prop>
|
||||||
|
<prop key="/flights/*">flightController</prop>
|
||||||
|
</props>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- ===================== HANDLERS ===================================== -->
|
||||||
|
|
||||||
|
<bean id="flightController" class="org.springframework.ws.samples.airline.web.FlightsController">
|
||||||
|
<constructor-arg ref="airlineService"/>
|
||||||
|
<property name="methodNameResolver">
|
||||||
|
<bean class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
|
||||||
|
<property name="mappings">
|
||||||
|
<props>
|
||||||
|
<prop key="/flights">flightList</prop>
|
||||||
|
<prop key="/flights/*">singleFlight</prop>
|
||||||
|
</props>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
||||||
|
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
|
||||||
|
<property name="prefix" value="/WEB-INF/jsp/"/>
|
||||||
|
<property name="suffix" value=".jsp"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
|
||||||
|
<property name="defaultErrorView" value="error"/>
|
||||||
|
<property name="exceptionMappings">
|
||||||
|
<props>
|
||||||
|
<prop key="org.springframework.ws.samples.airline.service.NoSuchFlightException">noSuchFlight</prop>
|
||||||
|
</props>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
|
</beans>
|
||||||
@@ -1,36 +1,48 @@
|
|||||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
|
|
||||||
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
|
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
|
||||||
version="2.4">
|
version="2.4">
|
||||||
<display-name>Spring-WS Airline Sample</display-name>
|
<display-name>Spring-WS Airline Sample</display-name>
|
||||||
<context-param>
|
<context-param>
|
||||||
<param-name>contextConfigLocation</param-name>
|
<param-name>contextConfigLocation</param-name>
|
||||||
<param-value>
|
<param-value>
|
||||||
classpath:org/springframework/ws/samples/airline/dao/hibernate/applicationContext-hibernate.xml
|
classpath:org/springframework/ws/samples/airline/dao/jpa/applicationContext-jpa.xml
|
||||||
classpath:org/springframework/ws/samples/airline/service/applicationContext.xml
|
classpath:org/springframework/ws/samples/airline/service/applicationContext.xml
|
||||||
<!-- Remove the following line if you want to disable WS-Security and Acegi -->
|
<!-- Remove the following line if you want to disable WS-Security and Acegi -->
|
||||||
classpath:org/springframework/ws/samples/airline/security/applicationContext-security.xml
|
<!--classpath:org/springframework/ws/samples/airline/security/applicationContext-security.xml-->
|
||||||
classpath:org/springframework/ws/samples/airline/ws/applicationContext-ws.xml
|
<!--classpath:org/springframework/ws/samples/airline/ws/applicationContext-ws.xml-->
|
||||||
</param-value>
|
</param-value>
|
||||||
</context-param>
|
</context-param>
|
||||||
<listener>
|
<listener>
|
||||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||||
</listener>
|
</listener>
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>airline</servlet-name>
|
<servlet-name>ws</servlet-name>
|
||||||
|
<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>ws</servlet-name>
|
||||||
|
<url-pattern>/services</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>ws</servlet-name>
|
||||||
|
<url-pattern>*.wsdl</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>mvc</servlet-name>
|
||||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||||
</servlet>
|
</servlet>
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>airline</servlet-name>
|
<servlet-name>mvc</servlet-name>
|
||||||
<url-pattern>/Airline</url-pattern>
|
<url-pattern>/</url-pattern>
|
||||||
</servlet-mapping>
|
|
||||||
<servlet-mapping>
|
|
||||||
<servlet-name>airline</servlet-name>
|
|
||||||
<url-pattern>*.wsdl</url-pattern>
|
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
<mime-mapping>
|
<mime-mapping>
|
||||||
<extension>xsd</extension>
|
<extension>xsd</extension>
|
||||||
<mime-type>text/xml</mime-type>
|
<mime-type>text/xml</mime-type>
|
||||||
</mime-mapping>
|
</mime-mapping>
|
||||||
|
<welcome-file-list>
|
||||||
|
<welcome-file>index.html</welcome-file>
|
||||||
|
</welcome-file-list>
|
||||||
</web-app>
|
</web-app>
|
||||||
119
samples/airline/src/main/webapp/WEB-INF/ws-servlet.xml
Normal file
119
samples/airline/src/main/webapp/WEB-INF/ws-servlet.xml
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:util="http://www.springframework.org/schema/util"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||||
|
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
|
||||||
|
|
||||||
|
<!-- ===================== ENDPOINTS ===================================== -->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<bean id="marshallingEndpoint" class="org.springframework.ws.samples.airline.ws.MarshallingAirlineEndpoint">
|
||||||
|
<description>
|
||||||
|
This endpoint handles the Airline Web Service messages using JAXB2 marshalling.
|
||||||
|
</description>
|
||||||
|
<constructor-arg ref="airlineService"/>
|
||||||
|
</bean>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<bean id="xpathEndpoint" class="org.springframework.ws.samples.airline.ws.XPathAirlineEndpoint">
|
||||||
|
<description>
|
||||||
|
This endpoint handles the Airline Web Service messages using XPath expressions and JAXB2 marshalling.
|
||||||
|
</description>
|
||||||
|
<constructor-arg ref="airlineService"/>
|
||||||
|
<constructor-arg ref="marshaller"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
|
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
|
||||||
|
<description>
|
||||||
|
The JAXB 2 Marshaller is used by the endpoints.
|
||||||
|
</description>
|
||||||
|
<property name="mtomEnabled" value="false"/>
|
||||||
|
<property name="contextPath" value="org.springframework.ws.samples.airline.schema"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- ===================== ENDPOINT MAPPINGS ============================== -->
|
||||||
|
|
||||||
|
<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping">
|
||||||
|
<description>
|
||||||
|
Detects @PayloadRoot annotations on @Endpoint bean methods. The MarshallingAirlineEndpoint
|
||||||
|
has such annotations. It uses two interceptors: one that logs the message payload, and the other validates
|
||||||
|
it accoring to the 'airline.xsd' schema file.
|
||||||
|
</description>
|
||||||
|
<property name="interceptors">
|
||||||
|
<list>
|
||||||
|
<bean class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor"/>
|
||||||
|
<bean class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
|
||||||
|
<property name="schema" value="/WEB-INF/xsd/airline.xsd"/>
|
||||||
|
<property name="validateRequest" value="true"/>
|
||||||
|
<property name="validateResponse" value="true"/>
|
||||||
|
</bean>
|
||||||
|
</list>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<!-- ===================== ENDPOINT ADAPTERS ============================== -->
|
||||||
|
|
||||||
|
<bean class="org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter">
|
||||||
|
<description>
|
||||||
|
This adapter allows for methods that need and returns marshalled objects. The MarshallingEndpoint
|
||||||
|
uses JAXB2 objects.
|
||||||
|
</description>
|
||||||
|
<constructor-arg ref="marshaller"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean class="org.springframework.ws.server.endpoint.adapter.XPathParamAnnotationMethodEndpointAdapter">
|
||||||
|
<description>
|
||||||
|
This adapter allows for methods that use @XPathParam annotations. The XPathAirlineEndpoint uses JAXB2 these.
|
||||||
|
</description>
|
||||||
|
<property name="namespaces">
|
||||||
|
<props>
|
||||||
|
<prop key="tns">http://www.springframework.org/spring-ws/samples/airline/schemas</prop>
|
||||||
|
</props>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- ===================== ENDPOINT EXCEPTION RESOLVER ===================== -->
|
||||||
|
|
||||||
|
<bean class="org.springframework.ws.soap.server.endpoint.SoapFaultMappingExceptionResolver">
|
||||||
|
<description>
|
||||||
|
This exception resolver maps exceptions to SOAP Faults. The business logic exceptions
|
||||||
|
NoSeatAvailableException and NoSuchFlightException are explictely mapped. Both
|
||||||
|
UnmarshallingException andValidationFailureException are mapped to a SOAP Fault with a "Sender" fault code.
|
||||||
|
All other exceptions are mapped to a "Server" error code, the default.
|
||||||
|
</description>
|
||||||
|
<property name="defaultFault" value="SERVER"/>
|
||||||
|
<property name="exceptionMappings">
|
||||||
|
<props>
|
||||||
|
<prop key="org.springframework.ws.samples.airline.service.NoSuchFlightException">CLIENT</prop>
|
||||||
|
<prop key="org.springframework.ws.samples.airline.service.NoSeatAvailableException">SERVER</prop>
|
||||||
|
<prop key="org.springframework.oxm.UnmarshallingFailureException">CLIENT,Invalid request</prop>
|
||||||
|
<prop key="org.springframework.oxm.ValidationFailureException">CLIENT,Invalid request</prop>
|
||||||
|
</props>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<!-- ===================== WSDL DEFINITION ============================== -->
|
||||||
|
|
||||||
|
<bean id="airline" class="org.springframework.ws.wsdl.wsdl11.DynamicWsdl11Definition">
|
||||||
|
<description>
|
||||||
|
Dynamically builds a WSDL from the airline.xsd.This bean definition represents the airline.wsdl file found
|
||||||
|
in the root of the web application. It is used
|
||||||
|
by the WsdlDefinitionHandlerAdapter in airline-servlet.xml.
|
||||||
|
</description>
|
||||||
|
<property name="builder">
|
||||||
|
<bean class="org.springframework.ws.wsdl.wsdl11.builder.XsdBasedSoap11Wsdl4jDefinitionBuilder">
|
||||||
|
<property name="schema" value="/WEB-INF/xsd/airline.xsd"/>
|
||||||
|
<property name="portTypeName" value="Airline"/>
|
||||||
|
<property name="locationUri" value="http://localhost:8080/airline/services"/>
|
||||||
|
<property name="targetNamespace"
|
||||||
|
value="http://www.springframework.org/spring-ws/samples/airline/definitions"/>
|
||||||
|
</bean>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
|
</beans>
|
||||||
118
samples/airline/src/main/webapp/WEB-INF/xsd/airline.xsd
Normal file
118
samples/airline/src/main/webapp/WEB-INF/xsd/airline.xsd
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<schema xmlns="http://www.w3.org/2001/XMLSchema"
|
||||||
|
targetNamespace="http://www.springframework.org/spring-ws/samples/airline/schemas"
|
||||||
|
xmlns:tns="http://www.springframework.org/spring-ws/samples/airline/schemas"
|
||||||
|
elementFormDefault="qualified">
|
||||||
|
|
||||||
|
<element name="GetFlightsRequest">
|
||||||
|
<complexType>
|
||||||
|
<all>
|
||||||
|
<element name="from" type="tns:AirportCode"/>
|
||||||
|
<element name="to" type="tns:AirportCode"/>
|
||||||
|
<element name="departureDate" type="date"/>
|
||||||
|
<element name="serviceClass" type="tns:ServiceClass" minOccurs="0"/>
|
||||||
|
</all>
|
||||||
|
</complexType>
|
||||||
|
</element>
|
||||||
|
|
||||||
|
<element name="GetFlightsResponse">
|
||||||
|
<complexType>
|
||||||
|
<sequence>
|
||||||
|
<element name="flight" type="tns:Flight" minOccurs="0" maxOccurs="unbounded"/>
|
||||||
|
</sequence>
|
||||||
|
</complexType>
|
||||||
|
</element>
|
||||||
|
|
||||||
|
<element name="BookFlightRequest">
|
||||||
|
<complexType>
|
||||||
|
<all>
|
||||||
|
<element name="flightNumber" type="tns:FlightNumber"/>
|
||||||
|
<element name="departureTime" type="dateTime"/>
|
||||||
|
<element name="passengers">
|
||||||
|
<complexType>
|
||||||
|
<choice maxOccurs="9">
|
||||||
|
<element name="passenger" type="tns:Name"/>
|
||||||
|
<element name="username" type="tns:FrequentFlyerUsername"/>
|
||||||
|
</choice>
|
||||||
|
</complexType>
|
||||||
|
</element>
|
||||||
|
</all>
|
||||||
|
</complexType>
|
||||||
|
</element>
|
||||||
|
|
||||||
|
<element name="BookFlightResponse" type="tns:Ticket"/>
|
||||||
|
|
||||||
|
<element name="GetFrequentFlyerMileageRequest" nillable="true" type="string"/>
|
||||||
|
|
||||||
|
<element name="GetFrequentFlyerMileageResponse" type="int"/>
|
||||||
|
|
||||||
|
|
||||||
|
<complexType name="Flight">
|
||||||
|
<sequence>
|
||||||
|
<element name="number" type="tns:FlightNumber"/>
|
||||||
|
<element name="departureTime" type="dateTime"/>
|
||||||
|
<element name="from" type="tns:Airport"/>
|
||||||
|
<element name="arrivalTime" type="dateTime"/>
|
||||||
|
<element name="to" type="tns:Airport"/>
|
||||||
|
<element name="serviceClass" type="tns:ServiceClass"/>
|
||||||
|
</sequence>
|
||||||
|
</complexType>
|
||||||
|
|
||||||
|
<simpleType name="FlightNumber">
|
||||||
|
<restriction base="string">
|
||||||
|
<pattern value="[A-Z][A-Z][0-9][0-9][0-9][0-9]"/>
|
||||||
|
</restriction>
|
||||||
|
</simpleType>
|
||||||
|
|
||||||
|
<complexType name="Name">
|
||||||
|
<sequence>
|
||||||
|
<element name="first" type="string"/>
|
||||||
|
<element name="last" type="string"/>
|
||||||
|
</sequence>
|
||||||
|
</complexType>
|
||||||
|
|
||||||
|
<simpleType name="FrequentFlyerUsername">
|
||||||
|
<restriction base="string"/>
|
||||||
|
</simpleType>
|
||||||
|
|
||||||
|
|
||||||
|
<complexType name="Airport">
|
||||||
|
<all>
|
||||||
|
<element name="code" type="tns:AirportCode"/>
|
||||||
|
<element name="name" type="string"/>
|
||||||
|
<element name="city" type="string"/>
|
||||||
|
</all>
|
||||||
|
</complexType>
|
||||||
|
|
||||||
|
<simpleType name="AirportCode">
|
||||||
|
<restriction base="string">
|
||||||
|
<pattern value="[A-Z][A-Z][A-Z]"/>
|
||||||
|
</restriction>
|
||||||
|
</simpleType>
|
||||||
|
|
||||||
|
|
||||||
|
<complexType name="Ticket">
|
||||||
|
<all>
|
||||||
|
<element name="id" type="long"/>
|
||||||
|
<element name="issueDate" type="date"/>
|
||||||
|
<element name="passengers">
|
||||||
|
<complexType>
|
||||||
|
<sequence>
|
||||||
|
<element name="passenger" type="tns:Name" maxOccurs="9"/>
|
||||||
|
</sequence>
|
||||||
|
</complexType>
|
||||||
|
</element>
|
||||||
|
<element name="flight" type="tns:Flight"/>
|
||||||
|
</all>
|
||||||
|
</complexType>
|
||||||
|
|
||||||
|
<simpleType name="ServiceClass">
|
||||||
|
<restriction base="NCName">
|
||||||
|
<enumeration value="economy"/>
|
||||||
|
<enumeration value="business"/>
|
||||||
|
<enumeration value="first"/>
|
||||||
|
</restriction>
|
||||||
|
</simpleType>
|
||||||
|
|
||||||
|
|
||||||
|
</schema>
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.ws.samples.airline.dao.jpa;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.joda.time.DateTime;
|
||||||
|
import org.joda.time.Interval;
|
||||||
|
import org.springframework.test.jpa.AbstractJpaTests;
|
||||||
|
import org.springframework.ws.samples.airline.dao.FlightDao;
|
||||||
|
import org.springframework.ws.samples.airline.domain.Airport;
|
||||||
|
import org.springframework.ws.samples.airline.domain.Flight;
|
||||||
|
import org.springframework.ws.samples.airline.domain.ServiceClass;
|
||||||
|
|
||||||
|
public class JpaFlightDaoTest extends AbstractJpaTests {
|
||||||
|
|
||||||
|
private FlightDao flightDao;
|
||||||
|
|
||||||
|
private DateTime departureTime;
|
||||||
|
|
||||||
|
private DateTime arrivalTime;
|
||||||
|
|
||||||
|
private Interval interval;
|
||||||
|
|
||||||
|
private Airport fromAirport;
|
||||||
|
|
||||||
|
private Airport toAirport;
|
||||||
|
|
||||||
|
public void setFlightDao(FlightDao flightDao) {
|
||||||
|
this.flightDao = flightDao;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String[] getConfigPaths() {
|
||||||
|
return new String[]{"applicationContext-jpa.xml"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSetUpBeforeTransaction() throws Exception {
|
||||||
|
departureTime = new DateTime(2006, 1, 31, 10, 5, 0, 0);
|
||||||
|
arrivalTime = new DateTime(2006, 1, 31, 12, 25, 0, 0);
|
||||||
|
interval = departureTime.toLocalDate().toInterval();
|
||||||
|
fromAirport = new Airport("RTM", "Rotterdam Airport", "Rotterdam");
|
||||||
|
toAirport = new Airport("OSL", "Gardermoen", "Oslo");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSetUpInTransaction() throws Exception {
|
||||||
|
jdbcTemplate.update("INSERT INTO AIRPORT(CODE, NAME, CITY) VALUES('RTM', 'Rotterdam Airport', 'Rotterdam')");
|
||||||
|
jdbcTemplate.update("INSERT INTO AIRPORT(CODE, NAME, CITY) VALUES('OSL', 'Gardermoen', 'Oslo')");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetFlightsInPeriod() throws Exception {
|
||||||
|
jdbcTemplate
|
||||||
|
.update("INSERT INTO FLIGHT(NUMBER, DEPARTURE_TIME, FROM_AIRPORT_CODE, ARRIVAL_TIME, TO_AIRPORT_CODE, SERVICE_CLASS, SEATS_AVAILABLE, MILES) " +
|
||||||
|
"VALUES ('KL020','2006-01-31 10:05:00', 'RTM', '2006-01-31 12:25:00', 'OSL', 'BUSINESS', 90, 10)");
|
||||||
|
List<Flight> flights = flightDao.findFlights("RTM", "OSL", interval, ServiceClass.BUSINESS);
|
||||||
|
assertNotNull("Invalid result", flights);
|
||||||
|
assertEquals("Invalid amount of flights", 1, flights.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetFlightsOutOfPeriod() throws Exception {
|
||||||
|
jdbcTemplate
|
||||||
|
.update("INSERT INTO FLIGHT(NUMBER, DEPARTURE_TIME, FROM_AIRPORT_CODE, ARRIVAL_TIME, TO_AIRPORT_CODE, SERVICE_CLASS, SEATS_AVAILABLE, MILES) " +
|
||||||
|
"VALUES ('KL020','2006-01-31 10:05:00', 'RTM', '2006-01-31 12:25:00', 'OSL', 'BUSINESS', 90, 10)");
|
||||||
|
DateTime dateTime = new DateTime(2006, 6, 1, 0, 0, 0, 0);
|
||||||
|
List flights = flightDao.findFlights("RTM", "OSL", new Interval(dateTime, dateTime), ServiceClass.BUSINESS);
|
||||||
|
assertNotNull("Invalid result", flights);
|
||||||
|
assertEquals("Invalid amount of flights", 0, flights.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetFlightByNumberDepartureTime() throws Exception {
|
||||||
|
jdbcTemplate
|
||||||
|
.update("INSERT INTO FLIGHT(NUMBER, DEPARTURE_TIME, FROM_AIRPORT_CODE, ARRIVAL_TIME, TO_AIRPORT_CODE, SERVICE_CLASS, SEATS_AVAILABLE, MILES) " +
|
||||||
|
"VALUES ('KL020','2006-01-31 10:05:00', 'RTM', '2006-01-31 12:25:00', 'OSL', 'BUSINESS', 90, 10)");
|
||||||
|
Flight flight = flightDao.getFlight("KL020", departureTime);
|
||||||
|
assertNotNull("No flight returned", flight);
|
||||||
|
assertNotNull("Invalid flight id", flight.getId());
|
||||||
|
assertEquals("Invalid flight number", "KL020", flight.getNumber());
|
||||||
|
assertEquals("Invalid flight departure time", departureTime, flight.getDepartureTime());
|
||||||
|
assertEquals("Invalid flight arrival time", arrivalTime, flight.getArrivalTime());
|
||||||
|
assertEquals("Invalid flight from airport", fromAirport, flight.getFrom());
|
||||||
|
assertEquals("Invalid flight to airport", toAirport, flight.getTo());
|
||||||
|
assertEquals("Invalid flight service class", ServiceClass.BUSINESS, flight.getServiceClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testUpdate() throws Exception {
|
||||||
|
jdbcTemplate
|
||||||
|
.update("INSERT INTO FLIGHT(NUMBER, DEPARTURE_TIME, FROM_AIRPORT_CODE, ARRIVAL_TIME, TO_AIRPORT_CODE, SERVICE_CLASS, SEATS_AVAILABLE, MILES) " +
|
||||||
|
"VALUES ('KL020','2006-01-31 10:05:00', 'RTM', '2006-01-31 12:25:00', 'OSL', 'BUSINESS', 90, 10)");
|
||||||
|
Flight flight = flightDao.getFlight("KL020", departureTime);
|
||||||
|
flight.setSeatsAvailable(0);
|
||||||
|
flightDao.update(flight);
|
||||||
|
sharedEntityManager.flush();
|
||||||
|
int count = jdbcTemplate
|
||||||
|
.queryForInt("SELECT SEATS_AVAILABLE FROM FLIGHT WHERE ID = ?", new Object[]{flight.getId()});
|
||||||
|
assertEquals("Flight not updated", 0, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.ws.samples.airline.dao.jpa;
|
||||||
|
|
||||||
|
import org.springframework.test.jpa.AbstractJpaTests;
|
||||||
|
import org.springframework.ws.samples.airline.dao.FrequentFlyerDao;
|
||||||
|
import org.springframework.ws.samples.airline.domain.FrequentFlyer;
|
||||||
|
|
||||||
|
public class JpaFrequentFlyerDaoTest extends AbstractJpaTests {
|
||||||
|
|
||||||
|
private FrequentFlyerDao frequentFlyerDao;
|
||||||
|
|
||||||
|
public void setFrequentFlyerDao(FrequentFlyerDao frequentFlyerDao) {
|
||||||
|
this.frequentFlyerDao = frequentFlyerDao;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String[] getConfigPaths() {
|
||||||
|
return new String[]{"applicationContext-jpa.xml"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSetUpInTransaction() throws Exception {
|
||||||
|
jdbcTemplate
|
||||||
|
.update("INSERT INTO PASSENGER(ID, FIRST_NAME, LAST_NAME) " + "VALUES (42, 'Arjen', 'Poutsma')");
|
||||||
|
jdbcTemplate
|
||||||
|
.update("INSERT INTO FREQUENT_FLYER(PASSENGER_ID, USERNAME, PASSWORD, MILES) " +
|
||||||
|
"VALUES (42, 'arjen', 'changeme', 0)");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetByUsername() throws Exception {
|
||||||
|
FrequentFlyer flyer = frequentFlyerDao.get("arjen");
|
||||||
|
assertNotNull("No frequent flyer returned", flyer);
|
||||||
|
assertEquals("Invalid username", "arjen", flyer.getUsername());
|
||||||
|
assertEquals("Invalid password", "changeme", flyer.getPassword());
|
||||||
|
assertEquals("Invalid first name", "Arjen", flyer.getFirstName());
|
||||||
|
assertEquals("Invalid last name", "Poutsma", flyer.getLastName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.ws.samples.airline.dao.jpa;
|
||||||
|
|
||||||
|
import org.joda.time.DateTime;
|
||||||
|
import org.joda.time.DateTimeZone;
|
||||||
|
import org.joda.time.LocalDate;
|
||||||
|
import org.springframework.test.jpa.AbstractJpaTests;
|
||||||
|
import org.springframework.ws.samples.airline.dao.TicketDao;
|
||||||
|
import org.springframework.ws.samples.airline.domain.Airport;
|
||||||
|
import org.springframework.ws.samples.airline.domain.Flight;
|
||||||
|
import org.springframework.ws.samples.airline.domain.Passenger;
|
||||||
|
import org.springframework.ws.samples.airline.domain.ServiceClass;
|
||||||
|
import org.springframework.ws.samples.airline.domain.Ticket;
|
||||||
|
|
||||||
|
public class JpaTicketDaoTest extends AbstractJpaTests {
|
||||||
|
|
||||||
|
private TicketDao ticketDao;
|
||||||
|
|
||||||
|
private DateTime departureTime;
|
||||||
|
|
||||||
|
private DateTime arrivalTime;
|
||||||
|
|
||||||
|
private Flight flight;
|
||||||
|
|
||||||
|
private Passenger passenger;
|
||||||
|
|
||||||
|
public void setTicketDao(TicketDao ticketDao) {
|
||||||
|
this.ticketDao = ticketDao;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String[] getConfigPaths() {
|
||||||
|
return new String[]{"applicationContext-jpa.xml"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSetUpBeforeTransaction() throws Exception {
|
||||||
|
departureTime = new DateTime(2006, 1, 31, 10, 5, 0, 0, DateTimeZone.UTC);
|
||||||
|
arrivalTime = new DateTime(2006, 1, 31, 12, 25, 0, 0, DateTimeZone.UTC);
|
||||||
|
Airport fromAirport = new Airport("RTM", "Rotterdam Airport", "Rotterdam");
|
||||||
|
Airport toAirport = new Airport("OSL", "Gardermoen", "Oslo");
|
||||||
|
flight = new Flight(42L);
|
||||||
|
flight.setNumber("KL1653");
|
||||||
|
flight.setDepartureTime(departureTime);
|
||||||
|
flight.setFrom(fromAirport);
|
||||||
|
flight.setArrivalTime(arrivalTime);
|
||||||
|
flight.setTo(toAirport);
|
||||||
|
flight.setServiceClass(ServiceClass.BUSINESS);
|
||||||
|
flight.setSeatsAvailable(90);
|
||||||
|
passenger = new Passenger(42L, "Arjen", "Poutsma");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSetUpInTransaction() throws Exception {
|
||||||
|
jdbcTemplate.update("INSERT INTO AIRPORT(CODE, NAME, CITY) VALUES('RTM', 'Rotterdam Airport', 'Rotterdam')");
|
||||||
|
jdbcTemplate.update("INSERT INTO AIRPORT(CODE, NAME, CITY) VALUES('OSL', 'Gardermoen', 'Oslo')");
|
||||||
|
jdbcTemplate
|
||||||
|
.update("INSERT INTO FLIGHT(ID, NUMBER, DEPARTURE_TIME, FROM_AIRPORT_CODE, ARRIVAL_TIME, TO_AIRPORT_CODE, SERVICE_CLASS, SEATS_AVAILABLE, MILES) " +
|
||||||
|
"VALUES (42, 'KL020','2006-01-31 10:05:00', 'RTM', '2006-01-31 12:25:00', 'OSL', 'BUSINESS', 90, 10)");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSave() throws Exception {
|
||||||
|
Ticket ticket = new Ticket();
|
||||||
|
ticket.addPassenger(passenger);
|
||||||
|
ticket.setFlight(flight);
|
||||||
|
ticket.setIssueDate(new LocalDate());
|
||||||
|
int startTicketCount = jdbcTemplate.queryForInt("SELECT COUNT(0) FROM TICKET");
|
||||||
|
int startPassengerCount = jdbcTemplate.queryForInt("SELECT COUNT(0) FROM PASSENGER");
|
||||||
|
ticket = ticketDao.save(ticket);
|
||||||
|
sharedEntityManager.flush();
|
||||||
|
assertNotNull("No Id generated", ticket.getId());
|
||||||
|
int endTicketCount = jdbcTemplate.queryForInt("SELECT COUNT(0) FROM TICKET");
|
||||||
|
int endPassengerCount = jdbcTemplate.queryForInt("SELECT COUNT(0) FROM PASSENGER");
|
||||||
|
assertEquals("Flight not inserted", 1, endTicketCount - startTicketCount);
|
||||||
|
assertEquals("Passenger not inserted", 1, endPassengerCount - startPassengerCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -21,8 +21,7 @@ import org.acegisecurity.context.SecurityContext;
|
|||||||
import org.acegisecurity.context.SecurityContextHolder;
|
import org.acegisecurity.context.SecurityContextHolder;
|
||||||
import org.acegisecurity.context.SecurityContextImpl;
|
import org.acegisecurity.context.SecurityContextImpl;
|
||||||
import org.acegisecurity.providers.TestingAuthenticationToken;
|
import org.acegisecurity.providers.TestingAuthenticationToken;
|
||||||
import org.easymock.MockControl;
|
import static org.easymock.EasyMock.*;
|
||||||
|
|
||||||
import org.springframework.ws.samples.airline.dao.FrequentFlyerDao;
|
import org.springframework.ws.samples.airline.dao.FrequentFlyerDao;
|
||||||
import org.springframework.ws.samples.airline.domain.FrequentFlyer;
|
import org.springframework.ws.samples.airline.domain.FrequentFlyer;
|
||||||
|
|
||||||
@@ -30,15 +29,11 @@ public class AcegiFrequentFlyerSecurityServiceTest extends TestCase {
|
|||||||
|
|
||||||
private AcegiFrequentFlyerSecurityService securityService;
|
private AcegiFrequentFlyerSecurityService securityService;
|
||||||
|
|
||||||
private MockControl control;
|
private FrequentFlyerDao flyerDaoMock;
|
||||||
|
|
||||||
private FrequentFlyerDao mock;
|
|
||||||
|
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
securityService = new AcegiFrequentFlyerSecurityService();
|
flyerDaoMock = createMock(FrequentFlyerDao.class);
|
||||||
control = MockControl.createControl(FrequentFlyerDao.class);
|
securityService = new AcegiFrequentFlyerSecurityService(flyerDaoMock);
|
||||||
mock = (FrequentFlyerDao) control.getMock();
|
|
||||||
securityService.setFrequentFlyerDao(mock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetCurrentlyAuthenticatedFrequentFlyer() throws Exception {
|
public void testGetCurrentlyAuthenticatedFrequentFlyer() throws Exception {
|
||||||
@@ -48,18 +43,18 @@ public class AcegiFrequentFlyerSecurityServiceTest extends TestCase {
|
|||||||
SecurityContext context = new SecurityContextImpl();
|
SecurityContext context = new SecurityContextImpl();
|
||||||
context.setAuthentication(token);
|
context.setAuthentication(token);
|
||||||
SecurityContextHolder.setContext(context);
|
SecurityContextHolder.setContext(context);
|
||||||
control.replay();
|
replay(flyerDaoMock);
|
||||||
FrequentFlyer result = securityService.getCurrentlyAuthenticatedFrequentFlyer();
|
FrequentFlyer result = securityService.getCurrentlyAuthenticatedFrequentFlyer();
|
||||||
assertEquals("Invalid result", frequentFlyer, result);
|
assertEquals("Invalid result", frequentFlyer, result);
|
||||||
control.verify();
|
verify(flyerDaoMock);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetFrequentFlyer() throws Exception {
|
public void testGetFrequentFlyer() throws Exception {
|
||||||
FrequentFlyer frequentFlyer = new FrequentFlyer("john");
|
FrequentFlyer frequentFlyer = new FrequentFlyer("john");
|
||||||
control.expectAndReturn(mock.get("john"), frequentFlyer);
|
expect(flyerDaoMock.get("john")).andReturn(frequentFlyer);
|
||||||
control.replay();
|
replay(flyerDaoMock);
|
||||||
FrequentFlyer result = securityService.getFrequentFlyer("john");
|
FrequentFlyer result = securityService.getFrequentFlyer("john");
|
||||||
assertEquals("Invalid result", frequentFlyer, result);
|
assertEquals("Invalid result", frequentFlyer, result);
|
||||||
control.verify();
|
verify(flyerDaoMock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,8 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import org.easymock.MockControl;
|
import static org.easymock.EasyMock.*;
|
||||||
|
import org.easymock.IAnswer;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.springframework.ws.samples.airline.dao.FlightDao;
|
import org.springframework.ws.samples.airline.dao.FlightDao;
|
||||||
@@ -38,148 +39,153 @@ public class AirlineServiceImplTest extends TestCase {
|
|||||||
|
|
||||||
private AirlineServiceImpl airlineService;
|
private AirlineServiceImpl airlineService;
|
||||||
|
|
||||||
private MockControl flightDaoControl;
|
|
||||||
|
|
||||||
private FlightDao flightDaoMock;
|
private FlightDao flightDaoMock;
|
||||||
|
|
||||||
private MockControl ticketDaoControl;
|
|
||||||
|
|
||||||
private TicketDao ticketDaoMock;
|
private TicketDao ticketDaoMock;
|
||||||
|
|
||||||
private MockControl securityServiceControl;
|
|
||||||
|
|
||||||
private FrequentFlyerSecurityService securityServiceMock;
|
private FrequentFlyerSecurityService securityServiceMock;
|
||||||
|
|
||||||
protected void setUp() throws Exception {
|
private String flightNumber;
|
||||||
airlineService = new AirlineServiceImpl();
|
|
||||||
flightDaoControl = MockControl.createControl(FlightDao.class);
|
|
||||||
flightDaoMock = (FlightDao) flightDaoControl.getMock();
|
|
||||||
airlineService.setFlightDao(flightDaoMock);
|
|
||||||
ticketDaoControl = MockControl.createControl(TicketDao.class);
|
|
||||||
ticketDaoMock = (TicketDao) ticketDaoControl.getMock();
|
|
||||||
airlineService.setTicketDao(ticketDaoMock);
|
|
||||||
securityServiceControl = MockControl.createControl(FrequentFlyerSecurityService.class);
|
|
||||||
securityServiceMock = (FrequentFlyerSecurityService) securityServiceControl.getMock();
|
|
||||||
airlineService.setFrequentFlyerSecurityService(securityServiceMock);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void tearDown() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
flightDaoControl.verify();
|
flightDaoMock = createMock(FlightDao.class);
|
||||||
ticketDaoControl.verify();
|
ticketDaoMock = createMock(TicketDao.class);
|
||||||
securityServiceControl.verify();
|
airlineService = new AirlineServiceImpl(flightDaoMock, ticketDaoMock);
|
||||||
|
securityServiceMock = createMock(FrequentFlyerSecurityService.class);
|
||||||
|
airlineService.setFrequentFlyerSecurityService(securityServiceMock);
|
||||||
|
flightNumber = "AB1234";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBookFlight() throws Exception {
|
public void testBookFlight() throws Exception {
|
||||||
String flightNumber = "AB1234";
|
|
||||||
DateTime departureTime = new DateTime();
|
DateTime departureTime = new DateTime();
|
||||||
Passenger passenger = new Passenger("John", "Doe");
|
Passenger passenger = new Passenger("John", "Doe");
|
||||||
List passengers = new ArrayList();
|
List<Passenger> passengers = new ArrayList<Passenger>();
|
||||||
passengers.add(passenger);
|
passengers.add(passenger);
|
||||||
Flight flight = new Flight();
|
Flight flight = new Flight();
|
||||||
flight.setNumber(flightNumber);
|
flight.setNumber(flightNumber);
|
||||||
flight.setSeatsAvailable(10);
|
flight.setSeatsAvailable(10);
|
||||||
flightDaoControl.expectAndReturn(flightDaoMock.getFlight(flightNumber, departureTime), flight);
|
expect(flightDaoMock.getFlight(flightNumber, departureTime)).andReturn(flight);
|
||||||
flightDaoMock.update(flight);
|
expect(flightDaoMock.update(flight)).andReturn(flight);
|
||||||
ticketDaoMock.save(null);
|
Ticket ticket = new Ticket();
|
||||||
ticketDaoControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
ticket.setFlight(flight);
|
||||||
flightDaoControl.replay();
|
expect(ticketDaoMock.save(isA(Ticket.class))).andAnswer(new IAnswer<Ticket>() {
|
||||||
ticketDaoControl.replay();
|
public Ticket answer() throws Throwable {
|
||||||
securityServiceControl.replay();
|
return (Ticket) getCurrentArguments()[0];
|
||||||
Ticket ticket = airlineService.bookFlight(flightNumber, departureTime, passengers);
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
replay(flightDaoMock, ticketDaoMock, securityServiceMock);
|
||||||
|
|
||||||
|
ticket = airlineService.bookFlight(flightNumber, departureTime, passengers);
|
||||||
assertNotNull("Invalid ticket", ticket);
|
assertNotNull("Invalid ticket", ticket);
|
||||||
assertEquals("Invalid flight", flight, ticket.getFlight());
|
assertEquals("Invalid flight", flight, ticket.getFlight());
|
||||||
assertEquals("Invalid seats available", 9, flight.getSeatsAvailable());
|
assertEquals("Invalid seats available", 9, flight.getSeatsAvailable());
|
||||||
assertEquals("Invalid passengers count", 1, ticket.getPassengers().size());
|
assertEquals("Invalid passengers count", 1, ticket.getPassengers().size());
|
||||||
|
|
||||||
|
verify(flightDaoMock, ticketDaoMock, securityServiceMock);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBookFlightFrequentFlyer() throws Exception {
|
public void testBookFlightFrequentFlyer() throws Exception {
|
||||||
String flightNumber = "AB1234";
|
|
||||||
DateTime departureTime = new DateTime();
|
DateTime departureTime = new DateTime();
|
||||||
FrequentFlyer frequentFlyer = new FrequentFlyer("john", "changeme", "John", "Doe");
|
FrequentFlyer frequentFlyer = new FrequentFlyer("John", "Doe", "john", "changeme");
|
||||||
List passengers = new ArrayList();
|
List<Passenger> passengers = new ArrayList<Passenger>();
|
||||||
passengers.add(frequentFlyer);
|
passengers.add(frequentFlyer);
|
||||||
Flight flight = new Flight();
|
Flight flight = new Flight();
|
||||||
flight.setNumber(flightNumber);
|
flight.setNumber(flightNumber);
|
||||||
flight.setSeatsAvailable(1);
|
flight.setSeatsAvailable(1);
|
||||||
flight.setMiles(10);
|
flight.setMiles(10);
|
||||||
securityServiceControl.expectAndReturn(securityServiceMock.getFrequentFlyer("john"), frequentFlyer);
|
expect(securityServiceMock.getFrequentFlyer("john")).andReturn(frequentFlyer);
|
||||||
flightDaoControl.expectAndReturn(flightDaoMock.getFlight(flightNumber, departureTime), flight);
|
expect(flightDaoMock.getFlight(flightNumber, departureTime)).andReturn(flight);
|
||||||
flightDaoMock.update(flight);
|
expect(flightDaoMock.update(flight)).andReturn(flight);
|
||||||
ticketDaoMock.save(null);
|
expect(ticketDaoMock.save(isA(Ticket.class))).andAnswer(new IAnswer<Ticket>() {
|
||||||
ticketDaoControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
public Ticket answer() throws Throwable {
|
||||||
flightDaoControl.replay();
|
return (Ticket) getCurrentArguments()[0];
|
||||||
ticketDaoControl.replay();
|
}
|
||||||
securityServiceControl.replay();
|
});
|
||||||
|
|
||||||
|
replay(flightDaoMock, ticketDaoMock, securityServiceMock);
|
||||||
|
|
||||||
Ticket ticket = airlineService.bookFlight(flightNumber, departureTime, passengers);
|
Ticket ticket = airlineService.bookFlight(flightNumber, departureTime, passengers);
|
||||||
assertNotNull("Invalid ticket", ticket);
|
assertNotNull("Invalid ticket", ticket);
|
||||||
assertEquals("Invalid flight", flight, ticket.getFlight());
|
assertEquals("Invalid flight", flight, ticket.getFlight());
|
||||||
assertEquals("Invalid amount of miles", 10, frequentFlyer.getMiles());
|
assertEquals("Invalid amount of miles", 10, frequentFlyer.getMiles());
|
||||||
|
|
||||||
|
verify(flightDaoMock, ticketDaoMock, securityServiceMock);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBookFlightNoSeatAvailable() throws Exception {
|
public void testBookFlightNoSeatAvailable() throws Exception {
|
||||||
String flightNumber = "AB1234";
|
|
||||||
DateTime departureTime = new DateTime();
|
DateTime departureTime = new DateTime();
|
||||||
List passengers = Collections.singletonList(new Passenger());
|
List<Passenger> passengers = Collections.singletonList(new Passenger());
|
||||||
Flight flight = new Flight();
|
Flight flight = new Flight();
|
||||||
flightDaoControl.expectAndReturn(flightDaoMock.getFlight(flightNumber, departureTime), flight);
|
flight.setNumber("AB1234");
|
||||||
flightDaoControl.replay();
|
flight.setDepartureTime(new DateTime());
|
||||||
ticketDaoControl.replay();
|
expect(flightDaoMock.getFlight(flightNumber, departureTime)).andReturn(flight);
|
||||||
securityServiceControl.replay();
|
|
||||||
|
replay(flightDaoMock, ticketDaoMock, securityServiceMock);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
airlineService.bookFlight(flightNumber, departureTime, passengers);
|
airlineService.bookFlight(flightNumber, departureTime, passengers);
|
||||||
fail("Should have thrown an NoSeatAvailableException");
|
fail("Should have thrown an NoSeatAvailableException");
|
||||||
}
|
}
|
||||||
catch (NoSeatAvailableException ex) {
|
catch (NoSeatAvailableException ex) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
verify(flightDaoMock, ticketDaoMock, securityServiceMock);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBookFlightNoSuchFlight() throws Exception {
|
public void testBookFlightNoSuchFlight() throws Exception {
|
||||||
String flightNumber = "AB1234";
|
String flightNumber = "AB1234";
|
||||||
DateTime departureTime = new DateTime();
|
DateTime departureTime = new DateTime();
|
||||||
List passengers = Collections.singletonList(new Passenger());
|
List<Passenger> passengers = Collections.singletonList(new Passenger());
|
||||||
flightDaoControl.expectAndReturn(flightDaoMock.getFlight(flightNumber, departureTime), null);
|
expect(flightDaoMock.getFlight(flightNumber, departureTime)).andReturn(null);
|
||||||
flightDaoControl.replay();
|
|
||||||
ticketDaoControl.replay();
|
replay(flightDaoMock, ticketDaoMock, securityServiceMock);
|
||||||
securityServiceControl.replay();
|
|
||||||
try {
|
try {
|
||||||
airlineService.bookFlight(flightNumber, departureTime, passengers);
|
airlineService.bookFlight(flightNumber, departureTime, passengers);
|
||||||
fail("Should have thrown an NoSuchFlightException");
|
fail("Should have thrown an NoSuchFlightException");
|
||||||
}
|
}
|
||||||
catch (NoSuchFlightException ex) {
|
catch (NoSuchFlightException ex) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
verify(flightDaoMock, ticketDaoMock, securityServiceMock);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetFlights() throws Exception {
|
public void testGetFlights() throws Exception {
|
||||||
String toCode = "to";
|
|
||||||
String fromCode = "from";
|
|
||||||
LocalDate departureDate = new LocalDate(2006, 1, 31);
|
LocalDate departureDate = new LocalDate(2006, 1, 31);
|
||||||
Flight flight = new Flight();
|
Flight flight = new Flight();
|
||||||
List flights = new ArrayList();
|
List<Flight> flights = new ArrayList<Flight>();
|
||||||
flights.add(flight);
|
flights.add(flight);
|
||||||
flightDaoControl.expectAndReturn(
|
String toCode = "to";
|
||||||
flightDaoMock.findFlights(fromCode, toCode, departureDate.toInterval(), ServiceClass.ECONOMY), flights);
|
String fromCode = "from";
|
||||||
flightDaoControl.replay();
|
|
||||||
ticketDaoControl.replay();
|
|
||||||
securityServiceControl.replay();
|
|
||||||
|
|
||||||
List result = airlineService.getFlights(fromCode, toCode, departureDate, ServiceClass.ECONOMY);
|
expect(flightDaoMock.findFlights(fromCode, toCode, departureDate.toInterval(), ServiceClass.ECONOMY))
|
||||||
|
.andReturn(flights);
|
||||||
|
|
||||||
|
replay(flightDaoMock, ticketDaoMock, securityServiceMock);
|
||||||
|
|
||||||
|
List<Flight> result = airlineService.getFlights(fromCode, toCode, departureDate, ServiceClass.ECONOMY);
|
||||||
assertEquals("Invalid result", flights, result);
|
assertEquals("Invalid result", flights, result);
|
||||||
|
|
||||||
|
verify(flightDaoMock, ticketDaoMock, securityServiceMock);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetFlightsDefaultServiceClass() throws Exception {
|
public void testGetFlightsDefaultServiceClass() throws Exception {
|
||||||
String toCode = "to";
|
|
||||||
String fromCode = "from";
|
|
||||||
LocalDate departureDate = new LocalDate(2006, 1, 31);
|
LocalDate departureDate = new LocalDate(2006, 1, 31);
|
||||||
Flight flight = new Flight();
|
Flight flight = new Flight();
|
||||||
List flights = new ArrayList();
|
List<Flight> flights = new ArrayList<Flight>();
|
||||||
flights.add(flight);
|
flights.add(flight);
|
||||||
flightDaoControl.expectAndReturn(
|
String toCode = "to";
|
||||||
flightDaoMock.findFlights(fromCode, toCode, departureDate.toInterval(), ServiceClass.ECONOMY), flights);
|
String fromCode = "from";
|
||||||
flightDaoControl.replay();
|
|
||||||
ticketDaoControl.replay();
|
|
||||||
securityServiceControl.replay();
|
|
||||||
|
|
||||||
List result = airlineService.getFlights(fromCode, toCode, departureDate, null);
|
expect(flightDaoMock.findFlights(fromCode, toCode, departureDate.toInterval(), ServiceClass.ECONOMY))
|
||||||
|
.andReturn(flights);
|
||||||
|
|
||||||
|
replay(flightDaoMock, ticketDaoMock, securityServiceMock);
|
||||||
|
|
||||||
|
List<Flight> result = airlineService.getFlights(fromCode, toCode, departureDate, null);
|
||||||
assertEquals("Invalid result", flights, result);
|
assertEquals("Invalid result", flights, result);
|
||||||
|
|
||||||
|
verify(flightDaoMock, ticketDaoMock, securityServiceMock);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.ws.samples.airline.web;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import static org.easymock.EasyMock.*;
|
||||||
|
import org.joda.time.LocalDate;
|
||||||
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
|
import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
import org.springframework.ws.samples.airline.domain.Flight;
|
||||||
|
import org.springframework.ws.samples.airline.domain.ServiceClass;
|
||||||
|
import org.springframework.ws.samples.airline.service.AirlineService;
|
||||||
|
|
||||||
|
public class FlightsControllerTest extends TestCase {
|
||||||
|
|
||||||
|
private FlightsController flightsController;
|
||||||
|
|
||||||
|
private AirlineService airlineServiceMock;
|
||||||
|
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
airlineServiceMock = createMock(AirlineService.class);
|
||||||
|
flightsController = new FlightsController(airlineServiceMock);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testFlightList() throws Exception {
|
||||||
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
|
String from = "AMS";
|
||||||
|
request.setParameter("from", from);
|
||||||
|
String to = "VCE";
|
||||||
|
request.setParameter("to", to);
|
||||||
|
LocalDate departureDate = new LocalDate();
|
||||||
|
request.setParameter("departureDate", departureDate.toString());
|
||||||
|
ServiceClass serviceClass = ServiceClass.FIRST;
|
||||||
|
request.setParameter("serviceClass", serviceClass.toString());
|
||||||
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
|
List<Flight> flights = new ArrayList<Flight>();
|
||||||
|
flights.add(new Flight());
|
||||||
|
expect(airlineServiceMock.getFlights(from, to, departureDate, serviceClass)).andReturn(flights);
|
||||||
|
|
||||||
|
replay(airlineServiceMock);
|
||||||
|
|
||||||
|
ModelAndView mav = flightsController.flightList(request, response);
|
||||||
|
assertNotNull("No ModelAndView returned", mav);
|
||||||
|
assertEquals("Invalid view name", "flights", mav.getViewName());
|
||||||
|
assertTrue("No flights in ModelAndView", mav.getModel().containsKey("flights"));
|
||||||
|
verify(airlineServiceMock);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2006 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.ws.samples.airline.ws;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.custommonkey.xmlunit.XMLTestCase;
|
|
||||||
import org.custommonkey.xmlunit.XMLUnit;
|
|
||||||
import org.easymock.MockControl;
|
|
||||||
import org.jdom.Document;
|
|
||||||
import org.jdom.Element;
|
|
||||||
import org.jdom.input.SAXBuilder;
|
|
||||||
import org.jdom.output.XMLOutputter;
|
|
||||||
import org.joda.time.DateTime;
|
|
||||||
import org.joda.time.DateTimeZone;
|
|
||||||
import org.joda.time.YearMonthDay;
|
|
||||||
import org.springframework.ws.samples.airline.domain.Airport;
|
|
||||||
import org.springframework.ws.samples.airline.domain.Flight;
|
|
||||||
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.domain.Ticket;
|
|
||||||
import org.springframework.ws.samples.airline.service.AirlineService;
|
|
||||||
|
|
||||||
public class BookFlightEndpointTest extends XMLTestCase {
|
|
||||||
|
|
||||||
private BookFlightEndpoint endpoint;
|
|
||||||
|
|
||||||
private MockControl serviceControl;
|
|
||||||
|
|
||||||
private AirlineService serviceMock;
|
|
||||||
|
|
||||||
private DateTime departure;
|
|
||||||
|
|
||||||
private Ticket ticket;
|
|
||||||
|
|
||||||
private Document responseDocument;
|
|
||||||
|
|
||||||
private SAXBuilder saxBuilder;
|
|
||||||
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
XMLUnit.setIgnoreWhitespace(true);
|
|
||||||
endpoint = new BookFlightEndpoint();
|
|
||||||
serviceControl = MockControl.createControl(AirlineService.class);
|
|
||||||
serviceMock = (AirlineService) serviceControl.getMock();
|
|
||||||
endpoint.setAirlineService(serviceMock);
|
|
||||||
endpoint.afterPropertiesSet();
|
|
||||||
saxBuilder = new SAXBuilder();
|
|
||||||
responseDocument = saxBuilder.build(getClass().getResourceAsStream("bookFlightResponse.xml"));
|
|
||||||
departure = new DateTime(2006, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC);
|
|
||||||
DateTime arrival = new DateTime(2006, 2, 2, 0, 0, 0, 0, DateTimeZone.UTC);
|
|
||||||
Flight flight = new Flight();
|
|
||||||
flight.setNumber("EF1234");
|
|
||||||
flight.setDepartureTime(departure);
|
|
||||||
flight.setArrivalTime(arrival);
|
|
||||||
Airport from = new Airport("ABC", "Airport", "City");
|
|
||||||
Airport to = new Airport("DEF", "Airport", "City");
|
|
||||||
flight.setFrom(from);
|
|
||||||
flight.setTo(to);
|
|
||||||
flight.setServiceClass(ServiceClass.ECONOMY);
|
|
||||||
ticket = new Ticket();
|
|
||||||
ticket.setId(new Long(42));
|
|
||||||
ticket.setFlight(flight);
|
|
||||||
ticket.setIssueDate(new YearMonthDay(2006, 1, 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testInvoke() throws Exception {
|
|
||||||
Passenger passenger = new Passenger("John", "Doe");
|
|
||||||
List passengers = Collections.singletonList(passenger);
|
|
||||||
ticket.addPassenger(passenger);
|
|
||||||
serviceControl.expectAndReturn(serviceMock.bookFlight("EF1234", departure, passengers), ticket);
|
|
||||||
serviceControl.replay();
|
|
||||||
Document requestDocument = saxBuilder.build(getClass().getResourceAsStream("bookFlightRequest.xml"));
|
|
||||||
Element result = endpoint.invokeInternal(requestDocument.getRootElement());
|
|
||||||
assertNotNull("Invalid result", result);
|
|
||||||
Document resultDocument = new Document();
|
|
||||||
resultDocument.setRootElement(result);
|
|
||||||
XMLOutputter outputter = new XMLOutputter();
|
|
||||||
assertXMLEqual(outputter.outputString(responseDocument), outputter.outputString(resultDocument));
|
|
||||||
serviceControl.verify();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testInvokeFrequentFlyer() throws Exception {
|
|
||||||
FrequentFlyer frequentFlyer = new FrequentFlyer("john", "changeme", "John", "Doe");
|
|
||||||
List passengers = Collections.singletonList(frequentFlyer);
|
|
||||||
ticket.addPassenger(frequentFlyer);
|
|
||||||
serviceControl.expectAndReturn(serviceMock.bookFlight("EF1234", departure, passengers), ticket);
|
|
||||||
serviceControl.replay();
|
|
||||||
Document requestDocument =
|
|
||||||
saxBuilder.build(getClass().getResourceAsStream("bookFlightRequestFrequentFlyer.xml"));
|
|
||||||
Element result = endpoint.invokeInternal(requestDocument.getRootElement());
|
|
||||||
assertNotNull("Invalid result", result);
|
|
||||||
Document resultDocument = new Document();
|
|
||||||
resultDocument.setRootElement(result);
|
|
||||||
XMLOutputter outputter = new XMLOutputter();
|
|
||||||
assertXMLEqual(outputter.outputString(responseDocument), outputter.outputString(resultDocument));
|
|
||||||
serviceControl.verify();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2006 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.ws.samples.airline.ws;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import org.easymock.MockControl;
|
|
||||||
import org.joda.time.DateTime;
|
|
||||||
import org.joda.time.LocalDate;
|
|
||||||
import org.springframework.oxm.jaxb.Jaxb1Marshaller;
|
|
||||||
import org.springframework.ws.WebServiceMessage;
|
|
||||||
import org.springframework.ws.context.MessageContext;
|
|
||||||
import org.springframework.ws.samples.airline.domain.Flight;
|
|
||||||
import org.springframework.ws.samples.airline.schema.GetFlightsRequest;
|
|
||||||
import org.springframework.ws.samples.airline.schema.GetFlightsResponse;
|
|
||||||
import org.springframework.ws.samples.airline.schema.ServiceClass;
|
|
||||||
import org.springframework.ws.samples.airline.schema.impl.GetFlightsRequestImpl;
|
|
||||||
import org.springframework.ws.samples.airline.service.AirlineService;
|
|
||||||
import org.springframework.xml.transform.StringResult;
|
|
||||||
import org.springframework.xml.transform.StringSource;
|
|
||||||
|
|
||||||
public class GetFlightsEndpointTest extends TestCase {
|
|
||||||
|
|
||||||
private GetFlightsEndpoint endpoint;
|
|
||||||
|
|
||||||
private MockControl serviceControl;
|
|
||||||
|
|
||||||
private AirlineService serviceMock;
|
|
||||||
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
endpoint = new GetFlightsEndpoint();
|
|
||||||
serviceControl = MockControl.createControl(AirlineService.class);
|
|
||||||
serviceMock = (AirlineService) serviceControl.getMock();
|
|
||||||
endpoint.setAirlineService(serviceMock);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testInvoke() throws Exception {
|
|
||||||
String fromAirportCode = "ABC";
|
|
||||||
String toAirportCode = "DEF";
|
|
||||||
LocalDate departureDate = new LocalDate();
|
|
||||||
GetFlightsRequest request = new GetFlightsRequestImpl();
|
|
||||||
request.setFrom(fromAirportCode);
|
|
||||||
request.setTo(toAirportCode);
|
|
||||||
request.setDepartureDate(departureDate.toDateTimeAtMidnight().toGregorianCalendar());
|
|
||||||
request.setServiceClass(ServiceClass.FIRST);
|
|
||||||
List flights = new ArrayList();
|
|
||||||
Flight flight = new Flight();
|
|
||||||
flight.setNumber("1");
|
|
||||||
flight.setDepartureTime(new DateTime());
|
|
||||||
flight.setArrivalTime(new DateTime());
|
|
||||||
flights.add(flight);
|
|
||||||
serviceControl.expectAndReturn(serviceMock.getFlights(fromAirportCode, toAirportCode, departureDate,
|
|
||||||
org.springframework.ws.samples.airline.domain.ServiceClass.FIRST), flights);
|
|
||||||
serviceControl.replay();
|
|
||||||
GetFlightsResponse response = (GetFlightsResponse) endpoint.invokeInternal(request);
|
|
||||||
serviceControl.verify();
|
|
||||||
assertNotNull("Response is null", response);
|
|
||||||
assertEquals("Invalid amount of flights in response", 1, response.getFlight().size());
|
|
||||||
org.springframework.ws.samples.airline.schema.Flight responseFlight =
|
|
||||||
(org.springframework.ws.samples.airline.schema.Flight) response.getFlight().get(0);
|
|
||||||
assertEquals("Invalid flight number on flight", "1", responseFlight.getNumber());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testMarshalling() throws Exception {
|
|
||||||
Jaxb1Marshaller marshaller = new Jaxb1Marshaller();
|
|
||||||
marshaller.setContextPath("org.springframework.ws.samples.airline.schema");
|
|
||||||
marshaller.setValidating(true);
|
|
||||||
marshaller.afterPropertiesSet();
|
|
||||||
endpoint.setMarshaller(marshaller);
|
|
||||||
endpoint.setUnmarshaller(marshaller);
|
|
||||||
|
|
||||||
MockControl contextControl = MockControl.createControl(MessageContext.class);
|
|
||||||
MessageContext contextMock = (MessageContext) contextControl.getMock();
|
|
||||||
MockControl messageControl = MockControl.createControl(WebServiceMessage.class);
|
|
||||||
WebServiceMessage requestMock = (WebServiceMessage) messageControl.getMock();
|
|
||||||
WebServiceMessage responseMock = (WebServiceMessage) messageControl.getMock();
|
|
||||||
|
|
||||||
contextControl.expectAndReturn(contextMock.getRequest(), requestMock);
|
|
||||||
StringSource source = new StringSource(
|
|
||||||
"<GetFlightsRequest xmlns=\"http://www.springframework.org/spring-ws/samples/airline/schemas\"><from>AMS</from><to>VCE</to><departureDate>2006-01-31Z</departureDate></GetFlightsRequest>");
|
|
||||||
messageControl.expectAndReturn(requestMock.getPayloadSource(), source);
|
|
||||||
String fromAirportCode = "AMS";
|
|
||||||
String toAirportCode = "VCE";
|
|
||||||
LocalDate departureDate = new LocalDate(2006, 1, 31);
|
|
||||||
serviceControl.expectAndReturn(serviceMock.getFlights(fromAirportCode, toAirportCode, departureDate, null),
|
|
||||||
Collections.EMPTY_LIST);
|
|
||||||
contextControl.expectAndReturn(contextMock.getResponse(), responseMock);
|
|
||||||
StringResult result = new StringResult();
|
|
||||||
messageControl.expectAndReturn(responseMock.getPayloadResult(), result);
|
|
||||||
|
|
||||||
contextControl.replay();
|
|
||||||
messageControl.replay();
|
|
||||||
serviceControl.replay();
|
|
||||||
|
|
||||||
endpoint.invoke(contextMock);
|
|
||||||
|
|
||||||
contextControl.verify();
|
|
||||||
messageControl.verify();
|
|
||||||
serviceControl.verify();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.ws.samples.airline.ws;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import javax.xml.bind.JAXBElement;
|
||||||
|
import javax.xml.datatype.DatatypeConstants;
|
||||||
|
import javax.xml.datatype.DatatypeFactory;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import static org.easymock.EasyMock.*;
|
||||||
|
import org.joda.time.DateTime;
|
||||||
|
import org.joda.time.DateTimeZone;
|
||||||
|
import org.joda.time.LocalDate;
|
||||||
|
import org.springframework.ws.samples.airline.domain.Airport;
|
||||||
|
import org.springframework.ws.samples.airline.domain.FrequentFlyer;
|
||||||
|
import org.springframework.ws.samples.airline.domain.Passenger;
|
||||||
|
import org.springframework.ws.samples.airline.schema.BookFlightRequest;
|
||||||
|
import org.springframework.ws.samples.airline.schema.Flight;
|
||||||
|
import org.springframework.ws.samples.airline.schema.GetFlightsRequest;
|
||||||
|
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.ServiceClass;
|
||||||
|
import org.springframework.ws.samples.airline.schema.Ticket;
|
||||||
|
import org.springframework.ws.samples.airline.service.AirlineService;
|
||||||
|
|
||||||
|
public class MarshallingAirlineEndpointTest extends TestCase {
|
||||||
|
|
||||||
|
private MarshallingAirlineEndpoint endpoint;
|
||||||
|
|
||||||
|
private AirlineService airlineServiceMock;
|
||||||
|
|
||||||
|
private DatatypeFactory datatypeFactory;
|
||||||
|
|
||||||
|
private ObjectFactory objectFactory;
|
||||||
|
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
airlineServiceMock = createMock(AirlineService.class);
|
||||||
|
endpoint = new MarshallingAirlineEndpoint(airlineServiceMock);
|
||||||
|
datatypeFactory = DatatypeFactory.newInstance();
|
||||||
|
objectFactory = new ObjectFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetFlights() throws Exception {
|
||||||
|
GetFlightsRequest request = objectFactory.createGetFlightsRequest();
|
||||||
|
request.setDepartureDate(
|
||||||
|
datatypeFactory.newXMLGregorianCalendarDate(2007, 6, 13, DatatypeConstants.FIELD_UNDEFINED));
|
||||||
|
request.setFrom("ABC");
|
||||||
|
request.setTo("DEF");
|
||||||
|
request.setServiceClass(ServiceClass.FIRST);
|
||||||
|
|
||||||
|
org.springframework.ws.samples.airline.domain.Flight domainFlight = createDomainFlight();
|
||||||
|
|
||||||
|
expect(airlineServiceMock.getFlights("ABC", "DEF", new LocalDate(2007, 6, 13),
|
||||||
|
org.springframework.ws.samples.airline.domain.ServiceClass.FIRST))
|
||||||
|
.andReturn(Collections.singletonList(domainFlight));
|
||||||
|
|
||||||
|
replay(airlineServiceMock);
|
||||||
|
|
||||||
|
GetFlightsResponse response = endpoint.getFlights(request);
|
||||||
|
assertEquals("Invalid amount of flights received", 1, response.getFlight().size());
|
||||||
|
Flight schemaFlight = response.getFlight().get(0);
|
||||||
|
verifySchemaFlight(schemaFlight);
|
||||||
|
|
||||||
|
verify(airlineServiceMock);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifySchemaFlight(Flight schemaFlight) {
|
||||||
|
assertEquals("Invalid number", "ABC1234", schemaFlight.getNumber());
|
||||||
|
assertEquals("Invalid departure time", datatypeFactory.newXMLGregorianCalendar(2007, 6, 13, 12, 0, 0, 0, 0),
|
||||||
|
schemaFlight.getDepartureTime());
|
||||||
|
assertEquals("Invalid from code", "ABC", schemaFlight.getFrom().getCode());
|
||||||
|
assertEquals("Invalid from name", "ABC Airport", schemaFlight.getFrom().getName());
|
||||||
|
assertEquals("Invalid from city", "ABC City", schemaFlight.getFrom().getCity());
|
||||||
|
assertEquals("Invalid arrival time", datatypeFactory.newXMLGregorianCalendar(2007, 6, 13, 14, 0, 0, 0, 0),
|
||||||
|
schemaFlight.getArrivalTime());
|
||||||
|
assertEquals("Invalid to code", "DEF", schemaFlight.getTo().getCode());
|
||||||
|
assertEquals("Invalid to name", "DEF Airport", schemaFlight.getTo().getName());
|
||||||
|
assertEquals("Invalid to city", "DEF City", schemaFlight.getTo().getCity());
|
||||||
|
assertEquals("Invalid service class", ServiceClass.FIRST, schemaFlight.getServiceClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
private org.springframework.ws.samples.airline.domain.Flight createDomainFlight() {
|
||||||
|
org.springframework.ws.samples.airline.domain.Flight domainFlight =
|
||||||
|
new org.springframework.ws.samples.airline.domain.Flight();
|
||||||
|
domainFlight.setNumber("ABC1234");
|
||||||
|
domainFlight.setDepartureTime(new DateTime(2007, 6, 13, 12, 0, 0, 0, DateTimeZone.UTC));
|
||||||
|
domainFlight.setFrom(new Airport("ABC", "ABC Airport", "ABC City"));
|
||||||
|
domainFlight.setArrivalTime(new DateTime(2007, 6, 13, 14, 0, 0, 0, DateTimeZone.UTC));
|
||||||
|
domainFlight.setTo(new Airport("DEF", "DEF Airport", "DEF City"));
|
||||||
|
domainFlight.setServiceClass(org.springframework.ws.samples.airline.domain.ServiceClass.FIRST);
|
||||||
|
return domainFlight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBookFlightPassenger() throws Exception {
|
||||||
|
BookFlightRequest request = objectFactory.createBookFlightRequest();
|
||||||
|
request.setDepartureTime(datatypeFactory.newXMLGregorianCalendar(2007, 6, 13, 12, 0, 0, 0, 0));
|
||||||
|
request.setFlightNumber("ABC1234");
|
||||||
|
Name passengerName = new Name();
|
||||||
|
passengerName.setFirst("John");
|
||||||
|
passengerName.setLast("Doe");
|
||||||
|
BookFlightRequest.Passengers passengers = new BookFlightRequest.Passengers();
|
||||||
|
passengers.getPassengerOrUsername().add(passengerName);
|
||||||
|
request.setPassengers(passengers);
|
||||||
|
|
||||||
|
Passenger domainPassenger = new Passenger("John", "Doe");
|
||||||
|
|
||||||
|
org.springframework.ws.samples.airline.domain.Ticket domainTicket =
|
||||||
|
new org.springframework.ws.samples.airline.domain.Ticket(42L);
|
||||||
|
domainTicket.setFlight(createDomainFlight());
|
||||||
|
domainTicket.setIssueDate(new LocalDate(2007, 6, 13));
|
||||||
|
domainTicket.setPassengers(Collections.singleton(domainPassenger));
|
||||||
|
|
||||||
|
expect(airlineServiceMock.bookFlight("ABC1234", new DateTime(2007, 6, 13, 12, 0, 0, 0, DateTimeZone.UTC),
|
||||||
|
Collections.singletonList(domainPassenger))).andReturn(domainTicket);
|
||||||
|
|
||||||
|
replay(airlineServiceMock);
|
||||||
|
|
||||||
|
JAXBElement<Ticket> response = endpoint.bookFlight(request);
|
||||||
|
Ticket schemaTicket = response.getValue();
|
||||||
|
assertEquals("Invalid id", 42L, schemaTicket.getId());
|
||||||
|
assertEquals("Invalid issue date",
|
||||||
|
datatypeFactory.newXMLGregorianCalendarDate(2007, 6, 13, DatatypeConstants.FIELD_UNDEFINED),
|
||||||
|
schemaTicket.getIssueDate());
|
||||||
|
assertEquals("Invalid amount of passengers", 1, schemaTicket.getPassengers().getPassenger().size());
|
||||||
|
Name schemaPassenger = schemaTicket.getPassengers().getPassenger().get(0);
|
||||||
|
assertEquals("Invalid passenger first name", "John", schemaPassenger.getFirst());
|
||||||
|
assertEquals("Invalid passenger first name", "Doe", schemaPassenger.getLast());
|
||||||
|
verifySchemaFlight(schemaTicket.getFlight());
|
||||||
|
|
||||||
|
verify(airlineServiceMock);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBookFlightFrequentFlyer() throws Exception {
|
||||||
|
BookFlightRequest request = objectFactory.createBookFlightRequest();
|
||||||
|
request.setDepartureTime(datatypeFactory.newXMLGregorianCalendar(2007, 6, 13, 12, 0, 0, 0, 0));
|
||||||
|
request.setFlightNumber("ABC1234");
|
||||||
|
BookFlightRequest.Passengers passengers = new BookFlightRequest.Passengers();
|
||||||
|
passengers.getPassengerOrUsername().add("john");
|
||||||
|
request.setPassengers(passengers);
|
||||||
|
|
||||||
|
FrequentFlyer domainFrequentFlyer = new FrequentFlyer("John", "Doe", "john", "changeme");
|
||||||
|
Set<Passenger> domainPassengers = new HashSet<Passenger>();
|
||||||
|
domainPassengers.add(domainFrequentFlyer);
|
||||||
|
|
||||||
|
org.springframework.ws.samples.airline.domain.Ticket domainTicket =
|
||||||
|
new org.springframework.ws.samples.airline.domain.Ticket(42L);
|
||||||
|
domainTicket.setFlight(createDomainFlight());
|
||||||
|
domainTicket.setIssueDate(new LocalDate(2007, 6, 13));
|
||||||
|
domainTicket.setPassengers(domainPassengers);
|
||||||
|
|
||||||
|
List<Passenger> domainPassengerList = new ArrayList<Passenger>(domainPassengers);
|
||||||
|
expect(airlineServiceMock.bookFlight("ABC1234", new DateTime(2007, 6, 13, 12, 0, 0, 0, DateTimeZone.UTC),
|
||||||
|
domainPassengerList)).andReturn(domainTicket);
|
||||||
|
|
||||||
|
replay(airlineServiceMock);
|
||||||
|
|
||||||
|
JAXBElement<Ticket> response = endpoint.bookFlight(request);
|
||||||
|
Ticket schemaTicket = response.getValue();
|
||||||
|
assertEquals("Invalid id", 42L, schemaTicket.getId());
|
||||||
|
assertEquals("Invalid issue date",
|
||||||
|
datatypeFactory.newXMLGregorianCalendarDate(2007, 6, 13, DatatypeConstants.FIELD_UNDEFINED),
|
||||||
|
schemaTicket.getIssueDate());
|
||||||
|
assertEquals("Invalid amount of passengers", 1, schemaTicket.getPassengers().getPassenger().size());
|
||||||
|
Name schemaPassenger = schemaTicket.getPassengers().getPassenger().get(0);
|
||||||
|
assertEquals("Invalid passenger first name", "John", schemaPassenger.getFirst());
|
||||||
|
assertEquals("Invalid passenger first name", "Doe", schemaPassenger.getLast());
|
||||||
|
verifySchemaFlight(schemaTicket.getFlight());
|
||||||
|
|
||||||
|
verify(airlineServiceMock);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetFrequentFlyerMileage() throws Exception {
|
||||||
|
JAXBElement<String> request = objectFactory.createGetFrequentFlyerMileageRequest(null);
|
||||||
|
|
||||||
|
expect(airlineServiceMock.getFrequentFlyerMileage()).andReturn(42);
|
||||||
|
|
||||||
|
replay(airlineServiceMock);
|
||||||
|
|
||||||
|
JAXBElement<Integer> response = endpoint.getFrequentFlyerMileage(request);
|
||||||
|
assertEquals("Invalid amount of miles received", 42, response.getValue().intValue());
|
||||||
|
|
||||||
|
verify(airlineServiceMock);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.ws.samples.airline.ws;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import static org.easymock.EasyMock.createMock;
|
||||||
|
import org.springframework.oxm.Marshaller;
|
||||||
|
import org.springframework.ws.samples.airline.service.AirlineService;
|
||||||
|
|
||||||
|
public class XPathAirlineEndpointTest extends TestCase {
|
||||||
|
|
||||||
|
private XPathAirlineEndpoint endpoint;
|
||||||
|
|
||||||
|
private AirlineService airlineServiceMock;
|
||||||
|
|
||||||
|
private Marshaller marshallerMock;
|
||||||
|
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
airlineServiceMock = createMock(AirlineService.class);
|
||||||
|
marshallerMock = createMock(Marshaller.class);
|
||||||
|
endpoint = new XPathAirlineEndpoint(airlineServiceMock, marshallerMock);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetFlights() throws Exception {
|
||||||
|
endpoint.getFlights("ABC", "DEF", "2006-01-31Z", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<BookFlightRequest xmlns="http://www.springframework.org/spring-ws/samples/airline/schemas">
|
|
||||||
<flightNumber>EF1234</flightNumber>
|
|
||||||
<departureTime>2006-01-01T00:00:00.000Z</departureTime>
|
|
||||||
<passengers>
|
|
||||||
<passenger>
|
|
||||||
<first>John</first>
|
|
||||||
<last>Doe</last>
|
|
||||||
</passenger>
|
|
||||||
</passengers>
|
|
||||||
</BookFlightRequest>
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<BookFlightRequest xmlns="http://www.springframework.org/spring-ws/samples/airline/schemas">
|
|
||||||
<flightNumber>EF1234</flightNumber>
|
|
||||||
<departureTime>2006-01-01T00:00:00.000Z</departureTime>
|
|
||||||
<passengers>
|
|
||||||
<username>john</username>
|
|
||||||
</passengers>
|
|
||||||
</BookFlightRequest>
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<BookFlightResponse xmlns="http://www.springframework.org/spring-ws/samples/airline/schemas">
|
|
||||||
<id>42</id>
|
|
||||||
<issueDate>2006-01-01</issueDate>
|
|
||||||
<passengers>
|
|
||||||
<passenger>
|
|
||||||
<first>John</first>
|
|
||||||
<last>Doe</last>
|
|
||||||
</passenger>
|
|
||||||
</passengers>
|
|
||||||
<flight>
|
|
||||||
<number>EF1234</number>
|
|
||||||
<departureTime>2006-01-01T00:00:00Z</departureTime>
|
|
||||||
<from>
|
|
||||||
<code>ABC</code>
|
|
||||||
<name>Airport</name>
|
|
||||||
<city>City</city>
|
|
||||||
</from>
|
|
||||||
<arrivalTime>2006-02-02T00:00:00Z</arrivalTime>
|
|
||||||
<to>
|
|
||||||
<code>DEF</code>
|
|
||||||
<name>Airport</name>
|
|
||||||
<city>City</city>
|
|
||||||
</to>
|
|
||||||
<serviceClass>economy</serviceClass>
|
|
||||||
</flight>
|
|
||||||
</BookFlightResponse>
|
|
||||||
Reference in New Issue
Block a user