Skip to content

Commit e2a449d

Browse files
mdeinumwilkinsona
authored andcommitted
Spring Web Services Starter and Sample Project
Fixes gh-412
1 parent b5d267c commit e2a449d

File tree

13 files changed

+376
-16
lines changed

13 files changed

+376
-16
lines changed

spring-boot-dependencies/pom.xml

Lines changed: 92 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
<jedis.version>2.4.1</jedis.version>
8080
<jetty.version>8.1.15.v20140411</jetty.version>
8181
<jetty-jsp.version>2.2.0.v201112011158</jetty-jsp.version>
82+
<jaxen.version>1.1.6</jaxen.version>
83+
<jdom.version>2.0.1</jdom.version>
8284
<joda-time.version>2.3</joda-time.version>
8385
<jolokia.version>1.2.1</jolokia.version>
8486
<jstl.version>1.2</jstl.version>
@@ -109,6 +111,7 @@
109111
<spring-social-linkedin.version>1.0.1.RELEASE</spring-social-linkedin.version>
110112
<spring-security.version>3.2.4.RELEASE</spring-security.version>
111113
<spring-security-jwt.version>1.0.2.RELEASE</spring-security-jwt.version>
114+
<spring-ws.version>2.1.4.RELEASE</spring-ws.version>
112115
<thymeleaf.version>2.1.3.RELEASE</thymeleaf.version>
113116
<thymeleaf-extras-springsecurity3.version>2.1.1.RELEASE</thymeleaf-extras-springsecurity3.version>
114117
<thymeleaf-layout-dialect.version>1.2.4</thymeleaf-layout-dialect.version>
@@ -330,6 +333,11 @@
330333
<artifactId>spring-boot-starter-websocket</artifactId>
331334
<version>1.1.0.BUILD-SNAPSHOT</version>
332335
</dependency>
336+
<dependency>
337+
<groupId>org.springframework.boot</groupId>
338+
<artifactId>spring-boot-starter-ws</artifactId>
339+
<version>1.1.0.BUILD-SNAPSHOT</version>
340+
</dependency>
333341

