Skip to content
Open

init #66

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"configurations": [
{
"type": "java",
"name": "Spring Boot-ConsumingWebServiceApplication<consuming-web-service-initial>",
"request": "launch",
"cwd": "${workspaceFolder}",
"mainClass": "com.example.consumingwebservice.ConsumingWebServiceApplication",
"projectName": "consuming-web-service-initial",
"args": "",
"envFile": "${workspaceFolder}/.env"
}
]
}
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"java.compile.nullAnalysis.mode": "automatic",
"java.configuration.updateBuildConfiguration": "interactive"
}
1 change: 1 addition & 0 deletions complete/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<version>3.0.0</version>
<executions>
<execution>
<?m2e execute onConfiguration?>
<goals>
<goal>wsimport</goal>
</goals>
Expand Down
46 changes: 43 additions & 3 deletions initial/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,34 @@
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>consuming-web-service-initial</artifactId>
<artifactId>consuming-web-service-complete</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>consuming-web-service-initial</name>
<name>consuming-web-service-complete</name>
<description>Demo project for Spring Boot</description>

<properties>
<java.version>17</java.version>
</properties>

<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<!-- tag::dependency[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- end::dependency[] -->

<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -35,7 +51,31 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- tag::wsdl[] -->
<plugin>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<?m2e execute onConfiguration?>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<packageName>com.example.consumingwebservice.wsdl</packageName>
<wsdlUrls>
<wsdlUrl>http://localhost:8080/ws/countries.wsdl</wsdlUrl>
</wsdlUrls>
<sourceDestDir>${sourcesDir}</sourceDestDir>
<destDir>${classesDir}</destDir>
<extension>true</extension>
</configuration>
</plugin>
<!-- end::wsdl[] -->
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
@@ -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());
};
}

}
}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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 <generatePackage> 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;
}

}