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:
Greg L. Turnquist
2020-06-22 09:44:38 -05:00
parent 29b50cc066
commit 27b18118c1
186 changed files with 5247 additions and 5200 deletions

View File

@@ -1,4 +0,0 @@
task runClient(dependsOn: 'classes', type:JavaExec) {
main = "org.springframework.ws.samples.echo.client.saaj.EchoClient"
classpath = sourceSets.main.runtimeClasspath
}

48
echo/client/saaj/pom.xml Normal file
View File

@@ -0,0 +1,48 @@
<?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.ws</groupId>
<artifactId>spring-ws-samples</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<relativePath>../../../</relativePath> <!-- lookup parent from repository -->
</parent>
<artifactId>echo-client-saaj</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Spring Web Services Samples - Echo - Client - SAAJ</name>
<description>Demo project for Spring Web Services</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@@ -16,7 +16,6 @@
package org.springframework.ws.samples.echo.client.saaj;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
@@ -29,8 +28,9 @@ import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFault;
import javax.xml.soap.SOAPMessage;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A client for the Echo Web Service that uses SAAJ.
@@ -40,64 +40,57 @@ import javax.xml.transform.TransformerFactory;
*/
public class EchoClient {
public static final String NAMESPACE_URI = "http://www.springframework.org/spring-ws/samples/echo";
public static final String NAMESPACE_URI = "http://www.springframework.org/spring-ws/samples/echo";
public static final String PREFIX = "tns";
public static final String PREFIX = "tns";
private SOAPConnectionFactory connectionFactory;
private static final Logger logger = LoggerFactory.getLogger(EchoClient.class);
private MessageFactory messageFactory;
private SOAPConnectionFactory connectionFactory;
private URL url;
private MessageFactory messageFactory;
public EchoClient(String url) throws SOAPException, MalformedURLException {
connectionFactory = SOAPConnectionFactory.newInstance();
messageFactory = MessageFactory.newInstance();
this.url = new URL(url);
}
private URL url;
private SOAPMessage createEchoRequest() throws SOAPException {
SOAPMessage message = messageFactory.createMessage();
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
Name echoRequestName = envelope.createName("echoRequest", PREFIX, NAMESPACE_URI);
SOAPBodyElement echoRequestElement = message.getSOAPBody()
.addBodyElement(echoRequestName);
echoRequestElement.setValue("Hello");
return message;
}
public EchoClient(String url) throws SOAPException, MalformedURLException {
public void callWebService() throws SOAPException, IOException {
SOAPMessage request = createEchoRequest();
SOAPConnection connection = connectionFactory.createConnection();
SOAPMessage response = connection.call(request, url);
if (!response.getSOAPBody().hasFault()) {
writeEchoResponse(response);
}
else {
SOAPFault fault = response.getSOAPBody().getFault();
System.err.println("Received SOAP Fault");
System.err.println("SOAP Fault Code :" + fault.getFaultCode());
System.err.println("SOAP Fault String :" + fault.getFaultString());
}
}
connectionFactory = SOAPConnectionFactory.newInstance();
messageFactory = MessageFactory.newInstance();
this.url = new URL(url);
}
private void writeEchoResponse(SOAPMessage message) throws SOAPException {
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
Name echoResponseName = envelope.createName("echoResponse", PREFIX, NAMESPACE_URI);
SOAPBodyElement echoResponseElement = (SOAPBodyElement) message
.getSOAPBody().getChildElements(echoResponseName).next();
String echoValue = echoResponseElement.getTextContent();
System.out.println();
System.out.println("Echo Response [" + echoValue + "]");
System.out.println();
}
private SOAPMessage createEchoRequest() throws SOAPException {
public static void main(String[] args) throws Exception {
String url = "http://localhost:8080/echo-server/services";
if (args.length > 0) {
url = args[0];
}
EchoClient echoClient = new EchoClient(url);
echoClient.callWebService();
}
}
SOAPMessage message = messageFactory.createMessage();
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
Name echoRequestName = envelope.createName("echoRequest", PREFIX, NAMESPACE_URI);
SOAPBodyElement echoRequestElement = message.getSOAPBody().addBodyElement(echoRequestName);
echoRequestElement.setValue("Hello");
return message;
}
public void callWebService() throws SOAPException {
SOAPMessage request = createEchoRequest();
SOAPConnection connection = connectionFactory.createConnection();
SOAPMessage response = connection.call(request, url);
if (!response.getSOAPBody().hasFault()) {
writeEchoResponse(response);
} else {
SOAPFault fault = response.getSOAPBody().getFault();
logger.error("Received SOAP Fault");
logger.error("SOAP Fault Code :" + fault.getFaultCode());
logger.error("SOAP Fault String :" + fault.getFaultString());
}
}
private void writeEchoResponse(SOAPMessage message) throws SOAPException {
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
Name echoResponseName = envelope.createName("echoResponse", PREFIX, NAMESPACE_URI);
SOAPBodyElement echoResponseElement = (SOAPBodyElement) message.getSOAPBody().getChildElements(echoResponseName)
.next();
String echoValue = echoResponseElement.getTextContent();
logger.info("Echo Response [" + echoValue + "]");
}
}

