- Removed packages scheduled for removal in 2.0.

- Added @Deprecated annotations.
This commit is contained in:
Arjen Poutsma
2010-02-01 11:25:25 +00:00
parent 9bc9786a0a
commit aba8e64434
44 changed files with 31 additions and 4897 deletions

View File

@@ -171,10 +171,22 @@
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>easymock</groupId>
<artifactId>easymock</artifactId>
<version>1.2_Java1.3</version>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.5.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.5.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.1_3</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005 the original author or authors.
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -191,6 +191,7 @@ public abstract class AbstractMarshallingPayloadEndpoint implements MessageEndpo
* @deprecated as of Spring Web Services 1.5: {@link #afterPropertiesSet()} is no longer final, so this can safely
* be overriden in subclasses
*/
@Deprecated
public void afterMarshallerSet() throws Exception {
}

View File

@@ -1,95 +0,0 @@
/*
* Copyright 2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.wsdl.wsdl11;
import javax.xml.transform.Source;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
/**
* <code>Wsdl11Definition</code> that creates a WSDL definition at runtime, using a {@link Wsdl11DefinitionBuilder}. Can
* be instructed to build abstract or concrete parts of the definition, by setting the <code>buildAbstractPart</code>
* and <code>buildConcretePart</code> properties.
*
* @author Arjen Poutsma
* @see #setBuilder(Wsdl11DefinitionBuilder)
* @see #setBuildAbstractPart(boolean)
* @see #setBuildConcretePart(boolean)
* @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 DynamicWsdl11Definition implements Wsdl11Definition, InitializingBean {
private Wsdl11DefinitionBuilder builder;
private Wsdl11Definition definition;
private boolean buildAbstractPart = true;
private boolean buildConcretePart = true;
public void setBuilder(Wsdl11DefinitionBuilder builder) {
this.builder = builder;
}
/**
* Indicates whether the built definition should contain an abstract part. If set to <code>true</code> (the default)
* the definition will contain types, messages, and portTypes; if <code>false</code>, it will not.
*/
public void setBuildAbstractPart(boolean buildAbstractPart) {
this.buildAbstractPart = buildAbstractPart;
}
/**
* Indicates whether the built definition should contain an concrete part. If set to <code>true</code> (the default)
* the definition will contain bindings, and services; if <code>false</code>, it will not.
*/
public void setBuildConcretePart(boolean buildConcretePart) {
this.buildConcretePart = buildConcretePart;
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(builder, "builder is required");
builder.buildDefinition();
builder.buildImports();
if (buildAbstractPart) {
builder.buildTypes();
builder.buildMessages();
builder.buildPortTypes();
}
if (buildConcretePart) {
builder.buildBindings();
builder.buildServices();
}
definition = builder.getDefinition();
}
public Source getSource() {
return definition.getSource();
}
public String toString() {
if (definition != null) {
return definition.toString();
}
else {
return "DynamicWsdl11Definition";
}
}
}

View File

@@ -1,90 +0,0 @@
/*
* Copyright 2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.wsdl.wsdl11;
import org.springframework.ws.wsdl.WsdlDefinitionException;
/**
* Defines the contract for classes that can create a {@link Wsdl11Definition} at runtime.
* <p/>
* Used by {@link DynamicWsdl11Definition} to generate the WSDL based on a schema, a class, etc.
*
* @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 interface Wsdl11DefinitionBuilder {
/**
* Builds a new, empty definition. This method should be called before all others.
*
* @throws WsdlDefinitionException in case of errors
*/
void buildDefinition() throws WsdlDefinitionException;
/**
* Adds imports to the definition.
*
* @throws WsdlDefinitionException in case of errors
*/
void buildImports() throws WsdlDefinitionException;
/**
* Adds types to the definition.
*
* @throws WsdlDefinitionException in case of errors
*/
void buildTypes() throws WsdlDefinitionException;
/**
* Adds messages to the definition.
*
* @throws WsdlDefinitionException in case of errors
*/
void buildMessages() throws WsdlDefinitionException;
/**
* Adds portTypes to the definition.
*
* @throws WsdlDefinitionException in case of errors
*/
void buildPortTypes() throws WsdlDefinitionException;
/**
* Adds bindings to the definition.
*
* @throws WsdlDefinitionException in case of errors
*/
void buildBindings() throws WsdlDefinitionException;
/**
* Adds services to the definition.
*
* @throws WsdlDefinitionException in case of errors
*/
void buildServices() throws WsdlDefinitionException;
/**
* Returns the built <code>Wsdl11Definition</code>.
*
* @return the WSDL definition, or <code>null</code> if {@link #buildDefinition()} has not been called
* @throws WsdlDefinitionException in case of errors
*/
Wsdl11Definition getDefinition() throws WsdlDefinitionException;
}

View File

@@ -1,257 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.builder;
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;
/**
* Abstract base class for <code>Wsdl11DefinitionBuilder</code> implementations that use WSDL4J and contain a concrete
* part. 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.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 {
/** The suffix used to create a binding name from a port type name. */
private static final String BINDING_SUFFIX = "Binding";
/** The suffix used to create a binding name from a port type name. */
private static final String PORT_SUFFIX = "Port";
/**
* Creates a {@link Binding} for each {@link PortType} in the definition, and calls {@link #populateBinding(Binding,
* PortType)} 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(Binding, PortType)
* @see #populateBindingOperation(BindingOperation, Operation)
* @see #populateBindingInput(BindingInput, Input)
* @see #populateBindingOutput(BindingOutput, Output)
* @see #populateBindingFault(BindingFault, Fault)
*/
@Override
public void buildBindings(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(binding, portType);
createBindingOperations(definition, binding, portType);
binding.setUndefined(false);
definition.addBinding(binding);
}
}
/**
* Called after the {@link Binding} 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 sets the binding name to the port type name with the suffix {@link Binding} appended to
* it.
*
* @param binding the WSDL4J <code>Binding</code>
* @param portType the corresponding <code>PortType</code>
* @throws WSDLException in case of errors
*/
protected void populateBinding(Binding binding, PortType portType) throws WSDLException {
QName portTypeName = portType.getQName();
if (portTypeName != null) {
binding.setQName(new QName(portTypeName.getNamespaceURI(), portTypeName.getLocalPart() + BINDING_SUFFIX));
}
}
private void createBindingOperations(Definition definition, Binding binding, PortType portType)
throws WSDLException {
for (Iterator operationIterator = portType.getOperations().iterator(); operationIterator.hasNext();) {
Operation operation = (Operation) operationIterator.next();
BindingOperation bindingOperation = definition.createBindingOperation();
bindingOperation.setOperation(operation);
populateBindingOperation(bindingOperation, operation);
if (operation.getStyle() == null || operation.getStyle().equals(OperationType.REQUEST_RESPONSE)) {
createBindingInput(definition, operation, bindingOperation);
createBindingOutput(definition, operation, bindingOperation);
}
else if (operation.getStyle().equals(OperationType.ONE_WAY)) {
createBindingInput(definition, operation, bindingOperation);
}
else if (operation.getStyle().equals(OperationType.NOTIFICATION)) {
createBindingOutput(definition, operation, bindingOperation);
}
else if (operation.getStyle().equals(OperationType.SOLICIT_RESPONSE)) {
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(bindingFault, fault);
bindingOperation.addBindingFault(bindingFault);
}
binding.addBindingOperation(bindingOperation);
}
}
private void createBindingOutput(Definition definition, Operation operation, BindingOperation bindingOperation)
throws WSDLException {
BindingOutput bindingOutput = definition.createBindingOutput();
populateBindingOutput(bindingOutput, operation.getOutput());
bindingOperation.setBindingOutput(bindingOutput);
}
private void createBindingInput(Definition definition, Operation operation, BindingOperation bindingOperation)
throws WSDLException {
BindingInput bindingInput = definition.createBindingInput();
populateBindingInput(bindingInput, operation.getInput());
bindingOperation.setBindingInput(bindingInput);
}
/**
* 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 sets the name of the binding operation to the name of the operation.
*
* @param bindingOperation the WSDL4J <code>BindingOperation</code>
* @param operation the corresponding WSDL4J <code>Operation</code>
* @throws WSDLException in case of errors
*/
protected void populateBindingOperation(BindingOperation bindingOperation, Operation operation)
throws WSDLException {
bindingOperation.setName(operation.getName());
}
/**
* 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 set the name of the binding input to the name of the input.
*
* @param bindingInput the WSDL4J <code>BindingInput</code>
* @param input the corresponding WSDL4J <code>Input</code>
* @throws WSDLException in case of errors
*/
protected void populateBindingInput(BindingInput bindingInput, Input input) throws WSDLException {
bindingInput.setName(input.getName());
}
/**
* Called after the {@link BindingOutput} 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 output to the name of the output.
*
* @param bindingOutput the WSDL4J <code>BindingOutput</code>
* @param output the corresponding WSDL4J <code>Output</code>
* @throws WSDLException in case of errors
*/
protected void populateBindingOutput(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(BindingFault bindingFault, Fault fault) throws WSDLException {
bindingFault.setName(fault.getName());
}
/**
* Creates a single {@link Service}, and calls {@link #populateService(Service)} with it. Creates a corresponding
* {@link Port} for each {@link Binding}, which is passed to {@link #populatePort(Port, Binding)}.
*
* @param definition the WSDL4J <code>Definition</code>
* @throws WSDLException in case of errors
* @see #populatePort(Port, Binding)
*/
@Override
public void buildServices(Definition definition) throws WSDLException {
Service service = definition.createService();
populateService(service);
createPorts(definition, service);
definition.addService(service);
}
/**
* Called after the {@link Binding} 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 is empty.
*
* @param service the WSDL4J <code>Service</code>
* @throws WSDLException in case of errors
*/
protected void populateService(Service service) throws WSDLException {
}
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 = definition.createPort();
port.setBinding(binding);
populatePort(port, binding);
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 port type name with the suffix {@link Port} appended to it.
*
* @param port the WSDL4J <code>Port</code>
* @param binding the corresponding WSDL4J <code>Binding</code>
* @throws WSDLException in case of errors
*/
protected void populatePort(Port port, Binding binding) throws WSDLException {
if (binding.getPortType() != null && binding.getPortType().getQName() != null) {
port.setName(binding.getPortType().getQName().getLocalPart() + PORT_SUFFIX);
}
}
}

View File

@@ -1,255 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.builder;
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.Output;
import javax.wsdl.Port;
import javax.wsdl.PortType;
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;
/**
* Abstract base class for <code>Wsdl11DefinitionBuilder</code> implementations that use WSDL4J and contain a SOAP 1.1
* binding. Requires the <code>locationUri</code> property to be set before use.
*
* @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 {
private static final String WSDL_SOAP_NAMESPACE_URI = "http://schemas.xmlsoap.org/wsdl/soap/";
private static final String WSDL_SOAP_PREFIX = "soap";
/** The default soap:binding transport attribute value. */
public static final String DEFAULT_TRANSPORT_URI = "http://schemas.xmlsoap.org/soap/http";
private String transportUri = DEFAULT_TRANSPORT_URI;
private String locationUri;
/**
* Sets the value used for the soap:binding transport attribute value.
*
* @see SOAPBinding#setTransportURI(String)
* @see #DEFAULT_TRANSPORT_URI
*/
public void setTransportUri(String transportUri) {
this.transportUri = transportUri;
}
/** Sets the value used for the soap:address location attribute value. */
public void setLocationUri(String locationUri) {
this.locationUri = locationUri;
}
/** Adds the WSDL SOAP namespace to the definition. */
@Override
protected void populateDefinition(Definition definition) throws WSDLException {
definition.addNamespace(WSDL_SOAP_PREFIX, WSDL_SOAP_NAMESPACE_URI);
}
/**
* Calls {@link AbstractBindingWsdl4jDefinitionBuilder#populateBinding(Binding, PortType)}, creates {@link
* SOAPBinding}, and calls {@link #populateSoapBinding(SOAPBinding)}.
*
* @param binding the WSDL4J <code>Binding</code>
* @param portType the corresponding <code>PortType</code>
* @throws WSDLException in case of errors
*/
@Override
protected void populateBinding(Binding binding, PortType portType) throws WSDLException {
super.populateBinding(binding, portType);
SOAPBinding soapBinding = (SOAPBinding) createSoapExtension(Binding.class, "binding");
populateSoapBinding(soapBinding);
binding.addExtensibilityElement(soapBinding);
}
/**
* Called after the {@link SOAPBinding} has been created. Default implementation sets the binding style to
* <code>"document"</code>, and set the transport URI to the value set on this builder. 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) throws WSDLException {
soapBinding.setStyle("document");
soapBinding.setTransportURI(transportUri);
}
/**
* Calls {@link AbstractBindingWsdl4jDefinitionBuilder#populateBindingOperation(BindingOperation, Operation)},
* creates a {@link SOAPOperation}, and calls {@link #populateSoapOperation(SOAPOperation)}.
*
* @param bindingOperation the WSDL4J <code>BindingOperation</code>
* @throws WSDLException in case of errors
*/
@Override
protected void populateBindingOperation(BindingOperation bindingOperation, Operation operation)
throws WSDLException {
super.populateBindingOperation(bindingOperation, operation);
SOAPOperation soapOperation = (SOAPOperation) createSoapExtension(BindingOperation.class, "operation");
populateSoapOperation(soapOperation);
bindingOperation.addExtensibilityElement(soapOperation);
}
/**
* Called after the {@link SOAPOperation} has been created.
* <p/>
* Default implementation set the <code>SOAPAction</code> uri to an empty string.
*
* @param soapOperation the WSDL4J <code>SOAPOperation</code>
* @throws WSDLException in case of errors
* @see SOAPOperation#setSoapActionURI(String)
*/
protected void populateSoapOperation(SOAPOperation soapOperation) throws WSDLException {
soapOperation.setSoapActionURI("");
}
/**
* Creates a {@link SOAPBody}, and calls {@link #populateSoapBody(SOAPBody)}.
*
* @param bindingInput the WSDL4J <code>BindingInput</code>
* @throws WSDLException in case of errors
*/
@Override
protected void populateBindingInput(BindingInput bindingInput, Input input) throws WSDLException {
super.populateBindingInput(bindingInput, input);
SOAPBody soapBody = (SOAPBody) createSoapExtension(BindingInput.class, "body");
populateSoapBody(soapBody);
bindingInput.addExtensibilityElement(soapBody);
}
/**
* Creates a {@link SOAPBody}, and calls {@link #populateSoapBody(SOAPBody)}.
*
* @param bindingOutput the WSDL4J <code>BindingOutput</code>
* @throws WSDLException in case of errors
*/
@Override
protected void populateBindingOutput(BindingOutput bindingOutput, Output output) throws WSDLException {
super.populateBindingOutput(bindingOutput, output);
SOAPBody soapBody = (SOAPBody) createSoapExtension(BindingOutput.class, "body");
populateSoapBody(soapBody);
bindingOutput.addExtensibilityElement(soapBody);
}
/**
* Creates a {@link SOAPBody}, and calls {@link #populateSoapBody(SOAPBody)}.
*
* @param bindingFault the WSDL4J <code>BindingFault</code>
* @throws WSDLException in case of errors
*/
@Override
protected void populateBindingFault(BindingFault bindingFault, Fault fault) throws WSDLException {
super.populateBindingFault(bindingFault, fault);
SOAPFault soapFault = (SOAPFault) createSoapExtension(BindingFault.class, "fault");
populateSoapFault(bindingFault, soapFault);
bindingFault.addExtensibilityElement(soapFault);
}
/**
* Called after the {@link SOAPBody} has been created. 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 SOAPFault} has been created. 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");
}
/**
* Creates a {@link SOAPAddress}, and calls {@link #populateSoapAddress(SOAPAddress)}.
*
* @param port the WSDL4J <code>Port</code>
* @throws WSDLException in case of errors
*/
@Override
protected void populatePort(Port port, Binding binding) throws WSDLException {
super.populatePort(port, binding);
SOAPAddress soapAddress = (SOAPAddress) createSoapExtension(Port.class, "address");
populateSoapAddress(soapAddress);
port.addExtensibilityElement(soapAddress);
}
/**
* 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(locationUri);
}
/**
* Creates a SOAP extensibility element.
*
* @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,javax.xml.namespace.QName)
*/
protected ExtensibilityElement createSoapExtension(Class parentType, String localName) throws WSDLException {
return createExtension(parentType, new QName(WSDL_SOAP_NAMESPACE_URI, localName));
}
}

View File

