This commit is contained in:
Arjen Poutsma
2008-03-16 13:39:43 +00:00
parent cb70abfc87
commit 7613bc5826
11 changed files with 74 additions and 92 deletions

View File

@@ -1,4 +1,5 @@
<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>
<artifactId>spring-ws-samples</artifactId>
<groupId>org.springframework.ws</groupId>
@@ -134,7 +135,8 @@
<phase>process-classes</phase>
<configuration>
<tasks>
<java classname="org.apache.openjpa.enhance.PCEnhancer" classpathref="maven.runtime.classpath" dir="target/classes" fork="true" />
<java classname="org.apache.openjpa.enhance.PCEnhancer"
classpathref="maven.runtime.classpath" dir="target/classes" fork="true"/>
</tasks>
</configuration>
<goals>
@@ -177,6 +179,12 @@
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-security</artifactId>
<scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>org.apache.ws.security</groupId>
<artifactId>wss4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Spring dependencies -->
<dependency>

View File

@@ -20,6 +20,7 @@ import java.util.List;
import org.acegisecurity.annotation.Secured;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ws.samples.airline.domain.Flight;
import org.springframework.ws.samples.airline.domain.FrequentFlyer;
@@ -32,7 +33,6 @@ import org.springframework.ws.samples.airline.domain.Ticket;
*
* @author Arjen Poutsma
*/
@Transactional(readOnly = true)
public interface AirlineService {
/**

View File

@@ -21,6 +21,10 @@ 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.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;
@@ -41,6 +45,8 @@ import org.springframework.ws.samples.airline.service.NoSuchFrequentFlyerExcepti
*
* @author Arjen Poutsma
*/
@Service
@Transactional(readOnly = true)
public class AirlineServiceImpl implements AirlineService {
private static final Log logger = LogFactory.getLog(AirlineServiceImpl.class);
@@ -51,15 +57,19 @@ public class AirlineServiceImpl implements AirlineService {
private FrequentFlyerSecurityService frequentFlyerSecurityService = new StubFrequentFlyerSecurityService();
@Autowired
public AirlineServiceImpl(FlightDao flightDao, TicketDao ticketDao) {
this.flightDao = flightDao;
this.ticketDao = ticketDao;
}
@Autowired
public void setFrequentFlyerSecurityService(FrequentFlyerSecurityService frequentFlyerSecurityService) {
this.frequentFlyerSecurityService = frequentFlyerSecurityService;
}
@Transactional(readOnly = false,
rollbackFor = {NoSuchFlightException.class, NoSeatAvailableException.class, NoSuchFrequentFlyerException.class})
public Ticket bookFlight(String flightNumber, DateTime departureTime, List<Passenger> passengers)
throws NoSuchFlightException, NoSeatAvailableException, NoSuchFrequentFlyerException {
Assert.notEmpty(passengers, "No passengers given");

View File

@@ -16,57 +16,62 @@
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.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.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
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;
/** @author Arjen Poutsma */
public class FlightsController extends MultiActionController {
@Controller
public class FlightsController {
private AirlineService airlineService;
@Autowired
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");
@RequestMapping("/flights")
public String flightList(@RequestParam(value = "from", required = false)String fromAirportCode,
@RequestParam(value = "to", required = false)String toAirportCode,
@RequestParam(value = "departureDate", required = false)String departureDateString,
@RequestParam(value = "serviceClass", required = false)String serviceClassString,
ModelMap model) {
if (!StringUtils.hasLength(departureDateString)) {
departureDateString = new LocalDate().toString();
}
if (!StringUtils.hasLength(serviceClassString)) {
serviceClassString = "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",
model.addAttribute("from", fromAirportCode);
model.addAttribute("to", toAirportCode);
model.addAttribute("departureDate", departureDateString);
model.addAttribute("serviceClass", serviceClassString);
model.addAttribute("flights",
airlineService.getFlights(fromAirportCode, toAirportCode, departureDate, serviceClass));
}
return mav;
return "flights";
}
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));
@RequestMapping(value = "/flight")
public String singleFlight(@RequestParam("id")long id, ModelMap model) throws Exception {
Flight flight = airlineService.getFlight(id);
return new ModelAndView("flight", "flight", flight);
model.addAttribute(flight);
return "flight";
}
}

View File

@@ -1,6 +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"
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.5.xsd">
<bean id="flightDao" class="org.springframework.ws.samples.airline.dao.jpa.JpaFlightDao">

View File

@@ -1,21 +0,0 @@
#
# 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

View File

@@ -2,21 +2,21 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
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
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
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">
<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>
<constructor-arg ref="flightDao"/>
<constructor-arg ref="ticketDao"/>
<property name="frequentFlyerSecurityService" ref="securityService"/>
</bean>
</beans>

View File

@@ -3,7 +3,7 @@
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.0.xsd
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
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-1.5.xsd">
@@ -184,5 +184,4 @@
</property>
</bean>
</beans>

View File

@@ -44,9 +44,10 @@
<c:forEach var="flight" items="${flights}">
<tr>
<td>
<a href='<c:url value="flights/${flight.id}"/>'>
<c:out value="${flight.number}"/>
</a>
<c:url var="flightUrl" value="flight">
<c:param name="id" value="${flight.id}"/>
</c:url>
<a href='<c:out value="${flightUrl}"/>'><c:out value="${flight.number}"/></a>
</td>
<td>
<c:out value="${flight.from.city}"/>

View File

@@ -1,39 +1,19 @@
<?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">
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.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.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>
<context:annotation-config/>
<!-- ===================== 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 id="flightController" class="org.springframework.ws.samples.airline.web.FlightsController"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>

View File

@@ -1,9 +1,9 @@
<?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"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
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"
version="2.4">
<display-name>Spring-WS Airline Sample</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
@@ -39,7 +39,7 @@
</servlet-mapping>
<servlet-mapping>
<servlet-name>mvc</servlet-name>
<url-pattern>/flights/*</url-pattern>
<url-pattern>/flight</url-pattern>
</servlet-mapping>
<mime-mapping>
<extension>xsd</extension>