diff --git a/samples/airline/client/saaj/pom.xml b/samples/airline/client/saaj/pom.xml index edcaeac8..df0c4e98 100644 --- a/samples/airline/client/saaj/pom.xml +++ b/samples/airline/client/saaj/pom.xml @@ -58,7 +58,7 @@ - org.springframework.ws.samples.airline.client.saaj.GetFlights + org.springframework.ws.samples.airline.client.saaj.Driver diff --git a/samples/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/Driver.java b/samples/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/Driver.java new file mode 100644 index 00000000..046d0023 --- /dev/null +++ b/samples/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/Driver.java @@ -0,0 +1,41 @@ +/* + * 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.client.saaj; + +/** + * @author Arjen Poutsma + */ +public class Driver { + + public static void main(String[] args) throws Exception { + String url = "http://localhost:8080/airline-server/services"; + if (args.length > 0) { + url = args[0]; + } + GetFlights getFlights = new GetFlights(url); + getFlights.getFlights(); + + if (!System.getProperty("java.version").startsWith("1.5")) { + return; + } + String username = "john"; + String password = "changeme"; + GetFrequentFlyerMileage getMileage = new GetFrequentFlyerMileage(url); + getMileage.getMileage(username, password); + } + +} diff --git a/samples/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/GetFlights.java b/samples/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/GetFlights.java index 96dae1bf..b6bf6f35 100644 --- a/samples/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/GetFlights.java +++ b/samples/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/GetFlights.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, @@ -20,7 +20,6 @@ import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.Iterator; - import javax.xml.soap.MessageFactory; import javax.xml.soap.Name; import javax.xml.soap.SOAPBodyElement; @@ -115,13 +114,4 @@ public class GetFlights { transformer.transform(source, new StreamResult(System.out)); } } - - public static void main(String[] args) throws Exception { - String url = "http://localhost:8080/airline-server/services"; - if (args.length > 0) { - url = args[0]; - } - GetFlights getFlights = new GetFlights(url); - getFlights.getFlights(); - } } diff --git a/samples/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/GetFrequentFlyerMileage.java b/samples/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/GetFrequentFlyerMileage.java index 40cfded8..8c27d41b 100644 --- a/samples/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/GetFrequentFlyerMileage.java +++ b/samples/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/GetFrequentFlyerMileage.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, @@ -20,7 +20,6 @@ import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; - import javax.security.auth.callback.Callback; import javax.security.auth.callback.CallbackHandler; import javax.security.auth.callback.UnsupportedCallbackException; @@ -126,16 +125,4 @@ public class GetFrequentFlyerMileage { System.err.println("SOAP Fault String: " + fault.getFaultString()); } } - - public static void main(String[] args) throws Exception { - if (!System.getProperty("java.version").startsWith("1.5")) { - System.out.println("This sample will only run under JDK 1.5"); - return; - } - String url = "http://localhost:8080/airline-server/services"; - String username = "john"; - String password = "changeme"; - GetFrequentFlyerMileage getMileage = new GetFrequentFlyerMileage(url); - getMileage.getMileage(username, password); - } } diff --git a/samples/airline/client/spring-ws/pom.xml b/samples/airline/client/spring-ws/pom.xml index 5b647a41..9a7928ae 100644 --- a/samples/airline/client/spring-ws/pom.xml +++ b/samples/airline/client/spring-ws/pom.xml @@ -52,7 +52,7 @@ - org.springframework.ws.samples.airline.client.sws.GetFlights + org.springframework.ws.samples.airline.client.sws.Driver diff --git a/samples/airline/client/spring-ws/src/main/java/org/springframework/ws/samples/airline/client/sws/Driver.java b/samples/airline/client/spring-ws/src/main/java/org/springframework/ws/samples/airline/client/sws/Driver.java new file mode 100644 index 00000000..dc2d3504 --- /dev/null +++ b/samples/airline/client/spring-ws/src/main/java/org/springframework/ws/samples/airline/client/sws/Driver.java @@ -0,0 +1,39 @@ +/* + * 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.client.sws; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @author Arjen Poutsma + */ +public class Driver { + + public static void main(String[] args) { + ApplicationContext applicationContext = new ClassPathXmlApplicationContext( + "org/springframework/ws/samples/airline/client/sws/applicationContext.xml"); + GetFlights getFlights = applicationContext.getBean("getFlights", GetFlights.class); + getFlights.getFlights(); + + GetFrequentFlyerMileage getFrequentFlyerMileage = applicationContext + .getBean("getFrequentFlyerMileage", GetFrequentFlyerMileage.class); + getFrequentFlyerMileage.getFrequentFlyerMileage(); + + } + +} diff --git a/samples/airline/client/spring-ws/src/main/java/org/springframework/ws/samples/airline/client/sws/GetFlights.java b/samples/airline/client/spring-ws/src/main/java/org/springframework/ws/samples/airline/client/sws/GetFlights.java index 72afccae..a2d3ef50 100644 --- a/samples/airline/client/spring-ws/src/main/java/org/springframework/ws/samples/airline/client/sws/GetFlights.java +++ b/samples/airline/client/spring-ws/src/main/java/org/springframework/ws/samples/airline/client/sws/GetFlights.java @@ -1,11 +1,11 @@ /* - * Copyright 2005-2010 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, @@ -19,8 +19,6 @@ package org.springframework.ws.samples.airline.client.sws; import java.text.SimpleDateFormat; import java.util.Calendar; -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.springWs.samples.airline.schemas.messages.BookFlightRequestDocument; import org.springframework.springWs.samples.airline.schemas.messages.BookFlightResponseDocument; import org.springframework.springWs.samples.airline.schemas.messages.GetFlightsRequestDocument; @@ -101,11 +99,4 @@ public class GetFlights extends WebServiceGatewaySupport { System.out.println("\t" + flight.getTo().getCity()); } - public static void main(String[] args) { - ApplicationContext applicationContext = new ClassPathXmlApplicationContext( - "org/springframework/ws/samples/airline/client/sws/applicationContext.xml"); - GetFlights getFlights = applicationContext.getBean("getFlights", GetFlights.class); - getFlights.getFlights(); - } - } diff --git a/samples/airline/client/spring-ws/src/main/java/org/springframework/ws/samples/airline/client/sws/GetFrequentFlyerMileage.java b/samples/airline/client/spring-ws/src/main/java/org/springframework/ws/samples/airline/client/sws/GetFrequentFlyerMileage.java index 8caf7893..99021bc9 100644 --- a/samples/airline/client/spring-ws/src/main/java/org/springframework/ws/samples/airline/client/sws/GetFrequentFlyerMileage.java +++ b/samples/airline/client/spring-ws/src/main/java/org/springframework/ws/samples/airline/client/sws/GetFrequentFlyerMileage.java @@ -1,11 +1,11 @@ /* - * Copyright 2008 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,15 +16,11 @@ package org.springframework.ws.samples.airline.client.sws; -import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.stream.StreamResult; -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.ws.WebServiceMessageFactory; import org.springframework.ws.client.core.support.WebServiceGatewaySupport; -import org.springframework.xml.transform.StringResult; import org.springframework.xml.transform.StringSource; public class GetFrequentFlyerMileage extends WebServiceGatewaySupport { @@ -41,14 +37,4 @@ public class GetFrequentFlyerMileage extends WebServiceGatewaySupport { } - public static void main(String[] args) { - ApplicationContext applicationContext = new ClassPathXmlApplicationContext( - "org/springframework/ws/samples/airline/client/sws/applicationContext.xml"); - - GetFrequentFlyerMileage getFrequentFlyerMileage = applicationContext - .getBean("getFrequentFlyerMileage", GetFrequentFlyerMileage.class); - getFrequentFlyerMileage.getFrequentFlyerMileage(); - } - - } diff --git a/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/ws/AirlineEndpoint.java b/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/ws/AirlineEndpoint.java index 22e7d5cf..e0c9f8d3 100644 --- a/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/ws/AirlineEndpoint.java +++ b/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/ws/AirlineEndpoint.java @@ -22,6 +22,8 @@ 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.springframework.beans.factory.annotation.Autowired; import org.springframework.util.StringUtils; @@ -49,6 +51,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.joda.time.DateTime; import org.joda.time.LocalDate; +import org.w3c.dom.Document; +import org.w3c.dom.Element; import static org.springframework.ws.samples.airline.ws.AirlineWebServiceConstants.*; @@ -65,6 +69,8 @@ public class AirlineEndpoint { private final ObjectFactory objectFactory = new ObjectFactory(); + private final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + private final AirlineService airlineService; @Autowired @@ -156,5 +162,18 @@ 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; + } } 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 deleted file mode 100644 index c8c96abc..00000000 --- a/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/ws/GetFrequentFlyerMileageEndpoint.java +++ /dev/null @@ -1,47 +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.ws; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.ws.samples.airline.service.AirlineService; -import org.springframework.ws.server.endpoint.AbstractDomPayloadEndpoint; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -/** - * Endpoint that returns the amount of frequent flyer miles for the currently logged in user. Secured via a WS-Security - * UsernameToken - * - * @author Arjen Poutsma - */ -public class GetFrequentFlyerMileageEndpoint extends AbstractDomPayloadEndpoint implements AirlineWebServiceConstants { - - private final AirlineService airlineService; - - @Autowired - public GetFrequentFlyerMileageEndpoint(AirlineService airlineService) { - this.airlineService = airlineService; - } - - protected Element invokeInternal(Element ignored, Document responseDocument) throws Exception { - int mileage = airlineService.getFrequentFlyerMileage(); - Element response = responseDocument.createElementNS(MESSAGES_NAMESPACE, GET_FREQUENT_FLYER_MILEAGE_RESPONSE); - response.setTextContent(Integer.toString(mileage)); - return response; - } -} \ No newline at end of file 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 deleted file mode 100644 index 74aa95df..00000000 --- a/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/ws/MarshallingAirlineEndpoint.java +++ /dev/null @@ -1,150 +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.ws; - -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 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; -import org.springframework.ws.samples.airline.schema.BookFlightRequest; -import org.springframework.ws.samples.airline.schema.Flight; -import org.springframework.ws.samples.airline.schema.GetFlightsRequest; -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.ServiceClass; -import org.springframework.ws.samples.airline.schema.Ticket; -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.PayloadRoot; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.joda.time.DateTime; -import org.joda.time.LocalDate; - -/** - * Endpoint that handles the Airline Web Service messages using JAXB2 marshalling. - *

- * This endpoint contains exactly the same logic as the {@link XPathAirlineEndpoint}, and is only provided as an - * example. Typically, you will not have two endpoints with the same logic. - * - * @author Arjen Poutsma - */ -@Endpoint -public class MarshallingAirlineEndpoint implements AirlineWebServiceConstants { - - private static final Log logger = LogFactory.getLog(MarshallingAirlineEndpoint.class); - - private final AirlineService airlineService; - - private ObjectFactory objectFactory = new ObjectFactory(); - - @Autowired - public MarshallingAirlineEndpoint(AirlineService airlineService) { - Assert.notNull(airlineService, "airlineService must not be null"); - this.airlineService = airlineService; - } - - /** - * This endpoint method uses marshalling to handle message with a <GetFlightsRequest> payload. - * - * @param request the JAXB2 representation of a <GetFlightsRequest> - */ - @PayloadRoot(localPart = GET_FLIGHTS_REQUEST, namespace = MESSAGES_NAMESPACE) - public GetFlightsResponse getFlights(GetFlightsRequest request) throws DatatypeConfigurationException { - if (logger.isDebugEnabled()) { - logger.debug("Received GetFlightsRequest '" + request.getFrom() + "' to '" + request.getTo() + "' on " + - request.getDepartureDate()); - } - List flights = getSchemaFlights(request.getFrom(), request.getTo(), request.getDepartureDate(), - request.getServiceClass()); - GetFlightsResponse response = new GetFlightsResponse(); - for (Flight flight : flights) { - response.getFlight().add(flight); - } - return response; - } - - /** Converts between the domain and schema types. */ - private List getSchemaFlights(String from, - String to, - XMLGregorianCalendar xmlDepartureDate, - ServiceClass xmlServiceClass) throws DatatypeConfigurationException { - LocalDate domainDepartureDate = SchemaConversionUtils.toLocalDate(xmlDepartureDate); - org.springframework.ws.samples.airline.domain.ServiceClass domainServiceClass = - SchemaConversionUtils.toDomainType(xmlServiceClass); - List domainFlights = - airlineService.getFlights(from, to, domainDepartureDate, domainServiceClass); - return SchemaConversionUtils.toSchemaType(domainFlights); - } - - /** - * This endpoint method uses marshalling to handle message with a <BookFlightRequest> payload. - * - * @param request the JAXB2 representation of a <BookFlightRequest> - * @return the JAXB2 representation of a <BookFlightResponse> - */ - @PayloadRoot(localPart = BOOK_FLIGHT_REQUEST, namespace = MESSAGES_NAMESPACE) - public JAXBElement bookFlight(BookFlightRequest request) throws NoSeatAvailableException, - DatatypeConfigurationException, NoSuchFlightException, NoSuchFrequentFlyerException { - if (logger.isDebugEnabled()) { - logger.debug("Received BookingFlightRequest '" + request.getFlightNumber() + "' on '" + - request.getDepartureTime() + "' for " + request.getPassengers().getPassengerOrUsername()); - } - Ticket ticket = bookSchemaFlight(request.getFlightNumber(), request.getDepartureTime(), - request.getPassengers().getPassengerOrUsername()); - return objectFactory.createBookFlightResponse(ticket); - } - - /** Converts between the domain and schema types. */ - private Ticket bookSchemaFlight(String flightNumber, - XMLGregorianCalendar xmlDepartureTime, - List passengerOrUsernameList) throws NoSeatAvailableException, - NoSuchFlightException, NoSuchFrequentFlyerException, DatatypeConfigurationException { - DateTime departureTime = SchemaConversionUtils.toDateTime(xmlDepartureTime); - List passengers = new ArrayList(passengerOrUsernameList.size()); - for (Iterator iterator = passengerOrUsernameList.iterator(); iterator.hasNext();) { - Object passengerOrUsername = iterator.next(); - if (passengerOrUsername instanceof Name) { - Name passengerName = (Name) passengerOrUsername; - Passenger passenger = new Passenger(passengerName.getFirst(), passengerName.getLast()); - passengers.add(passenger); - } - else if (passengerOrUsername instanceof String) { - String frequentFlyerUsername = (String) passengerOrUsername; - FrequentFlyer frequentFlyer = new FrequentFlyer(frequentFlyerUsername); - passengers.add(frequentFlyer); - } - } - org.springframework.ws.samples.airline.domain.Ticket domainTicket = - airlineService.bookFlight(flightNumber, departureTime, passengers); - return SchemaConversionUtils.toSchemaType(domainTicket); - } - -} 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 deleted file mode 100644 index b8ff76ab..00000000 --- a/samples/airline/server/src/main/java/org/springframework/ws/samples/airline/ws/XPathAirlineEndpoint.java +++ /dev/null @@ -1,172 +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.ws; - -import java.util.ArrayList; -import java.util.List; -import javax.xml.bind.JAXBElement; -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; -import org.springframework.util.StringUtils; -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.schema.GetFlightsResponse; -import org.springframework.ws.samples.airline.schema.ObjectFactory; -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.PayloadRoot; -import org.springframework.ws.server.endpoint.annotation.XPathParam; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.joda.time.DateTime; -import org.joda.time.LocalDate; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * Endpoint that handles the Airline Web Service request messages using XPath expressions, and creates response messages - * using JAXB2. - *