334342
<!-- Third Party -->
335343
<dependency>
@@ -454,6 +462,11 @@
454462
<artifactId>jstl</artifactId>
455463
<version>${jstl.version}</version>
456464
</dependency>
465+
<dependency>
466+
<groupId>jaxen</groupId>
467+
<artifactId>jaxen</artifactId>
468+
<version>${jaxen.version}</version>
469+
</dependency>
457470
<dependency>
458471
<groupId>joda-time</groupId>
459472
<artifactId>joda-time</artifactId>
@@ -819,6 +832,11 @@
819832
<artifactId>jolokia-core</artifactId>
820833
<version>${jolokia.version}</version>
821834
</dependency>
835+
<dependency>
836+
<groupId>org.jdom</groupId>
837+
<artifactId>jdom</artifactId>
838+
<version>${jdom.version}</version>
839+
</dependency>
822840
<dependency>
823841
<groupId>org.liquibase</groupId>
824842
<artifactId>liquibase-core</artifactId>
@@ -1049,39 +1067,98 @@
10491067
<version>${spring-social.version}</version>
10501068
</dependency>
10511069
<dependency>
1052-
<groupId>org.springframework.social</groupId>
1053-
<artifactId>spring-social-facebook</artifactId>
1054-
<version>${spring-social-facebook.version}</version>
1070+
<groupId>org.springframework.mobile</groupId>
1071+
<artifactId>spring-mobile-device</artifactId>
1072+
<version>${spring-mobile.version}</version>
10551073
</dependency>
10561074
<dependency>
1057-
<groupId>org.springframework.social</groupId>
1058-
<artifactId>spring-social-facebook-web</artifactId>
1059-
<version>${spring-social-facebook.version}</version>
1075+
<groupId>org.springframework.ws</groupId>
1076+
<artifactId>spring-ws-core</artifactId>
1077+
<version>${spring-ws.version}</version>
1078+
<exclusions>
1079+
<exclusion>
1080+
<groupId>commons-logging</groupId>
1081+
<artifactId>commons-logging</artifactId>
1082+
</exclusion>
1083+
</exclusions>
10601084
</dependency>
10611085
<dependency>
1062-
<groupId>org.springframework.social</groupId>
1063-
<artifactId>spring-social-twitter</artifactId>
1064-
<version>${spring-social-twitter.version}</version>
1086+
<groupId>org.springframework.ws</groupId>
1087+
<artifactId>spring-ws-support</artifactId>
1088+
<version>${spring-ws.version}</version>
1089+
<exclusions>
1090+
<exclusion>
1091+
<groupId>commons-logging</groupId>
1092+
<artifactId>commons-logging</artifactId>
1093+
</exclusion>
1094+
</exclusions>
10651095
</dependency>
10661096
<dependency>
1067-
<groupId>org.springframework.social</groupId>
1068-
<artifactId>spring-social-linkedin</artifactId>
1069-
<version>${spring-social-linkedin.version}</version>
1097+
<groupId>org.springframework.ws</groupId>
1098+
<artifactId>spring-ws-security</artifactId>
1099+
<version>${spring-ws.version}</version>
1100+
<exclusions>
1101+
<exclusion>
1102+
<groupId>commons-logging</groupId>
1103+
<artifactId>commons-logging</artifactId>
1104+
</exclusion>
1105+
</exclusions>
1106+
</dependency>
1107+
<dependency>
1108+
<groupId>org.springframework.ws</groupId>
1109+
<artifactId>spring-ws-test</artifactId>
1110+
<version>${spring-ws.version}</version>
1111+
<exclusions>
1112+
<exclusion>
1113+
<groupId>commons-logging</groupId>
1114+
<artifactId>commons-logging</artifactId>
1115+
</exclusion>
1116+
</exclusions>
1117+
</dependency>
1118+
<dependency>
1119+
<groupId>wsdl4j</groupId>
1120+
<artifactId>wsdl4j</artifactId>
1121+
<version>1.6.3</version>
1122+
</dependency>
1123+
<dependency>
1124+
<groupId>xmlunit</groupId>
1125+
<artifactId>xmlunit</artifactId>
1126+
<version>1.5</version>
10701127
</dependency>
10711128
<dependency>
10721129
<groupId>org.thymeleaf</groupId>
10731130
<artifactId>thymeleaf</artifactId>
10741131
<version>${thymeleaf.version}</version>
10751132
</dependency>
1133+
<dependency>
1134+
<groupId>org.thymeleaf</groupId>
1135+
<artifactId>thymeleaf-spring4</artifactId>
1136+
<version>${thymeleaf.version}</version>
1137+
</dependency>
10761138
<dependency>
10771139
<groupId>org.thymeleaf.extras</groupId>
10781140
<artifactId>thymeleaf-extras-springsecurity3</artifactId>
10791141
<version>${thymeleaf-extras-springsecurity3.version}</version>
10801142
</dependency>
10811143
<dependency>
1082-
<groupId>org.thymeleaf</groupId>
1083-
<artifactId>thymeleaf-spring4</artifactId>
1084-
<version>${thymeleaf.version}</version>
1144+
<groupId>org.springframework.social</groupId>
1145+
<artifactId>spring-social-facebook</artifactId>
1146+
<version>${spring-social-facebook.version}</version>
1147+
</dependency>
1148+
<dependency>
1149+
<groupId>org.springframework.social</groupId>
1150+
<artifactId>spring-social-facebook-web</artifactId>
1151+
<version>${spring-social-facebook.version}</version>
1152+
</dependency>
1153+
<dependency>
1154+
<groupId>org.springframework.social</groupId>
1155+
<artifactId>spring-social-twitter</artifactId>
1156+
<version>${spring-social-twitter.version}</version>
1157+
</dependency>
1158+
<dependency>
1159+
<groupId>org.springframework.social</groupId>
1160+
<artifactId>spring-social-linkedin</artifactId>
1161+
<version>${spring-social-linkedin.version}</version>
10851162
</dependency>
10861163
<dependency>
10871164
<groupId>org.yaml</groupId>

