Author: veithen Date: Tue Oct 13 19:31:46 2015 New Revision: 1708491 URL: http://svn.apache.org/viewvc?rev=1708491&view=rev Log: Configure SOAP version from WSDL.
Added: webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/WSDLUtil.java (with props) webservices/axiom/experimental/axiom-spring-integration/src/test/resources/log4j2-test.xml (with props) Modified: webservices/axiom/experimental/axiom-spring-integration/pom.xml webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/WebServiceOutboundGateway.java webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/config/WebServiceOutboundGatewayParser.java webservices/axiom/experimental/axiom-spring-integration/src/main/resources/org/apache/axiom/spring/integration/config/schema.xsd webservices/axiom/experimental/axiom-spring-integration/src/test/resources/org/apache/axiom/spring/integration/mtom-client-context.xml Modified: webservices/axiom/experimental/axiom-spring-integration/pom.xml URL: http://svn.apache.org/viewvc/webservices/axiom/experimental/axiom-spring-integration/pom.xml?rev=1708491&r1=1708490&r2=1708491&view=diff ============================================================================== --- webservices/axiom/experimental/axiom-spring-integration/pom.xml (original) +++ webservices/axiom/experimental/axiom-spring-integration/pom.xml Tue Oct 13 19:31:46 2015 @@ -50,6 +50,11 @@ <scope>runtime</scope> </dependency> <dependency> + <groupId>wsdl4j</groupId> + <artifactId>wsdl4j</artifactId> + <version>1.6.3</version> + </dependency> + <dependency> <groupId>com.google.truth</groupId> <artifactId>truth</artifactId> <scope>test</scope> @@ -75,6 +80,16 @@ <artifactId>cxf-rt-transports-http-jetty</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-jcl</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <scope>test</scope> + </dependency> </dependencies> <build> Added: webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/WSDLUtil.java URL: http://svn.apache.org/viewvc/webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/WSDLUtil.java?rev=1708491&view=auto ============================================================================== --- webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/WSDLUtil.java (added) +++ webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/WSDLUtil.java Tue Oct 13 19:31:46 2015 @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.axiom.spring.integration; + +import java.util.Arrays; +import java.util.List; + +import javax.wsdl.extensions.ElementExtensible; +import javax.wsdl.extensions.ExtensibilityElement; + +final class WSDLUtil { + private WSDLUtil() {} + + static ExtensibilityElement getExtensibilityElement(ElementExtensible element, Class<? extends ExtensibilityElement>... types) { + @SuppressWarnings("unchecked") + List<ExtensibilityElement> extensions = element.getExtensibilityElements(); + ExtensibilityElement extension = null; + for (ExtensibilityElement candidate : extensions) { + for (Class<? extends ExtensibilityElement> type : types) { + if (type.isInstance(candidate)) { + if (extension == null) { + extension = type.cast(candidate); + } else { + throw new IllegalArgumentException("Found multiple extensions matching " + Arrays.asList(types)); + } + break; + } + } + } + return extension; + } +} Propchange: webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/WSDLUtil.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/WebServiceOutboundGateway.java URL: http://svn.apache.org/viewvc/webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/WebServiceOutboundGateway.java?rev=1708491&r1=1708490&r2=1708491&view=diff ============================================================================== --- webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/WebServiceOutboundGateway.java (original) +++ webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/WebServiceOutboundGateway.java Tue Oct 13 19:31:46 2015 @@ -23,7 +23,17 @@ import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.text.ParseException; +import java.util.Map; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap12.SOAP12Binding; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.transform.stax.StAXSource; @@ -35,11 +45,15 @@ import org.apache.axiom.om.OMAbstractFac import org.apache.axiom.om.OMMetaFactory; import org.apache.axiom.om.OMOutputFormat; import org.apache.axiom.om.OMXMLBuilderFactory; +import org.apache.axiom.soap.SOAP11Version; import org.apache.axiom.soap.SOAPFactory; import org.apache.axiom.soap.SOAPMessage; import org.apache.axiom.soap.SOAPModelBuilder; import org.apache.axiom.util.stax.xop.XOPEncodedStream; import org.apache.axiom.util.stax.xop.XOPUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.core.io.Resource; import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; import org.springframework.messaging.Message; import org.springframework.messaging.MessageDeliveryException; @@ -48,27 +62,55 @@ import org.springframework.oxm.Unmarshal import org.springframework.oxm.mime.MimeContainer; import org.springframework.oxm.mime.MimeMarshaller; import org.springframework.oxm.mime.MimeUnmarshaller; +import org.springframework.util.Assert; public final class WebServiceOutboundGateway extends AbstractReplyProducingMessageHandler { + private static final Log log = LogFactory.getLog(WebServiceOutboundGateway.class); + private final OMMetaFactory metaFactory = OMAbstractFactory.getMetaFactory(); - private boolean useSOAP12; // TODO: find better convention private final URL url; + private final Resource wsdlResource; private final Marshaller marshaller; private final Unmarshaller unmarshaller; private SOAPFactory soapFactory; - public WebServiceOutboundGateway(URL url, Marshaller marshaller, Unmarshaller unmarshaller) { + public WebServiceOutboundGateway(URL url, Resource wsdlResource, Marshaller marshaller, Unmarshaller unmarshaller) { this.url = url; + this.wsdlResource = wsdlResource; this.marshaller = marshaller; this.unmarshaller = unmarshaller; } - public void setUseSOAP12(boolean useSOAP12) { - this.useSOAP12 = useSOAP12; - } @Override protected void doInit() { - soapFactory = useSOAP12 ? metaFactory.getSOAP12Factory() : metaFactory.getSOAP11Factory(); + try { + WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); + Definition definition = wsdlReader.readWSDL(wsdlResource.getURL().toString()); + Binding binding; + @SuppressWarnings("unchecked") + Map<QName,Binding> bindings = definition.getAllBindings(); + if (bindings.size() == 1) { + binding = bindings.values().iterator().next(); + } else { + // TODO + throw new Error(); + } + if (log.isDebugEnabled()) { + log.debug("Using binding " + binding.getQName()); + } + ExtensibilityElement soapBinding = WSDLUtil.getExtensibilityElement(binding, SOAPBinding.class, SOAP12Binding.class); + Assert.notNull(soapBinding, "No suitable SOAP binding found"); + if (soapBinding instanceof SOAPBinding) { + log.debug("Using SOAP 1.1"); + soapFactory = metaFactory.getSOAP11Factory(); + } else { + log.debug("Using SOAP 1.2"); + soapFactory = metaFactory.getSOAP12Factory(); + } + } catch (WSDLException | IOException ex) { + // TODO + throw new RuntimeException(ex); + } } @Override @@ -77,7 +119,7 @@ public final class WebServiceOutboundGat soapMessage.getSOAPEnvelope().getBody().addChild(soapFactory.createOMElement( new MarshallerOMDataSource(marshaller, requestMessage.getPayload()))); OMOutputFormat format = new OMOutputFormat(); - format.setSOAP11(!useSOAP12); + format.setSOAP11(soapFactory.getSOAPVersion() == SOAP11Version.getSingleton()); try { HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setDoOutput(true); Modified: webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/config/WebServiceOutboundGatewayParser.java URL: http://svn.apache.org/viewvc/webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/config/WebServiceOutboundGatewayParser.java?rev=1708491&r1=1708490&r2=1708491&view=diff ============================================================================== --- webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/config/WebServiceOutboundGatewayParser.java (original) +++ webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/config/WebServiceOutboundGatewayParser.java Tue Oct 13 19:31:46 2015 @@ -32,6 +32,7 @@ public final class WebServiceOutboundGat @Override protected void postProcessGateway(BeanDefinitionBuilder builder, Element element, ParserContext parserContext) { + builder.addConstructorArgValue(element.getAttribute("wsdl")); builder.addConstructorArgReference(element.getAttribute("marshaller")); builder.addConstructorArgReference(element.getAttribute("unmarshaller")); } Modified: webservices/axiom/experimental/axiom-spring-integration/src/main/resources/org/apache/axiom/spring/integration/config/schema.xsd URL: http://svn.apache.org/viewvc/webservices/axiom/experimental/axiom-spring-integration/src/main/resources/org/apache/axiom/spring/integration/config/schema.xsd?rev=1708491&r1=1708490&r2=1708491&view=diff ============================================================================== --- webservices/axiom/experimental/axiom-spring-integration/src/main/resources/org/apache/axiom/spring/integration/config/schema.xsd (original) +++ webservices/axiom/experimental/axiom-spring-integration/src/main/resources/org/apache/axiom/spring/integration/config/schema.xsd Tue Oct 13 19:31:46 2015 @@ -39,6 +39,11 @@ <xsd:documentation>The Destination URL for this Web Service Gateway.</xsd:documentation> </xsd:annotation> </xsd:attribute> + <xsd:attribute name="wsdl" type="xsd:string" use="required"> + <xsd:annotation> + <xsd:documentation>The location of the WSDL.</xsd:documentation> + </xsd:annotation> + </xsd:attribute> <xsd:attribute name="marshaller" type="xsd:string" use="required"> <xsd:annotation> <xsd:documentation>Reference to a Spring OXM Mashaller.</xsd:documentation> Added: webservices/axiom/experimental/axiom-spring-integration/src/test/resources/log4j2-test.xml URL: http://svn.apache.org/viewvc/webservices/axiom/experimental/axiom-spring-integration/src/test/resources/log4j2-test.xml?rev=1708491&view=auto ============================================================================== --- webservices/axiom/experimental/axiom-spring-integration/src/test/resources/log4j2-test.xml (added) +++ webservices/axiom/experimental/axiom-spring-integration/src/test/resources/log4j2-test.xml Tue Oct 13 19:31:46 2015 @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you 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. + --> +<Configuration> + <Appenders> + <Console name="stdout" target="SYSTEM_OUT"> + <PatternLayout pattern="%-6r %-5p %-8t [%c{1}] %m%n"/> + </Console> + </Appenders> + <Loggers> + <Logger name="org.apache.axiom" level="debug"/> + <Logger name="org.springframework.ws" level="warn"/> + <Root level="warn"> + <AppenderRef ref="stdout"/> + </Root> + </Loggers> +</Configuration> \ No newline at end of file Propchange: webservices/axiom/experimental/axiom-spring-integration/src/test/resources/log4j2-test.xml ------------------------------------------------------------------------------ svn:eol-style = native Modified: webservices/axiom/experimental/axiom-spring-integration/src/test/resources/org/apache/axiom/spring/integration/mtom-client-context.xml URL: http://svn.apache.org/viewvc/webservices/axiom/experimental/axiom-spring-integration/src/test/resources/org/apache/axiom/spring/integration/mtom-client-context.xml?rev=1708491&r1=1708490&r2=1708491&view=diff ============================================================================== --- webservices/axiom/experimental/axiom-spring-integration/src/test/resources/org/apache/axiom/spring/integration/mtom-client-context.xml (original) +++ webservices/axiom/experimental/axiom-spring-integration/src/test/resources/org/apache/axiom/spring/integration/mtom-client-context.xml Tue Oct 13 19:31:46 2015 @@ -38,6 +38,6 @@ </property> <property name="mtomEnabled" value="true"/> </bean> - <axiom:ws-outbound-gateway request-channel="request" url="http://localhost:${port}/mtom" + <axiom:ws-outbound-gateway request-channel="request" wsdl="http://localhost:${port}/mtom?wsdl" url="http://localhost:${port}/mtom" marshaller="marshaller" unmarshaller="marshaller"/> </beans>