Skip to content

Commit 7613bc5

Browse files
committed
SWS-313
1 parent cb70abf commit 7613bc5

File tree

11 files changed

+74
-92
lines changed

11 files changed

+74
-92
lines changed

samples/airline/pom.xml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<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">
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
23
<parent>
34
<artifactId>spring-ws-samples</artifactId>
45
<groupId>org.springframework.ws</groupId>
@@ -134,7 +135,8 @@
134135
<phase>process-classes</phase>
135136
<configuration>
136137
<tasks>
137-
<java classname="org.apache.openjpa.enhance.PCEnhancer" classpathref="maven.runtime.classpath" dir="target/classes" fork="true" />
138+
<java classname="org.apache.openjpa.enhance.PCEnhancer"
139+
classpathref="maven.runtime.classpath" dir="target/classes" fork="true"/>
138140
</tasks>
139141
</configuration>
140142
<goals>
@@ -177,6 +179,12 @@
177179
<groupId>org.springframework.ws</groupId>
178180
<artifactId>spring-ws-security</artifactId>
179181
<scope>runtime</scope>
182+
<exclusions>
183+
<exclusion>
184+
<groupId>org.apache.ws.security</groupId>
185+
<artifactId>wss4j</artifactId>
186+
</exclusion>
187+
</exclusions>
180188
</dependency>
181189
<!-- Spring dependencies -->
182190
<dependency>