spring-boot-samples/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
<module>spring-boot-sample-web-velocity</module>
5858
<module>spring-boot-sample-websocket</module>
5959
<module>spring-boot-sample-xml</module>
60-
</modules>
60+
<module>spring-boot-sample-ws</module>
61+
</modules>
6162
<!-- No dependencies - otherwise the samples won't work if you change the
6263
parent -->
6364
<build>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Spring Boot - Samples - Web Services
2+
3+
This sample project demonstrates how to bootstrap and use Spring Web Services with Spring Boot.
4+
5+
It is a runnable implementation of the HolidayRequest sample in the Spring Web Services [reference guide](http://docs.spring.io/spring-ws/site/reference/html/tutorial.html#tutorial.implementing.endpoint).
6+
7+
The sample can be build with Maven (>3) and simply run from the command line.
8+
9+
```
10+
$ mvn package
11+
$ java -jar target/*.jar
12+
```
13+
14+
Now pointing your browser to [http://localhost:8080/services/holidayService/holiday.wsdl] should display the generated WSDL.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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>
11+
12+
<artifactId>spring-boot-sample-ws</artifactId>
13+
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>
49+
</project>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package sample.ws;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5+
import org.springframework.boot.context.embedded.ServletRegistrationBean;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.ComponentScan;
8+
import org.springframework.context.annotation.Configuration;
9+
import org.springframework.context.annotation.ImportResource;
10+
import org.springframework.ws.transport.http.MessageDispatcherServlet;
11+
12+
/**
13+
* Created by in329dei on 28-2-14.
14+
*/
15+
@Configuration
16+
@EnableAutoConfiguration
17+
@ComponentScan
18+
@ImportResource("classpath:/META-INF/spring/spring-ws-context.xml")
19+
public class SampleWsApplication {
20+
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+
}
41+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package sample.ws.endpoint;
2+
3+
import org.jdom2.Element;
4+
import org.jdom2.JDOMException;
5+
import org.jdom2.Namespace;
6+
import org.jdom2.xpath.XPath;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.ws.server.endpoint.annotation.Endpoint;
9+
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
10+
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
11+
import sample.ws.service.HumanResourceService;
12+
13+
import java.text.SimpleDateFormat;
14+
import java.util.Date;
15+
16+
/**
17+
* Created by in329dei on 28-2-14.
18+
*/
19+
@Endpoint
20+
public class HolidayEndpoint {
21+
22+
private static final String NAMESPACE_URI = "http://mycompany.com/hr/schemas";
23+
24+
private XPath startDateExpression;
25+
26+
private XPath endDateExpression;
27+
28+
private XPath nameExpression;
29+
30+
private HumanResourceService humanResourceService;
31+
32+
@Autowired
33+
public HolidayEndpoint(HumanResourceService humanResourceService) throws JDOMException
34+
{
35+
this.humanResourceService = humanResourceService;
36+
37+
Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI);
38+
39+
startDateExpression = XPath.newInstance("//hr:StartDate");
40+
startDateExpression.addNamespace(namespace);
41+
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+
}
58+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package sample.ws.service;
2+
3+
import java.util.Date;
4+
5+
/**
6+
* Created by in329dei on 28-2-14.
7+
*/
8+
public interface HumanResourceService {
9+
void bookHoliday(Date startDate, Date endDate, String name);
10+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package sample.ws.service;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.stereotype.Service;
6+
7+
import java.util.Date;
8+
9+
/**
10+
* Created by in329dei on 28-2-14.
11+
*/
12+
@Service
13+
public class StubHumanResourceService implements HumanResourceService {
14+
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+
}
21+
}

0 commit comments

Comments
 (0)