35 Commits

Author SHA1 Message Date
Greg Turnquist
32682b4b20 Upgrade to Spring Boot 2.1.3.RELEASE 2019-03-20 10:00:47 -05:00
Greg Turnquist
51ffb90821 Upgrade to Spring Boot 2.0.8.RELEASE. 2019-03-20 09:37:43 -05:00
Spring Operator
8c6e8bee12 URL Cleanup (#36)
This commit updates URLs to prefer the https protocol. Redirects are not followed to avoid accidentally expanding intentionally shortened URLs (i.e. if using a URL shortener).

# Fixed URLs

## Fixed Success
These URLs were switched to an https URL with a 2xx status. While the status was successful, your review is still recommended.

* http://maven.apache.org/xsd/maven-4.0.0.xsd with 2 occurrences migrated to:
  https://maven.apache.org/xsd/maven-4.0.0.xsd ([https](https://maven.apache.org/xsd/maven-4.0.0.xsd) result 200).

# Ignored
These URLs were intentionally ignored.

* http://localhost:8080/ws/countries.wsdl with 2 occurrences
* http://maven.apache.org/POM/4.0.0 with 4 occurrences
* http://www.w3.org/2001/XMLSchema-instance with 2 occurrences
2019-03-20 08:56:32 -05:00
Spring Operator
ab5e8adfc2 URL Cleanup (#35)
This commit updates URLs to prefer the https protocol. Redirects are not followed to avoid accidentally expanding intentionally shortened URLs (i.e. if using a URL shortener).

# Fixed URLs

## Fixed Success
These URLs were switched to an https URL with a 2xx status. While the status was successful, your review is still recommended.

* http://www.apache.org/licenses/LICENSE-2.0 migrated to:
  https://www.apache.org/licenses/LICENSE-2.0 ([https](https://www.apache.org/licenses/LICENSE-2.0) result 200).

# Ignored
These URLs were intentionally ignored.

* http://localhost:8080/ws/countries.wsdl
* http://maven.apache.org/POM/4.0.0
* http://maven.apache.org/xsd/maven-4.0.0.xsd
* http://www.w3.org/2001/XMLSchema-instance
2019-03-11 14:02:41 -05:00
Greg Turnquist
4002ac9801 Upgrade to Spring Boot 2.0.5.RELEASE and Spring Cloud Finchley.SR1 2018-09-17 11:00:40 -05:00
Dave Syer
160ffd1480 Give CI chance to download everything 2018-07-30 09:15:45 +01:00
Dave Syer
7fa41df3ff Fix CI tests 2018-07-30 09:12:42 +01:00
Dave Syer
f5ee891b92 Switch from public SOAP API on internet to local one
Every time we pick a public SOAP API on the internet someone shuts
it down. It's easier to just use the one from the "producing"
guide.

Fixes gh-27
2018-07-30 08:53:52 +01:00
Greg Turnquist
114cdf9303 Upgrade to @SpringBoot 2.0.3.RELEASE and @SpringCloud Finchley.RELEASE 2018-06-18 16:16:23 -05:00
Greg Turnquist
b3ab774645 Upgrade to Spring Boot 2.0.2.RELEASE and Spring Cloud Finchley.RC1 2018-05-09 11:26:10 -05:00
Greg Turnquist
13f788828c Upgrade to Spring Boot 2.0.1.RELEASE 2018-04-05 11:44:33 -05:00
Greg Turnquist
37d9059170 Remove front matter 2018-04-02 13:03:21 -05:00
Greg Turnquist
3daf15481c Replace jar gradle task with bootJar task 2018-03-05 23:21:35 -06:00
Greg Turnquist
f330d642aa Polish guide to reference 2.0.0.RELEASE 2018-03-05 22:45:33 -06:00
Greg Turnquist
43e0f7b3d1 Upgrade to Spring Boot 2.0.0.RELEASE 2018-03-01 09:52:36 -06:00
Greg Turnquist
05ceb76b51 Upgrade to Gradle 4.6 2018-03-01 09:20:32 -06:00
Greg Turnquist
13aa315842 Upgrade to Spring Boot 1.5.10.RELEASE 2018-01-31 09:15:50 -06:00
Greg Turnquist
db286b73f1 Upgrade to Spring Boot 1.5.9.RELEASE 2017-11-30 11:06:30 -06:00
Augusto Toledo
1985a85c19 Change old ‘weather service’ references to the ‘stock market service’ 2017-11-14 14:09:18 +00:00
ma
c128804ac5 args parameter added
Added args parameter to SpringApplication.run method to support command line arguments
2017-11-08 10:03:50 +00:00
Greg Turnquist
ef22c0322d Upgrade to Spring Boot 1.5.8.RELEASE 2017-10-17 15:42:14 -05:00
Greg Turnquist
c96d6e8e4f Upgrade to Spring Boot 1.5.7.RELEASE 2017-09-13 13:15:15 -05:00
Jay Bryant
506745d1a2 Added See Also links (#21)
At the bottom of the document (above the footer), I added links to other guides that readers may find to be useful.
2017-08-11 14:55:30 -05:00
Greg Turnquist
4bb2c01474 Upgrade to Spring Boot 1.5.6.RELEASE 2017-07-27 10:04:21 -05:00
Greg Turnquist
dda3c483f7 Upgrade to Spring Boot 1.5.5.RELEASE 2017-07-26 12:23:00 -05:00
Greg Turnquist
a2e2c2d7c2 Upgrade to Spring Boot 1.5.3.RELEASE 2017-04-21 09:20:02 -05:00
Greg Turnquist
1c036c8093 Upgrade to Spring Boot 1.5.2.RELEASE 2017-03-03 11:12:55 -06:00
Greg Turnquist
69d1c5f793 Upgrade to Spring Boot 1.5.1.RELEASE 2017-01-30 23:29:36 -06:00
Greg Turnquist
c6783ee869 Upgrade to Spring Boot 1.5.0.RELEASE 2017-01-30 11:38:03 -06:00
Greg Turnquist
1b7fa858a0 Set maven pom.xml to Spring Boot 1.4.4.RELEASE 2017-01-26 12:47:34 -06:00
Greg Turnquist
2c03bf2281 Upgrade to Spring Boot 1.4.4.RELEASE 2017-01-26 12:37:09 -06:00
Dave Syer
a625386b76 Switch to quote service (SOAP endpoint actually exists)
The weather service we had been using no longer exists and there
doesn't seem to be a simple publicly available alternative
(everyone is using plain HTTP these days). So this change converts
the sample to a public SOAP service that does stock quotes.

Fixes gh-9
2017-01-16 11:00:22 +00:00
Greg Turnquist
537578d624 Upgrade to Spring Boot 1.4.3.RELEASE 2016-12-22 22:32:28 -06:00
KC Baltz
62359bb948 Adding a comment to help others avoid a mistake
I think "hello.wsdl" sounds too much like a file name and not a package.  My colleague changed one and not the other and didn't see the problem.  I think this comment would help.
2016-12-20 11:58:34 +00:00
Greg Turnquist
c1060bbb5a Upgrade plugin from spring-boot to o.s.boot 2016-11-30 10:06:22 -06:00
23 changed files with 169 additions and 187 deletions

View File

@@ -1,12 +1,8 @@
---
tags: [SOAP]
projects: [spring-ws]
---
:spring_version: current
:toc:
:project_id: gs-consuming-web-service
:spring_version: current
:spring_boot_version: 1.4.2.RELEASE
:spring_boot_version: 2.1.3.RELEASE
:icons: font
:source-highlighter: prettify
@@ -14,10 +10,10 @@ This guide walks you through the process of consuming a link:/understanding/SOAP
== What you'll build
You will build a client that fetches weather data from a remote, WSDL-based web service using http://en.wikipedia.org/wiki/SOAP[SOAP].
You can find out more about the weather service at http://wiki.cdyne.com/index.php/CDYNE_Weather
You will build a client that fetches country data data from a remote, WSDL-based web service using http://en.wikipedia.org/wiki/SOAP[SOAP].
You can find out more about the country service, and run the service yourself by following https://spring.io/guides/gs/producing-web-service/[this guide].
The service provides weather forecasts based on a zipcode. You will be able to use your own zip code.
The service provides country data. You will be able to query data about a country based on its name.
== What you'll need
@@ -39,12 +35,15 @@ include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/
NOTE: If you read link:/guides/gs/producing-web-service[Producing a SOAP web service], you might be wondering why this guide doesn't use *spring-boot-starter-ws*? That Spring Boot starter is
only for server-side web services. That starter brings on board things like embedded Tomcat, which isn't need to make a web call.
== Run the target web service locally
Follow the steps in the https://spring.io/guides/gs/producing-web-service/[companion guide], or just clone the https://github.com/spring-guides/gs-producing-web-service[repository] and run the service (e.g. using `mvn spring-boot:run`) from its `complete` directory. You can verify that is working by visiting http://localhost:8080/ws/countries.wsdl in your browser.
[[initial]]
== Generate domain objects based on a WSDL
The interface to a SOAP web service is captured in a http://en.wikipedia.org/wiki/Web_Services_Description_Language[WSDL]. JAXB provides an easy means to generate Java classes from a WSDL (or rather: the XSD contained in the `<Types/>` section of the WSDL).
The WSDL for the weather service can be found at http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl.
The WSDL for the country service can be found at http://localhost:8080/ws/countries.wsdl.
To generate Java classes from the WSDL in maven, you need the following plugin setup:
@@ -66,41 +65,41 @@ As gradle does not have a JAXB plugin (yet), it involves an ant task, which make
In both cases, the JAXB domain object generation process has been wired into the build tool's lifecycle so there are no extra steps to run.
== Create a weather service client
== Create a country service client
To create a web service client, you simply have to extend the http://docs.spring.io/spring-ws/sites/2.0/apidocs/org/springframework/ws/client/core/support/WebServiceGatewaySupport.html[WebServiceGatewaySupport] class and code your operations:
`src/main/java/hello/WeatherClient.java`
`src/main/java/hello/CountryClient.java`
[source,java]
----
include::complete/src/main/java/hello/WeatherClient.java[]
include::complete/src/main/java/hello/CountryClient.java[]
----
The client contains two methods: `getCityForecastByZip` which does the actual SOAP exchange, and `printResponse` which prints the received response. We will focus on the former method.
The client contains one method: `getCountry` which does the actual SOAP exchange.
In this method, both the `GetCityForecastByZIP` and the `GetCityForecastByZIPResponse` classes are derived from the WSDL and were generated in the JAXB generation process described in the previous step.
It creates the `GetCityForecastByZIP` request object and set it with the `zipCode` parameter.
After printing out the zip code, it uses the http://docs.spring.io/spring-ws/sites/2.0/apidocs/org/springframework/ws/client/core/WebServiceTemplate.html[WebServiceTemplate] supplied by the `WebServiceGatewaySupport` base class to do the actual SOAP exchange.
It passes the `GetCityForecastByZIP` request object, as well as a `SoapActionCallback` to pass on a http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383528[SOAPAction] header with the request, as the WSDL described that it needed this header in the `<soap:operation/>` elements.
It casts the response into a `GetCityForecastByZIPResponse` object, which is then returned.
In this method, both the `GetCountryRequest` and the `GetCountryResponse` classes are derived from the WSDL and were generated in the JAXB generation process described in the previous step.
It creates the `GetCountryRequest` request object and sets it up with the `country` parameter (the name of the country).
After printing out the country name, it uses the http://docs.spring.io/spring-ws/sites/2.0/apidocs/org/springframework/ws/client/core/WebServiceTemplate.html[WebServiceTemplate] supplied by the `WebServiceGatewaySupport` base class to do the actual SOAP exchange.
It passes the `GetCountryRequest` request object, as well as a `SoapActionCallback` to pass on a http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383528[SOAPAction] header with the request, as the WSDL described that it needed this header in the `<soap:operation/>` elements.
It casts the response into a `GetCountryResponse` object, which is then returned.
== Configuring web service components
Spring WS uses Spring Framework's OXM module which has the `Jaxb2Marshaller` to serialize and deserialize XML requests.
`src/main/java/hello/WeatherConfiguration.java`
`src/main/java/hello/CountryConfiguration.java`
[source,java]
----
include::complete/src/main/java/hello/WeatherConfiguration.java[]
include::complete/src/main/java/hello/CountryConfiguration.java[]
----
The `marshaller` is pointed at the collection of generated domain objects and will use them to both serialize and deserialize between XML and link:/understanding/POJO[POJOs].
The `weatherClient` is created and configured with the URI of the weather service shown up above. It is also configured to use the JAXB marshaller.
The `countryClient` is created and configured with the URI of the country service shown up above. It is also configured to use the JAXB marshaller.
== Make the application executable
This application is packaged up to run from the console and retrieve a single weather forecast for a given zip code.
This application is packaged up to run from the console and retrieve the data for a given country name:
`src/main/java/hello/Application.java`
[source,java]
@@ -108,9 +107,9 @@ This application is packaged up to run from the console and retrieve a single we
include::complete/src/main/java/hello/Application.java[]
----
The `main()` method defers to the http://docs.spring.io/spring-boot/docs/{spring_boot_version}/api/org/springframework/boot/SpringApplication.html[`SpringApplication`] helper class, providing `WeatherConfiguration.class` as an argument to its `run()` method. This tells Spring to read the annotation metadata from `WeatherConfiguration` and to manage it as a component in the link:/understanding/application-context[Spring application context].
The `main()` method defers to the http://docs.spring.io/spring-boot/docs/{spring_boot_version}/api/org/springframework/boot/SpringApplication.html[`SpringApplication`] helper class, providing `CountryConfiguration.class` as an argument to its `run()` method. This tells Spring to read the annotation metadata from `CountryConfiguration` and to manage it as a component in the link:/understanding/application-context[Spring application context].
NOTE: This application is hard coded to look up zip code 94304, Palo Alto, CA. Towards the end of this guide, you'll see how to plug in a different zip code without editing the code.
NOTE: This application is hard coded to look up symbol 'MSFT' which correspond to Microsoft Corporation. Towards the end of this guide, you'll see how to plug in a different symbol without editing the code.
include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/build_an_executable_jar_subhead.adoc[]
@@ -120,40 +119,28 @@ include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/
Logging output is displayed. The service should be up and running within a few seconds.
```
Requesting forecast for 94304
Requesting country data for Spain
Forecast for Palo Alto, CA
2013-01-03 Partly Cloudy °-57°
2013-01-04 Partly Cloudy 41°-58°
2013-01-05 Partly Cloudy 41°-59°
2013-01-06 Partly Cloudy 44°-56°
2013-01-07 Partly Cloudy 41°-60°
2013-01-08 Partly Cloudy 42°-60°
2013-01-09 Partly Cloudy 43°-58°
<getCountryRequest><name>Spain</name>...</getCountryRequest>
```
You can plug in a different zip code by typing `java -jar build/libs/gs-consuming-web-service-0.1.0.jar 34769`
You can plug in a different country by typing `java -jar build/libs/gs-consuming-web-service-0.1.0.jar Poland`
```
Requesting forecast for 34769
Requesting location for Poland
Forecast for Saint Cloud, FL
2014-02-18 Sunny 51°-79°
2014-02-19 Sunny 55°-81°
2014-02-20 Sunny 59°-84°
2014-02-21 Partly Cloudy 63°-85°
2014-02-22 Partly Cloudy 63°-84°
2014-02-23 Partly Cloudy 63°-82°
2014-02-24 Partly Cloudy 62°-80°
<getCountryRequest><name>Poland</name>...</getCountryRequest>
```
== Summary
Congratulations! You've just developed a client to consume a SOAP-based web service with Spring.
Congratulations! You've just developed a client to consume a SOAP-based web service with Spring.
== See Also
The following guides may also be helpful:
* https://spring.io/guides/gs/producing-web-service/[Producing a SOAP web service]
* https://spring.io/guides/gs/spring-boot/[Building an Application with Spring Boot]
include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/footer.adoc[]

View File

@@ -7,14 +7,15 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.2.RELEASE")
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.3.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
repositories {
mavenCentral()
@@ -24,7 +25,7 @@ repositories {
task genJaxb {
ext.sourcesDir = "${buildDir}/generated-sources/jaxb"
ext.classesDir = "${buildDir}/classes/jaxb"
ext.schema = "http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl"
ext.schema = "http://localhost:8080/ws/countries.wsdl"
outputs.dir classesDir
@@ -70,7 +71,7 @@ dependencies {
jaxb "com.sun.xml.bind:jaxb-xjc:2.1.7"
}
jar {
bootJar {
baseName = 'gs-consuming-web-service'
version = '0.1.0'

Binary file not shown.

View File

@@ -1,6 +1,6 @@
#Mon Aug 29 13:05:58 CDT 2016
#Thu Mar 01 09:01:11 CST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip

46
complete/gradlew vendored
View File

@@ -6,12 +6,30 @@
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
@@ -30,6 +48,7 @@ die ( ) {
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
@@ -40,26 +59,11 @@ case "`uname`" in
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
@@ -85,7 +89,7 @@ location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then

View File

@@ -8,14 +8,14 @@
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
@@ -46,7 +46,7 @@ echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args

2
complete/mvnw vendored
View File

@@ -8,7 +8,7 @@
# "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
# https://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

2
complete/mvnw.cmd vendored
View File

@@ -7,7 +7,7 @@
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM http://www.apache.org/licenses/LICENSE-2.0
@REM https://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
@@ -10,7 +10,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
<version>2.1.3.RELEASE</version>
</parent>
<properties>
@@ -51,7 +51,7 @@
<generatePackage>hello.wsdl</generatePackage>
<schemas>
<schema>
<url>http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl</url>
<url>http://localhost:8080/ws/countries.wsdl</url>
</schema>
</schemas>
</configuration>

View File

@@ -1,29 +1,30 @@
package hello;
import hello.wsdl.GetCityForecastByZIPResponse;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import hello.wsdl.GetCountryResponse;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class);
SpringApplication.run(Application.class, args);
}
@Bean
CommandLineRunner lookup(WeatherClient weatherClient) {
CommandLineRunner lookup(CountryClient quoteClient) {
return args -> {
String zipCode = "94304";
String country = "Spain";
if (args.length > 0) {
zipCode = args[0];
country = args[0];
}
GetCityForecastByZIPResponse response = weatherClient.getCityForecastByZip(zipCode);
GetCountryResponse response = quoteClient.getCountry(country);
System.err.println(response.getCountry().getCurrency());
};
}

View File

@@ -0,0 +1,32 @@
package hello;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
import org.springframework.ws.soap.client.core.SoapActionCallback;
import hello.wsdl.GetCountryRequest;
import hello.wsdl.GetCountryResponse;
public class CountryClient extends WebServiceGatewaySupport {
private static final Logger log = LoggerFactory.getLogger(CountryClient.class);
public GetCountryResponse getCountry(String country) {
GetCountryRequest request = new GetCountryRequest();
request.setName(country);
log.info("Requesting location for " + country);
GetCountryResponse response = (GetCountryResponse) getWebServiceTemplate()
.marshalSendAndReceive("http://localhost:8080/ws/countries", request,
new SoapActionCallback(
"http://spring.io/guides/gs-producing-web-service/GetCountryRequest"));
return response;
}
}

View File

@@ -6,19 +6,21 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
@Configuration
public class WeatherConfiguration {
public class CountryConfiguration {
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
// this package must match the package in the <generatePackage> specified in
// pom.xml
marshaller.setContextPath("hello.wsdl");
return marshaller;
}
@Bean
public WeatherClient weatherClient(Jaxb2Marshaller marshaller) {
WeatherClient client = new WeatherClient();
client.setDefaultUri("http://ws.cdyne.com/WeatherWS");
public CountryClient countryClient(Jaxb2Marshaller marshaller) {
CountryClient client = new CountryClient();
client.setDefaultUri("http://localhost:8080/ws");
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;

View File

@@ -1,58 +0,0 @@
package hello;
import java.text.SimpleDateFormat;
import hello.wsdl.Forecast;
import hello.wsdl.ForecastReturn;
import hello.wsdl.GetCityForecastByZIP;
import hello.wsdl.GetCityForecastByZIPResponse;
import hello.wsdl.Temp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
import org.springframework.ws.soap.client.core.SoapActionCallback;
public class WeatherClient extends WebServiceGatewaySupport {
private static final Logger log = LoggerFactory.getLogger(WeatherClient.class);
public GetCityForecastByZIPResponse getCityForecastByZip(String zipCode) {
GetCityForecastByZIP request = new GetCityForecastByZIP();
request.setZIP(zipCode);
log.info("Requesting forecast for " + zipCode);
GetCityForecastByZIPResponse response = (GetCityForecastByZIPResponse) getWebServiceTemplate()
.marshalSendAndReceive(
"http://wsf.cdyne.com/WeatherWS/Weather.asmx",
request,
new SoapActionCallback("http://ws.cdyne.com/WeatherWS/GetCityForecastByZIP"));
return response;
}
public void printResponse(GetCityForecastByZIPResponse response) {
ForecastReturn forecastReturn = response.getGetCityForecastByZIPResult();
if (forecastReturn.isSuccess()) {
log.info("Forecast for " + forecastReturn.getCity() + ", " + forecastReturn.getState());
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
for (Forecast forecast : forecastReturn.getForecastResult().getForecast()) {
Temp temperature = forecast.getTemperatures();
log.info(String.format("%s %s %s°-%s°", format.format(forecast.getDate().toGregorianCalendar().getTime()),
forecast.getDesciption(), temperature.getMorningLow(), temperature.getDaytimeHigh()));
log.info("");
}
} else {
log.info("No forecast received");
}
}
}

View File

@@ -7,14 +7,15 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.2.RELEASE")
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.3.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
repositories {
mavenCentral()
@@ -24,7 +25,7 @@ repositories {
task genJaxb {
ext.sourcesDir = "${buildDir}/generated-sources/jaxb"
ext.classesDir = "${buildDir}/classes/jaxb"
ext.schema = "http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl"
ext.schema = "http://localhost:8080/ws/countries.wsdl"
outputs.dir classesDir
@@ -70,7 +71,7 @@ dependencies {
jaxb "com.sun.xml.bind:jaxb-xjc:2.1.7"
}
jar {
bootJar {
baseName = 'gs-consuming-web-service'
version = '0.1.0'

Binary file not shown.

View File

@@ -1,6 +1,6 @@
#Mon Aug 29 13:06:03 CDT 2016
#Thu Mar 01 09:01:07 CST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip

46
initial/gradlew vendored
View File

@@ -6,12 +6,30 @@
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
@@ -30,6 +48,7 @@ die ( ) {
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
@@ -40,26 +59,11 @@ case "`uname`" in
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
@@ -85,7 +89,7 @@ location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then

8
initial/gradlew.bat vendored
View File

@@ -8,14 +8,14 @@
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
@@ -46,7 +46,7 @@ echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args

2
initial/mvnw vendored
View File

@@ -8,7 +8,7 @@
# "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
# https://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

2
initial/mvnw.cmd vendored
View File

@@ -7,7 +7,7 @@
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM http://www.apache.org/licenses/LICENSE-2.0
@REM https://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
@@ -10,7 +10,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
<version>2.1.3.RELEASE</version>
</parent>
<properties>
@@ -51,7 +51,7 @@
<generatePackage>hello.wsdl</generatePackage>
<schemas>
<schema>
<url>http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl</url>
<url>http://localhost:8080/ws/countries.wsdl</url>
</schema>
</schemas>
</configuration>

1
test/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
gs-producing*/

View File

@@ -1,6 +1,11 @@
#!/bin/sh
cd $(dirname $0)
git clone https://github.com/spring-guides/gs-producing-web-service
(cd gs-producing-web-service/complete; ./mvnw install; ./mvnw spring-boot:run &)
sleep 10
cd ../complete
mvn clean package
@@ -33,4 +38,6 @@ exit $ret
fi
rm -rf build
pkill -f spring-boot:run
exit