Reworked echo sample to code config
Echo Sample now uses Javaconfig instead of XML.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
ext.springWsVersion = '2.2.0.BUILD-SNAPSHOT'
|
||||
|
||||
subprojects {
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'eclipse'
|
||||
@@ -5,6 +7,7 @@ subprojects {
|
||||
|
||||
repositories {
|
||||
maven { url 'http://repo.spring.io/libs-release' }
|
||||
maven { url 'http://repo.spring.io/libs-snapshot' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -13,7 +16,3 @@ subprojects {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion = '1.8'
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
ext.springWsVersion = '2.1.4.RELEASE'
|
||||
|
||||
dependencies {
|
||||
compile("org.springframework.ws:spring-ws-core:$springWsVersion")
|
||||
runtime("log4j:log4j:1.2.16")
|
||||
@@ -8,4 +6,4 @@ dependencies {
|
||||
task runClient(dependsOn: 'classes', type:JavaExec) {
|
||||
main = "org.springframework.ws.samples.echo.client.sws.EchoClient"
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import javax.xml.transform.Source;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
|
||||
import org.springframework.xml.transform.ResourceSource;
|
||||
@@ -44,9 +45,11 @@ public class EchoClient extends WebServiceGatewaySupport {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
ApplicationContext applicationContext =
|
||||
new ClassPathXmlApplicationContext("applicationContext.xml", EchoClient.class);
|
||||
EchoClient echoClient = (EchoClient) applicationContext.getBean("echoClient");
|
||||
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"));
|
||||
|
||||
echoClient.echo();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean id="echoClient" class="org.springframework.ws.samples.echo.client.sws.EchoClient">
|
||||
<property name="defaultUri" value="http://localhost:8080/echo-server/services"/>
|
||||
<property name="request" value="classpath:org/springframework/ws/samples/echo/client/sws/echoRequest.xml"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1,31 +1,38 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url 'http://repo.springsource.org/plugins-release' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:0.9.9'
|
||||
classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:0.9.9'
|
||||
}
|
||||
}
|
||||
|
||||
ext.springVersion = '3.2.4.RELEASE'
|
||||
ext.springWsVersion = '2.1.4.RELEASE'
|
||||
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'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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 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;
|
||||
import org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor;
|
||||
import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
|
||||
import org.springframework.xml.xsd.SimpleXsdSchema;
|
||||
|
||||
/**
|
||||
* Configuration class for the Echo sample.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
@EnableWs
|
||||
@Configuration
|
||||
@ComponentScan("org.springframework.ws.samples.echo")
|
||||
public class EchoConfig extends WsConfigurerAdapter {
|
||||
|
||||
@Bean
|
||||
public SimpleXsdSchema echoXsd() {
|
||||
return new SimpleXsdSchema(new ClassPathResource("echo.xsd"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptors(List<EndpointInterceptor> interceptors) {
|
||||
PayloadValidatingInterceptor validatingInterceptor = new PayloadValidatingInterceptor();
|
||||
validatingInterceptor.setXsdSchema(echoXsd());
|
||||
validatingInterceptor.setValidateRequest(true);
|
||||
validatingInterceptor.setValidateResponse(true);
|
||||
interceptors.add(validatingInterceptor);
|
||||
|
||||
interceptors.add(new PayloadLoggingInterceptor());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DefaultWsdl11Definition echo() {
|
||||
DefaultWsdl11Definition definition = new DefaultWsdl11Definition();
|
||||
definition.setPortTypeName("Echo");
|
||||
definition.setLocationUri("http://localhost:8080/echo/services");
|
||||
definition.setSchema(echoXsd());
|
||||
|
||||
return definition;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="qualified"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/samples/echo"
|
||||
xmlns:tns="http://www.springframework.org/spring-ws/samples/echo">
|
||||
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
|
||||
attributeFormDefault="qualified"
|
||||
targetNamespace="http://www.springframework.org/spring-ws/samples/echo">
|
||||
|
||||
<element name="echoRequest">
|
||||
<simpleType>
|
||||
0
echo/server/src/main/webapp/EMTPY
Normal file
0
echo/server/src/main/webapp/EMTPY
Normal file
@@ -1,40 +0,0 @@
|
||||
<?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"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
|
||||
<description>
|
||||
This web application context contains Spring-WS beans. The beans defined in this context are automatically
|
||||
detected by Spring-WS, similar to the way Controllers are picked up in Spring Web MVC.
|
||||
</description>
|
||||
|
||||
<context:component-scan base-package="org.springframework.ws.samples.echo"/>
|
||||
|
||||
<sws:annotation-driven />
|
||||
|
||||
<sws:interceptors>
|
||||
<bean class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
|
||||
<description>
|
||||
This interceptor validates both incoming and outgoing message contents according to the 'echo.xsd' XML
|
||||
Schema file.
|
||||
</description>
|
||||
<property name="schema" value="/WEB-INF/echo.xsd"/>
|
||||
<property name="validateRequest" value="true"/>
|
||||
<property name="validateResponse" value="true"/>
|
||||
</bean>
|
||||
<bean class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor">
|
||||
<description>
|
||||
This interceptor logs the message payload.
|
||||
</description>
|
||||
</bean>
|
||||
</sws:interceptors>
|
||||
|
||||
<sws:dynamic-wsdl id="echo" portTypeName="Echo" locationUri="http://localhost:8080/echo/services">
|
||||
<sws:xsd location="/WEB-INF/echo.xsd"/>
|
||||
</sws:dynamic-wsdl>
|
||||
|
||||
</beans>
|
||||
@@ -1,30 +0,0 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
|
||||
<!DOCTYPE web-app PUBLIC
|
||||
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
|
||||
"http://java.sun.com/dtd/web-app_2_3.dtd">
|
||||
|
||||
<web-app>
|
||||
<display-name>
|
||||
"Echo" WebService
|
||||
</display-name>
|
||||
<description>Returns a given string(only A-Z and a-z chars allowed). See echo.xsd file.</description>
|
||||
|
||||
<!-- Defines the Spring-WS MessageDispatcherServlet -->
|
||||
<servlet>
|
||||
<servlet-name>spring-ws</servlet-name>
|
||||
<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
|
||||
<init-param>
|
||||
<!-- Transform the location attributes in WSDLs -->
|
||||
<param-name>transformWsdlLocations</param-name>
|
||||
<param-value>true</param-value>
|
||||
</init-param>
|
||||
</servlet>
|
||||
|
||||
<!-- Map all requests to this servlet -->
|
||||
<servlet-mapping>
|
||||
<servlet-name>spring-ws</servlet-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
</web-app>
|
||||
Reference in New Issue
Block a user