@@ -1,256 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.builder;
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.Output;
import javax.wsdl.Port;
import javax.wsdl.PortType;
import javax.wsdl.WSDLException;
import javax.wsdl.extensions.ExtensibilityElement;
import javax.wsdl.extensions.ExtensionRegistry;
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;
/**
* Abstract base class for <code>Wsdl11DefinitionBuilder</code> implementations that use WSDL4J and contain a SOAP 1.2
* binding. Requires the <code>locationUri</code> property to be set before use.
*
* @author Arjen Poutsma
* @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 {
private static final String WSDL_SOAP_NAMESPACE_URI = "http://schemas.xmlsoap.org/wsdl/soap12/";
private static final String WSDL_SOAP_PREFIX = "soap12";
/** 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;
private String locationUri;
/**
* Sets the value used for the soap12:binding transport attribute value.
*
* @see SOAP12Binding#setTransportURI(String)
* @see #DEFAULT_TRANSPORT_URI
*/
public void setTransportUri(String transportUri) {
this.transportUri = transportUri;
}
/** 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. */
@Override
protected void populateDefinition(Definition definition) throws WSDLException {
definition.addNamespace(WSDL_SOAP_PREFIX, WSDL_SOAP_NAMESPACE_URI);
}
/**
* Calls {@link AbstractBindingWsdl4jDefinitionBuilder#populateBinding(Binding, PortType)}, creates {@link
* SOAP12Binding}, and calls {@link #populateSoapBinding(SOAP12Binding)}.
*
* @param binding the WSDL4J <code>Binding</code>
* @param portType the corresponding <code>PortType</code>
* @throws WSDLException in case of errors
*/
@Override
protected void populateBinding(Binding binding, PortType portType) throws WSDLException {
super.populateBinding(binding, portType);
SOAP12Binding soapBinding = (SOAP12Binding) createSoapExtension(Binding.class, "binding");
populateSoapBinding(soapBinding);
binding.addExtensibilityElement(soapBinding);
}
/**
* Called after the {@link SOAP12Binding} has been created. Default implementation sets the binding style to
* <code>"document"</code>, and set the transport URI to the value set on this builder. Subclasses can override this
* behavior.
*
* @param soapBinding the WSDL4J <code>SOAP12Binding</code>
* @throws WSDLException in case of errors
* @see SOAP12Binding#setStyle(String)
* @see SOAP12Binding#setTransportURI(String)
* @see #setTransportUri(String)
* @see #DEFAULT_TRANSPORT_URI
*/
protected void populateSoapBinding(SOAP12Binding soapBinding) throws WSDLException {
soapBinding.setStyle("document");
soapBinding.setTransportURI(transportUri);
}
/**
* Calls {@link AbstractBindingWsdl4jDefinitionBuilder#populateBindingOperation(BindingOperation, Operation)},
* creates a {@link SOAP12Operation}, and calls {@link #populateSoapOperation(SOAP12Operation)}.
*
* @param bindingOperation the WSDL4J <code>BindingOperation</code>
* @throws WSDLException in case of errors
*/
@Override
protected void populateBindingOperation(BindingOperation bindingOperation, Operation operation)
throws WSDLException {
super.populateBindingOperation(bindingOperation, operation);
SOAP12Operation soapOperation = (SOAP12Operation) createSoapExtension(BindingOperation.class, "operation");
populateSoapOperation(soapOperation);
bindingOperation.addExtensibilityElement(soapOperation);
}
/**
* Called after the {@link SOAP12Operation} has been created.
* <p/>
* Default implementation set the <code>SOAPAction</code> uri to an empty string.
*
* @param soapOperation the WSDL4J <code>SOAP12Operation</code>
* @throws WSDLException in case of errors
* @see SOAP12Operation#setSoapActionURI(String)
*/
protected void populateSoapOperation(SOAP12Operation soapOperation) throws WSDLException {
soapOperation.setSoapActionURI("");
}
/**
* Creates a {@link SOAP12Body}, and calls {@link #populateSoapBody(SOAP12Body)}.
*
* @param bindingInput the WSDL4J <code>BindingInput</code>
* @throws WSDLException in case of errors
*/
@Override
protected void populateBindingInput(BindingInput bindingInput, Input input) throws WSDLException {
super.populateBindingInput(bindingInput, input);
SOAP12Body soapBody = (SOAP12Body) createSoapExtension(BindingInput.class, "body");
populateSoapBody(soapBody);
bindingInput.addExtensibilityElement(soapBody);
}
/**
* Creates a {@link SOAP12Body}, and calls {@link #populateSoapBody(SOAP12Body)}.
*
* @param bindingOutput the WSDL4J <code>BindingOutput</code>
* @throws WSDLException in case of errors
*/
@Override
protected void populateBindingOutput(BindingOutput bindingOutput, Output output) throws WSDLException {
super.populateBindingOutput(bindingOutput, output);
SOAP12Body soapBody = (SOAP12Body) createSoapExtension(BindingOutput.class, "body");
populateSoapBody(soapBody);
bindingOutput.addExtensibilityElement(soapBody);
}
/**
* Creates a {@link SOAP12Body}, and calls {@link #populateSoapBody(SOAP12Body)}.
*
* @param bindingFault the WSDL4J <code>BindingFault</code>
* @throws WSDLException in case of errors
*/
@Override
protected void populateBindingFault(BindingFault bindingFault, Fault fault) throws WSDLException {
super.populateBindingFault(bindingFault, fault);
SOAP12Fault soapFault = (SOAP12Fault) createSoapExtension(BindingFault.class, "fault");
populateSoapFault(bindingFault, soapFault);
bindingFault.addExtensibilityElement(soapFault);
}
/**
* Called after the {@link SOAP12Body} has been created. Default implementation sets the use style to
* <code>"literal"</code>. Subclasses can override this behavior.
*
* @param soapBody the WSDL4J <code>SOAP12Body</code>
* @throws WSDLException in case of errors
* @see SOAP12Body#setUse(String)
*/
protected void populateSoapBody(SOAP12Body soapBody) throws WSDLException {
soapBody.setUse("literal");
}
/**
* Called after the {@link SOAP12Fault} has been created. 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 SOAP12Fault#setUse(String)
*/
protected void populateSoapFault(BindingFault bindingFault, SOAP12Fault soapFault) throws WSDLException {
soapFault.setName(bindingFault.getName());
soapFault.setUse("literal");
}
/**
* Creates a {@link SOAP12Address}, and calls {@link #populateSoapAddress(SOAP12Address)}.
*
* @param port the WSDL4J <code>Port</code>
* @throws WSDLException in case of errors
*/
@Override
protected void populatePort(Port port, Binding binding) throws WSDLException {
super.populatePort(port, binding);
SOAP12Address soapAddress = (SOAP12Address) createSoapExtension(Port.class, "address");
populateSoapAddress(soapAddress);
port.addExtensibilityElement(soapAddress);
}
/**
* 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(locationUri);
}
/**
* Creates a SOAP 1.2 extensibility element.
*
* @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,javax.xml.namespace.QName)
*/
protected ExtensibilityElement createSoapExtension(Class parentType, String localName) throws WSDLException {
return createExtension(parentType, new QName(WSDL_SOAP_NAMESPACE_URI, localName));
}
}

View File

@@ -1,202 +0,0 @@
/*
* Copyright 2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.wsdl.wsdl11.builder;
import javax.wsdl.Definition;
import javax.wsdl.WSDLException;
import javax.wsdl.extensions.ExtensibilityElement;
import javax.wsdl.extensions.ExtensionRegistry;
import javax.wsdl.factory.WSDLFactory;
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;
import org.springframework.ws.wsdl.wsdl11.Wsdl4jDefinition;
import org.springframework.ws.wsdl.wsdl11.Wsdl4jDefinitionException;
/**
* Abstract base class for <code>Wsdl11DefinitionBuilder</code> implementations that use WSDL4J. Creates a base {@link
* Definition}, and passes that to subclass template methods.
*
* @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 {
/** Logger available to subclasses. */
protected final Log logger = LogFactory.getLog(getClass());
/** The WSDL4J <code>Definition</code> created by <code>buildDefinition()</code>. */
private Definition definition;
public final void buildDefinition() throws WsdlDefinitionException {
try {
WSDLFactory wsdlFactory = WSDLFactory.newInstance();
definition = wsdlFactory.newDefinition();
if (definition.getExtensionRegistry() == null) {
ExtensionRegistry extensionRegistry = wsdlFactory.newPopulatedExtensionRegistry();
definition.setExtensionRegistry(extensionRegistry);
}
populateExtensionRegistry(definition.getExtensionRegistry());
populateDefinition(definition);
}
catch (WSDLException ex) {
throw new Wsdl4jDefinitionException(ex);
}
}
/**
* Called after the <code>Definition</code> has been created, but before any sub-elements are added. Default
* implementation is empty.
*
* @param definition the WSDL4J <code>Definition</code>
* @throws WSDLException in case of errors
* @see #buildDefinition()
*/
protected void populateDefinition(Definition definition) throws WSDLException {
}
public final void buildImports() throws WsdlDefinitionException {
try {
buildImports(definition);
}
catch (WSDLException ex) {
throw new Wsdl4jDefinitionException(ex);
}
}
/**
* Adds imports to the definition.
*
* @param definition the WSDL4J <code>Definition</code>
* @throws WSDLException in case of errors
*/
protected abstract void buildImports(Definition definition) throws WSDLException;
public final void buildTypes() throws WsdlDefinitionException {
try {
buildTypes(definition);
}
catch (WSDLException ex) {
throw new Wsdl4jDefinitionException(ex);
}
}
/**
* Adds types to the definition.
*
* @param definition the WSDL4J <code>Definition</code>
* @throws WSDLException in case of errors
*/
protected abstract void buildTypes(Definition definition) throws WSDLException;
public final void buildMessages() throws WsdlDefinitionException {
try {
buildMessages(definition);
}
catch (WSDLException ex) {
throw new Wsdl4jDefinitionException(ex);
}
}
/**
* Adds messages to the definition.
*
* @param definition the WSDL4J <code>Definition</code>
* @throws WSDLException in case of errors
*/
protected abstract void buildMessages(Definition definition) throws WSDLException;
public final void buildPortTypes() throws WsdlDefinitionException {
try {
buildPortTypes(definition);
}
catch (WSDLException ex) {
throw new Wsdl4jDefinitionException(ex);
}
}
/**
* Adds port types to the definition.
*
* @param definition the WSDL4J <code>Definition</code>
* @throws WSDLException in case of errors
*/
protected abstract void buildPortTypes(Definition definition) throws WSDLException;
public final void buildBindings() throws WsdlDefinitionException {
try {
buildBindings(definition);
}
catch (WSDLException ex) {
throw new Wsdl4jDefinitionException(ex);
}
}
/**
* Adds bindings to the definition.
*
* @param definition the WSDL4J <code>Definition</code>
* @throws WSDLException in case of errors
*/
protected abstract void buildBindings(Definition definition) throws WSDLException;
public final void buildServices() throws WsdlDefinitionException {
try {
buildServices(definition);
}
catch (WSDLException ex) {
throw new Wsdl4jDefinitionException(ex);
}
}
/**
* Adds services to the definition.
*
* @param definition the WSDL4J <code>Definition</code>
* @throws WSDLException in case of errors
*/
protected abstract void buildServices(Definition definition) throws WSDLException;
public final Wsdl11Definition getDefinition() throws WsdlDefinitionException {
return new Wsdl4jDefinition(definition);
}
/**
* Creates a WSDL4J extensibility element.
*
* @param parentType a class object indicating where in the WSDL definition this extension will exist
* @param elementType the qname of the extensibility element
* @return the extensibility element
* @throws WSDLException in case of errors
* @see javax.wsdl.extensions.ExtensionRegistry#createExtension(Class,javax.xml.namespace.QName)
*/
protected ExtensibilityElement createExtension(Class parentType, QName elementType) throws WSDLException {
return definition.getExtensionRegistry().createExtension(parentType, elementType);
}
/** Allows customization of the given {@link ExtensionRegistry}. Default implementation is empty. */
protected void populateExtensionRegistry(ExtensionRegistry extensionRegistry) {
}
}

View File

