Get ArtemisMQ working.
This commit is contained in:
@@ -39,8 +39,8 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>artemis-jakarta-client</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-artemis</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.ws.samples.airline.client.jms;
|
||||
|
||||
import jakarta.jms.ConnectionFactory;
|
||||
|
||||
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.ws.transport.jms.JmsMessageSender;
|
||||
@@ -31,11 +30,6 @@ import org.springframework.ws.transport.jms.JmsMessageSender;
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class JmsConfiguration {
|
||||
|
||||
@Bean
|
||||
ConnectionFactory connectionFactory() {
|
||||
return new ActiveMQConnectionFactory("tcp://localhost:61616");
|
||||
}
|
||||
|
||||
@Bean
|
||||
JmsMessageSender jmsMessageSender(ConnectionFactory connectionFactory) {
|
||||
return new JmsMessageSender(connectionFactory);
|
||||
|
||||
@@ -16,19 +16,27 @@
|
||||
|
||||
package org.springframework.ws.samples.airline.client.jms;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* "Main" that creates a {@link JmsClient} and uses it to talk to the SOAP-based server.
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class JmsMain {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(JmsMain.class);
|
||||
}
|
||||
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(JmsConfiguration.class);
|
||||
|
||||
ctx.getBean(JmsClient.class).getFlights();
|
||||
@Bean
|
||||
CommandLineRunner getFlights(JmsClient client) {
|
||||
return args -> {
|
||||
client.getFlights();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
logging.level.org.springframework.jms=DEBUG
|
||||
logging.level.org.springframework.ws=DEBUG
|
||||
#logging.level.org.apache.activemq=DEBUG
|
||||
@@ -1,7 +0,0 @@
|
||||
log4j.rootLogger=WARN, stdout
|
||||
log4j.logger.org.springframework.ws=DEBUG
|
||||
|
||||
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
|
||||
@@ -17,14 +17,11 @@
|
||||
<description>Demo project for Spring Web Services</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<joda-time.version>2.10.6</joda-time.version>
|
||||
<log4j2.version>2.15.0</log4j2.version>
|
||||
<sourcesDir>${project.basedir}/target/generated-sources/axis</sourcesDir>
|
||||
<classesDir>${project.basedir}/target/classes</classesDir>
|
||||
<wsdl>${project.basedir}/../airline.wsdl</wsdl>
|
||||
<xmlschema.version>2.0.2</xmlschema.version>
|
||||
<xws-security.version>3.0</xws-security.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -39,52 +36,16 @@
|
||||
<artifactId>spring-boot-starter-web-services</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.ws</groupId>
|
||||
<artifactId>spring-ws-security</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.sun.xml.wsit</groupId>
|
||||
<artifactId>wsit-rt</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.sun.xml.wsit</groupId>
|
||||
<artifactId>xws-security</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.wss</groupId>
|
||||
<artifactId>xws-security</artifactId>
|
||||
<version>${xws-security.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>javax.activation</groupId>
|
||||
<artifactId>activation</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>javax.xml.crypto</groupId>
|
||||
<artifactId>xmldsig</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>javax.xml.stream</groupId>
|
||||
<artifactId>stax-api</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>javax.xml.ws</groupId>
|
||||
<artifactId>jaxws-api</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>mail</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.ws</groupId>-->
|
||||
<!-- <artifactId>spring-ws-security</artifactId>-->
|
||||
<!-- <exclusions>-->
|
||||
<!-- <exclusion>-->
|
||||
<!-- <groupId>com.sun.xml.wsit</groupId>-->
|
||||
<!-- <artifactId>wsit-rt</artifactId>-->
|
||||
<!-- </exclusion>-->
|
||||
<!-- </exclusions>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.ws</groupId>
|
||||
@@ -96,11 +57,6 @@
|
||||
<artifactId>wsdl4j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
@@ -121,26 +77,19 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-activemq</artifactId>
|
||||
<artifactId>spring-boot-starter-artemis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>activemq-kahadb-store</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>artemis-jakarta-server</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>${joda-time.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
@@ -151,12 +100,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
@@ -173,7 +116,7 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>jaxb2-maven-plugin</artifactId>
|
||||
<version>2.5.0</version>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>xjc</id>
|
||||
@@ -185,7 +128,7 @@
|
||||
<configuration>
|
||||
<sources>${project.basedir}/src/main/resources/messages.xsd</sources>
|
||||
<packageName>org.springframework.ws.samples.airline.schema</packageName>
|
||||
<target>2.1</target>
|
||||
<target>3.0</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
|
||||
@@ -2,9 +2,8 @@ package org.springframework.ws.samples.airline;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
||||
|
||||
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
|
||||
@SpringBootApplication
|
||||
public class AirlineServerApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.springframework.ws.samples.airline.dao;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -22,9 +24,9 @@ public class Databaseinit {
|
||||
|
||||
Flight flight = new Flight();
|
||||
flight.setNumber("KL1653");
|
||||
flight.setDepartureTime(new DateTime(2006, 1, 31, 10, 5, 0, 0).toGregorianCalendar().toZonedDateTime());
|
||||
flight.setDepartureTime(ZonedDateTime.of(2006, 1, 31, 10, 5, 0, 0, ZoneId.systemDefault()));
|
||||
flight.setFrom(amsterdam);
|
||||
flight.setArrivalTime(new DateTime(2006, 1, 31, 12, 25, 0, 0).toGregorianCalendar().toZonedDateTime());
|
||||
flight.setArrivalTime(ZonedDateTime.of(2006, 1, 31, 12, 25, 0, 0, ZoneId.systemDefault()));
|
||||
flight.setTo(venice);
|
||||
flight.setServiceClass(ServiceClass.ECONOMY);
|
||||
flight.setSeatsAvailable(5);
|
||||
@@ -34,9 +36,9 @@ public class Databaseinit {
|
||||
|
||||
flight = new Flight();
|
||||
flight.setNumber("KL1654");
|
||||
flight.setDepartureTime(new DateTime(2006, 2, 5, 12, 40, 0, 0).toGregorianCalendar().toZonedDateTime());
|
||||
flight.setDepartureTime(ZonedDateTime.of(2006, 2, 5, 12, 40, 0, 0, ZoneId.systemDefault()));
|
||||
flight.setFrom(venice);
|
||||
flight.setArrivalTime(new DateTime(2006, 2, 5, 14, 15, 0, 0).toGregorianCalendar().toZonedDateTime());
|
||||
flight.setArrivalTime(ZonedDateTime.of(2006, 2, 5, 14, 15, 0, 0, ZoneId.systemDefault()));
|
||||
flight.setTo(amsterdam);
|
||||
flight.setServiceClass(ServiceClass.ECONOMY);
|
||||
flight.setSeatsAvailable(5);
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.ws.samples.airline.dao;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import org.joda.time.Interval;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
@@ -28,29 +27,12 @@ import org.springframework.ws.samples.airline.domain.ServiceClass;
|
||||
public interface FlightDao extends CrudRepository<Flight, Long> {
|
||||
|
||||
@Query("SELECT f FROM Flight f WHERE f.from.code = :fromAirportCode "
|
||||
+ "AND f.to.code = :toAirportCode AND f.departureTime >= :#{#interval.start.toGregorianCalendar().toZonedDateTime()} AND f.departureTime <= :#{#interval.end.toGregorianCalendar().toZonedDateTime()} AND "
|
||||
+ "AND f.to.code = :toAirportCode AND f.departureTime >= :#{#date} AND f.departureTime <= :#{#date.plusDays(1)} AND "
|
||||
+ "f.serviceClass = :class")
|
||||
List<Flight> findFlights(@Param("fromAirportCode") String fromAirportCode, //
|
||||
@Param("toAirportCode") String toAirportCode, //
|
||||
@Param("interval") Interval interval, //
|
||||
@Param("class") ServiceClass serviceClass);
|
||||
|
||||
/**
|
||||
* @deprecated Migrate to {@link #findById(Object)}.
|
||||
*/
|
||||
default Flight getFlight(Long id) {
|
||||
return findById(id).get();
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* @deprecated Migrate to {@link #findFlightByNumberAndDepartureTime(String, ZonedDateTime)}.
|
||||
*/
|
||||
@Deprecated
|
||||
default Flight getFlight(String flightNumber, ZonedDateTime departureTime) {
|
||||
return findFlightByNumberAndDepartureTime(flightNumber, departureTime);
|
||||
}
|
||||
@Param("toAirportCode") String toAirportCode, //
|
||||
@Param("date") ZonedDateTime date, //
|
||||
@Param("class") ServiceClass serviceClass);
|
||||
|
||||
Flight findFlightByNumberAndDepartureTime(String flightNumber, ZonedDateTime departureTime);
|
||||
|
||||
|
||||
@@ -16,60 +16,56 @@
|
||||
|
||||
package org.springframework.ws.samples.airline.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Entity
|
||||
@Table(name = "AIRPORT")
|
||||
public class Airport implements Serializable {
|
||||
|
||||
@Id
|
||||
@Column(name = "CODE")
|
||||
private String code;
|
||||
@Id
|
||||
@Column(name = "CODE") private String code;
|
||||
|
||||
@Column(name = "NAME")
|
||||
private String name;
|
||||
@Column(name = "NAME") private String name;
|
||||
|
||||
@Column(name = "CITY")
|
||||
private String city;
|
||||
@Column(name = "CITY") private String city;
|
||||
|
||||
public Airport() {
|
||||
}
|
||||
public Airport() {}
|
||||
|
||||
public Airport(String code, String name, String city) {
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
this.city = city;
|
||||
}
|
||||
public Airport(String code, String name, String city) {
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof Airport)) {
|
||||
return false;
|
||||
}
|
||||
final Airport that = (Airport) other;
|
||||
return code.equals(that.code);
|
||||
}
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof Airport)) {
|
||||
return false;
|
||||
}
|
||||
final Airport that = (Airport) other;
|
||||
return code.equals(that.code);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return code.hashCode();
|
||||
}
|
||||
public int hashCode() {
|
||||
return code.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,39 +15,37 @@
|
||||
*/
|
||||
package org.springframework.ws.samples.airline.domain;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.springframework.data.annotation.Persistent;
|
||||
|
||||
@Entity
|
||||
@Table(name = "FLIGHT")
|
||||
public class Flight implements Serializable {
|
||||
|
||||
@Id @Column(name = "ID") @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id;
|
||||
@Id
|
||||
@Column(name = "ID")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY) private Long id;
|
||||
|
||||
@Column(name = "NUMBER") private String number;
|
||||
|
||||
@Column(name = "DEPARTURE_TIME") @Persistent private ZonedDateTime departureTime;
|
||||
@Column(name = "DEPARTURE_TIME")
|
||||
@Persistent private ZonedDateTime departureTime;
|
||||
|
||||
@ManyToOne @JoinColumn(name = "FROM_AIRPORT_CODE", nullable = false) private Airport from;
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "FROM_AIRPORT_CODE", nullable = false) private Airport from;
|
||||
|
||||
@Column(name = "ARRIVAL_TIME") @Persistent private ZonedDateTime arrivalTime;
|
||||
@Column(name = "ARRIVAL_TIME")
|
||||
@Persistent private ZonedDateTime arrivalTime;
|
||||
|
||||
@ManyToOne @JoinColumn(name = "TO_AIRPORT_CODE", nullable = false) private Airport to;
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "TO_AIRPORT_CODE", nullable = false) private Airport to;
|
||||
|
||||
@Column(name = "SERVICE_CLASS") @Enumerated(EnumType.STRING) private ServiceClass serviceClass;
|
||||
@Column(name = "SERVICE_CLASS")
|
||||
@Enumerated(EnumType.STRING) private ServiceClass serviceClass;
|
||||
|
||||
@Column(name = "SEATS_AVAILABLE") private int seatsAvailable;
|
||||
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
package org.springframework.ws.samples.airline.domain;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
import javax.persistence.Table;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.PrimaryKeyJoinColumn;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "FREQUENT_FLYER")
|
||||
|
||||
@@ -15,86 +15,75 @@
|
||||
*/
|
||||
package org.springframework.ws.samples.airline.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.Table;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Entity
|
||||
@Table(name = "PASSENGER")
|
||||
@Inheritance(strategy = InheritanceType.JOINED)
|
||||
public class Passenger implements Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "ID")
|
||||
private Long id;
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "ID") private Long id;
|
||||
|
||||
@Column(name = "FIRST_NAME")
|
||||
private String firstName;
|
||||
@Column(name = "FIRST_NAME") private String firstName;
|
||||
|
||||
@Column(name = "LAST_NAME")
|
||||
private String lastName;
|
||||
@Column(name = "LAST_NAME") private String lastName;
|
||||
|
||||
public Passenger() {
|
||||
}
|
||||
public Passenger() {}
|
||||
|
||||
public Passenger(String firstName, String lastName) {
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
public Passenger(String firstName, String lastName) {
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public Passenger(Long id, String firstName, String lastName) {
|
||||
this.id = id;
|
||||
this.firstName = firstName;
|
||||
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 String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return firstName + " " + lastName;
|
||||
}
|
||||
public String toString() {
|
||||
return firstName + " " + lastName;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Passenger passenger = (Passenger) o;
|
||||
final Passenger passenger = (Passenger) o;
|
||||
|
||||
if (!getFirstName().equals(passenger.getFirstName())) {
|
||||
return false;
|
||||
}
|
||||
if (!getLastName().equals(passenger.getLastName())) {
|
||||
return false;
|
||||
}
|
||||
if (!getFirstName().equals(passenger.getFirstName())) {
|
||||
return false;
|
||||
}
|
||||
if (!getLastName().equals(passenger.getLastName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result = getFirstName().hashCode();
|
||||
result = 29 * result + getLastName().hashCode();
|
||||
return result;
|
||||
}
|
||||
public int hashCode() {
|
||||
int result = getFirstName().hashCode();
|
||||
result = 29 * result + getLastName().hashCode();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,23 +16,13 @@
|
||||
|
||||
package org.springframework.ws.samples.airline.domain;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
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.LocalDate;
|
||||
import org.springframework.data.annotation.Persistent;
|
||||
|
||||
@Entity
|
||||
@@ -40,25 +30,19 @@ import org.springframework.data.annotation.Persistent;
|
||||
public class Ticket implements Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY) private Long id;
|
||||
|
||||
@Column(name = "ISSUE_DATE")
|
||||
@Persistent
|
||||
private LocalDate issueDate;
|
||||
@Persistent private LocalDate issueDate;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "FLIGHT_ID", nullable = false)
|
||||
private Flight flight;
|
||||
@JoinColumn(name = "FLIGHT_ID", nullable = false) 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>();
|
||||
@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() {}
|
||||
|
||||
public Ticket(Long id) {
|
||||
this.id = id;
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package org.springframework.ws.samples.airline.jms;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
import jakarta.jms.ConnectionFactory;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
import org.apache.activemq.artemis.api.core.TransportConfiguration;
|
||||
import org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptorFactory;
|
||||
import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;
|
||||
import org.apache.activemq.artemis.jms.client.ActiveMQQueue;
|
||||
import org.springframework.boot.autoconfigure.jms.artemis.ArtemisConfigurationCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jms.listener.DefaultMessageListenerContainer;
|
||||
@@ -16,19 +17,21 @@ import org.springframework.ws.transport.jms.WebServiceMessageListener;
|
||||
@Configuration
|
||||
public class JmsConfiguration {
|
||||
|
||||
@Bean(initMethod = "start")
|
||||
BrokerService broker() throws Exception {
|
||||
return BrokerFactory.createBroker("broker:tcp://localhost:61616?persistent=false");
|
||||
}
|
||||
|
||||
/**
|
||||
* Make embedded ActiveMQ broker open to tcp connections.
|
||||
*/
|
||||
@Bean
|
||||
ActiveMQConnectionFactory connectionFactory() {
|
||||
|
||||
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
|
||||
connectionFactory.setBrokerURL("tcp://localhost:61616");
|
||||
return connectionFactory;
|
||||
ArtemisConfigurationCustomizer customizer() {
|
||||
return configuration -> {
|
||||
configuration.addConnectorConfiguration("nettyConnector",
|
||||
new TransportConfiguration(NettyConnectorFactory.class.getName()));
|
||||
configuration.addAcceptorConfiguration(new TransportConfiguration(NettyAcceptorFactory.class.getName()));
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen for JMS messages and route them into the SOAP-based {@link WebServiceMessageListener}.
|
||||
*/
|
||||
@Bean
|
||||
DefaultMessageListenerContainer containerFactory(ConnectionFactory connectionFactory,
|
||||
WebServiceMessageListener messageListener) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.ws.samples.airline.schema.support;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
@@ -26,13 +27,8 @@ import javax.xml.datatype.DatatypeConstants;
|
||||
import javax.xml.datatype.DatatypeFactory;
|
||||
import javax.xml.datatype.XMLGregorianCalendar;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.springframework.ws.samples.airline.domain.Passenger;
|
||||
import org.springframework.ws.samples.airline.schema.Airport;
|
||||
import org.springframework.ws.samples.airline.schema.Flight;
|
||||
import org.springframework.ws.samples.airline.schema.Name;
|
||||
import org.springframework.ws.samples.airline.schema.ServiceClass;
|
||||
import org.springframework.ws.samples.airline.schema.Ticket;
|
||||
import org.springframework.ws.samples.airline.schema.*;
|
||||
|
||||
/** @author Arjen Poutsma */
|
||||
public abstract class SchemaConversionUtils {
|
||||
@@ -79,12 +75,12 @@ public abstract class SchemaConversionUtils {
|
||||
public static XMLGregorianCalendar toXMLGregorianCalendar(LocalDate localDate) throws DatatypeConfigurationException {
|
||||
|
||||
DatatypeFactory factory = DatatypeFactory.newInstance();
|
||||
return factory.newXMLGregorianCalendarDate(localDate.getYear(), localDate.getMonthOfYear(),
|
||||
return factory.newXMLGregorianCalendarDate(localDate.getYear(), localDate.getMonthValue(),
|
||||
localDate.getDayOfMonth(), DatatypeConstants.FIELD_UNDEFINED);
|
||||
}
|
||||
|
||||
public static LocalDate toLocalDate(XMLGregorianCalendar calendar) {
|
||||
return new LocalDate(calendar.getYear(), calendar.getMonth(), calendar.getDay());
|
||||
return LocalDate.of(calendar.getYear(), calendar.getMonth(), calendar.getDay());
|
||||
}
|
||||
|
||||
public static Airport toSchemaType(org.springframework.ws.samples.airline.domain.Airport domainAirport) {
|
||||
|
||||
@@ -1,82 +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.security;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.ws.samples.airline.domain.FrequentFlyer;
|
||||
|
||||
/**
|
||||
* A wrapper around an <code>FrequentFlyer</code> which provides extra functionality needed to implement the
|
||||
* <code>UserDetails</code> interface.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class FrequentFlyerDetails implements UserDetails {
|
||||
|
||||
private FrequentFlyer frequentFlyer;
|
||||
|
||||
public static final Collection<GrantedAuthority> GRANTED_AUTHORITIES =
|
||||
new ArrayList<GrantedAuthority>();
|
||||
{
|
||||
GRANTED_AUTHORITIES.add(new SimpleGrantedAuthority("ROLE_FREQUENT_FLYER"));
|
||||
};
|
||||
|
||||
public FrequentFlyerDetails(FrequentFlyer frequentFlyer) {
|
||||
this.frequentFlyer = frequentFlyer;
|
||||
}
|
||||
|
||||
public Collection<GrantedAuthority> getAuthorities() {
|
||||
return GRANTED_AUTHORITIES;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return frequentFlyer.getPassword();
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return frequentFlyer.getUsername();
|
||||
}
|
||||
|
||||
public boolean isAccountNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isAccountNonLocked() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public FrequentFlyer getFrequentFlyer() {
|
||||
return frequentFlyer;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return frequentFlyer.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,45 +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.security;
|
||||
|
||||
import org.springframework.ws.samples.airline.domain.FrequentFlyer;
|
||||
import org.springframework.ws.samples.airline.service.NoSuchFrequentFlyerException;
|
||||
|
||||
/**
|
||||
* Defines the business logic for handling frequent flyers.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public interface FrequentFlyerSecurityService {
|
||||
|
||||
/**
|
||||
* Returns the <code>FrequentFlyer</code> with the given username.
|
||||
*
|
||||
* @param username the username
|
||||
* @return the frequent flyer with the given username, or <code>null</code> if not found
|
||||
* @throws NoSuchFrequentFlyerException when the frequent flyer cannot be found
|
||||
*/
|
||||
FrequentFlyer getFrequentFlyer(String username) throws NoSuchFrequentFlyerException;
|
||||
|
||||
/**
|
||||
* Returns the <code>FrequentFlyer</code> that is currently logged in.
|
||||
*
|
||||
* @return the frequent flyer that is currently logged in, or <code>null</code> if not found
|
||||
*/
|
||||
FrequentFlyer getCurrentlyAuthenticatedFrequentFlyer();
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package org.springframework.ws.samples.airline.security;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.bytebuddy.build.Plugin;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.ProviderManager;
|
||||
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
import org.springframework.security.crypto.password.DelegatingPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.ws.samples.airline.dao.FrequentFlyerDao;
|
||||
|
||||
@EnableGlobalMethodSecurity(securedEnabled = true)
|
||||
public class SecurityConfiguration /*extends WebSecurityConfigurerAdapter*/ {
|
||||
|
||||
@Bean
|
||||
SpringFrequentFlyerSecurityService securityService(FrequentFlyerDao frequentFlyerDao) {
|
||||
return new SpringFrequentFlyerSecurityService(frequentFlyerDao);
|
||||
}
|
||||
|
||||
@Bean
|
||||
AuthenticationManager authenticationManager(SpringFrequentFlyerSecurityService securityService) {
|
||||
|
||||
DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider();
|
||||
authenticationProvider.setUserDetailsService(securityService);
|
||||
return new ProviderManager(authenticationProvider);
|
||||
}
|
||||
|
||||
@Bean
|
||||
PasswordEncoder passwordEncoder() {
|
||||
return NoOpPasswordEncoder.getInstance();
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2011 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.security;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.ws.samples.airline.dao.FrequentFlyerDao;
|
||||
import org.springframework.ws.samples.airline.domain.FrequentFlyer;
|
||||
import org.springframework.ws.samples.airline.service.NoSuchFrequentFlyerException;
|
||||
|
||||
/**
|
||||
* Implementation of the <code>FrequentFlyerSecurityService</code> that uses Spring Security.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class SpringFrequentFlyerSecurityService implements FrequentFlyerSecurityService, UserDetailsService {
|
||||
|
||||
private FrequentFlyerDao frequentFlyerDao;
|
||||
|
||||
public SpringFrequentFlyerSecurityService(FrequentFlyerDao frequentFlyerDao) {
|
||||
this.frequentFlyerDao = frequentFlyerDao;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public FrequentFlyer getCurrentlyAuthenticatedFrequentFlyer() {
|
||||
|
||||
SecurityContext context = SecurityContextHolder.getContext();
|
||||
Authentication authentication = context.getAuthentication();
|
||||
if (authentication != null) {
|
||||
if (authentication.getPrincipal() instanceof FrequentFlyerDetails) {
|
||||
FrequentFlyerDetails details = (FrequentFlyerDetails) authentication.getPrincipal();
|
||||
return details.getFrequentFlyer();
|
||||
} else {
|
||||
return (FrequentFlyer) authentication.getPrincipal();
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public FrequentFlyer getFrequentFlyer(String username) throws NoSuchFrequentFlyerException {
|
||||
|
||||
FrequentFlyer frequentFlyer = frequentFlyerDao.get(username);
|
||||
if (frequentFlyer != null) {
|
||||
return frequentFlyer;
|
||||
} else {
|
||||
throw new NoSuchFrequentFlyerException(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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,50 +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.security;
|
||||
|
||||
import org.springframework.ws.samples.airline.domain.FrequentFlyer;
|
||||
import org.springframework.ws.samples.airline.service.NoSuchFrequentFlyerException;
|
||||
|
||||
/**
|
||||
* Stub implementation of <code>FrequentFlyerSecurityService</code>. This implementation is used by default by {@link
|
||||
* org.springframework.ws.samples.airline.service.impl.AirlineServiceImpl}, to allow it to run without depending on
|
||||
* Spring Security.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class StubFrequentFlyerSecurityService implements FrequentFlyerSecurityService {
|
||||
|
||||
private FrequentFlyer john;
|
||||
|
||||
public StubFrequentFlyerSecurityService() {
|
||||
john = new FrequentFlyer("John", "Doe", "john", "changeme");
|
||||
john.setMiles(10);
|
||||
}
|
||||
|
||||
public FrequentFlyer getFrequentFlyer(String username) throws NoSuchFrequentFlyerException {
|
||||
if (john.getUsername().equals(username)) {
|
||||
return john;
|
||||
}
|
||||
else {
|
||||
throw new NoSuchFrequentFlyerException(username);
|
||||
}
|
||||
}
|
||||
|
||||
public FrequentFlyer getCurrentlyAuthenticatedFrequentFlyer() {
|
||||
return john;
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,7 @@ package org.springframework.ws.samples.airline.service;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
|
||||
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.Ticket;
|
||||
import org.springframework.ws.samples.airline.domain.*;
|
||||
|
||||
/**
|
||||
* Defines the business logic of the Airline application.
|
||||
@@ -32,52 +27,43 @@ import org.springframework.ws.samples.airline.domain.Ticket;
|
||||
*/
|
||||
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 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.
|
||||
*
|
||||
* @param fromAirportCode the three-letter airport code to get flights from
|
||||
* @param toAirportCode the three-letter airport code to get flights to
|
||||
* @param departureDate the date of the flights
|
||||
* @param serviceClass the desired service class level. May be <code>null</code>
|
||||
* @return a list of flights
|
||||
*/
|
||||
List<Flight> getFlights(String fromAirportCode,
|
||||
String toAirportCode,
|
||||
LocalDate departureDate,
|
||||
ServiceClass serviceClass);
|
||||
/**
|
||||
* Returns a list of <code>Flight</code> objects that fall within the specified criteria.
|
||||
*
|
||||
* @param fromAirportCode the three-letter airport code to get flights from
|
||||
* @param toAirportCode the three-letter airport code to get flights to
|
||||
* @param departureDate the date of the flights
|
||||
* @param serviceClass the desired service class level. May be <code>null</code>
|
||||
* @return a list of flights
|
||||
*/
|
||||
List<Flight> getFlights(String fromAirportCode, String toAirportCode, ZonedDateTime departureDate,
|
||||
ServiceClass serviceClass);
|
||||
|
||||
/**
|
||||
* Books a single flight for a number of passengers. Passengers can be either specified by name or by frequent flyer
|
||||
* 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 departureTime the departure time of the flight to book
|
||||
* @param passengers the list of passengers for the flight to book. Can be either {@link Passenger} objects with
|
||||
* a first and last name, or {@link FrequentFlyer} objects with a username.
|
||||
* @return the created ticket
|
||||
* @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 NoSuchFrequentFlyerException if a specified {@link FrequentFlyer} cannot be found
|
||||
* @see Passenger
|
||||
* @see FrequentFlyer
|
||||
*/
|
||||
Ticket bookFlight(String flightNumber, ZonedDateTime departureTime, List<Passenger> passengers)
|
||||
throws NoSuchFlightException, NoSeatAvailableException, NoSuchFrequentFlyerException;
|
||||
/**
|
||||
* Books a single flight for a number of passengers. Passengers can be either specified by name or by frequent flyer
|
||||
* 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 departureTime the departure time of the flight to book
|
||||
* @param passengers the list of passengers for the flight to book. Can be either {@link Passenger} objects with a
|
||||
* first and last name, or {@link FrequentFlyer} objects with a username.
|
||||
* @return the created ticket
|
||||
* @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 NoSuchFrequentFlyerException if a specified {@link FrequentFlyer} cannot be found
|
||||
* @see Passenger
|
||||
* @see FrequentFlyer
|
||||
*/
|
||||
Ticket bookFlight(String flightNumber, ZonedDateTime departureTime, List<Passenger> passengers)
|
||||
throws NoSuchFlightException, NoSeatAvailableException, NoSuchFrequentFlyerException;
|
||||
|
||||
/**
|
||||
* Returns the amount of frequent flyer award miles for the currently logged in frequent flyer.
|
||||
*
|
||||
* @return the amount of frequent flyer miles
|
||||
*/
|
||||
int getFrequentFlyerMileage();
|
||||
}
|
||||
|
||||
@@ -15,26 +15,22 @@
|
||||
*/
|
||||
package org.springframework.ws.samples.airline.service.impl;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.annotation.Secured;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.samples.airline.dao.FlightDao;
|
||||
import org.springframework.ws.samples.airline.dao.TicketDao;
|
||||
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.security.FrequentFlyerSecurityService;
|
||||
import org.springframework.ws.samples.airline.security.StubFrequentFlyerSecurityService;
|
||||
import org.springframework.ws.samples.airline.service.AirlineService;
|
||||
import org.springframework.ws.samples.airline.service.NoSeatAvailableException;
|
||||
import org.springframework.ws.samples.airline.service.NoSuchFlightException;
|
||||
@@ -55,8 +51,6 @@ public class AirlineServiceImpl implements AirlineService {
|
||||
|
||||
private TicketDao ticketDao;
|
||||
|
||||
private FrequentFlyerSecurityService frequentFlyerSecurityService = new StubFrequentFlyerSecurityService();
|
||||
|
||||
@Autowired
|
||||
public AirlineServiceImpl(FlightDao flightDao, TicketDao ticketDao) {
|
||||
|
||||
@@ -64,11 +58,6 @@ public class AirlineServiceImpl implements AirlineService {
|
||||
this.ticketDao = ticketDao;
|
||||
}
|
||||
|
||||
@Autowired(required = false)
|
||||
public void setFrequentFlyerSecurityService(FrequentFlyerSecurityService frequentFlyerSecurityService) {
|
||||
this.frequentFlyerSecurityService = frequentFlyerSecurityService;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = false,
|
||||
rollbackFor = { NoSuchFlightException.class, NoSeatAvailableException.class, NoSuchFrequentFlyerException.class })
|
||||
public Ticket bookFlight(String flightNumber, ZonedDateTime departureTime, List<Passenger> passengers)
|
||||
@@ -78,44 +67,27 @@ public class AirlineServiceImpl implements AirlineService {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Booking flight '" + flightNumber + "' on '" + departureTime + "' for " + passengers);
|
||||
}
|
||||
Flight flight = flightDao.getFlight(flightNumber, departureTime);
|
||||
Flight flight = flightDao.findFlightByNumberAndDepartureTime(flightNumber, departureTime);
|
||||
if (flight == null) {
|
||||
throw new NoSuchFlightException(flightNumber, departureTime);
|
||||
} else if (flight.getSeatsAvailable() < passengers.size()) {
|
||||
throw new NoSeatAvailableException(flight);
|
||||
}
|
||||
Ticket ticket = new Ticket();
|
||||
ticket.setIssueDate(new LocalDate());
|
||||
ticket.setIssueDate(LocalDate.now());
|
||||
ticket.setFlight(flight);
|
||||
for (Passenger passenger : passengers) {
|
||||
// frequent flyer service is not required
|
||||
if (passenger instanceof FrequentFlyer && frequentFlyerSecurityService != null) {
|
||||
String username = ((FrequentFlyer) passenger).getUsername();
|
||||
Assert.hasLength(username, "No username specified");
|
||||
FrequentFlyer frequentFlyer = frequentFlyerSecurityService.getFrequentFlyer(username);
|
||||
frequentFlyer.addMiles(flight.getMiles());
|
||||
ticket.addPassenger(frequentFlyer);
|
||||
} else {
|
||||
ticket.addPassenger(passenger);
|
||||
}
|
||||
}
|
||||
passengers.forEach(ticket::addPassenger);
|
||||
flight.substractSeats(passengers.size());
|
||||
flightDao.update(flight);
|
||||
flightDao.save(flight);
|
||||
ticketDao.save(ticket);
|
||||
return ticket;
|
||||
}
|
||||
|
||||
public Flight getFlight(Long id) throws NoSuchFlightException {
|
||||
|
||||
Flight flight = flightDao.getFlight(id);
|
||||
if (flight != null) {
|
||||
return flight;
|
||||
} else {
|
||||
throw new NoSuchFlightException(id);
|
||||
}
|
||||
return flightDao.findById(id).orElseThrow(() -> new NoSuchFlightException(id));
|
||||
}
|
||||
|
||||
public List<Flight> getFlights(String fromAirportCode, String toAirportCode, LocalDate departureDate,
|
||||
public List<Flight> getFlights(String fromAirportCode, String toAirportCode, ZonedDateTime departureDate,
|
||||
ServiceClass serviceClass) {
|
||||
|
||||
if (serviceClass == null) {
|
||||
@@ -124,21 +96,10 @@ public class AirlineServiceImpl implements AirlineService {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Getting flights from '" + fromAirportCode + "' to '" + toAirportCode + "' on " + departureDate);
|
||||
}
|
||||
List<Flight> flights = flightDao.findFlights(fromAirportCode, toAirportCode, departureDate.toInterval(),
|
||||
serviceClass);
|
||||
List<Flight> flights = flightDao.findFlights(fromAirportCode, toAirportCode, departureDate, serviceClass);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Returning " + flights.size() + " flights");
|
||||
}
|
||||
return flights;
|
||||
}
|
||||
|
||||
@Secured({ "ROLE_FREQUENT_FLYER" })
|
||||
public int getFrequentFlyerMileage() {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Using " + frequentFlyerSecurityService + " for security");
|
||||
}
|
||||
FrequentFlyer frequentFlyer = frequentFlyerSecurityService.getCurrentlyAuthenticatedFrequentFlyer();
|
||||
return frequentFlyer != null ? frequentFlyer.getMiles() : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,13 @@
|
||||
|
||||
package org.springframework.ws.samples.airline.web;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -48,14 +51,14 @@ public class FlightsController {
|
||||
@RequestParam(value = "departureDate", required = false) String departureDateString,
|
||||
@RequestParam(value = "serviceClass", required = false) String serviceClassString, ModelMap model) {
|
||||
|
||||
if (StringUtils.isEmpty(departureDateString)) {
|
||||
departureDateString = new LocalDate().toString();
|
||||
if (ObjectUtils.isEmpty(departureDateString)) {
|
||||
departureDateString = LocalDate.now().toString();
|
||||
}
|
||||
if (StringUtils.isEmpty(serviceClassString)) {
|
||||
if (ObjectUtils.isEmpty(serviceClassString)) {
|
||||
serviceClassString = "ECONOMY";
|
||||
}
|
||||
ServiceClass serviceClass = ServiceClass.valueOf(serviceClassString);
|
||||
LocalDate departureDate = new LocalDate(departureDateString);
|
||||
ZonedDateTime departureDate = ZonedDateTime.parse(departureDateString);
|
||||
|
||||
if (StringUtils.hasLength(fromAirportCode) && StringUtils.hasLength(toAirportCode)) {
|
||||
model.addAttribute("from", fromAirportCode);
|
||||
|
||||
@@ -18,43 +18,33 @@ package org.springframework.ws.samples.airline.ws;
|
||||
|
||||
import static org.springframework.ws.samples.airline.ws.AirlineWebServiceConstants.*;
|
||||
|
||||
import jakarta.xml.bind.JAXBElement;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBElement;
|
||||
import javax.xml.datatype.DatatypeConfigurationException;
|
||||
import javax.xml.datatype.XMLGregorianCalendar;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.ws.samples.airline.domain.FrequentFlyer;
|
||||
import org.springframework.ws.samples.airline.domain.Passenger;
|
||||
import org.springframework.ws.samples.airline.domain.ServiceClass;
|
||||
import org.springframework.ws.samples.airline.schema.BookFlightRequest;
|
||||
import org.springframework.ws.samples.airline.schema.GetFlightsResponse;
|
||||
import org.springframework.ws.samples.airline.schema.Name;
|
||||
import org.springframework.ws.samples.airline.schema.ObjectFactory;
|
||||
import org.springframework.ws.samples.airline.schema.Ticket;
|
||||
import org.springframework.ws.samples.airline.schema.*;
|
||||
import org.springframework.ws.samples.airline.schema.support.SchemaConversionUtils;
|
||||
import org.springframework.ws.samples.airline.service.AirlineService;
|
||||
import org.springframework.ws.samples.airline.service.NoSeatAvailableException;
|
||||
import org.springframework.ws.samples.airline.service.NoSuchFlightException;
|
||||
import org.springframework.ws.samples.airline.service.NoSuchFrequentFlyerException;
|
||||
import org.springframework.ws.server.endpoint.annotation.Endpoint;
|
||||
import org.springframework.ws.server.endpoint.annotation.Namespace;
|
||||
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
|
||||
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
|
||||
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
|
||||
import org.springframework.ws.server.endpoint.annotation.XPathParam;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.springframework.ws.server.endpoint.annotation.*;
|
||||
|
||||
/**
|
||||
* Endpoint that handles the Airline Web Service messages using a combination of JAXB2 marshalling and XPath
|
||||
@@ -99,7 +89,7 @@ public class AirlineEndpoint {
|
||||
logger.debug("Received GetFlightsRequest '" + from + "' to '" + to + "' on " + departureDateString);
|
||||
}
|
||||
|
||||
LocalDate departureDate = new LocalDate(departureDateString);
|
||||
ZonedDateTime departureDate = LocalDate.parse(departureDateString).atStartOfDay(ZoneId.systemDefault());
|
||||
ServiceClass serviceClass = null;
|
||||
|
||||
if (StringUtils.hasLength(serviceClassString)) {
|
||||
@@ -165,22 +155,4 @@ public class AirlineEndpoint {
|
||||
|
||||
return SchemaConversionUtils.toSchemaType(domainTicket);
|
||||
}
|
||||
|
||||
@PayloadRoot(localPart = GET_FREQUENT_FLYER_MILEAGE_REQUEST, namespace = MESSAGES_NAMESPACE)
|
||||
@ResponsePayload
|
||||
public Element getFrequentFlyerMileage() throws Exception {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Received GetFrequentFlyerMileageRequest");
|
||||
}
|
||||
|
||||
int mileage = airlineService.getFrequentFlyerMileage();
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.newDocument();
|
||||
Element response = document.createElementNS(MESSAGES_NAMESPACE, GET_FREQUENT_FLYER_MILEAGE_RESPONSE);
|
||||
response.setTextContent(Integer.toString(mileage));
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,14 +8,10 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
import org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.ws.soap.security.xwss.XwsSecurityInterceptor;
|
||||
import org.springframework.ws.soap.security.xwss.callback.SpringDigestPasswordValidationCallbackHandler;
|
||||
import org.springframework.ws.soap.server.SoapMessageDispatcher;
|
||||
import org.springframework.ws.soap.server.endpoint.interceptor.PayloadRootSmartSoapEndpointInterceptor;
|
||||
import org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor;
|
||||
import org.springframework.ws.transport.http.MessageDispatcherServlet;
|
||||
import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
|
||||
@@ -60,33 +56,33 @@ public class WebServicesConfiguration {
|
||||
return payloadValidatingInterceptor;
|
||||
}
|
||||
|
||||
@Bean
|
||||
XwsSecurityInterceptor securityInterceptor(UserDetailsService securityService) {
|
||||
// @Bean
|
||||
// XwsSecurityInterceptor securityInterceptor(UserDetailsService securityService) {
|
||||
//
|
||||
// XwsSecurityInterceptor securityInterceptor = new XwsSecurityInterceptor();
|
||||
// securityInterceptor.setSecureResponse(false);
|
||||
// securityInterceptor.setPolicyConfiguration(
|
||||
// new ClassPathResource("org/springframework/ws/samples/airline/security/securityPolicy.xml"));
|
||||
// securityInterceptor.setCallbackHandler(springDigestPasswordValidationCallbackHandler(securityService));
|
||||
//
|
||||
// return securityInterceptor;
|
||||
// }
|
||||
|
||||
XwsSecurityInterceptor securityInterceptor = new XwsSecurityInterceptor();
|
||||
securityInterceptor.setSecureResponse(false);
|
||||
securityInterceptor.setPolicyConfiguration(
|
||||
new ClassPathResource("org/springframework/ws/samples/airline/security/securityPolicy.xml"));
|
||||
securityInterceptor.setCallbackHandler(springDigestPasswordValidationCallbackHandler(securityService));
|
||||
// @Bean
|
||||
// PayloadRootSmartSoapEndpointInterceptor smartSoapEndpointInterceptor(XwsSecurityInterceptor securityInterceptor) {
|
||||
//
|
||||
// return new PayloadRootSmartSoapEndpointInterceptor(securityInterceptor,
|
||||
// "http://www.springframework.org/spring-ws/samples/airline/schemas/messages", "GetFrequentFlyerMileageRequest");
|
||||
// }
|
||||
|
||||
return securityInterceptor;
|
||||
}
|
||||
|
||||
@Bean
|
||||
PayloadRootSmartSoapEndpointInterceptor smartSoapEndpointInterceptor(XwsSecurityInterceptor securityInterceptor) {
|
||||
|
||||
return new PayloadRootSmartSoapEndpointInterceptor(securityInterceptor,
|
||||
"http://www.springframework.org/spring-ws/samples/airline/schemas/messages", "GetFrequentFlyerMileageRequest");
|
||||
}
|
||||
|
||||
@Bean
|
||||
SpringDigestPasswordValidationCallbackHandler springDigestPasswordValidationCallbackHandler(
|
||||
UserDetailsService securityService) {
|
||||
|
||||
SpringDigestPasswordValidationCallbackHandler handler = new SpringDigestPasswordValidationCallbackHandler();
|
||||
handler.setUserDetailsService(securityService);
|
||||
return handler;
|
||||
}
|
||||
// @Bean
|
||||
// SpringDigestPasswordValidationCallbackHandler springDigestPasswordValidationCallbackHandler(
|
||||
// UserDetailsService securityService) {
|
||||
//
|
||||
// SpringDigestPasswordValidationCallbackHandler handler = new SpringDigestPasswordValidationCallbackHandler();
|
||||
// handler.setUserDetailsService(securityService);
|
||||
// return handler;
|
||||
// }
|
||||
|
||||
@Bean
|
||||
SaajSoapMessageFactory messageFactory() {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
logging.level.org.springframework.data=DEBUG
|
||||
logging.level.org.springframework.ws=DEBUG
|
||||
logging.level.org.springframework.web=DEBUG
|
||||
logging.level.org.springframework.jms=DEBUG
|
||||
logging.level.org.springframework.ws=DEBUG
|
||||
#logging.level.org.apache.activemq=DEBUG
|
||||
|
||||
Reference in New Issue
Block a user