From d4b0c2979c6d286b3eecc05a567db86bb04f5b7a Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Tue, 10 Dec 2024 17:33:48 +0100 Subject: [PATCH] Added working SOAP API --- .gitignore | 1 + .../target/maven-archiver/pom.properties | 2 - .../compile/default-compile/inputFiles.lst | 2 +- .../target/rest-service-1.0-SNAPSHOT.jar | Bin 3033 -> 2963 bytes helpapp/soap-service/pom.xml | 105 ++++++++++++------ helpapp/soap-service/src/main/java/.gitignore | 1 + .../producingwebservice/CountryEndpoint.java | 31 ++++++ .../CountryRepository.java | 47 ++++++++ .../ProducingWebServiceApplication.java | 12 ++ .../producingwebservice/WebServiceConfig.java | 40 +++++++ .../helpapp/soap/SoapApplication.java | 12 -- .../src/main/resources/application.properties | 1 - .../src/main/resources/countries.xsd | 36 ++++++ ...WebServiceApplicationIntegrationTests.java | 56 ++++++++++ .../target/classes/application.properties | 1 - .../helpapp/soap/SoapApplication.class | Bin 729 -> 0 bytes .../target/maven-archiver/pom.properties | 8 +- .../compile/default-compile/createdFiles.lst | 11 +- .../compile/default-compile/inputFiles.lst | 11 +- .../target/soap-service-1.0-SNAPSHOT.jar | Bin 2826 -> 0 bytes 20 files changed, 317 insertions(+), 60 deletions(-) create mode 100644 .gitignore create mode 100644 helpapp/soap-service/src/main/java/.gitignore create mode 100644 helpapp/soap-service/src/main/java/com/example/producingwebservice/CountryEndpoint.java create mode 100644 helpapp/soap-service/src/main/java/com/example/producingwebservice/CountryRepository.java create mode 100644 helpapp/soap-service/src/main/java/com/example/producingwebservice/ProducingWebServiceApplication.java create mode 100644 helpapp/soap-service/src/main/java/com/example/producingwebservice/WebServiceConfig.java delete mode 100644 helpapp/soap-service/src/main/java/insa/application/helpapp/soap/SoapApplication.java create mode 100644 helpapp/soap-service/src/main/resources/countries.xsd create mode 100644 helpapp/soap-service/src/test/java/com/example/producingwebservice/ProducingWebServiceApplicationIntegrationTests.java delete mode 100644 helpapp/soap-service/target/classes/insa/application/helpapp/soap/SoapApplication.class delete mode 100644 helpapp/soap-service/target/soap-service-1.0-SNAPSHOT.jar diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f97022 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target/ \ No newline at end of file diff --git a/helpapp/rest-service/target/maven-archiver/pom.properties b/helpapp/rest-service/target/maven-archiver/pom.properties index d5ea815..2138542 100644 --- a/helpapp/rest-service/target/maven-archiver/pom.properties +++ b/helpapp/rest-service/target/maven-archiver/pom.properties @@ -1,5 +1,3 @@ -#Generated by Maven -#Tue Dec 10 16:22:56 CET 2024 artifactId=rest-service groupId=insa.application.helpapp version=1.0-SNAPSHOT diff --git a/helpapp/rest-service/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/helpapp/rest-service/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst index 3ec4258..ea7a2ce 100644 --- a/helpapp/rest-service/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ b/helpapp/rest-service/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -1 +1 @@ -/home/robin/Desktop/helpapp/rest-service/src/main/java/insa/application/helpapp/rest/RestApplication.java +/home/yoboujon/Documents/GEI/service-architecture/helpapp/rest-service/src/main/java/insa/application/helpapp/rest/RestApplication.java diff --git a/helpapp/rest-service/target/rest-service-1.0-SNAPSHOT.jar b/helpapp/rest-service/target/rest-service-1.0-SNAPSHOT.jar index a1b0940870ec94b067e4a8d093a922cda524494f..c76de09709624d435612047c8ffac10fef6a5092 100644 GIT binary patch delta 766 zcmca9K3SY6z?+$ci-CcIf#GuZL>_rz5g?lb$nJ`~74@hih=GA2aH5^Do1T}ij;HU% z(p6i6KKSZ*pAG&{#1q7ELeuyBnP7u!#utsBJT1~Xd&cwPSFe-Tc=bGdw*?t6b$u*i zWI$MOse9rDIaZ)eK*nb+2xGDmqY;!9$!HE@UGAQ2#G(OZ#j`j4;DryBu`u@G&1!8dctoq54%^Cw~p3HA8#MMk3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-service/pom.xml +++ b/helpapp/soap-service/pom.xml @@ -1,40 +1,73 @@ - - - insa.application.helpapp - helpapp - 1.0-SNAPSHOT - - 4.0.0 - soap-service + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.3.0 + + + com.example + producing-web-service-complete + 0.0.1-SNAPSHOT + producing-web-service-complete + Demo project for Spring Boot - - - - org.springframework.boot - spring-boot-starter-web-services - - + + 17 + - - - - - org.springframework.boot - spring-boot-maven-plugin - 3.1.4 - + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-web-services + + + + wsdl4j + wsdl4j + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.codehaus.mojo + jaxb2-maven-plugin + 3.1.0 + + + xjc + + xjc + + + + + + ${project.basedir}/src/main/resources/countries.xsd + + + + + + - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - 21 - 21 - - - - - diff --git a/helpapp/soap-service/src/main/java/.gitignore b/helpapp/soap-service/src/main/java/.gitignore new file mode 100644 index 0000000..5de3989 --- /dev/null +++ b/helpapp/soap-service/src/main/java/.gitignore @@ -0,0 +1 @@ +io diff --git a/helpapp/soap-service/src/main/java/com/example/producingwebservice/CountryEndpoint.java b/helpapp/soap-service/src/main/java/com/example/producingwebservice/CountryEndpoint.java new file mode 100644 index 0000000..f14655f --- /dev/null +++ b/helpapp/soap-service/src/main/java/com/example/producingwebservice/CountryEndpoint.java @@ -0,0 +1,31 @@ +package com.example.producingwebservice; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.ws.server.endpoint.annotation.Endpoint; +import org.springframework.ws.server.endpoint.annotation.PayloadRoot; +import org.springframework.ws.server.endpoint.annotation.RequestPayload; +import org.springframework.ws.server.endpoint.annotation.ResponsePayload; + +import io.spring.guides.gs_producing_web_service.GetCountryRequest; +import io.spring.guides.gs_producing_web_service.GetCountryResponse; + +@Endpoint +public class CountryEndpoint { + private static final String NAMESPACE_URI = "http://spring.io/guides/gs-producing-web-service"; + + private CountryRepository countryRepository; + + @Autowired + public CountryEndpoint(CountryRepository countryRepository) { + this.countryRepository = countryRepository; + } + + @PayloadRoot(namespace = NAMESPACE_URI, localPart = "getCountryRequest") + @ResponsePayload + public GetCountryResponse getCountry(@RequestPayload GetCountryRequest request) { + GetCountryResponse response = new GetCountryResponse(); + response.setCountry(countryRepository.findCountry(request.getName())); + + return response; + } +} diff --git a/helpapp/soap-service/src/main/java/com/example/producingwebservice/CountryRepository.java b/helpapp/soap-service/src/main/java/com/example/producingwebservice/CountryRepository.java new file mode 100644 index 0000000..d9e5a89 --- /dev/null +++ b/helpapp/soap-service/src/main/java/com/example/producingwebservice/CountryRepository.java @@ -0,0 +1,47 @@ +package com.example.producingwebservice; + +import jakarta.annotation.PostConstruct; +import java.util.HashMap; +import java.util.Map; + +import io.spring.guides.gs_producing_web_service.Country; +import io.spring.guides.gs_producing_web_service.Currency; +import org.springframework.stereotype.Component; +import org.springframework.util.Assert; + +@Component +public class CountryRepository { + private static final Map countries = new HashMap<>(); + + @PostConstruct + public void initData() { + Country spain = new Country(); + spain.setName("Spain"); + spain.setCapital("Madrid"); + spain.setCurrency(Currency.EUR); + spain.setPopulation(46704314); + + countries.put(spain.getName(), spain); + + Country poland = new Country(); + poland.setName("Poland"); + poland.setCapital("Warsaw"); + poland.setCurrency(Currency.PLN); + poland.setPopulation(38186860); + + countries.put(poland.getName(), poland); + + Country uk = new Country(); + uk.setName("United Kingdom"); + uk.setCapital("London"); + uk.setCurrency(Currency.GBP); + uk.setPopulation(63705000); + + countries.put(uk.getName(), uk); + } + + public Country findCountry(String name) { + Assert.notNull(name, "The country's name must not be null"); + return countries.get(name); + } +} diff --git a/helpapp/soap-service/src/main/java/com/example/producingwebservice/ProducingWebServiceApplication.java b/helpapp/soap-service/src/main/java/com/example/producingwebservice/ProducingWebServiceApplication.java new file mode 100644 index 0000000..e9308b1 --- /dev/null +++ b/helpapp/soap-service/src/main/java/com/example/producingwebservice/ProducingWebServiceApplication.java @@ -0,0 +1,12 @@ +package com.example.producingwebservice; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ProducingWebServiceApplication { + + public static void main(String[] args) { + SpringApplication.run(ProducingWebServiceApplication.class, args); + } +} diff --git a/helpapp/soap-service/src/main/java/com/example/producingwebservice/WebServiceConfig.java b/helpapp/soap-service/src/main/java/com/example/producingwebservice/WebServiceConfig.java new file mode 100644 index 0000000..3379538 --- /dev/null +++ b/helpapp/soap-service/src/main/java/com/example/producingwebservice/WebServiceConfig.java @@ -0,0 +1,40 @@ +package com.example.producingwebservice; + +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ClassPathResource; +import org.springframework.ws.config.annotation.EnableWs; +import org.springframework.ws.config.annotation.WsConfigurerAdapter; +import org.springframework.ws.transport.http.MessageDispatcherServlet; +import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition; +import org.springframework.xml.xsd.SimpleXsdSchema; +import org.springframework.xml.xsd.XsdSchema; + +@EnableWs +@Configuration +public class WebServiceConfig extends WsConfigurerAdapter { + @Bean + public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) { + MessageDispatcherServlet servlet = new MessageDispatcherServlet(); + servlet.setApplicationContext(applicationContext); + servlet.setTransformWsdlLocations(true); + return new ServletRegistrationBean<>(servlet, "/ws/*"); + } + + @Bean(name = "countries") + public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) { + DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition(); + wsdl11Definition.setPortTypeName("CountriesPort"); + wsdl11Definition.setLocationUri("/ws"); + wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service"); + wsdl11Definition.setSchema(countriesSchema); + return wsdl11Definition; + } + + @Bean + public XsdSchema countriesSchema() { + return new SimpleXsdSchema(new ClassPathResource("countries.xsd")); + } +} diff --git a/helpapp/soap-service/src/main/java/insa/application/helpapp/soap/SoapApplication.java b/helpapp/soap-service/src/main/java/insa/application/helpapp/soap/SoapApplication.java deleted file mode 100644 index 3abc8e9..0000000 --- a/helpapp/soap-service/src/main/java/insa/application/helpapp/soap/SoapApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package insa.application.helpapp.soap; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SoapApplication { - - public static void main(String[] args) { - SpringApplication.run(SoapApplication.class, args); - } -} diff --git a/helpapp/soap-service/src/main/resources/application.properties b/helpapp/soap-service/src/main/resources/application.properties index 4d360de..e69de29 100644 --- a/helpapp/soap-service/src/main/resources/application.properties +++ b/helpapp/soap-service/src/main/resources/application.properties @@ -1 +0,0 @@ -server.port=8081 diff --git a/helpapp/soap-service/src/main/resources/countries.xsd b/helpapp/soap-service/src/main/resources/countries.xsd new file mode 100644 index 0000000..a893956 --- /dev/null +++ b/helpapp/soap-service/src/main/resources/countries.xsd @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/helpapp/soap-service/src/test/java/com/example/producingwebservice/ProducingWebServiceApplicationIntegrationTests.java b/helpapp/soap-service/src/test/java/com/example/producingwebservice/ProducingWebServiceApplicationIntegrationTests.java new file mode 100644 index 0000000..cc030be --- /dev/null +++ b/helpapp/soap-service/src/test/java/com/example/producingwebservice/ProducingWebServiceApplicationIntegrationTests.java @@ -0,0 +1,56 @@ +/* + * Copyright 2014-2015 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 com.example.producingwebservice; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import io.spring.guides.gs_producing_web_service.GetCountryRequest; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.server.LocalServerPort; +import org.springframework.oxm.jaxb.Jaxb2Marshaller; +import org.springframework.util.ClassUtils; +import org.springframework.ws.client.core.WebServiceTemplate; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +public class ProducingWebServiceApplicationIntegrationTests { + + private Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); + + @LocalServerPort + private int port = 0; + + @BeforeEach + public void init() throws Exception { + marshaller.setPackagesToScan(ClassUtils.getPackageName(GetCountryRequest.class)); + marshaller.afterPropertiesSet(); + } + + @Test + public void testSendAndReceive() { + WebServiceTemplate ws = new WebServiceTemplate(marshaller); + GetCountryRequest request = new GetCountryRequest(); + request.setName("Spain"); + + assertThat(ws.marshalSendAndReceive("http://localhost:" + + port + "/ws", request) != null); + } +} diff --git a/helpapp/soap-service/target/classes/application.properties b/helpapp/soap-service/target/classes/application.properties index 4d360de..e69de29 100644 --- a/helpapp/soap-service/target/classes/application.properties +++ b/helpapp/soap-service/target/classes/application.properties @@ -1 +0,0 @@ -server.port=8081 diff --git a/helpapp/soap-service/target/classes/insa/application/helpapp/soap/SoapApplication.class b/helpapp/soap-service/target/classes/insa/application/helpapp/soap/SoapApplication.class deleted file mode 100644 index e398bf1db77462971bae9f9dc32e52c8209b7a73..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 729 zcmb7CxlRKy5Pc4T4Iy0NJ{r0Z3Ea^HAweXn2qc0+LFHY{V%XR#uNU|&Di8%9z(*m* z3sP1n4K8Lh*Bj59`TTnS0C0@$Ix3h5P;FomQw$6D;!*HK=$M~}_cC$}Q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