From 93988220ea335fc7269dcb2d8d46563c3908f0dc Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Tue, 22 Aug 2023 16:13:03 +0530 Subject: [PATCH] JAVA-20617 Migrated spring-soap to JDK 17 (#14413) --- pom.xml | 4 +- spring-soap/.gitignore | 2 + spring-soap/pom.xml | 29 +++- .../baeldung/springsoap/CountryEndpoint.java | 4 +- .../springsoap/CountryRepository.java | 11 +- .../baeldung/springsoap/WebServiceConfig.java | 4 +- .../springsoap/client/gen/Country.java | 139 ------------------ .../springsoap/client/gen/Currency.java | 40 ----- .../client/gen/GetCountryRequest.java | 64 -------- .../client/gen/GetCountryResponse.java | 64 -------- .../springsoap/client/gen/ObjectFactory.java | 56 ------- .../springsoap/client/gen/package-info.java | 2 - .../ApplicationIntegrationTest.java | 14 +- 13 files changed, 50 insertions(+), 383 deletions(-) delete mode 100644 spring-soap/src/main/java/com/baeldung/springsoap/client/gen/Country.java delete mode 100644 spring-soap/src/main/java/com/baeldung/springsoap/client/gen/Currency.java delete mode 100644 spring-soap/src/main/java/com/baeldung/springsoap/client/gen/GetCountryRequest.java delete mode 100644 spring-soap/src/main/java/com/baeldung/springsoap/client/gen/GetCountryResponse.java delete mode 100644 spring-soap/src/main/java/com/baeldung/springsoap/client/gen/ObjectFactory.java delete mode 100644 spring-soap/src/main/java/com/baeldung/springsoap/client/gen/package-info.java diff --git a/pom.xml b/pom.xml index fa35813c11..f06cd438f8 100644 --- a/pom.xml +++ b/pom.xml @@ -427,7 +427,6 @@ spring-security-modules/spring-security-ldap - spring-soap spring-swagger-codegen video-tutorials @@ -594,7 +593,6 @@ spring-security-modules/spring-security-ldap - spring-soap spring-swagger-codegen video-tutorials @@ -908,6 +906,7 @@ spring-kafka spring-native + spring-soap spring-security-modules spring-protobuf spring-quartz @@ -1180,6 +1179,7 @@ spring-kafka spring-native + spring-soap spring-security-modules spring-protobuf spring-quartz diff --git a/spring-soap/.gitignore b/spring-soap/.gitignore index cce17abdb9..2b04fd0719 100644 --- a/spring-soap/.gitignore +++ b/spring-soap/.gitignore @@ -1,2 +1,4 @@ /target/ sun-jaxb.episode + +**/gen/** \ No newline at end of file diff --git a/spring-soap/pom.xml b/spring-soap/pom.xml index 8188178d61..594eb3dd19 100644 --- a/spring-soap/pom.xml +++ b/spring-soap/pom.xml @@ -30,6 +30,22 @@ spring-boot-starter-test test + + + jakarta.xml.bind + jakarta.xml.bind-api + 4.0.0 + + + + org.glassfish.jaxb + jaxb-runtime + + + + javax.xml.bind + jaxb-api + @@ -42,7 +58,7 @@ org.codehaus.mojo jaxb2-maven-plugin - 1.6 + 3.1.0 xjc @@ -52,8 +68,10 @@ - ${project.basedir}/src/main/resources/ - ${project.basedir}/src/main/java + + src/main/resources/countries.xsd + + src/main/java false @@ -61,7 +79,7 @@ org.jvnet.jaxb2.maven2 maven-jaxb2-plugin - 0.14.0 + 0.15.3 @@ -83,4 +101,7 @@ + + 17 + \ No newline at end of file diff --git a/spring-soap/src/main/java/com/baeldung/springsoap/CountryEndpoint.java b/spring-soap/src/main/java/com/baeldung/springsoap/CountryEndpoint.java index 745131767a..49020cec21 100644 --- a/spring-soap/src/main/java/com/baeldung/springsoap/CountryEndpoint.java +++ b/spring-soap/src/main/java/com/baeldung/springsoap/CountryEndpoint.java @@ -1,12 +1,14 @@ package com.baeldung.springsoap; -import com.baeldung.springsoap.gen.*; 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 com.baeldung.springsoap.client.gen.GetCountryRequest; +import com.baeldung.springsoap.client.gen.GetCountryResponse; + @Endpoint public class CountryEndpoint { diff --git a/spring-soap/src/main/java/com/baeldung/springsoap/CountryRepository.java b/spring-soap/src/main/java/com/baeldung/springsoap/CountryRepository.java index 8a0f58a64e..183027cdb6 100644 --- a/spring-soap/src/main/java/com/baeldung/springsoap/CountryRepository.java +++ b/spring-soap/src/main/java/com/baeldung/springsoap/CountryRepository.java @@ -1,12 +1,15 @@ package com.baeldung.springsoap; -import com.baeldung.springsoap.gen.*; +import java.util.HashMap; +import java.util.Map; + +import javax.annotation.PostConstruct; + import org.springframework.stereotype.Component; import org.springframework.util.Assert; -import javax.annotation.PostConstruct; -import java.util.HashMap; -import java.util.Map; +import com.baeldung.springsoap.client.gen.Country; +import com.baeldung.springsoap.client.gen.Currency; @Component public class CountryRepository { diff --git a/spring-soap/src/main/java/com/baeldung/springsoap/WebServiceConfig.java b/spring-soap/src/main/java/com/baeldung/springsoap/WebServiceConfig.java index 930a961208..57636e9891 100644 --- a/spring-soap/src/main/java/com/baeldung/springsoap/WebServiceConfig.java +++ b/spring-soap/src/main/java/com/baeldung/springsoap/WebServiceConfig.java @@ -17,11 +17,11 @@ import org.springframework.xml.xsd.XsdSchema; public class WebServiceConfig extends WsConfigurerAdapter { @Bean - public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) { + public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) { MessageDispatcherServlet servlet = new MessageDispatcherServlet(); servlet.setApplicationContext(applicationContext); servlet.setTransformWsdlLocations(true); - return new ServletRegistrationBean(servlet, "/ws/*"); + return new ServletRegistrationBean<>(servlet, "/ws/*"); } @Bean(name = "countries") diff --git a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/Country.java b/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/Country.java deleted file mode 100644 index bb196d625d..0000000000 --- a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/Country.java +++ /dev/null @@ -1,139 +0,0 @@ - -package com.baeldung.springsoap.client.gen; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlSchemaType; -import javax.xml.bind.annotation.XmlType; - - -/** - *

Java class for country complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

- * <complexType name="country">
- *   <complexContent>
- *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       <sequence>
- *         <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
- *         <element name="population" type="{http://www.w3.org/2001/XMLSchema}int"/>
- *         <element name="capital" type="{http://www.w3.org/2001/XMLSchema}string"/>
- *         <element name="currency" type="{http://www.baeldung.com/springsoap/gen}currency"/>
- *       </sequence>
- *     </restriction>
- *   </complexContent>
- * </complexType>
- * 
- * - * - */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "country", propOrder = { - "name", - "population", - "capital", - "currency" -}) -public class Country { - - @XmlElement(required = true) - protected String name; - protected int population; - @XmlElement(required = true) - protected String capital; - @XmlElement(required = true) - @XmlSchemaType(name = "string") - protected Currency currency; - - /** - * Gets the value of the name property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getName() { - return name; - } - - /** - * Sets the value of the name property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setName(String value) { - this.name = value; - } - - /** - * Gets the value of the population property. - * - */ - public int getPopulation() { - return population; - } - - /** - * Sets the value of the population property. - * - */ - public void setPopulation(int value) { - this.population = value; - } - - /** - * Gets the value of the capital property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getCapital() { - return capital; - } - - /** - * Sets the value of the capital property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setCapital(String value) { - this.capital = value; - } - - /** - * Gets the value of the currency property. - * - * @return - * possible object is - * {@link Currency } - * - */ - public Currency getCurrency() { - return currency; - } - - /** - * Sets the value of the currency property. - * - * @param value - * allowed object is - * {@link Currency } - * - */ - public void setCurrency(Currency value) { - this.currency = value; - } - -} diff --git a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/Currency.java b/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/Currency.java deleted file mode 100644 index 023a8103e5..0000000000 --- a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/Currency.java +++ /dev/null @@ -1,40 +0,0 @@ - -package com.baeldung.springsoap.client.gen; - -import javax.xml.bind.annotation.XmlEnum; -import javax.xml.bind.annotation.XmlType; - - -/** - *

Java class for currency. - * - *

The following schema fragment specifies the expected content contained within this class. - *

- *

- * <simpleType name="currency">
- *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
- *     <enumeration value="GBP"/>
- *     <enumeration value="EUR"/>
- *     <enumeration value="PLN"/>
- *   </restriction>
- * </simpleType>
- * 
- * - */ -@XmlType(name = "currency") -@XmlEnum -public enum Currency { - - GBP, - EUR, - PLN; - - public String value() { - return name(); - } - - public static Currency fromValue(String v) { - return valueOf(v); - } - -} diff --git a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/GetCountryRequest.java b/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/GetCountryRequest.java deleted file mode 100644 index dcd5b1f08b..0000000000 --- a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/GetCountryRequest.java +++ /dev/null @@ -1,64 +0,0 @@ - -package com.baeldung.springsoap.client.gen; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - - -/** - *

Java class for anonymous complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

- * <complexType>
- *   <complexContent>
- *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       <sequence>
- *         <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
- *       </sequence>
- *     </restriction>
- *   </complexContent>
- * </complexType>
- * 
- * - * - */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "", propOrder = { - "name" -}) -@XmlRootElement(name = "getCountryRequest") -public class GetCountryRequest { - - @XmlElement(required = true) - protected String name; - - /** - * Gets the value of the name property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getName() { - return name; - } - - /** - * Sets the value of the name property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setName(String value) { - this.name = value; - } - -} diff --git a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/GetCountryResponse.java b/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/GetCountryResponse.java deleted file mode 100644 index 11135c32e1..0000000000 --- a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/GetCountryResponse.java +++ /dev/null @@ -1,64 +0,0 @@ - -package com.baeldung.springsoap.client.gen; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - - -/** - *

Java class for anonymous complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

- * <complexType>
- *   <complexContent>
- *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       <sequence>
- *         <element name="country" type="{http://www.baeldung.com/springsoap/gen}country"/>
- *       </sequence>
- *     </restriction>
- *   </complexContent>
- * </complexType>
- * 
- * - * - */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "", propOrder = { - "country" -}) -@XmlRootElement(name = "getCountryResponse") -public class GetCountryResponse { - - @XmlElement(required = true) - protected Country country; - - /** - * Gets the value of the country property. - * - * @return - * possible object is - * {@link Country } - * - */ - public Country getCountry() { - return country; - } - - /** - * Sets the value of the country property. - * - * @param value - * allowed object is - * {@link Country } - * - */ - public void setCountry(Country value) { - this.country = value; - } - -} diff --git a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/ObjectFactory.java b/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/ObjectFactory.java deleted file mode 100644 index e6d56d5aba..0000000000 --- a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/ObjectFactory.java +++ /dev/null @@ -1,56 +0,0 @@ - -package com.baeldung.springsoap.client.gen; - -import javax.xml.bind.annotation.XmlRegistry; - - -/** - * This object contains factory methods for each - * Java content interface and Java element interface - * generated in the com.baeldung.springsoap.client.gen package. - *

An ObjectFactory allows you to programatically - * construct new instances of the Java representation - * for XML content. The Java representation of XML - * content can consist of schema derived interfaces - * and classes representing the binding of schema - * type definitions, element declarations and model - * groups. Factory methods for each of these are - * provided in this class. - * - */ -@XmlRegistry -public class ObjectFactory { - - - /** - * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.baeldung.springsoap.client.gen - * - */ - public ObjectFactory() { - } - - /** - * Create an instance of {@link GetCountryRequest } - * - */ - public GetCountryRequest createGetCountryRequest() { - return new GetCountryRequest(); - } - - /** - * Create an instance of {@link GetCountryResponse } - * - */ - public GetCountryResponse createGetCountryResponse() { - return new GetCountryResponse(); - } - - /** - * Create an instance of {@link Country } - * - */ - public Country createCountry() { - return new Country(); - } - -} diff --git a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/package-info.java b/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/package-info.java deleted file mode 100644 index 9432e0c328..0000000000 --- a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/package-info.java +++ /dev/null @@ -1,2 +0,0 @@ -@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.baeldung.com/springsoap/gen", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) -package com.baeldung.springsoap.client.gen; diff --git a/spring-soap/src/test/java/com/baeldung/springsoap/ApplicationIntegrationTest.java b/spring-soap/src/test/java/com/baeldung/springsoap/ApplicationIntegrationTest.java index 3b071c286f..1150b8d91b 100644 --- a/spring-soap/src/test/java/com/baeldung/springsoap/ApplicationIntegrationTest.java +++ b/spring-soap/src/test/java/com/baeldung/springsoap/ApplicationIntegrationTest.java @@ -1,18 +1,19 @@ package com.baeldung.springsoap; -import com.baeldung.springsoap.gen.GetCountryRequest; +import static org.assertj.core.api.Assertions.assertThat; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.oxm.jaxb.Jaxb2Marshaller; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.ClassUtils; import org.springframework.ws.client.core.WebServiceTemplate; -import static org.assertj.core.api.Assertions.assertThat; +import com.baeldung.springsoap.client.gen.GetCountryRequest; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @@ -20,7 +21,8 @@ public class ApplicationIntegrationTest { private Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); - @LocalServerPort private int port = 0; + @LocalServerPort + private int port = 0; @Before public void init() throws Exception { @@ -34,6 +36,8 @@ public class ApplicationIntegrationTest { GetCountryRequest request = new GetCountryRequest(); request.setName("Spain"); - assertThat(ws.marshalSendAndReceive("http://localhost:" + port + "/ws", request)).isNotNull(); + Object response = ws.marshalSendAndReceive("http://localhost:" + port + "/ws", request); + + assertThat(response).isNotNull(); } }