View File

@@ -0,0 +1,24 @@
package org.springframework.ws.samples.echo.client.saaj;
import java.net.MalformedURLException;
import javax.xml.soap.SOAPException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SaajEchoClient {
public static void main(String[] args) throws MalformedURLException, SOAPException {
SpringApplication.run(SaajEchoClient.class);
String url = "http://localhost:8080/echo-server/services";
if (args.length > 0) {
url = args[0];
}
EchoClient echoClient = new EchoClient(url);
echoClient.callWebService();
}
}

View File

@@ -1,9 +0,0 @@
dependencies {
compile("org.springframework.ws:spring-ws-core:$springWsVersion")
runtime("log4j:log4j:1.2.16")
}
task runClient(dependsOn: 'classes', type:JavaExec) {
main = "org.springframework.ws.samples.echo.client.sws.EchoClient"
classpath = sourceSets.main.runtimeClasspath
}

View File

@@ -0,0 +1,49 @@
<?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.ws</groupId>
<artifactId>spring-ws-samples</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<relativePath>../../../</relativePath> <!-- lookup parent from repository -->
</parent>
<groupId>org.springframework.ws</groupId>
<artifactId>echo-client-spring-ws</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Spring Web Services Samples - Echo - Client - Spring WS</name>
<description>Demo project for Spring Web Services</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@@ -17,40 +17,34 @@
package org.springframework.ws.samples.echo.client.sws;
import java.io.IOException;
import javax.xml.transform.Source;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
import org.springframework.xml.transform.ResourceSource;
import org.springframework.xml.transform.StringResult;
@Service
public class EchoClient extends WebServiceGatewaySupport {
private Resource request;
private static final Logger logger = LoggerFactory.getLogger(EchoClient.class);
public void setRequest(Resource request) {
this.request = request;
}
private Resource request;
public void echo() throws IOException {
Source requestSource = new ResourceSource(request);
StringResult result = new StringResult();
getWebServiceTemplate().sendSourceAndReceiveToResult(requestSource, result);
System.out.println();
System.out.println(result);
System.out.println();
}
public void setRequest(Resource request) {
this.request = request;
}
public static void main(String[] args) throws IOException {
EchoClient echoClient = new EchoClient();
echoClient.setDefaultUri("http://localhost:8080/echo-server/services");
echoClient.setRequest(new ClassPathResource(
"org/springframework/ws/samples/echo/client/sws/echoRequest.xml"));
public void echo() throws IOException {
echoClient.echo();
}
Source requestSource = new ResourceSource(request);
StringResult result = new StringResult();
getWebServiceTemplate().sendSourceAndReceiveToResult(requestSource, result);
logger.info(result.toString());
}
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2007 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.client.sws;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ClassPathResource;
@SpringBootApplication
public class SpringWsEchoClient {
public static void main(String[] args) {
SpringApplication.run(SpringWsEchoClient.class, args);
}
@Bean
CommandLineRunner invoke(EchoClient echoClient) {
return args -> {
echoClient.setDefaultUri("http://localhost:8080/echo-server/services");
echoClient.setRequest(new ClassPathResource("echoRequest.xml"));
echoClient.echo();
};
}
}

View File

@@ -0,0 +1,6 @@
logging:
level:
org.springframework:
ws: TRACE
web: TRACE
xml: DEBUG

View File

@@ -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