From 20d9c055a36764144b08ecf13a96a1b6f2c1ef2e Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Tue, 4 Jan 2011 13:01:18 +0000 Subject: [PATCH] Bring airline sample up to date --- .../airline/dao/jpa/DatabaseInitializer.java | 28 +++++++----- .../SpringFrequentFlyerSecurityService.java | 6 ++- .../service/impl/AirlineServiceImpl.java | 16 +++---- .../airline/web/FlightsController.java | 17 ++++--- .../ws/GetFrequentFlyerMileageEndpoint.java | 6 ++- .../ws/MarshallingAirlineEndpoint.java | 6 ++- .../airline/ws/XPathAirlineEndpoint.java | 6 ++- .../dao/jpa/applicationContext-jpa.xml | 45 +++---------------- .../airline/jms/applicationContext-jms.xml | 4 +- .../security/applicationContext-security.xml | 1 - .../airline/service/applicationContext.xml | 14 ++---- .../airline/ws/applicationContext-ws.xml | 8 +--- .../src/main/webapp/WEB-INF/jsp/flight.jsp | 2 +- .../src/main/webapp/WEB-INF/jsp/flights.jsp | 9 ++-- .../server/src/main/webapp/WEB-INF/web.xml | 6 +-- .../src/main/webapp/WEB-INF/ws-servlet.xml | 3 +- .../airline/server/src/main/webapp/index.jsp | 2 +- 17 files changed, 75 insertions(+), 104 deletions(-) diff --git a/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/dao/jpa/DatabaseInitializer.java b/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/dao/jpa/DatabaseInitializer.java index 54d24aeb..a4a506a7 100644 --- a/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/dao/jpa/DatabaseInitializer.java +++ b/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/dao/jpa/DatabaseInitializer.java @@ -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"); diff --git a/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/security/SpringFrequentFlyerSecurityService.java b/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/security/SpringFrequentFlyerSecurityService.java index 88d4419e..355d2a7f 100644 --- a/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/security/SpringFrequentFlyerSecurityService.java +++ b/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/security/SpringFrequentFlyerSecurityService.java @@ -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; } diff --git a/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/service/impl/AirlineServiceImpl.java b/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/service/impl/AirlineServiceImpl.java index 178cca2c..c9cfec12 100644 --- a/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/service/impl/AirlineServiceImpl.java +++ b/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/service/impl/AirlineServiceImpl.java @@ -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 AirlineService 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; } diff --git a/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/web/FlightsController.java b/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/web/FlightsController.java index 18631b2a..19e8525c 100644 --- a/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/web/FlightsController.java +++ b/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/web/FlightsController.java @@ -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"; diff --git a/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/ws/GetFrequentFlyerMileageEndpoint.java b/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/ws/GetFrequentFlyerMileageEndpoint.java index cc04b55a..c8c96abc 100644 --- a/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/ws/GetFrequentFlyerMileageEndpoint.java +++ b/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/ws/GetFrequentFlyerMileageEndpoint.java @@ -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; } diff --git a/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/ws/MarshallingAirlineEndpoint.java b/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/ws/MarshallingAirlineEndpoint.java index 36887c41..74aa95df 100644 --- a/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/ws/MarshallingAirlineEndpoint.java +++ b/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/ws/MarshallingAirlineEndpoint.java @@ -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; diff --git a/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/ws/XPathAirlineEndpoint.java b/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/ws/XPathAirlineEndpoint.java index ea525303..b8ff76ab 100644 --- a/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/ws/XPathAirlineEndpoint.java +++ b/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/ws/XPathAirlineEndpoint.java @@ -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"); diff --git a/samples/airline/server/src/main/resources/org/springframework/ws/samples/airline/dao/jpa/applicationContext-jpa.xml b/samples/airline/server/src/main/resources/org/springframework/ws/samples/airline/dao/jpa/applicationContext-jpa.xml index c932958c..850da863 100644 --- a/samples/airline/server/src/main/resources/org/springframework/ws/samples/airline/dao/jpa/applicationContext-jpa.xml +++ b/samples/airline/server/src/main/resources/org/springframework/ws/samples/airline/dao/jpa/applicationContext-jpa.xml @@ -1,30 +1,13 @@ - + + - - - A DAO for Flights. - - - - - - A DAO for Tickets. - - - - - - - A DAO for FrequentFlyers. - - - - - - + @@ -56,18 +39,4 @@ - - - Handles the @Repository annotation used on the JPA Dao's, and translates from the JPA - exceptions to Spring's richer DataAccessException hierarchy. - - - - - - Injects the JPA PersistenceContext into the JPA Dao's. - - - - diff --git a/samples/airline/server/src/main/resources/org/springframework/ws/samples/airline/jms/applicationContext-jms.xml b/samples/airline/server/src/main/resources/org/springframework/ws/samples/airline/jms/applicationContext-jms.xml index b94a5a24..9ca02275 100644 --- a/samples/airline/server/src/main/resources/org/springframework/ws/samples/airline/jms/applicationContext-jms.xml +++ b/samples/airline/server/src/main/resources/org/springframework/ws/samples/airline/jms/applicationContext-jms.xml @@ -2,8 +2,8 @@ + 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"> diff --git a/samples/airline/server/src/main/resources/org/springframework/ws/samples/airline/security/applicationContext-security.xml b/samples/airline/server/src/main/resources/org/springframework/ws/samples/airline/security/applicationContext-security.xml index 8a764974..3b5d299c 100644 --- a/samples/airline/server/src/main/resources/org/springframework/ws/samples/airline/security/applicationContext-security.xml +++ b/samples/airline/server/src/main/resources/org/springframework/ws/samples/airline/security/applicationContext-security.xml @@ -20,7 +20,6 @@ A security service used to obtain Frequent Flyer information. - diff --git a/samples/airline/server/src/main/resources/org/springframework/ws/samples/airline/service/applicationContext.xml b/samples/airline/server/src/main/resources/org/springframework/ws/samples/airline/service/applicationContext.xml index 73f507ea..3c30f10a 100644 --- a/samples/airline/server/src/main/resources/org/springframework/ws/samples/airline/service/applicationContext.xml +++ b/samples/airline/server/src/main/resources/org/springframework/ws/samples/airline/service/applicationContext.xml @@ -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"> - - - 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. - - + \ No newline at end of file diff --git a/samples/airline/server/src/main/resources/org/springframework/ws/samples/airline/ws/applicationContext-ws.xml b/samples/airline/server/src/main/resources/org/springframework/ws/samples/airline/ws/applicationContext-ws.xml index 45cc547e..c1302ad9 100644 --- a/samples/airline/server/src/main/resources/org/springframework/ws/samples/airline/ws/applicationContext-ws.xml +++ b/samples/airline/server/src/main/resources/org/springframework/ws/samples/airline/ws/applicationContext-ws.xml @@ -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"> @@ -31,7 +31,6 @@ This endpoint handles the Airline Web Service messages using JAXB2 marshalling. - @@ -49,7 +46,6 @@ This endpoint handles get frequent flyer mileage requests. - diff --git a/samples/airline/server/src/main/webapp/WEB-INF/jsp/flight.jsp b/samples/airline/server/src/main/webapp/WEB-INF/jsp/flight.jsp index a0244a0e..7c76fc04 100644 --- a/samples/airline/server/src/main/webapp/WEB-INF/jsp/flight.jsp +++ b/samples/airline/server/src/main/webapp/WEB-INF/jsp/flight.jsp @@ -42,6 +42,6 @@ -Flights +Flights \ No newline at end of file diff --git a/samples/airline/server/src/main/webapp/WEB-INF/jsp/flights.jsp b/samples/airline/server/src/main/webapp/WEB-INF/jsp/flights.jsp index e8b97dea..441c92ef 100644 --- a/samples/airline/server/src/main/webapp/WEB-INF/jsp/flights.jsp +++ b/samples/airline/server/src/main/webapp/WEB-INF/jsp/flights.jsp @@ -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" %> Flights -
+ @@ -44,9 +45,9 @@
From:
- - - + + + diff --git a/samples/airline/server/src/main/webapp/WEB-INF/web.xml b/samples/airline/server/src/main/webapp/WEB-INF/web.xml index 4194a264..da691a45 100644 --- a/samples/airline/server/src/main/webapp/WEB-INF/web.xml +++ b/samples/airline/server/src/main/webapp/WEB-INF/web.xml @@ -36,11 +36,7 @@ mvc - /flights - - - mvc - /flight + *.html xsd diff --git a/samples/airline/server/src/main/webapp/WEB-INF/ws-servlet.xml b/samples/airline/server/src/main/webapp/WEB-INF/ws-servlet.xml index a36fdf2d..df46c1f0 100644 --- a/samples/airline/server/src/main/webapp/WEB-INF/ws-servlet.xml +++ b/samples/airline/server/src/main/webapp/WEB-INF/ws-servlet.xml @@ -1,7 +1,6 @@ + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> diff --git a/samples/airline/server/src/main/webapp/index.jsp b/samples/airline/server/src/main/webapp/index.jsp index 18044935..09375550 100644 --- a/samples/airline/server/src/main/webapp/index.jsp +++ b/samples/airline/server/src/main/webapp/index.jsp @@ -1,3 +1,3 @@ <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - \ No newline at end of file + \ No newline at end of file