You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by ve...@apache.org on 2016/02/14 18:12:37 UTC
svn commit: r1730359 - in /axis/axis2/java/core/branches/1_7: ./
modules/kernel/src/org/apache/axis2/description/
modules/kernel/test-resources/wsdl/imports/
modules/kernel/test/org/apache/axis2/description/
Author: veithen
Date: Sun Feb 14 17:12:36 2016
New Revision: 1730359
URL: http://svn.apache.org/viewvc?rev=1730359&view=rev
Log:
AXIS2-5732: Merge r1730335 to the 1.7 branch.
Added:
axis/axis2/java/core/branches/1_7/modules/kernel/test-resources/wsdl/imports/
- copied from r1730335, axis/axis2/java/core/trunk/modules/kernel/test-resources/wsdl/imports/
Modified:
axis/axis2/java/core/branches/1_7/ (props changed)
axis/axis2/java/core/branches/1_7/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java
axis/axis2/java/core/branches/1_7/modules/kernel/test/org/apache/axis2/description/WSDL11ToAxisServiceBuilderTest.java
Propchange: axis/axis2/java/core/branches/1_7/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Feb 14 17:12:36 2016
@@ -1,4 +1,4 @@
/axis/axis2/java/core/branches/1_6:1295540
/axis/axis2/java/core/branches/AXIOM-420:1334386-1336397
/axis/axis2/java/core/branches/AXIS2-4318:1230452,1295542,1324772,1327468,1329571,1332141,1335355,1335357,1340985
-/axis/axis2/java/core/trunk:1726494,1726509,1726513,1727171,1727174,1727177,1727180,1729891,1730095,1730139,1730186,1730195,1730197,1730222,1730300,1730308,1730310,1730317,1730322
+/axis/axis2/java/core/trunk:1726494,1726509,1726513,1727171,1727174,1727177,1727180,1729891,1730095,1730139,1730186,1730195,1730197,1730222,1730300,1730308,1730310,1730317,1730322,1730335
Modified: axis/axis2/java/core/branches/1_7/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_7/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java?rev=1730359&r1=1730358&r2=1730359&view=diff
==============================================================================
--- axis/axis2/java/core/branches/1_7/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java (original)
+++ axis/axis2/java/core/branches/1_7/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java Sun Feb 14 17:12:36 2016
@@ -332,10 +332,16 @@ public class WSDL11ToAxisServiceBuilder
Binding binding = findBinding(wsdl4jDefinition, wsdl4jService);
Definition bindingWSDL = getParentDefinition(wsdl4jDefinition,
binding.getQName(), COMPONENT_BINDING, new HashSet());
- Definition portTypeWSDL = getParentDefinition(bindingWSDL,
- binding.getPortType().getQName(), COMPONENT_PORT_TYPE, new HashSet());
- PortType portType = portTypeWSDL.getPortType(binding.getPortType().getQName());
-
+
+ //do not search for wsdl where port type is defined, this search is depth-first
+ //and might lead to a wsdl where the port is only referenced but undefined
+ //instead look up the port type in the wsdl and only if not found fall back to binding's port type
+ PortType portType = wsdl4jDefinition.getPortType(binding.getPortType().getQName());
+ if (portType == null) {
+ //TODO in case of recursive imports, binding's port type will contain operations with null input message
+ //requires fix for http://sourceforge.net/p/wsdl4j/bugs/39
+ portType = binding.getPortType();
+ }
if (portType == null) {
throw new AxisFault("There is no port type associated with the binding");
@@ -361,7 +367,7 @@ public class WSDL11ToAxisServiceBuilder
addDocumentation(axisService, documentationElement);
axisService.setName(wsdl4jService.getQName().getLocalPart());
- populateEndpoints(binding, bindingWSDL,wsdl4jService, portType, portTypeWSDL);
+ populateEndpoints(binding, bindingWSDL,wsdl4jService, portType);
processPoliciesInDefintion(wsdl4jDefinition);
axisService.getPolicyInclude().setPolicyRegistry(registry);
@@ -457,8 +463,7 @@ public class WSDL11ToAxisServiceBuilder
private void populateEndpoints(Binding binding,
Definition bindingWSDL,
Service wsdl4jService,
- PortType portType,
- Definition portTypeWSDL) throws AxisFault {
+ PortType portType) throws AxisFault {
Map wsdl4jPorts = wsdl4jService.getPorts();
QName bindingName = binding.getQName();
@@ -471,7 +476,7 @@ public class WSDL11ToAxisServiceBuilder
// process the port type for this binding
// although we support multiports they must be belongs to same port type and should have the
// same soap style
- populatePortType(portType, portTypeWSDL);
+ populatePortType(portType);
Binding currentBinding;
Definition currentBindingWSDL = null;
@@ -492,12 +497,12 @@ public class WSDL11ToAxisServiceBuilder
if (axisService.getEndpointName() == null &&
bindingName.equals(port.getBinding().getQName())) {
populateEndpoint(axisEndpoint, port, currentBinding,
- bindingWSDL, portType, portTypeWSDL, true);
+ bindingWSDL, portType, true);
axisService.setEndpointName(axisEndpoint.getName());
axisService.setBindingName(axisEndpoint.getBinding().getName().getLocalPart());
} else {
populateEndpoint(axisEndpoint, port, currentBinding,
- bindingWSDL, portType, portTypeWSDL, false);
+ bindingWSDL, portType, false);
}
axisEndpoint.setParent(axisService);
@@ -523,7 +528,6 @@ public class WSDL11ToAxisServiceBuilder
Binding wsdl4jBinding,
Definition bindingWSDL,
PortType portType,
- Definition portTypeWSDL,
boolean isSetMessageQNames)
throws AxisFault {
@@ -544,7 +548,6 @@ public class WSDL11ToAxisServiceBuilder
wsdl4jBinding,
bindingWSDL,
portType,
- portTypeWSDL,
isSetMessageQNames);
processedBindings.put(wsdl4jBinding.getQName(), axisBinding);
}
@@ -578,8 +581,7 @@ public class WSDL11ToAxisServiceBuilder
}
}
- private void populatePortType(PortType wsdl4jPortType,
- Definition portTypeWSDL) throws AxisFault {
+ private void populatePortType(PortType wsdl4jPortType) throws AxisFault {
copyExtensionAttributes(wsdl4jPortType.getExtensionAttributes(),
axisService, PORT_TYPE);
List wsdl4jOperations = wsdl4jPortType.getOperations();
@@ -600,7 +602,7 @@ public class WSDL11ToAxisServiceBuilder
for (Iterator iterator = wsdl4jOperations.iterator(); iterator.hasNext();) {
wsdl4jOperation = (Operation) iterator.next();
- axisOperation = populateOperations(wsdl4jOperation, wsdl4jPortType, portTypeWSDL);
+ axisOperation = populateOperations(wsdl4jOperation, wsdl4jPortType);
addDocumentation(axisOperation, wsdl4jOperation.getDocumentationElement());
if (wsdl4jOperation.getInput() != null) {
addMessageDocumentation(axisOperation, wsdl4jOperation.getInput().getDocumentationElement(), WSDLConstants.MESSAGE_LABEL_IN_VALUE);
@@ -645,7 +647,6 @@ public class WSDL11ToAxisServiceBuilder
Binding wsdl4jBinding,
Definition bindingWSDL,
PortType portType,
- Definition portTypeWSDL,
boolean isSetMessageQNames)
throws AxisFault {
@@ -678,7 +679,7 @@ public class WSDL11ToAxisServiceBuilder
axisBindingOperation.setName(new QName(bindingWSDL.getTargetNamespace(), wsdl4jBindingOperation.getName()));
addDocumentation(axisBindingOperation, wsdl4jBindingOperation.getDocumentationElement());
- axisOperation = axisService.getOperation(new QName(portTypeWSDL.getTargetNamespace(), wsdl4jOperation.getName()));
+ axisOperation = axisService.getOperation(new QName(portType.getQName().getNamespaceURI(), wsdl4jOperation.getName()));
axisBindingOperation.setAxisOperation(axisOperation);
// process ExtensibilityElements of the wsdl4jBinding
@@ -1406,9 +1407,9 @@ public class WSDL11ToAxisServiceBuilder
* @throws AxisFault
*/
private AxisOperation populateOperations(Operation wsdl4jOperation,
- PortType wsdl4jPortType, Definition dif)
+ PortType wsdl4jPortType)
throws AxisFault {
- QName opName = new QName(dif.getTargetNamespace(), wsdl4jOperation.getName());
+ QName opName = new QName(wsdl4jPortType.getQName().getNamespaceURI(), wsdl4jOperation.getName());
// Copy Name Attribute
AxisOperation axisOperation = axisService.getOperation(opName);
if (axisOperation == null) {
@@ -1444,7 +1445,7 @@ public class WSDL11ToAxisServiceBuilder
String action = null;
if (inputActions == null || inputActions.size() == 0) {
action = WSDL11ActionHelper
- .getActionFromInputElement(dif, wsdl4jPortType,
+ .getActionFromInputElement(wsdl4jDefinition, wsdl4jPortType,
wsdl4jOperation, wsdl4jInputMessage);
}
if (action != null) {
@@ -1475,7 +1476,7 @@ public class WSDL11ToAxisServiceBuilder
// with the Default Action Pattern
String action = axisOperation.getOutputAction();
if (action == null) {
- action = WSDL11ActionHelper.getActionFromOutputElement(dif,
+ action = WSDL11ActionHelper.getActionFromOutputElement(wsdl4jDefinition,
wsdl4jPortType,
wsdl4jOperation,
wsdl4jOutputMessage);
@@ -1507,7 +1508,7 @@ public class WSDL11ToAxisServiceBuilder
String action = axisOperation.getOutputAction();
if (action == null) {
action = WSDL11ActionHelper
- .getActionFromInputElement(dif, wsdl4jPortType,
+ .getActionFromInputElement(wsdl4jDefinition, wsdl4jPortType,
wsdl4jOperation, wsdl4jInputMessage);
}
if (action != null) {
@@ -1534,7 +1535,7 @@ public class WSDL11ToAxisServiceBuilder
ArrayList inputActions = axisOperation.getWSAMappingList();
String action = null;
if (inputActions == null || inputActions.size() == 0) {
- action = WSDL11ActionHelper.getActionFromOutputElement(dif,
+ action = WSDL11ActionHelper.getActionFromOutputElement(wsdl4jDefinition,
wsdl4jPortType,
wsdl4jOperation,
wsdl4jOutputMessage);
@@ -1563,7 +1564,7 @@ public class WSDL11ToAxisServiceBuilder
.setName(faultMessage.getQName().getLocalPart());
copyExtensibleElements(faultMessage.getExtensibilityElements(),
- dif, axisFaultMessage, PORT_TYPE_OPERATION_FAULT);
+ wsdl4jDefinition, axisFaultMessage, PORT_TYPE_OPERATION_FAULT);
}
@@ -1572,7 +1573,7 @@ public class WSDL11ToAxisServiceBuilder
// with the Default Action Pattern
String action = axisOperation.getFaultAction(fault.getName());
if (action == null) {
- action = WSDL11ActionHelper.getActionFromFaultElement(dif,
+ action = WSDL11ActionHelper.getActionFromFaultElement(wsdl4jDefinition,
wsdl4jPortType,
wsdl4jOperation, fault);
}
@@ -1593,7 +1594,7 @@ public class WSDL11ToAxisServiceBuilder
String faultAction = axisOperation.getFaultAction(exceptionClassName);
if (faultAction == null) {
- faultAction = WSDL11ActionHelper.getActionFromFaultElement(dif,
+ faultAction = WSDL11ActionHelper.getActionFromFaultElement(wsdl4jDefinition,
wsdl4jPortType,
wsdl4jOperation, fault);
if (log.isDebugEnabled()) {
Modified: axis/axis2/java/core/branches/1_7/modules/kernel/test/org/apache/axis2/description/WSDL11ToAxisServiceBuilderTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_7/modules/kernel/test/org/apache/axis2/description/WSDL11ToAxisServiceBuilderTest.java?rev=1730359&r1=1730358&r2=1730359&view=diff
==============================================================================
--- axis/axis2/java/core/branches/1_7/modules/kernel/test/org/apache/axis2/description/WSDL11ToAxisServiceBuilderTest.java (original)
+++ axis/axis2/java/core/branches/1_7/modules/kernel/test/org/apache/axis2/description/WSDL11ToAxisServiceBuilderTest.java Sun Feb 14 17:12:36 2016
@@ -23,11 +23,16 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import javax.wsdl.xml.WSDLLocator;
import javax.xml.namespace.QName;
import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.xml.sax.InputSource;
import junit.framework.TestCase;
@@ -113,4 +118,170 @@ public class WSDL11ToAxisServiceBuilderT
checkOperationActions(service, operation, expectedInputAction,expectedOutputAction,expectedFaultAction);
}
}
+
+ /**
+ * Tests parsing of <code>EchoService.wsdl</code> into an AxisService instance. The <code>EchoService.wsdl</code>
+ * imports <code>EchoBindings.wsdl</code>, which contains the binding definitions (note that it does not reverse-import the EchoService.wsdl).
+ * Parsing the wsdl should cause neither a "There is no port type associated with the binding" exception, nor a "Cannot determine the MEP" exception,
+ * provided that Axis2 does not recursively search the port type in all imported wsdls, but looks it up via {@link javax.wsdl.Definition#getPortType(QName)},
+ * falling back to {@link javax.wsdl.Binding#getPortType()} if not available (will be the case when port type is imported through another document but not directly)
+ *
+ * The test verifies that no exceptions are thrown and additionally checks that the endpoint, binding, operation and its in/out messages are correctly populated from the WSDL definition.
+ * @throws IOException
+ */
+ public void testImportedBindings() throws IOException {
+ AxisConfiguration axisConf = new AxisConfiguration();
+ WSDLLocator wsdlLocator = new CustomWSDLLocator("test-resources/wsdl/imports/binding/", "EchoService.wsdl");
+ AxisService service = populateAxisService(axisConf, new File(wsdlLocator.getBaseURI()), wsdlLocator);
+ assertValidEchoService(service, wsdlLocator);
+ }
+
+ /**
+ * Tests parsing of <code>EchoService.wsdl</code> into an AxisService instance. The <code>EchoService.wsdl</code>
+ * imports <code>EchoBindings.wsdl</code>, which reverse-imports the EchoService.wsdl (i.e. we have a circular import).
+ * Parsing the wsdl should cause neither a "There is no port type associated with the binding" exception, nor a "Cannot determine the MEP" exception,
+ * provided that Axis2 does not recursively search the port type in all imported wsdls, but looks it up via {@link javax.wsdl.Definition#getPortType(QName)},
+ * falling back to {@link javax.wsdl.Binding#getPortType()} if not available (will be the case when port type is imported through another document but not directly)
+ *
+ * The test verifies that no exceptions are thrown and additionally checks that the endpoint, binding, operation and its in/out messages are correctly populated from the WSDL definition.
+ * @throws IOException
+ */
+ public void testCircularImportedBindings() throws IOException {
+ AxisConfiguration axisConf = new AxisConfiguration();
+ WSDLLocator wsdlLocator = new CustomWSDLLocator("test-resources/wsdl/imports/binding_recursive/", "EchoService.wsdl");
+ AxisService service = populateAxisService(axisConf, new File(wsdlLocator.getBaseURI()), wsdlLocator);
+ assertValidEchoService(service, wsdlLocator);
+ }
+
+ /**
+ * Tests parsing of <code>EchoService.wsdl</code> into an AxisService instance. The <code>EchoService.wsdl</code>
+ * imports <code>EchoBindings.wsdl</code>, which in turn imports the <code>EchoPortType.wsdl</code>.
+ * Parsing the wsdl should cause neither a "There is no port type associated with the binding" exception, nor a "Cannot determine the MEP" exception,
+ * provided that Axis2 does not recursively search the port type in all imported wsdls, but looks it up via {@link javax.wsdl.Definition#getPortType(QName)},
+ * falling back to {@link javax.wsdl.Binding#getPortType()} if not available (will be the case when port type is imported through another document but not directly)
+ *
+ * The test verifies that no exceptions are thrown and additionally checks that the endpoint, binding, operation and its in/out messages are correctly populated from the WSDL definition.
+ * @throws IOException
+ */
+ public void testImportedPortType() throws IOException {
+ AxisConfiguration axisConf = new AxisConfiguration();
+ WSDLLocator wsdlLocator = new CustomWSDLLocator("test-resources/wsdl/imports/portType/", "EchoService.wsdl");
+ AxisService service = populateAxisService(axisConf, new File(wsdlLocator.getBaseURI()), wsdlLocator);
+ assertValidEchoService(service, wsdlLocator);
+ }
+
+ private void assertValidEchoService(AxisService echoService, WSDLLocator wsdlLocator) {
+ //check soap12 endpoint and binding are available
+ String endpointName = "EchoServiceHttpSoap12Endpoint";
+ AxisEndpoint soap12Endpoint = echoService.getEndpoint(endpointName);
+ assertNotNull(String.format("Cannot find %s endpoint in wsdl definition: %s", endpointName, wsdlLocator.getBaseURI()), soap12Endpoint);
+
+ AxisBinding soap12Binding = soap12Endpoint.getBinding();
+ assertNotNull(String.format("Binding not set on %s endpoint in wsdl definition: %s", endpointName, wsdlLocator.getBaseURI()), soap12Binding);
+
+ //check that policy reference is present on the binding subject
+ String bindingPolicyRefId = "#basicAuthPolicy";
+ assertNotNull(String.format("Cannot find policy reference %s on binding %s", bindingPolicyRefId, soap12Binding.getName()),
+ soap12Binding.getPolicySubject().getAttachedPolicyComponent(bindingPolicyRefId));
+
+ //check that binding operation and respective operation are available
+ QName echoBindingOpName = new QName("http://tempuri.org/bindings", "echo");
+ AxisBindingOperation echoBindingOp = (AxisBindingOperation) soap12Binding.getChild(echoBindingOpName);
+ assertNotNull(String.format("Cannot find %s binding operation on binding %s", echoBindingOpName, soap12Binding), echoBindingOp);
+
+ AxisOperation echoOp = echoBindingOp.getAxisOperation();
+ assertNotNull(String.format("Operation not set on binding operation %s", echoBindingOp.getName()), echoOp);
+
+ //check that operation style is correctly identified and an operation with respective mep is created
+ assertTrue(String.format("Operation %s is not an instance of %s", echoOp.getName(), InOutAxisOperation.class.getName()), echoOp instanceof InOutAxisOperation);
+ assertEquals(String.format("Operation %s specifies an unexpected MEP uri: %s", echoOp.getName(), echoOp.getMessageExchangePattern()),
+ WSDL2Constants.MEP_URI_IN_OUT, echoOp.getMessageExchangePattern());
+
+ //check in/out messages
+ AxisMessage inMessage = echoOp.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+ assertNotNull(String.format("No input message set on operation %s", echoOp.getName()), inMessage);
+ QName echoInMessageName = new QName("http://tempuri.org/types", "echo");
+ assertEquals(String.format("Unexpected input message QName set on operation %s", echoOp.getName()), echoInMessageName, inMessage.getElementQName());
+ //message name is 'echoRequest' whereas the QName's local name is simply 'echo'
+ assertEquals(String.format("Unexpected input message name set on operation %s", echoOp.getName()), "echoRequest", inMessage.getName());
+
+ AxisMessage outMessage = echoOp.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
+ assertNotNull(String.format("No output message set on operation %s", echoOp.getName()), outMessage);
+ QName echoOutMessageName = new QName("http://tempuri.org/types", "echoResponse");
+ assertEquals(String.format("Unexpected output message QName set on operation %s", echoOp.getName()), echoOutMessageName, outMessage.getElementQName());
+ assertEquals(String.format("Unexpected output message name set on operation %s", echoOp.getName()), echoOutMessageName.getLocalPart(), outMessage.getName());
+ }
+
+ private AxisService populateAxisService(AxisConfiguration axisConf, File wsdlFile, WSDLLocator wsdlLocator) throws IOException {
+ InputStream in = null;
+ try {
+ in = new FileInputStream(wsdlFile);
+ WSDL11ToAxisServiceBuilder wsdl11Builder = new WSDL11ToAxisServiceBuilder(in);
+ if (wsdlLocator != null) {
+ wsdl11Builder.setCustomWSDLResolver(wsdlLocator);
+ }
+ wsdl11Builder.setDocumentBaseUri(wsdlFile.getParentFile().toURI().toString());
+ if (axisConf != null) {
+ wsdl11Builder.useAxisConfiguration(axisConf);
+ }
+ AxisService service = wsdl11Builder.populateService();
+ assertNotNull("Could not load AxisService from wsdl: " + wsdlFile.getAbsolutePath(), service);
+
+ return service;
+ } finally {
+ if (in != null) {
+ in.close();
+ }
+ }
+ }
+
+ //custom locator that can located imported wsdls relative to the base wsdl uri (code borrowed from wsdl4j)
+ class CustomWSDLLocator implements WSDLLocator {
+ private String wsdlURI;
+
+ private InputSource baseInputSource;
+ private Map<String, InputSource> importInputSources = new HashMap<String, InputSource>();
+ private boolean closed = false;
+ private String baseURI;
+ private String lastImportURI;
+
+ public CustomWSDLLocator(String baseURI, String wsdlURI) {
+ this.baseURI = baseURI;
+ this.wsdlURI = wsdlURI;
+ }
+
+ public InputSource getBaseInputSource() {
+ if (baseInputSource == null) {
+ lastImportURI = baseURI + wsdlURI;
+ baseInputSource = new InputSource(lastImportURI);
+ }
+ return baseInputSource;
+ }
+
+ public InputSource getImportInputSource(String parentLocation, String importLocation) {
+ InputSource inSource = (InputSource) importInputSources.get(importLocation);
+ if (inSource == null) {
+ lastImportURI = baseURI + importLocation;
+ inSource = new InputSource(lastImportURI);
+ importInputSources.put(importLocation, inSource);
+ }
+ return inSource;
+ }
+
+ public String getBaseURI() {
+ return baseURI + wsdlURI;
+ }
+
+ public String getLatestImportURI() {
+ return lastImportURI;
+ }
+
+ public void close() {
+ closed = true;
+ }
+
+ public boolean isClosed() {
+ return closed;
+ }
+ }
}