@@ -1,511 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.builder;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
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.Part;
import javax.wsdl.PortType;
import javax.wsdl.Service;
import javax.wsdl.Types;
import javax.wsdl.WSDLException;
import javax.wsdl.extensions.schema.Schema;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.ws.wsdl.wsdl11.DynamicWsdl11Definition;
import org.springframework.xml.namespace.QNameUtils;
/**
* Builds a <code>WsdlDefinition</code> with a SOAP 1.1 binding based on an XSD schema. This builder iterates over all
* <code>element</code>s found in the schema, and creates a <code>message</code> for those elements that end with the
* request or response suffix. It combines these messages into <code>operation</code>s, and builds a
* <code>portType</code> based on the operations.
* <p/>
* By default, the schema file is inlined in a <code>types</code> block. However, if the <code>schemaLocation</code>
* property is set, an XSD <code>import</code> is used instead. As such, the imported schema file can contain further
* imports, which will be resolved correctly in accordance with the schema location.
* <p/>
* To create messages from imported and included schemas, set the <code>followIncludeImport</code> property to
* <code>true</code>.
* <p/>
* Typically used within a {@link DynamicWsdl11Definition}, like so:
* <pre>
* &lt;bean id=&quot;airline&quot; class=&quot;org.springframework.ws.wsdl.wsdl11.DynamicWsdl11Definition&quot;&gt;
* &lt;property name=&quot;builder&quot;&gt;
* &lt;bean class=&quot;org.springframework.ws.wsdl.wsdl11.builder.XsdBasedSoap11Wsdl4jDefinitionBuilder&quot;&gt;
* &lt;property name=&quot;schema&quot; value=&quot;/WEB-INF/airline.xsd&quot;/&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;
* &lt;/property&gt;
* &lt;/bean&gt;
* </pre>
* <p/>
* Requires the <code>schema</code> and <code>portTypeName</code> properties to be set.
*
* @author Arjen Poutsma
* @see #setSchema(org.springframework.core.io.Resource)
* @see #setPortTypeName(String)
* @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 {
/** 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";
/** The default prefix used to register the schema namespace in the WSDL. */
public static final String DEFAULT_SCHEMA_PREFIX = "schema";
/** The default prefix used to register the target namespace in the WSDL. */
public static final String DEFAULT_PREFIX = "tns";
/** The suffix used to create a service name from a port type name. */
public static final String SERVICE_SUFFIX = "Service";
private Resource schemaResource;
private XsdSchemaHelper schemaHelper;
private String schemaLocation;
private String targetNamespace;
private String portTypeName;
private String schemaPrefix = DEFAULT_SCHEMA_PREFIX;
private String prefix = DEFAULT_PREFIX;
private String requestSuffix = DEFAULT_REQUEST_SUFFIX;
private String responseSuffix = DEFAULT_RESPONSE_SUFFIX;
private String faultSuffix = DEFAULT_FAULT_SUFFIX;
private boolean followIncludeImport = false;
/**
* Sets the suffix used to detect request elements in the schema.
*
* @see #DEFAULT_REQUEST_SUFFIX
*/
public void setRequestSuffix(String requestSuffix) {
this.requestSuffix = requestSuffix;
}
/**
* Sets the suffix used to detect response elements in the schema.
*
* @see #DEFAULT_RESPONSE_SUFFIX
*/
public void setResponseSuffix(String responseSuffix) {
this.responseSuffix = responseSuffix;
}
/**
* Sets the suffix used to detect fault elements in the schema.
*
* @see #DEFAULT_FAULT_SUFFIX
*/
public void setFaultSuffix(String faultSuffix) {
this.faultSuffix = faultSuffix;
}
/** Sets the port type name used for this definition. Required. */
public void setPortTypeName(String portTypeName) {
this.portTypeName = portTypeName;
}
/** Sets the target namespace used for this definition. */
public void setTargetNamespace(String targetNamespace) {
this.targetNamespace = targetNamespace;
}
/**
* Sets the prefix used to declare the schema target namespace.
*
* @see #DEFAULT_SCHEMA_PREFIX
*/
public void setSchemaPrefix(String schemaPrefix) {
this.schemaPrefix = schemaPrefix;
}
/**
* Sets the prefix used to declare the target namespace.
*
* @see #DEFAULT_PREFIX
*/
public void setPrefix(String prefix) {
this.prefix = prefix;
}
/** Sets the XSD schema to use for generating the WSDL. */
public void setSchema(Resource schemaResource) {
Assert.notNull(schemaResource, "'schema' must not be null");
Assert.isTrue(schemaResource.exists(), "schema \"" + schemaResource + "\" does not exit");
this.schemaResource = schemaResource;
}
/**
* Sets the location of the schema to import. If this property is set, the <code>schema</code> element in the
* generated WSDL will only contain an <code>import</code>, referring to the value of this property.
*/
public void setSchemaLocation(String schemaLocation) {
Assert.hasLength(schemaLocation, "'schemaLocation' must not be empty");
this.schemaLocation = schemaLocation;
}
/**
* Indicates whether schema <code>&lt;xsd:include/&gt;</code> and <code>&lt;xsd:import/&gt;</code> should be
* followed. Default is <code>false</code>.
*/
public void setFollowIncludeImport(boolean followIncludeImport) {
this.followIncludeImport = followIncludeImport;
}
public final void afterPropertiesSet() throws IOException, ParserConfigurationException, SAXException {
Assert.notNull(schemaResource, "'schema' is required");
Assert.notNull(portTypeName, "'portTypeName' is required");
schemaHelper = new XsdSchemaHelper(schemaResource);
if (!StringUtils.hasLength(targetNamespace)) {
targetNamespace = schemaHelper.getTargetNamespace();
}
}
/** Adds the target namespace and schema namespace to the definition. */
@Override
protected void populateDefinition(Definition definition) throws WSDLException {
super.populateDefinition(definition);
definition.setTargetNamespace(targetNamespace);
definition.addNamespace(schemaPrefix, schemaHelper.getTargetNamespace());
if (!targetNamespace.equals(schemaHelper.getTargetNamespace())) {
definition.addNamespace(prefix, targetNamespace);
}
}
/** Does nothing. */
@Override
protected void buildImports(Definition definition) throws WSDLException {
}
/**
* Creates a {@link Types} object containing a {@link Schema}. By default, the schema set by the <code>schema</code>
* property will be inlined into this <code>type</code>. If the <code>schemaLocation</code> is set, </code>object
* that is populated with the types found in the schema.
*
* @param definition the WSDL4J <code>Definition</code>
* @throws WSDLException in case of errors
*/
@Override
protected void buildTypes(Definition definition) throws WSDLException {
Types types = definition.createTypes();
Schema schema = (Schema) createExtension(Types.class, XsdSchemaHelper.SCHEMA_NAME);
if (!StringUtils.hasLength(schemaLocation)) {
schema.setElement(schemaHelper.getSchemaElement());
}
else {
Document document;
try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
document = documentBuilder.newDocument();
}
catch (ParserConfigurationException ex) {
throw new WSDLException(WSDLException.PARSER_ERROR, "Could not create DocumentBuilder", ex);
}
Element importingSchemaElement = document.createElementNS(XsdSchemaHelper.SCHEMA_NAME.getNamespaceURI(),
QNameUtils.toQualifiedName(XsdSchemaHelper.SCHEMA_NAME));
schema.setElement(importingSchemaElement);
Element importElement = document.createElementNS(XsdSchemaHelper.IMPORT_NAME.getNamespaceURI(),
QNameUtils.toQualifiedName(XsdSchemaHelper.IMPORT_NAME));
importingSchemaElement.appendChild(importElement);
importElement.setAttribute("namespace", schemaHelper.getTargetNamespace());
importElement.setAttribute("schemaLocation", schemaLocation);
}
types.addExtensibilityElement(schema);
definition.setTypes(types);
}
/**
* Creates messages for each element found in the schema for which {@link #isRequestMessage(QName)}, {@link
* #isResponseMessage(QName)}, or {@link #isFaultMessage(QName)} is <code>true</code>.
*
* @param definition the WSDL4J <code>Definition</code>
* @throws WSDLException in case of errors
*/
@Override
protected void buildMessages(Definition definition) throws WSDLException {
List elementDeclarations = schemaHelper.getElementDeclarations(followIncludeImport);
for (Iterator iterator = elementDeclarations.iterator(); iterator.hasNext();) {
QName elementName = (QName) iterator.next();
if (elementName != null &&
(isRequestMessage(elementName) || isResponseMessage(elementName) || isFaultMessage(elementName))) {
if (definition.getPrefix(elementName.getNamespaceURI()) == null) {
int i = 0;
while (true) {
String prefix = schemaPrefix + Integer.toString(i);
if (!StringUtils.hasLength(definition.getNamespace(prefix))) {
definition.addNamespace(prefix, elementName.getNamespaceURI());
break;
}
i++;
}
}
Message message = definition.createMessage();
populateMessage(message, elementName);
Part part = definition.createPart();
populatePart(part, elementName);
message.addPart(part);
message.setUndefined(false);
definition.addMessage(message);
}
}
}
/**
* Indicates whether the given name name should be included as request {@link Message} in the definition. Default
* implementation checks whether the local part ends with the request suffix.
*
* @param name the name of the element elligable for being a message
* @return <code>true</code> if to be included as message; <code>false</code> otherwise
* @see #setRequestSuffix(String)
*/
protected boolean isRequestMessage(QName name) {
return name.getLocalPart().endsWith(requestSuffix);
}
/**
* Indicates whether the given name should be included as {@link Message} in the definition. Default implementation
* checks whether the local part ends with the response suffix.
*
* @param name the name of the element elligable for being a message
* @return <code>true</code> if to be included as message; <code>false</code> otherwise
* @see #setResponseSuffix(String)
*/
protected boolean isResponseMessage(QName name) {
return name.getLocalPart().endsWith(responseSuffix);
}
/**
* Indicates whether the given name should be included as {@link Message} in the definition. Default implementation
* checks whether the local part ends with the fault suffix.
*
* @param name the name of the element elligable for being a message
* @return <code>true</code> if to be included as message; <code>false</code> otherwise
* @see #setFaultSuffix(String)
*/
protected boolean isFaultMessage(QName name) {
return name.getLocalPart().endsWith(faultSuffix);
}
/**
* Called after the {@link Message} has been created.
* <p/>
* Default implementation sets the name of the message to the element name.
*
* @param message the WSDL4J <code>Message</code>
* @param elementName the element name
* @throws WSDLException in case of errors
*/
protected void populateMessage(Message message, QName elementName) throws WSDLException {
message.setQName(new QName(targetNamespace, elementName.getLocalPart()));
}
/**
* Called after the {@link Part} has been created.
* <p/>
* Default implementation sets the element name of the part.
*
* @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(Part part, QName elementName) throws WSDLException {
part.setElementName(elementName);
part.setName(elementName.getLocalPart());
}
@Override
protected void buildPortTypes(Definition definition) throws WSDLException {
PortType portType = definition.createPortType();
populatePortType(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(PortType portType) throws WSDLException {
portType.setQName(new QName(targetNamespace, portTypeName));
}
private void createOperations(Definition definition, PortType portType) throws WSDLException {
for (Iterator messageIterator = definition.getMessages().values().iterator(); messageIterator.hasNext();) {
Message message = (Message) messageIterator.next();
for (Iterator partIterator = message.getParts().values().iterator(); partIterator.hasNext();) {
Part part = (Part) partIterator.next();
if (isRequestMessage(part.getElementName())) {
Message requestMessage = message;
Message responseMessage = definition.getMessage(getResponseMessageName(requestMessage.getQName()));
Message faultMessage = definition.getMessage(getFaultMessageName(requestMessage.getQName()));
Operation operation = definition.createOperation();
populateOperation(operation, requestMessage, responseMessage);
if (requestMessage != null) {
Input input = definition.createInput();
input.setMessage(requestMessage);
input.setName(requestMessage.getQName().getLocalPart());
operation.setInput(input);
}
if (responseMessage != null) {
Output output = definition.createOutput();
output.setMessage(responseMessage);
output.setName(responseMessage.getQName().getLocalPart());
operation.setOutput(output);
}
if (faultMessage != null) {
Fault fault = definition.createFault();
fault.setMessage(faultMessage);
fault.setName(faultMessage.getQName().getLocalPart());
operation.addFault(fault);
}
if (requestMessage != null && responseMessage != null) {
operation.setStyle(OperationType.REQUEST_RESPONSE);
}
else if (requestMessage != null && responseMessage == null) {
operation.setStyle(OperationType.ONE_WAY);
}
else if (requestMessage == null && responseMessage != null) {
operation.setStyle(OperationType.NOTIFICATION);
}
operation.setUndefined(false);
portType.addOperation(operation);
}
}
}
}
/**
* Given an request message name, return the corresponding response message name.
* <p/>
* Default implementation removes the request suffix, and appends the response suffix.
*
* @param requestMessageName the name of the request message
* @return the name of the corresponding response message, or null
*/
protected QName getResponseMessageName(QName requestMessageName) {
String localPart = requestMessageName.getLocalPart();
if (localPart.endsWith(requestSuffix)) {
String prefix = localPart.substring(0, localPart.length() - requestSuffix.length());
return new QName(requestMessageName.getNamespaceURI(), prefix + responseSuffix);
}
else {
return null;
}
}
/**
* Given an request message name, return the corresponding fault message name.
* <p/>
* Default implementation removes the request suffix, and appends the fault suffix.
*
* @param requestMessageName the name of the request message
* @return the name of the corresponding response message, or null
*/
protected QName getFaultMessageName(QName requestMessageName) {
String localPart = requestMessageName.getLocalPart();
if (localPart.endsWith(requestSuffix)) {
String prefix = localPart.substring(0, localPart.length() - requestSuffix.length());
return new QName(requestMessageName.getNamespaceURI(), prefix + faultSuffix);
}
else {
return null;
}
}
/**
* Called after the {@link Operation} has been created.
* <p/>
* Default implementation sets the name of the operation to name of the messages, without suffix.
*
* @param operation the WSDL4J <code>Operation</code>
* @param requestMessage the WSDL4J request <code>Message</code>
* @param responseMessage the WSDL4J response <code>Message</code>
* @throws WSDLException in case of errors
* @see #setPortTypeName(String)
*/
protected void populateOperation(Operation operation, Message requestMessage, Message responseMessage)
throws WSDLException {
String localPart = requestMessage.getQName().getLocalPart();
String operationName = null;
if (localPart.endsWith(requestSuffix)) {
operationName = localPart.substring(0, localPart.length() - requestSuffix.length());
}
else {
localPart = responseMessage.getQName().getLocalPart();
if (localPart.endsWith(responseSuffix)) {
operationName = localPart.substring(0, localPart.length() - responseSuffix.length());
}
}
operation.setName(operationName);
}
/** Sets the name of the service to the name of the port type, with "Service" appended to it. */
@Override
protected void populateService(Service service) throws WSDLException {
service.setQName(new QName(targetNamespace, portTypeName + SERVICE_SUFFIX));
}
}

View File

