Added WSDL4J support for Wsdl definitions
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?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/maven-v4_0_0.xsd">
|
||||
<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/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<artifactId>spring-ws</artifactId>
|
||||
<groupId>org.springframework.ws</groupId>
|
||||
@@ -83,6 +84,11 @@
|
||||
<groupId>com.sun.xml.messaging.saaj</groupId>
|
||||
<artifactId>saaj-impl</artifactId>
|
||||
</dependency>
|
||||
<!-- WSDL dependencies -->
|
||||
<dependency>
|
||||
<groupId>wsdl4j</groupId>
|
||||
<artifactId>wsdl4j</artifactId>
|
||||
</dependency>
|
||||
<!-- JEE dependencies -->
|
||||
<dependency>
|
||||
<groupId>javax.xml.soap</groupId>
|
||||
|
||||
@@ -37,7 +37,17 @@ public class SimpleWsdl11Definition implements Wsdl11Definition, InitializingBea
|
||||
|
||||
private Resource wsdlResource;
|
||||
|
||||
public void setWsdl(Resource wsdlResource) {
|
||||
/**
|
||||
* Constructs a new <code>SimpleWsdl11Definition</code>. Calling <code>setWsdl</code> is required.
|
||||
*
|
||||
* @see #setWsdl(org.springframework.core.io.Resource)
|
||||
*/
|
||||
public SimpleWsdl11Definition() {
|
||||
}
|
||||
|
||||
/** Constructs a new <code>SimpleWsdl11Definition</code> with the given resource. */
|
||||
public SimpleWsdl11Definition(Resource wsdlResource) {
|
||||
Assert.notNull(wsdlResource, "wsdlResource must not be null");
|
||||
this.wsdlResource = wsdlResource;
|
||||
}
|
||||
|
||||
@@ -54,4 +64,8 @@ public class SimpleWsdl11Definition implements Wsdl11Definition, InitializingBea
|
||||
throw new WsdlDefinitionException("Could not create source from " + wsdlResource, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void setWsdl(Resource wsdlResource) {
|
||||
this.wsdlResource = wsdlResource;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright 2006 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.wsdl.wsdl11;
|
||||
|
||||
import javax.wsdl.Definition;
|
||||
import javax.wsdl.WSDLException;
|
||||
import javax.wsdl.factory.WSDLFactory;
|
||||
import javax.wsdl.xml.WSDLWriter;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.wsdl.WsdlDefinitionException;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
/**
|
||||
* Implementation of the <code>Wsdl11Definition</code> based on WSDL4J. A {@link javax.wsdl.Definition} can be given as
|
||||
* as constructor argument, or set using a property.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see #Wsdl4jDefinition(javax.wsdl.Definition)
|
||||
* @see #setDefinition(javax.wsdl.Definition)
|
||||
*/
|
||||
public class Wsdl4jDefinition implements Wsdl11Definition {
|
||||
|
||||
private Definition definition;
|
||||
|
||||
/**
|
||||
* Constructs a new, empty <code>Wsdl4jDefinition</code>.
|
||||
*
|
||||
* @see #setDefinition(javax.wsdl.Definition)
|
||||
*/
|
||||
public Wsdl4jDefinition() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new <code>Wsdl4jDefinition</code> based on the given <code>Definition</code>.
|
||||
*
|
||||
* @param definition the WSDL4J definition
|
||||
*/
|
||||
public Wsdl4jDefinition(Definition definition) {
|
||||
this.definition = definition;
|
||||
}
|
||||
|
||||
/** Returns the WSDL4J <code>Definition</code>. */
|
||||
public Definition getDefinition() {
|
||||
return definition;
|
||||
}
|
||||
|
||||
/** Set the WSDL4J <code>Definition</code>. */
|
||||
public void setDefinition(Definition definition) {
|
||||
this.definition = definition;
|
||||
}
|
||||
|
||||
public Source getSource() {
|
||||
Assert.notNull(definition, "definition must not be null");
|
||||
try {
|
||||
WSDLFactory wsdlFactory = WSDLFactory.newInstance();
|
||||
WSDLWriter wsdlWriter = wsdlFactory.newWSDLWriter();
|
||||
Document document = wsdlWriter.getDocument(definition);
|
||||
return new DOMSource(document);
|
||||
}
|
||||
catch (WSDLException ex) {
|
||||
throw new WsdlDefinitionException(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2006 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.wsdl.wsdl11;
|
||||
|
||||
import java.io.InputStream;
|
||||
import javax.wsdl.Definition;
|
||||
import javax.wsdl.factory.WSDLFactory;
|
||||
import javax.wsdl.xml.WSDLReader;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
public class Wsdl4jDefinitionTest extends XMLTestCase {
|
||||
|
||||
private Wsdl4jDefinition definition;
|
||||
|
||||
private Transformer transformer;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
WSDLFactory factory = WSDLFactory.newInstance();
|
||||
WSDLReader reader = factory.newWSDLReader();
|
||||
InputStream is = getClass().getResourceAsStream("complete.wsdl");
|
||||
try {
|
||||
Definition wsdl4jDefinition = reader.readWSDL(null, new InputSource(is));
|
||||
definition = new Wsdl4jDefinition(wsdl4jDefinition);
|
||||
}
|
||||
finally {
|
||||
is.close();
|
||||
}
|
||||
transformer = TransformerFactory.newInstance().newTransformer();
|
||||
}
|
||||
|
||||
public void testGetSource() throws Exception {
|
||||
Source source = definition.getSource();
|
||||
assertNotNull("Source is null", source);
|
||||
DOMResult result = new DOMResult();
|
||||
transformer.transform(source, result);
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document expected = documentBuilder.parse(getClass().getResourceAsStream("complete.wsdl"));
|
||||
assertXMLEqual(expected, (Document) result.getNode());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user