Upgrade to Spring Boot + Spring Data.
Update this repository to use modern Spring practices including: * Spring Boot * Spring Data JPA * Spring Framework's Java configuration
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
maven { url 'https://repo.springsource.org/plugins-release' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:0.9.9'
|
||||
}
|
||||
}
|
||||
|
||||
ext.springVersion = '4.0.2.RELEASE'
|
||||
ext.tomcatVersion = '7.0.42'
|
||||
|
||||
apply plugin: 'war'
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'tomcat'
|
||||
|
||||
tomcatRun {
|
||||
contextPath = 'echo-server'
|
||||
}
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile("org.springframework.ws:spring-ws-core:$springWsVersion")
|
||||
compile("org.springframework:spring-context:$springVersion")
|
||||
runtime("log4j:log4j:1.2.16")
|
||||
|
||||
providedCompile("javax.servlet:javax.servlet-api:3.0.1")
|
||||
runtime("wsdl4j:wsdl4j:1.6.1")
|
||||
|
||||
tomcat("org.apache.tomcat.embed:tomcat-embed-core:$tomcatVersion",
|
||||
"org.apache.tomcat.embed:tomcat-embed-logging-juli:$tomcatVersion")
|
||||
tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:$tomcatVersion") {
|
||||
exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
|
||||
}
|
||||
}
|
||||
121
echo/server/pom.xml
Normal file
121
echo/server/pom.xml
Normal file
@@ -0,0 +1,121 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.1.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<groupId>org.springframework.ws</groupId>
|
||||
<artifactId>echo-server</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>Spring Web Services Samples - Echo - Server</name>
|
||||
<description>Demo project for Spring Web Services</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<joda-time.version>2.10.6</joda-time.version>
|
||||
<log4j.version>1.2.16</log4j.version>
|
||||
<sourcesDir>${project.basedir}/target/generated-sources/axis</sourcesDir>
|
||||
<classesDir>${project.basedir}/target/classes</classesDir>
|
||||
<wsdl>${project.basedir}/../airline.wsdl</wsdl>
|
||||
<xmlschema.version>2.0.2</xmlschema.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web-services</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>wsdl4j</groupId>
|
||||
<artifactId>wsdl4j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.ws.xmlschema</groupId>
|
||||
<artifactId>xmlschema-core</artifactId>
|
||||
<version>${xmlschema.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
<plugins>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>jaxb2-maven-plugin</artifactId>
|
||||
<version>2.5.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>xjc</id>
|
||||
<goals>
|
||||
<goal>xjc</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<sources>${project.basedir}/src/main/resources/echo.xsd</sources>
|
||||
<packageName>org.springframework.ws.samples.airline.schema</packageName>
|
||||
<target>2.1</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<version>1.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add-source</id>
|
||||
<phase>process-sources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>target/generated-sources/xjc</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.springframework.ws.samples.echo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class EchoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(EchoApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -19,10 +19,8 @@ package org.springframework.ws.samples.echo.config;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
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.server.EndpointInterceptor;
|
||||
import org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor;
|
||||
@@ -35,9 +33,7 @@ import org.springframework.xml.xsd.SimpleXsdSchema;
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
@EnableWs
|
||||
@Configuration
|
||||
@ComponentScan("org.springframework.ws.samples.echo")
|
||||
public class EchoConfig extends WsConfigurerAdapter {
|
||||
|
||||
@Bean
|
||||
@@ -47,7 +43,9 @@ public class EchoConfig extends WsConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
public void addInterceptors(List<EndpointInterceptor> interceptors) {
|
||||
|
||||
PayloadValidatingInterceptor validatingInterceptor = new PayloadValidatingInterceptor();
|
||||
|
||||
validatingInterceptor.setXsdSchema(echoXsd());
|
||||
validatingInterceptor.setValidateRequest(true);
|
||||
validatingInterceptor.setValidateResponse(true);
|
||||
@@ -56,12 +54,13 @@ public class EchoConfig extends WsConfigurerAdapter {
|
||||
interceptors.add(new PayloadLoggingInterceptor());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DefaultWsdl11Definition echo() {
|
||||
@Bean("echo-server")
|
||||
public DefaultWsdl11Definition echo(SimpleXsdSchema echoXsd) {
|
||||
|
||||
DefaultWsdl11Definition definition = new DefaultWsdl11Definition();
|
||||
definition.setPortTypeName("Echo");
|
||||
definition.setLocationUri("http://localhost:8080/echo/services");
|
||||
definition.setSchema(echoXsd());
|
||||
definition.setLocationUri("http://localhost:8080/echo-server/services");
|
||||
definition.setSchema(echoXsd);
|
||||
|
||||
return definition;
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-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 org.springframework.ws.samples.echo.config;
|
||||
|
||||
import org.springframework.web.WebApplicationInitializer;
|
||||
import org.springframework.ws.transport.http.support.AbstractAnnotationConfigMessageDispatcherServletInitializer;
|
||||
|
||||
/**
|
||||
* {@link WebApplicationInitializer} for the echo sample.
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class EchoServletInitializer
|
||||
extends AbstractAnnotationConfigMessageDispatcherServletInitializer {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getRootConfigClasses() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getServletConfigClasses() {
|
||||
return new Class[]{EchoConfig.class};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTransformWsdlLocations() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -24,10 +24,10 @@ package org.springframework.ws.samples.echo.service;
|
||||
*/
|
||||
public interface EchoService {
|
||||
|
||||
/**
|
||||
* Returns the given string.
|
||||
*
|
||||
* @return <code>s</code>
|
||||
*/
|
||||
String echo(String s);
|
||||
/**
|
||||
* Returns the given string.
|
||||
*
|
||||
* @return <code>message</code>
|
||||
*/
|
||||
String echo(String message);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.ws.samples.echo.service.EchoService;
|
||||
@Service
|
||||
public class EchoServiceImpl implements EchoService {
|
||||
|
||||
public String echo(String s) {
|
||||
return s;
|
||||
}
|
||||
public String echo(String message) {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,14 +20,12 @@ import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.samples.echo.service.EchoService;
|
||||
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 org.springframework.ws.server.endpoint.annotation.ResponsePayload;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
@@ -43,62 +41,64 @@ import org.w3c.dom.Text;
|
||||
@Endpoint
|
||||
public class EchoEndpoint {
|
||||
|
||||
/**
|
||||
* Namespace of both request and response.
|
||||
*/
|
||||
public static final String NAMESPACE_URI = "http://www.springframework.org/spring-ws/samples/echo";
|
||||
/**
|
||||
* Namespace of both request and response.
|
||||
*/
|
||||
public static final String NAMESPACE_URI = "http://www.springframework.org/spring-ws/samples/echo";
|
||||
|
||||
/**
|
||||
* The local name of the expected request.
|
||||
*/
|
||||
public static final String ECHO_REQUEST_LOCAL_NAME = "echoRequest";
|
||||
/**
|
||||
* The local name of the expected request.
|
||||
*/
|
||||
public static final String ECHO_REQUEST_LOCAL_NAME = "echoRequest";
|
||||
|
||||
/**
|
||||
* The local name of the created response.
|
||||
*/
|
||||
public static final String ECHO_RESPONSE_LOCAL_NAME = "echoResponse";
|
||||
/**
|
||||
* The local name of the created response.
|
||||
*/
|
||||
public static final String ECHO_RESPONSE_LOCAL_NAME = "echoResponse";
|
||||
|
||||
private final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
private final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
|
||||
private final EchoService echoService;
|
||||
private final EchoService echoService;
|
||||
|
||||
@Autowired
|
||||
public EchoEndpoint(EchoService echoService) {
|
||||
this.echoService = echoService;
|
||||
}
|
||||
public EchoEndpoint(EchoService echoService) {
|
||||
this.echoService = echoService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the given <code>requestElement</code>, and sends a the response back.
|
||||
*
|
||||
* @param requestElement the contents of the SOAP message as DOM elements
|
||||
* @return the response element
|
||||
*/
|
||||
@PayloadRoot(localPart = ECHO_REQUEST_LOCAL_NAME, namespace = NAMESPACE_URI)
|
||||
@ResponsePayload
|
||||
public Element handleEchoRequest(@RequestPayload Element requestElement) throws ParserConfigurationException {
|
||||
|
||||
/**
|
||||
* Reads the given <code>requestElement</code>, and sends a the response back.
|
||||
*
|
||||
* @param requestElement the contents of the SOAP message as DOM elements
|
||||
* @return the response element
|
||||
*/
|
||||
@PayloadRoot(localPart = ECHO_REQUEST_LOCAL_NAME, namespace = NAMESPACE_URI)
|
||||
@ResponsePayload
|
||||
public Element handleEchoRequest(@RequestPayload Element requestElement) throws ParserConfigurationException {
|
||||
Assert.isTrue(NAMESPACE_URI.equals(requestElement.getNamespaceURI()), "Invalid namespace");
|
||||
Assert.isTrue(ECHO_REQUEST_LOCAL_NAME.equals(requestElement.getLocalName()), "Invalid local name");
|
||||
Assert.isTrue(NAMESPACE_URI.equals(requestElement.getNamespaceURI()), "Invalid namespace");
|
||||
Assert.isTrue(ECHO_REQUEST_LOCAL_NAME.equals(requestElement.getLocalName()), "Invalid local name");
|
||||
|
||||
NodeList children = requestElement.getChildNodes();
|
||||
Text requestText = null;
|
||||
for (int i = 0; i < children.getLength(); i++) {
|
||||
if (children.item(i).getNodeType() == Node.TEXT_NODE) {
|
||||
requestText = (Text) children.item(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (requestText == null) {
|
||||
throw new IllegalArgumentException("Could not find request text node");
|
||||
}
|
||||
NodeList children = requestElement.getChildNodes();
|
||||
Text requestText = null;
|
||||
|
||||
String echo = echoService.echo(requestText.getNodeValue());
|
||||
for (int i = 0; i < children.getLength(); i++) {
|
||||
if (children.item(i).getNodeType() == Node.TEXT_NODE) {
|
||||
requestText = (Text) children.item(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.newDocument();
|
||||
Element responseElement = document.createElementNS(NAMESPACE_URI, ECHO_RESPONSE_LOCAL_NAME);
|
||||
Text responseText = document.createTextNode(echo);
|
||||
responseElement.appendChild(responseText);
|
||||
return responseElement;
|
||||
}
|
||||
if (requestText == null) {
|
||||
throw new IllegalArgumentException("Could not find request text node");
|
||||
}
|
||||
|
||||
String echo = echoService.echo(requestText.getNodeValue());
|
||||
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.newDocument();
|
||||
Element responseElement = document.createElementNS(NAMESPACE_URI, ECHO_RESPONSE_LOCAL_NAME);
|
||||
Text responseText = document.createTextNode(echo);
|
||||
responseElement.appendChild(responseText);
|
||||
|
||||
return responseElement;
|
||||
}
|
||||
}
|
||||
|
||||
9
echo/server/src/main/resources/application.yml
Normal file
9
echo/server/src/main/resources/application.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
logging:
|
||||
level:
|
||||
org.springframework:
|
||||
ws: TRACE
|
||||
web: TRACE
|
||||
xml: DEBUG
|
||||
spring:
|
||||
webservices:
|
||||
path: /echo-server
|
||||
@@ -1,7 +0,0 @@
|
||||
log4j.rootLogger=WARN, stdout
|
||||
log4j.logger.org.springframework.ws=DEBUG
|
||||
log4j.logger.org.springframework.xml=DEBUG
|
||||
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
|
||||
@@ -16,60 +16,56 @@
|
||||
|
||||
package org.springframework.ws.samples.echo.ws;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.ws.samples.echo.service.EchoService;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
public class EchoEndpointTest {
|
||||
|
||||
private EchoEndpoint endpoint;
|
||||
private EchoEndpoint endpoint;
|
||||
|
||||
private Document requestDocument;
|
||||
private Document requestDocument;
|
||||
|
||||
private Document responseDocument;
|
||||
private Document responseDocument;
|
||||
|
||||
private EchoService mock;
|
||||
private EchoService echoServiceMock;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
requestDocument = documentBuilder.newDocument();
|
||||
responseDocument = documentBuilder.newDocument();
|
||||
mock = createMock(EchoService.class);
|
||||
endpoint = new EchoEndpoint(mock);
|
||||
}
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
|
||||
@Test
|
||||
public void testInvokeInternal() throws Exception {
|
||||
Element echoRequest =
|
||||
requestDocument.createElementNS(EchoEndpoint.NAMESPACE_URI, EchoEndpoint.ECHO_REQUEST_LOCAL_NAME);
|
||||
String content = "ABC";
|
||||
Text requestText = requestDocument.createTextNode(content);
|
||||
echoRequest.appendChild(requestText);
|
||||
String result = "DEF";
|
||||
expect(mock.echo(content)).andReturn(result);
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
requestDocument = documentBuilder.newDocument();
|
||||
responseDocument = documentBuilder.newDocument();
|
||||
echoServiceMock = mock(EchoService.class);
|
||||
endpoint = new EchoEndpoint(echoServiceMock);
|
||||
}
|
||||
|
||||
replay(mock);
|
||||
@Test
|
||||
public void testInvokeInternal() throws Exception {
|
||||
|
||||
Element echoResponse = endpoint.handleEchoRequest(echoRequest);
|
||||
Assert.assertEquals("Invalid namespace", EchoEndpoint.NAMESPACE_URI, echoResponse.getNamespaceURI());
|
||||
Assert.assertEquals("Invalid namespace", EchoEndpoint.ECHO_RESPONSE_LOCAL_NAME, echoResponse.getLocalName());
|
||||
Text responseText = (Text) echoResponse.getChildNodes().item(0);
|
||||
Assert.assertEquals("Invalid content", result, responseText.getNodeValue());
|
||||
Element echoRequest = requestDocument.createElementNS(EchoEndpoint.NAMESPACE_URI,
|
||||
EchoEndpoint.ECHO_REQUEST_LOCAL_NAME);
|
||||
Text requestText = requestDocument.createTextNode("ABC");
|
||||
echoRequest.appendChild(requestText);
|
||||
when(echoServiceMock.echo("ABC")).thenReturn("DEF");
|
||||
|
||||
verify(mock);
|
||||
}
|
||||
Element echoResponse = endpoint.handleEchoRequest(echoRequest);
|
||||
|
||||
}
|
||||
assertThat(echoResponse.getNamespaceURI()).isEqualTo(EchoEndpoint.NAMESPACE_URI);
|
||||
assertThat(echoResponse.getLocalName()).isEqualTo(EchoEndpoint.ECHO_RESPONSE_LOCAL_NAME);
|
||||
assertThat(echoResponse.getChildNodes().item(0).getNodeValue()).isEqualTo("DEF");
|
||||
|
||||
verify(echoServiceMock);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user