Skip to content

Commit 46e0c4c

Browse files
committed
Upgrade samples to new namespace
1 parent 596b824 commit 46e0c4c

File tree

3 files changed

+63
-75
lines changed

3 files changed

+63
-75
lines changed

core/src/main/java/org/springframework/ws/config/DynamicWsdlBeanDefinitionParser.java

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
import org.springframework.beans.factory.support.RootBeanDefinition;
2626
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
2727
import org.springframework.beans.factory.xml.ParserContext;
28+
import org.springframework.util.ClassUtils;
2829
import org.springframework.util.StringUtils;
2930
import org.springframework.util.xml.DomUtils;
3031
import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
32+
import org.springframework.xml.xsd.SimpleXsdSchema;
3133
import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection;
3234

3335
import org.w3c.dom.Element;
@@ -40,6 +42,9 @@
4042
*/
4143
class DynamicWsdlBeanDefinitionParser extends AbstractBeanDefinitionParser {
4244

45+
private static final boolean commonsSchemaPresent = ClassUtils.isPresent("org.apache.ws.commons.schema.XmlSchema",
46+
DynamicWsdlBeanDefinitionParser.class.getClassLoader());
47+
4348
@Override
4449
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
4550
Object source = parserContext.extractSource(element);
@@ -60,16 +65,30 @@ protected AbstractBeanDefinition parseInternal(Element element, ParserContext pa
6065
addProperty(element, wsdlBuilder, "serviceName");
6166

6267
List<Element> schemas = DomUtils.getChildElementsByTagName(element, "xsd");
63-
RootBeanDefinition collectionDef = createBeanDefinition(CommonsXsdSchemaCollection.class, source);
64-
collectionDef.getPropertyValues().addPropertyValue("inline", "true");
65-
ManagedList<String> xsds = new ManagedList<String>();
66-
xsds.setSource(source);
67-
for (Element schema : schemas) {
68-
xsds.add(schema.getAttribute("location"));
68+
if (commonsSchemaPresent) {
69+
RootBeanDefinition collectionDef = createBeanDefinition(CommonsXsdSchemaCollection.class, source);
70+
collectionDef.getPropertyValues().addPropertyValue("inline", "true");
71+
ManagedList<String> xsds = new ManagedList<String>();
72+
xsds.setSource(source);
73+
for (Element schema : schemas) {
74+
xsds.add(schema.getAttribute("location"));
75+
}
76+
collectionDef.getPropertyValues().addPropertyValue("xsds", xsds);
77+
String collectionName = parserContext.getReaderContext().registerWithGeneratedName(collectionDef);
78+
wsdlBuilder.addPropertyReference("schemaCollection", collectionName);
79+
}
80+
else {
81+
if (schemas.size() > 1) {
82+
throw new IllegalArgumentException(
83+
"Multiple <xsd/> elements requires Commons XMLSchema." +
84+
"Please put Commons XMLSchema on the classpath.");
85+
}
86+
RootBeanDefinition schemaDef = createBeanDefinition(SimpleXsdSchema.class, source);
87+
Element schema = schemas.iterator().next();
88+
schemaDef.getPropertyValues().addPropertyValue("xsd", schema.getAttribute("location"));
89+
String schemaName = parserContext.getReaderContext().registerWithGeneratedName(schemaDef);
90+
wsdlBuilder.addPropertyReference("schema", schemaName);
6991
}
70-
collectionDef.getPropertyValues().addPropertyValue("xsds", xsds);
71-
String collectionName = parserContext.getReaderContext().registerWithGeneratedName(collectionDef);
72-
wsdlBuilder.addPropertyReference("schemaCollection", collectionName);
7392
return wsdlBuilder.getBeanDefinition();
7493
}
7594

samples/echo/server/src/main/java/org/springframework/ws/samples/echo/service/impl/EchoServiceImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2006 the original author or authors.
2+
* Copyright 2005-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.ws.samples.echo.service.impl;
1818

19+
import org.springframework.stereotype.Service;
1920
import org.springframework.ws.samples.echo.service.EchoService;
2021

2122
/**
@@ -24,6 +25,7 @@
2425
* @author Ingo Siebert
2526
* @author Arjen Poutsma
2627
*/
28+
@Service
2729
public class EchoServiceImpl implements EchoService {
2830

2931
public String echo(String s) {
Lines changed: 31 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,40 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:sws="http://www.springframework.org/schema/web-services"
5+
xmlns:context="http://www.springframework.org/schema/context"
6+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
7+
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd
8+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
49

510
<description>
611
This web application context contains Spring-WS beans. The beans defined in this context are automatically
712
detected by Spring-WS, similar to the way Controllers are picked up in Spring Web MVC.
813
</description>
914

10-
<bean id="payloadMapping" class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping">
11-
<description>
12-
This endpoint mapping uses the qualified name of the payload (body contents) to determine the endpoint for
13-
an incoming message. Every message is passed to the default endpoint. Additionally, messages are logged
14-
using the logging interceptor.
15-
</description>
16-
<property name="interceptors">
17-
<list>
18-
<ref local="validatingInterceptor"/>
19-
<ref local="loggingInterceptor"/>
20-
</list>
21-
</property>
22-
</bean>
23-
24-
<bean id="validatingInterceptor"
25-
class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
26-
<description>
27-
This interceptor validates both incoming and outgoing message contents according to the 'echo.xsd' XML
28-
Schema file.
29-
</description>
30-
<property name="xsdSchema" ref="schema"/>
31-
<property name="validateRequest" value="true"/>
32-
<property name="validateResponse" value="true"/>
33-
</bean>
34-
35-
<bean class="org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter"/>
36-
37-
<bean id="loggingInterceptor" class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor">
38-
<description>
39-
This interceptor logs the message payload.
40-
</description>
41-
</bean>
42-
43-
<bean id="echoEndpoint" class="org.springframework.ws.samples.echo.ws.EchoEndpoint">
44-
<description>
45-
This endpoint handles echo requests.
46-
</description>
47-
<constructor-arg ref="echoService"/>
48-
</bean>
49-
50-
<bean id="echo" class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
51-
<description>
52-
This bean definition represents a WSDL definition that is generated at runtime. It can be retrieved by
53-
going to /echo/echo.wsdl (i.e. the bean name corresponds to the filename).
54-
</description>
55-
<property name="schema" ref="schema"/>
56-
<property name="portTypeName" value="Echo"/>
57-
<property name="locationUri" value="http://localhost:8080/echo/services"/>
58-
</bean>
59-
60-
<bean id="schema" class="org.springframework.xml.xsd.SimpleXsdSchema">
61-
<description>
62-
This bean definition contains the XSD schema.
63-
</description>
64-
<property name="xsd" value="/WEB-INF/echo.xsd"/>
65-
</bean>
66-
67-
<bean id="echoService" class="org.springframework.ws.samples.echo.service.impl.EchoServiceImpl">
68-
<description>
69-
This bean is our "business" service.
70-
</description>
71-
</bean>
15+
<context:component-scan base-package="org.springframework.ws.samples.echo"/>
16+
17+
<sws:annotation-driven />
18+
19+
<sws:interceptors>
20+
<bean class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
21+
<description>
22+
This interceptor validates both incoming and outgoing message contents according to the 'echo.xsd' XML
23+
Schema file.
24+
</description>
25+
<property name="schema" value="/WEB-INF/echo.xsd"/>
26+
<property name="validateRequest" value="true"/>
27+
<property name="validateResponse" value="true"/>
28+
</bean>
29+
<bean class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor">
30+
<description>
31+
This interceptor logs the message payload.
32+
</description>
33+
</bean>
34+
</sws:interceptors>
35+
36+
<sws:dynamic-wsdl id="echo" portTypeName="Echo" locationUri="http://localhost:8080/echo/services">
37+
<sws:xsd location="/WEB-INF/echo.xsd"/>
38+
</sws:dynamic-wsdl>
7239

7340
</beans>

0 commit comments

Comments
 (0)