Commit 95a6ce9e authored by Maciej Walkowiak's avatar Maciej Walkowiak Committed by Andy Wilkinson

Spring Web Services Starter

- upgraded Spring WS to 2.2.0.RELEASE
- replaced default MVC DispatcherServlet with MessageDispatcherServlet
- migrated XML based config with nww Spring WS Java config

Fixes: gh-412
parent e2a449da
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-build</artifactId> <artifactId>spring-boot-build</artifactId>
...@@ -148,20 +149,20 @@ ...@@ -148,20 +149,20 @@
<inherited>false</inherited> <inherited>false</inherited>
<configuration> <configuration>
<target> <target>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" /> <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<taskdef name="stringutil" classname="ise.antelope.tasks.StringUtilTask" /> <taskdef name="stringutil" classname="ise.antelope.tasks.StringUtilTask"/>
<var name="version-type" value="${project.version}" /> <var name="version-type" value="${project.version}"/>
<propertyregex property="version-type" override="true" input="${version-type}" regexp=".*\.(.*)" replace="\1" /> <propertyregex property="version-type" override="true" input="${version-type}" regexp=".*\.(.*)" replace="\1"/>
<propertyregex property="version-type" override="true" input="${version-type}" regexp="(M)\d+" replace="MILESTONE" /> <propertyregex property="version-type" override="true" input="${version-type}" regexp="(M)\d+" replace="MILESTONE"/>
<propertyregex property="version-type" override="true" input="${version-type}" regexp="(RC)\d+" replace="MILESTONE" /> <propertyregex property="version-type" override="true" input="${version-type}" regexp="(RC)\d+" replace="MILESTONE"/>
<propertyregex property="version-type" override="true" input="${version-type}" regexp="BUILD-(.*)" replace="SNAPSHOT" /> <propertyregex property="version-type" override="true" input="${version-type}" regexp="BUILD-(.*)" replace="SNAPSHOT"/>
<stringutil string="${version-type}" property="profile"> <stringutil string="${version-type}" property="profile">
<lowercase /> <lowercase/>
</stringutil> </stringutil>
<echo message="Writing settings for ${profile} profile" /> <echo message="Writing settings for ${profile} profile"/>
<copy file=".settings-template.xml" tofile="settings.xml" overwrite="true"> <copy file=".settings-template.xml" tofile="settings.xml" overwrite="true">
<filterset> <filterset>
<filter token="profile" value="${profile}" /> <filter token="profile" value="${profile}"/>
</filterset> </filterset>
</copy> </copy>
</target> </target>
...@@ -176,7 +177,7 @@ ...@@ -176,7 +177,7 @@
<inherited>false</inherited> <inherited>false</inherited>
<configuration> <configuration>
<target> <target>
<property name="sourceFile" value="spring-boot-dependencies/pom.xml" /> <property name="sourceFile" value="spring-boot-dependencies/pom.xml"/>
<xslt in="${sourceFile}" out="${sourceFile}.new" force="true"> <xslt in="${sourceFile}" out="${sourceFile}.new" force="true">
<style> <style>
<string><![CDATA[ <string><![CDATA[
...@@ -199,9 +200,9 @@ ...@@ -199,9 +200,9 @@
</string> </string>
</style> </style>
</xslt> </xslt>
<move file="${sourceFile}" tofile="${sourceFile}.old" /> <move file="${sourceFile}" tofile="${sourceFile}.old"/>
<move file="${sourceFile}.new" tofile="${sourceFile}" /> <move file="${sourceFile}.new" tofile="${sourceFile}"/>
<delete file="${sourceFile}.old" /> <delete file="${sourceFile}.old"/>
</target> </target>
</configuration> </configuration>
</execution> </execution>
......
...@@ -111,7 +111,7 @@ ...@@ -111,7 +111,7 @@
<spring-social-linkedin.version>1.0.1.RELEASE</spring-social-linkedin.version> <spring-social-linkedin.version>1.0.1.RELEASE</spring-social-linkedin.version>
<spring-security.version>3.2.4.RELEASE</spring-security.version> <spring-security.version>3.2.4.RELEASE</spring-security.version>
<spring-security-jwt.version>1.0.2.RELEASE</spring-security-jwt.version> <spring-security-jwt.version>1.0.2.RELEASE</spring-security-jwt.version>
<spring-ws.version>2.1.4.RELEASE</spring-ws.version> <spring-ws.version>2.2.0.RELEASE</spring-ws.version>
<thymeleaf.version>2.1.3.RELEASE</thymeleaf.version> <thymeleaf.version>2.1.3.RELEASE</thymeleaf.version>
<thymeleaf-extras-springsecurity3.version>2.1.1.RELEASE</thymeleaf-extras-springsecurity3.version> <thymeleaf-extras-springsecurity3.version>2.1.1.RELEASE</thymeleaf-extras-springsecurity3.version>
<thymeleaf-layout-dialect.version>1.2.4</thymeleaf-layout-dialect.version> <thymeleaf-layout-dialect.version>1.2.4</thymeleaf-layout-dialect.version>
...@@ -1066,11 +1066,6 @@ ...@@ -1066,11 +1066,6 @@
<artifactId>spring-social-web</artifactId> <artifactId>spring-social-web</artifactId>
<version>${spring-social.version}</version> <version>${spring-social.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.mobile</groupId>
<artifactId>spring-mobile-device</artifactId>
<version>${spring-mobile.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.ws</groupId> <groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId> <artifactId>spring-ws-core</artifactId>
......
...@@ -32,6 +32,10 @@ ...@@ -32,6 +32,10 @@
<groupId>jaxen</groupId> <groupId>jaxen</groupId>
<artifactId>jaxen</artifactId> <artifactId>jaxen</artifactId>
</dependency> </dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
</dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
......
...@@ -2,12 +2,8 @@ package sample.ws; ...@@ -2,12 +2,8 @@ package sample.ws;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.ws.transport.http.MessageDispatcherServlet;
/** /**
* Created by in329dei on 28-2-14. * Created by in329dei on 28-2-14.
...@@ -15,27 +11,9 @@ import org.springframework.ws.transport.http.MessageDispatcherServlet; ...@@ -15,27 +11,9 @@ import org.springframework.ws.transport.http.MessageDispatcherServlet;
@Configuration @Configuration
@EnableAutoConfiguration @EnableAutoConfiguration
@ComponentScan @ComponentScan
@ImportResource("classpath:/META-INF/spring/spring-ws-context.xml")
public class SampleWsApplication { public class SampleWsApplication {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
SpringApplication.run(SampleWsApplication.class, args); SpringApplication.run(SampleWsApplication.class, args);
} }
@Bean
public ServletRegistrationBean messageDispatcherServletRegistration() {
MessageDispatcherServlet mds = new MessageDispatcherServlet();
mds.setTransformWsdlLocations(true);
ServletRegistrationBean srb = new ServletRegistrationBean(messageDispatcherServlet(), "/services/*");
srb.setLoadOnStartup(1);
return srb;
}
@Bean
public MessageDispatcherServlet messageDispatcherServlet() {
MessageDispatcherServlet mds = new MessageDispatcherServlet();
mds.setTransformWsdlLocations(true);
return mds;
}
} }
package sample.ws;
import org.springframework.boot.context.embedded.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;
/**
* Configures Spring Web Service components
*
* @author Maciej Walkowiak
*/
@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
@Bean
public ServletRegistrationBean dispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
return new ServletRegistrationBean(servlet, "/services/*");
}
@Bean(name = "holiday")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("HumanResource");
wsdl11Definition.setLocationUri("/holidayService/");
wsdl11Definition.setTargetNamespace("http://mycompany.com/hr/definitions");
wsdl11Definition.setSchema(countriesSchema);
return wsdl11Definition;
}
@Bean
public XsdSchema countriesSchema() {
return new SimpleXsdSchema(new ClassPathResource("META-INF/schemas/hr.xsd"));
}
}
...@@ -3,55 +3,54 @@ package sample.ws.endpoint; ...@@ -3,55 +3,54 @@ package sample.ws.endpoint;
import org.jdom2.Element; import org.jdom2.Element;
import org.jdom2.JDOMException; import org.jdom2.JDOMException;
import org.jdom2.Namespace; import org.jdom2.Namespace;
import org.jdom2.xpath.XPath; import org.jdom2.filter.Filters;
import org.jdom2.xpath.XPathExpression;
import org.jdom2.xpath.XPathFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint; import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot; import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload; import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import sample.ws.service.HumanResourceService; import sample.ws.service.HumanResourceService;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactoryConfigurationException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
/** /**
* Created by in329dei on 28-2-14. * @author in329dei
* @author Maciej Walkowiak
*/ */
@Endpoint @Endpoint
public class HolidayEndpoint { public class HolidayEndpoint {
private static final String NAMESPACE_URI = "http://mycompany.com/hr/schemas"; private static final String NAMESPACE_URI = "http://mycompany.com/hr/schemas";
private XPath startDateExpression; private XPathExpression<Element> startDateExpression;
private XPathExpression<Element> endDateExpression;
private XPath endDateExpression; private XPathExpression<String> nameExpression;
private XPath nameExpression;
private HumanResourceService humanResourceService; private HumanResourceService humanResourceService;
@Autowired @Autowired
public HolidayEndpoint(HumanResourceService humanResourceService) throws JDOMException public HolidayEndpoint(HumanResourceService humanResourceService) throws JDOMException, XPathFactoryConfigurationException, XPathExpressionException {
{
this.humanResourceService = humanResourceService; this.humanResourceService = humanResourceService;
Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI); Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI);
startDateExpression = XPath.newInstance("//hr:StartDate"); XPathFactory xPathFactory = XPathFactory.instance();
startDateExpression.addNamespace(namespace);
endDateExpression = XPath.newInstance("//hr:EndDate");
endDateExpression.addNamespace(namespace);
nameExpression = XPath.newInstance("concat(//hr:FirstName,' ',//hr:LastName)"); startDateExpression = xPathFactory.compile("//hr:StartDate", Filters.element(), null, namespace);
nameExpression.addNamespace(namespace); endDateExpression = xPathFactory.compile("//hr:EndDate", Filters.element(), null, namespace);
nameExpression = xPathFactory.compile("concat(//hr:FirstName,' ',//hr:LastName)", Filters.fstring(), null, namespace);
} }
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "HolidayRequest") @PayloadRoot(namespace = NAMESPACE_URI, localPart = "HolidayRequest")
public void handleHolidayRequest(@RequestPayload Element holidayRequest) throws Exception { public void handleHolidayRequest(@RequestPayload Element holidayRequest) throws Exception {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date startDate = dateFormat.parse(startDateExpression.valueOf(holidayRequest)); Date startDate = dateFormat.parse(startDateExpression.evaluateFirst(holidayRequest).getText());
Date endDate = dateFormat.parse(endDateExpression.valueOf(holidayRequest)); Date endDate = dateFormat.parse(endDateExpression.evaluateFirst(holidayRequest).getText());
String name = nameExpression.valueOf(holidayRequest); String name = nameExpression.evaluateFirst(holidayRequest);
humanResourceService.bookHoliday(startDate, endDate, name); humanResourceService.bookHoliday(startDate, endDate, name);
} }
......
...@@ -11,7 +11,6 @@ import java.util.Date; ...@@ -11,7 +11,6 @@ import java.util.Date;
*/ */
@Service @Service
public class StubHumanResourceService implements HumanResourceService { public class StubHumanResourceService implements HumanResourceService {
private final Logger logger = LoggerFactory.getLogger(StubHumanResourceService.class); private final Logger logger = LoggerFactory.getLogger(StubHumanResourceService.class);
@Override @Override
......
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sws="http://www.springframework.org/schema/web-services"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services.xsd">
<sws:annotation-driven />
<sws:dynamic-wsdl id="holiday" portTypeName="HumanResource" locationUri="/holidayService/" targetNamespace="http://mycompany.com/hr/definitions">
<sws:xsd location="classpath:/META-INF/schemas/hr.xsd"/>
</sws:dynamic-wsdl>
</beans>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment