Reworked echo sample to code config

Echo Sample now uses Javaconfig instead of XML.
This commit is contained in:
Arjen Poutsma
2014-03-26 15:23:28 +01:00
parent 44d15e5f74
commit bdcf6e608d
11 changed files with 136 additions and 98 deletions

View File

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

View File

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

View File

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

View File

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

View File

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