@@ -1,513 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.builder;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
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.Part;
import javax.wsdl.PortType;
import javax.wsdl.Service;
import javax.wsdl.Types;
import javax.wsdl.WSDLException;
import javax.wsdl.extensions.schema.Schema;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.ws.wsdl.wsdl11.DynamicWsdl11Definition;
import org.springframework.xml.namespace.QNameUtils;
/**
* Builds a <code>WsdlDefinition</code> with a SOAP 1.2 binding based on an XSD schema. This builder iterates over all
* <code>element</code>s found in the schema, and creates a <code>message</code> for those elements that end with the
* request or response suffix. It combines these messages into <code>operation</code>s, and builds a
* <code>portType</code> based on the operations.
* <p/>
* By default, the schema file is inlined in a <code>types</code> block. However, if the <code>schemaLocation</code>
* property is set, an XSD <code>import</code> is used instead. As such, the imported schema file can contain further
* imports, which will be resolved correctly in accordance with the schema location.
* <p/>
* To create messages from imported and included schemas, set the <code>followIncludeImport</code> property to
* <code>true</code>.
* <p/>
* Typically used within a {@link DynamicWsdl11Definition}, like so:
* <pre>
* &lt;bean id=&quot;airline&quot; class=&quot;org.springframework.ws.wsdl.wsdl11.DynamicWsdl11Definition&quot;&gt;
* &lt;property name=&quot;builder&quot;&gt;
* &lt;bean class=&quot;org.springframework.ws.wsdl.wsdl11.builder.XsdBasedSoap11Wsdl4jDefinitionBuilder&quot;&gt;
* &lt;property name=&quot;schema&quot; value=&quot;/WEB-INF/airline.xsd&quot;/&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;
* &lt;/property&gt;
* &lt;/bean&gt;
* </pre>
* <p/>
* Requires the <code>schema</code> and <code>portTypeName</code> properties to be set.
*
* @author Arjen Poutsma
* @author Alex Marshall
* @see #setSchema(org.springframework.core.io.Resource)
* @see #setPortTypeName(String)
* @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 {
/** 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";
/** The default prefix used to register the schema namespace in the WSDL. */
public static final String DEFAULT_SCHEMA_PREFIX = "schema";
/** The default prefix used to register the target namespace in the WSDL. */
public static final String DEFAULT_PREFIX = "tns";
/** The suffix used to create a service name from a port type name. */
public static final String SERVICE_SUFFIX = "Service";
private Resource schemaResource;
private XsdSchemaHelper schemaHelper;
private String schemaLocation;
private String targetNamespace;
private String portTypeName;
private String schemaPrefix = DEFAULT_SCHEMA_PREFIX;
private String prefix = DEFAULT_PREFIX;
private String requestSuffix = DEFAULT_REQUEST_SUFFIX;
private String responseSuffix = DEFAULT_RESPONSE_SUFFIX;
private String faultSuffix = DEFAULT_FAULT_SUFFIX;
private boolean followIncludeImport = false;
/**
* Sets the suffix used to detect request elements in the schema.
*
* @see #DEFAULT_REQUEST_SUFFIX
*/
public void setRequestSuffix(String requestSuffix) {
this.requestSuffix = requestSuffix;
}
/**
* Sets the suffix used to detect response elements in the schema.
*
* @see #DEFAULT_RESPONSE_SUFFIX
*/
public void setResponseSuffix(String responseSuffix) {
this.responseSuffix = responseSuffix;
}
/**
* Sets the suffix used to detect fault elements in the schema.
*
* @see #DEFAULT_FAULT_SUFFIX
*/
public void setFaultSuffix(String faultSuffix) {
this.faultSuffix = faultSuffix;
}
/** Sets the port type name used for this definition. Required. */
public void setPortTypeName(String portTypeName) {
this.portTypeName = portTypeName;
}
/** Sets the target namespace used for this definition. */
public void setTargetNamespace(String targetNamespace) {
this.targetNamespace = targetNamespace;
}
/**
* Sets the prefix used to declare the schema target namespace.
*
* @see #DEFAULT_SCHEMA_PREFIX
*/
public void setSchemaPrefix(String schemaPrefix) {
this.schemaPrefix = schemaPrefix;
}
/**
* Sets the prefix used to declare the target namespace.
*
* @see #DEFAULT_PREFIX
*/
public void setPrefix(String prefix) {
this.prefix = prefix;
}
/** Sets the XSD schema to use for generating the WSDL. */
public void setSchema(Resource schemaResource) {
Assert.notNull(schemaResource, "'schema' must not be null");
Assert.isTrue(schemaResource.exists(), "schema \"" + schemaResource + "\" does not exit");
this.schemaResource = schemaResource;
}
/**
* Sets the location of the schema to import. If this property is set, the <code>schema</code> element in the
* generated WSDL will only contain an <code>import</code>, referring to the value of this property.
*/
public void setSchemaLocation(String schemaLocation) {
Assert.hasLength(schemaLocation, "'schemaLocation' must not be empty");
this.schemaLocation = schemaLocation;
}
/**
* Indicates whether schema <code>&lt;xsd:include/&gt;</code> and <code>&lt;xsd:import/&gt;</code> should be
* followed. Default is <code>false</code>.
*/
public void setFollowIncludeImport(boolean followIncludeImport) {
this.followIncludeImport = followIncludeImport;
}
public final void afterPropertiesSet() throws IOException, ParserConfigurationException, SAXException {
Assert.notNull(schemaResource, "'schema' is required");
Assert.notNull(portTypeName, "'portTypeName' is required");
schemaHelper = new XsdSchemaHelper(schemaResource);
if (!StringUtils.hasLength(targetNamespace)) {
targetNamespace = schemaHelper.getTargetNamespace();
}
}
/** Adds the target namespace and schema namespace to the definition. */
@Override
protected void populateDefinition(Definition definition) throws WSDLException {
super.populateDefinition(definition);
definition.setTargetNamespace(targetNamespace);
definition.addNamespace(schemaPrefix, schemaHelper.getTargetNamespace());
if (!targetNamespace.equals(schemaHelper.getTargetNamespace())) {
definition.addNamespace(prefix, targetNamespace);
}
}
/** Does nothing. */
@Override
protected void buildImports(Definition definition) throws WSDLException {
}
/**
* Creates a {@link Types} object containing a {@link Schema}. By default, the schema set by the <code>schema</code>
* property will be inlined into this <code>type</code>. If the <code>schemaLocation</code> is set, </code>object
* that is populated with the types found in the schema.
*
* @param definition the WSDL4J <code>Definition</code>
* @throws WSDLException in case of errors
*/
@Override
protected void buildTypes(Definition definition) throws WSDLException {
Types types = definition.createTypes();
Schema schema = (Schema) createExtension(Types.class, XsdSchemaHelper.SCHEMA_NAME);
if (!StringUtils.hasLength(schemaLocation)) {
schema.setElement(schemaHelper.getSchemaElement());
}
else {
Document document;
try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
document = documentBuilder.newDocument();
}
catch (ParserConfigurationException ex) {
throw new WSDLException(WSDLException.PARSER_ERROR, "Could not create DocumentBuilder", ex);
}
Element importingSchemaElement = document.createElementNS(XsdSchemaHelper.SCHEMA_NAME.getNamespaceURI(),
QNameUtils.toQualifiedName(XsdSchemaHelper.SCHEMA_NAME));
schema.setElement(importingSchemaElement);
Element importElement = document.createElementNS(XsdSchemaHelper.IMPORT_NAME.getNamespaceURI(),
QNameUtils.toQualifiedName(XsdSchemaHelper.IMPORT_NAME));
importingSchemaElement.appendChild(importElement);
importElement.setAttribute("namespace", schemaHelper.getTargetNamespace());
importElement.setAttribute("schemaLocation", schemaLocation);
}
types.addExtensibilityElement(schema);
definition.setTypes(types);
}
/**
* Creates messages for each element found in the schema for which {@link #isRequestMessage(QName)}, {@link
* #isResponseMessage(QName)}, or {@link #isFaultMessage(QName)} is <code>true</code>.
*
* @param definition the WSDL4J <code>Definition</code>
* @throws WSDLException in case of errors
*/
@Override
protected void buildMessages(Definition definition) throws WSDLException {
List elementDeclarations = schemaHelper.getElementDeclarations(followIncludeImport);
for (Iterator iterator = elementDeclarations.iterator(); iterator.hasNext();) {
QName elementName = (QName) iterator.next();
if (elementName != null &&
(isRequestMessage(elementName) || isResponseMessage(elementName) || isFaultMessage(elementName))) {
if (definition.getPrefix(elementName.getNamespaceURI()) == null) {
int i = 0;
while (true) {
String prefix = schemaPrefix + Integer.toString(i);
if (!StringUtils.hasLength(definition.getNamespace(prefix))) {
definition.addNamespace(prefix, elementName.getNamespaceURI());
break;
}
i++;
}
}
Message message = definition.createMessage();
populateMessage(message, elementName);
Part part = definition.createPart();
populatePart(part, elementName);
message.addPart(part);
message.setUndefined(false);
definition.addMessage(message);
}
}
}
/**
* Indicates whether the given name name should be included as request {@link Message} in the definition. Default
* implementation checks whether the local part ends with the request suffix.
*
* @param name the name of the element elligable for being a message
* @return <code>true</code> if to be included as message; <code>false</code> otherwise
* @see #setRequestSuffix(String)
*/
protected boolean isRequestMessage(QName name) {
return name.getLocalPart().endsWith(requestSuffix);
}
/**
* Indicates whether the given name should be included as {@link Message} in the definition. Default implementation
* checks whether the local part ends with the response suffix.
*
* @param name the name of the element elligable for being a message
* @return <code>true</code> if to be included as message; <code>false</code> otherwise
* @see #setResponseSuffix(String)
*/
protected boolean isResponseMessage(QName name) {
return name.getLocalPart().endsWith(responseSuffix);
}
/**
* Indicates whether the given name should be included as {@link Message} in the definition. Default implementation
* checks whether the local part ends with the fault suffix.
*
* @param name the name of the element elligable for being a message
* @return <code>true</code> if to be included as message; <code>false</code> otherwise
* @see #setFaultSuffix(String)
*/
protected boolean isFaultMessage(QName name) {
return name.getLocalPart().endsWith(faultSuffix);
}
/**
* Called after the {@link Message} has been created.
* <p/>
* Default implementation sets the name of the message to the element name.
*
* @param message the WSDL4J <code>Message</code>
* @param elementName the element name
* @throws WSDLException in case of errors
*/
protected void populateMessage(Message message, QName elementName) throws WSDLException {
message.setQName(new QName(targetNamespace, elementName.getLocalPart()));
}
/**
* Called after the {@link Part} has been created.
* <p/>
* Default implementation sets the element name of the part.
*
* @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(Part part, QName elementName) throws WSDLException {
part.setElementName(elementName);
part.setName(elementName.getLocalPart());
}
@Override
protected void buildPortTypes(Definition definition) throws WSDLException {
PortType portType = definition.createPortType();
populatePortType(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(PortType portType) throws WSDLException {
portType.setQName(new QName(targetNamespace, portTypeName));
}
private void createOperations(Definition definition, PortType portType) throws WSDLException {
for (Iterator messageIterator = definition.getMessages().values().iterator(); messageIterator.hasNext();) {
Message message = (Message) messageIterator.next();
for (Iterator partIterator = message.getParts().values().iterator(); partIterator.hasNext();) {
Part part = (Part) partIterator.next();
if (isRequestMessage(part.getElementName())) {
Message requestMessage = message;
Message responseMessage = definition.getMessage(getResponseMessageName(requestMessage.getQName()));
Message faultMessage = definition.getMessage(getFaultMessageName(requestMessage.getQName()));
Operation operation = definition.createOperation();
populateOperation(operation, requestMessage, responseMessage);
if (requestMessage != null) {
Input input = definition.createInput();
input.setMessage(requestMessage);
input.setName(requestMessage.getQName().getLocalPart());
operation.setInput(input);
}
if (responseMessage != null) {
Output output = definition.createOutput();
output.setMessage(responseMessage);
output.setName(responseMessage.getQName().getLocalPart());
operation.setOutput(output);
}
if (faultMessage != null) {
Fault fault = definition.createFault();
fault.setMessage(faultMessage);
fault.setName(faultMessage.getQName().getLocalPart());
operation.addFault(fault);
}
if (requestMessage != null && responseMessage != null) {
operation.setStyle(OperationType.REQUEST_RESPONSE);
}
else if (requestMessage != null && responseMessage == null) {
operation.setStyle(OperationType.ONE_WAY);
}
else if (requestMessage == null && responseMessage != null) {
operation.setStyle(OperationType.NOTIFICATION);
}
operation.setUndefined(false);
portType.addOperation(operation);
}
}
}
}
/**
* Given an request message name, return the corresponding response message name.
* <p/>
* Default implementation removes the request suffix, and appends the response suffix.
*
* @param requestMessageName the name of the request message
* @return the name of the corresponding response message, or null
*/
protected QName getResponseMessageName(QName requestMessageName) {
String localPart = requestMessageName.getLocalPart();
if (localPart.endsWith(requestSuffix)) {
String prefix = localPart.substring(0, localPart.length() - requestSuffix.length());
return new QName(requestMessageName.getNamespaceURI(), prefix + responseSuffix);
}
else {
return null;
}
}
/**
* Given an request message name, return the corresponding fault message name.
* <p/>
* Default implementation removes the request suffix, and appends the fault suffix.
*
* @param requestMessageName the name of the request message
* @return the name of the corresponding response message, or null
*/
protected QName getFaultMessageName(QName requestMessageName) {
String localPart = requestMessageName.getLocalPart();
if (localPart.endsWith(requestSuffix)) {
String prefix = localPart.substring(0, localPart.length() - requestSuffix.length());
return new QName(requestMessageName.getNamespaceURI(), prefix + faultSuffix);
}
else {
return null;
}
}
/**
* Called after the {@link Operation} has been created.
* <p/>
* Default implementation sets the name of the operation to name of the messages, without suffix.
*
* @param operation the WSDL4J <code>Operation</code>
* @param requestMessage the WSDL4J request <code>Message</code>
* @param responseMessage the WSDL4J response <code>Message</code>
* @throws WSDLException in case of errors
* @see #setPortTypeName(String)
*/
protected void populateOperation(Operation operation, Message requestMessage, Message responseMessage)
throws WSDLException {
String localPart = requestMessage.getQName().getLocalPart();
String operationName = null;
if (localPart.endsWith(requestSuffix)) {
operationName = localPart.substring(0, localPart.length() - requestSuffix.length());
}
else {
localPart = responseMessage.getQName().getLocalPart();
if (localPart.endsWith(responseSuffix)) {
operationName = localPart.substring(0, localPart.length() - responseSuffix.length());
}
}
operation.setName(operationName);
}
/** Sets the name of the service to the name of the port type, with "Service" appended to it. */
@Override
protected void populateService(Service service) throws WSDLException {
service.setQName(new QName(targetNamespace, portTypeName + SERVICE_SUFFIX));
}
}

View File

