mirror of
https://github.com/Lemonochrme/service-architecture.git
synced 2025-06-08 13:40:50 +02:00
Added working SOAP API
This commit is contained in:
parent
cc235da44b
commit
d4b0c2979c
20 changed files with 317 additions and 60 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
target/
|
|
@ -1,5 +1,3 @@
|
||||||
#Generated by Maven
|
|
||||||
#Tue Dec 10 16:22:56 CET 2024
|
|
||||||
artifactId=rest-service
|
artifactId=rest-service
|
||||||
groupId=insa.application.helpapp
|
groupId=insa.application.helpapp
|
||||||
version=1.0-SNAPSHOT
|
version=1.0-SNAPSHOT
|
||||||
|
|
|
@ -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
|
||||||
|
|
Binary file not shown.
|
@ -1,40 +1,73 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0">
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<parent>
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
<groupId>insa.application.helpapp</groupId>
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<artifactId>helpapp</artifactId>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<parent>
|
||||||
</parent>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<artifactId>soap-service</artifactId>
|
<version>3.3.0</version>
|
||||||
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
|
</parent>
|
||||||
|
<groupId>com.example</groupId>
|
||||||
|
<artifactId>producing-web-service-complete</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<name>producing-web-service-complete</name>
|
||||||
|
<description>Demo project for Spring Boot</description>
|
||||||
|
|
||||||
<dependencies>
|
<properties>
|
||||||
<!-- Dépendance pour créer un service SOAP -->
|
<java.version>17</java.version>
|
||||||
<dependency>
|
</properties>
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-web-services</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
<dependencies>
|
||||||
<plugins>
|
<dependency>
|
||||||
<!-- Plugin Maven pour Spring Boot -->
|
<groupId>org.springframework.boot</groupId>
|
||||||
<plugin>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
<groupId>org.springframework.boot</groupId>
|
</dependency>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<dependency>
|
||||||
<version>3.1.4</version>
|
<groupId>org.springframework.boot</groupId>
|
||||||
</plugin>
|
<artifactId>spring-boot-starter-web-services</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- tag::springws[] -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>wsdl4j</groupId>
|
||||||
|
<artifactId>wsdl4j</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- end::springws[] -->
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<!-- tag::xsd[] -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>jaxb2-maven-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>xjc</id>
|
||||||
|
<goals>
|
||||||
|
<goal>xjc</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<sources>
|
||||||
|
<source>${project.basedir}/src/main/resources/countries.xsd</source>
|
||||||
|
</sources>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<!-- end::xsd[] -->
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
<!-- Plugin pour configurer le compilateur -->
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.8.1</version>
|
|
||||||
<configuration>
|
|
||||||
<source>21</source>
|
|
||||||
<target>21</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|
1
helpapp/soap-service/src/main/java/.gitignore
vendored
Normal file
1
helpapp/soap-service/src/main/java/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
io
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<String, Country> 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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> 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"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
server.port=8081
|
|
36
helpapp/soap-service/src/main/resources/countries.xsd
Normal file
36
helpapp/soap-service/src/main/resources/countries.xsd
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://spring.io/guides/gs-producing-web-service"
|
||||||
|
targetNamespace="http://spring.io/guides/gs-producing-web-service" elementFormDefault="qualified">
|
||||||
|
|
||||||
|
<xs:element name="getCountryRequest">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="name" type="xs:string"/>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="getCountryResponse">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="country" type="tns:country"/>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:complexType name="country">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="name" type="xs:string"/>
|
||||||
|
<xs:element name="population" type="xs:int"/>
|
||||||
|
<xs:element name="capital" type="xs:string"/>
|
||||||
|
<xs:element name="currency" type="tns:currency"/>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
|
||||||
|
<xs:simpleType name="currency">
|
||||||
|
<xs:restriction base="xs:string">
|
||||||
|
<xs:enumeration value="GBP"/>
|
||||||
|
<xs:enumeration value="EUR"/>
|
||||||
|
<xs:enumeration value="PLN"/>
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
</xs:schema>
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1 +0,0 @@
|
||||||
server.port=8081
|
|
Binary file not shown.
|
@ -1,5 +1,3 @@
|
||||||
#Generated by Maven
|
artifactId=producing-web-service-complete
|
||||||
#Tue Dec 10 16:22:57 CET 2024
|
groupId=com.example
|
||||||
artifactId=soap-service
|
version=0.0.1-SNAPSHOT
|
||||||
groupId=insa.application.helpapp
|
|
||||||
version=1.0-SNAPSHOT
|
|
||||||
|
|
|
@ -1 +1,10 @@
|
||||||
insa/application/helpapp/soap/SoapApplication.class
|
com/example/producingwebservice/ProducingWebServiceApplication.class
|
||||||
|
com/example/producingwebservice/WebServiceConfig.class
|
||||||
|
com/example/producingwebservice/CountryRepository.class
|
||||||
|
io/spring/guides/gs_producing_web_service/GetCountryResponse.class
|
||||||
|
io/spring/guides/gs_producing_web_service/package-info.class
|
||||||
|
com/example/producingwebservice/CountryEndpoint.class
|
||||||
|
io/spring/guides/gs_producing_web_service/GetCountryRequest.class
|
||||||
|
io/spring/guides/gs_producing_web_service/ObjectFactory.class
|
||||||
|
io/spring/guides/gs_producing_web_service/Currency.class
|
||||||
|
io/spring/guides/gs_producing_web_service/Country.class
|
||||||
|
|
|
@ -1 +1,10 @@
|
||||||
/home/robin/Desktop/helpapp/soap-service/src/main/java/insa/application/helpapp/soap/SoapApplication.java
|
/home/yoboujon/Documents/GEI/service-architecture/helpapp/soap-service/src/main/java/com/example/producingwebservice/CountryEndpoint.java
|
||||||
|
/home/yoboujon/Documents/GEI/service-architecture/helpapp/soap-service/src/main/java/com/example/producingwebservice/CountryRepository.java
|
||||||
|
/home/yoboujon/Documents/GEI/service-architecture/helpapp/soap-service/src/main/java/com/example/producingwebservice/ProducingWebServiceApplication.java
|
||||||
|
/home/yoboujon/Documents/GEI/service-architecture/helpapp/soap-service/src/main/java/com/example/producingwebservice/WebServiceConfig.java
|
||||||
|
/home/yoboujon/Documents/GEI/service-architecture/helpapp/soap-service/target/generated-sources/jaxb/io/spring/guides/gs_producing_web_service/Country.java
|
||||||
|
/home/yoboujon/Documents/GEI/service-architecture/helpapp/soap-service/target/generated-sources/jaxb/io/spring/guides/gs_producing_web_service/Currency.java
|
||||||
|
/home/yoboujon/Documents/GEI/service-architecture/helpapp/soap-service/target/generated-sources/jaxb/io/spring/guides/gs_producing_web_service/GetCountryRequest.java
|
||||||
|
/home/yoboujon/Documents/GEI/service-architecture/helpapp/soap-service/target/generated-sources/jaxb/io/spring/guides/gs_producing_web_service/GetCountryResponse.java
|
||||||
|
/home/yoboujon/Documents/GEI/service-architecture/helpapp/soap-service/target/generated-sources/jaxb/io/spring/guides/gs_producing_web_service/ObjectFactory.java
|
||||||
|
/home/yoboujon/Documents/GEI/service-architecture/helpapp/soap-service/target/generated-sources/jaxb/io/spring/guides/gs_producing_web_service/package-info.java
|
||||||
|
|
Binary file not shown.
Loading…
Add table
Reference in a new issue