Skip to content

Commit 462ad0a

Browse files
committed
Bring airline sample up to date
1 parent 7bb66cb commit 462ad0a

File tree

18 files changed

+152
-912
lines changed

18 files changed

+152
-912
lines changed

samples/airline/client/saaj/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
</execution>
5959
</executions>
6060
<configuration>
61-
<mainClass>org.springframework.ws.samples.airline.client.saaj.GetFlights</mainClass>
61+
<mainClass>org.springframework.ws.samples.airline.client.saaj.Driver</mainClass>
6262
</configuration>
6363
</plugin>
6464
</plugins>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2005-2011 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ws.samples.airline.client.saaj;
18+
19+
/**
20+
* @author Arjen Poutsma
21+
*/
22+
public class Driver {
23+
24+
public static void main(String[] args) throws Exception {
25+
String url = "http://localhost:8080/airline-server/services";
26+
if (args.length > 0) {
27+
url = args[0];
28+
}
29+
GetFlights getFlights = new GetFlights(url);
30+
getFlights.getFlights();
31+
32+
if (!System.getProperty("java.version").startsWith("1.5")) {
33+
return;
34+
}
35+
String username = "john";
36+
String password = "changeme";
37+
GetFrequentFlyerMileage getMileage = new GetFrequentFlyerMileage(url);
38+
getMileage.getMileage(username, password);
39+
}
40+
41+
}

samples/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/GetFlights.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2006 the original author or authors.
2+
* Copyright 2005-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -20,7 +20,6 @@
2020
import java.net.MalformedURLException;
2121
import java.net.URL;
2222
import java.util.Iterator;
23-
2423
import javax.xml.soap.MessageFactory;
2524
import javax.xml.soap.Name;
2625
import javax.xml.soap.SOAPBodyElement;
@@ -115,13 +114,4 @@ private void writeGetFlightsResponse(SOAPMessage message) throws SOAPException,
115114
transformer.transform(source, new StreamResult(System.out));
116115
}
117116
}
118-
119-
public static void main(String[] args) throws Exception {
120-
String url = "http://localhost:8080/airline-server/services";
121-
if (args.length > 0) {
122-
url = args[0];
123-
}
124-
GetFlights getFlights = new GetFlights(url);
125-
getFlights.getFlights();
126-
}
127117
}

samples/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/GetFrequentFlyerMileage.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2006 the original author or authors.
2+
* Copyright 2005-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -20,7 +20,6 @@
2020
import java.io.InputStream;
2121
import java.net.MalformedURLException;
2222
import java.net.URL;
23-
2423
import javax.security.auth.callback.Callback;
2524
import javax.security.auth.callback.CallbackHandler;
2625
import javax.security.auth.callback.UnsupportedCallbackException;
@@ -126,16 +125,4 @@ public void getMileage(String username, String password) throws SOAPException, I
126125
System.err.println("SOAP Fault String: " + fault.getFaultString());
127126
}
128127
}
129-
130-
public static void main(String[] args) throws Exception {
131-
if (!System.getProperty("java.version").startsWith("1.5")) {
132-
System.out.println("This sample will only run under JDK 1.5");
133-
return;
134-
}
135-
String url = "http://localhost:8080/airline-server/services";
136-
String username = "john";
137-
String password = "changeme";
138-
GetFrequentFlyerMileage getMileage = new GetFrequentFlyerMileage(url);
139-
getMileage.getMileage(username, password);
140-
}
141128
}

samples/airline/client/spring-ws/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
</execution>
5353
</executions>
5454
<configuration>
55-
<mainClass>org.springframework.ws.samples.airline.client.sws.GetFlights</mainClass>
55+
<mainClass>org.springframework.ws.samples.airline.client.sws.Driver</mainClass>
5656
</configuration>
5757
</plugin>
5858
</plugins>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2005-2011 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ws.samples.airline.client.sws;
18+
19+
import org.springframework.context.ApplicationContext;
20+
import org.springframework.context.support.ClassPathXmlApplicationContext;
21+
22+
/**
23+
* @author Arjen Poutsma
24+
*/
25+
public class Driver {
26+
27+
public static void main(String[] args) {
28+
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
29+
"org/springframework/ws/samples/airline/client/sws/applicationContext.xml");
30+
GetFlights getFlights = applicationContext.getBean("getFlights", GetFlights.class);
31+
getFlights.getFlights();
32+
33+
GetFrequentFlyerMileage getFrequentFlyerMileage = applicationContext
34+
.getBean("getFrequentFlyerMileage", GetFrequentFlyerMileage.class);
35+
getFrequentFlyerMileage.getFrequentFlyerMileage();
36+
37+
}
38+
39+
}

samples/airline/client/spring-ws/src/main/java/org/springframework/ws/samples/airline/client/sws/GetFlights.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2005-2010 the original author or authors.
2+
* Copyright 2005-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -19,8 +19,6 @@
1919
import java.text.SimpleDateFormat;
2020
import java.util.Calendar;
2121

22-
import org.springframework.context.ApplicationContext;
23-
import org.springframework.context.support.ClassPathXmlApplicationContext;
2422
import org.springframework.springWs.samples.airline.schemas.messages.BookFlightRequestDocument;
2523
import org.springframework.springWs.samples.airline.schemas.messages.BookFlightResponseDocument;
2624
import org.springframework.springWs.samples.airline.schemas.messages.GetFlightsRequestDocument;
@@ -101,11 +99,4 @@ private void writeFlight(Flight flight) {
10199
System.out.println("\t" + flight.getTo().getCity());
102100
}
103101

104-
public static void main(String[] args) {
105-
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
106-
"org/springframework/ws/samples/airline/client/sws/applicationContext.xml");
107-
GetFlights getFlights = applicationContext.getBean("getFlights", GetFlights.class);
108-
getFlights.getFlights();
109-
}
110-
111102
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2008 the original author or authors.
2+
* Copyright 2005-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,15 +16,11 @@
1616

1717
package org.springframework.ws.samples.airline.client.sws;
1818

19-
import javax.xml.transform.Result;
2019
import javax.xml.transform.Source;
2120
import javax.xml.transform.stream.StreamResult;
2221

23-
import org.springframework.context.ApplicationContext;
24-
import org.springframework.context.support.ClassPathXmlApplicationContext;
2522
import org.springframework.ws.WebServiceMessageFactory;
2623
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
27-
import org.springframework.xml.transform.StringResult;
2824
import org.springframework.xml.transform.StringSource;
2925

3026
public class GetFrequentFlyerMileage extends WebServiceGatewaySupport {
@@ -41,14 +37,4 @@ public void getFrequentFlyerMileage() {
4137

4238
}
4339

44-
public static void main(String[] args) {
45-
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
46-
"org/springframework/ws/samples/airline/client/sws/applicationContext.xml");
47-
48-
GetFrequentFlyerMileage getFrequentFlyerMileage = applicationContext
49-
.getBean("getFrequentFlyerMileage", GetFrequentFlyerMileage.class);
50-
getFrequentFlyerMileage.getFrequentFlyerMileage();
51-
}
52-
53-
5440
}

samples/airline/server/src/main/java/org/springframework/ws/samples/airline/ws/AirlineEndpoint.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import javax.xml.bind.JAXBElement;
2323
import javax.xml.datatype.DatatypeConfigurationException;
2424
import javax.xml.datatype.XMLGregorianCalendar;
25+
import javax.xml.parsers.DocumentBuilder;
26+
import javax.xml.parsers.DocumentBuilderFactory;
2527

2628
import org.springframework.beans.factory.annotation.Autowired;
2729
import org.springframework.util.StringUtils;
@@ -49,6 +51,8 @@
4951
import org.apache.commons.logging.LogFactory;
5052
import org.joda.time.DateTime;
5153
import org.joda.time.LocalDate;
54+
import org.w3c.dom.Document;
55+
import org.w3c.dom.Element;
5256

5357
import static org.springframework.ws.samples.airline.ws.AirlineWebServiceConstants.*;
5458

@@ -65,6 +69,8 @@ public class AirlineEndpoint {
6569

6670
private final ObjectFactory objectFactory = new ObjectFactory();
6771

72+
private final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
73+
6874
private final AirlineService airlineService;
6975

7076
@Autowired
@@ -156,5 +162,18 @@ else if (passengerOrUsername instanceof String) {
156162
return SchemaConversionUtils.toSchemaType(domainTicket);
157163
}
158164

165+
@PayloadRoot(localPart = GET_FREQUENT_FLYER_MILEAGE_REQUEST, namespace = MESSAGES_NAMESPACE)
166+
@ResponsePayload
167+
public Element getFrequentFlyerMileage() throws Exception {
168+
if (logger.isDebugEnabled()) {
169+
logger.debug("Received GetFrequentFlyerMileageRequest");
170+
}
171+
int mileage = airlineService.getFrequentFlyerMileage();
172+
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
173+
Document document = documentBuilder.newDocument();
174+
Element response = document.createElementNS(MESSAGES_NAMESPACE, GET_FREQUENT_FLYER_MILEAGE_RESPONSE);
175+
response.setTextContent(Integer.toString(mileage));
176+
return response;
177+
}
159178

160179
}

samples/airline/server/src/main/java/org/springframework/ws/samples/airline/ws/GetFrequentFlyerMileageEndpoint.java

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

0 commit comments

Comments
 (0)