@@ -1,145 +0,0 @@
/*
* Copyright 2007 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.builder;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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 {
private static final Log logger = LogFactory.getLog(XsdSchemaHelper.class);
private static final String SCHEMA_NAMESPACE = "http://www.w3.org/2001/XMLSchema";
static final QName SCHEMA_NAME = QNameUtils.createQName(SCHEMA_NAMESPACE, "schema", "xsd");
static final QName ELEMENT_NAME = QNameUtils.createQName(SCHEMA_NAMESPACE, "element", "xsd");
static final QName INCLUDE_NAME = QNameUtils.createQName(SCHEMA_NAMESPACE, "include", "xsd");
static final QName IMPORT_NAME = QNameUtils.createQName(SCHEMA_NAMESPACE, "import", "xsd");
private final Resource schemaResource;
private final Element schemaElement;
private static DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
static {
documentBuilderFactory.setNamespaceAware(true);
}
public XsdSchemaHelper(Resource schemaResource) throws ParserConfigurationException, IOException, SAXException {
Assert.notNull(schemaResource, "schema must not be empty or null");
Assert.isTrue(schemaResource.exists(), "schema \"" + schemaResource + "\" does not exit");
this.schemaResource = schemaResource;
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document schemaDocument = documentBuilder.parse(SaxUtils.createInputSource(schemaResource));
schemaElement = schemaDocument.getDocumentElement();
Assert.isTrue(SCHEMA_NAME.getLocalPart().equals(schemaElement.getLocalName()),
"schema document root element has invalid local name : [" + schemaElement.getLocalName() +
"] instead of [schema]");
Assert.isTrue(SCHEMA_NAME.getNamespaceURI().equals(schemaElement.getNamespaceURI()),
"schema document root element has invalid namespace uri: [" + schemaElement.getNamespaceURI() +
"] instead of [" + SCHEMA_NAME.getNamespaceURI() + "]");
Assert.hasLength(getTargetNamespace(), "schema [" + schemaResource + "] has no targetNamespace");
}
public String getTargetNamespace() {
return schemaElement.getAttribute("targetNamespace");
}
public Element getSchemaElement() {
return schemaElement;
}
public List getElementDeclarations(boolean followIncludeImport) {
List declarations = new ArrayList();
getElementDeclarationsInternal(declarations, followIncludeImport);
return declarations;
}
private void getElementDeclarationsInternal(List declarations, boolean followIncludeImport) {
NodeList children = schemaElement.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
Element childElement = (Element) children.item(i);
QName childName = QNameUtils.getQNameForNode(childElement);
if (ELEMENT_NAME.equals(childName)) {
declarations.add(getElementName(childElement));
}
else if (followIncludeImport) {
if (INCLUDE_NAME.equals(childName) || IMPORT_NAME.equals(childName)) {
String schemaLocation = childElement.getAttribute("schemaLocation");
if (StringUtils.hasLength(schemaLocation)) {
try {
Resource resource = schemaResource.createRelative(schemaLocation);
if (resource.exists()) {
XsdSchemaHelper helper = new XsdSchemaHelper(resource);
helper.getElementDeclarationsInternal(declarations, followIncludeImport);
}
else {
logger.warn("Imported/Includes schema with location " + schemaLocation +
" does not exist");
}
}
catch (Exception ex) {
logger.warn(ex);
// ignore
}
}
}
}
}
}
}
private QName getElementName(Element element) {
String attributeValue = element.getAttribute("name");
return StringUtils.hasLength(attributeValue) ? new QName(getTargetNamespace(), attributeValue) : null;
}
}

View File

@@ -1,6 +0,0 @@
<html>
<body>
<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

@@ -1,76 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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 junit.framework.TestCase;
import org.easymock.MockControl;
public class DynamicWsdl11DefinitionTest extends TestCase {
private DynamicWsdl11Definition definition;
private MockControl builderControl;
private Wsdl11DefinitionBuilder builderMock;
@Override
protected void setUp() throws Exception {
definition = new DynamicWsdl11Definition();
builderControl = MockControl.createControl(Wsdl11DefinitionBuilder.class);
builderMock = (Wsdl11DefinitionBuilder) builderControl.getMock();
definition.setBuilder(builderMock);
}
public void testComplete() throws Exception {
builderMock.buildDefinition();
builderMock.buildImports();
builderMock.buildTypes();
builderMock.buildMessages();
builderMock.buildPortTypes();
builderMock.buildBindings();
builderMock.buildServices();
builderControl.expectAndReturn(builderMock.getDefinition(), null);
builderControl.replay();
definition.afterPropertiesSet();
builderControl.verify();
}
public void testAbstract() throws Exception {
definition.setBuildConcretePart(false);
builderMock.buildDefinition();
builderMock.buildImports();
builderMock.buildTypes();
builderMock.buildMessages();
builderMock.buildPortTypes();
builderControl.expectAndReturn(builderMock.getDefinition(), null);
builderControl.replay();
definition.afterPropertiesSet();
builderControl.verify();
}
public void testConcrete() throws Exception {
definition.setBuildAbstractPart(false);
builderMock.buildDefinition();
builderMock.buildImports();
builderMock.buildBindings();
builderMock.buildServices();
builderControl.expectAndReturn(builderMock.getDefinition(), null);
builderControl.replay();
definition.afterPropertiesSet();
builderControl.verify();
}
}

View File

@@ -1,176 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.builder;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import org.custommonkey.xmlunit.XMLTestCase;
import org.custommonkey.xmlunit.XMLUnit;
import org.w3c.dom.Document;
import org.springframework.core.io.ClassPathResource;
import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition;
import org.springframework.xml.transform.StringResult;
public class XsdBasedSoap11Wsdl4jDefinitionBuilderTest extends XMLTestCase {
private XsdBasedSoap11Wsdl4jDefinitionBuilder builder;
private Transformer transformer;
private DocumentBuilder documentBuilder;
@Override
protected void setUp() throws Exception {
builder = new XsdBasedSoap11Wsdl4jDefinitionBuilder();
builder.setLocationUri("http://localhost:8080/");
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformer = transformerFactory.newTransformer();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
documentBuilder = documentBuilderFactory.newDocumentBuilder();
XMLUnit.setIgnoreWhitespace(true);
}
public void testNonExistingSchema() throws Exception {
try {
builder.setSchema(new ClassPathResource("bla"));
fail("IllegalArgumentException expected");
}
catch (IllegalArgumentException ex) {
// expected
}
}
public void testSingle() throws Exception {
builder.setSchema(new ClassPathResource("single.xsd", getClass()));
builder.setPortTypeName("Order");
builder.setTargetNamespace("http://www.springframework.org/spring-ws/single/definitions");
builder.afterPropertiesSet();
buildAll();
Wsdl11Definition definition = builder.getDefinition();
DOMResult domResult = new DOMResult();
transformer.transform(definition.getSource(), domResult);
Document result = (Document) domResult.getNode();
Document expected = documentBuilder.parse(getClass().getResourceAsStream("single-inline.wsdl"));
assertXMLEqual("Invalid WSDL built", expected, result);
}
public void testSingleImport() throws Exception {
builder.setSchema(new ClassPathResource("single.xsd", getClass()));
builder.setSchemaLocation("single.xsd");
builder.setPortTypeName("Order");
builder.setTargetNamespace("http://www.springframework.org/spring-ws/single/definitions");
builder.afterPropertiesSet();
buildAll();
Wsdl11Definition definition = builder.getDefinition();
DOMResult domResult = new DOMResult();
transformer.transform(definition.getSource(), domResult);
Document result = (Document) domResult.getNode();
Document expected = documentBuilder.parse(getClass().getResourceAsStream("single-import.wsdl"));
assertXMLEqual("Invalid WSDL built", expected, result);
}
public void testFollowIncluding() throws Exception {
builder.setSchema(new ClassPathResource("including.xsd", getClass()));
builder.setPortTypeName("Order");
builder.setTargetNamespace("http://www.springframework.org/spring-ws/include/definitions");
builder.setFollowIncludeImport(true);
builder.afterPropertiesSet();
buildAll();
Wsdl11Definition definition = builder.getDefinition();
DOMResult domResult = new DOMResult();
transformer.transform(definition.getSource(), domResult);
Document result = (Document) domResult.getNode();
Document expected = documentBuilder.parse(getClass().getResourceAsStream("include-inline.wsdl"));
assertXMLEqual("Invalid WSDL built", expected, result);
}
public void testFollowImport() throws Exception {
builder.setSchema(new ClassPathResource("importing.xsd", getClass()));
builder.setPortTypeName("Order");
builder.setTargetNamespace("http://www.springframework.org/spring-ws/import/definitions");
builder.setFollowIncludeImport(true);
builder.afterPropertiesSet();
buildAll();
Wsdl11Definition definition = builder.getDefinition();
DOMResult domResult = new DOMResult();
transformer.transform(definition.getSource(), domResult);
Document result = (Document) domResult.getNode();
Document expected = documentBuilder.parse(getClass().getResourceAsStream("import-inline.wsdl"));
assertXMLEqual("Invalid WSDL built", expected, result);
}
public void testAirline() throws Exception {
builder.setSchema(new ClassPathResource("airline.xsd", getClass()));
builder.setPortTypeName("Airline");
builder.setTargetNamespace("http://www.springframework.org/spring-ws/samples/airline/definitions");
builder.afterPropertiesSet();
buildAll();
Wsdl11Definition definition = builder.getDefinition();
DOMResult domResult = new DOMResult();
transformer.transform(definition.getSource(), domResult);
Document result = (Document) domResult.getNode();
Document expected = documentBuilder.parse(getClass().getResourceAsStream("airline-soap11.wsdl"));
XMLUnit.setIgnoreWhitespace(true);
assertXMLEqual("Invalid WSDL built", expected, result);
}
public void testNoSchemaPrefix() throws Exception {
builder.setSchema(new ClassPathResource("single.xsd", getClass()));
builder.setPortTypeName("Order");
builder.setTargetNamespace("http://www.springframework.org/spring-ws/single/definitions");
builder.setSchemaPrefix("");
builder.afterPropertiesSet();
buildAll();
Wsdl11Definition definition = builder.getDefinition();
transformer.transform(definition.getSource(), new StringResult());
}
private void buildAll() {
builder.buildDefinition();
builder.buildImports();
builder.buildTypes();
builder.buildMessages();
builder.buildPortTypes();
builder.buildBindings();
builder.buildServices();
}
}

View File

@@ -1,104 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.builder;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import org.custommonkey.xmlunit.XMLTestCase;
import org.custommonkey.xmlunit.XMLUnit;
import org.w3c.dom.Document;
import org.springframework.core.io.ClassPathResource;
import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition;
import org.springframework.xml.transform.StringResult;
public class XsdBasedSoap12Wsdl4jDefinitionBuilderTest extends XMLTestCase {
private XsdBasedSoap12Wsdl4jDefinitionBuilder builder;
private Transformer transformer;
private DocumentBuilder documentBuilder;
@Override
protected void setUp() throws Exception {
builder = new XsdBasedSoap12Wsdl4jDefinitionBuilder();
builder.setLocationUri("http://localhost:8080/");
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformer = transformerFactory.newTransformer();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
documentBuilder = documentBuilderFactory.newDocumentBuilder();
XMLUnit.setIgnoreWhitespace(true);
}
public void testNonExistingSchema() throws Exception {
try {
builder.setSchema(new ClassPathResource("bla"));
fail("IllegalArgumentException expected");
}
catch (IllegalArgumentException ex) {
// expected
}
}
public void testAirline() throws Exception {
builder.setSchema(new ClassPathResource("airline.xsd", getClass()));
builder.setPortTypeName("Airline");
builder.setTargetNamespace("http://www.springframework.org/spring-ws/samples/airline/definitions");
builder.afterPropertiesSet();
buildAll();
Wsdl11Definition definition = builder.getDefinition();
DOMResult domResult = new DOMResult();
transformer.transform(definition.getSource(), domResult);
Document result = (Document) domResult.getNode();
Document expected = documentBuilder.parse(getClass().getResourceAsStream("airline-soap12.wsdl"));
XMLUnit.setIgnoreWhitespace(true);
assertXMLEqual("Invalid WSDL built", expected, result);
}
public void testNoSchemaPrefix() throws Exception {
builder.setSchema(new ClassPathResource("single.xsd", getClass()));
builder.setPortTypeName("Order");
builder.setTargetNamespace("http://www.springframework.org/spring-ws/single/definitions");
builder.setSchemaPrefix("");
builder.afterPropertiesSet();
buildAll();
Wsdl11Definition definition = builder.getDefinition();
transformer.transform(definition.getSource(), new StringResult());
}
private void buildAll() {
builder.buildDefinition();
builder.buildImports();
builder.buildTypes();
builder.buildMessages();
builder.buildPortTypes();
builder.buildBindings();
builder.buildServices();
}
}

View File

@@ -1,99 +0,0 @@
/*
* 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.builder;
import java.util.List;
import javax.xml.namespace.QName;
import junit.framework.TestCase;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
public class XsdSchemaHelperTest extends TestCase {
public void testSingle() throws Exception {
Resource resource = new ClassPathResource("single.xsd", getClass());
XsdSchemaHelper helper = new XsdSchemaHelper(resource);
assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/single/schema",
helper.getTargetNamespace());
List elementDeclarations = helper.getElementDeclarations(true);
assertEquals("Invalid amount of elements", 3, elementDeclarations.size());
assertEquals("Invalid element declaration name",
new QName("http://www.springframework.org/spring-ws/single/schema", "GetOrderRequest"),
elementDeclarations.get(0));
assertEquals("Invalid element declaration name",
new QName("http://www.springframework.org/spring-ws/single/schema", "GetOrderResponse"),
elementDeclarations.get(1));
assertEquals("Invalid element declaration name",
new QName("http://www.springframework.org/spring-ws/single/schema", "GetOrderFault"),
elementDeclarations.get(2));
}
public void testFollowInclude() throws Exception {
Resource resource = new ClassPathResource("including.xsd", getClass());
XsdSchemaHelper helper = new XsdSchemaHelper(resource);
assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/include/schema",
helper.getTargetNamespace());
List elementDeclarations = helper.getElementDeclarations(true);
assertEquals("Invalid amount of elements", 2, elementDeclarations.size());
assertEquals("Invalid element declaration name",
new QName("http://www.springframework.org/spring-ws/include/schema", "GetOrderResponse"),
elementDeclarations.get(0));
assertEquals("Invalid element declaration name",
new QName("http://www.springframework.org/spring-ws/include/schema", "GetOrderRequest"),
elementDeclarations.get(1));
}
public void testNotFollowInclude() throws Exception {
Resource resource = new ClassPathResource("including.xsd", getClass());
XsdSchemaHelper helper = new XsdSchemaHelper(resource);
assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/include/schema",
helper.getTargetNamespace());
List elementDeclarations = helper.getElementDeclarations(false);
assertEquals("Invalid amount of elements", 1, elementDeclarations.size());
assertEquals("Invalid element declaration name",
new QName("http://www.springframework.org/spring-ws/include/schema", "GetOrderRequest"),
elementDeclarations.get(0));
}
public void testFollowImport() throws Exception {
Resource resource = new ClassPathResource("importing.xsd", getClass());
XsdSchemaHelper helper = new XsdSchemaHelper(resource);
assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/importing/schema",
helper.getTargetNamespace());
List elementDeclarations = helper.getElementDeclarations(true);
assertEquals("Invalid amount of elements", 2, elementDeclarations.size());
assertEquals("Invalid element declaration name",
new QName("http://www.springframework.org/spring-ws/imported/schema", "GetOrderResponse"),
elementDeclarations.get(0));
assertEquals("Invalid element declaration name",
new QName("http://www.springframework.org/spring-ws/importing/schema", "GetOrderRequest"),
elementDeclarations.get(1));
}
public void testNotFollowImport() throws Exception {
Resource resource = new ClassPathResource("importing.xsd", getClass());
XsdSchemaHelper helper = new XsdSchemaHelper(resource);
assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/importing/schema",
helper.getTargetNamespace());
List elementDeclarations = helper.getElementDeclarations(false);
assertEquals("Invalid amount of elements", 1, elementDeclarations.size());
assertEquals("Invalid element declaration name",
new QName("http://www.springframework.org/spring-ws/importing/schema", "GetOrderRequest"),
elementDeclarations.get(0));
}
}

View File

@@ -1,207 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:schema="http://www.springframework.org/spring-ws/samples/airline/schemas"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.springframework.org/spring-ws/samples/airline/definitions"
targetNamespace="http://www.springframework.org/spring-ws/samples/airline/definitions">
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.springframework.org/spring-ws/samples/airline/schemas"
elementFormDefault="qualified"
targetNamespace="http://www.springframework.org/spring-ws/samples/airline/schemas">
<element name="GetFlightsRequest">
<complexType>
<all>
<element name="from" type="tns:AirportCode"/>
<element name="to" type="tns:AirportCode"/>
<element name="departureDate" type="date"/>
<element minOccurs="0" name="serviceClass" type="tns:ServiceClass"/>
</all>
</complexType>
</element>
<element name="GetFlightsResponse">
<complexType>
<sequence>
<element maxOccurs="unbounded" minOccurs="0" name="flight" type="tns:Flight"/>
</sequence>
</complexType>
</element>
<element name="GetFlightsFault">
<complexType>
<sequence>
<element name="errorCode" type="string"/>
</sequence>
</complexType>
</element>
<element name="BookFlightRequest">
<complexType>
<all>
<element name="flightNumber" type="tns:FlightNumber"/>
<element name="departureTime" type="dateTime"/>
<element name="passengers">
<complexType>
<choice maxOccurs="9">
<element name="passenger" type="tns:Name"/>
<element name="username" type="tns:FrequentFlyerUsername"/>
</choice>
</complexType>
</element>
</all>
</complexType>
</element>
<element name="BookFlightResponse" type="tns:Ticket"/>
<element name="GetFrequentFlyerMileageRequest"/>
<element name="GetFrequentFlyerMileageResponse" type="int"/>
<complexType name="Flight">
<sequence>
<element name="number" type="tns:FlightNumber"/>
<element name="departureTime" type="dateTime"/>
<element name="from" type="tns:Airport"/>
<element name="arrivalTime" type="dateTime"/>
<element name="to" type="tns:Airport"/>
<element name="serviceClass" type="tns:ServiceClass"/>
</sequence>
</complexType>
<simpleType name="FlightNumber">
<restriction base="string">
<pattern value="[A-Z][A-Z][0-9][0-9][0-9][0-9]"/>
</restriction>
</simpleType>
<complexType name="Name">
<sequence>
<element name="first" type="string"/>
<element name="last" type="string"/>
</sequence>
</complexType>
<simpleType name="FrequentFlyerUsername">
<restriction base="string"/>
</simpleType>
<complexType name="Airport">
<all>
<element name="code" type="tns:AirportCode"/>
<element name="name" type="string"/>
<element name="city" type="string"/>
</all>
</complexType>
<simpleType name="AirportCode">
<restriction base="string">
<pattern value="[A-Z][A-Z][A-Z]"/>
</restriction>
</simpleType>
<complexType name="Ticket">
<all>
<element name="id" type="long"/>
<element name="issueDate" type="date"/>
<element name="passengers">
<complexType>
<sequence>
<element maxOccurs="9" name="passenger" type="tns:Name"/>
</sequence>
</complexType>
</element>
<element name="flight" type="tns:Flight"/>
</all>
</complexType>
<simpleType name="ServiceClass">
<restriction base="NCName">
<enumeration value="economy"/>
<enumeration value="business"/>
<enumeration value="first"/>
</restriction>
</simpleType>
</schema>
</wsdl:types>
<wsdl:message name="BookFlightRequest">
<wsdl:part element="schema:BookFlightRequest" name="BookFlightRequest"/>
</wsdl:message>
<wsdl:message name="GetFlightsResponse">
<wsdl:part element="schema:GetFlightsResponse" name="GetFlightsResponse"/>
</wsdl:message>
<wsdl:message name="BookFlightResponse">
<wsdl:part element="schema:BookFlightResponse" name="BookFlightResponse"/>
</wsdl:message>
<wsdl:message name="GetFrequentFlyerMileageRequest">
<wsdl:part element="schema:GetFrequentFlyerMileageRequest" name="GetFrequentFlyerMileageRequest"/>
</wsdl:message>
<wsdl:message name="GetFlightsFault">
<wsdl:part element="schema:GetFlightsFault" name="GetFlightsFault"/>
</wsdl:message>
<wsdl:message name="GetFlightsRequest">
<wsdl:part element="schema:GetFlightsRequest" name="GetFlightsRequest"/>
</wsdl:message>
<wsdl:message name="GetFrequentFlyerMileageResponse">
<wsdl:part element="schema:GetFrequentFlyerMileageResponse" name="GetFrequentFlyerMileageResponse"/>
</wsdl:message>
<wsdl:portType name="Airline">
<wsdl:operation name="BookFlight">
<wsdl:input message="tns:BookFlightRequest" name="BookFlightRequest"/>
<wsdl:output message="tns:BookFlightResponse" name="BookFlightResponse"/>
</wsdl:operation>
<wsdl:operation name="GetFrequentFlyerMileage">
<wsdl:input message="tns:GetFrequentFlyerMileageRequest" name="GetFrequentFlyerMileageRequest"/>
<wsdl:output message="tns:GetFrequentFlyerMileageResponse" name="GetFrequentFlyerMileageResponse"/>
</wsdl:operation>
<wsdl:operation name="GetFlights">
<wsdl:input message="tns:GetFlightsRequest" name="GetFlightsRequest"/>
<wsdl:output message="tns:GetFlightsResponse" name="GetFlightsResponse"/>
<wsdl:fault message="tns:GetFlightsFault" name="GetFlightsFault"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="AirlineBinding" type="tns:Airline">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="BookFlight">
<soap:operation soapAction=""/>
<wsdl:input name="BookFlightRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="BookFlightResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetFrequentFlyerMileage">
<soap:operation soapAction=""/>
<wsdl:input name="GetFrequentFlyerMileageRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="GetFrequentFlyerMileageResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetFlights">
<soap:operation soapAction=""/>
<wsdl:input name="GetFlightsRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="GetFlightsResponse">
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="GetFlightsFault">
<soap:fault name="GetFlightsFault" use="literal"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="AirlineService">
<wsdl:port binding="tns:AirlineBinding" name="AirlinePort">
<soap:address location="http://localhost:8080/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

View File

@@ -1,207 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:schema="http://www.springframework.org/spring-ws/samples/airline/schemas"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:tns="http://www.springframework.org/spring-ws/samples/airline/definitions"
targetNamespace="http://www.springframework.org/spring-ws/samples/airline/definitions">
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.springframework.org/spring-ws/samples/airline/schemas"
elementFormDefault="qualified"
targetNamespace="http://www.springframework.org/spring-ws/samples/airline/schemas">
<element name="GetFlightsRequest">
<complexType>
<all>
<element name="from" type="tns:AirportCode"/>
<element name="to" type="tns:AirportCode"/>
<element name="departureDate" type="date"/>
<element minOccurs="0" name="serviceClass" type="tns:ServiceClass"/>
</all>
</complexType>
</element>
<element name="GetFlightsResponse">
<complexType>
<sequence>
<element maxOccurs="unbounded" minOccurs="0" name="flight" type="tns:Flight"/>
</sequence>
</complexType>
</element>
<element name="GetFlightsFault">
<complexType>
<sequence>
<element name="errorCode" type="string"/>
</sequence>
</complexType>
</element>
<element name="BookFlightRequest">
<complexType>
<all>
<element name="flightNumber" type="tns:FlightNumber"/>
<element name="departureTime" type="dateTime"/>
<element name="passengers">
<complexType>
<choice maxOccurs="9">
<element name="passenger" type="tns:Name"/>
<element name="username" type="tns:FrequentFlyerUsername"/>
</choice>
</complexType>
</element>
</all>
</complexType>
</element>
<element name="BookFlightResponse" type="tns:Ticket"/>
<element name="GetFrequentFlyerMileageRequest"/>
<element name="GetFrequentFlyerMileageResponse" type="int"/>
<complexType name="Flight">
<sequence>
<element name="number" type="tns:FlightNumber"/>
<element name="departureTime" type="dateTime"/>
<element name="from" type="tns:Airport"/>
<element name="arrivalTime" type="dateTime"/>
<element name="to" type="tns:Airport"/>
<element name="serviceClass" type="tns:ServiceClass"/>
</sequence>
</complexType>
<simpleType name="FlightNumber">
<restriction base="string">
<pattern value="[A-Z][A-Z][0-9][0-9][0-9][0-9]"/>
</restriction>
</simpleType>
<complexType name="Name">
<sequence>
<element name="first" type="string"/>
<element name="last" type="string"/>
</sequence>
</complexType>
<simpleType name="FrequentFlyerUsername">
<restriction base="string"/>
</simpleType>
<complexType name="Airport">
<all>
<element name="code" type="tns:AirportCode"/>
<element name="name" type="string"/>
<element name="city" type="string"/>
</all>
</complexType>
<simpleType name="AirportCode">
<restriction base="string">
<pattern value="[A-Z][A-Z][A-Z]"/>
</restriction>
</simpleType>
<complexType name="Ticket">
<all>
<element name="id" type="long"/>
<element name="issueDate" type="date"/>
<element name="passengers">
<complexType>
<sequence>
<element maxOccurs="9" name="passenger" type="tns:Name"/>
</sequence>
</complexType>
</element>
<element name="flight" type="tns:Flight"/>
</all>
</complexType>
<simpleType name="ServiceClass">
<restriction base="NCName">
<enumeration value="economy"/>
<enumeration value="business"/>
<enumeration value="first"/>
</restriction>
</simpleType>
</schema>
</wsdl:types>
<wsdl:message name="BookFlightRequest">
<wsdl:part element="schema:BookFlightRequest" name="BookFlightRequest"/>
</wsdl:message>
<wsdl:message name="GetFlightsResponse">
<wsdl:part element="schema:GetFlightsResponse" name="GetFlightsResponse"/>
</wsdl:message>
<wsdl:message name="BookFlightResponse">
<wsdl:part element="schema:BookFlightResponse" name="BookFlightResponse"/>
</wsdl:message>
<wsdl:message name="GetFrequentFlyerMileageRequest">
<wsdl:part element="schema:GetFrequentFlyerMileageRequest" name="GetFrequentFlyerMileageRequest"/>
</wsdl:message>
<wsdl:message name="GetFlightsFault">
<wsdl:part element="schema:GetFlightsFault" name="GetFlightsFault"/>
</wsdl:message>
<wsdl:message name="GetFlightsRequest">
<wsdl:part element="schema:GetFlightsRequest" name="GetFlightsRequest"/>
</wsdl:message>
<wsdl:message name="GetFrequentFlyerMileageResponse">
<wsdl:part element="schema:GetFrequentFlyerMileageResponse" name="GetFrequentFlyerMileageResponse"/>
</wsdl:message>
<wsdl:portType name="Airline">
<wsdl:operation name="BookFlight">
<wsdl:input message="tns:BookFlightRequest" name="BookFlightRequest"/>
<wsdl:output message="tns:BookFlightResponse" name="BookFlightResponse"/>
</wsdl:operation>
<wsdl:operation name="GetFrequentFlyerMileage">
<wsdl:input message="tns:GetFrequentFlyerMileageRequest" name="GetFrequentFlyerMileageRequest"/>
<wsdl:output message="tns:GetFrequentFlyerMileageResponse" name="GetFrequentFlyerMileageResponse"/>
</wsdl:operation>
<wsdl:operation name="GetFlights">
<wsdl:input message="tns:GetFlightsRequest" name="GetFlightsRequest"/>
<wsdl:output message="tns:GetFlightsResponse" name="GetFlightsResponse"/>
<wsdl:fault message="tns:GetFlightsFault" name="GetFlightsFault"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="AirlineBinding" type="tns:Airline">
<soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="BookFlight">
<soap12:operation soapAction=""/>
<wsdl:input name="BookFlightRequest">
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output name="BookFlightResponse">
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetFrequentFlyerMileage">
<soap12:operation soapAction=""/>
<wsdl:input name="GetFrequentFlyerMileageRequest">
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output name="GetFrequentFlyerMileageResponse">
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetFlights">
<soap12:operation soapAction=""/>
<wsdl:input name="GetFlightsRequest">
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output name="GetFlightsResponse">
<soap12:body use="literal"/>
</wsdl:output>
<wsdl:fault name="GetFlightsFault">
<soap12:fault name="GetFlightsFault" use="literal"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="AirlineService">
<wsdl:port binding="tns:AirlineBinding" name="AirlinePort">
<soap12:address location="http://localhost:8080/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

View File

@@ -1,125 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.springframework.org/spring-ws/samples/airline/schemas"
xmlns:tns="http://www.springframework.org/spring-ws/samples/airline/schemas" elementFormDefault="qualified">
<element name="GetFlightsRequest">
<complexType>
<all>
<element name="from" type="tns:AirportCode"/>
<element name="to" type="tns:AirportCode"/>
<element name="departureDate" type="date"/>
<element name="serviceClass" type="tns:ServiceClass" minOccurs="0"/>
</all>
</complexType>
</element>
<element name="GetFlightsResponse">
<complexType>
<sequence>
<element name="flight" type="tns:Flight" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
<element name="GetFlightsFault">
<complexType>
<sequence>
<element name="errorCode" type="string"/>
</sequence>
</complexType>
</element>
<element name="BookFlightRequest">
<complexType>
<all>
<element name="flightNumber" type="tns:FlightNumber"/>
<element name="departureTime" type="dateTime"/>
<element name="passengers">
<complexType>
<choice maxOccurs="9">
<element name="passenger" type="tns:Name"/>
<element name="username" type="tns:FrequentFlyerUsername"/>
</choice>
</complexType>
</element>
</all>
</complexType>
</element>
<element name="BookFlightResponse" type="tns:Ticket"/>
<element name="GetFrequentFlyerMileageRequest"/>
<element name="GetFrequentFlyerMileageResponse" type="int"/>
<complexType name="Flight">
<sequence>
<element name="number" type="tns:FlightNumber"/>
<element name="departureTime" type="dateTime"/>
<element name="from" type="tns:Airport"/>
<element name="arrivalTime" type="dateTime"/>
<element name="to" type="tns:Airport"/>
<element name="serviceClass" type="tns:ServiceClass"/>
</sequence>
</complexType>
<simpleType name="FlightNumber">
<restriction base="string">
<pattern value="[A-Z][A-Z][0-9][0-9][0-9][0-9]"/>
</restriction>
</simpleType>
<complexType name="Name">
<sequence>
<element name="first" type="string"/>
<element name="last" type="string"/>
</sequence>
</complexType>
<simpleType name="FrequentFlyerUsername">
<restriction base="string"/>
</simpleType>
<complexType name="Airport">
<all>
<element name="code" type="tns:AirportCode"/>
<element name="name" type="string"/>
<element name="city" type="string"/>
</all>
</complexType>
<simpleType name="AirportCode">
<restriction base="string">
<pattern value="[A-Z][A-Z][A-Z]"/>
</restriction>
</simpleType>
<complexType name="Ticket">
<all>
<element name="id" type="long"/>
<element name="issueDate" type="date"/>
<element name="passengers">
<complexType>
<sequence>
<element name="passenger" type="tns:Name" maxOccurs="9"/>
</sequence>
</complexType>
</element>
<element name="flight" type="tns:Flight"/>
</all>
</complexType>
<simpleType name="ServiceClass">
<restriction base="NCName">
<enumeration value="economy"/>
<enumeration value="business"/>
<enumeration value="first"/>
</restriction>
</simpleType>
</schema>

View File

@@ -1,57 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:schema="http://www.springframework.org/spring-ws/importing/schema"
xmlns:schema0="http://www.springframework.org/spring-ws/imported/schema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.springframework.org/spring-ws/import/definitions"
targetNamespace="http://www.springframework.org/spring-ws/import/definitions">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.springframework.org/spring-ws/importing/schema"
xmlns="http://www.springframework.org/spring-ws/importing/schema" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xsd:import namespace="http://www.springframework.org/spring-ws/imported/schema"
schemaLocation="imported.xsd"/>
<xsd:element name="GetOrderRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="child" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="GetOrderRequest">
<wsdl:part name="GetOrderRequest" element="schema:GetOrderRequest"/>
</wsdl:message>
<wsdl:message name="GetOrderResponse">
<wsdl:part name="GetOrderResponse" element="schema0:GetOrderResponse"/>
</wsdl:message>
<wsdl:portType name="Order">
<wsdl:operation name="GetOrder">
<wsdl:input message="tns:GetOrderRequest" name="GetOrderRequest"/>
<wsdl:output message="tns:GetOrderResponse" name="GetOrderResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="OrderBinding" type="tns:Order">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetOrder">
<soap:operation soapAction=""/>
<wsdl:input name="GetOrderRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="GetOrderResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="OrderService">
<wsdl:port binding="tns:OrderBinding" name="OrderPort">
<soap:address location="http://localhost:8080/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

View File

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

View File

@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.springframework.org/spring-ws/importing/schema"
xmlns="http://www.springframework.org/spring-ws/importing/schema" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xsd:import namespace="http://www.springframework.org/spring-ws/imported/schema" schemaLocation="imported.xsd"/>
<xsd:element name="GetOrderRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="child" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

View File

@@ -1,54 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:schema="http://www.springframework.org/spring-ws/include/schema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.springframework.org/spring-ws/include/definitions"
targetNamespace="http://www.springframework.org/spring-ws/include/definitions">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.springframework.org/spring-ws/include/schema"
xmlns="http://www.springframework.org/spring-ws/include/schema" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xsd:include schemaLocation="included.xsd"/>
<xsd:element name="GetOrderRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="child" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="GetOrderResponse">
<wsdl:part name="GetOrderResponse" element="schema:GetOrderResponse"/>
</wsdl:message>
<wsdl:message name="GetOrderRequest">
<wsdl:part name="GetOrderRequest" element="schema:GetOrderRequest"/>
</wsdl:message>
<wsdl:portType name="Order">
<wsdl:operation name="GetOrder">
<wsdl:input message="tns:GetOrderRequest" name="GetOrderRequest"/>
<wsdl:output message="tns:GetOrderResponse" name="GetOrderResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="OrderBinding" type="tns:Order">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetOrder">
<soap:operation soapAction=""/>
<wsdl:input name="GetOrderRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="GetOrderResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="OrderService">
<wsdl:port binding="tns:OrderBinding" name="OrderPort">
<soap:address location="http://localhost:8080/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

View File

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

View File

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

View File

@@ -1,49 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:schema="http://www.springframework.org/spring-ws/single/schema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.springframework.org/spring-ws/single/definitions"
targetNamespace="http://www.springframework.org/spring-ws/single/definitions">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://www.springframework.org/spring-ws/single/schema" schemaLocation="single.xsd"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="GetOrderRequest">
<wsdl:part name="GetOrderRequest" element="schema:GetOrderRequest"/>
</wsdl:message>
<wsdl:message name="GetOrderFault">
<wsdl:part name="GetOrderFault" element="schema:GetOrderFault"/>
</wsdl:message>
<wsdl:message name="GetOrderResponse">
<wsdl:part name="GetOrderResponse" element="schema:GetOrderResponse"/>
</wsdl:message>
<wsdl:portType name="Order">
<wsdl:operation name="GetOrder">
<wsdl:input message="tns:GetOrderRequest" name="GetOrderRequest"/>
<wsdl:output message="tns:GetOrderResponse" name="GetOrderResponse"/>
<wsdl:fault message="tns:GetOrderFault" name="GetOrderFault"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="OrderBinding" type="tns:Order">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetOrder">
<soap:operation soapAction=""/>
<wsdl:input name="GetOrderRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="GetOrderResponse">
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="GetOrderFault">
<soap:fault name="GetOrderFault" use="literal"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="OrderService">
<wsdl:port binding="tns:OrderBinding" name="OrderPort">
<soap:address location="http://localhost:8080/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

View File

@@ -1,75 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:schema="http://www.springframework.org/spring-ws/single/schema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.springframework.org/spring-ws/single/definitions"
targetNamespace="http://www.springframework.org/spring-ws/single/definitions">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.springframework.org/spring-ws/single/schema"
xmlns="http://www.springframework.org/spring-ws/single/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>
</wsdl:types>
<wsdl:message name="GetOrderRequest">
<wsdl:part name="GetOrderRequest" element="schema:GetOrderRequest"/>
</wsdl:message>
<wsdl:message name="GetOrderFault">
<wsdl:part name="GetOrderFault" element="schema:GetOrderFault"/>
</wsdl:message>
<wsdl:message name="GetOrderResponse">
<wsdl:part name="GetOrderResponse" element="schema:GetOrderResponse"/>
</wsdl:message>
<wsdl:portType name="Order">
<wsdl:operation name="GetOrder">
<wsdl:input message="tns:GetOrderRequest" name="GetOrderRequest"/>
<wsdl:output message="tns:GetOrderResponse" name="GetOrderResponse"/>
<wsdl:fault message="tns:GetOrderFault" name="GetOrderFault"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="OrderBinding" type="tns:Order">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetOrder">
<soap:operation soapAction=""/>
<wsdl:input name="GetOrderRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="GetOrderResponse">
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="GetOrderFault">
<soap:fault name="GetOrderFault" use="literal"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="OrderService">
<wsdl:port binding="tns:OrderBinding" name="OrderPort">
<soap:address location="http://localhost:8080/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

View File

@@ -1,35 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.springframework.org/spring-ws/single/schema"
xmlns="http://www.springframework.org/spring-ws/single/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>

View File

@@ -739,7 +739,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
<version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -748,6 +748,12 @@
<version>1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
<version>2.2</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
@@ -778,5 +784,10 @@
<artifactId>log4j</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -1,65 +0,0 @@
/*
* Copyright 2002-2009 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.soap.security.support;
import org.acegisecurity.AccountExpiredException;
import org.acegisecurity.CredentialsExpiredException;
import org.acegisecurity.DisabledException;
import org.acegisecurity.LockedException;
import org.acegisecurity.userdetails.UserDetails;
/**
* Generic utility methods for Spring Security
*
* @author Tareq Abedrabbo
* @since 1.5.8
* @deprecated As of Spring-WS 1.5, in favor of Spring Security
*/
public abstract class AcegiUtils {
/**
* Checks the validity of a user's account and credentials.
*
* @param user the user to check
* @throws org.springframework.security.AccountExpiredException
* if the account has expired
* @throws org.springframework.security.CredentialsExpiredException
* if the credentials have expired
* @throws org.springframework.security.DisabledException
* if the account is disabled
* @throws org.springframework.security.LockedException
* if the account is locked
*/
public static void checkUserValidity(UserDetails user)
throws AccountExpiredException, CredentialsExpiredException, DisabledException, LockedException {
if (!user.isAccountNonLocked()) {
throw new LockedException("User account is locked");
}
if (!user.isEnabled()) {
throw new DisabledException("User is disabled");
}
if (!user.isAccountNonExpired()) {
throw new AccountExpiredException("User account has expired");
}
if (!user.isCredentialsNonExpired()) {
throw new CredentialsExpiredException("User credentials have expired");
}
}
}

