Skip to content

Commit 95a6ce9

Browse files
maciejwalkowiakwilkinsona
authored andcommitted
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
1 parent e2a449d commit 95a6ce9

File tree

10 files changed

+191
-183
lines changed

10 files changed

+191
-183
lines changed

pom.xml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45
<groupId>org.springframework.boot</groupId>
56
<artifactId>spring-boot-build</artifactId>
@@ -148,20 +149,20 @@
148149
<inherited>false</inherited>
149150
<configuration>
150151
<target>
151-
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
152-
<taskdef name="stringutil" classname="ise.antelope.tasks.StringUtilTask" />
153-
<var name="version-type" value="${project.version}" />
154-
<propertyregex property="version-type" override="true" input="${version-type}" regexp=".*\.(.*)" replace="\1" />
155-
<propertyregex property="version-type" override="true" input="${version-type}" regexp="(M)\d+" replace="MILESTONE" />
156-
<propertyregex property="version-type" override="true" input="${version-type}" regexp="(RC)\d+" replace="MILESTONE" />
157-
<propertyregex property="version-type" override="true" input="${version-type}" regexp="BUILD-(.*)" replace="SNAPSHOT" />
152+
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
153+
<taskdef name="stringutil" classname="ise.antelope.tasks.StringUtilTask"/>
154+
<var name="version-type" value="${project.version}"/>
155+
<propertyregex property="version-type" override="true" input="${version-type}" regexp=".*\.(.*)" replace="\1"/>
156+
<propertyregex property="version-type" override="true" input="${version-type}" regexp="(M)\d+" replace="MILESTONE"/>
157+
<propertyregex property="version-type" override="true" input="${version-type}" regexp="(RC)\d+" replace="MILESTONE"/>
158+
<propertyregex property="version-type" override="true" input="${version-type}" regexp="BUILD-(.*)" replace="SNAPSHOT"/>
158159
<stringutil string="${version-type}" property="profile">
159-
<lowercase />
160+
<lowercase/>
160161
</stringutil>
161-
<echo message="Writing settings for ${profile} profile" />
162+
<echo message="Writing settings for ${profile} profile"/>
162163
<copy file=".settings-template.xml" tofile="settings.xml" overwrite="true">
163164
<filterset>
164-
<filter token="profile" value="${profile}" />
165+
<filter token="profile" value="${profile}"/>
165166
</filterset>
166167
</copy>
167168
</target>
@@ -176,7 +177,7 @@
176177
<inherited>false</inherited>
177178
<configuration>
178179
<target>
179-
<property name="sourceFile" value="spring-boot-dependencies/pom.xml" />
180+
<property name="sourceFile" value="spring-boot-dependencies/pom.xml"/>
180181
<xslt in="${sourceFile}" out="${sourceFile}.new" force="true">
181182
<style>
182183
<string><![CDATA[
@@ -199,9 +200,9 @@
199200
</string>
200201
</style>
201202
</xslt>
202-
<move file="${sourceFile}" tofile="${sourceFile}.old" />
203-
<move file="${sourceFile}.new" tofile="${sourceFile}" />
204-
<delete file="${sourceFile}.old" />
203+
<move file="${sourceFile}" tofile="${sourceFile}.old"/>
204+
<move file="${sourceFile}.new" tofile="${sourceFile}"/>
205+
<delete file="${sourceFile}.old"/>
205206
</target>
206207
</configuration>
207208
</execution>

spring-boot-dependencies/pom.xml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
<spring-social-linkedin.version>1.0.1.RELEASE</spring-social-linkedin.version>
112112
<spring-security.version>3.2.4.RELEASE</spring-security.version>
113113
<spring-security-jwt.version>1.0.2.RELEASE</spring-security-jwt.version>
114-
<spring-ws.version>2.1.4.RELEASE</spring-ws.version>
114+
<spring-ws.version>2.2.0.RELEASE</spring-ws.version>
115115
<thymeleaf.version>2.1.3.RELEASE</thymeleaf.version>
116116
<thymeleaf-extras-springsecurity3.version>2.1.1.RELEASE</thymeleaf-extras-springsecurity3.version>
117117
<thymeleaf-layout-dialect.version>1.2.4</thymeleaf-layout-dialect.version>
@@ -1066,11 +1066,6 @@
10661066
<artifactId>spring-social-web</artifactId>
10671067
<version>${spring-social.version}</version>
10681068
</dependency>
1069-
<dependency>
1070-
<groupId>org.springframework.mobile</groupId>
1071-
<artifactId>spring-mobile-device</artifactId>
1072-
<version>${spring-mobile.version}</version>
1073-
</dependency>
10741069
<dependency>
10751070
<groupId>org.springframework.ws</groupId>
10761071
<artifactId>spring-ws-core</artifactId>
Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,53 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5-
<parent>
6-
<artifactId>spring-boot-samples</artifactId>
7-
<groupId>org.springframework.boot</groupId>
8-
<version>1.1.0.BUILD-SNAPSHOT</version>
9-
</parent>
10-
<modelVersion>4.0.0</modelVersion>
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>spring-boot-samples</artifactId>
7+
<groupId>org.springframework.boot</groupId>
8+
<version>1.1.0.BUILD-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
1111

12-
<artifactId>spring-boot-sample-ws</artifactId>
12+
<artifactId>spring-boot-sample-ws</artifactId>
1313

14-
<properties>
15-
<main.basedir>${basedir}/../..</main.basedir>
16-
<java.version>1.7</java.version>
17-
</properties>
18-
<dependencies>
19-
<dependency>
20-
<groupId>org.springframework.boot</groupId>
21-
<artifactId>spring-boot-starter-ws</artifactId>
22-
</dependency>
23-
<dependency>
24-
<groupId>org.springframework.boot</groupId>
25-
<artifactId>spring-boot-starter-actuator</artifactId>
26-
</dependency>
27-
<dependency>
28-
<groupId>org.jdom</groupId>
29-
<artifactId>jdom</artifactId>
30-
</dependency>
31-
<dependency>
32-
<groupId>jaxen</groupId>
33-
<artifactId>jaxen</artifactId>
34-
</dependency>
35-
<dependency>
36-
<groupId>${project.groupId}</groupId>
37-
<artifactId>spring-boot-starter-test</artifactId>
38-
<scope>test</scope>
39-
</dependency>
40-
</dependencies>
41-
<build>
42-
<plugins>
43-
<plugin>
44-
<groupId>org.springframework.boot</groupId>
45-
<artifactId>spring-boot-maven-plugin</artifactId>
46-
</plugin>
47-
</plugins>
48-
</build>
14+
<properties>
15+
<main.basedir>${basedir}/../..</main.basedir>
16+
<java.version>1.7</java.version>
17+
</properties>
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-starter-ws</artifactId>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter-actuator</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.jdom</groupId>
29+
<artifactId>jdom</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>jaxen</groupId>
33+
<artifactId>jaxen</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>wsdl4j</groupId>
37+
<artifactId>wsdl4j</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>${project.groupId}</groupId>
41+
<artifactId>spring-boot-starter-test</artifactId>
42+
<scope>test</scope>
43+
</dependency>
44+
</dependencies>
45+
<build>
46+
<plugins>
47+
<plugin>
48+
<groupId>org.springframework.boot</groupId>
49+
<artifactId>spring-boot-maven-plugin</artifactId>
50+
</plugin>
51+
</plugins>
52+
</build>
4953
</project>

spring-boot-samples/spring-boot-sample-ws/src/main/java/sample/ws/SampleWsApplication.java

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,18 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5-
import org.springframework.boot.context.embedded.ServletRegistrationBean;
6-
import org.springframework.context.annotation.Bean;
75
import org.springframework.context.annotation.ComponentScan;
86
import org.springframework.context.annotation.Configuration;
9-
import org.springframework.context.annotation.ImportResource;
10-
import org.springframework.ws.transport.http.MessageDispatcherServlet;
117

128
/**
139
* Created by in329dei on 28-2-14.
1410
*/
1511
@Configuration
1612
@EnableAutoConfiguration
1713
@ComponentScan
18-
@ImportResource("classpath:/META-INF/spring/spring-ws-context.xml")
1914
public class SampleWsApplication {
2015

21-
public static void main(String[] args) throws Exception {
22-
SpringApplication.run(SampleWsApplication.class, args);
23-
}
24-
25-
@Bean
26-
public ServletRegistrationBean messageDispatcherServletRegistration() {
27-
MessageDispatcherServlet mds = new MessageDispatcherServlet();
28-
mds.setTransformWsdlLocations(true);
29-
30-
ServletRegistrationBean srb = new ServletRegistrationBean(messageDispatcherServlet(), "/services/*");
31-
srb.setLoadOnStartup(1);
32-
return srb;
33-
}
34-
35-
@Bean
36-
public MessageDispatcherServlet messageDispatcherServlet() {
37-
MessageDispatcherServlet mds = new MessageDispatcherServlet();
38-
mds.setTransformWsdlLocations(true);
39-
return mds;
40-
}
16+
public static void main(String[] args) throws Exception {
17+
SpringApplication.run(SampleWsApplication.class, args);
18+
}
4119
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package sample.ws;
2+
3+
import org.springframework.boot.context.embedded.ServletRegistrationBean;
4+
import org.springframework.context.ApplicationContext;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.Configuration;
7+
import org.springframework.core.io.ClassPathResource;
8+
import org.springframework.ws.config.annotation.EnableWs;
9+
import org.springframework.ws.config.annotation.WsConfigurerAdapter;
10+
import org.springframework.ws.transport.http.MessageDispatcherServlet;
11+
import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
12+
import org.springframework.xml.xsd.SimpleXsdSchema;
13+
import org.springframework.xml.xsd.XsdSchema;
14+
15+
/**
16+
* Configures Spring Web Service components
17+
*
18+
* @author Maciej Walkowiak
19+
*/
20+
@EnableWs
21+
@Configuration
22+
public class WebServiceConfig extends WsConfigurerAdapter {
23+
@Bean
24+
public ServletRegistrationBean dispatcherServlet(ApplicationContext applicationContext) {
25+
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
26+
servlet.setApplicationContext(applicationContext);
27+
28+
return new ServletRegistrationBean(servlet, "/services/*");
29+
}
30+
31+
@Bean(name = "holiday")
32+
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) {
33+
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
34+
wsdl11Definition.setPortTypeName("HumanResource");
35+
wsdl11Definition.setLocationUri("/holidayService/");
36+
wsdl11Definition.setTargetNamespace("http://mycompany.com/hr/definitions");
37+
wsdl11Definition.setSchema(countriesSchema);
38+
return wsdl11Definition;
39+
}
40+
41+
@Bean
42+
public XsdSchema countriesSchema() {
43+
return new SimpleXsdSchema(new ClassPathResource("META-INF/schemas/hr.xsd"));
44+
}
45+
}

spring-boot-samples/spring-boot-sample-ws/src/main/java/sample/ws/endpoint/HolidayEndpoint.java

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,55 @@
33
import org.jdom2.Element;
44
import org.jdom2.JDOMException;
55
import org.jdom2.Namespace;
6-
import org.jdom2.xpath.XPath;
6+
import org.jdom2.filter.Filters;
7+
import org.jdom2.xpath.XPathExpression;
8+
import org.jdom2.xpath.XPathFactory;
79
import org.springframework.beans.factory.annotation.Autowired;
810
import org.springframework.ws.server.endpoint.annotation.Endpoint;
911
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
1012
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
1113
import sample.ws.service.HumanResourceService;
1214

15+
import javax.xml.xpath.XPathExpressionException;
16+
import javax.xml.xpath.XPathFactoryConfigurationException;
1317
import java.text.SimpleDateFormat;
1418
import java.util.Date;
1519

1620
/**
17-
* Created by in329dei on 28-2-14.
21+
* @author in329dei
22+
* @author Maciej Walkowiak
1823
*/
1924
@Endpoint
2025
public class HolidayEndpoint {
2126

22-
private static final String NAMESPACE_URI = "http://mycompany.com/hr/schemas";
27+
private static final String NAMESPACE_URI = "http://mycompany.com/hr/schemas";
2328

24-
private XPath startDateExpression;
29+
private XPathExpression<Element> startDateExpression;
30+
private XPathExpression<Element> endDateExpression;
31+
private XPathExpression<String> nameExpression;
2532

26-
private XPath endDateExpression;
33+
private HumanResourceService humanResourceService;
2734

28-
private XPath nameExpression;
35+
@Autowired
36+
public HolidayEndpoint(HumanResourceService humanResourceService) throws JDOMException, XPathFactoryConfigurationException, XPathExpressionException {
37+
this.humanResourceService = humanResourceService;
2938

30-
private HumanResourceService humanResourceService;
39+
Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI);
3140

32-
@Autowired
33-
public HolidayEndpoint(HumanResourceService humanResourceService) throws JDOMException
34-
{
35-
this.humanResourceService = humanResourceService;
41+
XPathFactory xPathFactory = XPathFactory.instance();
3642

37-
Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI);
43+
startDateExpression = xPathFactory.compile("//hr:StartDate", Filters.element(), null, namespace);
44+
endDateExpression = xPathFactory.compile("//hr:EndDate", Filters.element(), null, namespace);
45+
nameExpression = xPathFactory.compile("concat(//hr:FirstName,' ',//hr:LastName)", Filters.fstring(), null, namespace);
46+
}
3847

39-
startDateExpression = XPath.newInstance("//hr:StartDate");
40-
startDateExpression.addNamespace(namespace);
48+
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "HolidayRequest")
49+
public void handleHolidayRequest(@RequestPayload Element holidayRequest) throws Exception {
50+
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
51+
Date startDate = dateFormat.parse(startDateExpression.evaluateFirst(holidayRequest).getText());
52+
Date endDate = dateFormat.parse(endDateExpression.evaluateFirst(holidayRequest).getText());
53+
String name = nameExpression.evaluateFirst(holidayRequest);
4154

42-
endDateExpression = XPath.newInstance("//hr:EndDate");
43-
endDateExpression.addNamespace(namespace);
44-
45-
nameExpression = XPath.newInstance("concat(//hr:FirstName,' ',//hr:LastName)");
46-
nameExpression.addNamespace(namespace);
47-
}
48-
49-
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "HolidayRequest")
50-
public void handleHolidayRequest(@RequestPayload Element holidayRequest) throws Exception {
51-
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
52-
Date startDate = dateFormat.parse(startDateExpression.valueOf(holidayRequest));
53-
Date endDate = dateFormat.parse(endDateExpression.valueOf(holidayRequest));
54-
String name = nameExpression.valueOf(holidayRequest);
55-
56-
humanResourceService.bookHoliday(startDate, endDate, name);
57-
}
55+
humanResourceService.bookHoliday(startDate, endDate, name);
56+
}
5857
}

