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
This commit is contained in:
committed by
Andy Wilkinson
parent
e2a449da97
commit
95a6ce9e48
@@ -3,56 +3,55 @@ package sample.ws.endpoint;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user