Bring airline sample up to date

This commit is contained in:
Arjen Poutsma
2011-01-04 13:01:18 +00:00
parent dfd12c01f2
commit 20d9c055a3
17 changed files with 75 additions and 104 deletions

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2007 the original author or authors.
* 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
* 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,
@@ -16,13 +16,12 @@
package org.springframework.ws.samples.airline.dao.jpa;
import javax.annotation.PostConstruct;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.joda.time.DateTime;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
@@ -32,16 +31,23 @@ import org.springframework.ws.samples.airline.domain.Flight;
import org.springframework.ws.samples.airline.domain.FrequentFlyer;
import org.springframework.ws.samples.airline.domain.ServiceClass;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.joda.time.DateTime;
/**
* A simple class that uses JPA to initialize the database.
*
* @author Arjen Poutsma
* @since 1.5.0
*/
public class DatabaseInitializer implements InitializingBean {
@Component
public class DatabaseInitializer {
private static final Log logger = LogFactory.getLog(DatabaseInitializer.class);
private final TransactionTemplate transactionTemplate;
@PersistenceContext
private EntityManager entityManager;
@@ -49,13 +55,13 @@ public class DatabaseInitializer implements InitializingBean {
private Airport venice;
private TransactionTemplate transactionTemplate;
public void setTransactionManager(PlatformTransactionManager transactionManager) {
@Autowired
public DatabaseInitializer(PlatformTransactionManager transactionManager) {
this.transactionTemplate = new TransactionTemplate(transactionManager);
}
public void afterPropertiesSet() throws Exception {
@PostConstruct
public void initDatabase() {
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
logger.info("Initializing Database");

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2006 the original author or authors.
* 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
* 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,
@@ -16,6 +16,7 @@
package org.springframework.ws.samples.airline.security;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
@@ -37,6 +38,7 @@ public class SpringFrequentFlyerSecurityService implements FrequentFlyerSecurity
private FrequentFlyerDao frequentFlyerDao;
@Autowired
public SpringFrequentFlyerSecurityService(FrequentFlyerDao frequentFlyerDao) {
this.frequentFlyerDao = frequentFlyerDao;
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2006 the original author or authors.
* 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
* 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,
@@ -17,11 +17,6 @@ package org.springframework.ws.samples.airline.service.impl;
import java.util.List;
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.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Service;
@@ -41,6 +36,11 @@ 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.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
/**
* Default implementation of the <code>AirlineService</code> interface.
*
@@ -64,7 +64,7 @@ public class AirlineServiceImpl implements AirlineService {
this.ticketDao = ticketDao;
}
@Autowired
@Autowired(required = false)
public void setFrequentFlyerSecurityService(FrequentFlyerSecurityService frequentFlyerSecurityService) {
this.frequentFlyerSecurityService = frequentFlyerSecurityService;
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2007 the original author or authors.
* 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
* 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,
@@ -16,21 +16,24 @@
package org.springframework.ws.samples.airline.web;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.ws.samples.airline.domain.Flight;
import org.springframework.ws.samples.airline.domain.ServiceClass;
import org.springframework.ws.samples.airline.service.AirlineService;
import org.springframework.ws.samples.airline.service.NoSuchFlightException;
import org.joda.time.LocalDate;
/** @author Arjen Poutsma */
@Controller
@RequestMapping("/flights")
public class FlightsController {
private AirlineService airlineService;
@@ -41,7 +44,7 @@ public class FlightsController {
this.airlineService = airlineService;
}
@RequestMapping("/flights")
@RequestMapping
public String flightList(@RequestParam(value = "from", required = false)String fromAirportCode,
@RequestParam(value = "to", required = false)String toAirportCode,
@RequestParam(value = "departureDate", required = false)String departureDateString,
@@ -67,8 +70,8 @@ public class FlightsController {
return "flights";
}
@RequestMapping(value = "/flight")
public String singleFlight(@RequestParam("id")long id, ModelMap model) throws Exception {
@RequestMapping(value = "{id}")
public String singleFlight(@PathVariable("id") long id, ModelMap model) throws NoSuchFlightException {
Flight flight = airlineService.getFlight(id);
model.addAttribute(flight);
return "flight";

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2006 the original author or authors.
* 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
* 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,
@@ -16,6 +16,7 @@
package org.springframework.ws.samples.airline.ws;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.samples.airline.service.AirlineService;
import org.springframework.ws.server.endpoint.AbstractDomPayloadEndpoint;
@@ -32,6 +33,7 @@ public class GetFrequentFlyerMileageEndpoint extends AbstractDomPayloadEndpoint
private final AirlineService airlineService;
@Autowired
public GetFrequentFlyerMileageEndpoint(AirlineService airlineService) {
this.airlineService = airlineService;
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2007 the original author or authors.
* 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
* 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,
@@ -23,6 +23,7 @@ import javax.xml.bind.JAXBElement;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.XMLGregorianCalendar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.ws.samples.airline.domain.FrequentFlyer;
import org.springframework.ws.samples.airline.domain.Passenger;
@@ -64,6 +65,7 @@ public class MarshallingAirlineEndpoint implements AirlineWebServiceConstants {
private ObjectFactory objectFactory = new ObjectFactory();
@Autowired
public MarshallingAirlineEndpoint(AirlineService airlineService) {
Assert.notNull(airlineService, "airlineService must not be null");
this.airlineService = airlineService;

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2007 the original author or authors.
* 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
* 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,
@@ -23,6 +23,7 @@ import javax.xml.bind.JAXBException;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.transform.Source;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.oxm.Marshaller;
import org.springframework.oxm.support.MarshallingSource;
import org.springframework.util.Assert;
@@ -71,6 +72,7 @@ public class XPathAirlineEndpoint implements AirlineWebServiceConstants {
private final Marshaller marshaller;
@Autowired
public XPathAirlineEndpoint(AirlineService airlineService, Marshaller marshaller) {
Assert.notNull(airlineService, "airlineService must not be null");
Assert.notNull(marshaller, "'marshaller' must not be null");

View File

@@ -1,30 +1,13 @@
<?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.5.xsd">
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="org.springframework.ws.samples.airline.dao.jpa"/>
<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 class="org.springframework.ws.samples.airline.dao.jpa.DatabaseInitializer">
<property name="transactionManager" ref="transactionManager"/>
</bean>
<context:annotation-config/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="airline"/>
@@ -56,18 +39,4 @@
<property name="password" value=""/>
</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>

View File

@@ -2,8 +2,8 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jms="http://www.springframework.org/schema/jms"
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.5.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-2.5.xsd">
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd">
<!-- ===================== JMS TRANSPORT ===================================== -->

View File

@@ -20,7 +20,6 @@
<description>
A security service used to obtain Frequent Flyer information.
</description>
<constructor-arg ref="frequentFlyerDao"/>
</bean>
<bean id="wsSecurityInterceptor" class="org.springframework.ws.soap.security.xwss.XwsSecurityInterceptor">

View File

@@ -3,20 +3,14 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<tx:annotation-driven/>
<context:annotation-config/>
<bean id="airlineService" class="org.springframework.ws.samples.airline.service.impl.AirlineServiceImpl">
<description>
The Airline business service. It requires a flight DAO and ticket DAO to work. The
frequentFlyerSecurityService property is not required, so we use a property to configure it.
</description>
</bean>
<context:component-scan base-package="org.springframework.ws.samples.airline.service"/>
</beans>

View File

@@ -3,8 +3,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:oxm="http://www.springframework.org/schema/oxm"
xmlns:sws="http://www.springframework.org/schema/web-services"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-1.5.xsd">
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
@@ -31,7 +31,6 @@
<description>
This endpoint handles the Airline Web Service messages using JAXB2 marshalling.
</description>
<constructor-arg ref="airlineService"/>
</bean>
<!--
@@ -39,8 +38,6 @@
<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>
-->
@@ -49,7 +46,6 @@
<description>
This endpoint handles get frequent flyer mileage requests.
</description>
<constructor-arg ref="airlineService"/>
</bean>
<oxm:jaxb2-marshaller id="marshaller" contextPath="org.springframework.ws.samples.airline.schema"/>

View File

@@ -42,6 +42,6 @@
</td>
</tr>
</table>
<a href='<c:url value="/flights"/>'>Flights</a>
<a href='<c:url value="/flights.html"/>'>Flights</a>
</body>
</html>

View File

@@ -1,10 +1,11 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ 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"/>'>
<form a method="get" action='<c:url value="/flights.html"/>'>
<table>
<tr>
<td>From:</td>
@@ -44,9 +45,9 @@
<c:forEach var="flight" items="${flights}">
<tr>
<td>
<c:url var="flightUrl" value="flight">
<c:param name="id" value="${flight.id}"/>
</c:url>
<spring:url var="flightUrl" value="flights/{id}.html">
<spring:param name="id" value="${flight.id}"/>
</spring:url>
<a href='<c:out value="${flightUrl}"/>'><c:out value="${flight.number}"/></a>
</td>
<td>

View File

@@ -36,11 +36,7 @@
</servlet>
<servlet-mapping>
<servlet-name>mvc</servlet-name>
<url-pattern>/flights</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>mvc</servlet-name>
<url-pattern>/flight</url-pattern>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<mime-mapping>
<extension>xsd</extension>

View File

@@ -1,7 +1,6 @@
<?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">
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- ===================== WSDL DEFINITION ============================== -->

View File

@@ -1,3 +1,3 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:redirect url="/flights"/>
<c:redirect url="/flights.html"/>