View File

@@ -366,7 +366,8 @@ public class Wss4jSecurityInterceptor extends AbstractWsSecurityInterceptor impl
/** Sets the server-side time to live
* @deprecated Use {@link #setValidationTimeToLive(int)} instead.
* */
*/
@Deprecated
public void setTimeToLive(int timeToLive) {
setValidationTimeToLive(timeToLive);
}

View File

@@ -1,119 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.soap.security.wss4j.callback.acegi;
import java.io.IOException;
import javax.security.auth.callback.UnsupportedCallbackException;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
import org.acegisecurity.providers.dao.UserCache;
import org.acegisecurity.providers.dao.cache.NullUserCache;
import org.acegisecurity.userdetails.UserDetails;
import org.acegisecurity.userdetails.UserDetailsService;
import org.acegisecurity.userdetails.UsernameNotFoundException;
import org.apache.ws.security.WSPasswordCallback;
import org.apache.ws.security.WSUsernameTokenPrincipal;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.DataAccessException;
import org.springframework.util.Assert;
import org.springframework.ws.soap.security.callback.CleanupCallback;
import org.springframework.ws.soap.security.support.AcegiUtils;
import org.springframework.ws.soap.security.wss4j.callback.AbstractWsPasswordCallbackHandler;
import org.springframework.ws.soap.security.wss4j.callback.UsernameTokenPrincipalCallback;
/**
* Callback handler that validates a password digest using an Acegi <code>UserDetailsService</code>. Logic based on
* Acegi's <code>DigestProcessingFilter</code>.
* <p/>
* An Acegi <code>UserDetailService</code> is used to load <code>UserDetails</code> from. The digest of the password
* contained in this details object is then compared with the digest in the message.
*
* @author Arjen Poutsma
* @see org.acegisecurity.userdetails.UserDetailsService
* @see org.acegisecurity.ui.digestauth.DigestProcessingFilter
* @since 1.5.0
* @deprecated As of Spring-WS 1.5, in favor of Spring Security
*/
public class AcegiDigestPasswordValidationCallbackHandler extends AbstractWsPasswordCallbackHandler
implements InitializingBean {
private UserCache userCache = new NullUserCache();
private UserDetailsService userDetailsService;
/** Sets the users cache. Not required, but can benefit performance. */
public void setUserCache(UserCache userCache) {
this.userCache = userCache;
}
/** Sets the Acegi user details service. Required. */
public void setUserDetailsService(UserDetailsService userDetailsService) {
this.userDetailsService = userDetailsService;
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(userDetailsService, "userDetailsService is required");
}
@Override
protected void handleUsernameToken(WSPasswordCallback callback) throws IOException, UnsupportedCallbackException {
String identifier = callback.getIdentifier();
UserDetails user = loadUserDetails(identifier);
if (user != null) {
AcegiUtils.checkUserValidity(user);
callback.setPassword(user.getPassword());
}
}
@Override
protected void handleUsernameTokenPrincipal(UsernameTokenPrincipalCallback callback)
throws IOException, UnsupportedCallbackException {
UserDetails user = loadUserDetails(callback.getPrincipal().getName());
WSUsernameTokenPrincipal principal = callback.getPrincipal();
UsernamePasswordAuthenticationToken authRequest =
new UsernamePasswordAuthenticationToken(principal, principal.getPassword(), user.getAuthorities());
if (logger.isDebugEnabled()) {
logger.debug("Authentication success: " + authRequest.toString());
}
SecurityContextHolder.getContext().setAuthentication(authRequest);
}
@Override
protected void handleCleanup(CleanupCallback callback) throws IOException, UnsupportedCallbackException {
SecurityContextHolder.clearContext();
}
private UserDetails loadUserDetails(String username) throws DataAccessException {
UserDetails user = userCache.getUserFromCache(username);
if (user == null) {
try {
user = userDetailsService.loadUserByUsername(username);
}
catch (UsernameNotFoundException notFound) {
if (logger.isDebugEnabled()) {
logger.debug("Username '" + username + "' not found");
}
return null;
}
userCache.putUserInCache(user);
}
return user;
}
}

