From 0c9445f2d5a2467cc5be2f7ff45c208047dc4a0d Mon Sep 17 00:00:00 2001 From: mskakici <133224700+mskakici@users.noreply.github.com> Date: Wed, 9 Apr 2025 16:31:13 +0200 Subject: [PATCH 1/4] init --- .vscode/settings.json | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7b016a8 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.compile.nullAnalysis.mode": "automatic" +} \ No newline at end of file From 6301d4826d8004c3795c009f3c387b7037b48446 Mon Sep 17 00:00:00 2001 From: mskakici <133224700+mskakici@users.noreply.github.com> Date: Wed, 9 Apr 2025 16:38:29 +0200 Subject: [PATCH 2/4] dodan jaxs maven plugin --- .vscode/settings.json | 3 ++- initial/pom.xml | 28 +++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 7b016a8..e012065 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "java.compile.nullAnalysis.mode": "automatic" + "java.compile.nullAnalysis.mode": "automatic", + "java.configuration.updateBuildConfiguration": "interactive" } \ No newline at end of file diff --git a/initial/pom.xml b/initial/pom.xml index 2c9c5f3..db8f067 100644 --- a/initial/pom.xml +++ b/initial/pom.xml @@ -1,12 +1,13 @@ - 4.0.0 org.springframework.boot spring-boot-starter-parent 3.3.0 - + com.example consuming-web-service-initial @@ -35,7 +36,28 @@ org.springframework.boot spring-boot-maven-plugin + + com.sun.xml.ws + jaxws-maven-plugin + 3.0.0 + + + + wsimport + + + + + com.example.consumingwebservice.wsdl + + http://localhost:8080/ws/countries.wsdl + + ${sourcesDir} + ${classesDir} + true + + - + \ No newline at end of file From ddd9fa4a1d28d8b649ca17b73034f3ec70b76d87 Mon Sep 17 00:00:00 2001 From: mskakici <133224700+mskakici@users.noreply.github.com> Date: Wed, 9 Apr 2025 20:21:48 +0200 Subject: [PATCH 3/4] upitno gotovo --- .vscode/launch.json | 14 +++++++++ initial/pom.xml | 28 ++++++++++++++--- .../ConsumingWebServiceApplication.java | 25 ++++++++++++--- .../consumingwebservice/CountryClient.java | 31 +++++++++++++++++++ .../CountryConfiguration.java | 28 +++++++++++++++++ 5 files changed, 117 insertions(+), 9 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 initial/src/main/java/com/example/consumingwebservice/CountryClient.java create mode 100644 initial/src/main/java/com/example/consumingwebservice/CountryConfiguration.java diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..9fbb8c6 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + "configurations": [ + { + "type": "java", + "name": "Spring Boot-ConsumingWebServiceApplication", + "request": "launch", + "cwd": "${workspaceFolder}", + "mainClass": "com.example.consumingwebservice.ConsumingWebServiceApplication", + "projectName": "consuming-web-service-initial", + "args": "", + "envFile": "${workspaceFolder}/.env" + } + ] +} \ No newline at end of file diff --git a/initial/pom.xml b/initial/pom.xml index db8f067..93cb620 100644 --- a/initial/pom.xml +++ b/initial/pom.xml @@ -1,27 +1,42 @@ - 4.0.0 org.springframework.boot spring-boot-starter-parent 3.3.0 - + com.example - consuming-web-service-initial + consuming-web-service-complete 0.0.1-SNAPSHOT - consuming-web-service-initial + consuming-web-service-complete Demo project for Spring Boot + 17 + + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot spring-boot-starter-web-services + + + org.springframework.boot + spring-boot-starter-tomcat + + + org.springframework.boot @@ -36,12 +51,14 @@ org.springframework.boot spring-boot-maven-plugin + com.sun.xml.ws jaxws-maven-plugin 3.0.0 + wsimport @@ -57,6 +74,7 @@ true + diff --git a/initial/src/main/java/com/example/consumingwebservice/ConsumingWebServiceApplication.java b/initial/src/main/java/com/example/consumingwebservice/ConsumingWebServiceApplication.java index 0afc9ba..03f312d 100644 --- a/initial/src/main/java/com/example/consumingwebservice/ConsumingWebServiceApplication.java +++ b/initial/src/main/java/com/example/consumingwebservice/ConsumingWebServiceApplication.java @@ -1,13 +1,30 @@ package com.example.consumingwebservice; +import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; + +import com.example.consumingwebservice.wsdl.GetCountryResponse; @SpringBootApplication public class ConsumingWebServiceApplication { - public static void main(String[] args) { - SpringApplication.run(ConsumingWebServiceApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(ConsumingWebServiceApplication.class, args); + } + + @Bean + CommandLineRunner lookup(CountryClient countryClient) { + return args -> { + String country = "Spain"; + + if (args.length > 0) { + country = args[0]; + } + GetCountryResponse response = countryClient.getCountry(country); + System.err.println(response.getCountry().getCurrency()); + }; + } -} +} \ No newline at end of file diff --git a/initial/src/main/java/com/example/consumingwebservice/CountryClient.java b/initial/src/main/java/com/example/consumingwebservice/CountryClient.java new file mode 100644 index 0000000..edba042 --- /dev/null +++ b/initial/src/main/java/com/example/consumingwebservice/CountryClient.java @@ -0,0 +1,31 @@ +package com.example.consumingwebservice; + +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 com.example.consumingwebservice.wsdl.GetCountryRequest; +import com.example.consumingwebservice.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; + } + +} \ No newline at end of file diff --git a/initial/src/main/java/com/example/consumingwebservice/CountryConfiguration.java b/initial/src/main/java/com/example/consumingwebservice/CountryConfiguration.java new file mode 100644 index 0000000..f436953 --- /dev/null +++ b/initial/src/main/java/com/example/consumingwebservice/CountryConfiguration.java @@ -0,0 +1,28 @@ +package com.example.consumingwebservice; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.oxm.jaxb.Jaxb2Marshaller; + +@Configuration +public class CountryConfiguration { + + @Bean + public Jaxb2Marshaller marshaller() { + Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); + // this package must match the package in the specified in + // pom.xml + marshaller.setContextPath("com.example.consumingwebservice.wsdl"); + return marshaller; + } + + @Bean + public CountryClient countryClient(Jaxb2Marshaller marshaller) { + CountryClient client = new CountryClient(); + client.setDefaultUri("http://localhost:8080/ws"); + client.setMarshaller(marshaller); + client.setUnmarshaller(marshaller); + return client; + } + +} \ No newline at end of file From 3eb792157956050ab219bbc5d1e9a89e0bccd160 Mon Sep 17 00:00:00 2001 From: mskakici <133224700+mskakici@users.noreply.github.com> Date: Wed, 9 Apr 2025 20:37:45 +0200 Subject: [PATCH 4/4] gotovo --- complete/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/complete/pom.xml b/complete/pom.xml index 3874e53..5caf373 100644 --- a/complete/pom.xml +++ b/complete/pom.xml @@ -52,6 +52,7 @@ 3.0.0 + wsimport