spring-boot-samples/spring-boot-sample-ws/src/main/java/sample/ws/service/HumanResourceService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
* Created by in329dei on 28-2-14.
77
*/
88
public interface HumanResourceService {
9-
void bookHoliday(Date startDate, Date endDate, String name);
9+
void bookHoliday(Date startDate, Date endDate, String name);
1010
}

spring-boot-samples/spring-boot-sample-ws/src/main/java/sample/ws/service/StubHumanResourceService.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
*/
1212
@Service
1313
public class StubHumanResourceService implements HumanResourceService {
14+
private final Logger logger = LoggerFactory.getLogger(StubHumanResourceService.class);
1415

15-
private final Logger logger = LoggerFactory.getLogger(StubHumanResourceService.class);
16-
17-
@Override
18-
public void bookHoliday(Date startDate, Date endDate, String name) {
19-
logger.info("Booking holiday for [{} - {}] for [{}] ", startDate, endDate, name);
20-
}
16+
@Override
17+
public void bookHoliday(Date startDate, Date endDate, String name) {
18+
logger.info("Booking holiday for [{} - {}] for [{}] ", startDate, endDate, name);
19+
}
2120
}

spring-boot-samples/spring-boot-sample-ws/src/main/resources/META-INF/spring/spring-ws-context.xml

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)