diff --git a/airline/client/saaj/pom.xml b/airline/client/saaj/pom.xml
index 4835c55..84c11ee 100644
--- a/airline/client/saaj/pom.xml
+++ b/airline/client/saaj/pom.xml
@@ -10,48 +10,29 @@
../../../
- org.springframework.ws
airline-client-saaj
0.0.1-SNAPSHOT
Spring Web Services Samples - Airline - Client - SAAJ
Demo project for Spring Web Services
- 1.8
- 2.15.0
- 3.0
+ 2.0.1
-
+
+ com.sun.xml.messaging.saaj
+ saaj-impl
+ ${saaj-impl.version}
+
+
+
org.slf4j
slf4j-api
-
- com.sun.xml.wss
- xws-security
- ${xws.version}
-
-
- javax.xml.crypto
- xmldsig
-
-
- javax.activation
- activation
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/GetFlights.java b/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/GetFlights.java
index b6bf6f3..f6e1bb1 100644
--- a/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/GetFlights.java
+++ b/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/GetFlights.java
@@ -16,20 +16,13 @@
package org.springframework.ws.samples.airline.client.saaj;
+import jakarta.xml.soap.*;
+
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;
-import javax.xml.soap.SOAPConnection;
-import javax.xml.soap.SOAPConnectionFactory;
-import javax.xml.soap.SOAPElement;
-import javax.xml.soap.SOAPEnvelope;
-import javax.xml.soap.SOAPException;
-import javax.xml.soap.SOAPFault;
-import javax.xml.soap.SOAPMessage;
+
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
@@ -44,74 +37,73 @@ import javax.xml.transform.stream.StreamResult;
*/
public class GetFlights {
- public static final String NAMESPACE_URI = "http://www.springframework.org/spring-ws/samples/airline/schemas/messages";
+ public static final String NAMESPACE_URI = "http://www.springframework.org/spring-ws/samples/airline/schemas/messages";
- public static final String PREFIX = "airline";
+ public static final String PREFIX = "airline";
- private SOAPConnectionFactory connectionFactory;
+ private SOAPConnectionFactory connectionFactory;
- private MessageFactory messageFactory;
+ private MessageFactory messageFactory;
- private URL url;
+ private URL url;
- private TransformerFactory transfomerFactory;
+ private TransformerFactory transfomerFactory;
- public GetFlights(String url) throws SOAPException, MalformedURLException {
- connectionFactory = SOAPConnectionFactory.newInstance();
- messageFactory = MessageFactory.newInstance();
- transfomerFactory = TransformerFactory.newInstance();
- this.url = new URL(url);
- }
+ public GetFlights(String url) throws SOAPException, MalformedURLException {
+ connectionFactory = SOAPConnectionFactory.newInstance();
+ messageFactory = MessageFactory.newInstance();
+ transfomerFactory = TransformerFactory.newInstance();
+ this.url = new URL(url);
+ }
- private SOAPMessage createGetFlightsRequest() throws SOAPException {
- SOAPMessage message = messageFactory.createMessage();
- SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
- Name getFlightsRequestName = envelope.createName("GetFlightsRequest", PREFIX, NAMESPACE_URI);
- SOAPBodyElement getFlightsRequestElement = message.getSOAPBody().addBodyElement(getFlightsRequestName);
- Name fromName = envelope.createName("from", PREFIX, NAMESPACE_URI);
- SOAPElement fromElement = getFlightsRequestElement.addChildElement(fromName);
- fromElement.setValue("AMS");
- Name toName = envelope.createName("to", PREFIX, NAMESPACE_URI);
- SOAPElement toElement = getFlightsRequestElement.addChildElement(toName);
- toElement.setValue("VCE");
- Name departureDateName = envelope.createName("departureDate", PREFIX, NAMESPACE_URI);
- SOAPElement departureDateElement = getFlightsRequestElement.addChildElement(departureDateName);
- departureDateElement.setValue("2006-01-31");
- return message;
- }
+ private SOAPMessage createGetFlightsRequest() throws SOAPException {
+ SOAPMessage message = messageFactory.createMessage();
+ SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
+ Name getFlightsRequestName = envelope.createName("GetFlightsRequest", PREFIX, NAMESPACE_URI);
+ SOAPBodyElement getFlightsRequestElement = message.getSOAPBody().addBodyElement(getFlightsRequestName);
+ Name fromName = envelope.createName("from", PREFIX, NAMESPACE_URI);
+ SOAPElement fromElement = getFlightsRequestElement.addChildElement(fromName);
+ fromElement.setValue("AMS");
+ Name toName = envelope.createName("to", PREFIX, NAMESPACE_URI);
+ SOAPElement toElement = getFlightsRequestElement.addChildElement(toName);
+ toElement.setValue("VCE");
+ Name departureDateName = envelope.createName("departureDate", PREFIX, NAMESPACE_URI);
+ SOAPElement departureDateElement = getFlightsRequestElement.addChildElement(departureDateName);
+ departureDateElement.setValue("2006-01-31");
+ return message;
+ }
- public void getFlights() throws SOAPException, IOException, TransformerException {
- SOAPMessage request = createGetFlightsRequest();
- SOAPConnection connection = connectionFactory.createConnection();
- SOAPMessage response = connection.call(request, url);
- if (!response.getSOAPBody().hasFault()) {
- writeGetFlightsResponse(response);
- }
- else {
- SOAPFault fault = response.getSOAPBody().getFault();
- System.err.println("Received SOAP Fault");
- System.err.println("SOAP Fault Code: " + fault.getFaultCode());
- System.err.println("SOAP Fault String: " + fault.getFaultString());
- }
- }
+ public void getFlights() throws SOAPException, IOException, TransformerException {
+ SOAPMessage request = createGetFlightsRequest();
+ SOAPConnection connection = connectionFactory.createConnection();
+ SOAPMessage response = connection.call(request, url);
+ if (!response.getSOAPBody().hasFault()) {
+ writeGetFlightsResponse(response);
+ } else {
+ SOAPFault fault = response.getSOAPBody().getFault();
+ System.err.println("Received SOAP Fault");
+ System.err.println("SOAP Fault Code: " + fault.getFaultCode());
+ System.err.println("SOAP Fault String: " + fault.getFaultString());
+ }
+ }
- private void writeGetFlightsResponse(SOAPMessage message) throws SOAPException, TransformerException {
- SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
- Name getFlightsResponseName = envelope.createName("GetFlightsResponse", PREFIX, NAMESPACE_URI);
- SOAPBodyElement getFlightsResponseElement =
- (SOAPBodyElement) message.getSOAPBody().getChildElements(getFlightsResponseName).next();
- Name flightName = envelope.createName("flight", PREFIX, NAMESPACE_URI);
- Iterator iterator = getFlightsResponseElement.getChildElements(flightName);
- Transformer transformer = transfomerFactory.newTransformer();
- transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- int count = 1;
- while (iterator.hasNext()) {
- System.out.println("Flight " + count);
- System.out.println("--------");
- SOAPElement flightElement = (SOAPElement) iterator.next();
- DOMSource source = new DOMSource(flightElement);
- transformer.transform(source, new StreamResult(System.out));
- }
- }
+ private void writeGetFlightsResponse(SOAPMessage message) throws SOAPException, TransformerException {
+ SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
+ Name getFlightsResponseName = envelope.createName("GetFlightsResponse", PREFIX, NAMESPACE_URI);
+ SOAPBodyElement getFlightsResponseElement = (SOAPBodyElement) message.getSOAPBody()
+ .getChildElements(getFlightsResponseName).next();
+ Name flightName = envelope.createName("flight", PREFIX, NAMESPACE_URI);
+ Iterator iterator = getFlightsResponseElement.getChildElements(flightName);
+ Transformer transformer = transfomerFactory.newTransformer();
+ transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ int count = 1;
+ while (iterator.hasNext()) {
+ System.out.println("Flight " + count);
+ System.out.println("--------");
+ SOAPElement flightElement = (SOAPElement) iterator.next();
+ DOMSource source = new DOMSource(flightElement);
+ transformer.transform(source, new StreamResult(System.out));
+ }
+ }
}
diff --git a/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/GetFrequentFlyerMileage.java b/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/GetFrequentFlyerMileage.java
deleted file mode 100644
index 8c27d41..0000000
--- a/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/GetFrequentFlyerMileage.java
+++ /dev/null
@@ -1,128 +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.client.saaj;
-
-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;
-import javax.xml.soap.MessageFactory;
-import javax.xml.soap.Name;
-import javax.xml.soap.SOAPBodyElement;
-import javax.xml.soap.SOAPConnection;
-import javax.xml.soap.SOAPConnectionFactory;
-import javax.xml.soap.SOAPEnvelope;
-import javax.xml.soap.SOAPException;
-import javax.xml.soap.SOAPFault;
-import javax.xml.soap.SOAPMessage;
-
-import com.sun.xml.wss.ProcessingContext;
-import com.sun.xml.wss.XWSSProcessor;
-import com.sun.xml.wss.XWSSProcessorFactory;
-import com.sun.xml.wss.XWSSecurityException;
-import com.sun.xml.wss.impl.callback.PasswordCallback;
-import com.sun.xml.wss.impl.callback.UsernameCallback;
-
-/**
- * Simple client that calls the WS-Security GetFrequentFlyerMileage operation using SAAJ and XWSS.
- *
- * @author Arjen Poutsma
- */
-public class GetFrequentFlyerMileage {
-
- public static final String NAMESPACE_URI = "http://www.springframework.org/spring-ws/samples/airline/schemas/messages";
-
- public static final String PREFIX = "airline";
-
- private SOAPConnectionFactory connectionFactory;
-
- private MessageFactory messageFactory;
-
- private URL url;
-
- private XWSSProcessorFactory processorFactory;
-
- public GetFrequentFlyerMileage(String url) throws SOAPException, MalformedURLException, XWSSecurityException {
- connectionFactory = SOAPConnectionFactory.newInstance();
- messageFactory = MessageFactory.newInstance();
- processorFactory = XWSSProcessorFactory.newInstance();
- this.url = new URL(url);
- }
-
- private SOAPMessage createGetMileageRequest() throws SOAPException {
- SOAPMessage message = messageFactory.createMessage();
- SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
- Name getFlightsRequestName = envelope.createName("GetFrequentFlyerMileageRequest", GetFrequentFlyerMileage.PREFIX,
- GetFrequentFlyerMileage.NAMESPACE_URI);
- message.getSOAPBody().addBodyElement(getFlightsRequestName);
- return message;
- }
-
- private SOAPMessage secureMessage(SOAPMessage message, final String username, final String password)
- throws IOException, XWSSecurityException {
- CallbackHandler callbackHandler = new CallbackHandler() {
- public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
- for (int i = 0; i < callbacks.length; i++) {
- if (callbacks[i] instanceof UsernameCallback) {
- UsernameCallback callback = (UsernameCallback) callbacks[i];
- callback.setUsername(username);
- }
- else if (callbacks[i] instanceof PasswordCallback) {
- PasswordCallback callback = (PasswordCallback) callbacks[i];
- callback.setPassword(password);
- }
- else {
- throw new UnsupportedCallbackException(callbacks[i]);
- }
- }
- }
- };
- InputStream policyStream = null;
- XWSSProcessor processor = null;
- try {
- policyStream = getClass().getResourceAsStream("securityPolicy.xml");
- processor = processorFactory.createProcessorForSecurityConfiguration(policyStream, callbackHandler);
- }
- finally {
- if (policyStream != null) {
- policyStream.close();
- }
- }
- ProcessingContext context = processor.createProcessingContext(message);
- return processor.secureOutboundMessage(context);
- }
-
- public void getMileage(String username, String password) throws SOAPException, IOException, XWSSecurityException {
- SOAPMessage request = createGetMileageRequest();
- request = secureMessage(request, username, password);
- SOAPConnection connection = connectionFactory.createConnection();
- SOAPMessage response = connection.call(request, url);
- if (!response.getSOAPBody().hasFault()) {
- SOAPBodyElement mileage = (SOAPBodyElement) response.getSOAPBody().getChildElements().next();
- System.out.println("'" + username + "' has " + mileage.getValue() + " frequent flyer miles");
- }
- else {
- SOAPFault fault = response.getSOAPBody().getFault();
- System.err.println("Received SOAP Fault");
- System.err.println("SOAP Fault Code: " + fault.getFaultCode());
- System.err.println("SOAP Fault String: " + fault.getFaultString());
- }
- }
-}
diff --git a/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/SaajMain.java b/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/SaajMain.java
index 074d48f..b33c14e 100644
--- a/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/SaajMain.java
+++ b/airline/client/saaj/src/main/java/org/springframework/ws/samples/airline/client/saaj/SaajMain.java
@@ -24,7 +24,7 @@ import org.slf4j.LoggerFactory;
*/
public class SaajMain {
- private static final Logger logger = LoggerFactory.getLogger(SaajMain.class);
+ private static final Logger logger = LoggerFactory.getLogger(SaajMain.class);
public static void main(String[] args) throws Exception {
@@ -33,15 +33,9 @@ public class SaajMain {
url = args[0];
}
- logger.info("Connecting to " + url + " for flight details...");
+ logger.info("Connecting to " + url + " for flight details...");
- GetFlights getFlights = new GetFlights(url);
+ GetFlights getFlights = new GetFlights(url);
getFlights.getFlights();
-
- String username = "john";
- String password = "changeme";
- GetFrequentFlyerMileage getMileage = new GetFrequentFlyerMileage(url);
- getMileage.getMileage(username, password);
}
-
}
diff --git a/airline/client/saaj/src/main/resources/org/springframework/ws/samples/airline/client/saaj/securityPolicy.xml b/airline/client/saaj/src/main/resources/org/springframework/ws/samples/airline/client/saaj/securityPolicy.xml
deleted file mode 100644
index 8509073..0000000
--- a/airline/client/saaj/src/main/resources/org/springframework/ws/samples/airline/client/saaj/securityPolicy.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-