Skip to content

Commit f365db2

Browse files
authored
BAEL-4983: Update article "Calling SOAP service in Java" (eugenp#10898)
1 parent b61e9b7 commit f365db2

13 files changed

Lines changed: 534 additions & 0 deletions

File tree

core-java-modules/core-java-11-2/pom.xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,23 @@
5555
<artifactId>commons-lang3</artifactId>
5656
<version>${commons-lang3.version}</version>
5757
</dependency>
58+
<dependency>
59+
<groupId>jakarta.xml.ws</groupId>
60+
<artifactId>jakarta.xml.ws-api</artifactId>
61+
<version>${jakarta.ws-api.version}</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>com.sun.xml.ws</groupId>
65+
<artifactId>jaxws-rt</artifactId>
66+
<version>${jaxws-rt.version}</version>
67+
<scope>runtime</scope>
68+
</dependency>
69+
<dependency>
70+
<groupId>com.sun.xml.ws</groupId>
71+
<artifactId>jaxws-ri</artifactId>
72+
<version>${jaxws-ri.version}</version>
73+
<type>pom</type>
74+
</dependency>
5875
</dependencies>
5976

6077
<build>
@@ -68,6 +85,20 @@
6885
<target>${maven.compiler.target.version}</target>
6986
</configuration>
7087
</plugin>
88+
<!-- jax-ws maven plugin -->
89+
<plugin>
90+
<groupId>com.sun.xml.ws</groupId>
91+
<artifactId>jaxws-maven-plugin</artifactId>
92+
<version>${jaxws-maven-plugin.version}</version>
93+
<configuration>
94+
<wsdlUrls>
95+
<wsdlUrl>http://localhost:8888/ws/country?wsdl</wsdlUrl>
96+
</wsdlUrls>
97+
<keep>true</keep>
98+
<packageName>com.baeldung.soap.ws.client.generated</packageName>
99+
<sourceDestDir>src/main/java</sourceDestDir>
100+
</configuration>
101+
</plugin>
71102
</plugins>
72103
</build>
73104

@@ -79,6 +110,10 @@
79110
<assertj.version>3.17.2</assertj.version>
80111
<mockserver.version>5.11.1</mockserver.version>
81112
<commons-lang3.version>3.12.0</commons-lang3.version>
113+
<jakarta.ws-api.version>3.0.0</jakarta.ws-api.version>
114+
<jaxws-rt.version>3.0.0</jaxws-rt.version>
115+
<jaxws-ri.version>2.3.1</jaxws-ri.version>
116+
<jaxws-maven-plugin.version>2.3.2</jaxws-maven-plugin.version>
82117
</properties>
83118

84119
</project>
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
2+
package com.baeldung.soap.ws.client.generated;
3+
4+
import javax.xml.bind.annotation.XmlAccessType;
5+
import javax.xml.bind.annotation.XmlAccessorType;
6+
import javax.xml.bind.annotation.XmlSchemaType;
7+
import javax.xml.bind.annotation.XmlType;
8+
9+
10+
/**
11+
* <p>Java class for country complex type.
12+
*
13+
* <p>The following schema fragment specifies the expected content contained within this class.
14+
*
15+
* <pre>
16+
* &lt;complexType name="country"&gt;
17+
* &lt;complexContent&gt;
18+
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
19+
* &lt;sequence&gt;
20+
* &lt;element name="capital" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
21+
* &lt;element name="currency" type="{http://server.ws.soap.baeldung.com/}currency" minOccurs="0"/&gt;
22+
* &lt;element name="name" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
23+
* &lt;element name="population" type="{http://www.w3.org/2001/XMLSchema}int"/&gt;
24+
* &lt;/sequence&gt;
25+
* &lt;/restriction&gt;
26+
* &lt;/complexContent&gt;
27+
* &lt;/complexType&gt;
28+
* </pre>
29+
*
30+
*
31+
*/
32+
@XmlAccessorType(XmlAccessType.FIELD)
33+
@XmlType(name = "country", propOrder = {
34+
"capital",
35+
"currency",
36+
"name",
37+
"population"
38+
})
39+
public class Country {
40+
41+
protected String capital;
42+
@XmlSchemaType(name = "string")
43+
protected Currency currency;
44+
protected String name;
45+
protected int population;
46+
47+
/**
48+
* Gets the value of the capital property.
49+
*
50+
* @return
51+
* possible object is
52+
* {@link String }
53+
*
54+
*/
55+
public String getCapital() {
56+
return capital;
57+
}
58+
59+
/**
60+
* Sets the value of the capital property.
61+
*
62+
* @param value
63+
* allowed object is
64+
* {@link String }
65+
*
66+
*/
67+
public void setCapital(String value) {
68+
this.capital = value;
69+
}
70+
71+
/**
72+
* Gets the value of the currency property.
73+
*
74+
* @return
75+
* possible object is
76+
* {@link Currency }
77+
*
78+
*/
79+
public Currency getCurrency() {
80+
return currency;
81+
}
82+
83+
/**
84+
* Sets the value of the currency property.
85+
*
86+
* @param value
87+
* allowed object is
88+
* {@link Currency }
89+
*
90+
*/
91+
public void setCurrency(Currency value) {
92+
this.currency = value;
93+
}
94+
95+
/**
96+
* Gets the value of the name property.
97+
*
98+
* @return
99+
* possible object is
100+
* {@link String }
101+
*
102+
*/
103+
public String getName() {
104+
return name;
105+
}
106+
107+
/**
108+
* Sets the value of the name property.
109+
*
110+
* @param value
111+
* allowed object is
112+
* {@link String }
113+
*
114+
*/
115+
public void setName(String value) {
116+
this.name = value;
117+
}
118+
119+
/**
120+
* Gets the value of the population property.
121+
*
122+
*/
123+
public int getPopulation() {
124+
return population;
125+
}
126+
127+
/**
128+
* Sets the value of the population property.
129+
*
130+
*/
131+
public void setPopulation(int value) {
132+
this.population = value;
133+
}
134+
135+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
package com.baeldung.soap.ws.client.generated;
3+
4+
import javax.jws.WebMethod;
5+
import javax.jws.WebParam;
6+
import javax.jws.WebResult;
7+
import javax.jws.WebService;
8+
import javax.jws.soap.SOAPBinding;
9+
import javax.xml.bind.annotation.XmlSeeAlso;
10+
import javax.xml.ws.Action;
11+
12+
13+
/**
14+
* This class was generated by the JAX-WS RI.
15+
* JAX-WS RI 2.3.2
16+
* Generated source version: 2.2
17+
*
18+
*/
19+
@WebService(name = "CountryService", targetNamespace = "http://server.ws.soap.baeldung.com/")
20+
@SOAPBinding(style = SOAPBinding.Style.RPC)
21+
@XmlSeeAlso({
22+
ObjectFactory.class
23+
})
24+
public interface CountryService {
25+
26+
27+
/**
28+
*
29+
* @param arg0
30+
* @return
31+
* returns com.baeldung.soap.ws.client.generated.Country
32+
*/
33+
@WebMethod
34+
@WebResult(partName = "return")
35+
@Action(input = "http://server.ws.soap.baeldung.com/CountryService/findByNameRequest", output = "http://server.ws.soap.baeldung.com/CountryService/findByNameResponse")
36+
public Country findByName(
37+
@WebParam(name = "arg0", partName = "arg0")
38+
String arg0);
39+
40+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
2+
package com.baeldung.soap.ws.client.generated;
3+
4+
import java.net.MalformedURLException;
5+
import java.net.URL;
6+
import javax.xml.namespace.QName;
7+
import javax.xml.ws.Service;
8+
import javax.xml.ws.WebEndpoint;
9+
import javax.xml.ws.WebServiceClient;
10+
import javax.xml.ws.WebServiceException;
11+
import javax.xml.ws.WebServiceFeature;
12+
13+
14+
/**
15+
* This class was generated by the JAX-WS RI.
16+
* JAX-WS RI 2.3.2
17+
* Generated source version: 2.2
18+
*
19+
*/
20+
@WebServiceClient(name = "CountryServiceImplService", targetNamespace = "http://server.ws.soap.baeldung.com/", wsdlLocation = "http://localhost:8888/ws/country?wsdl")
21+
public class CountryServiceImplService
22+
extends Service
23+
{
24+
25+
private final static URL COUNTRYSERVICEIMPLSERVICE_WSDL_LOCATION;
26+
private final static WebServiceException COUNTRYSERVICEIMPLSERVICE_EXCEPTION;
27+
private final static QName COUNTRYSERVICEIMPLSERVICE_QNAME = new QName("http://server.ws.soap.baeldung.com/", "CountryServiceImplService");
28+
29+
static {
30+
URL url = null;
31+
WebServiceException e = null;
32+
try {
33+
url = new URL("http://localhost:8888/ws/country?wsdl");
34+
} catch (MalformedURLException ex) {
35+
e = new WebServiceException(ex);
36+
}
37+
COUNTRYSERVICEIMPLSERVICE_WSDL_LOCATION = url;
38+
COUNTRYSERVICEIMPLSERVICE_EXCEPTION = e;
39+
}
40+
41+
public CountryServiceImplService() {
42+
super(__getWsdlLocation(), COUNTRYSERVICEIMPLSERVICE_QNAME);
43+
}
44+
45+
public CountryServiceImplService(WebServiceFeature... features) {
46+
super(__getWsdlLocation(), COUNTRYSERVICEIMPLSERVICE_QNAME, features);
47+
}
48+
49+
public CountryServiceImplService(URL wsdlLocation) {
50+
super(wsdlLocation, COUNTRYSERVICEIMPLSERVICE_QNAME);
51+
}
52+
53+
public CountryServiceImplService(URL wsdlLocation, WebServiceFeature... features) {
54+
super(wsdlLocation, COUNTRYSERVICEIMPLSERVICE_QNAME, features);
55+
}
56+
57+
public CountryServiceImplService(URL wsdlLocation, QName serviceName) {
58+
super(wsdlLocation, serviceName);
59+
}
60+
61+
public CountryServiceImplService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
62+
super(wsdlLocation, serviceName, features);
63+
}
64+
65+
/**
66+
*
67+
* @return
68+
* returns CountryService
69+
*/
70+
@WebEndpoint(name = "CountryServiceImplPort")
71+
public CountryService getCountryServiceImplPort() {
72+
return super.getPort(new QName("http://server.ws.soap.baeldung.com/", "CountryServiceImplPort"), CountryService.class);
73+
}
74+
75+
/**
76+
*
77+
* @param features
78+
* A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
79+
* @return
80+
* returns CountryService
81+
*/
82+
@WebEndpoint(name = "CountryServiceImplPort")
83+
public CountryService getCountryServiceImplPort(WebServiceFeature... features) {
84+
return super.getPort(new QName("http://server.ws.soap.baeldung.com/", "CountryServiceImplPort"), CountryService.class, features);
85+
}
86+
87+
private static URL __getWsdlLocation() {
88+
if (COUNTRYSERVICEIMPLSERVICE_EXCEPTION!= null) {
89+
throw COUNTRYSERVICEIMPLSERVICE_EXCEPTION;
90+
}
91+
return COUNTRYSERVICEIMPLSERVICE_WSDL_LOCATION;
92+
}
93+
94+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
package com.baeldung.soap.ws.client.generated;
3+
4+
import javax.xml.bind.annotation.XmlEnum;
5+
import javax.xml.bind.annotation.XmlType;
6+
7+
8+
/**
9+
* <p>Java class for currency.
10+
*
11+
* <p>The following schema fragment specifies the expected content contained within this class.
12+
* <p>
13+
* <pre>
14+
* &lt;simpleType name="currency"&gt;
15+
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}string"&gt;
16+
* &lt;enumeration value="EUR"/&gt;
17+
* &lt;enumeration value="INR"/&gt;
18+
* &lt;enumeration value="USD"/&gt;
19+
* &lt;/restriction&gt;
20+
* &lt;/simpleType&gt;
21+
* </pre>
22+
*
23+
*/
24+
@XmlType(name = "currency")
25+
@XmlEnum
26+
public enum Currency {
27+
28+
EUR,
29+
INR,
30+
USD;
31+
32+
public String value() {
33+
return name();
34+
}
35+
36+
public static Currency fromValue(String v) {
37+
return valueOf(v);
38+
}
39+
40+
}

0 commit comments

Comments
 (0)