Moved new WSDL design over from sandbox

This commit is contained in:
Arjen Poutsma
2008-03-08 03:07:16 +00:00
parent 0bfbe2f2a0
commit c425dc8ba3
45 changed files with 40 additions and 427 deletions

View File

@@ -0,0 +1,172 @@
/*
* Copyright 2008 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.util.Properties;
import javax.xml.transform.Source;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.StringUtils;
import org.springframework.ws.wsdl.wsdl11.provider.DefaultMessagesProvider;
import org.springframework.ws.wsdl.wsdl11.provider.InliningXsdSchemaTypesProvider;
import org.springframework.ws.wsdl.wsdl11.provider.SoapProvider;
import org.springframework.ws.wsdl.wsdl11.provider.SuffixBasedPortTypesProvider;
import org.springframework.xml.xsd.XsdSchema;
import org.springframework.xml.xsd.XsdSchemaCollection;
/**
* Convenient implementation of {@link Wsdl11Definition} that creates a SOAP 1.1 or 1.2 binding based on naming
* conventions in one or more inlined XSD schemas. Delegates to {@link InliningXsdSchemaTypesProvider}, {@link
* DefaultMessagesProvider}, {@link SuffixBasedPortTypesProvider}, {@link SoapProvider} underneath; effectively
* equivalent to using a {@link ProviderBasedWsdl4jDefinition} with all these providers.
* <p/>
* Example configuration:
* <pre>
* &lt;bean id=&quot;airline&quot; class=&quot;org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition&quot;&gt;
* &lt;property name=&quot;schema&quot;&gt;
* &lt;bean class=&quot;org.springframework.xml.xsd.SimpleXsdSchema&quot;&gt;
* &lt;property name=&quot;xsd&quot; value=&quot;/WEB-INF/airline.xsd&quot;/&gt;
* &lt;/bean&gt;
* &lt;/property&gt;
* &lt;property name=&quot;portTypeName&quot; value=&quot;Airline&quot;/&gt;
* &lt;property name=&quot;locationUri&quot; value=&quot;http://localhost:8080/airline/services&quot;/&gt;
* &lt;/bean&gt;
* </pre>
*
* @author Arjen Poutsma
* @since 1.5.0
*/
public class DefaultWsdl11Definition implements Wsdl11Definition, InitializingBean {
private final InliningXsdSchemaTypesProvider typesProvider = new InliningXsdSchemaTypesProvider();
private final DefaultMessagesProvider messagesProvider = new DefaultMessagesProvider();
private final SuffixBasedPortTypesProvider portTypesProvider = new SuffixBasedPortTypesProvider();
private final SoapProvider soapProvider = new SoapProvider();
private final ProviderBasedWsdl4jDefinition delegate = new ProviderBasedWsdl4jDefinition();
private String serviceName;
/** Creates a new instance of the {@link DefaultWsdl11Definition}. */
public DefaultWsdl11Definition() {
delegate.setTypesProvider(typesProvider);
delegate.setMessagesProvider(messagesProvider);
delegate.setPortTypesProvider(portTypesProvider);
delegate.setBindingsProvider(soapProvider);
delegate.setServicesProvider(soapProvider);
}
/**
* Sets the target namespace used for this definition.
* <p/>
* Defaults to the target namespace of the defined schema.
*/
public void setTargetNamespace(String targetNamespace) {
delegate.setTargetNamespace(targetNamespace);
}
/**
* Sets the single XSD schema to inline. Either this property, or {@link #setSchemaCollection(XsdSchemaCollection)
* schemaCollection} must be set.
*/
public void setSchema(final XsdSchema schema) {
typesProvider.setSchema(schema);
}
/**
* Sets the XSD schema collection to inline. Either this property, or {@link #setSchema(XsdSchema) schema} must be
* set.
*/
public void setSchemaCollection(XsdSchemaCollection schemaCollection) {
typesProvider.setSchemaCollection(schemaCollection);
}
/** Sets the port type name used for this definition. Required. */
public void setPortTypeName(String portTypeName) {
portTypesProvider.setPortTypeName(portTypeName);
}
/** Sets the suffix used to detect request elements in the schema. */
public void setRequestSuffix(String requestSuffix) {
portTypesProvider.setRequestSuffix(requestSuffix);
}
/** Sets the suffix used to detect response elements in the schema. */
public void setResponseSuffix(String responseSuffix) {
portTypesProvider.setResponseSuffix(responseSuffix);
}
/** Sets the suffix used to detect fault elements in the schema. */
public void setFaultSuffix(String faultSuffix) {
portTypesProvider.setFaultSuffix(faultSuffix);
}
/** Indicates whether a SOAP 1.1 binding should be created. */
public void setCreateSoap11Binding(boolean createSoap11Binding) {
soapProvider.setCreateSoap11Binding(createSoap11Binding);
}
/** Indicates whether a SOAP 1.2 binding should be created. */
public void setCreateSoap12Binding(boolean createSoap12Binding) {
soapProvider.setCreateSoap12Binding(createSoap12Binding);
}
/**
* Sets the SOAP Actions for this binding. Keys are {@link javax.wsdl.BindingOperation#getName() binding operation
* names}; values are {@link javax.wsdl.extensions.soap.SOAPOperation#getSoapActionURI() SOAP Action URIs}.
*
* @param soapActions the soap
*/
public void setSoapActions(Properties soapActions) {
soapProvider.setSoapActions(soapActions);
}
/** Sets the value used for the binding transport attribute value. Defaults to HTTP. */
public void setTransportUri(String transportUri) {
soapProvider.setTransportUri(transportUri);
}
/** Sets the value used for the SOAP Address location attribute value. */
public void setLocationUri(String locationUri) {
soapProvider.setLocationUri(locationUri);
}
/** Sets the service name. */
public void setServiceName(String serviceName) {
soapProvider.setServiceName(serviceName);
this.serviceName = serviceName;
}
public void afterPropertiesSet() throws Exception {
if (!StringUtils.hasText(delegate.getTargetNamespace()) && typesProvider.getSchemaCollection() != null &&
typesProvider.getSchemaCollection().getXsdSchemas().length > 0) {
XsdSchema schema = typesProvider.getSchemaCollection().getXsdSchemas()[0];
setTargetNamespace(schema.getTargetNamespace());
}
if (!StringUtils.hasText(serviceName) && StringUtils.hasText(portTypesProvider.getPortTypeName())) {
soapProvider.setServiceName(portTypesProvider.getPortTypeName() + "Service");
}
delegate.afterPropertiesSet();
}
public Source getSource() {
return delegate.getSource();
}
}

View File

@@ -0,0 +1,114 @@
/*
* Copyright 2008 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 org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
import org.springframework.ws.wsdl.wsdl11.provider.BindingsProvider;
import org.springframework.ws.wsdl.wsdl11.provider.ImportsProvider;
import org.springframework.ws.wsdl.wsdl11.provider.MessagesProvider;
import org.springframework.ws.wsdl.wsdl11.provider.PortTypesProvider;
import org.springframework.ws.wsdl.wsdl11.provider.ServicesProvider;
import org.springframework.ws.wsdl.wsdl11.provider.TypesProvider;
/**
* @author Arjen Poutsma
* @since 1.5.0
*/
public class ProviderBasedWsdl4jDefinition extends Wsdl4jDefinition implements InitializingBean {
/** The prefix used to register the target namespace in the WSDL. */
public static final String TARGET_NAMESPACE_PREFIX = "tns";
private ImportsProvider importsProvider;
private TypesProvider typesProvider;
private MessagesProvider messagesProvider;
private PortTypesProvider portTypesProvider;
private BindingsProvider bindingsProvider;
private ServicesProvider servicesProvider;
private String targetNamespace;
public void setImportsProvider(ImportsProvider importsProvider) {
this.importsProvider = importsProvider;
}
public void setTypesProvider(TypesProvider typesProvider) {
this.typesProvider = typesProvider;
}
public void setMessagesProvider(MessagesProvider messagesProvider) {
this.messagesProvider = messagesProvider;
}
public void setPortTypesProvider(PortTypesProvider portTypesProvider) {
this.portTypesProvider = portTypesProvider;
}
public void setBindingsProvider(BindingsProvider bindingsProvider) {
this.bindingsProvider = bindingsProvider;
}
public void setServicesProvider(ServicesProvider servicesProvider) {
this.servicesProvider = servicesProvider;
}
public String getTargetNamespace() {
return targetNamespace;
}
/** Sets the target namespace used for this definition. Required. */
public void setTargetNamespace(String targetNamespace) {
this.targetNamespace = targetNamespace;
}
public void afterPropertiesSet() throws WSDLException {
Assert.notNull(getTargetNamespace(), "'targetNamespace' is required");
WSDLFactory wsdlFactory = WSDLFactory.newInstance();
Definition definition = wsdlFactory.newDefinition();
definition.setTargetNamespace(getTargetNamespace());
definition.addNamespace(TARGET_NAMESPACE_PREFIX, getTargetNamespace());
if (importsProvider != null) {
importsProvider.addImports(definition);
}
if (typesProvider != null) {
typesProvider.addTypes(definition);
}
if (messagesProvider != null) {
messagesProvider.addMessages(definition);
}
if (portTypesProvider != null) {
portTypesProvider.addPortTypes(definition);
}
if (bindingsProvider != null) {
bindingsProvider.addBindings(definition);
}
if (servicesProvider != null) {
servicesProvider.addServices(definition);
}
setDefinition(definition);
}
}

View File