View File

@@ -1,96 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.soap.security.wss4j.callback.acegi;
import java.io.IOException;
import javax.security.auth.callback.UnsupportedCallbackException;
import org.acegisecurity.Authentication;
import org.acegisecurity.AuthenticationException;
import org.acegisecurity.AuthenticationManager;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
import org.apache.ws.security.WSPasswordCallback;
import org.apache.ws.security.WSSecurityException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
import org.springframework.ws.soap.security.callback.CleanupCallback;
import org.springframework.ws.soap.security.wss4j.callback.AbstractWsPasswordCallbackHandler;
/**
* Callback handler that validates a certificate uses an Acegi <code>AuthenticationManager</code>. Logic based on
* Acegi's <code>BasicProcessingFilter</code>.
* <p/>
* This handler requires an Acegi <code>AuthenticationManager</code> to operate. It can be set using the
* <code>authenticationManager</code> property. An Acegi <code>UsernamePasswordAuthenticationToken</code> is created
* with the username as principal and password as credentials.
*
* @author Arjen Poutsma
* @see org.acegisecurity.providers.UsernamePasswordAuthenticationToken
* @see org.acegisecurity.ui.basicauth.BasicProcessingFilter
* @since 1.5.0
* @deprecated As of Spring-WS 1.5, in favor of Spring Security
*/
public class AcegiPlainTextPasswordValidationCallbackHandler extends AbstractWsPasswordCallbackHandler
implements InitializingBean {
private AuthenticationManager authenticationManager;
private boolean ignoreFailure = false;
/** Sets the Acegi authentication manager. Required. */
public void setAuthenticationManager(AuthenticationManager authenticationManager) {
this.authenticationManager = authenticationManager;
}
public void setIgnoreFailure(boolean ignoreFailure) {
this.ignoreFailure = ignoreFailure;
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(authenticationManager, "authenticationManager is required");
}
@Override
protected void handleCleanup(CleanupCallback callback) throws IOException, UnsupportedCallbackException {
SecurityContextHolder.clearContext();
}
@Override
protected void handleUsernameTokenUnknown(WSPasswordCallback callback)
throws IOException, UnsupportedCallbackException {
String identifier = callback.getIdentifier();
try {
Authentication authResult = authenticationManager
.authenticate(new UsernamePasswordAuthenticationToken(identifier, callback.getPassword()));
if (logger.isDebugEnabled()) {
logger.debug("Authentication success: " + authResult.toString());
}
SecurityContextHolder.getContext().setAuthentication(authResult);
}
catch (AuthenticationException failed) {
if (logger.isDebugEnabled()) {
logger.debug("Authentication request for user '" + identifier + "' failed: " + failed.toString());
}
SecurityContextHolder.clearContext();
if (!ignoreFailure) {
throw new WSSecurityException(WSSecurityException.FAILED_AUTHENTICATION);
}
}
}
}

View File

@@ -1,6 +0,0 @@
<html>
<body>
Contains <code>CallbackHandler</code> implementations for WSS4J that use the <a href="http://www.acegisecurity.org/">Acegi
Security System for Spring</a>.
</body>
</html>

View File

@@ -1,117 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.soap.security.xwss.callback.acegi;
import java.io.IOException;
import java.security.cert.X509Certificate;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.UnsupportedCallbackException;
import com.sun.xml.wss.impl.callback.CertificateValidationCallback;
import org.acegisecurity.Authentication;
import org.acegisecurity.AuthenticationException;
import org.acegisecurity.AuthenticationManager;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.providers.x509.X509AuthenticationToken;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
import org.springframework.ws.soap.security.callback.AbstractCallbackHandler;
import org.springframework.ws.soap.security.callback.CleanupCallback;
/**
* Callback handler that validates a certificate using an Acegi <code>AuthenticationManager</code>. Logic based on
* Acegi's <code>X509ProcessingFilter</code>. <p/> An Acegi <code>X509AuthenticationToken</code> is created with the
* certificate as the credentials. <p/> The configured authentication manager is expected to supply a provider which can
* handle this token (usually an instance of <code>X509AuthenticationProvider</code>).</p>
* <p/>
* This class only handles <code>CertificateValidationCallback</code>s, and throws an
* <code>UnsupportedCallbackException</code> for others.
*
* @author Arjen Poutsma
* @see X509AuthenticationToken
* @see org.acegisecurity.providers.x509.X509AuthenticationProvider
* @see org.acegisecurity.ui.x509.X509ProcessingFilter
* @see CertificateValidationCallback
* @since 1.0.0
* @deprecated As of Spring-WS 1.5, in favor of Spring Security
*/
public class AcegiCertificateValidationCallbackHandler extends AbstractCallbackHandler implements InitializingBean {
private AuthenticationManager authenticationManager;
private boolean ignoreFailure = false;
/** Sets the Acegi authentication manager. Required. */
public void setAuthenticationManager(AuthenticationManager authenticationManager) {
this.authenticationManager = authenticationManager;
}
public void setIgnoreFailure(boolean ignoreFailure) {
this.ignoreFailure = ignoreFailure;
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(authenticationManager, "authenticationManager is required");
}
/**
* Handles <code>CertificateValidationCallback</code>s, and throws an <code>UnsupportedCallbackException</code> for
* others
*
* @throws UnsupportedCallbackException when the callback is not supported
*/
@Override
protected void handleInternal(Callback callback) throws IOException, UnsupportedCallbackException {
if (callback instanceof CertificateValidationCallback) {
((CertificateValidationCallback) callback).setValidator(new AcegiCertificateValidator());
}
else if (callback instanceof CleanupCallback) {
SecurityContextHolder.clearContext();
}
else {
throw new UnsupportedCallbackException(callback);
}
}
private class AcegiCertificateValidator implements CertificateValidationCallback.CertificateValidator {
public boolean validate(X509Certificate certificate)
throws CertificateValidationCallback.CertificateValidationException {
boolean result;
try {
Authentication authResult =
authenticationManager.authenticate(new X509AuthenticationToken(certificate));
if (logger.isDebugEnabled()) {
logger.debug("Authentication request for certificate with DN [" +
certificate.getSubjectX500Principal().getName() + "] successful");
}
SecurityContextHolder.getContext().setAuthentication(authResult);
return true;
}
catch (AuthenticationException failed) {
if (logger.isDebugEnabled()) {
logger.debug("Authentication request for certificate with DN [" +
certificate.getSubjectX500Principal().getName() + "] failed: " + failed.toString());
}
SecurityContextHolder.clearContext();
result = ignoreFailure;
}
return result;
}
}
}

View File

@@ -1,160 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.soap.security.xwss.callback.acegi;
import java.io.IOException;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.UnsupportedCallbackException;
import com.sun.xml.wss.impl.callback.PasswordValidationCallback;
import com.sun.xml.wss.impl.callback.TimestampValidationCallback;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
import org.acegisecurity.providers.dao.UserCache;
import org.acegisecurity.providers.dao.cache.NullUserCache;
import org.acegisecurity.userdetails.UserDetails;
import org.acegisecurity.userdetails.UserDetailsService;
import org.acegisecurity.userdetails.UsernameNotFoundException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.DataAccessException;
import org.springframework.util.Assert;
import org.springframework.ws.soap.security.callback.AbstractCallbackHandler;
import org.springframework.ws.soap.security.callback.CleanupCallback;
import org.springframework.ws.soap.security.support.AcegiUtils;
import org.springframework.ws.soap.security.xwss.callback.DefaultTimestampValidator;
/**
* Callback handler that validates a password digest using an Acegi <code>UserDetailsService</code>. Logic based on
* Acegi's <code>DigestProcessingFilter</code>.
* <p/>
* An Acegi <code>UserDetailService</code> is used to load <code>UserDetails</code> from. The digest of the password
* contained in this details object is then compared with the digest in the message.
* <p/>
* This class only handles <code>PasswordValidationCallback</code>s that contain a <code>DigestPasswordRequest</code>,
* and throws an <code>UnsupportedCallbackException</code> for others.
*
* @author Arjen Poutsma
* @see UserDetailsService
* @see PasswordValidationCallback
* @see com.sun.xml.wss.impl.callback.PasswordValidationCallback.DigestPasswordRequest
* @see org.acegisecurity.ui.digestauth.DigestProcessingFilter
* @since 1.0.0
* @deprecated As of Spring-WS 1.5, in favor of Spring Security
*/
public class AcegiDigestPasswordValidationCallbackHandler extends AbstractCallbackHandler implements InitializingBean {
private UserCache userCache = new NullUserCache();
private UserDetailsService userDetailsService;
/** Sets the users cache. Not required, but can benefit performance. */
public void setUserCache(UserCache userCache) {
this.userCache = userCache;
}
/** Sets the Acegi user details service. Required. */
public void setUserDetailsService(UserDetailsService userDetailsService) {
this.userDetailsService = userDetailsService;
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(userDetailsService, "userDetailsService is required");
}
/**
* Handles <code>PasswordValidationCallback</code>s that contain a <code>DigestPasswordRequest</code>, and throws an
* <code>UnsupportedCallbackException</code> for others
*
* @throws UnsupportedCallbackException when the callback is not supported
*/
@Override
protected void handleInternal(Callback callback) throws IOException, UnsupportedCallbackException {
if (callback instanceof PasswordValidationCallback) {
PasswordValidationCallback passwordCallback = (PasswordValidationCallback) callback;
if (passwordCallback.getRequest() instanceof PasswordValidationCallback.DigestPasswordRequest) {
PasswordValidationCallback.DigestPasswordRequest request =
(PasswordValidationCallback.DigestPasswordRequest) passwordCallback.getRequest();
String username = request.getUsername();
UserDetails user = loadUserDetails(username);
if (user != null) {
AcegiUtils.checkUserValidity(user);
request.setPassword(user.getPassword());
}
AcegiDigestPasswordValidator validator = new AcegiDigestPasswordValidator(user);
passwordCallback.setValidator(validator);
return;
}
}
else if (callback instanceof TimestampValidationCallback) {
TimestampValidationCallback timestampCallback = (TimestampValidationCallback) callback;
timestampCallback.setValidator(new DefaultTimestampValidator());
}
else if (callback instanceof CleanupCallback) {
SecurityContextHolder.clearContext();
return;
}
throw new UnsupportedCallbackException(callback);
}
private UserDetails loadUserDetails(String username) throws DataAccessException {
UserDetails user = userCache.getUserFromCache(username);
if (user == null) {
try {
user = userDetailsService.loadUserByUsername(username);
}
catch (UsernameNotFoundException notFound) {
if (logger.isDebugEnabled()) {
logger.debug("Username '" + username + "' not found");
}
return null;
}
userCache.putUserInCache(user);
}
return user;
}
private class AcegiDigestPasswordValidator extends PasswordValidationCallback.DigestPasswordValidator {
private UserDetails user;
private AcegiDigestPasswordValidator(UserDetails user) {
this.user = user;
}
@Override
public boolean validate(PasswordValidationCallback.Request request)
throws PasswordValidationCallback.PasswordValidationException {
if (super.validate(request)) {
UsernamePasswordAuthenticationToken authRequest =
new UsernamePasswordAuthenticationToken(user, user.getPassword());
if (logger.isDebugEnabled()) {
logger.debug("Authentication success: " + authRequest.toString());
}
SecurityContextHolder.getContext().setAuthentication(authRequest);
return true;
}
else {
return false;
}
}
}
}

View File

@@ -1,123 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.soap.security.xwss.callback.acegi;
import java.io.IOException;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.UnsupportedCallbackException;
import com.sun.xml.wss.impl.callback.PasswordValidationCallback;
import org.acegisecurity.Authentication;
import org.acegisecurity.AuthenticationException;
import org.acegisecurity.AuthenticationManager;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
import org.springframework.ws.soap.security.callback.AbstractCallbackHandler;
import org.springframework.ws.soap.security.callback.CleanupCallback;
/**
* Callback handler that validates a certificate uses an Acegi <code>AuthenticationManager</code>. Logic based on
* Acegi's <code>BasicProcessingFilter</code>.
* <p/>
* This handler requires an Acegi <code>AuthenticationManager</code> to operate. It can be set using the
* <code>authenticationManager</code> property. An Acegi <code>UsernamePasswordAuthenticationToken</code> is created
* with the username as principal and password as credentials.
* <p/>
* This class only handles <code>PasswordValidationCallback</code>s that contain a
* <code>PlainTextPasswordRequest</code>, and throws an <code>UnsupportedCallbackException</code> for others.
*
* @author Arjen Poutsma
* @see UsernamePasswordAuthenticationToken
* @see PasswordValidationCallback
* @see com.sun.xml.wss.impl.callback.PasswordValidationCallback.PlainTextPasswordRequest
* @see org.acegisecurity.ui.basicauth.BasicProcessingFilter
* @since 1.0.0
* @deprecated As of Spring-WS 1.5, in favor of Spring Security
*/
public class AcegiPlainTextPasswordValidationCallbackHandler extends AbstractCallbackHandler
implements InitializingBean {
private AuthenticationManager authenticationManager;
private boolean ignoreFailure = false;
/** Sets the Acegi authentication manager. Required. */
public void setAuthenticationManager(AuthenticationManager authenticationManager) {
this.authenticationManager = authenticationManager;
}
public void setIgnoreFailure(boolean ignoreFailure) {
this.ignoreFailure = ignoreFailure;
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(authenticationManager, "authenticationManager is required");
}
/**
* Handles <code>PasswordValidationCallback</code>s that contain a <code>PlainTextPasswordRequest</code>, and throws
* an <code>UnsupportedCallbackException</code> for others.
*
* @throws UnsupportedCallbackException when the callback is not supported
*/
@Override
protected void handleInternal(Callback callback) throws IOException, UnsupportedCallbackException {
if (callback instanceof PasswordValidationCallback) {
PasswordValidationCallback validationCallback = (PasswordValidationCallback) callback;
if (validationCallback.getRequest() instanceof PasswordValidationCallback.PlainTextPasswordRequest) {
validationCallback.setValidator(new AcegiPlainTextPasswordValidator());
return;
}
}
else if (callback instanceof CleanupCallback) {
SecurityContextHolder.clearContext();
return;
}
throw new UnsupportedCallbackException(callback);
}
private class AcegiPlainTextPasswordValidator implements PasswordValidationCallback.PasswordValidator {
public boolean validate(PasswordValidationCallback.Request request)
throws PasswordValidationCallback.PasswordValidationException {
PasswordValidationCallback.PlainTextPasswordRequest plainTextRequest =
(PasswordValidationCallback.PlainTextPasswordRequest) request;
try {
Authentication authResult = authenticationManager.authenticate(
new UsernamePasswordAuthenticationToken(plainTextRequest.getUsername(),
plainTextRequest.getPassword()));
if (logger.isDebugEnabled()) {
logger.debug("Authentication success: " + authResult.toString());
}
SecurityContextHolder.getContext().setAuthentication(authResult);
return true;
}
catch (AuthenticationException failed) {
if (logger.isDebugEnabled()) {
logger.debug("Authentication request for user '" + plainTextRequest.getUsername() + "' failed: " +
failed.toString());
}
SecurityContextHolder.clearContext();
return ignoreFailure;
}
}
}
}

