Spring Web Services Starter and Sample Project
Fixes gh-412
This commit is contained in:
committed by
Andy Wilkinson
parent
b5d267ca89
commit
e2a449da97
@@ -0,0 +1,41 @@
|
||||
package sample.ws;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package sample.ws.endpoint;
|
||||
|
||||
import org.jdom2.Element;
|
||||
import org.jdom2.JDOMException;
|
||||
import org.jdom2.Namespace;
|
||||
import org.jdom2.xpath.XPath;
|
||||
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 java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Created by in329dei on 28-2-14.
|
||||
*/
|
||||
@Endpoint
|
||||
public class HolidayEndpoint {
|
||||
|
||||
private static final String NAMESPACE_URI = "http://mycompany.com/hr/schemas";
|
||||
|
||||
private XPath startDateExpression;
|
||||
|
||||
private XPath endDateExpression;
|
||||
|
||||
private XPath nameExpression;
|
||||
|
||||
private HumanResourceService humanResourceService;
|
||||
|
||||
@Autowired
|
||||
public HolidayEndpoint(HumanResourceService humanResourceService) throws JDOMException
|
||||
{
|
||||
this.humanResourceService = humanResourceService;
|
||||
|
||||
Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI);
|
||||
|
||||
startDateExpression = XPath.newInstance("//hr:StartDate");
|
||||
startDateExpression.addNamespace(namespace);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package sample.ws.service;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Created by in329dei on 28-2-14.
|
||||
*/
|
||||
public interface HumanResourceService {
|
||||
void bookHoliday(Date startDate, Date endDate, String name);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package sample.ws.service;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Created by in329dei on 28-2-14.
|
||||
*/
|
||||
@Service
|
||||
public class StubHumanResourceService implements HumanResourceService {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:hr="http://mycompany.com/hr/schemas"
|
||||
elementFormDefault="qualified"
|
||||
targetNamespace="http://mycompany.com/hr/schemas">
|
||||
<xs:element name="HolidayRequest">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="Holiday" type="hr:HolidayType"/>
|
||||
<xs:element name="Employee" type="hr:EmployeeType"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:complexType name="HolidayType">
|
||||
<xs:sequence>
|
||||
<xs:element name="StartDate" type="xs:date"/>
|
||||
<xs:element name="EndDate" type="xs:date"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="EmployeeType">
|
||||
<xs:sequence>
|
||||
<xs:element name="Number" type="xs:integer"/>
|
||||
<xs:element name="FirstName" type="xs:string"/>
|
||||
<xs:element name="LastName" type="xs:string"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:schema>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?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>
|
||||
Reference in New Issue
Block a user