From 46e0c4c408b4bd61f5436bf98950fe07bc660e75 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Mon, 20 Dec 2010 09:56:31 +0000 Subject: [PATCH] Upgrade samples to new namespace --- .../DynamicWsdlBeanDefinitionParser.java | 37 ++++++-- .../echo/service/impl/EchoServiceImpl.java | 6 +- .../main/webapp/WEB-INF/spring-ws-servlet.xml | 89 ++++++------------- 3 files changed, 60 insertions(+), 72 deletions(-) diff --git a/core/src/main/java/org/springframework/ws/config/DynamicWsdlBeanDefinitionParser.java b/core/src/main/java/org/springframework/ws/config/DynamicWsdlBeanDefinitionParser.java index 5c50e4ee..83ac2c7b 100644 --- a/core/src/main/java/org/springframework/ws/config/DynamicWsdlBeanDefinitionParser.java +++ b/core/src/main/java/org/springframework/ws/config/DynamicWsdlBeanDefinitionParser.java @@ -25,9 +25,11 @@ import org.springframework.beans.factory.support.ManagedList; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition; +import org.springframework.xml.xsd.SimpleXsdSchema; import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection; import org.w3c.dom.Element; @@ -40,6 +42,9 @@ import org.w3c.dom.Element; */ class DynamicWsdlBeanDefinitionParser extends AbstractBeanDefinitionParser { + private static final boolean commonsSchemaPresent = ClassUtils.isPresent("org.apache.ws.commons.schema.XmlSchema", + DynamicWsdlBeanDefinitionParser.class.getClassLoader()); + @Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { Object source = parserContext.extractSource(element); @@ -60,16 +65,30 @@ class DynamicWsdlBeanDefinitionParser extends AbstractBeanDefinitionParser { addProperty(element, wsdlBuilder, "serviceName"); List schemas = DomUtils.getChildElementsByTagName(element, "xsd"); - RootBeanDefinition collectionDef = createBeanDefinition(CommonsXsdSchemaCollection.class, source); - collectionDef.getPropertyValues().addPropertyValue("inline", "true"); - ManagedList xsds = new ManagedList(); - xsds.setSource(source); - for (Element schema : schemas) { - xsds.add(schema.getAttribute("location")); + if (commonsSchemaPresent) { + RootBeanDefinition collectionDef = createBeanDefinition(CommonsXsdSchemaCollection.class, source); + collectionDef.getPropertyValues().addPropertyValue("inline", "true"); + ManagedList xsds = new ManagedList(); + xsds.setSource(source); + for (Element schema : schemas) { + xsds.add(schema.getAttribute("location")); + } + collectionDef.getPropertyValues().addPropertyValue("xsds", xsds); + String collectionName = parserContext.getReaderContext().registerWithGeneratedName(collectionDef); + wsdlBuilder.addPropertyReference("schemaCollection", collectionName); + } + else { + if (schemas.size() > 1) { + throw new IllegalArgumentException( + "Multiple elements requires Commons XMLSchema." + + "Please put Commons XMLSchema on the classpath."); + } + RootBeanDefinition schemaDef = createBeanDefinition(SimpleXsdSchema.class, source); + Element schema = schemas.iterator().next(); + schemaDef.getPropertyValues().addPropertyValue("xsd", schema.getAttribute("location")); + String schemaName = parserContext.getReaderContext().registerWithGeneratedName(schemaDef); + wsdlBuilder.addPropertyReference("schema", schemaName); } - collectionDef.getPropertyValues().addPropertyValue("xsds", xsds); - String collectionName = parserContext.getReaderContext().registerWithGeneratedName(collectionDef); - wsdlBuilder.addPropertyReference("schemaCollection", collectionName); return wsdlBuilder.getBeanDefinition(); } diff --git a/samples/echo/server/src/main/java/org/springframework/ws/samples/echo/service/impl/EchoServiceImpl.java b/samples/echo/server/src/main/java/org/springframework/ws/samples/echo/service/impl/EchoServiceImpl.java index 3f106550..954b9a3f 100755 --- a/samples/echo/server/src/main/java/org/springframework/ws/samples/echo/service/impl/EchoServiceImpl.java +++ b/samples/echo/server/src/main/java/org/springframework/ws/samples/echo/service/impl/EchoServiceImpl.java @@ -1,11 +1,11 @@ /* - * Copyright 2006 the original author or authors. + * Copyright 2005-2010 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 + * 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, @@ -16,6 +16,7 @@ package org.springframework.ws.samples.echo.service.impl; +import org.springframework.stereotype.Service; import org.springframework.ws.samples.echo.service.EchoService; /** @@ -24,6 +25,7 @@ import org.springframework.ws.samples.echo.service.EchoService; * @author Ingo Siebert * @author Arjen Poutsma */ +@Service public class EchoServiceImpl implements EchoService { public String echo(String s) { diff --git a/samples/echo/server/src/main/webapp/WEB-INF/spring-ws-servlet.xml b/samples/echo/server/src/main/webapp/WEB-INF/spring-ws-servlet.xml index 4c4cb168..9a63b52e 100755 --- a/samples/echo/server/src/main/webapp/WEB-INF/spring-ws-servlet.xml +++ b/samples/echo/server/src/main/webapp/WEB-INF/spring-ws-servlet.xml @@ -1,73 +1,40 @@ - + 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. - - - This endpoint mapping uses the qualified name of the payload (body contents) to determine the endpoint for - an incoming message. Every message is passed to the default endpoint. Additionally, messages are logged - using the logging interceptor. - - - - - - - - + - - - This interceptor validates both incoming and outgoing message contents according to the 'echo.xsd' XML - Schema file. - - - - - + - + + + + This interceptor validates both incoming and outgoing message contents according to the 'echo.xsd' XML + Schema file. + + + + + + + + This interceptor logs the message payload. + + + - - - This interceptor logs the message payload. - - - - - - This endpoint handles echo requests. - - - - - - - This bean definition represents a WSDL definition that is generated at runtime. It can be retrieved by - going to /echo/echo.wsdl (i.e. the bean name corresponds to the filename). - - - - - - - - - This bean definition contains the XSD schema. - - - - - - - This bean is our "business" service. - - + + + \ No newline at end of file