View File

@@ -1,69 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.soap.security.xwss.callback.acegi;
import java.io.IOException;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.UnsupportedCallbackException;
import com.sun.xml.wss.impl.callback.PasswordCallback;
import com.sun.xml.wss.impl.callback.UsernameCallback;
import org.acegisecurity.Authentication;
import org.acegisecurity.context.SecurityContextHolder;
import org.springframework.ws.soap.security.callback.AbstractCallbackHandler;
/**
* Callback handler that adds username/password information to a mesage using an Acegi {@link
* org.acegisecurity.context.SecurityContext SecurityContext}.
* <p/>
* This class handles <code>UsernameCallback</code>s and <code>PasswordCallback</code>s, and throws an
* <code>UnsupportedCallbackException</code> for others
*
* @author Arjen Poutsma
* @since 1.5.0
* @deprecated As of Spring-WS 1.5, in favor of Spring Security
*/
public class AcegiUsernamePasswordCallbackHandler extends AbstractCallbackHandler {
@Override
protected void handleInternal(Callback callback) throws IOException, UnsupportedCallbackException {
if (callback instanceof UsernameCallback) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null && authentication.getName() != null) {
UsernameCallback usernameCallback = (UsernameCallback) callback;
usernameCallback.setUsername(authentication.getName());
return;
}
else {
logger.warn("Cannot handle UsernameCallback: Acegi SecurityContext contains no Authentication");
}
}
else if (callback instanceof PasswordCallback) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null && authentication.getName() != null) {
PasswordCallback passwordCallback = (PasswordCallback) callback;
passwordCallback.setPassword(authentication.getCredentials().toString());
return;
}
else {
logger.warn("Canot handle PasswordCallback: Acegi SecurityContext contains no Authentication");
}
}
throw new UnsupportedCallbackException(callback);
}
}

View File

@@ -1,6 +0,0 @@
<html>
<body>
Contains <code>CallbackHandler</code> implementations for XWSS that use the <a href="http://www.acegisecurity.org/">Acegi
Security System for Spring</a>.
</body>
</html>

View File

@@ -1,92 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.soap.security.wss4j.callback.acegi;
import junit.framework.TestCase;
import org.acegisecurity.Authentication;
import org.acegisecurity.GrantedAuthority;
import org.acegisecurity.GrantedAuthorityImpl;
import org.acegisecurity.DisabledException;
import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.userdetails.User;
import org.acegisecurity.userdetails.UserDetails;
import org.acegisecurity.userdetails.UserDetailsService;
import org.apache.ws.security.WSUsernameTokenPrincipal;
import org.apache.ws.security.WSPasswordCallback;
import org.easymock.MockControl;
import org.springframework.ws.soap.security.wss4j.callback.UsernameTokenPrincipalCallback;
/** @author tareq */
public class AcegiDigestPasswordValidationCallbackHandlerTest extends TestCase {
private AcegiDigestPasswordValidationCallbackHandler callbackHandler;
private GrantedAuthorityImpl grantedAuthority;
private UserDetailsService userDetailsService;
private MockControl control;
private UserDetails user;
@Override
protected void setUp() throws Exception {
callbackHandler = new AcegiDigestPasswordValidationCallbackHandler();
grantedAuthority = new GrantedAuthorityImpl("ROLE_1");
control = MockControl.createControl(UserDetailsService.class);
userDetailsService = (UserDetailsService) control.getMock();
userDetailsService.loadUserByUsername("Ernie");
callbackHandler.setUserDetailsService(userDetailsService);
}
@Override
protected void tearDown() throws Exception {
control.reset();
}
public void testHandleUsernameTokenPrincipal() throws Exception {
user = new User("Ernie", "Bert", true, true, true, true, new GrantedAuthority[]{grantedAuthority});
WSUsernameTokenPrincipal principal = new WSUsernameTokenPrincipal("Ernie", true);
UsernameTokenPrincipalCallback callback = new UsernameTokenPrincipalCallback(principal);
control.setDefaultReturnValue(user);
control.replay();
callbackHandler.handleUsernameTokenPrincipal(callback);
SecurityContext context = SecurityContextHolder.getContext();
assertNotNull("SecurityContext must not be null", context);
Authentication authentication = context.getAuthentication();
assertNotNull("Authentication must not be null", authentication);
GrantedAuthority[] authorities = authentication.getAuthorities();
assertTrue("GrantedAuthority[] must not be null or empty", (authorities != null && authorities.length > 0));
assertEquals("Unexpected authority", grantedAuthority, authorities[0]);
}
public void testHandleUsernameTokenWithDisabledUser() throws Exception {
user = new User("Ernie", "Bert", false, true, true, true, new GrantedAuthority[]{grantedAuthority});
WSPasswordCallback callback = new WSPasswordCallback("ID", WSPasswordCallback.USERNAME_TOKEN);
control.setDefaultReturnValue(user);
control.replay();
try {
callbackHandler.handleUsernameToken(callback);
fail("disabled user authenticated");
} catch (DisabledException expected) {
}
}
}

View File

@@ -1,108 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.soap.security.xwss.callback.acegi;
import java.io.InputStream;
import java.security.KeyStore;
import java.security.cert.X509Certificate;
import com.sun.xml.wss.impl.callback.CertificateValidationCallback;
import junit.framework.TestCase;
import org.acegisecurity.AuthenticationManager;
import org.acegisecurity.BadCredentialsException;
import org.acegisecurity.GrantedAuthority;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.providers.TestingAuthenticationToken;
import org.acegisecurity.providers.x509.X509AuthenticationToken;
import org.easymock.MockControl;
import org.springframework.core.io.ClassPathResource;
import org.springframework.ws.soap.security.callback.CleanupCallback;
public class AcegiCertificateValidationCallbackHandlerTest extends TestCase {
private AcegiCertificateValidationCallbackHandler callbackHandler;
private MockControl control;
private AuthenticationManager mock;
private X509Certificate certificate;
private CertificateValidationCallback callback;
@Override
protected void setUp() throws Exception {
callbackHandler = new AcegiCertificateValidationCallbackHandler();
control = MockControl.createControl(AuthenticationManager.class);
mock = (AuthenticationManager) control.getMock();
callbackHandler.setAuthenticationManager(mock);
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
InputStream is = null;
try {
is = new ClassPathResource("/org/springframework/ws/soap/security/xwss/test-keystore.jks").getInputStream();
keyStore.load(is, "password".toCharArray());
}
finally {
if (is != null) {
is.close();
}
}
certificate = (X509Certificate) keyStore.getCertificate("alias");
callback = new CertificateValidationCallback(certificate);
}
@Override
protected void tearDown() throws Exception {
SecurityContextHolder.clearContext();
}
public void testValidateCertificateValid() throws Exception {
mock.authenticate(new X509AuthenticationToken(certificate));
control.setMatcher(MockControl.ALWAYS_MATCHER);
control.setReturnValue(new TestingAuthenticationToken(certificate, null, new GrantedAuthority[0]));
control.replay();
callbackHandler.handleInternal(callback);
boolean authenticated = callback.getResult();
assertTrue("Not authenticated", authenticated);
assertNotNull("No Authentication created", SecurityContextHolder.getContext().getAuthentication());
control.verify();
}
public void testValidateCertificateInvalid() throws Exception {
mock.authenticate(new X509AuthenticationToken(certificate));
control.setMatcher(MockControl.ALWAYS_MATCHER);
control.setThrowable(new BadCredentialsException(""));
control.replay();
callbackHandler.handleInternal(callback);
boolean authenticated = callback.getResult();
assertFalse("Authenticated", authenticated);
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
control.verify();
}
public void testCleanUp() throws Exception {
TestingAuthenticationToken authentication =
new TestingAuthenticationToken(new Object(), new Object(), new GrantedAuthority[0]);
SecurityContextHolder.getContext().setAuthentication(authentication);
CleanupCallback cleanupCallback = new CleanupCallback();
callbackHandler.handleInternal(cleanupCallback);
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
}
}

View File

@@ -1,121 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.soap.security.xwss.callback.acegi;
import com.sun.xml.wss.impl.callback.PasswordValidationCallback;
import junit.framework.TestCase;
import org.acegisecurity.GrantedAuthority;
import org.acegisecurity.DisabledException;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.providers.TestingAuthenticationToken;
import org.acegisecurity.userdetails.User;
import org.acegisecurity.userdetails.UserDetailsService;
import org.acegisecurity.userdetails.UsernameNotFoundException;
import org.easymock.MockControl;
import org.springframework.ws.soap.security.callback.CleanupCallback;
public class AcegiDigestPasswordValidationCallbackHandlerTest extends TestCase {
private AcegiDigestPasswordValidationCallbackHandler callbackHandler;
private MockControl control;
private UserDetailsService mock;
private String username;
private String password;
private PasswordValidationCallback callback;
@Override
protected void setUp() throws Exception {
callbackHandler = new AcegiDigestPasswordValidationCallbackHandler();
control = MockControl.createControl(UserDetailsService.class);
mock = (UserDetailsService) control.getMock();
callbackHandler.setUserDetailsService(mock);
username = "Bert";
password = "Ernie";
String nonce = "9mdsYDCrjjYRur0rxzYt2oD7";
String passwordDigest = "kwNstEaiFOrI7B31j7GuETYvdgk=";
String creationTime = "2006-06-01T23:48:42Z";
PasswordValidationCallback.DigestPasswordRequest request =
new PasswordValidationCallback.DigestPasswordRequest(username, passwordDigest, nonce, creationTime);
callback = new PasswordValidationCallback(request);
}
@Override
protected void tearDown() throws Exception {
SecurityContextHolder.clearContext();
}
public void testAuthenticateUserDigestUserNotFound() throws Exception {
control.expectAndThrow(mock.loadUserByUsername(username), new UsernameNotFoundException(username));
control.replay();
callbackHandler.handleInternal(callback);
boolean authenticated = callback.getResult();
assertFalse("Authenticated", authenticated);
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
control.verify();
}
public void testAuthenticateUserDigestValid() throws Exception {
User user = new User(username, password, true, true, true, true, new GrantedAuthority[0]);
control.expectAndReturn(mock.loadUserByUsername(username), user);
control.replay();
callbackHandler.handleInternal(callback);
boolean authenticated = callback.getResult();
assertTrue("Not authenticated", authenticated);
assertNotNull("No Authentication created", SecurityContextHolder.getContext().getAuthentication());
control.verify();
}
public void testAuthenticateUserDigestValidInvalid() throws Exception {
User user = new User(username, "Big bird", true, true, true, true, new GrantedAuthority[0]);
control.expectAndReturn(mock.loadUserByUsername(username), user);
control.replay();
callbackHandler.handleInternal(callback);
boolean authenticated = callback.getResult();
assertFalse("Authenticated", authenticated);
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
control.verify();
}
public void testAuthenticateUserDigestDisbaled() throws Exception {
User user = new User(username, "Ernie", false, true, true, true, new GrantedAuthority[0]);
control.expectAndReturn(mock.loadUserByUsername(username), user);
control.replay();
try {
callbackHandler.handleInternal(callback);
fail("disabled user authenticated");
} catch (
DisabledException expected) {
}
}
public void testCleanUp() throws Exception {
TestingAuthenticationToken authentication =
new TestingAuthenticationToken(new Object(), new Object(), new GrantedAuthority[0]);
SecurityContextHolder.getContext().setAuthentication(authentication);
CleanupCallback cleanupCallback = new CleanupCallback();
callbackHandler.handleInternal(cleanupCallback);
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
}
}

View File

@@ -1,97 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.soap.security.xwss.callback.acegi;
import com.sun.xml.wss.impl.callback.PasswordValidationCallback;
import junit.framework.TestCase;
import org.acegisecurity.Authentication;
import org.acegisecurity.AuthenticationManager;
import org.acegisecurity.BadCredentialsException;
import org.acegisecurity.GrantedAuthority;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.providers.TestingAuthenticationToken;
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
import org.easymock.MockControl;
import org.springframework.ws.soap.security.callback.CleanupCallback;
public class AcegiPlainTextPasswordValidationCallbackHandlerTest extends TestCase {
private AcegiPlainTextPasswordValidationCallbackHandler callbackHandler;
private MockControl control;
private AuthenticationManager mock;
private PasswordValidationCallback callback;
private String username;
private String password;
@Override
protected void setUp() throws Exception {
callbackHandler = new AcegiPlainTextPasswordValidationCallbackHandler();
control = MockControl.createControl(AuthenticationManager.class);
mock = (AuthenticationManager) control.getMock();
callbackHandler.setAuthenticationManager(mock);
username = "Bert";
password = "Ernie";
PasswordValidationCallback.PlainTextPasswordRequest request =
new PasswordValidationCallback.PlainTextPasswordRequest(username, password);
callback = new PasswordValidationCallback(request);
}
@Override
protected void tearDown() throws Exception {
SecurityContextHolder.clearContext();
}
public void testAuthenticateUserPlainTextValid() throws Exception {
Authentication authResult = new TestingAuthenticationToken(username, password, new GrantedAuthority[0]);
control.expectAndReturn(mock.authenticate(new UsernamePasswordAuthenticationToken(username, password)),
authResult);
control.replay();
callbackHandler.handleInternal(callback);
boolean authenticated = callback.getResult();
assertTrue("Not authenticated", authenticated);
assertNotNull("No Authentication created", SecurityContextHolder.getContext().getAuthentication());
control.verify();
}
public void testAuthenticateUserPlainTextInvalid() throws Exception {
control.expectAndThrow(mock.authenticate(new UsernamePasswordAuthenticationToken(username, password)),
new BadCredentialsException(""));
control.replay();
callbackHandler.handleInternal(callback);
boolean authenticated = callback.getResult();
assertFalse("Authenticated", authenticated);
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
control.verify();
}
public void testCleanUp() throws Exception {
TestingAuthenticationToken authentication =
new TestingAuthenticationToken(new Object(), new Object(), new GrantedAuthority[0]);
SecurityContextHolder.getContext().setAuthentication(authentication);
CleanupCallback cleanupCallback = new CleanupCallback();
callbackHandler.handleInternal(cleanupCallback);
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
}
}

View File

@@ -1,53 +0,0 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.soap.security.xwss.callback.acegi;
import com.sun.xml.wss.impl.callback.PasswordCallback;
import com.sun.xml.wss.impl.callback.UsernameCallback;
import junit.framework.TestCase;
import org.acegisecurity.Authentication;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
public class AcegiUsernamePasswordCallbackHandlerTest extends TestCase {
private AcegiUsernamePasswordCallbackHandler handler;
@Override
protected void setUp() throws Exception {
handler = new AcegiUsernamePasswordCallbackHandler();
Authentication authentication = new UsernamePasswordAuthenticationToken("Bert", "Ernie");
SecurityContextHolder.getContext().setAuthentication(authentication);
}
@Override
protected void tearDown() throws Exception {
SecurityContextHolder.clearContext();
}
public void testUsernameCallback() throws Exception {
UsernameCallback usernameCallback = new UsernameCallback();
handler.handleInternal(usernameCallback);
assertEquals("Invalid username", "Bert", usernameCallback.getUsername());
}
public void testPasswordCallback() throws Exception {
PasswordCallback passwordCallback = new PasswordCallback();
handler.handleInternal(passwordCallback);
assertEquals("Invalid username", "Ernie", passwordCallback.getPassword());
}
}