* BAEL-5298

* Renamed the tests

* Changed the Parent to parent-boot-2

Co-authored-by: Bhaskara Navuluri <bhaskara.navuluri@hpe.com>
This commit is contained in:
Bhaskara
2022-03-28 20:45:16 +05:30
committed by GitHub
parent 0c229c433f
commit 8f2cc51af4
10 changed files with 376 additions and 42 deletions
@@ -0,0 +1,14 @@
package com.baeldung.feign.soap;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class FeignSoapApplication {
public static void main(String[] args) {
SpringApplication.run(FeignSoapApplication.class, args);
}
}
@@ -0,0 +1,14 @@
package com.baeldung.feign.soap;
import feign.Headers;
import feign.RequestLine;
public interface SoapClient {
@RequestLine("POST")
@Headers({"SOAPAction: createUser", "Content-Type: text/xml;charset=UTF-8", "Accept: text/xml"})
String createUserWithPlainText(String soapBody);
@RequestLine("POST")
@Headers({"Content-Type: text/xml;charset=UTF-8"})
CreateUserResponse createUserWithSoap(CreateUserRequest soapBody);
}
@@ -0,0 +1,36 @@
package com.baeldung.feign.soap;
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 java.util.HashMap;
import java.util.Map;
@Endpoint
public class UsersEndpoint {
private static final Map<String, User> userMap = new HashMap<>();
@PayloadRoot(namespace = "http://www.baeldung.com/springbootsoap/feignclient", localPart = "getUserRequest")
@ResponsePayload
public GetUserResponse getUser(@RequestPayload GetUserRequest request) {
GetUserResponse response = new GetUserResponse();
response.setUser(userMap.get(request.getId()));
return response;
}
@PayloadRoot(namespace = "http://www.baeldung.com/springbootsoap/feignclient", localPart = "createUserRequest")
@ResponsePayload
public CreateUserResponse createUser(@RequestPayload CreateUserRequest request) {
CreateUserResponse response = new CreateUserResponse();
if (request.getUser().getId().equalsIgnoreCase("500"))
throw new RuntimeException("This is a reserved user id");
userMap.put(request.getUser().id, request.getUser());
response.setMessage("Success! Created the user with id - " + request.getUser().getId());
return response;
}
}
@@ -0,0 +1,52 @@
package com.baeldung.feign.soap;
import org.springframework.beans.factory.annotation.Value;
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 WebServicesConfiguration extends WsConfigurerAdapter {
@Value("${ws.api.path:/ws/api/v1/*}")
private String webserviceApiPath;
@Value("${ws.port.type.name:UsersPort}")
private String webservicePortTypeName;
@Value("${ws.target.namespace:http://www.baeldung.com/springbootsoap/feignclient}")
private String webserviceTargetNamespace;
@Value("${ws.location.uri:http://localhost:18080/ws/api/v1/}")
private String locationUri;
@Bean
public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean<>(servlet, webserviceApiPath);
}
@Bean(name = "users")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema usersSchema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName(webservicePortTypeName);
wsdl11Definition.setTargetNamespace(webserviceTargetNamespace);
wsdl11Definition.setLocationUri(locationUri);
wsdl11Definition.setSchema(usersSchema);
return wsdl11Definition;
}
@Bean
public XsdSchema userSchema() {
return new SimpleXsdSchema(new ClassPathResource("users.xsd"));
}
}
@@ -0,0 +1,7 @@
server.port=18080
# Custom properties begin here
ws.api.path=/ws/users/*
ws.port.type.name=UsersPort
ws.target.namespace=http://www.baeldung.com/springbootsoap/feignclient
ws.location.uri=http://localhost:${server.port}/ws/users/
debug=false
+44
View File
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.baeldung.com/springbootsoap/feignclient"
targetNamespace="http://www.baeldung.com/springbootsoap/feignclient" elementFormDefault="qualified">
<xs:element name="getUserRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getUserResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="user" type="tns:user"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="createUserRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="user" type="tns:user"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="createUserResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="message" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- Define the complex object Product -->
<xs:complexType name="user">
<xs:sequence>
<xs:element name="id" type="xs:string"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="email" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>