Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc8ec86ea2 |
60
Jenkinsfile
vendored
Normal file
60
Jenkinsfile
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
pipeline {
|
||||
agent none
|
||||
|
||||
triggers {
|
||||
pollSCM 'H/10 * * * *'
|
||||
}
|
||||
|
||||
options {
|
||||
disableConcurrentBuilds()
|
||||
buildDiscarder(logRotator(numToKeepStr: '14'))
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Publish OpenJDK 8 + git') {
|
||||
when {
|
||||
changeset "ci/Dockerfile"
|
||||
}
|
||||
agent any
|
||||
|
||||
steps {
|
||||
script {
|
||||
def image = docker.build("springci/gs-consuming-web-service-and-git", "ci/")
|
||||
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
||||
image.push()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage("test: baseline (jdk8)") {
|
||||
agent {
|
||||
docker {
|
||||
image 'springci/gs-consuming-web-service-and-git:latest'
|
||||
args '-v $HOME/.m2:/tmp/jenkins-home/.m2'
|
||||
}
|
||||
}
|
||||
options { timeout(time: 30, unit: 'MINUTES') }
|
||||
steps {
|
||||
sh 'test/run.sh'
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
post {
|
||||
changed {
|
||||
script {
|
||||
slackSend(
|
||||
color: (currentBuild.currentResult == 'SUCCESS') ? 'good' : 'danger',
|
||||
channel: '#sagan-content',
|
||||
message: "${currentBuild.fullDisplayName} - `${currentBuild.currentResult}`\n${env.BUILD_URL}")
|
||||
emailext(
|
||||
subject: "[${currentBuild.fullDisplayName}] ${currentBuild.currentResult}",
|
||||
mimeType: 'text/html',
|
||||
recipientProviders: [[$class: 'CulpritsRecipientProvider'], [$class: 'RequesterRecipientProvider']],
|
||||
body: "<a href=\"${env.BUILD_URL}\">${currentBuild.fullDisplayName} is reported as ${currentBuild.currentResult}</a>")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
40
README.adoc
40
README.adoc
@@ -20,11 +20,16 @@ The service provides country data. You will be able to query data about a countr
|
||||
|
||||
== What You Need
|
||||
|
||||
:java_version: 17
|
||||
:java_version: 1.8
|
||||
include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/main/prereq_editor_jdk_buildtools.adoc[]
|
||||
|
||||
include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/main/how_to_complete_this_guide.adoc[]
|
||||
|
||||
NOTE: If you read link:/guides/gs/producing-web-service[Producing a SOAP web service], you
|
||||
might wonder why this guide does not use `spring-boot-starter-ws`? That Spring Boot
|
||||
starter is only for server-side web services. That starter brings on board such things as
|
||||
embedded Tomcat, which is not needed to make a web call.
|
||||
|
||||
== Run the Target Web Service Locally
|
||||
|
||||
Follow the steps in the
|
||||
@@ -32,7 +37,7 @@ https://spring.io/guides/gs/producing-web-service/[companion guide] or clone the
|
||||
https://github.com/spring-guides/gs-producing-web-service[repository] and run the service
|
||||
(for example, by using `mvn spring-boot:run`) from its `complete` directory. You can
|
||||
verify that it works by visiting `http://localhost:8080/ws/countries.wsdl` in your
|
||||
browser. If you do not do so, you will see a confusing exception in your build later from the JAXB tooling.
|
||||
browser. If you don't do this you will see a confusing exception in your build later from the JAXB tooling.
|
||||
|
||||
[[scratch]]
|
||||
== Starting with Spring Initializr
|
||||
@@ -42,8 +47,6 @@ Initializr]. The Initializr offers a fast way to pull in all the dependencies yo
|
||||
an application and does a lot of the setup for you. This example needs only the Spring Web
|
||||
Services dependency.
|
||||
|
||||
You can use this https://start.spring.io/#!type=maven-project&language=java&&packaging=jar&jvmVersion=17&groupId=com.example&artifactId=consuming-web-service&name=consuming-web-service&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.consuming-web-service&dependencies=web-services[pre-initialized project] and click Generate to download a ZIP file. This project is configured to fit the examples in this tutorial.
|
||||
|
||||
To initialize the project:
|
||||
|
||||
. Navigate to https://start.spring.io.
|
||||
@@ -76,6 +79,15 @@ include::complete/pom.xml[tags=dependency]
|
||||
----
|
||||
====
|
||||
|
||||
The following listing shows the profile you need to add in Maven if you want it to work with Java 11:
|
||||
|
||||
====
|
||||
[source,xml,indent=0]
|
||||
----
|
||||
include::complete/pom.xml[tags=profile]
|
||||
----
|
||||
====
|
||||
|
||||
The <<initial>> section describes the WSDL generation plugin.
|
||||
|
||||
The following listing shows the final `pom.xml` file:
|
||||
@@ -104,10 +116,14 @@ include::complete/build.gradle[tags=dependency]
|
||||
Note the exclusion of Tomcat. If Tomcat is allowed to run in this build, you get a port
|
||||
collision with the Tomcat instance that provides the country data.
|
||||
|
||||
NOTE: Due to this port collision, the initial project fails to start.
|
||||
You can fix it by adding an `application.properties` file with a single property of
|
||||
`server.port=8081`. Since the initial project exists to be a starting point, you
|
||||
can skip trying to get it to run.
|
||||
The following listing shows the `bootJar` section you need to add in Gradle:
|
||||
|
||||
====
|
||||
[source,xml,indent=0]
|
||||
----
|
||||
include::complete/build.gradle[tags=bootjar]
|
||||
----
|
||||
====
|
||||
|
||||
The <<initial>> section describes the WSDL generation plugin.
|
||||
|
||||
@@ -138,11 +154,11 @@ include::complete/pom.xml[tags=wsdl]
|
||||
----
|
||||
====
|
||||
|
||||
This setup generates classes for the WSDL found at the specified URL, putting those
|
||||
classes in the `com.example.consumingwebservice.wsdl` package. To generate that code run, `./mvnw compile`
|
||||
This setup will generate classes for the WSDL found at the specified URL, putting those
|
||||
classes in the `com.example.consumingwebservice.wsdl` package. To generate that code run `./mvnw compile`
|
||||
and then look in `target/generated-sources` if you want to check that it worked.
|
||||
|
||||
To do the same with Gradle, you need the following in your build file:
|
||||
To do the same with Gradle, you will need the following in your build file:
|
||||
|
||||
====
|
||||
[source,java,tabsize=2,indent=0]
|
||||
@@ -155,7 +171,7 @@ As Gradle does not (yet) have a JAXB plugin, it involves an Ant task, which make
|
||||
more complex than in Maven. To generate that code run `./gradlew compileJava`
|
||||
and then look in `build/generated-sources` if you want to check that it worked.
|
||||
|
||||
In both Maven and Gradle, the JAXB domain object generation process has been wired into the build
|
||||
In both cases, the JAXB domain object generation process has been wired into the build
|
||||
tool's lifecycle, so you need not run any extra steps once you have a successful build.
|
||||
|
||||
== Create a Country Service Client
|
||||
|
||||
25
build.gradle
25
build.gradle
@@ -1,25 +0,0 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'org.springframework.boot' version '3.1.2'
|
||||
id 'io.spring.dependency-management' version '1.1.2'
|
||||
}
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
|
||||
java {
|
||||
sourceCompatibility = '17'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web-services'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
@@ -1,19 +1,16 @@
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.7.6'
|
||||
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
|
||||
id 'java'
|
||||
id 'org.springframework.boot' version '3.1.2'
|
||||
id 'io.spring.dependency-management' version '1.1.2'
|
||||
}
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
java {
|
||||
sourceCompatibility = '17'
|
||||
}
|
||||
ext.jaxwsSourceDir = "${buildDir}/generated/sources/jaxws"
|
||||
sourceCompatibility = '1.8'
|
||||
|
||||
// tag::configurations[]
|
||||
configurations {
|
||||
jaxws
|
||||
jaxb
|
||||
}
|
||||
// end::configurations[]
|
||||
|
||||
@@ -22,39 +19,42 @@ repositories {
|
||||
}
|
||||
|
||||
// tag::wsdl[]
|
||||
task wsimport {
|
||||
description = 'Generate classes from wsdl using wsimport'
|
||||
task genJaxb {
|
||||
ext.sourcesDir = "${buildDir}/generated-sources/jaxb"
|
||||
ext.classesDir = "${buildDir}/classes/jaxb"
|
||||
ext.schema = "http://localhost:8080/ws/countries.wsdl"
|
||||
|
||||
doLast {
|
||||
project.mkdir(jaxwsSourceDir)
|
||||
ant {
|
||||
taskdef(name: 'wsimport',
|
||||
classname: 'com.sun.tools.ws.ant.WsImport',
|
||||
classpath: configurations.jaxws.asPath
|
||||
)
|
||||
wsimport(
|
||||
keep: true,
|
||||
destdir: jaxwsSourceDir,
|
||||
extension: "true",
|
||||
verbose: true,
|
||||
wsdl: "http://localhost:8080/ws/countries.wsdl",
|
||||
xnocompile: true,
|
||||
package: "com.example.consumingwebservice.wsdl") {
|
||||
xjcarg(value: "-XautoNameResolution")
|
||||
outputs.dir classesDir
|
||||
|
||||
doLast() {
|
||||
project.ant {
|
||||
taskdef name: "xjc", classname: "com.sun.tools.xjc.XJCTask",
|
||||
classpath: configurations.jaxb.asPath
|
||||
mkdir(dir: sourcesDir)
|
||||
mkdir(dir: classesDir)
|
||||
|
||||
xjc(destdir: sourcesDir, schema: schema,
|
||||
package: "com.example.consumingwebservice.wsdl") {
|
||||
arg(value: "-wsdl")
|
||||
produces(dir: sourcesDir, includes: "**/*.java")
|
||||
}
|
||||
|
||||
javac(destdir: classesDir, source: 1.8, target: 1.8, debug: true,
|
||||
debugLevel: "lines,vars,source",
|
||||
classpath: configurations.jaxb.asPath) {
|
||||
src(path: sourcesDir)
|
||||
include(name: "**/*.java")
|
||||
include(name: "*.java")
|
||||
}
|
||||
|
||||
copy(todir: classesDir) {
|
||||
fileset(dir: sourcesDir, erroronmissingdir: false) {
|
||||
exclude(name: "**/*.java")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
java.srcDirs += jaxwsSourceDir
|
||||
}
|
||||
}
|
||||
|
||||
compileJava {
|
||||
dependsOn wsimport
|
||||
}
|
||||
// end::wsdl[]
|
||||
|
||||
dependencies {
|
||||
@@ -62,15 +62,23 @@ dependencies {
|
||||
implementation ('org.springframework.boot:spring-boot-starter-web-services') {
|
||||
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
|
||||
}
|
||||
jaxws 'com.sun.xml.ws:jaxws-tools:3.0.0',
|
||||
'jakarta.xml.ws:jakarta.xml.ws-api:3.0.0',
|
||||
'jakarta.xml.bind:jakarta.xml.bind-api:3.0.0',
|
||||
'jakarta.activation:jakarta.activation-api:2.0.0',
|
||||
'com.sun.xml.ws:jaxws-rt:3.0.0'
|
||||
implementation 'org.springframework.ws:spring-ws-core'
|
||||
// For Java 11:
|
||||
implementation 'org.glassfish.jaxb:jaxb-runtime'
|
||||
implementation(files(genJaxb.classesDir).builtBy(genJaxb))
|
||||
|
||||
jaxb "com.sun.xml.bind:jaxb-xjc:2.1.7"
|
||||
// end::dependency[]
|
||||
testImplementation('org.springframework.boot:spring-boot-starter-test')
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
// tag::bootjar[]
|
||||
bootJar {
|
||||
baseName = 'gs-consuming-web-service'
|
||||
version = '0.0.1'
|
||||
}
|
||||
// end::bootjar[]
|
||||
|
||||
@@ -5,8 +5,9 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.1.2</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
<version>2.7.6</version>
|
||||
<!-- lookup parent from repository -->
|
||||
<relativePath/>
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>consuming-web-service-complete</artifactId>
|
||||
@@ -15,10 +16,14 @@
|
||||
<description>Demo project for Spring Boot</description>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- tag::dependency[] -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -39,6 +44,24 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<!-- tag::profile[] -->
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>java11</id>
|
||||
<activation>
|
||||
<jdk>[11,)</jdk>
|
||||
</activation>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jaxb</groupId>
|
||||
<artifactId>jaxb-runtime</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
</profiles>
|
||||
<!-- end::profile[] -->
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
@@ -47,25 +70,25 @@
|
||||
</plugin>
|
||||
<!-- tag::wsdl[] -->
|
||||
<plugin>
|
||||
<groupId>com.sun.xml.ws</groupId>
|
||||
<artifactId>jaxws-maven-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>wsimport</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<packageName>com.example.consumingwebservice.wsdl</packageName>
|
||||
<wsdlUrls>
|
||||
<wsdlUrl>http://localhost:8080/ws/countries.wsdl</wsdlUrl>
|
||||
</wsdlUrls>
|
||||
<sourceDestDir>${sourcesDir}</sourceDestDir>
|
||||
<destDir>${classesDir}</destDir>
|
||||
<extension>true</extension>
|
||||
</configuration>
|
||||
<groupId>org.jvnet.jaxb2.maven2</groupId>
|
||||
<artifactId>maven-jaxb2-plugin</artifactId>
|
||||
<version>0.14.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<schemaLanguage>WSDL</schemaLanguage>
|
||||
<generatePackage>com.example.consumingwebservice.wsdl</generatePackage>
|
||||
<schemas>
|
||||
<schema>
|
||||
<url>http://localhost:8080/ws/countries.wsdl</url>
|
||||
</schema>
|
||||
</schemas>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- end::wsdl[] -->
|
||||
</plugins>
|
||||
|
||||
@@ -1,26 +1,22 @@
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.7.6'
|
||||
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
|
||||
id 'java'
|
||||
id 'org.springframework.boot' version '3.1.2'
|
||||
id 'io.spring.dependency-management' version '1.1.2'
|
||||
}
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
java {
|
||||
sourceCompatibility = '17'
|
||||
}
|
||||
sourceCompatibility = '1.8'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation ('org.springframework.boot:spring-boot-starter-web-services') {
|
||||
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
|
||||
}
|
||||
implementation 'org.springframework.boot:spring-boot-starter'
|
||||
testImplementation('org.springframework.boot:spring-boot-starter-test')
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.1.2</version>
|
||||
<version>2.7.6</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
@@ -13,13 +13,15 @@
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>consuming-web-service-initial</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web-services</artifactId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
1
initial/src/main/resources/application.properties
Normal file
1
initial/src/main/resources/application.properties
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
logging:
|
||||
level:
|
||||
com.example.consumingwebservice: INFO
|
||||
org:
|
||||
springframework:
|
||||
ws: DEBUG
|
||||
Reference in New Issue
Block a user