samples/airline/src/main/java/org/springframework/ws/samples/airline/service/AirlineService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.acegisecurity.annotation.Secured;
2121
import org.joda.time.DateTime;
2222
import org.joda.time.LocalDate;
23+
2324
import org.springframework.transaction.annotation.Transactional;
2425
import org.springframework.ws.samples.airline.domain.Flight;
2526
import org.springframework.ws.samples.airline.domain.FrequentFlyer;
@@ -32,7 +33,6 @@
3233
*
3334
* @author Arjen Poutsma
3435
*/
35-
@Transactional(readOnly = true)
3636
public interface AirlineService {
3737

3838
/**

samples/airline/src/main/java/org/springframework/ws/samples/airline/service/impl/AirlineServiceImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
import org.apache.commons.logging.LogFactory;
2222
import org.joda.time.DateTime;
2323
import org.joda.time.LocalDate;
24+
25+
import org.springframework.beans.factory.annotation.Autowired;
26+
import org.springframework.stereotype.Service;
27+
import org.springframework.transaction.annotation.Transactional;
2428
import org.springframework.util.Assert;
2529
import org.springframework.ws.samples.airline.dao.FlightDao;
2630
import org.springframework.ws.samples.airline.dao.TicketDao;
@@ -41,6 +45,8 @@
4145
*
4246
* @author Arjen Poutsma
4347
*/
48+
@Service
49+
@Transactional(readOnly = true)
4450
public class AirlineServiceImpl implements AirlineService {
4551

4652
private static final Log logger = LogFactory.getLog(AirlineServiceImpl.class);
@@ -51,15 +57,19 @@ public class AirlineServiceImpl implements AirlineService {
5157

5258
private FrequentFlyerSecurityService frequentFlyerSecurityService = new StubFrequentFlyerSecurityService();
5359

60+
@Autowired
5461
public AirlineServiceImpl(FlightDao flightDao, TicketDao ticketDao) {
5562
this.flightDao = flightDao;
5663
this.ticketDao = ticketDao;
5764
}
5865

66+
@Autowired
5967
public void setFrequentFlyerSecurityService(FrequentFlyerSecurityService frequentFlyerSecurityService) {
6068
this.frequentFlyerSecurityService = frequentFlyerSecurityService;
6169
}
6270

71+
@Transactional(readOnly = false,
72+
rollbackFor = {NoSuchFlightException.class, NoSeatAvailableException.class, NoSuchFrequentFlyerException.class})
6373
public Ticket bookFlight(String flightNumber, DateTime departureTime, List<Passenger> passengers)
6474
throws NoSuchFlightException, NoSeatAvailableException, NoSuchFrequentFlyerException {
6575
Assert.notEmpty(passengers, "No passengers given");

samples/airline/src/main/java/org/springframework/ws/samples/airline/web/FlightsController.java

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,57 +16,62 @@
1616

1717
package org.springframework.ws.samples.airline.web;
1818

19-
import javax.servlet.http.HttpServletRequest;
20-
import javax.servlet.http.HttpServletResponse;
21-
2219
import org.joda.time.LocalDate;
20+
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.stereotype.Controller;
23+
import org.springframework.ui.ModelMap;
2324
import org.springframework.util.Assert;
2425
import org.springframework.util.StringUtils;
25-
import org.springframework.web.bind.ServletRequestUtils;
26-
import org.springframework.web.servlet.ModelAndView;
27-
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
26+
import org.springframework.web.bind.annotation.RequestMapping;
27+
import org.springframework.web.bind.annotation.RequestParam;
2828
import org.springframework.ws.samples.airline.domain.Flight;
2929
import org.springframework.ws.samples.airline.domain.ServiceClass;
3030
import org.springframework.ws.samples.airline.service.AirlineService;
3131

3232
/** @author Arjen Poutsma */
33-
public class FlightsController extends MultiActionController {
33+
@Controller
34+
public class FlightsController {
3435

3536
private AirlineService airlineService;
3637

38+
@Autowired
3739
public FlightsController(AirlineService airlineService) {
3840
Assert.notNull(airlineService, "'airlineService' must not be null");
3941
this.airlineService = airlineService;
4042
}
4143

42-
public ModelAndView flightList(HttpServletRequest request, HttpServletResponse response) throws Exception {
43-
String fromAirportCode = ServletRequestUtils.getStringParameter(request, "from");
44-
String toAirportCode = ServletRequestUtils.getStringParameter(request, "to");
45-
String departureDateString =
46-
ServletRequestUtils.getStringParameter(request, "departureDate", new LocalDate().toString());
47-
String serviceClassString = ServletRequestUtils.getStringParameter(request, "serviceClass", "ECONOMY");
48-
44+
@RequestMapping("/flights")
45+
public String flightList(@RequestParam(value = "from", required = false)String fromAirportCode,
46+
@RequestParam(value = "to", required = false)String toAirportCode,
47+
@RequestParam(value = "departureDate", required = false)String departureDateString,
48+
@RequestParam(value = "serviceClass", required = false)String serviceClassString,
49+
ModelMap model) {
50+
if (!StringUtils.hasLength(departureDateString)) {
51+
departureDateString = new LocalDate().toString();
52+
}
53+
if (!StringUtils.hasLength(serviceClassString)) {
54+
serviceClassString = "ECONOMY";
55+
}
4956
ServiceClass serviceClass = ServiceClass.valueOf(serviceClassString);
5057
LocalDate departureDate = new LocalDate(departureDateString);
5158

52-
ModelAndView mav = new ModelAndView("flights");
5359
if (StringUtils.hasLength(fromAirportCode) && StringUtils.hasLength(toAirportCode)) {
54-
mav.addObject("from", fromAirportCode);
55-
mav.addObject("to", toAirportCode);
56-
mav.addObject("departureDate", departureDateString);
57-
mav.addObject("serviceClass", serviceClassString);
58-
mav.addObject("flights",
60+
model.addAttribute("from", fromAirportCode);
61+
model.addAttribute("to", toAirportCode);
62+
model.addAttribute("departureDate", departureDateString);
63+
model.addAttribute("serviceClass", serviceClassString);
64+
model.addAttribute("flights",
5965
airlineService.getFlights(fromAirportCode, toAirportCode, departureDate, serviceClass));
6066
}
61-
return mav;
67+
return "flights";
6268
}
6369

64-
public ModelAndView singleFlight(HttpServletRequest request, HttpServletResponse response) throws Exception {
65-
String uri = request.getRequestURI();
66-
int pos = uri.lastIndexOf('/') + 1;
67-
long id = Long.parseLong(uri.substring(pos));
70+
@RequestMapping(value = "/flight")
71+
public String singleFlight(@RequestParam("id")long id, ModelMap model) throws Exception {
6872
Flight flight = airlineService.getFlight(id);
69-
return new ModelAndView("flight", "flight", flight);
73+
model.addAttribute(flight);
74+
return "flight";
7075
}
7176

7277
}

samples/airline/src/main/resources/org/springframework/ws/samples/airline/dao/jpa/applicationContext-jpa.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
3+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
44

55

66
<bean id="flightDao" class="org.springframework.ws.samples.airline.dao.jpa.JpaFlightDao">

samples/airline/src/main/resources/org/springframework/ws/samples/airline/dao/jpa/hibernate.properties

Lines changed: 0 additions & 21 deletions
This file was deleted.

samples/airline/src/main/resources/org/springframework/ws/samples/airline/service/applicationContext.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
<beans xmlns="http://www.springframework.org/schema/beans"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xmlns:tx="http://www.springframework.org/schema/tx"
5-
xmlns:aop="http://www.springframework.org/schema/aop"
6-
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
7-
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
8-
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
5+
xmlns:context="http://www.springframework.org/schema/context"
6+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
7+
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
8+
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
9+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
910

1011
<tx:annotation-driven/>
1112

13+
<context:annotation-config/>
14+
1215
<bean id="airlineService" class="org.springframework.ws.samples.airline.service.impl.AirlineServiceImpl">
1316
<description>
1417
The Airline business service. It requires a flight DAO and ticket DAO to work. The
1518
frequentFlyerSecurityService property is not required, so we use a property to configure it.
1619
</description>
17-
<constructor-arg ref="flightDao"/>
18-
<constructor-arg ref="ticketDao"/>
19-
<property name="frequentFlyerSecurityService" ref="securityService"/>
2020
</bean>
2121

2222
</beans>

samples/airline/src/main/resources/org/springframework/ws/samples/airline/ws/applicationContext-ws.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xmlns:oxm="http://www.springframework.org/schema/oxm"
55
xmlns:sws="http://www.springframework.org/schema/web-services"
6-
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
6+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
77
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd
88
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-1.5.xsd">
99

@@ -184,5 +184,4 @@
184184
</property>
185185
</bean>
186186

187-
188187
</beans>

samples/airline/src/main/webapp/WEB-INF/jsp/flights.jsp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@
4444
<c:forEach var="flight" items="${flights}">
4545
<tr>
4646
<td>
47-
<a href='<c:url value="flights/${flight.id}"/>'>
48-
<c:out value="${flight.number}"/>
49-
</a>
47+
<c:url var="flightUrl" value="flight">
48+
<c:param name="id" value="${flight.id}"/>
49+
</c:url>
50+
<a href='<c:out value="${flightUrl}"/>'><c:out value="${flight.number}"/></a>
5051
</td>
5152
<td>
5253
<c:out value="${flight.from.city}"/>

samples/airline/src/main/webapp/WEB-INF/mvc-servlet.xml

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<beans xmlns="http://www.springframework.org/schema/beans"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
4+
xmlns:context="http://www.springframework.org/schema/context"
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
6+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
57

68
<description>
79
This web application context contains a simple Spring Web MVC web application that shows flights
810
</description>
911

10-
<!-- ===================== HANDLER MAPPINGS ============================== -->
11-
12-
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
13-
<property name="mappings">
14-
<props>
15-
<prop key="/flights">flightController</prop>
16-
<prop key="/flights/*">flightController</prop>
17-
</props>
18-
</property>
19-
</bean>
20-
12+
<context:annotation-config/>
2113

2214
<!-- ===================== HANDLERS ===================================== -->
2315

24-
<bean id="flightController" class="org.springframework.ws.samples.airline.web.FlightsController">
25-
<constructor-arg ref="airlineService"/>
26-
<property name="methodNameResolver">
27-
<bean class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
28-
<property name="mappings">
29-
<props>
30-
<prop key="/flights">flightList</prop>
31-
<prop key="/flights/*">singleFlight</prop>
32-
</props>
33-
</property>
34-
</bean>
35-
</property>
36-
</bean>
16+
<bean id="flightController" class="org.springframework.ws.samples.airline.web.FlightsController"/>
3717

3818
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
3919
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>

0 commit comments

Comments
 (0)