summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws')
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/LICENSE205
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/META-INF/MANIFEST.MF56
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/NOTICE6
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/pom.xml177
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingInvoker.java702
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingProvider.java329
6 files changed, 1475 insertions, 0 deletions
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/LICENSE b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
+
+
+
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/META-INF/MANIFEST.MF b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..b5862eff58
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/META-INF/MANIFEST.MF
@@ -0,0 +1,56 @@
+Manifest-Version: 1.0
+Tool: Bnd-0.0.255
+Bundle-Name: Apache Tuscany SCA JAXWS-based WS Binding Extension
+Created-By: 1.6.0_07 (Sun Microsystems Inc.)
+Bundle-Vendor: The Apache Software Foundation
+Bundle-Version: 2.0.0
+Bnd-LastModified: 1225397353000
+Bundle-ManifestVersion: 2
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Bundle-Description: Apache Tuscany SCA JAXWS-based WS Binding Extensio
+ n
+Import-Package: javax.security.auth.callback;resolution:=optional,
+ javax.servlet,
+ javax.servlet.http,
+ javax.wsdl,
+ javax.wsdl.extensions,
+ javax.wsdl.extensions.soap,
+ javax.wsdl.extensions.soap12,
+ javax.wsdl.factory;resolution:=optional,
+ javax.wsdl.xml;resolution:=optional,
+ javax.xml.namespace,
+ javax.xml.soap,
+ javax.xml.stream,
+ javax.xml.transform,
+ javax.xml.transform.dom,
+ javax.xml.ws,
+ org.apache.tuscany.sca.assembly;version="2.0.0",
+ org.apache.tuscany.sca.binding.ws;version="2.0.0",
+ org.apache.tuscany.sca.contribution.processor;version="2.0.0",
+ org.apache.tuscany.sca.core;version="2.0.0",
+ org.apache.tuscany.sca.core.assembly;version="2.0.0",
+ org.apache.tuscany.sca.core.invocation;version="2.0.0",
+ org.apache.tuscany.sca.databinding;version="2.0.0",
+ org.apache.tuscany.sca.definitions;version="2.0.0",
+ org.apache.tuscany.sca.host.http;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.java;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.util;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.wsdl;version="2.0.0",
+ org.apache.tuscany.sca.invocation;version="2.0.0",
+ org.apache.tuscany.sca.policy;version="2.0.0",
+ org.apache.tuscany.sca.policy.authentication.basic;version="2.0.0",
+ org.apache.tuscany.sca.policy.security;version="2.0.0",
+ org.apache.tuscany.sca.policy.util;version="2.0.0",
+ org.apache.tuscany.sca.provider;version="2.0.0",
+ org.apache.tuscany.sca.runtime;version="2.0.0",
+ org.apache.tuscany.sca.xsd;version="2.0.0",
+ org.apache.tuscany.sca.xsd.xml;version="2.0.0",
+ org.oasisopen.sca;version="2.0.0",
+ org.oasisopen.sca.annotation;version="2.0.0";resolution:=optional,
+ org.w3c.dom,
+ org.xml.sax
+Bundle-SymbolicName: org.apache.tuscany.sca.binding.ws.jaxws
+Bundle-DocURL: http://www.apache.org/
+Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6
+Export-Package: org.apache.tuscany.sca.binding.ws.jaxws;version="2.0.0"
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/NOTICE b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/NOTICE
new file mode 100644
index 0000000000..4dc9c94cd5
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2013 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/pom.xml b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/pom.xml
new file mode 100644
index 0000000000..035badb798
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/pom.xml
@@ -0,0 +1,177 @@
+<?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.
+-->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>2.0.1</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>tuscany-binding-ws-runtime-jaxws</artifactId>
+ <name>Apache Tuscany SCA JAXWS-based WS Binding Extension</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core</artifactId>
+ <version>2.0.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-interface-wsdl</artifactId>
+ <version>2.0.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly-xml</artifactId>
+ <version>2.0.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-binding-ws</artifactId>
+ <version>2.0.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-binding-ws-wsdlgen</artifactId>
+ <version>2.0.1</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core-databinding</artifactId>
+ <version>2.0.1</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-databinding-jaxb</artifactId>
+ <version>2.0.1</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-databinding</artifactId>
+ <version>2.0.1</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-interface-java-jaxws</artifactId>
+ <version>2.0.1</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-xsd</artifactId>
+ <version>2.0.1</version>
+ </dependency>
+
+ <!-- Test dependencies -->
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-node-impl</artifactId>
+ <version>2.0.1</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-implementation-java-runtime</artifactId>
+ <version>2.0.1</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <!--
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.0</version>
+ <executions>
+ <execution>
+ <id>add-source</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-test-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>target/jaxws-source</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.jvnet.jax-ws-commons</groupId>
+ <artifactId>jaxws-maven-plugin</artifactId>
+ <version>2.1</version>
+ <dependencies>
+ <dependency>
+ <groupId>com.sun.xml.ws</groupId>
+ <artifactId>jaxws-tools</artifactId>
+ <version>2.2.6-promoted-b10</version>
+ </dependency>
+ </dependencies>
+ <executions>
+ <execution>
+ <id>wsimport</id>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>wsimport</goal>
+ </goals>
+ <configuration>
+ <packageName>com.example.weather</packageName>
+ <wsdlDirectory>${basedir}/src/test/resources/wsdl</wsdlDirectory>
+ <wsdlFiles>
+ <wsdlFile>WeatherForecast.wsdl</wsdlFile>
+ </wsdlFiles>
+ </configuration>
+ </execution>
+ </executions>
+ <configuration>
+ <target>2.1</target>
+ <sourceDestDir>${project.build.directory}/jaxws-source</sourceDestDir>
+ <verbose>false</verbose>
+ <xnocompile>true</xnocompile>
+ </configuration>
+ </plugin>
+-->
+ </plugins>
+ </build>
+
+
+</project>
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingInvoker.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingInvoker.java
new file mode 100644
index 0000000000..5d6b3aeb64
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingInvoker.java
@@ -0,0 +1,702 @@
+/*
+ * 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.tuscany.sca.binding.ws.jaxws;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.UUID;
+
+import javax.wsdl.Binding;
+import javax.wsdl.BindingOperation;
+import javax.wsdl.Definition;
+import javax.wsdl.Input;
+import javax.wsdl.OperationType;
+import javax.wsdl.PortType;
+import javax.wsdl.extensions.AttributeExtensible;
+import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.wsdl.extensions.soap.SOAPOperation;
+import javax.wsdl.extensions.soap12.SOAP12Address;
+import javax.wsdl.extensions.soap12.SOAP12Operation;
+import javax.xml.namespace.QName;
+import javax.xml.soap.Detail;
+import javax.xml.soap.DetailEntry;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFault;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPHeaderElement;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.SOAPPart;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.WebServiceFeature;
+import javax.xml.ws.soap.SOAPBinding;
+import javax.xml.ws.soap.SOAPFaultException;
+
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.binding.ws.WebServiceBinding;
+import org.apache.tuscany.sca.core.invocation.Constants;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.FaultException;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface;
+import org.apache.tuscany.sca.invocation.DataExchangeSemantics;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+import org.oasisopen.sca.ServiceRuntimeException;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Uses JAXWS Dispatch to invoke a remote web service
+ *
+ * @version $Rev$ $Date$
+ */
+public class JAXWSBindingInvoker implements Invoker, DataExchangeSemantics {
+ private final static String SCA11_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1";
+
+ public static final String WSA_FINAL_NAMESPACE = "http://www.w3.org/2005/08/addressing";
+ public static final QName QNAME_WSA_ADDRESS = new QName(WSA_FINAL_NAMESPACE, "Address", "wsa");
+ public static final QName QNAME_WSA_FROM = new QName(WSA_FINAL_NAMESPACE, "From", "wsa");
+ public static final QName QNAME_WSA_MESSAGEID = new QName(WSA_FINAL_NAMESPACE, "MessageID", "wsa");
+ public static final QName QNAME_WSA_TO = new QName(WSA_FINAL_NAMESPACE, "To", "wsa");
+ public static final QName QNAME_WSA_ACTION = new QName(WSA_FINAL_NAMESPACE, "Action", "wsa");
+ public static final QName QNAME_WSA_RELATESTO = new QName(WSA_FINAL_NAMESPACE, "RelatesTo", "wsa");
+ private static final QName submissionWSAWNS = new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing",
+ QNAME_WSA_ACTION.getLocalPart());
+ private static final QName finalWSANS = new QName("http://www.w3.org/2005/08/addressing",
+ QNAME_WSA_ACTION.getLocalPart());
+ private static final QName finalWSAWNS = new QName("http://www.w3.org/2006/05/addressing/wsdl",
+ QNAME_WSA_ACTION.getLocalPart());
+ private static final QName finalWSAMNS = new QName("http://www.w3.org/2007/05/addressing/metadata",
+ QNAME_WSA_ACTION.getLocalPart());
+
+ public static final String TUSCANY_PREFIX = "tuscany";
+ public static final QName CALLBACK_ID_REFPARM_QN = new QName(SCA11_TUSCANY_NS, "CallbackID", TUSCANY_PREFIX);
+ public static final QName CONVERSATION_ID_REFPARM_QN =
+ new QName(SCA11_TUSCANY_NS, "ConversationID", TUSCANY_PREFIX);
+
+ private boolean dynamicDispatchForCallback = false;
+ protected Dispatch<SOAPMessage> staticDispatch;
+ private MessageFactory messageFactory;
+ private Operation operation;
+ protected WebServiceBinding wsBinding;
+ private RuntimeEndpointReference endpointReference;
+
+ public JAXWSBindingInvoker(Operation operation,
+ WebServiceFeature[] features,
+ MessageFactory messageFactory,
+ WebServiceBinding wsBinding,
+ RuntimeEndpointReference endpointReference) {
+ this.messageFactory = messageFactory;
+ this.operation = operation;
+ this.wsBinding = wsBinding;
+ this.endpointReference = endpointReference;
+
+ if (endpointReference.getReference().isForCallback()) {
+ this.dynamicDispatchForCallback = true;
+ } else {
+ this.staticDispatch = createStaticDispatch();
+ }
+ }
+
+ protected Dispatch<SOAPMessage> createDynamicDispatch() {
+ QName serviceName = wsBinding.getService().getQName();
+ QName portName = new QName(serviceName.getNamespaceURI(), wsBinding.getPort().getName());
+ Service service = Service.create(serviceName);
+ service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointReference.getDeployedURI());
+
+ return service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
+ }
+
+ protected Dispatch<SOAPMessage> createStaticDispatch() {
+ URL wsdlLocation = null;
+ try {
+ if (wsBinding.getGeneratedWSDLDocument() != null && wsBinding.getGeneratedWSDLDocument().getDocumentBaseURI() != null) {
+ wsdlLocation = new URL(wsBinding.getGeneratedWSDLDocument().getDocumentBaseURI());
+ }
+ } catch (Exception e) {
+ // ignore and try getting the location from the other places
+ }
+ try {
+ if (wsBinding.getUserSpecifiedWSDLDefinition().getLocation() != null) {
+ wsdlLocation = wsBinding.getUserSpecifiedWSDLDefinition().getLocation().toURL();
+ }
+ } catch (MalformedURLException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ if (wsdlLocation != null) {
+ return createDispatchFromWSDL(wsdlLocation);
+ } else {
+ return createDispatchFromURI(endpointReference.getDeployedURI());
+ }
+ }
+
+ protected Dispatch<SOAPMessage> createDynamicDispatch(String uri) {
+ return createDispatchFromURI(uri);
+ }
+
+ private Dispatch<SOAPMessage> createDispatchFromWSDL(URL wsdlLocation) {
+ QName serviceName = wsBinding.getServiceName();
+ QName portName = new QName(serviceName.getNamespaceURI(), wsBinding.getPortName());
+ Service service = Service.create(wsdlLocation, serviceName);
+
+ return service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
+ }
+
+ protected Dispatch<SOAPMessage> createDispatchFromURI(String uri) {
+ QName serviceName = wsBinding.getService().getQName();
+ QName portName = new QName(serviceName.getNamespaceURI(), wsBinding.getPort().getName());
+ Service service = Service.create(serviceName);
+ service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, uri);
+
+ return service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
+ }
+
+ public Message invoke(Message msg) {
+ try {
+ SOAPMessage resp = invokeTarget(msg);
+ if (resp != null) {
+ SOAPBody body = resp.getSOAPBody();
+ if (body != null) {
+ SOAPFault fault = body.getFault();
+ if (fault != null) {
+ // setFault(msg, fault);
+ } else {
+ // WS-I uses single-element payload
+ Element payload =(Element)body.getChildElements().next();
+ if (wsBinding.isRpcLiteral()) {
+ Element unwrappedPayload = null;
+ NodeList children = payload.getChildNodes();
+ for (int i = 0; i < children.getLength(); i++) {
+ Node nextChild = children.item(i);
+ if (nextChild instanceof Element) {
+ unwrappedPayload = (Element)nextChild;
+ break;
+ }
+ }
+ msg.setBody(unwrappedPayload);
+ } else {
+ msg.setBody(payload);
+ }
+ }
+ }
+ }
+ } catch (SOAPFaultException e) {
+ setFault(msg, e);
+ } catch (WebServiceException e) {
+ msg.setFaultBody(e);
+ } catch (SOAPException e) {
+ msg.setFaultBody(e);
+ } catch (Throwable e) {
+ msg.setFaultBody(e);
+ }
+
+ return msg;
+ }
+
+ private void setFault(Message msg, SOAPFaultException e) {
+ SOAPFault fault = e.getFault();
+ Detail detail = fault.getDetail();
+ if (detail != null) {
+ for (Iterator i = detail.getDetailEntries(); i.hasNext();) {
+ DetailEntry entry = (DetailEntry)i.next();
+ FaultException fe = new FaultException(e.getMessage(), entry, e);
+ fe.setFaultName(entry.getElementQName());
+ msg.setFaultBody(fe);
+ }
+ } else {
+ msg.setFaultBody(e);
+ }
+ }
+
+ protected String getSOAPAction(String operationName) {
+ Binding binding = wsBinding.getBinding();
+ if (binding != null) {
+ for (Object o : binding.getBindingOperations()) {
+ BindingOperation bop = (BindingOperation)o;
+ if (bop.getName().equalsIgnoreCase(operationName)) {
+ for (Object o2 : bop.getExtensibilityElements()) {
+ if (o2 instanceof SOAPOperation) {
+ return ((SOAPOperation)o2).getSoapActionURI();
+ } else if (o2 instanceof SOAP12Operation) {
+ return ((SOAP12Operation)o2).getSoapActionURI();
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ protected SOAPMessage invokeTarget(Message msg) throws SOAPException {
+ SOAPMessage soapMessage = messageFactory.createMessage();
+ SOAPPart soapPart = soapMessage.getSOAPPart();
+ javax.xml.soap.SOAPEnvelope envelope = soapPart.getEnvelope();
+
+ String action = getSOAPAction(operation.getName());
+
+ setHeaders(envelope.getHeader(), msg, action);
+
+ javax.xml.soap.SOAPBody body = envelope.getBody();
+ Object[] args = (Object[])msg.getBody();
+
+ if (wsBinding.isRpcLiteral()) {
+
+ String wrapperNamespace = null;
+
+ // the rpc style creates a wrapper with a namespace where the namespace is
+ // defined on the wsdl binding operation. If no binding is provided by the
+ // user then default to the namespace of the WSDL itself.
+ if (wsBinding.getBinding() != null){
+ Iterator iter = wsBinding.getBinding().getBindingOperations().iterator();
+ loopend:
+ while(iter.hasNext()){
+ BindingOperation bOp = (BindingOperation)iter.next();
+ if (bOp.getName().equals(msg.getOperation().getName())){
+ for (Object ext : bOp.getBindingInput().getExtensibilityElements()){
+ if (ext instanceof javax.wsdl.extensions.soap.SOAPBody){
+ wrapperNamespace = ((javax.wsdl.extensions.soap.SOAPBody)ext).getNamespaceURI();
+ break loopend;
+ }
+ }
+ }
+ }
+ }
+
+ if (wrapperNamespace == null){
+ wrapperNamespace = wsBinding.getUserSpecifiedWSDLDefinition().getNamespace();
+ }
+
+ Element rpcOperationWrapper = body.getOwnerDocument().createElementNS(wrapperNamespace, msg.getOperation().getName());
+ for (Object arg : args) {
+ Node next = (Node)arg;
+ Node nextImported = body.getOwnerDocument().importNode(next, true);
+ rpcOperationWrapper.appendChild(nextImported);
+ }
+ body.appendChild(rpcOperationWrapper);
+ } else if (wsBinding.isRpcEncoded()) {
+ throw new ServiceRuntimeException("rpc/encoded WSDL style not supported for endpoint reference " + endpointReference);
+ } else if (wsBinding.isDocEncoded()){
+ throw new ServiceRuntimeException("doc/encoded WSDL style not supported for endpoint reference " + endpointReference);
+ } else {
+ // In the unit test the owner doc is null
+ // so explicitly adopt the node instead
+ // body.addDocument(((Node)args[0]).getOwnerDocument());
+ Node msgNode = body.getOwnerDocument().importNode((Node)args[0], true);
+ body.appendChild(msgNode);
+ }
+
+ soapMessage.saveChanges();
+
+ Dispatch<SOAPMessage> invocationDispatch = null;
+
+ //TODO - captured static case as well???
+ if (dynamicDispatchForCallback) {
+ Endpoint ep = msg.getTo();
+ if (ep != null && ep.getBinding() != null) {
+ String address = ep.getDeployedURI();
+ invocationDispatch = createDynamicDispatch(address);
+ } else {
+ throw new ServiceRuntimeException("[BWS20025] Unable to determine destination endpoint for endpoint reference " + endpointReference);
+ }
+ } else {
+ invocationDispatch = staticDispatch;
+ }
+
+ if (operation.isNonBlocking()) {
+ invocationDispatch.invokeOneWay(soapMessage);
+ return null;
+ }
+
+ if (action != null) {
+ invocationDispatch.getRequestContext().put(Dispatch.SOAPACTION_USE_PROPERTY, true);
+ invocationDispatch.getRequestContext().put(Dispatch.SOAPACTION_URI_PROPERTY, action);
+ }
+ SOAPMessage response = invocationDispatch.invoke(soapMessage);
+ return response;
+ }
+
+ protected void setHeaders(SOAPHeader sh, Message msg, String action) throws SOAPException {
+
+ Endpoint callbackEndpoint = msg.getFrom().getCallbackEndpoint();
+
+ // add WS-Addressing header for the invocation of a bidirectional
+ // service
+ // FIXME: is there any way to use the Axis2 addressing support for this?
+ //
+ // IIUC, this 'if (callbackEndpoint != null)' will be true if:
+ // 1) This is a bidirectional interface
+ // AND
+ // 2) We are invoking in the forward direction of the bidirectional interface.
+ //
+ if (callbackEndpoint != null) {
+ // // Load the actual callback endpoint URI into an Axis EPR ready
+ // to form the content of the wsa:From header
+ // EndpointReference fromEPR = new
+ // EndpointReference(callbackEndpoint.getBinding().getURI());
+ //
+ // addWSAFromHeader(sh, fromEPR);
+ SOAPHeaderElement fromH = sh.addHeaderElement(QNAME_WSA_FROM);
+ SOAPElement fromAddress = fromH.addChildElement(QNAME_WSA_ADDRESS);
+ fromAddress.setTextContent(callbackEndpoint.getDeployedURI());
+
+ addWSAActionHeader(sh, action);
+
+ // We need a wsa:MessageId for request-response operation per WS-Addressing core specification,
+ // (and Axis2 will choke if addressing module is enabled.)
+ if (!operation.isNonBlocking()) {
+ String messageId = UUID.randomUUID().toString();
+ SOAPHeaderElement msgIdHeader = sh.addHeaderElement(QNAME_WSA_MESSAGEID);
+ msgIdHeader.setTextContent(messageId);
+ }
+
+ } // end if
+
+ String toAddress = getToAddress(msg);
+ // requestMC.setTo( new EndpointReference(toAddress) );
+
+ // IIUC, this 'if (callbackEndpoint != null)' will be true if:
+ // 1) This is a bidirectional interface
+ // AND
+ // 2) We are invoking in the callback direction of the bidirectional interface.
+ //
+ if (isInvocationForCallback(msg)) {
+ addWSAToHeader(sh, toAddress, msg);
+ addWSARefParms(sh, msg);
+ addWSAActionHeader(sh, action);
+ addWSARelatesTo(sh, msg);
+ } // end if
+
+ }
+
+ private String getToAddress(Message msg) throws ServiceRuntimeException {
+ String address = null;
+
+ // if target endpoint was not specified when this invoker was created,
+ // use dynamically specified target endpoint passed in with the message
+
+ String to = getPortLocation();
+ if (to == null) {
+ Endpoint ep = msg.getTo();
+ if (ep != null && ep.getBinding() != null) {
+ address = ep.getDeployedURI();
+ } else {
+ throw new ServiceRuntimeException(
+ "[BWS20025] Unable to determine destination endpoint for endpoint reference " + endpointReference);
+ }
+ } else {
+ address = to;
+ }
+
+ return address;
+ } // end method getToAddress
+
+ protected String getPortLocation() {
+ String ep = null;
+ if (wsBinding.getPort() != null) {
+ List<?> wsdlPortExtensions = wsBinding.getPort().getExtensibilityElements();
+ for (final Object extension : wsdlPortExtensions) {
+ if (extension instanceof SOAPAddress) {
+ ep = ((SOAPAddress)extension).getLocationURI();
+ break;
+ }
+ if (extension instanceof SOAP12Address) {
+ SOAP12Address address = (SOAP12Address)extension;
+ ep = address.getLocationURI();
+ break;
+ }
+ }
+ }
+ if (ep == null || ep.equals("")) {
+ ep = endpointReference.getDeployedURI();
+ }
+ return ep;
+ }
+
+ // private void addWSAFromHeader( SOAPHeader sh, EndpointReference fromEPR )
+ // throws AxisFault {
+ // OMElement epr = EndpointReferenceHelper.toOM(sh.getOMFactory(),
+ // fromEPR,
+ // QNAME_WSA_FROM,
+ // AddressingConstants.Final.WSA_NAMESPACE);
+ // sh.addChild(epr);
+ //
+ // } // end method addWSAFromHeader
+
+ private static String WS_REF_PARMS = "WS_REFERENCE_PARAMETERS";
+
+ private void addWSAToHeader(SOAPHeader sh, String address, Message msg) throws SOAPException {
+ // Create wsa:To header which is required by ws-addressing spec
+ // OMElement wsaToOM = sh.getOMFactory().createOMElement(QNAME_WSA_TO);
+ // wsaToOM.setText( address );
+ // sh.addChild(wsaToOM);
+ SOAPHeaderElement toH = sh.addHeaderElement(QNAME_WSA_TO);
+ toH.setTextContent(address);
+ } // end method addWSAToHeader
+
+ protected void addWSARefParms(SOAPHeader sh, Message msg) throws SOAPException {
+
+ // Not implemented and so will not pass compliance test BWS_5006.
+
+
+ } // end method addWSARefParms
+
+
+ private void addWSAActionHeader(SOAPHeader sh, String action) throws SOAPException {
+ // Create wsa:Action header which is required by ws-addressing spec
+
+ if (action == null) {
+ PortType portType = ((WSDLInterface)wsBinding.getBindingInterfaceContract().getInterface()).getPortType();
+ javax.wsdl.Operation op = portType.getOperation(operation.getName(), null, null);
+ action = getActionFromInputElement(wsBinding.getGeneratedWSDLDocument(), portType, op, op.getInput());
+ }
+
+ // OMElement actionOM =
+ // sh.getOMFactory().createOMElement(QNAME_WSA_ACTION);
+ // actionOM.setText(action == null ? "" : action);
+ // sh.addChild(actionOM);
+
+ SOAPHeaderElement actionH = sh.addHeaderElement(QNAME_WSA_ACTION);
+ actionH.setTextContent(action == null ? "" : action);
+
+ } // end method addWSAActionHeader
+
+ protected static String SCA_CALLBACK_REL = "http://docs.oasis-open.org/opencsa/sca-bindings/ws/callback";
+
+ /**
+ * Adds a wsa:RelatesTo SOAP header if the incoming invocation had a
+ * wsa:MessageID SOAP header present - note that OASIS SCA requires that the
+ * RelationshipType attribute is set to a particular SCA value
+ *
+ * @param sh - the SOAP headers
+ * @param msg - the message
+ * @throws SOAPException
+ */
+ private void addWSARelatesTo(SOAPHeader sh, Message msg) throws SOAPException {
+
+ //
+ // Note that the 'core' (loosely speaking) part of the invocation chain
+ // will have already copied the forward message msgId to the RELATES_TO header.
+ //
+ String idValue = (String)msg.getHeaders().get(Constants.RELATES_TO);
+ if (idValue != null) {
+ SOAPHeaderElement relatesToH = sh.addHeaderElement(QNAME_WSA_RELATESTO);
+ relatesToH.addAttribute(new QName(null, "RelationshipType"), SCA_CALLBACK_REL);
+ relatesToH.setTextContent(idValue);
+ // OMElement relatesToOM = sh.getOMFactory().createOMElement(
+ // QNAME_WSA_RELATESTO );
+ // OMAttribute relType =
+ // sh.getOMFactory().createOMAttribute("RelationshipType", null,
+ // SCA_CALLBACK_REL);
+ // relatesToOM.addAttribute( relType );
+ // relatesToOM.setText( idValue );
+ // sh.addChild( relatesToOM );
+ }
+ } // end method addWSARelatesTo
+
+ /**
+ * Indicates if the invocation is for the callback of a bidirectional
+ * service
+ *
+ * @param msg the Message
+ * @return true if the invocation is for the callback of a bidirectional
+ * service, false otherwise
+ */
+ private boolean isInvocationForCallback(Message msg) {
+ org.apache.tuscany.sca.assembly.EndpointReference fromEPR = msg.getFrom();
+ if (fromEPR != null) {
+ ComponentReference ref = fromEPR.getReference();
+ if (ref != null)
+ return ref.isForCallback();
+ } // end if
+ return false;
+ } // end method isInvocationForCallback
+
+ /**
+ * getActionFromInputElement
+ *
+ * @param def the wsdl:definitions which contains the wsdl:portType
+ * @param wsdl4jPortType the wsdl:portType which contains the wsdl:operation
+ * @param op the wsdl:operation which contains the input element
+ * @param input the input element to be examined to generate the wsa:Action
+ * @return either the wsaw:Action from the input element or an action
+ * generated using the DefaultActionPattern
+ */
+ public static String getActionFromInputElement(Definition def,
+ PortType wsdl4jPortType,
+ javax.wsdl.Operation op,
+ Input input) {
+ String result = getWSAWActionExtensionAttribute(input);
+ if (result == null) {
+ result = generateActionFromInputElement(def, wsdl4jPortType, op, input);
+ }
+ return result;
+ }
+
+ private static String getWSAWActionExtensionAttribute(AttributeExtensible ae) {
+ // Search first for a wsaw:Action using the submission namespace
+ Object attribute = ae.getExtensionAttribute(submissionWSAWNS);
+ // Then if that did not exist one using the w3c WSAM namespace
+ if (attribute == null) {
+ attribute = ae.getExtensionAttribute(finalWSAMNS);
+ }
+ // Then if that did not exist one using the w3c WSAW namespace
+ // (for backwards compat reasons)
+ if (attribute == null) {
+ attribute = ae.getExtensionAttribute(finalWSAWNS);
+ }
+ // Then finally if that did not exist, try the 2005/08 NS
+ // (Included here because it's needed for Apache Muse)
+ if (attribute == null) {
+ attribute = ae.getExtensionAttribute(finalWSANS);
+ }
+
+ // wsdl4j may return a String, QName or a List of either
+ // If it is a list, extract the first element
+ if (attribute instanceof List) {
+ List l = (List)attribute;
+ if (l.size() > 0) {
+ attribute = l.get(0);
+ } else {
+ attribute = null;
+ }
+ }
+
+ // attribute must now be a QName or String or null
+ // If it is a QName, take the LocalPart as a String
+ if (attribute instanceof QName) {
+ QName qn = (QName)attribute;
+ attribute = qn.getLocalPart();
+ }
+
+ if ((attribute instanceof String)) {
+ String result = (String)attribute;
+ return result;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Generate the Action for an Input using the Default Action Pattern
+ * <p/>
+ * Pattern is defined as [target namespace][delimiter][port type
+ * name][delimiter][input name]
+ *
+ * @param def is required to obtain the targetNamespace
+ * @param wsdl4jPortType is required to obtain the portType name
+ * @param op is required to generate the input name if not explicitly
+ * specified
+ * @param input is required for its name if specified
+ * @return a wsa:Action value based on the Default Action Pattern and the
+ * provided objects
+ */
+ public static String generateActionFromInputElement(Definition def,
+ PortType wsdl4jPortType,
+ javax.wsdl.Operation op,
+ Input input) {
+ // Get the targetNamespace of the wsdl:definitions
+ String targetNamespace = def.getTargetNamespace();
+
+ // Determine the delimiter. Per the spec: 'is ":" when the [target
+ // namespace] is a URN, otherwise "/".
+ // Note that for IRI schemes other than URNs which aren't path-based
+ // (i.e. those that outlaw the "/"
+ // character), the default action value may not conform to the rules of
+ // the IRI scheme. Authors
+ // are advised to specify explicit values in the WSDL in this case.'
+ String delimiter = SLASH;
+ if (targetNamespace.toLowerCase().startsWith(URN)) {
+ delimiter = COLON;
+ }
+
+ // Get the portType name (as a string to be included in the action)
+ String portTypeName = wsdl4jPortType.getQName().getLocalPart();
+ // Get the name of the input element (and generate one if none
+ // explicitly specified)
+ String inputName = getNameFromInputElement(op, input);
+
+ // Append the bits together
+ StringBuffer sb = new StringBuffer();
+ sb.append(targetNamespace);
+ // Deal with the problem that the targetNamespace may or may not have a
+ // trailing delimiter
+ if (!targetNamespace.endsWith(delimiter)) {
+ sb.append(delimiter);
+ }
+ sb.append(portTypeName);
+ sb.append(delimiter);
+ sb.append(inputName);
+
+ // Resolve the action from the StringBuffer
+ String result = sb.toString();
+
+ return result;
+ }
+
+ /**
+ * Get the name of the specified Input element using the rules defined in
+ * WSDL 1.1 Section 2.4.5 http://www.w3.org/TR/wsdl#_names
+ */
+ private static String getNameFromInputElement(javax.wsdl.Operation op, Input input) {
+ // Get the name from the input element if specified.
+ String result = input.getName();
+
+ // If not we'll have to generate it.
+ if (result == null) {
+ // If Request-Response or Solicit-Response do something special per
+ // WSDL 1.1 Section 2.4.5
+ OperationType operationType = op.getStyle();
+ if (null != operationType) {
+ if (operationType.equals(OperationType.REQUEST_RESPONSE)) {
+ result = op.getName() + REQUEST;
+ } else if (operationType.equals(OperationType.SOLICIT_RESPONSE)) {
+ result = op.getName() + RESPONSE;
+ }
+ }
+ // If the OperationType was not available for some reason, assume
+ // on-way or notification
+ if (result == null) {
+ result = op.getName();
+ }
+ }
+ return result;
+ }
+
+ private static final String URN = "urn";
+ private static final String SLASH = "/";
+ private static final String COLON = ":";
+ private static final String REQUEST = "Request";
+ private static final String RESPONSE = "Response";
+
+ public boolean allowsPassByReference() {
+ return true;
+ }
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingProvider.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingProvider.java
new file mode 100644
index 0000000000..6afaf3c7c8
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-ws-runtime-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingProvider.java
@@ -0,0 +1,329 @@
+/*
+ * 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.tuscany.sca.binding.ws.jaxws;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.annotation.Resource;
+import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.xml.namespace.QName;
+import javax.xml.soap.Detail;
+import javax.xml.soap.DetailEntry;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFactory;
+import javax.xml.soap.SOAPFault;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.ws.Provider;
+import javax.xml.ws.Service.Mode;
+import javax.xml.ws.ServiceMode;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.WebServiceProvider;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.binding.ws.WebServiceBinding;
+import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory;
+import org.apache.tuscany.sca.core.invocation.Constants;
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.FaultException;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.oasisopen.sca.ServiceRuntimeException;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+@WebServiceProvider
+@ServiceMode(Mode.MESSAGE)
+public class JAXWSBindingProvider implements Provider<SOAPMessage> {
+ public static final String WSA_FINAL_NAMESPACE = "http://www.w3.org/2005/08/addressing";
+ public static final QName QNAME_WSA_ADDRESS = new QName(WSA_FINAL_NAMESPACE, "Address");
+ public static final QName QNAME_WSA_FROM = new QName(WSA_FINAL_NAMESPACE, "From");
+ public static final QName QNAME_WSA_RELATESTO = new QName(WSA_FINAL_NAMESPACE, "RelatesTo");
+ public static final QName QNAME_WSA_REPLYTO = new QName(WSA_FINAL_NAMESPACE, "ReplyTo");
+ public static final QName QNAME_WSA_REFERENCE_PARAMETERS = new QName(WSA_FINAL_NAMESPACE, "ReferenceParameters");
+ public static final QName QNAME_WSA_MESSAGEID = new QName(WSA_FINAL_NAMESPACE, "MessageID");
+
+ private MessageFactory messageFactory;
+ private RuntimeEndpoint endpoint;
+ private WebServiceBinding wsBinding;
+ private javax.xml.soap.MessageFactory soapMessageFactory;
+ private SOAPFactory soapFactory;
+
+ @Resource
+ private WebServiceContext context;
+ private RuntimeAssemblyFactory assemblyFactory;
+ private WebServiceBindingFactory webServiceBindingFactory;
+
+ public JAXWSBindingProvider(){
+ // to keep Axis2 JAXWS implementation happy
+ }
+
+ public JAXWSBindingProvider(RuntimeEndpoint endpoint,
+ FactoryExtensionPoint modelFactories,
+ DataBindingExtensionPoint dataBindings, String defaultPort) {
+
+ this.messageFactory = modelFactories.getFactory(MessageFactory.class);
+
+ this.soapMessageFactory = modelFactories.getFactory(javax.xml.soap.MessageFactory.class);
+ this.soapFactory = modelFactories.getFactory(SOAPFactory.class);
+ this.assemblyFactory = (RuntimeAssemblyFactory)modelFactories.getFactory(AssemblyFactory.class);
+ this.webServiceBindingFactory = (WebServiceBindingFactory)modelFactories.getFactory(WebServiceBindingFactory.class);
+
+ // soapMessageFactory = javax.xml.soap.MessageFactory.newInstance();
+ // soapFactory = SOAPFactory.newInstance();
+
+ this.endpoint = endpoint;
+ this.wsBinding = (WebServiceBinding)endpoint.getBinding();
+
+ // A WSDL document should always be present in the binding
+ if (wsBinding.getGeneratedWSDLDocument() == null) {
+ throw new ServiceRuntimeException("No WSDL document for " + endpoint.getURI());
+ }
+
+ // Set to use the DOM data binding
+ InterfaceContract contract = wsBinding.getBindingInterfaceContract();
+ contract.getInterface().resetDataBinding(Node.class.getName());
+
+ // Can we safely assume there is only one port because you configure
+ // a binding in the following ways:
+ // 1/ default - one port generated = host domain : host port / structural path
+ // 2/ uri="absolute addr" - one port generated = host domain : uri port / uri path
+ // 3/ uri="relative addr" - one port generated = host domain : host port / structural path / relative path
+ // 4/ wsdl.binding - one port generated = host domain : host port / structural path
+ // 5/ wsdl.port - one port generated = host domain : port port / port path
+ // 6/ wsa:Address - one port generated = host domain : address port / address path
+ // 7/ 4 + 6 - as 6
+
+ // TODO the binding URI will currently have been calculated during build
+ // however we don't give the provider a chance to get in and effect the
+ // calculation (see above comment). For now just fake the addition of binding
+ // specific processing by adding a root if it's not already present
+ if (!wsBinding.getURI().startsWith("http://")) {
+ String serviceURI = null;
+
+ // look in the port for the location URL
+ List wsdlPortExtensions = wsBinding.getPort().getExtensibilityElements();
+ for (final Object extension : wsdlPortExtensions) {
+ if (extension instanceof SOAPAddress) {
+ serviceURI = ((SOAPAddress) extension).getLocationURI();
+ }
+ }
+
+ if (serviceURI == null ||
+ !serviceURI.startsWith("http://")){
+ serviceURI = "http://localhost:" + defaultPort + wsBinding.getURI();
+ }
+
+ wsBinding.setURI(serviceURI);
+ }
+ System.out.println("Binding.ws JAXWS provider - Service URI: " + wsBinding.getURI());
+ }
+
+ public void start() {
+ // TODO - do we need this?
+ }
+
+ public void stop() {
+ // TODO - do we need this?
+ }
+
+ public SOAPMessage invoke(SOAPMessage request) {
+ try {
+ // Assuming document-literal-wrapper style
+ Node root = request.getSOAPBody().getFirstChild();
+ String operationName = root.getLocalName();
+ Operation operation = null;
+ for (InvocationChain invocationChain : endpoint.getInvocationChains()) {
+ if (operationName.equals(invocationChain.getSourceOperation().getName())) {
+ operation = invocationChain.getSourceOperation();
+ break;
+ }
+ }
+ if (operation == null) {
+ throw new SOAPException("Operation not found: " + operationName);
+ }
+
+ Message requestMsg = messageFactory.createMessage();
+ Object[] body = new Object[]{root};
+ requestMsg.setBody(body);
+ requestMsg.setOperation(operation);
+
+ SOAPHeader header = request.getSOAPHeader();
+ String callbackAddress = null;
+ if (header != null) {
+ callbackAddress = handleCallbackAddress( header, requestMsg );
+ // Retrieve other callback-related headers
+ handleMessageIDHeader( header, requestMsg );
+ handleRelatesToHeader( header, requestMsg );
+ } // end if
+
+ // Create a from EPR to hold the details of the callback endpoint
+ EndpointReference from = null;
+ if (callbackAddress != null ) {
+ // Check for special (& not allowed!) WS_Addressing values
+ checkCallbackAddress( callbackAddress, request );
+ //
+ from = assemblyFactory.createEndpointReference();
+ Endpoint fromEndpoint = assemblyFactory.createEndpoint();
+ from.setTargetEndpoint(fromEndpoint);
+ from.setStatus(EndpointReference.Status.WIRED_TARGET_FOUND_AND_MATCHED);
+ requestMsg.setFrom(from);
+ RuntimeEndpoint callbackEndpoint = (RuntimeEndpoint)assemblyFactory.createEndpoint();
+ //
+ WebServiceBinding cbBinding = webServiceBindingFactory.createWebServiceBinding();
+ cbBinding.setURI(callbackAddress);
+ callbackEndpoint.setBinding(cbBinding);
+ //
+ callbackEndpoint.setURI(callbackAddress);
+ callbackEndpoint.setUnresolved(true);
+ from.setCallbackEndpoint(callbackEndpoint);
+ }
+
+ Message responseMsg = endpoint.invoke(operation, requestMsg);
+
+ SOAPMessage response = soapMessageFactory.createMessage();
+ if (responseMsg.isFault()) {
+ // ServiceRuntimeException e = responseMsg.getBody();
+ // throw e;
+
+ FaultException fe = responseMsg.getBody();
+ SOAPFault fault = response.getSOAPBody().addFault(new QName(response.getSOAPBody().getNamespaceURI(), "Server"), fe.getMessage());
+ Detail d = fault.addDetail();
+ DetailEntry de = d.addDetailEntry(fe.getFaultName());
+ SOAPElement dece = de.addChildElement("message");
+ if (fe.getMessage() != null) {
+ dece.addTextNode(fe.getMessage());
+ }
+
+ } else {
+ Element element = responseMsg.getBody();
+ response.getSOAPBody().addChildElement(soapFactory.createElement(element));
+ }
+ return response;
+ } catch (SOAPException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+ private static String WS_REF_PARMS = "WS_REFERENCE_PARAMETERS";
+ private String handleCallbackAddress( SOAPHeader header, Message msg ) {
+ String callbackAddress = null;
+
+ Iterator<SOAPElement> it = header.getChildElements(QNAME_WSA_FROM);
+ SOAPElement from = it.hasNext() ? it.next() : null;
+ if( from == null ) {
+ Iterator<SOAPElement> it2 = header.getChildElements(QNAME_WSA_REPLYTO);
+ from = it2.hasNext() ? it2.next() : null;
+ }
+
+ if (from != null) {
+ Iterator<SOAPElement> it2 = header.getChildElements(QNAME_WSA_ADDRESS);
+ SOAPElement callbackAddrElement = it2.hasNext() ? it2.next() : null;
+ if (callbackAddrElement != null) {
+ if (endpoint.getService().getInterfaceContract().getCallbackInterface() != null) {
+ callbackAddress = callbackAddrElement.getTextContent();
+ }
+ // OMElement refParms = from.getFirstChildWithName(QNAME_WSA_REFERENCE_PARAMETERS);
+ Iterator<SOAPElement> it3 = header.getChildElements(QNAME_WSA_REFERENCE_PARAMETERS);
+ SOAPElement refParms = it3.hasNext() ? it3.next() : null;
+ if( refParms != null ) msg.getHeaders().put(WS_REF_PARMS, refParms);
+ }
+ } // end if
+
+ return callbackAddress;
+ } // end method handleCallbackAddress
+
+ /**
+ * Handle a SOAP wsa:MessageID header - place the contents into the Tuscany message for use by any callback
+ * @param header - the SOAP Headers
+ * @param msg - the Tuscany Message
+ */
+ private void handleMessageIDHeader( SOAPHeader header, Message msg ) {
+ if( header == null ) return;
+ Iterator<SOAPElement> it = header.getChildElements(QNAME_WSA_MESSAGEID);
+ SOAPElement messageID = it.hasNext() ? it.next() : null;
+ if (messageID != null) {
+ String idValue = messageID.getTextContent();
+ msg.getHeaders().put(Constants.MESSAGE_ID, idValue);
+ } // end if
+ } // end method handleMessageID
+
+ /**
+ * Handle a SOAP wsa:RelatesTo header - place the contents into the Tuscany message for use by any callback
+ * @param header - the SOAP Headers
+ * @param msg - the Tuscany Message
+ */
+ private void handleRelatesToHeader( SOAPHeader header, Message msg ) {
+ if( header == null ) return;
+ Iterator<SOAPElement> it = header.getChildElements(QNAME_WSA_RELATESTO);
+ SOAPElement relatesTo = it.hasNext() ? it.next() : null;
+ if (relatesTo != null) {
+ String relatesToVal = relatesTo.getTextContent();
+ msg.getHeaders().put(Constants.RELATES_TO, relatesToVal);
+ } // end if
+ } // end method handleRelatesToHeader
+
+ // Special WS_Addressing values
+ private static String WS_ADDR_ANONYMOUS = "http://www.w3.org/2005/08/addressing/anonymous";
+ private static String WS_ADDR_NONE = "http://www.w3.org/2005/08/addressing/none";
+
+ /**
+ * Check if the received callback address has either of the special WS-Addressing forms which are outlawed by the
+ * Web Service Binding specification [BWS50004]
+ * @param callbackAddress - the received callback address
+ * @param inMC - the Axis message context for the received forward call
+ * @throws AxisFault - throws a "OnlyNonAnonymousAddressSupportedFault" if the callback address has either of the special forms
+ */
+ private void checkCallbackAddress( String callbackAddress, SOAPMessage request) {
+ // If the address is anonymous or none, throw a SOAP fault...
+ if( WS_ADDR_ANONYMOUS.equals(callbackAddress) || WS_ADDR_NONE.equals(callbackAddress) ) {
+ triggerOnlyNonAnonymousAddressSupportedFault(request, "wsa:From");
+ }
+ } // end method checkCallbackAddress
+ // wsa:OnlyAnonymousAddressSupported
+
+ // wsa:OnlyNonAnonymousAddressSupported
+ public void triggerOnlyNonAnonymousAddressSupportedFault(SOAPMessage request, String incorrectHeaderName){
+ // TODO
+ // String namespace = (String)messageContext.getProperty(AddressingConstants.WS_ADDRESSING_VERSION);
+ // if (Submission.WSA_NAMESPACE.equals(namespace)) {
+ // triggerAddressingFault(messageContext, Final.FAULT_HEADER_PROB_HEADER_QNAME,
+ // AddressingConstants.WSA_DEFAULT_PREFIX + ":" +
+ // incorrectHeaderName, Submission.FAULT_INVALID_HEADER,
+ // null, AddressingMessages.getMessage(
+ // "spec.submission.FAULT_INVALID_HEADER_REASON"));
+ // } else {
+ // triggerAddressingFault(messageContext, Final.FAULT_HEADER_PROB_HEADER_QNAME,
+ // AddressingConstants.WSA_DEFAULT_PREFIX + ":" +
+ // incorrectHeaderName, Final.FAULT_INVALID_HEADER,
+ // Final.FAULT_ONLY_NON_ANONYMOUS_ADDRESS_SUPPORTED,
+ // AddressingMessages.getMessage(
+ // "spec.final.FAULT_INVALID_HEADER_REASON"));
+ // }
+ }
+}