Polishing

This commit is contained in:
Andy Wilkinson
2014-06-09 18:03:22 +01:00
parent e40320a8ed
commit b585afe537
16 changed files with 247 additions and 158 deletions

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample.ws;
import org.springframework.boot.SpringApplication;
@@ -5,9 +20,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
/**
* Created by in329dei on 28-2-14.
*/
@Configuration
@EnableAutoConfiguration
@ComponentScan

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample.ws;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
@@ -12,19 +27,14 @@ 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/*");
}

View File

@@ -1,5 +1,26 @@
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample.ws.endpoint;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactoryConfigurationException;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.Namespace;
@@ -10,17 +31,9 @@ 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;
/**
* @author in329dei
* @author Maciej Walkowiak
*/
@Endpoint
public class HolidayEndpoint {
@@ -33,25 +46,34 @@ public class HolidayEndpoint {
private HumanResourceService humanResourceService;
@Autowired
public HolidayEndpoint(HumanResourceService humanResourceService) throws JDOMException, XPathFactoryConfigurationException, XPathExpressionException {
public HolidayEndpoint(HumanResourceService humanResourceService)
throws JDOMException, XPathFactoryConfigurationException,
XPathExpressionException {
this.humanResourceService = humanResourceService;
Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI);
XPathFactory xPathFactory = XPathFactory.instance();
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);
this.startDateExpression = xPathFactory.compile("//hr:StartDate",
Filters.element(), null, namespace);
this.endDateExpression = xPathFactory.compile("//hr:EndDate", Filters.element(),
null, namespace);
this.nameExpression = xPathFactory.compile(
"concat(//hr:FirstName,' ',//hr:LastName)", Filters.fstring(), null,
namespace);
}
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "HolidayRequest")
public void handleHolidayRequest(@RequestPayload Element holidayRequest) throws Exception {
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);
Date startDate = dateFormat.parse(this.startDateExpression.evaluateFirst(
holidayRequest).getText());
Date endDate = dateFormat.parse(this.endDateExpression.evaluateFirst(
holidayRequest).getText());
String name = this.nameExpression.evaluateFirst(holidayRequest);
humanResourceService.bookHoliday(startDate, endDate, name);
this.humanResourceService.bookHoliday(startDate, endDate, name);
}
}

View File

@@ -1,10 +1,23 @@
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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);
}

View File

@@ -1,20 +1,34 @@
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample.ws.service;
import java.util.Date;
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);
this.logger.info("Booking holiday for [{} - {}] for [{}] ", startDate, endDate,
name);
}
}