Skip to content

Commit

Permalink
Spring Web Services Starter
Browse files Browse the repository at this point in the history
- 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: spring-projectsgh-412
  • Loading branch information
maciejwalkowiak authored and wilkinsona committed Jun 9, 2014
1 parent e2a449d commit 95a6ce9
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 183 deletions.
31 changes: 16 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?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>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-build</artifactId>
Expand Down Expand Up @@ -148,20 +149,20 @@
<inherited>false</inherited>
<configuration>
<target>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
<taskdef name="stringutil" classname="ise.antelope.tasks.StringUtilTask" />
<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="(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="BUILD-(.*)" replace="SNAPSHOT" />
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<taskdef name="stringutil" classname="ise.antelope.tasks.StringUtilTask"/>
<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="(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="BUILD-(.*)" replace="SNAPSHOT"/>
<stringutil string="${version-type}" property="profile">
<lowercase />
<lowercase/>
</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">
<filterset>
<filter token="profile" value="${profile}" />
<filter token="profile" value="${profile}"/>
</filterset>
</copy>
</target>
Expand All @@ -176,7 +177,7 @@
<inherited>false</inherited>
<configuration>
<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">
<style>
<string><![CDATA[
Expand All @@ -199,9 +200,9 @@
</string>
</style>
</xslt>
<move file="${sourceFile}" tofile="${sourceFile}.old" />
<move file="${sourceFile}.new" tofile="${sourceFile}" />
<delete file="${sourceFile}.old" />
<move file="${sourceFile}" tofile="${sourceFile}.old"/>
<move file="${sourceFile}.new" tofile="${sourceFile}"/>
<delete file="${sourceFile}.old"/>
</target>
</configuration>
</execution>
Expand Down
7 changes: 1 addition & 6 deletions spring-boot-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
<spring-social-linkedin.version>1.0.1.RELEASE</spring-social-linkedin.version>
<spring-security.version>3.2.4.RELEASE</spring-security.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-extras-springsecurity3.version>2.1.1.RELEASE</thymeleaf-extras-springsecurity3.version>
<thymeleaf-layout-dialect.version>1.2.4</thymeleaf-layout-dialect.version>
Expand Down Expand Up @@ -1066,11 +1066,6 @@
<artifactId>spring-social-web</artifactId>
<version>${spring-social.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.mobile</groupId>
<artifactId>spring-mobile-device</artifactId>
<version>${spring-mobile.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
Expand Down
92 changes: 48 additions & 44 deletions spring-boot-samples/spring-boot-sample-ws/pom.xml
Original file line number Diff line number Diff line change
@@ -1,49 +1,53 @@
<?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">
<parent>
<artifactId>spring-boot-samples</artifactId>
<groupId>org.springframework.boot</groupId>
<version>1.1.0.BUILD-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
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">
<parent>
<artifactId>spring-boot-samples</artifactId>
<groupId>org.springframework.boot</groupId>
<version>1.1.0.BUILD-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-boot-sample-ws</artifactId>
<artifactId>spring-boot-sample-ws</artifactId>

<properties>
<main.basedir>${basedir}/../..</main.basedir>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-ws</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-ws</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,18 @@

import org.springframework.boot.SpringApplication;
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.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.ws.transport.http.MessageDispatcherServlet;

/**
* Created by in329dei on 28-2-14.
*/
@Configuration
@EnableAutoConfiguration
@ComponentScan
@ImportResource("classpath:/META-INF/spring/spring-ws-context.xml")
public class SampleWsApplication {

public static void main(String[] args) throws Exception {
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;
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleWsApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,55 @@
import org.jdom2.Element;
import org.jdom2.JDOMException;
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.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import sample.ws.service.HumanResourceService;

import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactoryConfigurationException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
* Created by in329dei on 28-2-14.
* @author in329dei
* @author Maciej Walkowiak
*/
@Endpoint
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 XPathExpression<String> nameExpression;

private XPath endDateExpression;
private HumanResourceService humanResourceService;

private XPath nameExpression;
@Autowired
public HolidayEndpoint(HumanResourceService humanResourceService) throws JDOMException, XPathFactoryConfigurationException, XPathExpressionException {
this.humanResourceService = humanResourceService;

private HumanResourceService humanResourceService;
Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI);

@Autowired
public HolidayEndpoint(HumanResourceService humanResourceService) throws JDOMException
{
this.humanResourceService = humanResourceService;
XPathFactory xPathFactory = XPathFactory.instance();

Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI);
startDateExpression = xPathFactory.compile("//hr:StartDate", Filters.element(), null, namespace);
endDateExpression = xPathFactory.compile("//hr:EndDate", Filters.element(), null, namespace);
nameExpression = xPathFactory.compile("concat(//hr:FirstName,' ',//hr:LastName)", Filters.fstring(), null, namespace);
}

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

endDateExpression = XPath.newInstance("//hr:EndDate");
endDateExpression.addNamespace(namespace);

nameExpression = XPath.newInstance("concat(//hr:FirstName,' ',//hr:LastName)");
nameExpression.addNamespace(namespace);
}

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "HolidayRequest")
public void handleHolidayRequest(@RequestPayload Element holidayRequest) throws Exception {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date startDate = dateFormat.parse(startDateExpression.valueOf(holidayRequest));
Date endDate = dateFormat.parse(endDateExpression.valueOf(holidayRequest));
String name = nameExpression.valueOf(holidayRequest);

humanResourceService.bookHoliday(startDate, endDate, name);
}
humanResourceService.bookHoliday(startDate, endDate, name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
* Created by in329dei on 28-2-14.
*/
public interface HumanResourceService {
void bookHoliday(Date startDate, Date endDate, String name);
void bookHoliday(Date startDate, Date endDate, String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
*/
@Service
public class StubHumanResourceService implements HumanResourceService {
private final Logger logger = LoggerFactory.getLogger(StubHumanResourceService.class);

private final Logger logger = LoggerFactory.getLogger(StubHumanResourceService.class);

@Override
public void bookHoliday(Date startDate, Date endDate, String name) {
logger.info("Booking holiday for [{} - {}] for [{}] ", startDate, endDate, name);
}
@Override
public void bookHoliday(Date startDate, Date endDate, String name) {
logger.info("Booking holiday for [{} - {}] for [{}] ", startDate, endDate, name);
}
}

This file was deleted.

Loading

0 comments on commit 95a6ce9

Please sign in to comment.