@@ -41,6 +41,8 @@ import javax.xml.namespace.QName;
*
* @author Arjen Poutsma
* @since 1.0.0
* @deprecated as of Spring Web Services 1.5: superseded by {@link org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition}
* and the {@link org.springframework.ws.wsdl.wsdl11.provider} package
*/
public abstract class AbstractBindingWsdl4jDefinitionBuilder extends AbstractWsdl4jDefinitionBuilder {

View File

@@ -45,6 +45,8 @@ import javax.xml.namespace.QName;
* @author Arjen Poutsma
* @see #setLocationUri(String)
* @since 1.0.0
* @deprecated as of Spring Web Services 1.5: superseded by {@link org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition}
* and the {@link org.springframework.ws.wsdl.wsdl11.provider} package
*/
public abstract class AbstractSoap11Wsdl4jDefinitionBuilder extends AbstractBindingWsdl4jDefinitionBuilder {

View File

@@ -46,6 +46,8 @@ import javax.xml.namespace.QName;
* @author Alex Marshall
* @see #setLocationUri(String)
* @since 1.5.0
* @deprecated as of Spring Web Services 1.5: superseded by {@link org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition}
* and the {@link org.springframework.ws.wsdl.wsdl11.provider} package
*/
public abstract class AbstractSoap12Wsdl4jDefinitionBuilder extends AbstractBindingWsdl4jDefinitionBuilder {
@@ -53,9 +55,7 @@ public abstract class AbstractSoap12Wsdl4jDefinitionBuilder extends AbstractBind
private static final String WSDL_SOAP_PREFIX = "soap12";
/**
* The default soap12:binding transport attribute value.
*/
/** The default soap12:binding transport attribute value. */
public static final String DEFAULT_TRANSPORT_URI = "http://schemas.xmlsoap.org/soap/http";
private String transportUri = DEFAULT_TRANSPORT_URI;
@@ -72,16 +72,12 @@ public abstract class AbstractSoap12Wsdl4jDefinitionBuilder extends AbstractBind
this.transportUri = transportUri;
}
/**
* Sets the value used for the soap12:address location attribute value.
*/
/** Sets the value used for the soap12:address location attribute value. */
public void setLocationUri(String locationUri) {
this.locationUri = locationUri;
}
/**
* Adds the WSDL SOAP namespace to the definition.
*/
/** Adds the WSDL SOAP namespace to the definition. */
protected void populateDefinition(Definition definition) throws WSDLException {
definition.addNamespace(WSDL_SOAP_PREFIX, WSDL_SOAP_NAMESPACE_URI);
}

View File

@@ -25,6 +25,7 @@ import javax.xml.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.ws.wsdl.WsdlDefinitionException;
import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition;
import org.springframework.ws.wsdl.wsdl11.Wsdl11DefinitionBuilder;
@@ -37,6 +38,8 @@ import org.springframework.ws.wsdl.wsdl11.Wsdl4jDefinitionException;
*
* @author Arjen Poutsma
* @since 1.0.0
* @deprecated as of Spring Web Services 1.5: superseded by {@link org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition}
* and the {@link org.springframework.ws.wsdl.wsdl11.provider} package
*/
public abstract class AbstractWsdl4jDefinitionBuilder implements Wsdl11DefinitionBuilder {

View File

@@ -82,6 +82,8 @@ import org.springframework.xml.namespace.QNameUtils;
* @see #setRequestSuffix(String)
* @see #setResponseSuffix(String)
* @since 1.0.0
* @deprecated as of Spring Web Services 1.5: superseded by {@link org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition}
* and the {@link org.springframework.ws.wsdl.wsdl11.provider} package
*/
public class XsdBasedSoap11Wsdl4jDefinitionBuilder extends AbstractSoap11Wsdl4jDefinitionBuilder
implements InitializingBean {

View File

@@ -83,6 +83,8 @@ import org.springframework.xml.namespace.QNameUtils;
* @see #setRequestSuffix(String)
* @see #setResponseSuffix(String)
* @since 1.5.0
* @deprecated as of Spring Web Services 1.5: superseded by {@link org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition}
* and the {@link org.springframework.ws.wsdl.wsdl11.provider} package
*/
public class XsdBasedSoap12Wsdl4jDefinitionBuilder extends AbstractSoap12Wsdl4jDefinitionBuilder
implements InitializingBean {
@@ -288,7 +290,7 @@ public class XsdBasedSoap12Wsdl4jDefinitionBuilder extends AbstractSoap12Wsdl4jD
definition.addNamespace(prefix, elementName.getNamespaceURI());
break;
}
i++;
i++;
}
}
Message message = definition.createMessage();

View File

@@ -26,23 +26,26 @@ import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.xml.namespace.QNameUtils;
import org.springframework.xml.sax.SaxUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.xml.namespace.QNameUtils;
import org.springframework.xml.sax.SaxUtils;
/**
* Helper class for dealing with XSD schemas. Exposes the target namespace, and the list of qualified names declared in
* a schema.
*
* @author Arjen Poutsma
* @since 1.0.2
* @deprecated as of Spring Web Services 1.5: superseded by {@link org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition}
* and the {@link org.springframework.ws.wsdl.wsdl11.provider} package
*/
class XsdSchemaHelper {

View File

@@ -1,5 +1,6 @@
<html>
<body>
Provides a strategy for WSDL building. Used by DynamicWsdl11Definition to generate WSDL definitions at runtime.
<strong>Deprecated</strong> as of Spring Web Services 1.5: superseded by the <code>DefaultWsdl11Definition</code>
and <code>org.springframework.ws.wsdl.wsdl11.provider</code> package.
</body>
</html>

View File

@@ -0,0 +1,232 @@
/*
* Copyright 2008 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.provider;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.wsdl.Definition;
import javax.wsdl.Fault;
import javax.wsdl.Input;
import javax.wsdl.Message;
import javax.wsdl.Operation;
import javax.wsdl.OperationType;
import javax.wsdl.Output;
import javax.wsdl.PortType;
import javax.wsdl.WSDLException;
import javax.xml.namespace.QName;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Abstract base class for {@link PortTypesProvider} implementations.
*
* @author Arjen Poutsma
* @since 1.5.0
*/
public abstract class AbstractPortTypesProvider implements PortTypesProvider {
private String portTypeName;
/** Returns the port type name used for this definition. */
public String getPortTypeName() {
return portTypeName;
}
/** Sets the port type name used for this definition. Required. */
public void setPortTypeName(String portTypeName) {
this.portTypeName = portTypeName;
}
/**
* Creates a single {@link PortType}, and calls {@link #populatePortType(Definition, PortType)} with it.
*
* @param definition the WSDL4J <code>Definition</code>
* @throws WSDLException in case of errors
*/
public void addPortTypes(Definition definition) throws WSDLException {
Assert.notNull(getPortTypeName(), "'portTypeName' is required");
PortType portType = definition.createPortType();
populatePortType(definition, portType);
createOperations(definition, portType);
portType.setUndefined(false);
definition.addPortType(portType);
}
/**
* Called after the {@link PortType} has been created.
* <p/>
* Default implementation sets the name of the port type to the defined value.
*
* @param portType the WSDL4J <code>PortType</code>
* @throws WSDLException in case of errors
* @see #setPortTypeName(String)
*/
protected void populatePortType(Definition definition, PortType portType) throws WSDLException {
portType.setQName(new QName(definition.getTargetNamespace(), getPortTypeName()));
}
private void createOperations(Definition definition, PortType portType) throws WSDLException {
Map operations = new HashMap();
for (Iterator iterator = definition.getMessages().values().iterator(); iterator.hasNext();) {
Message message = (Message) iterator.next();
String operationName = getOperationName(message);
if (StringUtils.hasText(operationName)) {
List messages = (List) operations.get(operationName);
if (messages == null) {
messages = new ArrayList();
operations.put(operationName, messages);
}
messages.add(message);
}
}
for (Iterator iterator = operations.keySet().iterator(); iterator.hasNext();) {
String operationName = (String) iterator.next();
Operation operation = definition.createOperation();
operation.setName(operationName);
List messages = (List) operations.get(operationName);
for (Iterator messagesIterator = messages.iterator(); messagesIterator.hasNext();) {
Message message = (Message) messagesIterator.next();
if (isInputMessage(message)) {
Input input = definition.createInput();
input.setMessage(message);
populateInput(definition, input);
operation.setInput(input);
}
else if (isOutputMessage(message)) {
Output output = definition.createOutput();
output.setMessage(message);
populateOutput(definition, output);
operation.setOutput(output);
}
else if (isFaultMessage(message)) {
Fault fault = definition.createFault();
fault.setMessage(message);
populateFault(definition, fault);
operation.addFault(fault);
}
}
operation.setStyle(getOperationType(operation));
operation.setUndefined(false);
portType.addOperation(operation);
}
}
/**
* Template method that returns the name of the operation coupled to the given {@link Message}. Subclasses can
* return <code>null</code> to indicate that a message should not be coupled to an operation.
*
* @param message the WSDL4J <code>Message</code>
* @return the operation name; or <code>null</code>
*/
protected abstract String getOperationName(Message message);
/**
* Indicates whether the given name name should be included as {@link Input} message in the definition.
*
* @param message the message
* @return <code>true</code> if to be included as input; <code>false</code> otherwise
*/
protected abstract boolean isInputMessage(Message message);
/**
* Called after the {@link javax.wsdl.Input} has been created, but it's added to the operation. Subclasses can
* override this method to define the input name.
* <p/>
* Default implementation sets the input name to the message name.
*
* @param definition the WSDL4J <code>Definition</code>
* @param input the WSDL4J <code>Input</code>
*/
protected void populateInput(Definition definition, Input input) {
input.setName(input.getMessage().getQName().getLocalPart());
}
/**
* Indicates whether the given name name should be included as {@link Output} message in the definition.
*
* @param message the message
* @return <code>true</code> if to be included as output; <code>false</code> otherwise
*/
protected abstract boolean isOutputMessage(Message message);
/**
* Called after the {@link javax.wsdl.Output} has been created, but it's added to the operation. Subclasses can
* override this method to define the output name.
* <p/>
* Default implementation sets the output name to the message name.
*
* @param definition the WSDL4J <code>Definition</code>
* @param output the WSDL4J <code>Output</code>
*/
protected void populateOutput(Definition definition, Output output) {
output.setName(output.getMessage().getQName().getLocalPart());
}
/**
* Indicates whether the given name name should be included as {@link Fault} message in the definition.
*
* @param message the message
* @return <code>true</code> if to be included as fault; <code>false</code> otherwise
*/
protected abstract boolean isFaultMessage(Message message);
/**
* Called after the {@link javax.wsdl.Fault} has been created, but it's added to the operation. Subclasses can
* override this method to define the fault name.
* <p/>
* Default implementation sets the fault name to the message name.
*
* @param definition the WSDL4J <code>Definition</code>
* @param fault the WSDL4J <code>Fault</code>
*/
protected void populateFault(Definition definition, Fault fault) {
fault.setName(fault.getMessage().getQName().getLocalPart());
}
/**
* Returns the {@link OperationType} for the given operation.
* <p/>
* Default implementation returns {@link OperationType#REQUEST_RESPONSE} if both input and output are set; {@link
* OperationType#ONE_WAY} if only input is set, or {@link OperationType#NOTIFICATION} if only output is set.
*
* @param operation the WSDL4J <code>Operation</code>
* @return the operation type for the operation
*/
protected OperationType getOperationType(Operation operation) {
if (operation.getInput() != null && operation.getOutput() != null) {
return OperationType.REQUEST_RESPONSE;
}
else if (operation.getInput() != null && operation.getOutput() == null) {
return OperationType.ONE_WAY;
}
else if (operation.getInput() == null && operation.getOutput() != null) {
return OperationType.NOTIFICATION;
}
else {
return null;
}
}
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2008 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.provider;
import javax.wsdl.Definition;
import javax.wsdl.WSDLException;
/**
* Strategy for adding {@link javax.wsdl.Binding}s to a {@link javax.wsdl.Definition}.
* <p/>
* Used by {@link org.springframework.ws.wsdl.wsdl11.ProviderBasedWsdl4jDefinition}.
*
* @author Arjen Poutsma
* @since 1.5.0
*/
public interface BindingsProvider {
void addBindings(Definition definition) throws WSDLException;
}

View File

@@ -0,0 +1,305 @@
/*
* Copyright 2008 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.provider;
import java.util.Iterator;
import javax.wsdl.Binding;
import javax.wsdl.BindingFault;
import javax.wsdl.BindingInput;
import javax.wsdl.BindingOperation;
import javax.wsdl.BindingOutput;
import javax.wsdl.Definition;
import javax.wsdl.Fault;
import javax.wsdl.Input;
import javax.wsdl.Operation;
import javax.wsdl.OperationType;
import javax.wsdl.Output;
import javax.wsdl.Port;
import javax.wsdl.PortType;
import javax.wsdl.Service;
import javax.wsdl.WSDLException;
import javax.xml.namespace.QName;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Default implementation of the {@link BindingsProvider} and {@link ServicesProvider} interfaces.
* <p/>
* Creates a <code>binding</code> that matches any present <code>portType</code>, and a service containing
* <code>port</code>s that match the <code>binding</code>s. Lets subclasses populate these through template methods. *
*
* @author Arjen Poutsma
* @since 1.5.0
*/
public class DefaultConcretePartProvider implements BindingsProvider, ServicesProvider {
private String bindingSuffix;
private String serviceName;
/** Returns the service name. */
public String getServiceName() {
return serviceName;
}
/** Sets the service name. */
public void setServiceName(String serviceName) {
Assert.hasText(serviceName, "'serviceName' must not be null");
this.serviceName = serviceName;
}
/** Returns the suffix to append to the port type name to obtain the binding name. */
public String getBindingSuffix() {
return bindingSuffix;
}
/** Sets the suffix to append to the port type name to obtain the binding name. */
public void setBindingSuffix(String bindingSuffix) {
Assert.hasText(bindingSuffix, "'bindingSuffix' must not be null");
this.bindingSuffix = bindingSuffix;
}
/**
* Creates a {@link Binding} for each {@link PortType} in the definition, and calls {@link
* #populateBinding(Definition,javax.wsdl.Binding)} with it. Creates a {@link BindingOperation} for each {@link
* Operation} in the port type, a {@link BindingInput} for each {@link Input} in the operation, etc.
* <p/>
* Calls the various <code>populate</code> methods with the created WSDL4J objects.
*
* @param definition the WSDL4J <code>Definition</code>
* @throws WSDLException in case of errors
* @see #populateBinding(Definition,javax.wsdl.Binding)
* @see #populateBindingOperation(Definition,javax.wsdl.BindingOperation)
* @see #populateBindingInput(Definition,javax.wsdl.BindingInput,javax.wsdl.Input)
* @see #populateBindingOutput(Definition,javax.wsdl.BindingOutput,javax.wsdl.Output)
* @see #populateBindingFault(Definition,javax.wsdl.BindingFault,javax.wsdl.Fault)
*/
public void addBindings(Definition definition) throws WSDLException {
for (Iterator iterator = definition.getPortTypes().values().iterator(); iterator.hasNext();) {
PortType portType = (PortType) iterator.next();
Binding binding = definition.createBinding();
binding.setPortType(portType);
populateBinding(definition, binding);
createBindingOperations(definition, binding);
binding.setUndefined(false);
if (binding.getQName() != null) {
definition.addBinding(binding);
}
}
}
/**
* Called after the {@link Binding} has been created, but before any sub-elements are added. Subclasses can override
* this method to define the binding name, or add extensions to it.
* <p/>
* Default implementation sets the binding name to the port type name with the {@link #getBindingSuffix() suffix}
* appended to it.
*
* @param definition the WSDL4J <code>Definition</code>
* @param binding the WSDL4J <code>Binding</code>
*/
protected void populateBinding(Definition definition, Binding binding) throws WSDLException {
QName portTypeName = binding.getPortType().getQName();
if (portTypeName != null) {
binding.setQName(
new QName(portTypeName.getNamespaceURI(), portTypeName.getLocalPart() + getBindingSuffix()));
}
}
private void createBindingOperations(Definition definition, Binding binding) throws WSDLException {
PortType portType = binding.getPortType();
for (Iterator operationIterator = portType.getOperations().iterator(); operationIterator.hasNext();) {
Operation operation = (Operation) operationIterator.next();
BindingOperation bindingOperation = definition.createBindingOperation();
bindingOperation.setOperation(operation);
populateBindingOperation(definition, bindingOperation);
if (OperationType.REQUEST_RESPONSE.equals(operation.getStyle())) {
createBindingInput(definition, operation, bindingOperation);
createBindingOutput(definition, operation, bindingOperation);
}
else if (OperationType.ONE_WAY.equals(operation.getStyle())) {
createBindingInput(definition, operation, bindingOperation);
}
else if (OperationType.NOTIFICATION.equals(operation.getStyle())) {
createBindingOutput(definition, operation, bindingOperation);
}
else if (OperationType.SOLICIT_RESPONSE.equals(operation.getStyle())) {
createBindingOutput(definition, operation, bindingOperation);
createBindingInput(definition, operation, bindingOperation);
}
for (Iterator faultIterator = operation.getFaults().values().iterator(); faultIterator.hasNext();) {
Fault fault = (Fault) faultIterator.next();
BindingFault bindingFault = definition.createBindingFault();
populateBindingFault(definition, bindingFault, fault);
if (StringUtils.hasText(bindingFault.getName())) {
bindingOperation.addBindingFault(bindingFault);
}
}
binding.addBindingOperation(bindingOperation);
}
}
/**
* Called after the {@link BindingOperation} has been created, but before any sub-elements are added. Subclasses can
* override this method to define the binding name, or add extensions to it.
* <p/>
* Default implementation sets the name of the binding operation to the name of the operation.
*
* @param definition the WSDL4J <code>Definition</code>
* @param bindingOperation the WSDL4J <code>BindingOperation</code>
* @throws WSDLException in case of errors
*/
protected void populateBindingOperation(Definition definition, BindingOperation bindingOperation)
throws WSDLException {
bindingOperation.setName(bindingOperation.getOperation().getName());
}
private void createBindingInput(Definition definition, Operation operation, BindingOperation bindingOperation)
throws WSDLException {
BindingInput bindingInput = definition.createBindingInput();
populateBindingInput(definition, bindingInput, operation.getInput());
bindingOperation.setBindingInput(bindingInput);
}
private void createBindingOutput(Definition definition, Operation operation, BindingOperation bindingOperation)
throws WSDLException {
BindingOutput bindingOutput = definition.createBindingOutput();
populateBindingOutput(definition, bindingOutput, operation.getOutput());
bindingOperation.setBindingOutput(bindingOutput);
}
/**
* Called after the {@link BindingInput} has been created. Subclasses can override this method to define the name,
* or add extensions to it.
* <p/>
* Default implementation set the name of the binding input to the name of the input.
*
* @param definition the WSDL4J <code>Definition</code>
* @param bindingInput the WSDL4J <code>BindingInput</code>
* @param input the corresponding WSDL4J <code>Input</code> @throws WSDLException in case of errors
*/
protected void populateBindingInput(Definition definition, BindingInput bindingInput, Input input)
throws WSDLException {
bindingInput.setName(input.getName());
}
/**
* Called after the {@link BindingOutput} has been created. Subclasses can override this method to define the name,
* or add extensions to it.
* <p/>
* Default implementation sets the name of the binding output to the name of the output.
*
* @param definition the WSDL4J <code>Definition</code>
* @param bindingOutput the WSDL4J <code>BindingOutput</code>
* @param output the corresponding WSDL4J <code>Output</code> @throws WSDLException in case of errors
*/
protected void populateBindingOutput(Definition definition, BindingOutput bindingOutput, Output output)
throws WSDLException {
bindingOutput.setName(output.getName());
}
/**
* Called after the {@link BindingFault} has been created. Subclasses can implement this method to define the name,
* or add extensions to it.
* <p/>
* Default implementation set the name of the binding fault to the name of the fault.
*
* @param bindingFault the WSDL4J <code>BindingFault</code>
* @param fault the corresponding WSDL4J <code>Fault</code> @throws WSDLException in case of errors
*/
protected void populateBindingFault(Definition definition, BindingFault bindingFault, Fault fault)
throws WSDLException {
bindingFault.setName(fault.getName());
}
/**
* Creates a single {@link Service} if not present, and calls {@link #populateService(Definition, Service)} with it.
* Creates a corresponding {@link Port} for each {@link Binding}, which is passed to {@link
* #populatePort(javax.wsdl.Definition,javax.wsdl.Port)}.
*
* @param definition the WSDL4J <code>Definition</code>
* @throws WSDLException in case of errors
*/
public void addServices(Definition definition) throws WSDLException {
Assert.notNull(getServiceName(), "'serviceName' is required");
Service service;
if (definition.getServices().isEmpty()) {
service = definition.createService();
}
else {
service = (Service) definition.getServices().values().iterator().next();
}
populateService(definition, service);
createPorts(definition, service);
if (service.getQName() != null) {
definition.addService(service);
}
}
/**
* Called after the {@link Service} has been created, but before any sub-elements are added. Subclasses can
* implement this method to define the service name, or add extensions to it.
* <p/>
* Default implementation sets the name to the {@link #setServiceName(String) serviceName} property.
*
* @param service the WSDL4J <code>Service</code>
* @throws WSDLException in case of errors
*/
protected void populateService(Definition definition, Service service) throws WSDLException {
if (StringUtils.hasText(definition.getTargetNamespace()) && StringUtils.hasText(getServiceName())) {
QName serviceName = new QName(definition.getTargetNamespace(), getServiceName());
service.setQName(serviceName);
}
}
private void createPorts(Definition definition, Service service) throws WSDLException {
for (Iterator iterator = definition.getBindings().values().iterator(); iterator.hasNext();) {
Binding binding = (Binding) iterator.next();
Port port = null;
for (Iterator iterator1 = service.getPorts().values().iterator(); iterator1.hasNext();) {
Port existingPort = (Port) iterator1.next();
if (binding.equals(existingPort.getBinding())) {
port = existingPort;
}
}
if (port == null) {
port = definition.createPort();
port.setBinding(binding);
}
populatePort(definition, port);
if (StringUtils.hasText(port.getName())) {
service.addPort(port);
}
}
}
/**
* Called after the {@link Port} has been created, but before any sub-elements are added. Subclasses can implement
* this method to define the port name, or add extensions to it.
* <p/>
* Default implementation sets the port name to the binding name.
*
* @param definition the WSDL4J <code>Definition</code>
* @param port the WSDL4J <code>Port</code>
* @throws WSDLException in case of errors
*/
protected void populatePort(Definition definition, Port port) throws WSDLException {
port.setName(port.getBinding().getQName().getLocalPart());
}
}

View File

@@ -0,0 +1,124 @@
/*
* Copyright 2008 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.provider;
import java.util.Iterator;
import javax.wsdl.Definition;
import javax.wsdl.Message;
import javax.wsdl.Part;
import javax.wsdl.Types;
import javax.wsdl.WSDLException;
import javax.wsdl.extensions.ExtensibilityElement;
import javax.wsdl.extensions.schema.Schema;
import javax.xml.namespace.QName;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.springframework.util.Assert;
/**
* Default implementation of the {@link MessagesProvider}.
* <p/>
* Simply adds all elements contained in the schema(s) as messages.
*
* @author Arjen Poutsma
* @since 1.5.0
*/
public class DefaultMessagesProvider implements MessagesProvider {
public void addMessages(Definition definition) throws WSDLException {
Types types = definition.getTypes();
Assert.notNull(types, "No types element present in definition");
for (Iterator iterator = types.getExtensibilityElements().iterator(); iterator.hasNext();) {
ExtensibilityElement extensibilityElement = (ExtensibilityElement) iterator.next();
if (extensibilityElement instanceof Schema) {
Schema schema = (Schema) extensibilityElement;
if (schema.getElement() != null) {
createMessages(definition, schema.getElement());
}
}
}
}
private void createMessages(Definition definition, Element schemaElement) throws WSDLException {
String schemaTargetNamespace = schemaElement.getAttribute("targetNamespace");
Assert.hasText("No targetNamespace defined on schema");
NodeList children = schemaElement.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE) {
Element childElement = (Element) child;
if (isMessageElement(childElement)) {
QName elementName = new QName(schemaTargetNamespace, childElement.getAttribute("name"));
Message message = definition.createMessage();
populateMessage(definition, message, elementName);
Part part = definition.createPart();
populatePart(definition, part, elementName);
message.addPart(part);
message.setUndefined(false);
definition.addMessage(message);
}
}
}
}
/**
* Indicates whether the given element should be includes as {@link Message} in the definition.
* <p/>
* Default implementation checks whether the element has the XML Schema namespace, and if it has the local name
* "element".
*
* @param element the element elligable for being a message
* @return <code>true</code> if to be included as message; <code>false</code> otherwise
*/
protected boolean isMessageElement(Element element) {
return "element".equals(element.getLocalName()) &&
"http://www.w3.org/2001/XMLSchema".equals(element.getNamespaceURI());
}
/**
* Called after the {@link Message} has been created.
* <p/>
* Default implementation sets the name of the message to the element name.
*
* @param definition the WSDL4J <code>Definition</code>
* @param message the WSDL4J <code>Message</code>
* @param elementName the element name
* @throws WSDLException in case of errors
*/
protected void populateMessage(Definition definition, Message message, QName elementName) throws WSDLException {
message.setQName(new QName(definition.getTargetNamespace(), elementName.getLocalPart()));
}
/**
* Called after the {@link Part} has been created.
* <p/>
* Default implementation sets the element name of the part.
*
* @param definition the WSDL4J <code>Definition</code>
* @param part the WSDL4J <code>Part</code>
* @param elementName the elementName @throws WSDLException in case of errors
* @see Part#setElementName(javax.xml.namespace.QName)
*/
protected void populatePart(Definition definition, Part part, QName elementName) throws WSDLException {
part.setElementName(elementName);
part.setName(elementName.getLocalPart());
}
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2008 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.provider;
import javax.wsdl.Definition;
import javax.wsdl.WSDLException;
/**
* Strategy for adding {@link javax.wsdl.Import}s to a {@link javax.wsdl.Definition}.
* <p/>
* Used by {@link org.springframework.ws.wsdl.wsdl11.ProviderBasedWsdl4jDefinition}.
*
* @author Arjen Poutsma
* @since 1.5.0
*/
public interface ImportsProvider {
void addImports(Definition definition) throws WSDLException;
}

View File

@@ -0,0 +1,109 @@
/*
* Copyright 2008 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.provider;
import javax.wsdl.Definition;
import javax.wsdl.Types;
import javax.wsdl.WSDLException;
import javax.wsdl.extensions.schema.Schema;
import javax.xml.namespace.QName;
import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.springframework.util.Assert;
import org.springframework.ws.wsdl.WsdlDefinitionException;
import org.springframework.xml.transform.TransformerObjectSupport;
import org.springframework.xml.xsd.XsdSchema;
import org.springframework.xml.xsd.XsdSchemaCollection;
/**
* Implementation of {@link TypesProvider} that inlines a {@link XsdSchema} or {@link XsdSchemaCollection} into the
* WSDL.
*
* @author Arjen Poutsma
* @since 1.5.0
*/
public class InliningXsdSchemaTypesProvider extends TransformerObjectSupport implements TypesProvider {
/** The prefix used to register the schema namespace in the WSDL. */
public static final String SCHEMA_PREFIX = "sch";
private XsdSchemaCollection schemaCollection;
/**
* Sets the single XSD schema to inline. Either this property, or {@link #setSchemaCollection(XsdSchemaCollection)
* schemaCollection} must be set.
*/
public void setSchema(final XsdSchema schema) {
this.schemaCollection = new XsdSchemaCollection() {
public XsdSchema[] getXsdSchemas() {
return new XsdSchema[]{schema};
}
};
}
/** Returns the XSD schema collection to inline. */
public XsdSchemaCollection getSchemaCollection() {
return schemaCollection;
}
/**
* Sets the XSD schema collection to inline. Either this property, or {@link #setSchema(XsdSchema) schema} must be
* set.
*/
public void setSchemaCollection(XsdSchemaCollection schemaCollection) {
this.schemaCollection = schemaCollection;
}
public void addTypes(Definition definition) throws WSDLException {
Assert.notNull(getSchemaCollection(), "setting 'schema' or 'schemaCollection' is required");
Types types = definition.createTypes();
XsdSchema[] schemas = schemaCollection.getXsdSchemas();
for (int i = 0; i < schemas.length; i++) {
if (schemas.length == 1) {
definition.addNamespace(SCHEMA_PREFIX, schemas[i].getTargetNamespace());
}
else {
String prefix = SCHEMA_PREFIX + i;
definition.addNamespace(prefix, schemas[i].getTargetNamespace());
}
Element schemaElement = getSchemaElement(schemas[i]);
Schema schema = (Schema) definition.getExtensionRegistry()
.createExtension(Types.class, new QName("http://www.w3.org/2001/XMLSchema", "schema"));
types.addExtensibilityElement(schema);
schema.setElement(schemaElement);
}
definition.setTypes(types);
}
private Element getSchemaElement(XsdSchema schema) {
try {
DOMResult result = new DOMResult();
transform(schema.getSource(), result);
Document schemaDocument = (Document) result.getNode();
return schemaDocument.getDocumentElement();
}
catch (TransformerException e) {
throw new WsdlDefinitionException("Could not transform schema source to Document");
}
}
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2008 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.provider;
import javax.wsdl.Definition;
import javax.wsdl.WSDLException;
/**
* Strategy for adding {@link javax.wsdl.Message}s to a {@link javax.wsdl.Definition}.
* <p/>
* Used by {@link org.springframework.ws.wsdl.wsdl11.ProviderBasedWsdl4jDefinition}.
*
* @author Arjen Poutsma
* @since 1.5.0
*/
public interface MessagesProvider {
void addMessages(Definition definition) throws WSDLException;
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2008 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.provider;
import javax.wsdl.Definition;
import javax.wsdl.WSDLException;
/**
* Strategy for adding {@link javax.wsdl.PortType}s to a {@link javax.wsdl.Definition}.
* <p/>
* Used by {@link org.springframework.ws.wsdl.wsdl11.ProviderBasedWsdl4jDefinition}.
*
* @author Arjen Poutsma
* @since 1.5.0
*/
public interface PortTypesProvider {
void addPortTypes(Definition definition) throws WSDLException;
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2008 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.provider;
import javax.wsdl.Definition;
import javax.wsdl.WSDLException;
/**
* Strategy for adding {@link javax.wsdl.Service}s to a {@link javax.wsdl.Definition}.
* <p/>
* Used by {@link org.springframework.ws.wsdl.wsdl11.ProviderBasedWsdl4jDefinition}.
*
* @author Arjen Poutsma
* @since 1.5.0
*/
public interface ServicesProvider {
void addServices(Definition definition) throws WSDLException;
}

View File

@@ -0,0 +1,345 @@
/*
* Copyright 2008 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.provider;
import java.util.Iterator;
import java.util.Properties;
import javax.wsdl.Binding;
import javax.wsdl.BindingFault;
import javax.wsdl.BindingInput;
import javax.wsdl.BindingOperation;
import javax.wsdl.BindingOutput;
import javax.wsdl.Definition;
import javax.wsdl.Fault;
import javax.wsdl.Input;
import javax.wsdl.Output;
import javax.wsdl.Port;
import javax.wsdl.WSDLException;
import javax.wsdl.extensions.ExtensibilityElement;
import javax.wsdl.extensions.ExtensionRegistry;
import javax.wsdl.extensions.soap.SOAPAddress;
import javax.wsdl.extensions.soap.SOAPBinding;
import javax.wsdl.extensions.soap.SOAPBody;
import javax.wsdl.extensions.soap.SOAPFault;
import javax.wsdl.extensions.soap.SOAPOperation;
import javax.xml.namespace.QName;
import org.springframework.util.Assert;
/**
* Implementation of the {@link BindingsProvider} and {@link ServicesProvider} interfaces that are SOAP 1.1 specific.
* <p/>
* By setting the {@link #setSoapActions(java.util.Properties) soapActions} property, the SOAP Actions defined in the
* resulting WSDL can be set. Additionaly, the transport uri can be changed from the default HTTP transport by using the
* {@link #setTransportUri(String) transportUri} property.
*
* @author Arjen Poutsma
* @since 1.5.0
*/
public class Soap11Provider extends DefaultConcretePartProvider {
/** The default transport URI, which indicates an HTTP transport. */
public static final String DEFAULT_TRANSPORT_URI = "http://schemas.xmlsoap.org/soap/http";
/** The prefix of the WSDL SOAP 1.1 namespace. */
public static final String SOAP_11_NAMESPACE_PREFIX = "soap";
/** The WSDL SOAP 1.1 namespace. */
public static final String SOAP_11_NAMESPACE_URI = "http://schemas.xmlsoap.org/wsdl/soap/";
private String transportUri = DEFAULT_TRANSPORT_URI;
private Properties soapActions = new Properties();
private String locationUri;
/**
* Constructs a new version of the {@link Soap11Provider}.
* <p/>
* Sets the {@link #setBindingSuffix(String) binding suffix} to <code>Soap11</code>.
*/
public Soap11Provider() {
setBindingSuffix("Soap11");
}
/**
* Returns the SOAP Actions for this binding. Keys are {@link BindingOperation#getName() binding operation names};
* values are {@link javax.wsdl.extensions.soap.SOAPOperation#getSoapActionURI() SOAP Action URIs}.
*
* @return the soap actions
*/
public Properties getSoapActions() {
return soapActions;
}
/**
* Sets the SOAP Actions for this binding. Keys are {@link BindingOperation#getName() binding operation names};
* values are {@link javax.wsdl.extensions.soap.SOAPOperation#getSoapActionURI() SOAP Action URIs}.
*
* @param soapActions the soap
*/
public void setSoapActions(Properties soapActions) {
Assert.notNull(soapActions, "'soapActions' must not be null");
this.soapActions = soapActions;
}
/**
* Returns the value used for the binding transport attribute value. Defaults to {@link #DEFAULT_TRANSPORT_URI}.
*
* @return the binding transport value
*/
public String getTransportUri() {
return transportUri;
}
/**
* Sets the value used for the binding transport attribute value. Defaults to {@link #DEFAULT_TRANSPORT_URI}.
*
* @param transportUri the binding transport value
*/
public void setTransportUri(String transportUri) {
Assert.notNull(transportUri, "'transportUri' must not be null");
this.transportUri = transportUri;
}
/** Returns the value used for the SOAP Address location attribute value. */
public String getLocationUri() {
return locationUri;
}
/** Sets the value used for the SOAP Address location attribute value. */
public void setLocationUri(String locationUri) {
this.locationUri = locationUri;
}
/**
* Called after the {@link Binding} has been created, but before any sub-elements are added. Subclasses can override
* this method to define the binding name, or add extensions to it.
* <p/>
* Default implementation calls {@link DefaultConcretePartProvider#populateBinding(Definition, Binding)}, adds the
* SOAP 1.1 namespace, creates a {@link SOAPBinding}, and calls {@link #populateSoapBinding(SOAPBinding, Binding)}
* sets the binding name to the port type name with the {@link #getBindingSuffix() suffix} appended to it.
*
* @param definition the WSDL4J <code>Definition</code>
* @param binding the WSDL4J <code>Binding</code>
*/
protected void populateBinding(Definition definition, Binding binding) throws WSDLException {
definition.addNamespace(SOAP_11_NAMESPACE_PREFIX, SOAP_11_NAMESPACE_URI);
super.populateBinding(definition, binding);
SOAPBinding soapBinding = (SOAPBinding) createSoapExtension(definition, Binding.class, "binding");
populateSoapBinding(soapBinding, binding);
binding.addExtensibilityElement(soapBinding);
}
/**
* Called after the {@link SOAPBinding} has been created.
* <p/>
* Default implementation sets the binding style to <code>"document"</code>, and set the transport URI to the {@link
* #setTransportUri(String) transportUri} property value. Subclasses can override this behavior.
*
* @param soapBinding the WSDL4J <code>SOAPBinding</code>
* @throws WSDLException in case of errors
* @see SOAPBinding#setStyle(String)
* @see SOAPBinding#setTransportURI(String)
* @see #setTransportUri(String)
* @see #DEFAULT_TRANSPORT_URI
*/
protected void populateSoapBinding(SOAPBinding soapBinding, Binding binding) throws WSDLException {
soapBinding.setStyle("document");
soapBinding.setTransportURI(getTransportUri());
}
/**
* Called after the {@link BindingFault} has been created. Subclasses can override this method to define the name,
* or add extensions to it.
* <p/>
* Default implementation calls {@link DefaultConcretePartProvider#populateBindingFault(Definition, BindingFault,
* Fault)}, creates a {@link SOAPFault}, and calls {@link #populateSoapFault(BindingFault, SOAPFault)}.
*
* @param definition the WSDL4J <code>Definition</code>
* @param bindingFault the WSDL4J <code>BindingFault</code>
* @param fault the corresponding WSDL4J <code>Fault</code> @throws WSDLException in case of errors
*/
protected void populateBindingFault(Definition definition, BindingFault bindingFault, Fault fault)
throws WSDLException {
super.populateBindingFault(definition, bindingFault, fault);
SOAPFault soapFault = (SOAPFault) createSoapExtension(definition, BindingFault.class, "fault");
populateSoapFault(bindingFault, soapFault);
bindingFault.addExtensibilityElement(soapFault);
}
/**
* Called after the {@link SOAPFault} has been created.
* <p/>
* Default implementation sets the use style to <code>"literal"</code>, and sets the name equal to the binding
* fault. Subclasses can override this behavior.
*
* @param bindingFault the WSDL4J <code>BindingFault</code>
* @param soapFault the WSDL4J <code>SOAPFault</code>
* @throws WSDLException in case of errors
* @see SOAPFault#setUse(String)
*/
protected void populateSoapFault(BindingFault bindingFault, SOAPFault soapFault) throws WSDLException {
soapFault.setName(bindingFault.getName());
soapFault.setUse("literal");
}
/**
* Called after the {@link BindingInput} has been created. Subclasses can implement this method to define the name,
* or add extensions to it.
* <p/>
* Default implementation calls {@link DefaultConcretePartProvider#populateBindingInput(Definition,
* javax.wsdl.BindingInput, javax.wsdl.Input)}, creates a {@link SOAPBody}, and calls {@link
* #populateSoapBody(SOAPBody)}.
*
* @param definition the WSDL4J <code>Definition</code>
* @param bindingInput the WSDL4J <code>BindingInput</code>
* @param input the corresponding WSDL4J <code>Input</code> @throws WSDLException in case of errors
*/
protected void populateBindingInput(Definition definition, BindingInput bindingInput, Input input)
throws WSDLException {
super.populateBindingInput(definition, bindingInput, input);
SOAPBody soapBody = (SOAPBody) createSoapExtension(definition, BindingInput.class, "body");
populateSoapBody(soapBody);
bindingInput.addExtensibilityElement(soapBody);
}
/**
* Called after the {@link SOAPBody} has been created.
* <p/>
* Default implementation sets the use style to <code>"literal"</code>. Subclasses can override this behavior.
*
* @param soapBody the WSDL4J <code>SOAPBody</code>
* @throws WSDLException in case of errors
* @see SOAPBody#setUse(String)
*/
protected void populateSoapBody(SOAPBody soapBody) throws WSDLException {
soapBody.setUse("literal");
}
/**
* Called after the {@link BindingOperation} has been created, but before any sub-elements are added. Subclasses can
* implement this method to define the binding name, or add extensions to it.
* <p/>
* Default implementation calls {@link DefaultConcretePartProvider#populateBindingOperation(Definition,
* BindingOperation)}, creates a {@link SOAPOperation}, and calls {@link #populateSoapOperation} sets the name of
* the binding operation to the name of the operation.
*
* @param definition the WSDL4J <code>Definition</code>
* @param bindingOperation the WSDL4J <code>BindingOperation</code>
* @throws WSDLException in case of errors
*/
protected void populateBindingOperation(Definition definition, BindingOperation bindingOperation)
throws WSDLException {
super.populateBindingOperation(definition, bindingOperation);
SOAPOperation soapOperation =
(SOAPOperation) createSoapExtension(definition, BindingOperation.class, "operation");
populateSoapOperation(soapOperation, bindingOperation);
bindingOperation.addExtensibilityElement(soapOperation);
}
/**
* Called after the {@link SOAPOperation} has been created.
* <p/>
* Default implementation sets <code>SOAPAction</code> to the corresponding {@link
* #setSoapActions(java.util.Properties) soapActions} property, and defaults to "".
*
* @param soapOperation the WSDL4J <code>SOAPOperation</code>
* @param bindingOperation the WSDL4J <code>BindingOperation</code>
* @throws WSDLException in case of errors
* @see SOAPOperation#setSoapActionURI(String)
* @see #setSoapActions(java.util.Properties)
*/
protected void populateSoapOperation(SOAPOperation soapOperation, BindingOperation bindingOperation)
throws WSDLException {
String bindingOperationName = bindingOperation.getName();
String soapAction = getSoapActions().getProperty(bindingOperationName, "");
soapOperation.setSoapActionURI(soapAction);
}
/**
* Called after the {@link BindingInput} has been created. Subclasses can implement this method to define the name,
* or add extensions to it.
* <p/>
* Default implementation calls {@link DefaultConcretePartProvider#populateBindingOutput(Definition, BindingOutput,
* Output)}, creates a {@link SOAPBody}, and calls {@link #populateSoapBody(SOAPBody)}.
*
* @param definition the WSDL4J <code>Definition</code>
* @param bindingOutput the WSDL4J <code>BindingOutput</code>
* @param output the corresponding WSDL4J <code>Output</code> @throws WSDLException in case of errors
*/
protected void populateBindingOutput(Definition definition, BindingOutput bindingOutput, Output output)
throws WSDLException {
super.populateBindingOutput(definition, bindingOutput, output);
SOAPBody soapBody = (SOAPBody) createSoapExtension(definition, BindingOutput.class, "body");
populateSoapBody(soapBody);
bindingOutput.addExtensibilityElement(soapBody);
}
/**
* Called after the {@link Port} has been created, but before any sub-elements are added. Subclasses can implement
* this method to define the port name, or add extensions to it.
* <p/>
* Default implementation calls {@link DefaultConcretePartProvider#populatePort(javax.wsdl.Definition,javax.wsdl.Port)},
* creates a {@link SOAPAddress}, and calls {@link #populateSoapAddress(SOAPAddress)}.
*
* @param port the WSDL4J <code>Port</code>
* @throws WSDLException in case of errors
*/
protected void populatePort(Definition definition, Port port) throws WSDLException {
for (Iterator iterator = port.getBinding().getExtensibilityElements().iterator(); iterator.hasNext();) {
if (iterator.next() instanceof SOAPBinding) {
// this is a SOAP 1.1 binding, create a SOAP Address for it
super.populatePort(definition, port);
SOAPAddress soapAddress = (SOAPAddress) createSoapExtension(definition, Port.class, "address");
populateSoapAddress(soapAddress);
port.addExtensibilityElement(soapAddress);
return;
}
}
}
/**
* Called after the {@link SOAPAddress} has been created. Default implementation sets the location URI to the value
* set on this builder. Subclasses can override this behavior.
*
* @param soapAddress the WSDL4J <code>SOAPAddress</code>
* @throws WSDLException in case of errors
* @see SOAPAddress#setLocationURI(String)
* @see #setLocationUri(String)
*/
protected void populateSoapAddress(SOAPAddress soapAddress) throws WSDLException {
soapAddress.setLocationURI(getLocationUri());
}
/**
* Creates a SOAP extensibility element.
*
* @param definition the WSDL4J <code>Definition</code>
* @param parentType a class object indicating where in the WSDL definition this extension will exist
* @param localName the local name of the extensibility element
* @return the extensibility element
* @throws WSDLException in case of errors
* @see ExtensionRegistry#createExtension(Class, QName)
*/
private ExtensibilityElement createSoapExtension(Definition definition, Class parentType, String localName)
throws WSDLException {
return definition.getExtensionRegistry()
.createExtension(parentType, new QName(SOAP_11_NAMESPACE_URI, localName));
}
}

View File

@@ -0,0 +1,348 @@
/*
* Copyright 2008 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.provider;
import java.util.Iterator;
import java.util.Properties;
import javax.wsdl.Binding;
import javax.wsdl.BindingFault;
import javax.wsdl.BindingInput;
import javax.wsdl.BindingOperation;
import javax.wsdl.BindingOutput;
import javax.wsdl.Definition;
import javax.wsdl.Fault;
import javax.wsdl.Input;
import javax.wsdl.Output;
import javax.wsdl.Port;
import javax.wsdl.WSDLException;
import javax.wsdl.extensions.ExtensibilityElement;
import javax.wsdl.extensions.soap12.SOAP12Address;
import javax.wsdl.extensions.soap12.SOAP12Binding;
import javax.wsdl.extensions.soap12.SOAP12Body;
import javax.wsdl.extensions.soap12.SOAP12Fault;
import javax.wsdl.extensions.soap12.SOAP12Operation;
import javax.xml.namespace.QName;
import org.springframework.util.Assert;
/**
* Implementation of the {@link BindingsProvider} and {@link ServicesProvider} interfaces that are SOAP 1.2 specific.
* <p/>
* By setting the {@link #setSoapActions(java.util.Properties) soapActions} property, the SOAP Actions defined in the
* resulting WSDL can be set. Additionaly, the transport uri can be changed from the default HTTP transport by using the
* {@link #setTransportUri(String) transportUri} property.
*
* @author Arjen Poutsma
* @since 1.5.0
*/
public class Soap12Provider extends DefaultConcretePartProvider {
/** The default transport URI, which indicates an HTTP transport. */
public static final String DEFAULT_TRANSPORT_URI = "http://schemas.xmlsoap.org/soap/http";
/** The prefix of the WSDL SOAP 1.2 namespace. */
public static final String SOAP_12_NAMESPACE_PREFIX = "soap12";
/** The WSDL SOAP 1.1 namespace. */
public static final String SOAP_12_NAMESPACE_URI = "http://schemas.xmlsoap.org/wsdl/soap12/";
private String transportUri = DEFAULT_TRANSPORT_URI;
private Properties soapActions = new Properties();
private String locationUri;
/**
* Constructs a new version of the {@link Soap12Provider}.
* <p/>
* Sets the {@link #setBindingSuffix(String) binding suffix} to <code>Soap12</code>.
*/
public Soap12Provider() {
setBindingSuffix("Soap12");
}
/**
* Returns the SOAP Actions for this binding. Keys are {@link javax.wsdl.BindingOperation#getName() binding
* operation names}; values are {@link javax.wsdl.extensions.soap.SOAPOperation#getSoapActionURI() SOAP Action
* URIs}.
*
* @return the soap actions
*/
public Properties getSoapActions() {
return soapActions;
}
/**
* Sets the SOAP Actions for this binding. Keys are {@link javax.wsdl.BindingOperation#getName() binding operation
* names}; values are {@link javax.wsdl.extensions.soap.SOAPOperation#getSoapActionURI() SOAP Action URIs}.
*
* @param soapActions the soap
*/
public void setSoapActions(Properties soapActions) {
Assert.notNull(soapActions, "'soapActions' must not be null");
this.soapActions = soapActions;
}
/**
* Returns the value used for the binding transport attribute value. Defaults to {@link #DEFAULT_TRANSPORT_URI}.
*
* @return the binding transport value
*/
public String getTransportUri() {
return transportUri;
}
/**
* Sets the value used for the binding transport attribute value. Defaults to {@link #DEFAULT_TRANSPORT_URI}.
*
* @param transportUri the binding transport value
*/
public void setTransportUri(String transportUri) {
Assert.notNull(transportUri, "'transportUri' must not be null");
this.transportUri = transportUri;
}
/** Returns the value used for the SOAP Address location attribute value. */
public String getLocationUri() {
return locationUri;
}
/** Sets the value used for the SOAP Address location attribute value. */
public void setLocationUri(String locationUri) {
this.locationUri = locationUri;
}
/**
* Called after the {@link javax.wsdl.Binding} has been created, but before any sub-elements are added. Subclasses
* can override this method to define the binding name, or add extensions to it.
* <p/>
* Default implementation calls {@link DefaultConcretePartProvider#populateBinding(javax.wsdl.Definition,
* javax.wsdl.Binding)}, adds the SOAP 1.1 namespace, creates a {@link javax.wsdl.extensions.soap.SOAPBinding}, and
* calls {@link #populateSoapBinding(javax.wsdl.extensions.soap12.SOAP12Binding, javax.wsdl.Binding)} sets the
* binding name to the port type name with the {@link #getBindingSuffix() suffix} appended to it.
*
* @param definition the WSDL4J <code>Definition</code>
* @param binding the WSDL4J <code>Binding</code>
*/
protected void populateBinding(Definition definition, Binding binding) throws WSDLException {
definition.addNamespace(SOAP_12_NAMESPACE_PREFIX, SOAP_12_NAMESPACE_URI);
super.populateBinding(definition, binding);
SOAP12Binding soapBinding = (SOAP12Binding) createSoapExtension(definition, Binding.class, "binding");
populateSoapBinding(soapBinding, binding);
binding.addExtensibilityElement(soapBinding);
}
/**
* Called after the {@link javax.wsdl.extensions.soap.SOAPBinding} has been created.
* <p/>
* Default implementation sets the binding style to <code>"document"</code>, and set the transport URI to the {@link
* #setTransportUri(String) transportUri} property value. Subclasses can override this behavior.
*
* @param soapBinding the WSDL4J <code>SOAPBinding</code>
* @throws javax.wsdl.WSDLException in case of errors
* @see javax.wsdl.extensions.soap.SOAPBinding#setStyle(String)
* @see javax.wsdl.extensions.soap.SOAPBinding#setTransportURI(String)
* @see #setTransportUri(String)
* @see #DEFAULT_TRANSPORT_URI
*/
protected void populateSoapBinding(SOAP12Binding soapBinding, Binding binding) throws WSDLException {
soapBinding.setStyle("document");
soapBinding.setTransportURI(getTransportUri());
}
/**
* Called after the {@link javax.wsdl.BindingFault} has been created. Subclasses can override this method to define
* the name, or add extensions to it.
* <p/>
* Default implementation calls {@link DefaultConcretePartProvider#populateBindingFault(javax.wsdl.Definition,
* javax.wsdl.BindingFault, javax.wsdl.Fault)}, creates a {@link javax.wsdl.extensions.soap.SOAPFault}, and calls
* {@link #populateSoapFault(javax.wsdl.BindingFault, javax.wsdl.extensions.soap12.SOAP12Fault)}.
*
* @param definition the WSDL4J <code>Definition</code>
* @param bindingFault the WSDL4J <code>BindingFault</code>
* @param fault the corresponding WSDL4J <code>Fault</code> @throws WSDLException in case of errors
*/
protected void populateBindingFault(Definition definition, BindingFault bindingFault, Fault fault)
throws WSDLException {
super.populateBindingFault(definition, bindingFault, fault);
SOAP12Fault soapFault = (SOAP12Fault) createSoapExtension(definition, BindingFault.class, "fault");
populateSoapFault(bindingFault, soapFault);
bindingFault.addExtensibilityElement(soapFault);
}
/**
* Called after the {@link javax.wsdl.extensions.soap.SOAPFault} has been created.
* <p/>
* Default implementation sets the use style to <code>"literal"</code>, and sets the name equal to the binding
* fault. Subclasses can override this behavior.
*
* @param bindingFault the WSDL4J <code>BindingFault</code>
* @param soapFault the WSDL4J <code>SOAPFault</code>
* @throws javax.wsdl.WSDLException in case of errors
* @see javax.wsdl.extensions.soap.SOAPFault#setUse(String)
*/
protected void populateSoapFault(BindingFault bindingFault, SOAP12Fault soapFault) throws WSDLException {
soapFault.setName(bindingFault.getName());
soapFault.setUse("literal");
}
/**
* Called after the {@link javax.wsdl.BindingInput} has been created. Subclasses can implement this method to define
* the name, or add extensions to it.
* <p/>
* Default implementation calls {@link DefaultConcretePartProvider#populateBindingInput(javax.wsdl.Definition,
* javax.wsdl.BindingInput, javax.wsdl.Input)}, creates a {@link javax.wsdl.extensions.soap.SOAPBody}, and calls
* {@link #populateSoapBody(javax.wsdl.extensions.soap12.SOAP12Body)}. 2
*
* @param definition the WSDL4J <code>Definition</code>
* @param bindingInput the WSDL4J <code>BindingInput</code>
* @param input the corresponding WSDL4J <code>Input</code> @throws WSDLException in case of errors
*/
protected void populateBindingInput(Definition definition, BindingInput bindingInput, Input input)
throws WSDLException {
super.populateBindingInput(definition, bindingInput, input);
SOAP12Body soapBody = (SOAP12Body) createSoapExtension(definition, BindingInput.class, "body");
populateSoapBody(soapBody);
bindingInput.addExtensibilityElement(soapBody);
}
/**
* Called after the {@link javax.wsdl.extensions.soap.SOAPBody} has been created.
* <p/>
* Default implementation sets the use style to <code>"literal"</code>. Subclasses can override this behavior.
*
* @param soapBody the WSDL4J <code>SOAPBody</code>
* @throws javax.wsdl.WSDLException in case of errors
* @see javax.wsdl.extensions.soap.SOAPBody#setUse(String)
*/
protected void populateSoapBody(SOAP12Body soapBody) throws WSDLException {
soapBody.setUse("literal");
}
/**
* Called after the {@link javax.wsdl.BindingOperation} has been created, but before any sub-elements are added.
* Subclasses can implement this method to define the binding name, or add extensions to it.
* <p/>
* Default implementation calls {@link DefaultConcretePartProvider#populateBindingOperation(javax.wsdl.Definition,
* javax.wsdl.BindingOperation)}, creates a {@link javax.wsdl.extensions.soap.SOAPOperation}, and calls {@link
* #populateSoapOperation} sets the name of the binding operation to the name of the operation.
*
* @param definition the WSDL4J <code>Definition</code>
* @param bindingOperation the WSDL4J <code>BindingOperation</code>
* @throws javax.wsdl.WSDLException in case of errors
*/
protected void populateBindingOperation(Definition definition, BindingOperation bindingOperation)
throws WSDLException {
super.populateBindingOperation(definition, bindingOperation);
SOAP12Operation soapOperation =
(SOAP12Operation) createSoapExtension(definition, BindingOperation.class, "operation");
populateSoapOperation(soapOperation, bindingOperation);
bindingOperation.addExtensibilityElement(soapOperation);
}
/**
* Called after the {@link javax.wsdl.extensions.soap.SOAPOperation} has been created.
* <p/>
* Default implementation sets <code>SOAPAction</code> to the corresponding {@link
* #setSoapActions(java.util.Properties) soapActions} property, and defaults to "".
*
* @param soapOperation the WSDL4J <code>SOAPOperation</code>
* @param bindingOperation the WSDL4J <code>BindingOperation</code>
* @throws javax.wsdl.WSDLException in case of errors
* @see javax.wsdl.extensions.soap.SOAPOperation#setSoapActionURI(String)
* @see #setSoapActions(java.util.Properties)
*/
protected void populateSoapOperation(SOAP12Operation soapOperation, BindingOperation bindingOperation)
throws WSDLException {
String bindingOperationName = bindingOperation.getName();
String soapAction = getSoapActions().getProperty(bindingOperationName, "");
soapOperation.setSoapActionURI(soapAction);
}
/**
* Called after the {@link javax.wsdl.BindingInput} has been created. Subclasses can implement this method to define
* the name, or add extensions to it.
* <p/>
* Default implementation calls {@link DefaultConcretePartProvider#populateBindingOutput(javax.wsdl.Definition,
* javax.wsdl.BindingOutput, javax.wsdl.Output)}, creates a {@link javax.wsdl.extensions.soap.SOAPBody}, and calls
* {@link #populateSoapBody(javax.wsdl.extensions.soap12.SOAP12Body)}.
*
* @param definition the WSDL4J <code>Definition</code>
* @param bindingOutput the WSDL4J <code>BindingOutput</code>
* @param output the corresponding WSDL4J <code>Output</code> @throws WSDLException in case of errors
*/
protected void populateBindingOutput(Definition definition, BindingOutput bindingOutput, Output output)
throws WSDLException {
super.populateBindingOutput(definition, bindingOutput, output);
SOAP12Body soapBody = (SOAP12Body) createSoapExtension(definition, BindingOutput.class, "body");
populateSoapBody(soapBody);
bindingOutput.addExtensibilityElement(soapBody);
}
/**
* Called after the {@link javax.wsdl.Port} has been created, but before any sub-elements are added. Subclasses can
* implement this method to define the port name, or add extensions to it.
* <p/>
* Default implementation calls {@link DefaultConcretePartProvider#populatePort(javax.wsdl.Definition,javax.wsdl.Port)},
* creates a {@link javax.wsdl.extensions.soap.SOAPAddress}, and calls {@link #populateSoapAddress(SOAP12Address)}.
*
* @param port the WSDL4J <code>Port</code>
* @throws WSDLException in case of errors
*/
protected void populatePort(Definition definition, Port port) throws WSDLException {
for (Iterator iterator = port.getBinding().getExtensibilityElements().iterator(); iterator.hasNext();) {
if (iterator.next() instanceof SOAP12Binding) {
// this is a SOAP 1.2 binding, create a SOAP Address for it
super.populatePort(definition, port);
SOAP12Address soapAddress = (SOAP12Address) createSoapExtension(definition, Port.class, "address");
populateSoapAddress(soapAddress);
port.addExtensibilityElement(soapAddress);
return;
}
}
}
/**
* Called after the {@link SOAP12Address} has been created. Default implementation sets the location URI to the
* value set on this builder. Subclasses can override this behavior.
*
* @param soapAddress the WSDL4J <code>SOAPAddress</code>
* @throws WSDLException in case of errors
* @see SOAP12Address#setLocationURI(String)
* @see #setLocationUri(String)
*/
protected void populateSoapAddress(SOAP12Address soapAddress) throws WSDLException {
soapAddress.setLocationURI(getLocationUri());
}
/**
* Creates a SOAP extensibility element.
*
* @param definition the WSDL4J <code>Definition</code>
* @param parentType a class object indicating where in the WSDL definition this extension will exist
* @param localName the local name of the extensibility element
* @return the extensibility element
* @throws WSDLException in case of errors
* @see javax.wsdl.extensions.ExtensionRegistry#createExtension(Class, QName)
*/
private ExtensibilityElement createSoapExtension(Definition definition, Class parentType, String localName)
throws WSDLException {
return definition.getExtensionRegistry()
.createExtension(parentType, new QName(SOAP_12_NAMESPACE_URI, localName));
}
}

View File

@@ -0,0 +1,112 @@
/*
* Copyright 2008 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.provider;
import java.util.Properties;
import javax.wsdl.Definition;
import javax.wsdl.WSDLException;
/**
* Implementation of the {@link BindingsProvider} and {@link ServicesProvider} interfaces that supports SOAP 1.1 and
* SOAP 1.2. Delegates to {@link Soap11Provider} and {@link Soap12Provider}.
* <p/>
* By setting the {@link #setSoapActions(java.util.Properties) soapActions} property, the SOAP Actions defined in the
* resulting WSDL can be set. Additionaly, the transport uri can be changed from the default HTTP transport by using the
* {@link #setTransportUri(String) transportUri} property.
* <p/>
* The {@link #setCreateSoap11Binding(boolean) createSoap11} and {@link #setCreateSoap12Binding(boolean) createSoap12}
* properties indicate whether a SOAP 1.1 or SOAP 1.2 binding should be created. These properties default to
* <code>true</code> and <code>false</code> respectively.
*
* @author Arjen Poutsma
* @since 1.5.0
*/
public class SoapProvider implements BindingsProvider, ServicesProvider {
private final Soap11Provider soap11BindingProvider = new Soap11Provider();
private final Soap12Provider soap12BindingProvider = new Soap12Provider();
private boolean createSoap11Binding = true;
private boolean createSoap12Binding = false;
/**
* Indicates whether a SOAP 1.1 binding should be created.
* <p/>
* Defaults to <code>true</code>.
*/
public void setCreateSoap11Binding(boolean createSoap11Binding) {
this.createSoap11Binding = createSoap11Binding;
}
/**
* Indicates whether a SOAP 1.2 binding should be created.
* <p/>
* Defaults to <code>false</code>.
*/
public void setCreateSoap12Binding(boolean createSoap12Binding) {
this.createSoap12Binding = createSoap12Binding;
}
/**
* Sets the SOAP Actions for this binding. Keys are {@link javax.wsdl.BindingOperation#getName() binding operation
* names}; values are {@link javax.wsdl.extensions.soap.SOAPOperation#getSoapActionURI() SOAP Action URIs}.
*
* @param soapActions the soap
*/
public void setSoapActions(Properties soapActions) {
soap11BindingProvider.setSoapActions(soapActions);
soap12BindingProvider.setSoapActions(soapActions);
}
/** Sets the value used for the binding transport attribute value. Defaults to HTTP. */
public void setTransportUri(String transportUri) {
soap11BindingProvider.setTransportUri(transportUri);
soap12BindingProvider.setTransportUri(transportUri);
}
/** Sets the value used for the SOAP Address location attribute value. */
public void setLocationUri(String locationUri) {
soap11BindingProvider.setLocationUri(locationUri);
soap12BindingProvider.setLocationUri(locationUri);
}
/** Sets the service name. */
public void setServiceName(String serviceName) {
soap11BindingProvider.setServiceName(serviceName);
soap12BindingProvider.setServiceName(serviceName);
}
public void addBindings(Definition definition) throws WSDLException {
if (createSoap11Binding) {
soap11BindingProvider.addBindings(definition);
}
if (createSoap12Binding) {
soap12BindingProvider.addBindings(definition);
}
}
public void addServices(Definition definition) throws WSDLException {
if (createSoap11Binding) {
soap11BindingProvider.addServices(definition);
}
if (createSoap12Binding) {
soap12BindingProvider.addServices(definition);
}
}
}

View File

@@ -0,0 +1,158 @@
/*
* Copyright 2008 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.provider;
import javax.wsdl.Message;
/**
* Implementation of the {@link PortTypesProvider} interface that is based on suffixes.
*
* @author Arjen Poutsma
* @since 1.5.0
*/
public class SuffixBasedPortTypesProvider extends AbstractPortTypesProvider {
/** The default suffix used to detect request elements in the schema. */
public static final String DEFAULT_REQUEST_SUFFIX = "Request";
/** The default suffix used to detect response elements in the schema. */
public static final String DEFAULT_RESPONSE_SUFFIX = "Response";
/** The default suffix used to detect fault elements in the schema. */
public static final String DEFAULT_FAULT_SUFFIX = "Fault";
private String requestSuffix = DEFAULT_REQUEST_SUFFIX;
private String responseSuffix = DEFAULT_RESPONSE_SUFFIX;
private String faultSuffix = DEFAULT_FAULT_SUFFIX;
/**
* Returns the suffix used to detect request elements in the schema.
*
* @see #DEFAULT_REQUEST_SUFFIX
*/
public String getRequestSuffix() {
return requestSuffix;
}
/**
* Sets the suffix used to detect request elements in the schema.
*
* @see #DEFAULT_REQUEST_SUFFIX
*/
public void setRequestSuffix(String requestSuffix) {
this.requestSuffix = requestSuffix;
}
/**
* Returns the suffix used to detect response elements in the schema.
*
* @see #DEFAULT_RESPONSE_SUFFIX
*/
public String getResponseSuffix() {
return responseSuffix;
}
/**
* Sets the suffix used to detect response elements in the schema.
*
* @see #DEFAULT_RESPONSE_SUFFIX
*/
public void setResponseSuffix(String responseSuffix) {
this.responseSuffix = responseSuffix;
}
/**
* Returns the suffix used to detect fault elements in the schema.
*
* @see #DEFAULT_FAULT_SUFFIX
*/
public String getFaultSuffix() {
return faultSuffix;
}
/**
* Sets the suffix used to detect fault elements in the schema.
*
* @see #DEFAULT_FAULT_SUFFIX
*/
public void setFaultSuffix(String faultSuffix) {
this.faultSuffix = faultSuffix;
}
protected String getOperationName(Message message) {
String messageName = getMessageName(message);
if (messageName != null) {
if (messageName.endsWith(getRequestSuffix())) {
return messageName.substring(0, messageName.length() - getRequestSuffix().length());
}
else if (messageName.endsWith(getResponseSuffix())) {
return messageName.substring(0, messageName.length() - getResponseSuffix().length());
}
else if (messageName.endsWith(getFaultSuffix())) {
return messageName.substring(0, messageName.length() - getFaultSuffix().length());
}
}
return null;
}
/**
* Indicates whether the given name name should be included as {@link javax.wsdl.Input} message in the definition.
* <p/>
* This implementation checks whether the message name ends with the {@link #setRequestSuffix(String)
* requestSuffix}.
*
* @param message the message
* @return <code>true</code> if to be included as input; <code>false</code> otherwise
*/
protected boolean isInputMessage(Message message) {
String messageName = getMessageName(message);
return messageName != null && messageName.endsWith(getRequestSuffix());
}
/**
* Indicates whether the given name name should be included as {@link javax.wsdl.Output} message in the definition.
* <p/>
* This implementation checks whether the message name ends with the {@link #setResponseSuffix(String)
* responseSuffix}.
*
* @param message the message
* @return <code>true</code> if to be included as output; <code>false</code> otherwise
*/
protected boolean isOutputMessage(Message message) {
String messageName = getMessageName(message);
return messageName != null && messageName.endsWith(getResponseSuffix());
}
/**
* Indicates whether the given name name should be included as {@link javax.wsdl.Fault} message in the definition.
* <p/>
* This implementation checks whether the message name ends with the {@link #setFaultSuffix(String) faultSuffix}.
*
* @param message the message
* @return <code>true</code> if to be included as fault; <code>false</code> otherwise
*/
protected boolean isFaultMessage(Message message) {
String messageName = getMessageName(message);
return messageName != null && messageName.endsWith(getFaultSuffix());
}
private String getMessageName(Message message) {
return message.getQName().getLocalPart();
}
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2008 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.provider;
import javax.wsdl.Definition;
import javax.wsdl.WSDLException;
/**
* Strategy for adding {@link javax.wsdl.Types} to a {@link javax.wsdl.Definition}.
* <p/>
* Used by {@link org.springframework.ws.wsdl.wsdl11.ProviderBasedWsdl4jDefinition}.
*
* @author Arjen Poutsma
* @since 1.5.0
*/
public interface TypesProvider {
void addTypes(Definition definition) throws WSDLException;
}

View File

@@ -0,0 +1,5 @@
<html>
<body>
Provides a contribution strategy for WSDL definitions.
</body>
</html>

View File

@@ -0,0 +1,89 @@
/*
* Copyright ${YEAR} 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.provider;
import javax.wsdl.Definition;
import javax.wsdl.Message;
import javax.wsdl.Part;
import javax.wsdl.Types;
import javax.wsdl.extensions.schema.Schema;
import javax.wsdl.factory.WSDLFactory;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import junit.framework.TestCase;
import org.w3c.dom.Document;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.xml.sax.SaxUtils;
public class DefaultMessagesProviderTest extends TestCase {
private DefaultMessagesProvider provider;
private Definition definition;
private DocumentBuilder documentBuilder;
protected void setUp() throws Exception {
provider = new DefaultMessagesProvider();
WSDLFactory factory = WSDLFactory.newInstance();
definition = factory.newDefinition();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
documentBuilder = documentBuilderFactory.newDocumentBuilder();
}
public void testAddMessages() throws Exception {
String definitionNamespace = "http://springframework.org/spring-ws";
definition.addNamespace("tns", definitionNamespace);
definition.setTargetNamespace(definitionNamespace);
String schemaNamespace = "http://www.springframework.org/spring-ws/schema";
definition.addNamespace("schema", schemaNamespace);
Resource resource = new ClassPathResource("schema.xsd", getClass());
Document schemaDocument = documentBuilder.parse(SaxUtils.createInputSource(resource));
Types types = definition.createTypes();
definition.setTypes(types);
Schema schema = (Schema) definition.getExtensionRegistry()
.createExtension(Types.class, new QName("http://www.w3.org/2001/XMLSchema", "schema"));
types.addExtensibilityElement(schema);
schema.setElement(schemaDocument.getDocumentElement());
provider.addMessages(definition);
Message message = definition.getMessage(new QName(definitionNamespace, "GetOrderRequest"));
assertNotNull("Message not created", message);
Part part = message.getPart("GetOrderRequest");
assertNotNull("Part not created", part);
assertEquals("Invalid element on part", new QName(schemaNamespace, "GetOrderRequest"), part.getElementName());
message = definition.getMessage(new QName(definitionNamespace, "GetOrderResponse"));
assertNotNull("Message not created", message);
part = message.getPart("GetOrderResponse");
assertNotNull("Part not created", part);
assertEquals("Invalid element on part", new QName(schemaNamespace, "GetOrderResponse"), part.getElementName());
message = definition.getMessage(new QName(definitionNamespace, "GetOrderFault"));
assertNotNull("Message not created", message);
part = message.getPart("GetOrderFault");
assertNotNull("Part not created", part);
assertEquals("Invalid element on part", new QName(schemaNamespace, "GetOrderFault"), part.getElementName());
}
}

View File

@@ -0,0 +1,92 @@
/*
* Copyright ${YEAR} 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.provider;
import javax.wsdl.Definition;
import javax.wsdl.Types;
import javax.wsdl.extensions.schema.Schema;
import javax.wsdl.factory.WSDLFactory;
import junit.framework.TestCase;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.xml.xsd.SimpleXsdSchema;
import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection;
public class InliningXsdSchemaTypesProviderTest extends TestCase {
private InliningXsdSchemaTypesProvider provider;
private Definition definition;
protected void setUp() throws Exception {
provider = new InliningXsdSchemaTypesProvider();
WSDLFactory factory = WSDLFactory.newInstance();
definition = factory.newDefinition();
}
public void testSingle() throws Exception {
String definitionNamespace = "http://springframework.org/spring-ws";
definition.addNamespace("tns", definitionNamespace);
definition.setTargetNamespace(definitionNamespace);
String schemaNamespace = "http://www.springframework.org/spring-ws/schema";
definition.addNamespace("schema", schemaNamespace);
Resource resource = new ClassPathResource("schema.xsd", getClass());
SimpleXsdSchema schema = new SimpleXsdSchema(resource);
schema.afterPropertiesSet();
provider.setSchema(schema);
provider.addTypes(definition);
Types types = definition.getTypes();
assertNotNull("No types created", types);
assertEquals("Invalid amount of schemas", 1, types.getExtensibilityElements().size());
Schema wsdlSchema = (Schema) types.getExtensibilityElements().get(0);
assertNotNull("No element defined", wsdlSchema.getElement());
}
public void testComplex() throws Exception {
String definitionNamespace = "http://springframework.org/spring-ws";
definition.addNamespace("tns", definitionNamespace);
definition.setTargetNamespace(definitionNamespace);
String schemaNamespace = "http://www.springframework.org/spring-ws/schema";
definition.addNamespace("schema", schemaNamespace);
Resource resource = new ClassPathResource("A.xsd", getClass());
CommonsXsdSchemaCollection collection = new CommonsXsdSchemaCollection(new Resource[]{resource});
collection.setInline(true);
collection.afterPropertiesSet();
provider.setSchemaCollection(collection);
provider.addTypes(definition);
Types types = definition.getTypes();
assertNotNull("No types created", types);
assertEquals("Invalid amount of schemas", 2, types.getExtensibilityElements().size());
Schema wsdlSchema = (Schema) types.getExtensibilityElements().get(0);
assertNotNull("No element defined", wsdlSchema.getElement());
wsdlSchema = (Schema) types.getExtensibilityElements().get(1);
assertNotNull("No element defined", wsdlSchema.getElement());
}
}

View File

@@ -0,0 +1,142 @@
/*
* Copyright ${YEAR} 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.provider;
import java.util.Properties;
import javax.wsdl.Binding;
import javax.wsdl.BindingFault;
import javax.wsdl.BindingInput;
import javax.wsdl.BindingOperation;
import javax.wsdl.BindingOutput;
import javax.wsdl.Definition;
import javax.wsdl.Fault;
import javax.wsdl.Input;
import javax.wsdl.Operation;
import javax.wsdl.OperationType;
import javax.wsdl.Output;
import javax.wsdl.Port;
import javax.wsdl.PortType;
import javax.wsdl.Service;
import javax.wsdl.extensions.soap.SOAPAddress;
import javax.wsdl.extensions.soap.SOAPBinding;
import javax.wsdl.extensions.soap.SOAPBody;
import javax.wsdl.extensions.soap.SOAPFault;
import javax.wsdl.extensions.soap.SOAPOperation;
import javax.wsdl.factory.WSDLFactory;
import javax.xml.namespace.QName;
import junit.framework.TestCase;
public class Soap11ProviderTest extends TestCase {
private Soap11Provider provider;
private Definition definition;
protected void setUp() throws Exception {
provider = new Soap11Provider();
WSDLFactory factory = WSDLFactory.newInstance();
definition = factory.newDefinition();
}
public void testPopulateBinding() throws Exception {
String namespace = "http://springframework.org/spring-ws";
definition.addNamespace("tns", namespace);
definition.setTargetNamespace(namespace);
PortType portType = definition.createPortType();
portType.setQName(new QName(namespace, "PortType"));
portType.setUndefined(false);
definition.addPortType(portType);
Operation operation = definition.createOperation();
operation.setName("Operation");
operation.setUndefined(false);
operation.setStyle(OperationType.REQUEST_RESPONSE);
portType.addOperation(operation);
Input input = definition.createInput();
input.setName("Input");
operation.setInput(input);
Output output = definition.createOutput();
output.setName("Output");
operation.setOutput(output);
Fault fault = definition.createFault();
fault.setName("Fault");
operation.addFault(fault);
Properties soapActions = new Properties();
soapActions.setProperty("Operation", namespace + "/Action");
provider.setSoapActions(soapActions);
provider.setServiceName("Service");
String locationUri = "http://localhost:8080/services";
provider.setLocationUri(locationUri);
provider.addBindings(definition);
provider.addServices(definition);
Binding binding = definition.getBinding(new QName(namespace, "PortTypeSoap11"));
assertNotNull("No binding created", binding);
assertEquals("Invalid port type", portType, binding.getPortType());
assertEquals("Invalid amount of extensibility elements", 1, binding.getExtensibilityElements().size());
SOAPBinding soapBinding = (SOAPBinding) binding.getExtensibilityElements().get(0);
assertEquals("Invalid style", "document", soapBinding.getStyle());
assertEquals("Invalid amount of binding operations", 1, binding.getBindingOperations().size());
BindingOperation bindingOperation = binding.getBindingOperation("Operation", "Input", "Output");
assertNotNull("No binding operation created", bindingOperation);
assertEquals("Invalid amount of extensibility elements", 1, bindingOperation.getExtensibilityElements().size());
SOAPOperation soapOperation = (SOAPOperation) bindingOperation.getExtensibilityElements().get(0);
assertEquals("Invalid SOAPAction", namespace + "/Action", soapOperation.getSoapActionURI());
BindingInput bindingInput = bindingOperation.getBindingInput();
assertNotNull("No binding input", bindingInput);
assertEquals("Invalid name", "Input", bindingInput.getName());
assertEquals("Invalid amount of extensibility elements", 1, bindingInput.getExtensibilityElements().size());
SOAPBody soapBody = (SOAPBody) bindingInput.getExtensibilityElements().get(0);
assertEquals("Invalid soap body use", "literal", soapBody.getUse());
BindingOutput bindingOutput = bindingOperation.getBindingOutput();
assertNotNull("No binding output", bindingOutput);
assertEquals("Invalid name", "Output", bindingOutput.getName());
assertEquals("Invalid amount of extensibility elements", 1, bindingOutput.getExtensibilityElements().size());
soapBody = (SOAPBody) bindingOutput.getExtensibilityElements().get(0);
assertEquals("Invalid soap body use", "literal", soapBody.getUse());
BindingFault bindingFault = bindingOperation.getBindingFault("Fault");
assertNotNull("No binding fault", bindingFault);
assertEquals("Invalid amount of extensibility elements", 1, bindingFault.getExtensibilityElements().size());
SOAPFault soapFault = (SOAPFault) bindingFault.getExtensibilityElements().get(0);
assertEquals("Invalid soap fault use", "literal", soapFault.getUse());
Service service = definition.getService(new QName(namespace, "Service"));
assertNotNull("No Service created", service);
assertEquals("Invalid amount of ports", 1, service.getPorts().size());
Port port = service.getPort("PortTypeSoap11");
assertNotNull("No port created", port);
assertEquals("Invalid binding", binding, port.getBinding());
assertEquals("Invalid amount of extensibility elements", 1, port.getExtensibilityElements().size());
SOAPAddress soapAddress = (SOAPAddress) port.getExtensibilityElements().get(0);
assertEquals("Invalid soap address", locationUri, soapAddress.getLocationURI());
}
}

View File

@@ -0,0 +1,142 @@
/*
* Copyright ${YEAR} 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.provider;
import java.util.Properties;
import javax.wsdl.Binding;
import javax.wsdl.BindingFault;
import javax.wsdl.BindingInput;
import javax.wsdl.BindingOperation;
import javax.wsdl.BindingOutput;
import javax.wsdl.Definition;
import javax.wsdl.Fault;
import javax.wsdl.Input;
import javax.wsdl.Operation;
import javax.wsdl.OperationType;
import javax.wsdl.Output;
import javax.wsdl.Port;
import javax.wsdl.PortType;
import javax.wsdl.Service;
import javax.wsdl.extensions.soap12.SOAP12Address;
import javax.wsdl.extensions.soap12.SOAP12Binding;
import javax.wsdl.extensions.soap12.SOAP12Body;
import javax.wsdl.extensions.soap12.SOAP12Fault;
import javax.wsdl.extensions.soap12.SOAP12Operation;
import javax.wsdl.factory.WSDLFactory;
import javax.xml.namespace.QName;
import junit.framework.TestCase;
public class Soap12ProviderTest extends TestCase {
private Soap12Provider provider;
private Definition definition;
protected void setUp() throws Exception {
provider = new Soap12Provider();
WSDLFactory factory = WSDLFactory.newInstance();
definition = factory.newDefinition();
}
public void testPopulateBinding() throws Exception {
String namespace = "http://springframework.org/spring-ws";
definition.addNamespace("tns", namespace);
definition.setTargetNamespace(namespace);
PortType portType = definition.createPortType();
portType.setQName(new QName(namespace, "PortType"));
portType.setUndefined(false);
definition.addPortType(portType);
Operation operation = definition.createOperation();
operation.setName("Operation");
operation.setUndefined(false);
operation.setStyle(OperationType.REQUEST_RESPONSE);
portType.addOperation(operation);
Input input = definition.createInput();
input.setName("Input");
operation.setInput(input);
Output output = definition.createOutput();
output.setName("Output");
operation.setOutput(output);
Fault fault = definition.createFault();
fault.setName("Fault");
operation.addFault(fault);
Properties soapActions = new Properties();
soapActions.setProperty("Operation", namespace + "/Action");
provider.setSoapActions(soapActions);
provider.setServiceName("Service");
String locationUri = "http://localhost:8080/services";
provider.setLocationUri(locationUri);
provider.addBindings(definition);
provider.addServices(definition);
Binding binding = definition.getBinding(new QName(namespace, "PortTypeSoap12"));
assertNotNull("No binding created", binding);
assertEquals("Invalid port type", portType, binding.getPortType());
assertEquals("Invalid amount of extensibility elements", 1, binding.getExtensibilityElements().size());
SOAP12Binding soapBinding = (SOAP12Binding) binding.getExtensibilityElements().get(0);
assertEquals("Invalid style", "document", soapBinding.getStyle());
assertEquals("Invalid amount of binding operations", 1, binding.getBindingOperations().size());
BindingOperation bindingOperation = binding.getBindingOperation("Operation", "Input", "Output");
assertNotNull("No binding operation created", bindingOperation);
assertEquals("Invalid amount of extensibility elements", 1, bindingOperation.getExtensibilityElements().size());
SOAP12Operation soapOperation = (SOAP12Operation) bindingOperation.getExtensibilityElements().get(0);
assertEquals("Invalid SOAPAction", namespace + "/Action", soapOperation.getSoapActionURI());
BindingInput bindingInput = bindingOperation.getBindingInput();
assertNotNull("No binding input", bindingInput);
assertEquals("Invalid name", "Input", bindingInput.getName());
assertEquals("Invalid amount of extensibility elements", 1, bindingInput.getExtensibilityElements().size());
SOAP12Body soapBody = (SOAP12Body) bindingInput.getExtensibilityElements().get(0);
assertEquals("Invalid soap body use", "literal", soapBody.getUse());
BindingOutput bindingOutput = bindingOperation.getBindingOutput();
assertNotNull("No binding output", bindingOutput);
assertEquals("Invalid name", "Output", bindingOutput.getName());
assertEquals("Invalid amount of extensibility elements", 1, bindingOutput.getExtensibilityElements().size());
soapBody = (SOAP12Body) bindingOutput.getExtensibilityElements().get(0);
assertEquals("Invalid soap body use", "literal", soapBody.getUse());
BindingFault bindingFault = bindingOperation.getBindingFault("Fault");
assertNotNull("No binding fault", bindingFault);
assertEquals("Invalid amount of extensibility elements", 1, bindingFault.getExtensibilityElements().size());
SOAP12Fault soapFault = (SOAP12Fault) bindingFault.getExtensibilityElements().get(0);
assertEquals("Invalid soap fault use", "literal", soapFault.getUse());
Service service = definition.getService(new QName(namespace, "Service"));
assertNotNull("No Service created", service);
assertEquals("Invalid amount of ports", 1, service.getPorts().size());
Port port = service.getPort("PortTypeSoap12");
assertNotNull("No port created", port);
assertEquals("Invalid binding", binding, port.getBinding());
assertEquals("Invalid amount of extensibility elements", 1, port.getExtensibilityElements().size());
SOAP12Address soapAddress = (SOAP12Address) port.getExtensibilityElements().get(0);
assertEquals("Invalid soap address", locationUri, soapAddress.getLocationURI());
}
}

View File

@@ -0,0 +1,102 @@
/*
* Copyright ${YEAR} 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.provider;
import java.util.Properties;
import javax.wsdl.Binding;
import javax.wsdl.Definition;
import javax.wsdl.Fault;
import javax.wsdl.Input;
import javax.wsdl.Operation;
import javax.wsdl.OperationType;
import javax.wsdl.Output;
import javax.wsdl.Port;
import javax.wsdl.PortType;
import javax.wsdl.Service;
import javax.wsdl.factory.WSDLFactory;
import javax.xml.namespace.QName;
import junit.framework.TestCase;
public class SoapProviderTest extends TestCase {
private SoapProvider provider;
private Definition definition;
protected void setUp() throws Exception {
provider = new SoapProvider();
WSDLFactory factory = WSDLFactory.newInstance();
definition = factory.newDefinition();
}
public void testPopulateBinding() throws Exception {
String namespace = "http://springframework.org/spring-ws";
definition.addNamespace("tns", namespace);
definition.setTargetNamespace(namespace);
PortType portType = definition.createPortType();
portType.setQName(new QName(namespace, "PortType"));
portType.setUndefined(false);
definition.addPortType(portType);
Operation operation = definition.createOperation();
operation.setName("Operation");
operation.setUndefined(false);
operation.setStyle(OperationType.REQUEST_RESPONSE);
portType.addOperation(operation);
Input input = definition.createInput();
input.setName("Input");
operation.setInput(input);
Output output = definition.createOutput();
output.setName("Output");
operation.setOutput(output);
Fault fault = definition.createFault();
fault.setName("Fault");
operation.addFault(fault);
Properties soapActions = new Properties();
soapActions.setProperty("Operation", namespace + "/Action");
provider.setSoapActions(soapActions);
provider.setServiceName("Service");
String locationUri = "http://localhost:8080/services";
provider.setLocationUri(locationUri);
provider.setCreateSoap11Binding(true);
provider.setCreateSoap12Binding(true);
provider.addBindings(definition);
provider.addServices(definition);
Binding binding = definition.getBinding(new QName(namespace, "PortTypeSoap11"));
assertNotNull("No SOAP 1.1 binding created", binding);
binding = definition.getBinding(new QName(namespace, "PortTypeSoap12"));
assertNotNull("No SOAP 1.2 binding created", binding);
Service service = definition.getService(new QName(namespace, "Service"));
assertNotNull("No Service created", service);
assertEquals("Invalid amount of ports", 2, service.getPorts().size());
Port port = service.getPort("PortTypeSoap11");
assertNotNull("No SOAP 1.1 port created", port);
port = service.getPort("PortTypeSoap12");
assertNotNull("No SOAP 1.2 port created", port);
}
}

View File

@@ -0,0 +1,69 @@
/*
* Copyright ${YEAR} 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.provider;
import javax.wsdl.Definition;
import javax.wsdl.Message;
import javax.wsdl.Operation;
import javax.wsdl.PortType;
import javax.wsdl.factory.WSDLFactory;
import javax.xml.namespace.QName;
import junit.framework.TestCase;
public class SuffixBasedPortTypesProviderTest extends TestCase {
private SuffixBasedPortTypesProvider provider;
private Definition definition;
protected void setUp() throws Exception {
provider = new SuffixBasedPortTypesProvider();
WSDLFactory factory = WSDLFactory.newInstance();
definition = factory.newDefinition();
}
public void testAddPortTypes() throws Exception {
String namespace = "http://springframework.org/spring-ws";
definition.addNamespace("tns", namespace);
definition.setTargetNamespace(namespace);
Message message = definition.createMessage();
message.setQName(new QName(namespace, "OperationRequest"));
definition.addMessage(message);
message = definition.createMessage();
message.setQName(new QName(namespace, "OperationResponse"));
definition.addMessage(message);
message = definition.createMessage();
message.setQName(new QName(namespace, "OperationFault"));
definition.addMessage(message);
provider.setPortTypeName("PortType");
provider.addPortTypes(definition);
PortType portType = definition.getPortType(new QName(namespace, "PortType"));
assertNotNull("No port type created", portType);
Operation operation = portType.getOperation("Operation", "OperationRequest", "OperationResponse");
assertNotNull("No operation created", operation);
assertNotNull("No input created", operation.getInput());
assertNotNull("No output created", operation.getOutput());
assertFalse("No fault created", operation.getFaults().isEmpty());
}
}

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:1"
xmlns:tns="urn:1" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xsd:include schemaLocation="B.xsd"/>
<xsd:simpleType name="A">
<xsd:restriction base="tns:B"/>
</xsd:simpleType>
</xsd:schema>

View File

@@ -0,0 +1,16 @@
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns0="urn:2" xmlns:tns="urn:1"
attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="urn:1">
<xsd:import namespace="urn:2" schemaLocation="D.xsd"/>
<xsd:simpleType name="A">
<xsd:restriction base="tns:B"/>
</xsd:simpleType>
<xsd:complexType name="B">
<xsd:sequence>
<xsd:element name="c" type="tns:C"/>
<xsd:element name="d" type="ns0:D"/>
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="C">
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>
</xsd:schema>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:1"
xmlns="urn:1"
xmlns:imported="urn:2" elementFormDefault="qualified">
<xsd:include schemaLocation="C.xsd"/>
<xsd:import schemaLocation="D.xsd" namespace="urn:2"/>
<xsd:complexType name="B">
<xsd:sequence>
<xsd:element type="C" name="c"/>
<xsd:element type="imported:D" name="d"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xsd:simpleType name="C">
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>
</xsd:schema>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:2"
xmlns="urn:2" elementFormDefault="qualified">
<xsd:include schemaLocation="C.xsd"/>
<xsd:simpleType name="D">
<xsd:restriction base="C"/>
</xsd:simpleType>
</xsd:schema>

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.springframework.org/spring-ws/schema"
xmlns="http://www.springframework.org/spring-ws/schema" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xsd:simpleType name="customType">
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>
<xsd:element name="GetOrderRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="child" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetOrderResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="child" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetOrderFault">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="child" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>