From 13a5008ad3d8acc34af5789ded1d2f71cb34d521 Mon Sep 17 00:00:00 2001 From: meselfi Date: Sat, 2 Mar 2019 15:00:50 +0100 Subject: [PATCH] init --- pom.xml | 128 ++++++++++++++++++ .../ws/CustomerServiceClient.java | 17 +++ .../ws/CustomerServiceConfiguration.java | 35 +++++ src/main/schemas/Customer.xsd | 19 +++ src/main/schemas/CustomerID.xsd | 5 + src/main/schemas/CustomerService.wsdl | 51 +++++++ src/main/schemas/GetCustomerRequest.xsd | 14 ++ src/main/schemas/GetCustomerResponse.xsd | 14 ++ .../serviceclient/CustomerServiceTest.java | 48 +++++++ .../soapui/CustomerService-soapui-project.xml | 90 ++++++++++++ 10 files changed, 421 insertions(+) create mode 100644 pom.xml create mode 100644 src/main/java/com/sorenpoulsen/ws/CustomerServiceClient.java create mode 100644 src/main/java/com/sorenpoulsen/ws/CustomerServiceConfiguration.java create mode 100644 src/main/schemas/Customer.xsd create mode 100644 src/main/schemas/CustomerID.xsd create mode 100644 src/main/schemas/CustomerService.wsdl create mode 100644 src/main/schemas/GetCustomerRequest.xsd create mode 100644 src/main/schemas/GetCustomerResponse.xsd create mode 100644 src/test/java/com/sorenpoulsen/serviceclient/CustomerServiceTest.java create mode 100644 src/test/soapui/CustomerService-soapui-project.xml diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..6822027 --- /dev/null +++ b/pom.xml @@ -0,0 +1,128 @@ + + 4.0.0 + + com.sorenpoulsen.ws + SpringWebServiceClient + 0.0.1-SNAPSHOT + jar + + + 1.8 + 1.8 + UTF-8 + + + + + org.springframework.ws + spring-ws-core + 3.0.6.RELEASE + + + org.springframework + spring-test + 5.0.10.RELEASE + test + + + junit + junit + 4.12 + test + + + + + + SmartBearPluginRepository + http://www.soapui.org/repository/maven2/ + + + + + + + + org.codehaus.mojo + jaxb2-maven-plugin + 2.4 + + + + xjc + + + + + wsdl + + src/main/schemas/CustomerService.wsdl + + + + + + org.sonatype.plugins + port-allocator-maven-plugin + 1.2 + + + validate + + allocate-ports + + + + + mockport + + + + + + + + + org.codehaus.mojo + properties-maven-plugin + 1.0.0 + + + generate-resources + + write-project-properties + + + ${project.build.outputDirectory}/test.properties + + + + + + + com.smartbear.soapui + soapui-maven-plugin + 5.4.0 + + + + ${basedir}/src/test/soapui/CustomerService-soapui-project.xml + ${mockport} + /customerservice + CustomerServiceMock + true + + + mock + + process-test-classes + + + + + + + + + diff --git a/src/main/java/com/sorenpoulsen/ws/CustomerServiceClient.java b/src/main/java/com/sorenpoulsen/ws/CustomerServiceClient.java new file mode 100644 index 0000000..d427294 --- /dev/null +++ b/src/main/java/com/sorenpoulsen/ws/CustomerServiceClient.java @@ -0,0 +1,17 @@ +package com.sorenpoulsen.ws; + +import org.springframework.ws.client.core.support.WebServiceGatewaySupport; + +import com.sorenpoulsen.enterprisemodel.Customer; +import com.sorenpoulsen.enterprisemodel.GetCustomer; +import com.sorenpoulsen.enterprisemodel.GetCustomerResponse; + +public class CustomerServiceClient extends WebServiceGatewaySupport { + + public Customer getCustomer(String customerID) { + GetCustomer getCustomer = new GetCustomer(); + getCustomer.setCustomerID(customerID); + GetCustomerResponse response = (GetCustomerResponse)getWebServiceTemplate().marshalSendAndReceive(getCustomer); + return response.getCustomer(); + } +} diff --git a/src/main/java/com/sorenpoulsen/ws/CustomerServiceConfiguration.java b/src/main/java/com/sorenpoulsen/ws/CustomerServiceConfiguration.java new file mode 100644 index 0000000..6857d3a --- /dev/null +++ b/src/main/java/com/sorenpoulsen/ws/CustomerServiceConfiguration.java @@ -0,0 +1,35 @@ +package com.sorenpoulsen.ws; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.oxm.jaxb.Jaxb2Marshaller; +import org.springframework.ws.soap.SoapVersion; +import org.springframework.ws.soap.saaj.SaajSoapMessageFactory; + +@Configuration +public class CustomerServiceConfiguration { + + @Bean + public SaajSoapMessageFactory messageFactory() { + SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory(); + messageFactory.setSoapVersion(SoapVersion.SOAP_12); + return messageFactory; + } + + @Bean + public Jaxb2Marshaller marshaller() { + Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); + marshaller.setContextPath("com.sorenpoulsen.enterprisemodel"); + return marshaller; + } + + @Bean + public CustomerServiceClient customerServiceClient(Jaxb2Marshaller marshaller, + SaajSoapMessageFactory messageFactory) { + CustomerServiceClient customerServiceClient = new CustomerServiceClient(); + customerServiceClient.setMessageFactory(messageFactory); + customerServiceClient.setMarshaller(marshaller); + customerServiceClient.setUnmarshaller(marshaller); + return customerServiceClient; + } +} diff --git a/src/main/schemas/Customer.xsd b/src/main/schemas/Customer.xsd new file mode 100644 index 0000000..40e34aa --- /dev/null +++ b/src/main/schemas/Customer.xsd @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/schemas/CustomerID.xsd b/src/main/schemas/CustomerID.xsd new file mode 100644 index 0000000..3080843 --- /dev/null +++ b/src/main/schemas/CustomerID.xsd @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/src/main/schemas/CustomerService.wsdl b/src/main/schemas/CustomerService.wsdl new file mode 100644 index 0000000..ecd07c2 --- /dev/null +++ b/src/main/schemas/CustomerService.wsdl @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/schemas/GetCustomerRequest.xsd b/src/main/schemas/GetCustomerRequest.xsd new file mode 100644 index 0000000..d604b3a --- /dev/null +++ b/src/main/schemas/GetCustomerRequest.xsd @@ -0,0 +1,14 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/schemas/GetCustomerResponse.xsd b/src/main/schemas/GetCustomerResponse.xsd new file mode 100644 index 0000000..08b5e97 --- /dev/null +++ b/src/main/schemas/GetCustomerResponse.xsd @@ -0,0 +1,14 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/com/sorenpoulsen/serviceclient/CustomerServiceTest.java b/src/test/java/com/sorenpoulsen/serviceclient/CustomerServiceTest.java new file mode 100644 index 0000000..8f06b3a --- /dev/null +++ b/src/test/java/com/sorenpoulsen/serviceclient/CustomerServiceTest.java @@ -0,0 +1,48 @@ +package com.sorenpoulsen.serviceclient; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.sorenpoulsen.enterprisemodel.Customer; +import com.sorenpoulsen.ws.CustomerServiceClient; +import com.sorenpoulsen.ws.CustomerServiceConfiguration; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { CustomerServiceConfiguration.class }) +public class CustomerServiceTest { + + String mockEndpoint; + + @Autowired + CustomerServiceClient customerServiceClient; + + @Before + public void readMockPort() { + Properties p = new Properties(); + try (InputStream is = CustomerServiceTest.class.getResourceAsStream("/test.properties")) { + p.load(is); + } catch (IOException e) { + Assert.fail(); + } + String mockport = p.getProperty("mockport"); + Assert.assertNotNull(mockport); + mockEndpoint = "http://localhost:" + mockport + "/customerservice"; + } + + @Test + public void testCustomerServiceClient() { + customerServiceClient.setDefaultUri(mockEndpoint); + Customer customer = customerServiceClient.getCustomer("1"); + Assert.assertNotNull(customer); + Assert.assertEquals("Orisa", customer.getName()); + } +} diff --git a/src/test/soapui/CustomerService-soapui-project.xml b/src/test/soapui/CustomerService-soapui-project.xml new file mode 100644 index 0000000..5fab6d4 --- /dev/null +++ b/src/test/soapui/CustomerService-soapui-project.xml @@ -0,0 +1,90 @@ + +file:/home/stp/code/SpringWebServiceClient/src/main/schemas/CustomerService.wsdl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +]]>http://schemas.xmlsoap.org/wsdl/file:/home/stp/code/SpringWebServiceClient/src/main/schemas/GetCustomerRequest.xsd + + + + + + + + +]]>http://www.w3.org/2001/XMLSchemafile:/home/stp/code/SpringWebServiceClient/src/main/schemas/CustomerID.xsd<schema targetNamespace="http://sorenpoulsen.com/enterprisemodel" version="1.0" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://sorenpoulsen.com/enterprisemodel"> + <element name="CustomerID" type="token"/> +</schema>http://www.w3.org/2001/XMLSchemafile:/home/stp/code/SpringWebServiceClient/src/main/schemas/GetCustomerResponse.xsd + + + + + + + + +]]>http://www.w3.org/2001/XMLSchemafile:/home/stp/code/SpringWebServiceClient/src/main/schemas/Customer.xsd + + + + + + + + + + + + +]]>http://www.w3.org/2001/XMLSchemahttp://sorenpoulsen.com/customerservice<xml-fragment/>UTF-8http://localhost:8111/customerservice + + + + 1 + + +]]>No AuthorizationfalseResponse 1SEQUENCE + + + + + 1 + Orisa +
Harald Blåtandsvej 3333
+ Frederikssund + DK +
+
+
+]]>
\ No newline at end of file