- * This endpoint contains exactly the same logic as the {@link MarshallingAirlineEndpoint}, and is only provided as an - * example. Typically, you will not have two endpoints with the same logic. - * - * @author Arjen Poutsma - */ -@Endpoint -public class XPathAirlineEndpoint implements AirlineWebServiceConstants { - - private static final Log logger = LogFactory.getLog(XPathAirlineEndpoint.class); - - private final AirlineService airlineService; - - private ObjectFactory objectFactory = new ObjectFactory(); - - 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"); - this.airlineService = airlineService; - this.marshaller = marshaller; - } - - /** - * This endpoint method uses XPath to handle message with a <GetFlightsRequest> payload. - * - * @param from the from airport - * @param to the to airport - * @param departureDateString the string representation of the departure date - * @param serviceClassString the string representation of the service class - */ - @PayloadRoot(localPart = GET_FLIGHTS_REQUEST, namespace = MESSAGES_NAMESPACE) - public Source getFlights(@XPathParam("//messages:from")String from, - @XPathParam("//messages:to")String to, - @XPathParam("//messages:departureDate")String departureDateString, - @XPathParam("//messages:serviceClass")String serviceClassString) - throws DatatypeConfigurationException { - if (logger.isDebugEnabled()) { - logger.debug("Received GetFlightsRequest '" + from + "' to '" + to + "' on " + departureDateString); - } - LocalDate departureDate = new LocalDate(departureDateString); - ServiceClass serviceClass = null; - if (StringUtils.hasLength(serviceClassString)) { - serviceClass = ServiceClass.valueOf(serviceClassString.toUpperCase()); - } - List flights = airlineService.getFlights(from, to, departureDate, serviceClass); - - GetFlightsResponse response = objectFactory.createGetFlightsResponse(); - for (Flight domainFlight : flights) { - response.getFlight().add(SchemaConversionUtils.toSchemaType(domainFlight)); - } - return new MarshallingSource(marshaller, response); - } - - /** - * This endpoint method uses XPath to handle message with a <BookFlightRequest> payload. - * - * @param flightNumber the flight number - * @param departureTimeString the string representation of the departure time - * @param passengerNodes the passenger nodes - * @param frequentFlyerNodes the frequent flyer nodes - */ - @PayloadRoot(localPart = BOOK_FLIGHT_REQUEST, namespace = MESSAGES_NAMESPACE) - public Source bookFlight(@XPathParam("//messages:flightNumber")String flightNumber, - @XPathParam("//messages:departureTime")String departureTimeString, - @XPathParam("//messages:passengers/messages:passenger")NodeList passengerNodes, - @XPathParam("//messages:passengers/messages:username")NodeList frequentFlyerNodes) throws - NoSeatAvailableException, NoSuchFlightException, NoSuchFrequentFlyerException, - DatatypeConfigurationException, JAXBException { - if (logger.isDebugEnabled()) { - logger.debug("Received BookingFlightRequest '" + flightNumber + "' on '" + departureTimeString + "' for " + - passengerNodes.getLength() + " passengers and " + frequentFlyerNodes.getLength() + - " frequent flyers"); - } - DateTime departureTime = new DateTime(departureTimeString); - List passengers = new ArrayList(); - parsePassengers(passengerNodes, passengers); - parseFrequentFlyers(frequentFlyerNodes, passengers); - Ticket domainTicket = airlineService.bookFlight(flightNumber, departureTime, passengers); - - JAXBElement response = - objectFactory.createBookFlightResponse(SchemaConversionUtils.toSchemaType(domainTicket)); - return new MarshallingSource(marshaller, response); - } - - private void parsePassengers(NodeList passengerNodes, List passengers) { - for (int i = 0; i < passengerNodes.getLength(); i++) { - if (passengerNodes.item(i).getNodeType() != Node.ELEMENT_NODE) { - continue; - } - Element passengerElement = (Element) passengerNodes.item(i); - Element firstNameElement = - (Element) passengerElement.getElementsByTagNameNS(MESSAGES_NAMESPACE, "first").item(0); - Element lastNameElement = - (Element) passengerElement.getElementsByTagNameNS(MESSAGES_NAMESPACE, "last").item(0); - Passenger passenger = new Passenger(firstNameElement.getTextContent(), lastNameElement.getTextContent()); - passengers.add(passenger); - } - } - - private void parseFrequentFlyers(NodeList frequentFlyerNodes, List passengers) { - for (int i = 0; i < frequentFlyerNodes.getLength(); i++) { - if (frequentFlyerNodes.item(i).getNodeType() != Node.ELEMENT_NODE) { - continue; - } - Element frequentFlyerElement = (Element) frequentFlyerNodes.item(i); - FrequentFlyer frequentFlyer = new FrequentFlyer(frequentFlyerElement.getTextContent()); - passengers.add(frequentFlyer); - } - } - - -} 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 3b5d299c..18b526ba 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 @@ -22,20 +22,5 @@ - - - This interceptor validates incoming messages according to the policy defined in 'securityPolicy.xml'. - The policy defines that all incoming requests must have a UsernameToken with a password digest in it. - The actual authentication is performed by the Spring Security callback handler. - - - - - - - - - \ 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 6734945c..3955a932 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 @@ -1,14 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + @@ -21,148 +44,4 @@ - - - - - - - - - - - - - This endpoint handles get frequent flyer mileage requests. - - - - - - - - - - - - Detects @PayloadRoot annotations on @Endpoint bean methods. The MarshallingAirlineEndpoint - has such annotations. It uses two interceptors: one that logs the message payload, and the other validates - it accoring to the 'airline.xsd' schema file. - - - - - - - - - - - - - - - - - This endpoint mapping is used for endpoints that are secured via WS-Security. It uses a - securityInterceptor, defined in applicationContext-security.xml, to validate incoming messages. - - - - - getFrequentFlyerMileageEndpoint - - - - - - - - - - - - - - - - - - - - - - - This adapter allows for endpoints which implement the PayloadEndpoint interface. The Get - FrequentFlyerMileageEndpoint implements this interface. - - - - - - - - - - This exception resolver maps exceptions with the @SoapFault annotation to SOAP Faults. The business logic - exceptions NoSeatAvailableException and NoSuchFlightException have these. - - - - - - - This exception resolver maps other exceptions to SOAP Faults. Both UnmarshallingException and - ValidationFailureException are mapped to a SOAP Fault with a "Client" fault code. - All other exceptions are mapped to a "Server" error code, the default. - - - - - CLIENT,Invalid request - CLIENT,Invalid request - - - - - diff --git a/samples/airline/server/src/test/java/org/springframework/ws/samples/airline/ws/AirlineEndpointTest.java b/samples/airline/server/src/test/java/org/springframework/ws/samples/airline/ws/AirlineEndpointTest.java index 6a30f551..870c4433 100644 --- a/samples/airline/server/src/test/java/org/springframework/ws/samples/airline/ws/AirlineEndpointTest.java +++ b/samples/airline/server/src/test/java/org/springframework/ws/samples/airline/ws/AirlineEndpointTest.java @@ -43,8 +43,10 @@ import org.joda.time.LocalDate; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.w3c.dom.Element; import static org.easymock.EasyMock.*; +import static org.junit.Assert.assertNotNull; public class AirlineEndpointTest { @@ -110,7 +112,7 @@ public class AirlineEndpointTest { } @Test - public void testBookFlightPassenger() throws Exception { + public void bookFlightPassenger() throws Exception { BookFlightRequest request = objectFactory.createBookFlightRequest(); request.setDepartureTime(datatypeFactory.newXMLGregorianCalendar(2007, 6, 13, 12, 0, 0, 0, 0)); request.setFlightNumber("ABC1234"); @@ -169,8 +171,9 @@ public class AirlineEndpointTest { domainTicket.setPassengers(domainPassengers); List domainPassengerList = new ArrayList(domainPassengers); - expect(airlineServiceMock.bookFlight("ABC1234", new DateTime(2007, 6, 13, 12, 0, 0, 0, DateTimeZone.UTC), - domainPassengerList)).andReturn(domainTicket); + expect(airlineServiceMock + .bookFlight("ABC1234", new DateTime(2007, 6, 13, 12, 0, 0, 0, DateTimeZone.UTC), domainPassengerList)) + .andReturn(domainTicket); replay(airlineServiceMock); @@ -189,4 +192,16 @@ public class AirlineEndpointTest { verify(airlineServiceMock); } + @Test + public void testGetFrequentFlyerMileage() throws Exception { + expect(airlineServiceMock.getFrequentFlyerMileage()).andReturn(42); + + replay(airlineServiceMock); + + Element response = endpoint.getFrequentFlyerMileage(); + assertNotNull("Invalid response", response); + + verify(airlineServiceMock); + } + } \ No newline at end of file diff --git a/samples/airline/server/src/test/java/org/springframework/ws/samples/airline/ws/GetFrequentFlyerMileageEndpointTest.java b/samples/airline/server/src/test/java/org/springframework/ws/samples/airline/ws/GetFrequentFlyerMileageEndpointTest.java deleted file mode 100644 index 538a16c8..00000000 --- a/samples/airline/server/src/test/java/org/springframework/ws/samples/airline/ws/GetFrequentFlyerMileageEndpointTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2005-2010 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.ws; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import junit.framework.TestCase; -import static org.easymock.EasyMock.*; -import org.springframework.ws.samples.airline.service.AirlineService; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -public class GetFrequentFlyerMileageEndpointTest extends TestCase { - - private GetFrequentFlyerMileageEndpoint endpoint; - - private AirlineService airlineServiceMock; - - private Document document; - - @Override - protected void setUp() throws Exception { - airlineServiceMock = createMock(AirlineService.class); - endpoint = new GetFrequentFlyerMileageEndpoint(airlineServiceMock); - DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); - document = documentBuilder.newDocument(); - } - - public void testGetFrequentFlyerMileage() throws Exception { - expect(airlineServiceMock.getFrequentFlyerMileage()).andReturn(42); - - replay(airlineServiceMock); - - Element response = endpoint.invokeInternal(null, document); - assertNotNull("Invalid response", response); - - verify(airlineServiceMock); - } - -} \ No newline at end of file diff --git a/samples/airline/server/src/test/java/org/springframework/ws/samples/airline/ws/MarshallingAirlineEndpointTest.java b/samples/airline/server/src/test/java/org/springframework/ws/samples/airline/ws/MarshallingAirlineEndpointTest.java deleted file mode 100644 index 79d7f61b..00000000 --- a/samples/airline/server/src/test/java/org/springframework/ws/samples/airline/ws/MarshallingAirlineEndpointTest.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright 2005-2010 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.ws; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import javax.xml.bind.JAXBElement; -import javax.xml.datatype.DatatypeConstants; -import javax.xml.datatype.DatatypeFactory; - -import junit.framework.TestCase; -import static org.easymock.EasyMock.*; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.LocalDate; -import org.springframework.ws.samples.airline.domain.Airport; -import org.springframework.ws.samples.airline.domain.FrequentFlyer; -import org.springframework.ws.samples.airline.domain.Passenger; -import org.springframework.ws.samples.airline.schema.BookFlightRequest; -import org.springframework.ws.samples.airline.schema.Flight; -import org.springframework.ws.samples.airline.schema.GetFlightsRequest; -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.ServiceClass; -import org.springframework.ws.samples.airline.schema.Ticket; -import org.springframework.ws.samples.airline.service.AirlineService; - -public class MarshallingAirlineEndpointTest extends TestCase { - - private MarshallingAirlineEndpoint endpoint; - - private AirlineService airlineServiceMock; - - private DatatypeFactory datatypeFactory; - - private ObjectFactory objectFactory; - - @Override - protected void setUp() throws Exception { - airlineServiceMock = createMock(AirlineService.class); - endpoint = new MarshallingAirlineEndpoint(airlineServiceMock); - datatypeFactory = DatatypeFactory.newInstance(); - objectFactory = new ObjectFactory(); - } - - public void testGetFlights() throws Exception { - GetFlightsRequest request = objectFactory.createGetFlightsRequest(); - request.setDepartureDate( - datatypeFactory.newXMLGregorianCalendarDate(2007, 6, 13, DatatypeConstants.FIELD_UNDEFINED)); - request.setFrom("ABC"); - request.setTo("DEF"); - request.setServiceClass(ServiceClass.FIRST); - - org.springframework.ws.samples.airline.domain.Flight domainFlight = createDomainFlight(); - - expect(airlineServiceMock.getFlights("ABC", "DEF", new LocalDate(2007, 6, 13), - org.springframework.ws.samples.airline.domain.ServiceClass.FIRST)) - .andReturn(Collections.singletonList(domainFlight)); - - replay(airlineServiceMock); - - GetFlightsResponse response = endpoint.getFlights(request); - assertEquals("Invalid amount of flights received", 1, response.getFlight().size()); - Flight schemaFlight = response.getFlight().get(0); - verifySchemaFlight(schemaFlight); - - verify(airlineServiceMock); - } - - private void verifySchemaFlight(Flight schemaFlight) { - assertEquals("Invalid number", "ABC1234", schemaFlight.getNumber()); - assertEquals("Invalid departure time", datatypeFactory.newXMLGregorianCalendar(2007, 6, 13, 12, 0, 0, 0, 0), - schemaFlight.getDepartureTime()); - assertEquals("Invalid from code", "ABC", schemaFlight.getFrom().getCode()); - assertEquals("Invalid from name", "ABC Airport", schemaFlight.getFrom().getName()); - assertEquals("Invalid from city", "ABC City", schemaFlight.getFrom().getCity()); - assertEquals("Invalid arrival time", datatypeFactory.newXMLGregorianCalendar(2007, 6, 13, 14, 0, 0, 0, 0), - schemaFlight.getArrivalTime()); - assertEquals("Invalid to code", "DEF", schemaFlight.getTo().getCode()); - assertEquals("Invalid to name", "DEF Airport", schemaFlight.getTo().getName()); - assertEquals("Invalid to city", "DEF City", schemaFlight.getTo().getCity()); - assertEquals("Invalid service class", ServiceClass.FIRST, schemaFlight.getServiceClass()); - } - - private org.springframework.ws.samples.airline.domain.Flight createDomainFlight() { - org.springframework.ws.samples.airline.domain.Flight domainFlight = - new org.springframework.ws.samples.airline.domain.Flight(); - domainFlight.setNumber("ABC1234"); - domainFlight.setDepartureTime(new DateTime(2007, 6, 13, 12, 0, 0, 0, DateTimeZone.UTC)); - domainFlight.setFrom(new Airport("ABC", "ABC Airport", "ABC City")); - domainFlight.setArrivalTime(new DateTime(2007, 6, 13, 14, 0, 0, 0, DateTimeZone.UTC)); - domainFlight.setTo(new Airport("DEF", "DEF Airport", "DEF City")); - domainFlight.setServiceClass(org.springframework.ws.samples.airline.domain.ServiceClass.FIRST); - return domainFlight; - } - - public void testBookFlightPassenger() throws Exception { - BookFlightRequest request = objectFactory.createBookFlightRequest(); - request.setDepartureTime(datatypeFactory.newXMLGregorianCalendar(2007, 6, 13, 12, 0, 0, 0, 0)); - request.setFlightNumber("ABC1234"); - Name passengerName = new Name(); - passengerName.setFirst("John"); - passengerName.setLast("Doe"); - BookFlightRequest.Passengers passengers = new BookFlightRequest.Passengers(); - passengers.getPassengerOrUsername().add(passengerName); - request.setPassengers(passengers); - - Passenger domainPassenger = new Passenger("John", "Doe"); - - org.springframework.ws.samples.airline.domain.Ticket domainTicket = - new org.springframework.ws.samples.airline.domain.Ticket(42L); - domainTicket.setFlight(createDomainFlight()); - domainTicket.setIssueDate(new LocalDate(2007, 6, 13)); - domainTicket.setPassengers(Collections.singleton(domainPassenger)); - - expect(airlineServiceMock.bookFlight("ABC1234", new DateTime(2007, 6, 13, 12, 0, 0, 0, DateTimeZone.UTC), - Collections.singletonList(domainPassenger))).andReturn(domainTicket); - - replay(airlineServiceMock); - - JAXBElement response = endpoint.bookFlight(request); - Ticket schemaTicket = response.getValue(); - assertEquals("Invalid id", 42L, schemaTicket.getId()); - assertEquals("Invalid issue date", - datatypeFactory.newXMLGregorianCalendarDate(2007, 6, 13, DatatypeConstants.FIELD_UNDEFINED), - schemaTicket.getIssueDate()); - assertEquals("Invalid amount of passengers", 1, schemaTicket.getPassengers().getPassenger().size()); - Name schemaPassenger = schemaTicket.getPassengers().getPassenger().get(0); - assertEquals("Invalid passenger first name", "John", schemaPassenger.getFirst()); - assertEquals("Invalid passenger first name", "Doe", schemaPassenger.getLast()); - verifySchemaFlight(schemaTicket.getFlight()); - - verify(airlineServiceMock); - } - - public void testBookFlightFrequentFlyer() throws Exception { - BookFlightRequest request = objectFactory.createBookFlightRequest(); - request.setDepartureTime(datatypeFactory.newXMLGregorianCalendar(2007, 6, 13, 12, 0, 0, 0, 0)); - request.setFlightNumber("ABC1234"); - BookFlightRequest.Passengers passengers = new BookFlightRequest.Passengers(); - passengers.getPassengerOrUsername().add("john"); - request.setPassengers(passengers); - - FrequentFlyer domainFrequentFlyer = new FrequentFlyer("John", "Doe", "john", "changeme"); - Set domainPassengers = new HashSet(); - domainPassengers.add(domainFrequentFlyer); - - org.springframework.ws.samples.airline.domain.Ticket domainTicket = - new org.springframework.ws.samples.airline.domain.Ticket(42L); - domainTicket.setFlight(createDomainFlight()); - domainTicket.setIssueDate(new LocalDate(2007, 6, 13)); - domainTicket.setPassengers(domainPassengers); - - List domainPassengerList = new ArrayList(domainPassengers); - expect(airlineServiceMock.bookFlight("ABC1234", new DateTime(2007, 6, 13, 12, 0, 0, 0, DateTimeZone.UTC), - domainPassengerList)).andReturn(domainTicket); - - replay(airlineServiceMock); - - JAXBElement response = endpoint.bookFlight(request); - Ticket schemaTicket = response.getValue(); - assertEquals("Invalid id", 42L, schemaTicket.getId()); - assertEquals("Invalid issue date", - datatypeFactory.newXMLGregorianCalendarDate(2007, 6, 13, DatatypeConstants.FIELD_UNDEFINED), - schemaTicket.getIssueDate()); - assertEquals("Invalid amount of passengers", 1, schemaTicket.getPassengers().getPassenger().size()); - Name schemaPassenger = schemaTicket.getPassengers().getPassenger().get(0); - assertEquals("Invalid passenger first name", "John", schemaPassenger.getFirst()); - assertEquals("Invalid passenger first name", "Doe", schemaPassenger.getLast()); - verifySchemaFlight(schemaTicket.getFlight()); - - verify(airlineServiceMock); - } - -} \ No newline at end of file diff --git a/samples/airline/server/src/test/java/org/springframework/ws/samples/airline/ws/XPathAirlineEndpointTest.java b/samples/airline/server/src/test/java/org/springframework/ws/samples/airline/ws/XPathAirlineEndpointTest.java deleted file mode 100644 index e5ef2230..00000000 --- a/samples/airline/server/src/test/java/org/springframework/ws/samples/airline/ws/XPathAirlineEndpointTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2005-2010 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.ws; - -import java.util.Collections; -import javax.xml.transform.Source; - -import junit.framework.TestCase; -import static org.easymock.EasyMock.*; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.LocalDate; -import org.springframework.oxm.Marshaller; -import org.springframework.ws.samples.airline.domain.Airport; -import org.springframework.ws.samples.airline.service.AirlineService; - -public class XPathAirlineEndpointTest extends TestCase { - - private XPathAirlineEndpoint endpoint; - - private AirlineService airlineServiceMock; - - private Marshaller marshallerMock; - - @Override - protected void setUp() throws Exception { - airlineServiceMock = createMock(AirlineService.class); - marshallerMock = createMock(Marshaller.class); - endpoint = new XPathAirlineEndpoint(airlineServiceMock, marshallerMock); - } - - public void testGetFlights() throws Exception { - org.springframework.ws.samples.airline.domain.Flight domainFlight = createDomainFlight(); - - expect(airlineServiceMock.getFlights("ABC", "DEF", new LocalDate(2007, 6, 13), - org.springframework.ws.samples.airline.domain.ServiceClass.FIRST)) - .andReturn(Collections.singletonList(domainFlight)); - - replay(airlineServiceMock, marshallerMock); - - Source response = endpoint.getFlights("ABC", "DEF", "2007-06-13", "first"); - assertNotNull("No response received", response); - - verify(airlineServiceMock, marshallerMock); - } - - private org.springframework.ws.samples.airline.domain.Flight createDomainFlight() { - org.springframework.ws.samples.airline.domain.Flight domainFlight = - new org.springframework.ws.samples.airline.domain.Flight(); - domainFlight.setNumber("ABC1234"); - domainFlight.setDepartureTime(new DateTime(2007, 6, 13, 12, 0, 0, 0, DateTimeZone.UTC)); - domainFlight.setFrom(new Airport("ABC", "ABC Airport", "ABC City")); - domainFlight.setArrivalTime(new DateTime(2007, 6, 13, 14, 0, 0, 0, DateTimeZone.UTC)); - domainFlight.setTo(new Airport("DEF", "DEF Airport", "DEF City")); - domainFlight.setServiceClass(org.springframework.ws.samples.airline.domain.ServiceClass.FIRST); - return domainFlight; - } - - -} \ No newline at end of file