diff options
Diffstat (limited to '')
125 files changed, 14781 insertions, 0 deletions
diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/LICENSE b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/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/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/META-INF/MANIFEST.MF b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..61c5ab01dd --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/META-INF/MANIFEST.MF @@ -0,0 +1,138 @@ +Manifest-Version: 1.0
+Export-Package: org.apache.tuscany.sca.binding.ws.axis2;version="2.0.0";
+ uses:="org.apache.axis2.deployment.util,
+ org.apache.tuscany.sca.definitions,
+ org.apache.ws.security.handler,
+ javax.xml.namespace,
+ org.apache.axiom.om,
+ org.xml.sax,
+ org.apache.commons.httpclient,
+ org.apache.axiom.soap,
+ org.apache.axis2.util,
+ javax.servlet,
+ javax.xml.stream,
+ org.apache.tuscany.sca.core.assembly,
+ org.apache.axis2.transport.http.server,
+ org.oasisopen.sca,
+ org.apache.axis2.i18n,
+ org.apache.axis2.transport,
+ org.apache.axis2.client,
+ org.apache.axis2.context,
+ org.apache.axiom.om.impl.builder,
+ org.apache.tuscany.sca.interfacedef.java,
+ org.w3c.dom,
+ javax.wsdl,
+ org.apache.tuscany.sca.xsd.xml,
+ org.apache.tuscany.sca.binding.ws,
+ org.apache.axis2.engine,
+ org.apache.axis2.receivers,
+ org.apache.commons.httpclient.params,
+ org.apache.tuscany.sca.interfacedef.wsdl,
+ org.apache.tuscany.sca.xsd,
+ org.apache.tuscany.sca.databinding,
+ org.apache.axis2.addressing,
+ org.apache.axis2.deployment,
+ org.apache.axis2.transport.http,
+ org.apache.axis2.transport.local,
+ org.apache.tuscany.sca.runtime,
+ org.apache.commons.logging,
+ org.apache.tuscany.sca.interfacedef.util,
+ org.apache.tuscany.sca.provider,
+ org.apache.tuscany.sca.core,
+ javax.xml.transform.dom,
+ org.apache.tuscany.sca.policy,
+ org.apache.axis2.description,
+ javax.wsdl.extensions,
+ org.apache.tuscany.sca.host.http,
+ org.apache.tuscany.sca.policy.util,
+ org.apache.axis2.util.threadpool,
+ org.apache.ws.security,
+ org.apache.axis2,
+ org.apache.ws.commons.schema,
+ org.apache.tuscany.sca.assembly,
+ org.apache.ws.commons.schema.resolver,
+ javax.wsdl.extensions.soap,
+ org.apache.tuscany.sca.interfacedef,
+ org.apache.tuscany.sca.invocation,
+ javax.xml.transform,
+ javax.wsdl.extensions.soap12,
+ org.apache.tuscany.sca.contribution.processor,
+ javax.servlet.http"
+Private-Package:
+SCA-Version: 1.1
+Bundle-Name: Apache Tuscany SCA Axis2-based WS Binding Extension
+Bundle-Vendor: The Apache Software Foundation
+Bundle-Version: 2.0.0
+Bundle-ManifestVersion: 2
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Bundle-Description: Apache Tuscany SCA Axis2-based WS Binding Extension
+Eclipse-RegisterBuddy: org.apache.axis2.kernel
+Import-Package: javax.servlet,
+ javax.servlet.http,
+ javax.wsdl,
+ javax.wsdl.extensions,
+ javax.wsdl.extensions.soap,
+ javax.wsdl.extensions.soap12,
+ javax.xml.namespace,
+ javax.xml.parsers,
+ javax.xml.stream,
+ javax.xml.transform.dom,
+ org.apache.axiom.om,
+ org.apache.axiom.om.impl.builder,
+ org.apache.axiom.soap,
+ org.apache.axiom.util.base64,
+ org.apache.axis2,
+ org.apache.axis2.addressing,
+ org.apache.axis2.addressing.wsdl,
+ org.apache.axis2.client,
+ org.apache.axis2.context,
+ org.apache.axis2.deployment,
+ org.apache.axis2.deployment.util,
+ org.apache.axis2.description,
+ org.apache.axis2.engine,
+ org.apache.axis2.handlers,
+ org.apache.axis2.i18n,
+ org.apache.axis2.receivers,
+ org.apache.axis2.transport,
+ org.apache.axis2.transport.http,
+ org.apache.axis2.util,
+ org.apache.axis2.util.threadpool,
+ org.apache.commons.httpclient,
+ org.apache.commons.httpclient.params,
+ org.apache.commons.logging;resolution:=optional,
+ org.apache.tuscany.sca.assembly;version="2.0.0",
+ org.apache.tuscany.sca.assembly.xml;version="2.0.0",
+ org.apache.tuscany.sca.binding.ws;version="2.0.0",
+ org.apache.tuscany.sca.common.xml;version="2.0.0",
+ org.apache.tuscany.sca.context;version="2.0.0",
+ org.apache.tuscany.sca.contribution.processor;version="2.0.0",
+ org.apache.tuscany.sca.contribution.resolver;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.databinding;version="2.0.0",
+ org.apache.tuscany.sca.extensibility;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.security.http.ssl;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.ws.commons.schema,
+ org.apache.ws.commons.schema.resolver,
+ 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.axis2
+Bundle-DocURL: http://www.apache.org/
+Bundle-RequiredExecutionEnvironment: J2SE-1.5,
+ JavaSE-1.6
+Require-Bundle: org.apache.tuscany.sca.core
diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/NOTICE b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/NOTICE new file mode 100644 index 0000000000..d69e595698 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2011 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/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/pom.xml b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/pom.xml new file mode 100644 index 0000000000..58f72b9134 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/pom.xml @@ -0,0 +1,437 @@ +<?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-Beta3-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>tuscany-binding-ws-runtime-axis2</artifactId> + <name>Apache Tuscany SCA Axis2-1.5-based WS Binding Runtime</name> + + + <dependencies> + <!-- Compile dependencies --> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-core-runtime-pom</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <type>pom</type> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-policy-security</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>provided</scope> <!-- it's in base --> + </dependency> + + <dependency> + <groupId>org.apache.axis2</groupId> + <artifactId>org.apache.axis2.osgi</artifactId> + <version>1.5.3</version> + <exclusions> + <exclusion> + <groupId>org.apache.axis2</groupId> + <artifactId>axis2-adb</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.axis2</groupId> + <artifactId>axis2-kernel</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.axis2</groupId> + <artifactId>axis2-transport-http</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.axis2</groupId> + <artifactId>axis2-transport-local</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>org.apache.rampart</groupId> + <artifactId>rampart-core</artifactId> + <version>1.5.1</version> + <exclusions> + <!-- + We can live without most of the Rampart dependencies. The following + jars were added to Tuscany support Rampart + + axiom-dom-1.2.10.jar, + mex-1.5.4-impl.jar, + not-yet-commons-ssl-0.3.9.jar, + opensaml-2.4.1.jar, + openws-1.4.1.jar, + rampart-core-1.5.1.jar, + rampart-policy-1.5.1.jar, + rampart-trust-1.5.1.jar, + wss4j-1.5.10.jar, + xmlsec-1.4.4.jar, + xmltooling-1.3.1.jar + --> + <exclusion> + <groupId>org.apache.axis2</groupId> + <artifactId>axis2-kernel</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.axis2</groupId> + <artifactId>addressing</artifactId> + </exclusion> + <exclusion> + <groupId>org.opensaml</groupId> + <artifactId>opensaml1</artifactId> + </exclusion> + <exclusion> + <groupId>bouncycastle</groupId> + <artifactId>bcprov-jdk14</artifactId> + </exclusion> + <exclusion> + <groupId>org.bouncycastle</groupId> + <artifactId>bcprov-ext-jdk15</artifactId> + </exclusion> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-jdk14</artifactId> + </exclusion> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </exclusion> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>jcl-over-slf4j</artifactId> + </exclusion> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>log4j-over-slf4j</artifactId> + </exclusion> + <exclusion> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + </exclusion> + <exclusion> + <groupId>joda-time</groupId> + <artifactId>joda-time</artifactId> + </exclusion> + <exclusion> + <groupId>net.jcip</groupId> + <artifactId>jcip-annotations</artifactId> + </exclusion> + <exclusion> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + </exclusion> + <exclusion> + <groupId>jargs</groupId> + <artifactId>jargs</artifactId> + </exclusion> + <exclusion> + <groupId>velocity</groupId> + <artifactId>velocity</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.xerces</groupId> + <artifactId>xml-apis</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.xerces</groupId> + <artifactId>xercesImpl</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.xerces</groupId> + <artifactId>resolver</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.xerces</groupId> + <artifactId>serializer</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-stax-api_1.0_spec</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-activation_1.1_spec</artifactId> + </exclusion> + <exclusion> + <groupId>org.codehaus.woodstox</groupId> + <artifactId>wstx-asl</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.xalan</groupId> + <artifactId>xalan</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.santuario</groupId> + <artifactId>xmlsec</artifactId> + </exclusion> + </exclusions> + </dependency> + + <!-- replace the Rampart xmlsec with the version Tuscany is using --> + <dependency> + <groupId>org.apache.santuario</groupId> + <artifactId>xmlsec</artifactId> + <version>1.4.4</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>org.opensaml</groupId> + <artifactId>opensaml</artifactId> + <version>2.4.1</version> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-jdk14</artifactId> + </exclusion> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </exclusion> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>jcl-over-slf4j</artifactId> + </exclusion> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>log4j-over-slf4j</artifactId> + </exclusion> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>jul-to-slf4j</artifactId> + </exclusion> + <exclusion> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + </exclusion> + <exclusion> + <groupId>joda-time</groupId> + <artifactId>joda-time</artifactId> + </exclusion> + <exclusion> + <groupId>net.jcip</groupId> + <artifactId>jcip-annotations</artifactId> + </exclusion> + <exclusion> + <groupId>org.bouncycastle</groupId> + <artifactId>bcprov-ext-jdk15</artifactId> + </exclusion> + <exclusion> + <groupId>org.bouncycastle</groupId> + <artifactId>bcprov-jdk15</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.commons.ssl</groupId> + <artifactId>not-yet-commons-ssl</artifactId> + </exclusion> + <exclusion> + <groupId>ca.juliusdavies</groupId> + <artifactId>not-yet-commons-ssl</artifactId> + </exclusion> + <exclusion> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + </exclusion> + <exclusion> + <groupId>jargs</groupId> + <artifactId>jargs</artifactId> + </exclusion> + <exclusion> + <groupId>velocity</groupId> + <artifactId>velocity</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.xerces</groupId> + <artifactId>xml-apis</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.xerces</groupId> + <artifactId>xercesImpl</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.xerces</groupId> + <artifactId>resolver</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.xerces</groupId> + <artifactId>serializer</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.xalan</groupId> + <artifactId>xalan</artifactId> + </exclusion> + <exclusion> + <groupId>xalan</groupId> + <artifactId>xalan</artifactId> + </exclusion> + <exclusion> + <groupId>xml-resolver</groupId> + <artifactId>xml-resolver</artifactId> + </exclusion> + </exclusions> + </dependency> + + <!-- replace the Rampart xalan with the version Tuscany is using --> + <dependency> + <groupId>xalan</groupId> + <artifactId>xalan</artifactId> + <version>2.7.0</version> + <exclusions> + <exclusion> + <groupId>xml-apis</groupId> + <artifactId>xml-apis</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>commons-httpclient</groupId> + <artifactId>commons-httpclient</artifactId> + <version>3.1</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>org.apache.ws.commons.axiom</groupId> + <artifactId>axiom-api</artifactId> + <version>1.2.10</version> + <exclusions> + <exclusion> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-activation_1.1_spec</artifactId> + </exclusion> + <!-- exclusion> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-javamail_1.4_spec</artifactId> + </exclusion --> + <exclusion> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-stax-api_1.0_spec</artifactId> + </exclusion> + <!-- needed by rampart + <exclusion> + <groupId>jaxen</groupId> + <artifactId>jaxen</artifactId> + </exclusion> + --> + </exclusions> + </dependency> + + <dependency> + <groupId>org.apache.ws.commons.axiom</groupId> + <artifactId>axiom-impl</artifactId> + <version>1.2.10</version> + <exclusions> + <exclusion> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-activation_1.1_spec</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-javamail_1.4_spec</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-stax-api_1.0_spec</artifactId> + </exclusion> + <exclusion> + <groupId>org.codehaus.woodstox</groupId> + <artifactId>wstx-asl</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>org.apache.neethi</groupId> + <artifactId>neethi</artifactId> + <version>2.0.4</version> + <exclusions> + <exclusion> + <groupId>org.codehaus.woodstox</groupId> + <artifactId>wstx-asl</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.5</version> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-policy-wspolicy</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + </dependency> + + <!-- Runtime dependencies --> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-databinding-axiom</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-databinding-jaxb-axiom</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <!-- Test dependencies --> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-base-runtime-pom</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <type>pom</type> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-host-jetty</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + </dependencies> + +</project> diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/context/WSAxis2BindingContext.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/context/WSAxis2BindingContext.java new file mode 100644 index 0000000000..e9b388f793 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/context/WSAxis2BindingContext.java @@ -0,0 +1,58 @@ +/*
+ * 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.axis2.context;
+
+import org.apache.axis2.client.OperationClient;
+import org.apache.axis2.context.MessageContext;
+
+/**
+ * Context that the WS Axis2 binding puts on the Tuscany wire
+ *
+ * @version $Rev: 813727 $ $Date: 2009-09-11 10:02:58 +0100 (Fri, 11 Sep 2009) $
+ */
+public class WSAxis2BindingContext {
+
+ private OperationClient axisOperationClient;
+ private MessageContext axisInMessageContext;
+ private MessageContext axisOutMessageContext;
+
+ public OperationClient getAxisOperationClient() {
+ return axisOperationClient;
+ }
+
+ public void setAxisOperationClient(OperationClient axisOperationClient) {
+ this.axisOperationClient = axisOperationClient;
+ }
+
+ public MessageContext getAxisInMessageContext() {
+ return axisInMessageContext;
+ }
+
+ public void setAxisInMessageContext(MessageContext axisInMessageContext) {
+ this.axisInMessageContext = axisInMessageContext;
+ }
+
+ public MessageContext getAxisOutMessageContext() {
+ return axisOutMessageContext;
+ }
+
+ public void setAxisOutMessageContext(MessageContext axisOutMessageContext) {
+ this.axisOutMessageContext = axisOutMessageContext;
+ }
+}
diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationPolicyProviderFactory.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationPolicyProviderFactory.java new file mode 100644 index 0000000000..699846ead2 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationPolicyProviderFactory.java @@ -0,0 +1,57 @@ +/* + * 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.axis2.policy.authentication.basic; + +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicy; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.PolicyProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * @version $Rev$ $Date$ + */ +public class BasicAuthenticationPolicyProviderFactory implements PolicyProviderFactory<BasicAuthenticationPolicy> { + private ExtensionPointRegistry registry; + + public BasicAuthenticationPolicyProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component) { + return null; + } + + public PolicyProvider createReferencePolicyProvider(EndpointReference endpointReference) { + return new BasicAuthenticationReferencePolicyProvider(endpointReference); + } + + public PolicyProvider createServicePolicyProvider(Endpoint endpoint) { + return new BasicAuthenticationServicePolicyProvider(endpoint); + } + + public Class<BasicAuthenticationPolicy> getModelType() { + return BasicAuthenticationPolicy.class; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationReferencePolicyInterceptor.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationReferencePolicyInterceptor.java new file mode 100644 index 0000000000..78a150b0b4 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationReferencePolicyInterceptor.java @@ -0,0 +1,131 @@ +/* + * 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.axis2.policy.authentication.basic; + +import java.util.ArrayList; +import java.util.List; + +import javax.security.auth.Subject; +import javax.xml.namespace.QName; + +import org.apache.axis2.client.OperationClient; +import org.apache.axis2.transport.http.HTTPConstants; +import org.apache.axis2.transport.http.HttpTransportProperties; +import org.apache.axis2.transport.http.HttpTransportProperties.Authenticator; +import org.apache.tuscany.sca.binding.ws.axis2.context.WSAxis2BindingContext; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.policy.PolicyExpression; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicy; +import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPrincipal; +import org.apache.tuscany.sca.policy.security.SecurityUtil; +import org.oasisopen.sca.ServiceRuntimeException; + +/** + * + * @version $Rev$ $Date$ + */ +public class BasicAuthenticationReferencePolicyInterceptor implements PhasedInterceptor { + private static final String SCA10_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1"; + public static final QName policySetQName = new QName(SCA10_TUSCANY_NS, "wsBasicAuthentication"); + + private Invoker next; + private PolicySet policySet = null; + private String context; + private BasicAuthenticationPolicy policy; + + public BasicAuthenticationReferencePolicyInterceptor(String context, PolicySet policySet) { + super(); + this.policySet = policySet; + this.context = context; + init(); + } + + private void init() { + // TODO - how to get the appropriate expression out of the + // policy set. Need WS Policy help here + if (policySet != null) { + for (PolicyExpression policyExpression : policySet.getPolicies()){ + if (policyExpression.getPolicy() instanceof BasicAuthenticationPolicy){ + policy = (BasicAuthenticationPolicy)policyExpression.getPolicy(); + break; + } + } + } + } + + public Message invoke(Message msg) { + + WSAxis2BindingContext bindingContext = msg.getBindingContext(); + OperationClient operationClient = bindingContext.getAxisOperationClient(); + + String username = null; + String password = null; + + // get the security context + Subject subject = SecurityUtil.getSubject(msg); + BasicAuthenticationPrincipal principal = SecurityUtil.getPrincipal(subject, + BasicAuthenticationPrincipal.class); + + // could use the security principal to look up basic auth credentials + if ( principal != null ) { + username = ((BasicAuthenticationPrincipal)principal).getName(); + password = ((BasicAuthenticationPrincipal)principal).getPassword(); + } else if (policy != null ){ + username = policy.getUserName(); + password = policy.getPassword(); + + principal = new BasicAuthenticationPrincipal(username, + password); + subject.getPrincipals().add(principal); + } + + if (username == null || password == null ){ + throw new ServiceRuntimeException("Basic authentication username and/or password is null"); + } + + HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator(); + List<String> auth = new ArrayList<String>(); + auth.add(Authenticator.BASIC); + authenticator.setAuthSchemes(auth); + authenticator.setPreemptiveAuthentication(true); + authenticator.setUsername(username); + authenticator.setPassword(password); + + operationClient.getOptions().setProperty(HTTPConstants.AUTHENTICATE, + authenticator); + + return getNext().invoke(msg); + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } + + public String getPhase() { + return Phase.REFERENCE_BINDING_POLICY; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationReferencePolicyProvider.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationReferencePolicyProvider.java new file mode 100644 index 0000000000..d4b3851d97 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationReferencePolicyProvider.java @@ -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.tuscany.sca.binding.ws.axis2.policy.authentication.basic; + +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicy; +import org.apache.tuscany.sca.provider.BasePolicyProvider; + +/** + * @version $Rev$ $Date$ + */ +public class BasicAuthenticationReferencePolicyProvider extends BasePolicyProvider<BasicAuthenticationPolicy> { + + public BasicAuthenticationReferencePolicyProvider(EndpointReference endpointReference) { + super(BasicAuthenticationPolicy.class, endpointReference); + } + + public PhasedInterceptor createBindingInterceptor() { + PolicySet ps = findPolicySet(); + return ps == null ? null : new BasicAuthenticationReferencePolicyInterceptor(getContext(), ps); + } + + public void start() { + } + + public void stop() { + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationServicePolicyInterceptor.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationServicePolicyInterceptor.java new file mode 100644 index 0000000000..33e623135f --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationServicePolicyInterceptor.java @@ -0,0 +1,127 @@ +/* + * 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.axis2.policy.authentication.basic; + + +import java.util.Map; + +import javax.security.auth.Subject; +import javax.xml.namespace.QName; + +import org.apache.axiom.util.base64.Base64Utils; +import org.apache.axis2.client.OperationClient; +import org.apache.axis2.context.MessageContext; +import org.apache.tuscany.sca.binding.ws.axis2.context.WSAxis2BindingContext; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.policy.PolicyExpression; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicy; +import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPrincipal; +import org.apache.tuscany.sca.policy.security.SecurityUtil; + + +/** + * Policy handler to handle PolicySet related to Logging with the QName + * {http://tuscany.apache.org/xmlns/sca/1.1/impl/java}LoggingPolicy + * + * @version $Rev$ $Date$ + */ +public class BasicAuthenticationServicePolicyInterceptor implements PhasedInterceptor { + private static final String SCA10_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1"; + public static final QName policySetQName = new QName(SCA10_TUSCANY_NS, "wsBasicAuthentication"); + + private Invoker next; + private PolicySet policySet = null; + private String context; + private BasicAuthenticationPolicy policy; + + public BasicAuthenticationServicePolicyInterceptor(String context, PolicySet policySet) { + super(); + this.policySet = policySet; + this.context = context; + init(); + } + + private void init() { + // TODO - how to get the appropriate expression out of the + // policy set. Need WS Policy help here + if (policySet != null) { + for (PolicyExpression policyExpression : policySet.getPolicies()){ + if (policyExpression.getPolicy() instanceof BasicAuthenticationPolicy){ + policy = (BasicAuthenticationPolicy)policyExpression.getPolicy(); + break; + } + } + } + } + + public Message invoke(Message msg) { + + WSAxis2BindingContext bindingContext = msg.getBindingContext(); + MessageContext messageContext = bindingContext.getAxisInMessageContext(); + + Map httpHeaderProperties = (Map)messageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); + + String basicAuthString = (String)httpHeaderProperties.get("Authorization"); + String decodedBasicAuthString = null; + String username = null; + String password = null; + + if (basicAuthString != null) { + basicAuthString = basicAuthString.trim(); + + if (basicAuthString.startsWith("Basic ")) { + decodedBasicAuthString = new String(Base64Utils.decode(basicAuthString.substring(6))); + } + + int collonIndex = decodedBasicAuthString.indexOf(':'); + + if (collonIndex == -1){ + username = decodedBasicAuthString; + } else { + username = decodedBasicAuthString.substring(0, collonIndex); + password = decodedBasicAuthString.substring(collonIndex + 1); + } + } + + // get the security context + Subject subject = SecurityUtil.getSubject(msg); + BasicAuthenticationPrincipal principal = new BasicAuthenticationPrincipal(username, + password); + subject.getPrincipals().add(principal); + + return getNext().invoke(msg); + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } + + public String getPhase() { + return Phase.SERVICE_BINDING_POLICY; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationServicePolicyProvider.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationServicePolicyProvider.java new file mode 100644 index 0000000000..ec4536c309 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationServicePolicyProvider.java @@ -0,0 +1,49 @@ +/* + * 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.axis2.policy.authentication.basic; + + +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicy; +import org.apache.tuscany.sca.provider.BasePolicyProvider; + +/** + * @version $Rev$ $Date$ + */ +public class BasicAuthenticationServicePolicyProvider extends BasePolicyProvider<BasicAuthenticationPolicy> { + + public BasicAuthenticationServicePolicyProvider(Endpoint endpoint) { + super(BasicAuthenticationPolicy.class, endpoint); + } + + public PhasedInterceptor createBindingInterceptor() { + PolicySet ps = findPolicySet(); + return ps == null ? null : new BasicAuthenticationServicePolicyInterceptor(getContext(), ps); + } + + public void start() { + } + + public void stop() { + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicy.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicy.java new file mode 100644 index 0000000000..ded09392ec --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicy.java @@ -0,0 +1,53 @@ +/* + * 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.axis2.policy.configuration; + +import java.util.Hashtable; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMElement; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev$ $Date$ + */ +public class Axis2ConfigParamPolicy { + private static final String SCA11_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1"; + public static final QName NAME = new QName(SCA11_TUSCANY_NS, "wsConfigParam"); + private Map<String, OMElement> paramElements = new Hashtable<String, OMElement>(); + + public Map<String, OMElement> getParamElements() { + return paramElements; + } + + public QName getSchemaName() { + return NAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProcessor.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProcessor.java new file mode 100644 index 0000000000..c13c009edf --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProcessor.java @@ -0,0 +1,156 @@ +/* + * 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.axis2.policy.configuration; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; + +/** + * + * @version $Rev$ $Date$ + */ +public class Axis2ConfigParamPolicyProcessor implements StAXArtifactProcessor<Axis2ConfigParamPolicy> { + public static final QName AXIS2_CONFIG_PARAM_POLICY_QNAME = Axis2ConfigParamPolicy.NAME; + public static final String PARAMETER = "parameter"; + public QName getArtifactType() { + return AXIS2_CONFIG_PARAM_POLICY_QNAME; + } + + public Axis2ConfigParamPolicyProcessor(FactoryExtensionPoint modelFactories) { + } + + public Axis2ConfigParamPolicy read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { + Axis2ConfigParamPolicy policy = new Axis2ConfigParamPolicy(); + int event = reader.getEventType(); + QName name = null; + OMElement parameterElement = null; + String paramName = null; + while (reader.hasNext()) { + event = reader.getEventType(); + switch (event) { + case START_ELEMENT : { + name = reader.getName(); + if ( PARAMETER.equals(name.getLocalPart()) ) { + paramName = reader.getAttributeValue(null, "name"); + parameterElement = loadElement(reader); + policy.getParamElements().put(paramName, parameterElement); + } + break; + } + } + + if ( event == END_ELEMENT ) { + if ( AXIS2_CONFIG_PARAM_POLICY_QNAME.equals(reader.getName()) ) { + break; + } + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + + return policy; + } + + public void write(Axis2ConfigParamPolicy arg0, XMLStreamWriter arg1, ProcessorContext context) throws ContributionWriteException, + XMLStreamException { + } + + public Class<Axis2ConfigParamPolicy> getModelType() { + return Axis2ConfigParamPolicy.class; + } + + public void resolve(Axis2ConfigParamPolicy arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { + + } + + private OMElement loadElement(XMLStreamReader reader) throws XMLStreamException { + OMFactory fac = OMAbstractFactory.getOMFactory(); + OMElement head = fac.createOMElement(reader.getName()); + OMElement current = head; + while (true) { + switch (reader.next()) { + case XMLStreamConstants.START_ELEMENT: + //since the axis2 code checks against a no namespace we need to generate accordingly + QName name = new QName(reader.getName().getLocalPart()); + OMElement child = fac.createOMElement(name, current); + + int count = reader.getNamespaceCount(); + for (int i = 0; i < count; i++) { + String prefix = reader.getNamespacePrefix(i); + String ns = reader.getNamespaceURI(i); + child.declareNamespace(ns, prefix); + } + + if(!"".equals(name.getNamespaceURI())) { + child.declareNamespace(name.getNamespaceURI(), name.getPrefix()); + } + + // add the attributes for this element + count = reader.getAttributeCount(); + for (int i = 0; i < count; i++) { + String ns = reader.getAttributeNamespace(i); + String prefix = reader.getAttributePrefix(i); + String qname = reader.getAttributeLocalName(i); + String value = reader.getAttributeValue(i); + + if (ns != null) { + child.addAttribute(qname, value, fac.createOMNamespace(ns, prefix)); + child.declareNamespace(ns, prefix); + } else { + child.addAttribute(qname, value, null); + } + } + current = child; + break; + case XMLStreamConstants.CDATA: + fac.createOMText(current, reader.getText()); + break; + case XMLStreamConstants.CHARACTERS: + fac.createOMText(current, reader.getText()); + break; + case XMLStreamConstants.END_ELEMENT: + if ( current == head ) { + return head; + } else { + current = (OMElement)current.getParent(); + } + } + } + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProvider.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProvider.java new file mode 100644 index 0000000000..a77f71b734 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProvider.java @@ -0,0 +1,60 @@ +/* + * 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.axis2.policy.configuration; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.description.Parameter; +import org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2BaseBindingProvider; +import org.apache.tuscany.sca.policy.PolicySubject; +import org.apache.tuscany.sca.provider.BasePolicyProvider; +import org.oasisopen.sca.ServiceRuntimeException; + +/** + * @version $Rev$ $Date$ + */ +public class Axis2ConfigParamPolicyProvider extends BasePolicyProvider<Axis2ConfigParamPolicy> { + + public Axis2ConfigParamPolicyProvider(PolicySubject subject) { + super(Axis2ConfigParamPolicy.class, subject); + } + + public void configureBinding(Object context) { + ConfigurationContext configurationContext = ((Axis2BaseBindingProvider)context).getAxisConfigurationContext(); + Axis2ConfigParamPolicy axis2ConfigParamPolicy = null; + Parameter configParam = null; + for (Object policy : findPolicies()) { + if (policy instanceof Axis2ConfigParamPolicy) { + axis2ConfigParamPolicy = (Axis2ConfigParamPolicy)policy; + for (String paramName : axis2ConfigParamPolicy.getParamElements().keySet()) { + configParam = + new Parameter(paramName, axis2ConfigParamPolicy.getParamElements().get(paramName) + .getFirstElement()); + configParam.setParameterElement(axis2ConfigParamPolicy.getParamElements().get(paramName)); + try { + configurationContext.getAxisConfiguration().addParameter(configParam); + } catch (AxisFault e) { + throw new ServiceRuntimeException(e); + } + } + } + } + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProviderFactory.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProviderFactory.java new file mode 100644 index 0000000000..c4c93cd33d --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProviderFactory.java @@ -0,0 +1,54 @@ +/* + * 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.axis2.policy.configuration; + + +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.PolicyProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * @version $Rev$ $Date$ + */ +public class Axis2ConfigParamPolicyProviderFactory implements PolicyProviderFactory<Axis2ConfigParamPolicy> { + + public Axis2ConfigParamPolicyProviderFactory(ExtensionPointRegistry registry) { + super(); + } + + public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component) { + return null; + } + + public PolicyProvider createReferencePolicyProvider(EndpointReference endpointReference) { + return new Axis2ConfigParamPolicyProvider(endpointReference); + } + + public PolicyProvider createServicePolicyProvider(Endpoint endpoint) { + return new Axis2ConfigParamPolicyProvider(endpoint); + } + + public Class<Axis2ConfigParamPolicy> getModelType() { + return Axis2ConfigParamPolicy.class; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/mtom/Axis2MTOMPolicyProvider.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/mtom/Axis2MTOMPolicyProvider.java new file mode 100644 index 0000000000..e27da2bbd1 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/mtom/Axis2MTOMPolicyProvider.java @@ -0,0 +1,44 @@ +/* + * 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.axis2.policy.mtom; + +import org.apache.axis2.Constants.Configuration; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.tuscany.sca.policy.PolicySubject; +import org.apache.tuscany.sca.provider.BasePolicyProvider; + +/** + * @version $Rev$ $Date$ + */ +public class Axis2MTOMPolicyProvider extends BasePolicyProvider<Object> { + + public Axis2MTOMPolicyProvider(PolicySubject subject) { + super(Object.class, subject); + } + + public void configureBinding(Object configuration) { + + if (configuration instanceof ConfigurationContext){ + ConfigurationContext configurationContext = (ConfigurationContext)configuration; + configurationContext.getAxisConfiguration().getParameter(Configuration.ENABLE_MTOM).setLocked(false); + configurationContext.getAxisConfiguration().getParameter(Configuration.ENABLE_MTOM).setValue("true"); + } + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/security/http/ssl/HTTPSPolicyProvider.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/security/http/ssl/HTTPSPolicyProvider.java new file mode 100644 index 0000000000..8355c0fa4e --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/security/http/ssl/HTTPSPolicyProvider.java @@ -0,0 +1,66 @@ +/* + * 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.axis2.policy.security.http.ssl; + +import java.util.logging.Logger; + +import org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2BaseBindingProvider; +import org.apache.tuscany.sca.host.http.SecurityContext; +import org.apache.tuscany.sca.policy.PolicySubject; +import org.apache.tuscany.sca.policy.security.http.ssl.HTTPSPolicy; +import org.apache.tuscany.sca.provider.BasePolicyProvider; + +/** + * @version $Rev$ $Date$ + */ +public class HTTPSPolicyProvider extends BasePolicyProvider<HTTPSPolicy> { + private final Logger logger = Logger.getLogger(HTTPSPolicyProvider.class.getName()); + + public HTTPSPolicyProvider(PolicySubject subject) { + super(HTTPSPolicy.class, subject); + } + + public void configureBinding(Object context) { + SecurityContext securityContext = ((Axis2BaseBindingProvider)context).getHttpSecurityContext(); + + for (Object policy : findPolicies()) { + if (policy instanceof HTTPSPolicy) { + HTTPSPolicy httpsPolicy = (HTTPSPolicy)policy; + + securityContext.setSSLEnabled(true); + securityContext.setSSLProperties(httpsPolicy.toProperties()); + + // TODO - what is the right way to set trust/key store on client side? + + logger.info("HTTPSPolicyProvider: Setting JVM trust store to " + httpsPolicy.getTrustStore()); + System.setProperty("javax.net.ssl.trustStore", httpsPolicy.getTrustStore()); + System.setProperty("javax.net.ssl.trustStorePassword", httpsPolicy.getTrustStorePassword()); + System.setProperty("javax.net.ssl.trustStoreType", httpsPolicy.getTrustStoreType()); + + logger.info("HTTPSPolicyProvider: Setting JVM key store to " + httpsPolicy.getKeyStore()); + System.setProperty("javax.net.ssl.keyStore", httpsPolicy.getKeyStore()); + System.setProperty("javax.net.ssl.keyStorePassword", httpsPolicy.getKeyStorePassword()); + System.setProperty("javax.net.ssl.keyStoreType", httpsPolicy.getKeyStoreType()); + + return; + } + } + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/security/http/ssl/HTTPSPolicyProviderFactory.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/security/http/ssl/HTTPSPolicyProviderFactory.java new file mode 100644 index 0000000000..592300aaa3 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/security/http/ssl/HTTPSPolicyProviderFactory.java @@ -0,0 +1,57 @@ +/* + * 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.axis2.policy.security.http.ssl; + +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicy; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.PolicyProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * @version $Rev$ $Date$ + */ +public class HTTPSPolicyProviderFactory implements PolicyProviderFactory<BasicAuthenticationPolicy> { + private ExtensionPointRegistry registry; + + public HTTPSPolicyProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component) { + return null; + } + + public PolicyProvider createReferencePolicyProvider(EndpointReference endpointReference) { + return new HTTPSPolicyProvider(endpointReference); + } + + public PolicyProvider createServicePolicyProvider(Endpoint endpoint) { + return new HTTPSPolicyProvider(endpoint); + } + + public Class<BasicAuthenticationPolicy> getModelType() { + return BasicAuthenticationPolicy.class; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/wspolicy/WSPolicyProvider.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/wspolicy/WSPolicyProvider.java new file mode 100644 index 0000000000..12f3d81c98 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/wspolicy/WSPolicyProvider.java @@ -0,0 +1,67 @@ +/*
+ * 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.axis2.policy.wspolicy;
+
+import java.util.logging.Logger;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2BaseBindingProvider;
+import org.apache.tuscany.sca.host.http.SecurityContext;
+import org.apache.tuscany.sca.policy.PolicySubject;
+import org.apache.tuscany.sca.policy.security.http.ssl.HTTPSPolicy;
+import org.apache.tuscany.sca.policy.wspolicy.WSPolicy;
+import org.apache.tuscany.sca.provider.BasePolicyProvider;
+
+/**
+ * @version $Rev: 918583 $ $Date: 2010-03-03 17:16:15 +0000 (Wed, 03 Mar 2010) $
+ */
+public class WSPolicyProvider extends BasePolicyProvider<WSPolicy> {
+ private final Logger logger = Logger.getLogger(WSPolicyProvider.class.getName());
+
+ public WSPolicyProvider(PolicySubject subject) {
+ super(WSPolicy.class, subject);
+ }
+
+ public void configureBinding(Object context) {
+ ConfigurationContext configContext = ((Axis2BaseBindingProvider)context).getAxisConfigurationContext();
+
+ for ( Object policy : findPolicies() ) {
+ if ( policy instanceof WSPolicy ) {
+ WSPolicy wsPolicy = (WSPolicy)policy;
+ try {
+ configContext.getAxisConfiguration().applyPolicy(wsPolicy.getNeethiPolicy());
+ configContext.getAxisConfiguration().engageModule("rampart");
+
+ // TUSCANY-2824
+ // hack to make service side pick up rampart policies
+ // "rampartPolicy" comes from RampartMessageData.KEY_RAMPART_POLICY
+ // but I'm avoiding adding an explicit dependency just yet.
+ // There must be a proper way of getting rampart to recognize
+ // these policies
+ configContext.setProperty("rampartPolicy", wsPolicy.getNeethiPolicy());
+
+ } catch ( AxisFault e ) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ }
+}
diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/wspolicy/WSPolicyProviderFactory.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/wspolicy/WSPolicyProviderFactory.java new file mode 100644 index 0000000000..fc4879c0d9 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/wspolicy/WSPolicyProviderFactory.java @@ -0,0 +1,57 @@ +/*
+ * 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.axis2.policy.wspolicy;
+
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.policy.wspolicy.WSPolicy;
+import org.apache.tuscany.sca.provider.PolicyProvider;
+import org.apache.tuscany.sca.provider.PolicyProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * @version $Rev: 916317 $ $Date: 2010-02-25 15:16:44 +0000 (Thu, 25 Feb 2010) $
+ */
+public class WSPolicyProviderFactory implements PolicyProviderFactory<WSPolicy> {
+ private ExtensionPointRegistry registry;
+
+ public WSPolicyProviderFactory(ExtensionPointRegistry registry) {
+ super();
+ this.registry = registry;
+ }
+
+ public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component) {
+ return null;
+ }
+
+ public PolicyProvider createReferencePolicyProvider(EndpointReference endpointReference) {
+ return new WSPolicyProvider(endpointReference);
+ }
+
+ public PolicyProvider createServicePolicyProvider(Endpoint endpoint) {
+ return new WSPolicyProvider(endpoint);
+ }
+
+ public Class<WSPolicy> getModelType() {
+ return WSPolicy.class;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2BaseBindingProvider.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2BaseBindingProvider.java new file mode 100644 index 0000000000..dbefbf4a2d --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2BaseBindingProvider.java @@ -0,0 +1,63 @@ +/* + * 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.axis2.provider; + +import org.apache.axis2.context.ConfigurationContext; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.host.http.SecurityContext; +import org.apache.tuscany.sca.invocation.MessageFactory; + +public class Axis2BaseBindingProvider { + + // Tuscany extensions + protected ExtensionPointRegistry extensionPoints; + protected FactoryExtensionPoint modelFactories; + protected MessageFactory messageFactory; + + // derived policy configuration + protected boolean isSOAP12Required = false; + protected boolean isSOAP11Required = false; + protected boolean isRampartRequired = false; + protected boolean isMTOMRequired = false; + protected boolean isJMSRequired = false; + + // The Axis2 configuration that the binding creates + protected ConfigurationContext configContext; + protected SecurityContext httpSecurityContext; + + public Axis2BaseBindingProvider(ExtensionPointRegistry extensionPoints) { + + this.extensionPoints = extensionPoints; + + this.modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); + this.messageFactory = modelFactories.getFactory(MessageFactory.class); + + this.httpSecurityContext = new SecurityContext(); + } + + public ConfigurationContext getAxisConfigurationContext() { + return configContext; + } + + public SecurityContext getHttpSecurityContext() { + return httpSecurityContext; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2BindingProviderFactory.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2BindingProviderFactory.java new file mode 100644 index 0000000000..bd9b177c39 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2BindingProviderFactory.java @@ -0,0 +1,63 @@ +/* + * 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.axis2.provider; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.host.http.ServletHostHelper; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; + +/** + * Axis2BindingProviderFactory + * + * @version $Rev$ $Date$ + */ + +public class Axis2BindingProviderFactory implements BindingProviderFactory<WebServiceBinding> { + + public static final QName MTOM_INTENT = new QName(Constants.SCA11_TUSCANY_NS, "MTOM"); + + private ExtensionPointRegistry extensionPoints; + private ServletHost servletHost; + + public Axis2BindingProviderFactory(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; + this.servletHost = ServletHostHelper.getServletHost(extensionPoints); + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeEndpointReference endpointReference) { + return new Axis2ReferenceBindingProvider(extensionPoints, endpointReference); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeEndpoint endpoint) { + return new Axis2ServiceBindingProvider(extensionPoints, endpoint, servletHost); + } + + public Class<WebServiceBinding> getModelType() { + return WebServiceBinding.class; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2EngineIntegration.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2EngineIntegration.java new file mode 100644 index 0000000000..e25f5768e5 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2EngineIntegration.java @@ -0,0 +1,622 @@ +/* + * 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.axis2.provider; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Vector; + +import javax.wsdl.Definition; +import javax.wsdl.Import; +import javax.wsdl.Port; +import javax.wsdl.Types; +import javax.wsdl.extensions.UnknownExtensibilityElement; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.extensions.soap12.SOAP12Address; +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.stream.XMLInputFactory; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.addressing.AddressingConstants; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.client.Options; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.ConfigurationContextFactory; +import org.apache.axis2.deployment.DeploymentEngine; +import org.apache.axis2.deployment.DeploymentErrorMsgs; +import org.apache.axis2.deployment.DeploymentException; +import org.apache.axis2.deployment.ModuleBuilder; +import org.apache.axis2.deployment.URLBasedAxisConfigurator; +import org.apache.axis2.deployment.util.Utils; +import org.apache.axis2.description.AxisEndpoint; +import org.apache.axis2.description.AxisModule; +import org.apache.axis2.description.AxisOperation; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.description.Parameter; +import org.apache.axis2.description.Version; +import org.apache.axis2.description.WSDL11ToAxisServiceBuilder; +import org.apache.axis2.description.WSDL2Constants; +import org.apache.axis2.description.WSDLToAxisServiceBuilder; +import org.apache.axis2.engine.AxisConfiguration; +import org.apache.axis2.engine.MessageReceiver; +import org.apache.axis2.i18n.Messages; +import org.apache.tuscany.sca.assembly.AbstractContract; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.common.xml.XMLDocumentHelper; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.extensibility.ClassLoaderContext; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; +import org.apache.tuscany.sca.xsd.XSDefinition; +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaExternal; +import org.apache.ws.commons.schema.resolver.URIResolver; +import org.oasisopen.sca.ServiceRuntimeException; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + + +public class Axis2EngineIntegration { + + //========================================================= + // most of the following is related to rewriting WSDL imports + // I'd like to move this but don't know where to yet. + + public static final String IMPORT_TAG = "import"; + public static final String INCLUDE_TAG = "include"; + + public static final QName QNAME_WSA_ADDRESS = + new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.EPR_ADDRESS); + public static final QName QNAME_WSA_FROM = + new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.WSA_FROM); + public static final QName QNAME_WSA_REFERENCE_PARAMETERS = + new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.EPR_REFERENCE_PARAMETERS); + + //Schema element names + public static final String ELEM_SCHEMA = "schema"; + + //Schema URI + public static final String NS_URI_XSD_1999 = "http://www.w3.org/1999/XMLSchema"; + public static final String NS_URI_XSD_2000 = "http://www.w3.org/2000/10/XMLSchema"; + public static final String NS_URI_XSD_2001 = "http://www.w3.org/2001/XMLSchema"; + + //Schema QNames + public static final QName Q_ELEM_XSD_1999 = new QName(NS_URI_XSD_1999, ELEM_SCHEMA); + public static final QName Q_ELEM_XSD_2000 = new QName(NS_URI_XSD_2000, ELEM_SCHEMA); + public static final QName Q_ELEM_XSD_2001 = new QName(NS_URI_XSD_2001, ELEM_SCHEMA); + public static final List<QName> XSD_QNAME_LIST = + Arrays.asList(new QName[] {Q_ELEM_XSD_1999, Q_ELEM_XSD_2000, Q_ELEM_XSD_2001}); + + //========================================================= + + /* + * Create the whole configuration context for the Axis engine + */ + private static class Axis2Config { + private ClassLoaderContext classLoaderContext; + private URL axis2xmlURL; + private URL repositoryURL; + } + + // Cache the discovered axis2 configuration but we need to create a new instance of ConfigurationContext every time + private static Axis2Config axis2Config; + + public synchronized static ConfigurationContext getAxisConfigurationContext(final ServiceDiscovery serviceDiscovery) { + + // get the axis configuration context from the Tuscany axis2.xml file + // Allow privileged access to read properties. Requires PropertyPermission read in + // security policy. + if (axis2Config == null) { + try { + axis2Config = AccessController.doPrivileged(new PrivilegedExceptionAction<Axis2Config>() { + public Axis2Config run() throws AxisFault, MalformedURLException { + // collect together the classloaders that Axis2 requires in order to load + // pluggable items such as the Tuscany MessageReceivers and the Xerces + // document builder. + ClassLoader wsBindingCL = getClass().getClassLoader(); + ClassLoader axis2CL = URLBasedAxisConfigurator.class.getClassLoader(); + ClassLoaderContext classLoaderContext = new ClassLoaderContext(wsBindingCL, axis2CL); + + classLoaderContext = new ClassLoaderContext(classLoaderContext.getClassLoader(), + serviceDiscovery, + XMLInputFactory.class, + DocumentBuilderFactory.class); + + URL axis2xmlURL = wsBindingCL.getResource("org/apache/tuscany/sca/binding/ws/axis2/engine/conf/tuscany-axis2.xml"); + + if (axis2xmlURL != null) { + URL repositoryURL = new URL(axis2xmlURL, "../repository/"); + Axis2Config config = new Axis2Config(); + config.classLoaderContext = classLoaderContext; + config.axis2xmlURL = axis2xmlURL; + config.repositoryURL = repositoryURL; + return config; + } else { + return null; + } + } + }); + } catch (PrivilegedActionException e) { + throw new ServiceRuntimeException(e.getException()); + } + } + + if (axis2Config == null) { + return null; + } + + try { + return AccessController.doPrivileged(new PrivilegedExceptionAction<ConfigurationContext>() { + public ConfigurationContext run() throws AxisFault { + ClassLoader oldTCCL = axis2Config.classLoaderContext.setContextClassLoader(); + try { + ConfigurationContext configurationContext = + ConfigurationContextFactory.createConfigurationContextFromURIs(axis2Config.axis2xmlURL, + axis2Config.repositoryURL); + return configurationContext; + } finally { + if (oldTCCL != null) { + Thread.currentThread().setContextClassLoader(oldTCCL); + } + } + } + }); + } catch (PrivilegedActionException e) { + throw new ServiceRuntimeException(e.getException()); + } + } + + // Some code to programatically load an Axis2 module only if we need it + // currently hard coded to load rampart only. Needs generalization + public synchronized static void loadRampartModule(ConfigurationContext axis2ConfigContext) { + try { + final AxisConfiguration axisConfiguration = axis2ConfigContext.getAxisConfiguration(); + final URL rampartURL = new URL(axis2Config.repositoryURL.toString() + "modules/rampart-1.4.mar"); + + ClassLoader deploymentClassLoader = org.apache.axis2.deployment.util.Utils.createClassLoader( + new URL[]{rampartURL}, + axisConfiguration.getModuleClassLoader(), + true, + (File) axisConfiguration.getParameterValue(Constants.Configuration.ARTIFACTS_TEMP_DIR)); + + final AxisModule module = new AxisModule(); + module.setModuleClassLoader(deploymentClassLoader); + module.setParent(axisConfiguration); + + if (module.getName() == null) { + module.setName("rampart-1.4"); + module.setVersion(new Version("1.4")); + } + + populateModule(axis2ConfigContext, module, rampartURL); + module.setFileName(rampartURL); + + // Allow privileged access to read properties. Requires PropertiesPermission read in + // security policy. + try { + AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { + public Object run() throws IOException { + DeploymentEngine.addNewModule(module, axisConfiguration); + return null; + } + }); + } catch (PrivilegedActionException e) { + throw (AxisFault)e.getException(); + } + + org.apache.axis2.util.Utils.calculateDefaultModuleVersion(axisConfiguration.getModules(), + axisConfiguration); + axisConfiguration.validateSystemPredefinedPhases(); + } catch (IOException e) { + throw new ServiceRuntimeException(e); + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } + + private static void populateModule(ConfigurationContext axis2ConfigContext, AxisModule module, URL moduleUrl) throws DeploymentException { + try { + ClassLoader classLoader = module.getModuleClassLoader(); + InputStream moduleStream = classLoader.getResourceAsStream("META-INF/module.xml"); + if (moduleStream == null) { + moduleStream = classLoader.getResourceAsStream("meta-inf/module.xml"); + } + if (moduleStream == null) { + throw new DeploymentException(Messages.getMessage(DeploymentErrorMsgs.MODULE_XML_MISSING, moduleUrl.toString())); + } + ModuleBuilder moduleBuilder = new ModuleBuilder(moduleStream, module, axis2ConfigContext.getAxisConfiguration()); + moduleBuilder.populateModule(); + } catch (IOException e) { + throw new DeploymentException(e); + } + } + + //========================================================= + + /** + * Create an AxisService from the Java interface class of the SCA service interface + */ + public static AxisService createJavaAxisService(String endpointURL, + ConfigurationContext configContext, + AbstractContract contract) throws AxisFault { + AxisService axisService = new AxisService(); + String path = URI.create(endpointURL).getPath(); + axisService.setName(path); + axisService.setServiceDescription("Tuscany configured AxisService for service: " + endpointURL); + axisService.setClientSide(false); + Parameter classParam = + new Parameter(Constants.SERVICE_CLASS, + ((JavaInterface)contract.getInterfaceContract().getInterface()).getJavaClass().getName()); + axisService.addParameter(classParam); + try { + Utils.fillAxisService(axisService, configContext.getAxisConfiguration(), null, null); + } catch (Exception e) { + throw new RuntimeException(e); + } + + return axisService; + } + + //========================================================= + + /** + * Create an AxisService from the WSDL doc used by ws binding + */ + public static AxisService createWSDLAxisService(String endpointURL, + Port port, + WebServiceBinding wsBinding) throws AxisFault { + + Definition definition = wsBinding.getGeneratedWSDLDocument(); + QName serviceQName = wsBinding.getService().getQName(); + Definition def = getDefinition(definition, serviceQName); + + ClassLoader oldTCCL = axis2Config.classLoaderContext.setContextClassLoader(); + final WSDLToAxisServiceBuilder builder; + try { + builder = new WSDL11ToAxisServiceBuilder(def, serviceQName, port.getName()); + } finally { + if (oldTCCL != null) { + Thread.currentThread().setContextClassLoader(oldTCCL); + } + } + //final WSDLToAxisServiceBuilder builder = new WSDL11ToAxisServiceBuilder(def, serviceQName, port.getName()); + + + builder.setServerSide(true); + // [rfeng] Add a custom resolver to work around WSCOMMONS-228 + // TODO - 228 is resolved, is this still required + builder.setCustomResolver(new URIResolverImpl(def)); + builder.setBaseUri(def.getDocumentBaseURI()); + // [rfeng] + // AxisService axisService = builder.populateService(); + // Allow privileged access to read properties. Requires PropertiesPermission read in + // security policy. + AxisService axisService; + try { + axisService = AccessController.doPrivileged(new PrivilegedExceptionAction<AxisService>() { + public AxisService run() throws AxisFault { + return builder.populateService(); + } + }); + } catch (PrivilegedActionException e) { + throw (AxisFault)e.getException(); + } + + String name = URI.create(endpointURL).getPath(); + //[nash] HTTP endpoints need a leading slash for WSDL imports to work with ?wsdl + if (endpointURL.startsWith("jms")) { + name = name.startsWith("/") ? name.substring(1) : name; + } + axisService.setName(name); + axisService.setEndpointURL(endpointURL); + axisService.setDocumentation("Tuscany configured AxisService for service: " + endpointURL); + + // TODO - again, do we ever have more than one endpoint + // on the service side? + for (Iterator i = axisService.getEndpoints().values().iterator(); i.hasNext();) { + AxisEndpoint ae = (AxisEndpoint)i.next(); + if (endpointURL.startsWith("jms")) { +// not in Axis2 1.5.1 +// Parameter qcf = new Parameter(JMSConstants.CONFAC_PARAM, null); +// qcf.setValue(DEFAULT_QUEUE_CONNECTION_FACTORY); +// axisService.addParameter(qcf); + break; + } + } + + // Add schema information to the AxisService (needed for "?xsd=" support) + addSchemas(wsBinding.getUserSpecifiedWSDLDefinition(), axisService); + + // Use the existing WSDL + Parameter wsdlParam = new Parameter("wsdl4jDefinition", null); + wsdlParam.setValue(definition); + axisService.addParameter(wsdlParam); + Parameter userWSDL = new Parameter("useOriginalwsdl", "true"); + axisService.addParameter(userWSDL); + + // Modify schema imports and includes to add "servicename?xsd=" prefix. + // Axis2 does this for schema extensibility elements, but Tuscany has + // overriden the WSDl4J deserializer to create UnknownExtensibilityElement + // elements in place of these. + modifySchemaImportsAndIncludes(definition, name); + + // Axis2 1.3 has a bug with returning incorrect values for the port + // addresses. To work around this, compute the values here. + Parameter modifyAddr = new Parameter("modifyUserWSDLPortAddress", "false"); + axisService.addParameter(modifyAddr); + + return axisService; + } + + + /** + * Workaround for https://issues.apache.org/jira/browse/AXIS2-3205 + */ + private static Definition getDefinition(Definition definition, QName serviceName) { + + if (serviceName == null) { + return definition; + } + + if (definition == null) { + return null; + } + Object service = definition.getServices().get(serviceName); + if (service != null) { + return definition; + } + for (Object i : definition.getImports().values()) { + List<Import> imports = (List<Import>)i; + for (Import imp : imports) { + Definition d = getDefinition(imp.getDefinition(), serviceName); + if (d != null) { + return d; + } + } + } + return null; + } + + private static void addSchemas(WSDLDefinition wsdlDef, AxisService axisService) { + for (XSDefinition xsDef : wsdlDef.getXmlSchemas()) { + if (xsDef.getSchema() != null) { + axisService.addSchema(xsDef.getSchema()); + updateSchemaRefs(xsDef.getSchema(), axisService.getName()); + } + } + for (WSDLDefinition impDef : wsdlDef.getImportedDefinitions()) { + addSchemas(impDef, axisService); + } + } + + private static void updateSchemaRefs(XmlSchema parentSchema, String name) { + for (Iterator iter = parentSchema.getIncludes().getIterator(); iter.hasNext();) { + Object obj = iter.next(); + if (obj instanceof XmlSchemaExternal) { + XmlSchemaExternal extSchema = (XmlSchemaExternal)obj; + String location = extSchema.getSchemaLocation(); + if (location.length() > 0 && location.indexOf(":/") < 0 && location.indexOf("?xsd=") < 0) { + extSchema.setSchemaLocation(name + "?xsd=" + location); + } + if (extSchema.getSchema() != null) { + updateSchemaRefs(extSchema.getSchema(), name); + } + } + } + } + + private static void modifySchemaImportsAndIncludes(Definition definition, String name) { + // adjust the schema locations in types section + Types types = definition.getTypes(); + if (types != null) { + for (Iterator iter = types.getExtensibilityElements().iterator(); iter.hasNext();) { + Object ext = iter.next(); + if (ext instanceof UnknownExtensibilityElement && XSD_QNAME_LIST + .contains(((UnknownExtensibilityElement)ext).getElementType())) { + changeLocations(((UnknownExtensibilityElement)ext).getElement(), name); + } + } + } + for (Iterator iter = definition.getImports().values().iterator(); iter.hasNext();) { + Vector values = (Vector)iter.next(); + for (Iterator valuesIter = values.iterator(); valuesIter.hasNext();) { + Import wsdlImport = (Import)valuesIter.next(); + modifySchemaImportsAndIncludes(wsdlImport.getDefinition(), name); + } + } + } + + private static void changeLocations(Element element, String name) { + NodeList nodeList = element.getChildNodes(); + for (int i = 0; i < nodeList.getLength(); i++) { + String tagName = nodeList.item(i).getLocalName(); + if (IMPORT_TAG.equals(tagName) || INCLUDE_TAG.equals(tagName)) { + processImport(nodeList.item(i), name); + } + } + } + + private static void processImport(Node importNode, String name) { + NamedNodeMap nodeMap = importNode.getAttributes(); + for (int i = 0; i < nodeMap.getLength(); i++) { + Node attribute = nodeMap.item(i); + if (attribute.getNodeName().equals("schemaLocation")) { + String location = attribute.getNodeValue(); + if (location.indexOf(":/") < 0 & location.indexOf("?xsd=") < 0) { + attribute.setNodeValue(name + "?xsd=" + location); + } + } + } + } + + //========================================================= + + /* + * Create the service message receivers and the service provider that will push + * messages out onto the binding wire + */ + public static void createAxisServiceProviders(AxisService axisService, + RuntimeEndpoint endpoint, + WebServiceBinding wsBinding, + ExtensionPointRegistry extensionPoints) { + for (Iterator<?> i = axisService.getOperations(); i.hasNext();) { + AxisOperation axisOp = (AxisOperation)i.next(); + Operation op = getOperation(axisOp, wsBinding); + if (op != null) { + + if (op.isNonBlocking()) { + axisOp.setMessageExchangePattern(WSDL2Constants.MEP_URI_IN_ONLY); + } else { + axisOp.setMessageExchangePattern(WSDL2Constants.MEP_URI_IN_OUT); + } + + MessageReceiver msgrec = null; + TuscanyServiceProvider serviceProvider = new TuscanyServiceProvider(extensionPoints, endpoint, wsBinding, op); + if (op.isNonBlocking()) { + msgrec = new Axis2ServiceInMessageReceiver(serviceProvider); + } else { + msgrec = new Axis2ServiceInOutSyncMessageReceiver(serviceProvider); + } + axisOp.setMessageReceiver(msgrec); + } + } + } + + private static Operation getOperation(AxisOperation axisOp,WebServiceBinding wsBinding) { + String operationName = axisOp.getName().getLocalPart(); + Interface iface = wsBinding.getBindingInterfaceContract().getInterface(); + for (Operation op : iface.getOperations()) { + if (op.getName().equalsIgnoreCase(operationName)) { + return op; + } + } + return null; + } + + //========================================================= + + public static String getPortAddress(Port port) { + Object ext = port.getExtensibilityElements().get(0); + if (ext instanceof SOAPAddress) { + return ((SOAPAddress)ext).getLocationURI(); + } + if (ext instanceof SOAP12Address) { + return ((SOAP12Address)ext).getLocationURI(); + } + return null; + } + + public static void setPortAddress(Port port, String locationURI) { + Object ext = port.getExtensibilityElements().get(0); + if (ext instanceof SOAPAddress) { + ((SOAPAddress)ext).setLocationURI(locationURI); + } + if (ext instanceof SOAP12Address) { + ((SOAP12Address)ext).setLocationURI(locationURI); + } + } + + /** + * This method is copied from AxisService.createClientSideAxisService to + * work around http://issues.apache.org/jira/browse/WSCOMMONS-228 + * + * @param wsdlDefinition + * @param wsdlServiceName + * @param portName + * @param options + * @return + * @throws AxisFault + */ + @Deprecated + public static AxisService createClientSideAxisService(Definition definition, + QName serviceName, + String portName, + Options options) throws AxisFault { + Definition def = getDefinition(definition, serviceName); + final WSDL11ToAxisServiceBuilder serviceBuilder = new WSDL11ToAxisServiceBuilder(def, serviceName, portName); + serviceBuilder.setServerSide(false); + // [rfeng] Add a custom resolver to work around WSCOMMONS-228 + serviceBuilder.setCustomResolver(new URIResolverImpl(def)); + serviceBuilder.setBaseUri(def.getDocumentBaseURI()); + // [rfeng] + // Allow access to read properties. Requires PropertiesPermission in security policy. + AxisService axisService; + try { + axisService = AccessController.doPrivileged(new PrivilegedExceptionAction<AxisService>() { + public AxisService run() throws AxisFault { + return serviceBuilder.populateService(); + } + }); + } catch ( PrivilegedActionException e ) { + throw (AxisFault) e.getException(); + } + + AxisEndpoint axisEndpoint = (AxisEndpoint)axisService.getEndpoints().get(axisService.getEndpointName()); + options.setTo(new EndpointReference(axisEndpoint.getEndpointURL())); + if (axisEndpoint != null) { + options.setSoapVersionURI((String)axisEndpoint.getBinding().getProperty(WSDL2Constants.ATTR_WSOAP_VERSION)); + } + return axisService; + } + + /** + * URI resolver implementation for XML schema + */ + public static class URIResolverImpl implements URIResolver { + private Definition definition; + + public URIResolverImpl(Definition definition) { + this.definition = definition; + } + + public org.xml.sax.InputSource resolveEntity(java.lang.String targetNamespace, + java.lang.String schemaLocation, + java.lang.String baseUri) { + try { + if (baseUri == null) { + baseUri = definition.getDocumentBaseURI(); + } + URL url = new URL(new URL(baseUri), schemaLocation); + return XMLDocumentHelper.getInputSource(url); + } catch (IOException e) { + return null; + } + } + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingInvoker.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingInvoker.java new file mode 100644 index 0000000000..c7b81ccac1 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingInvoker.java @@ -0,0 +1,433 @@ +/* + * 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.axis2.provider; + +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.wsdl.BindingOperation; +import javax.wsdl.Operation; +import javax.wsdl.PortType; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMAttribute; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNode; +import org.apache.axiom.soap.SOAPBody; +import org.apache.axiom.soap.SOAPEnvelope; +import org.apache.axiom.soap.SOAPFactory; +import org.apache.axiom.soap.SOAPHeader; +import org.apache.axis2.AxisFault; +import org.apache.axis2.addressing.AddressingConstants; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.addressing.EndpointReferenceHelper; +import org.apache.axis2.addressing.wsdl.WSDL11ActionHelper; +import org.apache.axis2.client.OperationClient; +import org.apache.axis2.client.Options; +import org.apache.axis2.client.ServiceClient; +import org.apache.axis2.context.MessageContext; +import org.apache.tuscany.sca.assembly.AssemblyFactory; +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.binding.ws.WebServiceBindingFactory; +import org.apache.tuscany.sca.binding.ws.axis2.context.WSAxis2BindingContext; +import org.apache.tuscany.sca.context.CompositeContext; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory; +import org.apache.tuscany.sca.core.invocation.AsyncResponseInvoker; +import org.apache.tuscany.sca.core.invocation.Constants; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; +import org.oasisopen.sca.ServiceRuntimeException; + + +/** + * Axis2BindingInvoker creates an Axis2 OperationClient to pass down the + * binding chain + * + * @version $Rev$ $Date$ + */ +public class Axis2ReferenceBindingInvoker implements Invoker { + public static final QName QNAME_WSA_FROM = + new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.WSA_FROM, AddressingConstants.WSA_DEFAULT_PREFIX); + public static final QName QNAME_WSA_TO = + new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.WSA_TO, AddressingConstants.WSA_DEFAULT_PREFIX); + public static final QName QNAME_WSA_ACTION = + new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.WSA_ACTION, AddressingConstants.WSA_DEFAULT_PREFIX); + public static final QName QNAME_WSA_RELATESTO = + new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.WSA_RELATES_TO, AddressingConstants.WSA_DEFAULT_PREFIX); + public static final QName QNAME_WSA_MESSAGEID = + new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.WSA_MESSAGE_ID, AddressingConstants.WSA_DEFAULT_PREFIX); + + + private RuntimeEndpointReference endpointReference; + private ServiceClient serviceClient; + private QName wsdlOperationName; + private Options options; + private SOAPFactory soapFactory; + private WebServiceBinding wsBinding; + + public Axis2ReferenceBindingInvoker(RuntimeEndpointReference endpointReference, + ServiceClient serviceClient, + QName wsdlOperationName, + Options options, + SOAPFactory soapFactory, + WebServiceBinding wsBinding) { + this.endpointReference = endpointReference; + this.serviceClient = serviceClient; + this.wsdlOperationName = wsdlOperationName; + this.options = options; + this.soapFactory = soapFactory; + this.wsBinding = wsBinding; + } + + public Message invoke(Message msg) { + try { + final OperationClient operationClient = createOperationClient(msg); + WSAxis2BindingContext bindingContext = new WSAxis2BindingContext(); + bindingContext.setAxisOperationClient(operationClient); + bindingContext.setAxisOutMessageContext(operationClient.getMessageContext("Out")); + // set in the transport invoker when the response is received + //bindingContext.setAxisInMessageContext(operationClient.getMessageContext("In")); + msg.setBindingContext(bindingContext); + + msg = endpointReference.getBindingInvocationChain().getHeadInvoker().invoke(msg); + + if (wsBinding.isRpcLiteral()){ + // remove the wrapping element containing + // the operation response name + OMElement operationResponseElement = msg.getBody(); + if (operationResponseElement != null){ + msg.setBody(operationResponseElement.getChildElements().next()); + } + } + + } catch (AxisFault e) { + if (e.getDetail() != null ) { + FaultException f = new FaultException(e.getMessage(), e.getDetail(), e); + f.setFaultName(e.getDetail().getQName()); + msg.setFaultBody(f); + } else { + msg.setFaultBody(e); + } + } catch (Throwable e) { + msg.setFaultBody(e); + } + + return msg; + } + + @SuppressWarnings("deprecation") + protected OperationClient createOperationClient(Message msg) throws AxisFault { + SOAPEnvelope env = soapFactory.getDefaultEnvelope(); + Object[] args = (Object[])msg.getBody(); + if (args != null && args.length > 0) { + + if (wsBinding.isRpcLiteral()){ + // create the wrapping element containing + // the operation name + OMFactory factory = OMAbstractFactory.getOMFactory(); + 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(); + } + + QName operationQName = new QName(wrapperNamespace, + msg.getOperation().getName()); + OMElement operationNameElement = factory.createOMElement(operationQName); + + // add the parameters as children of the operation name element + for (Object bc : args) { + if (bc instanceof OMElement) { + operationNameElement.addChild((OMElement)bc); + } else { + throw new IllegalArgumentException( "Can't handle mixed payloads between OMElements and other types for endpoint reference " + endpointReference); + } + } + + SOAPBody body = env.getBody(); + body.addChild(operationNameElement); + + } 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 if (wsBinding.isDocLiteralUnwrapped()){ + // throw new ServiceRuntimeException("doc/literal/unwrapped WSDL style not supported for endpoint reference " + endpointReference); + } else if (wsBinding.isDocLiteralWrapped() || + wsBinding.isDocLiteralUnwrapped()){ + // it's doc/lit + SOAPBody body = env.getBody(); + for (Object bc : args) { + if (bc instanceof OMElement) { + body.addChild((OMElement)bc); + } else { + throw new IllegalArgumentException( "Can't handle mixed payloads between OMElements and other types for endpoint reference " + endpointReference); + } + } + } else { + throw new ServiceRuntimeException("Unrecognized WSDL style for endpoint reference " + endpointReference); + } + } + + final MessageContext requestMC = new MessageContext(); + requestMC.setEnvelope(env); + + // Axis2 operationClients can not be shared so create a new one for each request + final OperationClient operationClient = serviceClient.createClient(wsdlOperationName); + operationClient.setOptions(options); + + Endpoint callbackEndpoint; + AsyncResponseInvoker<String> respInvoker = (AsyncResponseInvoker<String>) msg.getHeaders().get(Constants.ASYNC_RESPONSE_INVOKER); + if( respInvoker != null ) { + callbackEndpoint = createAsyncResponseEndpoint( msg, respInvoker ); + msg.setTo(callbackEndpoint); + } else { + callbackEndpoint = msg.getFrom().getCallbackEndpoint(); + } // end if + + SOAPEnvelope sev = requestMC.getEnvelope(); + SOAPHeader sh = sev.getHeader(); + + // Add WS-Addressing header for the invocation of a bidirectional service + 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 ); + addWSAActionHeader( sh ); + addWSAMessageIDHeader( sh, (String)msg.getHeaders().get("MESSAGE_ID")); + + requestMC.setFrom(fromEPR); + } // end if + + String toAddress = getToAddress( msg ); + requestMC.setTo( new EndpointReference(toAddress) ); + + // For callback references, add wsa:To, wsa:Action and wsa:RelatesTo headers + if( isInvocationForCallback( msg ) ) { + addWSAToHeader( sh, toAddress, msg ); + addWSAActionHeader( sh ); + addWSARelatesTo( sh, msg ); + } // end if + + // Allow privileged access to read properties. Requires PropertiesPermission read in security policy. + try { + AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { + public Object run() throws AxisFault { + operationClient.addMessageContext(requestMC); + return null; + } + }); + } catch (PrivilegedActionException e) { + throw (AxisFault)e.getException(); + } + return operationClient; + } // end method createOperationClient + + /** + * Create an Async Response Endpoint + * @param msg - the Tuscany message + * @param respInvoker - the AsyncResponseInvoker for the async response + * @return - an Endpoint which embodies the callback address + */ + private Endpoint createAsyncResponseEndpoint(Message msg, + AsyncResponseInvoker<String> respInvoker) { + String callbackAddress = respInvoker.getResponseTargetAddress(); + if( callbackAddress == null ) return null; + + // Get the necessary factories + ExtensionPointRegistry registry = endpointReference.getCompositeContext().getExtensionPointRegistry(); + FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); + RuntimeAssemblyFactory assemblyFactory = (RuntimeAssemblyFactory)modelFactories.getFactory(AssemblyFactory.class); + WebServiceBindingFactory webServiceBindingFactory = (WebServiceBindingFactory)modelFactories.getFactory(WebServiceBindingFactory.class); + + // Create the endpoint + RuntimeEndpoint callbackEndpoint = (RuntimeEndpoint)assemblyFactory.createEndpoint(); + // Add a binding + WebServiceBinding cbBinding = webServiceBindingFactory.createWebServiceBinding(); + cbBinding.setURI(callbackAddress); + callbackEndpoint.setBinding(cbBinding); + // Embed the response Address URI + callbackEndpoint.setURI(callbackAddress); + callbackEndpoint.setUnresolved(true); + return callbackEndpoint; + } // end method createAsyncResponseEndpoint + + 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 + if (options.getTo() == null) { + Endpoint ep = msg.getTo(); + if (ep != null && ep.getBinding() != null) { + address = ep.getBinding().getURI(); + } else { + throw new ServiceRuntimeException("[BWS20025] Unable to determine destination endpoint for endpoint reference " + endpointReference); + } + } else { + address = options.getTo().getAddress(); + } + + return address; + } // end method getToAddress + + /** + * Add wsa:From SOAP header to the message + * @param sh - the SOAP header for the message + * @param fromEPR - the (Axis2) EPR to include in the wsa:From + * @throws AxisFault - if an error occurs setting the wsa:From into the header + */ + 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 + + /** + * Add wsa:MessageID SOAP header to the message + * @param sh - the SOAP header for the message + * @param msgID - the message ID + * @throws AxisFault - if an error occurs setting the wsa:From into the header + */ + private void addWSAMessageIDHeader( SOAPHeader sh, String msgID ) throws AxisFault { + if( msgID == null ) return; + OMElement idHeader = sh.getOMFactory().createOMElement(QNAME_WSA_MESSAGEID); + idHeader.setText( msgID ); + + sh.addChild(idHeader); + } // end method addWSAMessageIDHeader + + private static String WS_REF_PARMS = "WS_REFERENCE_PARAMETERS"; + /** + * Add wsa:To SOAP header to the message - also handles ReferenceParameters, if present + * @param sh - the SOAP header for the message + * @param address - the address to use + * @param msg - the Tuscany message + */ + private void addWSAToHeader( SOAPHeader sh, String address, Message msg ) { + if( address == null ) return; + + // 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); + + if( msg == null ) return; + + // Deal with Reference Parameters, if present - copy to the header without the wsa:ReferenceParameters wrapper + OMElement refParms = (OMElement) msg.getHeaders().get(WS_REF_PARMS); + if( refParms != null ) { + Iterator<?> children = refParms.getChildren(); + while( children.hasNext() ) { + OMNode node = (OMNode) children.next(); + sh.addChild(node); + } + } // end if + + } // end method addWSAActionHeader + + + private void addWSAActionHeader( SOAPHeader sh ) { + // Create wsa:Action header which is required by ws-addressing spec + String action = options.getAction(); + + if (action == null) { + PortType portType = ((WSDLInterface)wsBinding.getBindingInterfaceContract().getInterface()).getPortType(); + Operation op = portType.getOperation(wsdlOperationName.getLocalPart(), null, null); + action = WSDL11ActionHelper.getActionFromInputElement(wsBinding.getGeneratedWSDLDocument(), portType, op, op.getInput()); + } + + OMElement actionOM = sh.getOMFactory().createOMElement(QNAME_WSA_ACTION); + actionOM.setText(action == null ? "" : action); + sh.addChild(actionOM); + } // end method addWSAActionHeader + + private static String WS_MESSAGE_ID = "WS_MESSAGE_ID"; + 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 + */ + private void addWSARelatesTo( SOAPHeader sh, Message msg ) { + String idValue = (String) msg.getHeaders().get("RELATES_TO"); + if( idValue != null ){ + 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 + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingProvider.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingProvider.java new file mode 100644 index 0000000000..7b22dc443b --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingProvider.java @@ -0,0 +1,390 @@ +/* + * 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.axis2.provider; + +import java.io.IOException; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.Collection; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPOperation; +import javax.wsdl.extensions.soap12.SOAP12Address; +import javax.wsdl.extensions.soap12.SOAP12Binding; +import javax.xml.namespace.QName; +import javax.xml.stream.FactoryConfigurationError; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.transform.dom.DOMSource; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.axiom.soap.SOAPFactory; +import org.apache.axis2.AxisFault; +import org.apache.axis2.addressing.EndpointReferenceHelper; +import org.apache.axis2.client.Options; +import org.apache.axis2.client.ServiceClient; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.transport.http.HTTPConstants; +import org.apache.axis2.util.threadpool.ThreadPool; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; +import org.apache.commons.httpclient.params.HttpConnectionManagerParams; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.axis2.transport.TransportReferenceInterceptor; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.policy.PolicySubject; +import org.apache.tuscany.sca.policy.util.PolicyHelper; +import org.apache.tuscany.sca.provider.EndpointReferenceProvider; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; +import org.oasisopen.sca.ServiceRuntimeException; + +public class Axis2ReferenceBindingProvider extends Axis2BaseBindingProvider implements EndpointReferenceProvider { + + // the endpoint reference configuration that's driving this binding provider + // and some convenience data retrieved from the endpoint reference + private RuntimeEndpointReference endpointReference; + private RuntimeComponent component; + private RuntimeComponentReference reference; + private WebServiceBinding wsBinding; + + // The Axis2 configuration that the binding creates + private ServiceClient serviceClient; + private AxisService axisClientSideService; + + + public Axis2ReferenceBindingProvider(ExtensionPointRegistry extensionPoints, + EndpointReference endpointReference) { + + super(extensionPoints); + + this.endpointReference = (RuntimeEndpointReference)endpointReference; + + this.wsBinding = (WebServiceBinding)endpointReference.getBinding(); + this.component = (RuntimeComponent)endpointReference.getComponent(); + this.reference = (RuntimeComponentReference)endpointReference.getReference(); + + // A WSDL document should always be present in the binding + if (wsBinding.getGeneratedWSDLDocument() == null) { + throw new ServiceRuntimeException("No WSDL document for " + component.getName() + "/" + reference.getName()); + } + + // Set to use the Axiom data binding + InterfaceContract contract = wsBinding.getBindingInterfaceContract(); + if (contract.getInterface() != null) { + contract.getInterface().resetDataBinding(OMElement.class.getName()); + } + + // TODO - why don't intents get aggregated to EPR correctly? + isSOAP11Required = PolicyHelper.isIntentRequired((PolicySubject)wsBinding, Constants.SOAP11_INTENT); + isSOAP12Required = PolicyHelper.isIntentRequired((PolicySubject)wsBinding, Constants.SOAP12_INTENT); + + isMTOMRequired = PolicyHelper.isIntentRequired((PolicySubject)wsBinding, Axis2BindingProviderFactory.MTOM_INTENT); + + // if the endpoint contains any WS Policy expressions then we probably need rampart + // TODO - need to take into account Axis configuration policy also + QName wsPolicyQName = new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "Policy"); + if (PolicyHelper.getPolicies(endpointReference, wsPolicyQName).size() > 0){ + isRampartRequired = true; + } + + // Validate the configuration for provided policies + + // check the WSDL style as we currently only support some of them + if (wsBinding.isRpcEncoded()){ + throw new ServiceRuntimeException("rpc/encoded WSDL style not supported. Component " + endpointReference.getComponent().getName() + + " Reference " + endpointReference.getReference() + + " Binding " + endpointReference.getBinding().getName()); + } + + if (wsBinding.isDocEncoded()){ + throw new ServiceRuntimeException("doc/encoded WSDL style not supported. Component " + endpointReference.getComponent().getName() + + " Reference " + endpointReference.getReference() + + " Binding " + endpointReference.getBinding().getName()); + } + + if (wsBinding.isDocLiteralUnwrapped()){ + //throw new ServiceRuntimeException("doc/literal/unwrapped WSDL style not supported for endpoint reference " + endpointReference); + } + + // Validate that the WSDL is not using SOAP v1.2 if requires="SOAP.v1_1" has been specified + if ( isSOAP11Required ) { + Definition def = wsBinding.getGeneratedWSDLDocument(); + Binding binding = def.getBinding(wsBinding.getBinding().getQName()); + for ( Object ext : binding.getExtensibilityElements() ) { + if ( ext instanceof SOAP12Binding ) + throw new ServiceRuntimeException("WSDL document is using SOAP v1.2 but SOAP v1.1 " + + "is required by the specified policy intents"); + } + } + + // Validate that the WSDL is not using SOAP v1.1 if requires="SOAP.v1_2" has been specified + if ( isSOAP12Required ) { + Definition def = wsBinding.getGeneratedWSDLDocument(); + Binding binding = def.getBinding(wsBinding.getBinding().getQName()); + for ( Object ext : binding.getExtensibilityElements() ) { + if ( ext instanceof SOAPBinding ) + throw new ServiceRuntimeException("WSDL document is using SOAP v1.1 but SOAP v1.2 " + + "is required by the specified policy intents"); + } + } + } + + public void start() { + configContext = Axis2EngineIntegration.getAxisConfigurationContext(extensionPoints.getServiceDiscovery()); + + // Apply the configuration from any other policies + + if (isRampartRequired){ + Axis2EngineIntegration.loadRampartModule(configContext); + } + + for (PolicyProvider pp : this.endpointReference.getPolicyProviders()) { + pp.configureBinding(this); + } + + try { + Definition definition = wsBinding.getGeneratedWSDLDocument(); + QName serviceQName = wsBinding.getService().getQName(); + Port port = wsBinding.getPort(); + if (port == null) { + // service has multiple ports, select one port to use + // TODO - it feels like there is much more to this than is + // here at the moment as need to match with the service side + // assuming that it's available + Collection<Port> ports = wsBinding.getService().getPorts().values(); + for (Port p : ports) { + // look for a SOAP 1.1 port first + if (p.getExtensibilityElements().get(0) instanceof SOAPAddress) { + port = p; + break; + } + } + if (port == null) { + // no SOAP 1.1 port available, so look for a SOAP 1.2 port + for (Port p : ports) { + if (p.getExtensibilityElements().get(0) instanceof SOAP12Address) { + port = p; + break; + } + } + } + } + + axisClientSideService = Axis2EngineIntegration.createClientSideAxisService(definition, serviceQName, port.getName(), new Options()); + + HttpClient httpClient = (HttpClient)configContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT); + if (httpClient == null) { + MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); + HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams(); + connectionManagerParams.setDefaultMaxConnectionsPerHost(2); + connectionManagerParams.setTcpNoDelay(true); + connectionManagerParams.setStaleCheckingEnabled(true); + connectionManagerParams.setLinger(0); + connectionManager.setParams(connectionManagerParams); + httpClient = new HttpClient(connectionManager); + configContext.setThreadPool(new ThreadPool(1, 5)); + configContext.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE); + configContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); + } + + serviceClient = new ServiceClient(configContext, axisClientSideService); + + } catch (AxisFault e) { + throw new RuntimeException(e); // TODO: better exception + } + } + + public void stop() { + if (serviceClient != null) { + // close all connections that we have initiated, so that the jetty server + // can be restarted without seeing ConnectExceptions + HttpClient httpClient = + (HttpClient)serviceClient.getServiceContext().getConfigurationContext() + .getProperty(HTTPConstants.CACHED_HTTP_CLIENT); + if (httpClient != null) + ((MultiThreadedHttpConnectionManager)httpClient.getHttpConnectionManager()).shutdown(); + + serviceClient = null; + } + } + + public InterfaceContract getBindingInterfaceContract() { + return wsBinding.getBindingInterfaceContract(); + + } + + public boolean supportsOneWayInvocation() { + return true; + } + + public Invoker createInvoker(Operation operation) { + Options options = new Options(); + org.apache.axis2.addressing.EndpointReference epTo = getWSATOEPR(wsBinding); + if (epTo != null) { + options.setTo(epTo); + } + options.setProperty(HTTPConstants.CHUNKED, Boolean.FALSE); + + String operationName = operation.getName(); + + String soapAction = getSOAPAction(operationName); + if (soapAction != null && soapAction.length() > 1) { + options.setAction(soapAction); + } + + options.setTimeOutInMilliSeconds(30 * 1000); // 30 seconds + + // Allow privileged access to read properties. Requires PropertiesPermission read in + // security policy. + SOAPFactory soapFactory = AccessController.doPrivileged(new PrivilegedAction<SOAPFactory>() { + public SOAPFactory run() { + if (isSOAP12Required) + return OMAbstractFactory.getSOAP12Factory(); + else + return OMAbstractFactory.getSOAP11Factory(); + + } + }); + QName wsdlOperationQName = new QName(operationName); + if (isMTOMRequired) + { + options.setProperty(org.apache.axis2.Constants.Configuration.ENABLE_MTOM, org.apache.axis2.Constants.VALUE_TRUE); + } + + return new Axis2ReferenceBindingInvoker(endpointReference, serviceClient, wsdlOperationQName, options, soapFactory, wsBinding); + +/* + if (operation.isNonBlocking()) { + invoker = new Axis2OneWayBindingInvoker(this, wsdlOperationQName, options, soapFactory, wsBinding); + } else { + invoker = new Axis2BindingInvoker(endpointReference, serviceClient, wsdlOperationQName, options, soapFactory, wsBinding); + } + + return invoker; +*/ + } + + /* + * set up the reference binding wire with the right set of ws reference + * interceptors + */ + public void configure() { + InvocationChain bindingChain = endpointReference.getBindingInvocationChain(); + + // add transport interceptor + bindingChain.addInterceptor(Phase.REFERENCE_BINDING_TRANSPORT, + new TransportReferenceInterceptor()); + + } + + // Reference specific utility operations + + protected org.apache.axis2.addressing.EndpointReference getWSATOEPR(WebServiceBinding binding) { + org.apache.axis2.addressing.EndpointReference epr = getEPR(binding); + if (epr == null) { + epr = getPortLocationEPR(binding); + } else if (epr.getAddress() == null || epr.getAddress().length() < 1) { + org.apache.axis2.addressing.EndpointReference bindingEPR = getPortLocationEPR(binding); + if (bindingEPR != null) { + epr.setAddress(bindingEPR.getAddress()); + } + } + return epr; + } + + protected org.apache.axis2.addressing.EndpointReference getPortLocationEPR(WebServiceBinding binding) { + String ep = null; + if (binding.getPort() != null) { + List<?> wsdlPortExtensions = binding.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 = binding.getURI(); + } + return ep == null || "".equals(ep) ? null : new org.apache.axis2.addressing.EndpointReference(ep); + } + + protected org.apache.axis2.addressing.EndpointReference getEPR(WebServiceBinding wsBinding) { + if (wsBinding.getEndPointReference() == null) { + return null; + } + try { + + XMLStreamReader parser = + XMLInputFactory.newInstance().createXMLStreamReader(new DOMSource(wsBinding.getEndPointReference())); + StAXOMBuilder builder = new StAXOMBuilder(parser); + OMElement omElement = builder.getDocumentElement(); + org.apache.axis2.addressing.EndpointReference epr = EndpointReferenceHelper.fromOM(omElement); + return epr; + + } catch (IOException e) { + throw new RuntimeException(e); + } catch (XMLStreamException e) { + throw new RuntimeException(e); + } catch (FactoryConfigurationError e) { + throw new RuntimeException(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(); + } + } + } + } + } + return null; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java new file mode 100644 index 0000000000..34e5bc4026 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java @@ -0,0 +1,257 @@ +/* + * 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.axis2.provider; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.logging.Logger; + +import javax.wsdl.Port; +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMElement; +import org.apache.axis2.AxisFault; +import org.apache.axis2.description.AxisService; +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.axis2.policy.mtom.Axis2MTOMPolicyProvider; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.policy.PolicySubject; +import org.apache.tuscany.sca.policy.util.PolicyHelper; +import org.apache.tuscany.sca.provider.EndpointProvider; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; +import org.oasisopen.sca.ServiceRuntimeException; + +public class Axis2ServiceBindingProvider extends Axis2BaseBindingProvider implements EndpointProvider { + private static final Logger logger = Logger.getLogger(Axis2ServiceBindingProvider.class.getName()); + + // Tuscany extensions + private AssemblyFactory assemblyFactory; + private ServletHost servletHost; + private RuntimeComponent component; + private RuntimeComponentService service; + + // the endpoint configuration that's driving this binding provider + // and some convenience data retrieved from the endpoint + private RuntimeEndpoint endpoint; + private WebServiceBinding wsBinding; + private Port wsdlPort; + private String endpointURI; + private String deployedURI; + private InterfaceContract contract; + + public Axis2ServiceBindingProvider(ExtensionPointRegistry extensionPoints, + RuntimeEndpoint endpoint, + ServletHost servletHost ) { + super(extensionPoints); + + this.extensionPoints = extensionPoints; + this.endpoint = endpoint; + this.servletHost = servletHost; + + this.assemblyFactory = (RuntimeAssemblyFactory)modelFactories.getFactory(AssemblyFactory.class); + this.wsBinding = (WebServiceBinding)endpoint.getBinding(); + this.component = (RuntimeComponent)endpoint.getComponent(); + this.service = (RuntimeComponentService)endpoint.getService(); + + // A WSDL document should always be present in the binding + if (wsBinding.getGeneratedWSDLDocument() == null) { + throw new ServiceRuntimeException("No WSDL document for " + component.getName() + "/" + service.getName()); + } + + // Set to use the Axiom data binding + contract = wsBinding.getBindingInterfaceContract(); + contract.getInterface().resetDataBinding(OMElement.class.getName()); + + configContext = Axis2EngineIntegration.getAxisConfigurationContext(extensionPoints.getServiceDiscovery()); + + // set the root context for this instance of Axis + configContext.setContextRoot(servletHost.getContextPath()); + + // Determine the configuration from the bindings "mayProvides" intents + // TODO - why don't intents get aggregated to EP correctly? + isSOAP12Required = PolicyHelper.isIntentRequired((PolicySubject)wsBinding, Constants.SOAP12_INTENT); + + isMTOMRequired = PolicyHelper.isIntentRequired((PolicySubject)wsBinding, Axis2BindingProviderFactory.MTOM_INTENT); + + // if the endpoint contains any WS Policy expressions then we probably need rampart + // TODO - need to take into account Axis configuration policy also + QName wsPolicyQName = new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "Policy"); + if (PolicyHelper.getPolicies(endpoint, wsPolicyQName).size() > 0){ + isRampartRequired = true; + } + + + // Update port addresses with runtime information + // We can safely assume there is only one port here 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 + wsdlPort = (Port)wsBinding.getService().getPorts().values().iterator().next(); + + if (wsdlPort == null){ + throw new ServiceRuntimeException("No WSDL port for ws binding of " + component.getName() + "/" + service.getName()); + } + + endpointURI = Axis2EngineIntegration.getPortAddress(wsdlPort); + + if (endpointURI.startsWith("jms:")) { + deployedURI = endpointURI; + isJMSRequired = true; + } else { + if (servletHost == null) { + throw new ServiceRuntimeException("No Servlet host is avaible for HTTP web services"); + } + deployedURI = servletHost.getURLMapping(endpointURI, httpSecurityContext).toString(); + } + + Axis2EngineIntegration.setPortAddress(wsdlPort, deployedURI); + + // Apply the configuration from the mayProvides intents + + if (isRampartRequired){ + Axis2EngineIntegration.loadRampartModule(configContext); + } + + if (isMTOMRequired) { + new Axis2MTOMPolicyProvider(endpoint).configureBinding(configContext); + } + + if (isJMSRequired){ + // TODO - do we need to go back to configurator? + } + + wsBinding.setURI(deployedURI); + + // Check the WSDL style as we only support some of them + + if (wsBinding.isRpcEncoded()){ + throw new ServiceRuntimeException("rpc/encoded WSDL style not supported. Component " + endpoint.getComponent().getName() + + " Service " + endpoint.getService() + + " Binding " + endpoint.getBinding().getName()); + } + + if (wsBinding.isDocEncoded()){ + throw new ServiceRuntimeException("doc/encoded WSDL style not supported. Component " + endpoint.getComponent().getName() + + " Service " + endpoint.getService() + + " Binding " + endpoint.getBinding().getName()); + } + + // if (wsBinding.isDocLiteralUnwrapped()){ + // throw new ServiceRuntimeException("doc/literal/unwrapped WSDL style not supported for endpoint " + endpoint); + // } + } + + private static final String DEFAULT_QUEUE_CONNECTION_FACTORY = "TuscanyQueueConnectionFactory"; + + public void start() { + try { + createAxisService(deployedURI, wsdlPort); + + // Apply the configuration from any other policies + + for (PolicyProvider pp : endpoint.getPolicyProviders()) { + pp.configureBinding(this); + } + + if (deployedURI.startsWith("http://") || + deployedURI.startsWith("https://") || + deployedURI.startsWith("/")) { + Axis2ServiceServlet servlet = new Axis2ServiceServlet(); + servlet.init(configContext); + + if (httpSecurityContext.isSSLEnabled()){ + deployedURI = servletHost.addServletMapping(endpointURI, servlet, httpSecurityContext); + } else { + deployedURI = servletHost.addServletMapping(endpointURI, servlet); + } + } + endpoint.setDeployedURI(deployedURI); + } catch (AxisFault e) { + throw new RuntimeException(e); + } + } + + public void stop() { + try { + servletHost.removeServletMapping(endpointURI); + servletHost = null; + + // get the path to the service + // [nash] Need a leading slash for WSDL imports to work with ?wsdl + URI uriPath = new URI(deployedURI); + String stringURIPath = uriPath.getPath(); + configContext.getAxisConfiguration().removeService(stringURIPath); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } catch (AxisFault e) { + throw new RuntimeException(e); + } + } + + public InterfaceContract getBindingInterfaceContract() { + return wsBinding.getBindingInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return true; + } + + @Override + public void configure() { + // add in the response interceptor that turns the response message back into a SOAP + // envelope before the response returns through the binding chain + InvocationChain bindingChain = endpoint.getBindingInvocationChain(); + + // add transport interceptor + bindingChain.addInterceptor(Phase.SERVICE_BINDING_POLICY, + new Axis2ServiceBindingResponseInterceptor(endpoint) ); + + } + + // Service specific utility operations + + private void createAxisService(String endpointURL, Port port) throws AxisFault { + AxisService axisService; + if (wsBinding.getGeneratedWSDLDocument() != null) { + axisService = Axis2EngineIntegration.createWSDLAxisService(endpointURL, port, wsBinding); + } else { + axisService = Axis2EngineIntegration.createJavaAxisService(endpointURL, configContext, service); + } + + Axis2EngineIntegration.createAxisServiceProviders(axisService, endpoint, wsBinding, extensionPoints); + + configContext.getAxisConfiguration().addService(axisService); + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingResponseInterceptor.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingResponseInterceptor.java new file mode 100644 index 0000000000..6391132148 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingResponseInterceptor.java @@ -0,0 +1,124 @@ +/*
+ * 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.axis2.provider;
+
+
+import java.util.Iterator;
+
+import javax.wsdl.BindingOperation;
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.client.OperationClient;
+import org.apache.axis2.context.MessageContext;
+import org.apache.tuscany.sca.binding.ws.WebServiceBinding;
+import org.apache.tuscany.sca.binding.ws.axis2.context.WSAxis2BindingContext;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.invocation.PhasedInterceptor;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ * Create the SOAP envelope from the response message before the reponse
+ * passes back through the binding chain
+ */
+public class Axis2ServiceBindingResponseInterceptor implements PhasedInterceptor {
+
+ private Invoker next;
+
+ private RuntimeEndpoint endpoint;
+ private WebServiceBinding wsBinding;
+
+ public Axis2ServiceBindingResponseInterceptor(RuntimeEndpoint endpoint) {
+ this.endpoint = endpoint;
+ this.wsBinding = (WebServiceBinding)endpoint.getBinding();
+ }
+
+ public Message invoke(Message msg) {
+
+ Message response = getNext().invoke(msg);
+
+ // set up the response envelope here before we return back through the binding chain
+ // so that this is symetrical with how the outgoing reference binding chain behaves
+ WSAxis2BindingContext bindingContext = msg.getBindingContext();
+ MessageContext responseMC = bindingContext.getAxisOutMessageContext();
+
+ if(!response.isFault()) {
+ OMElement responseOM = response.getBody();
+
+ if (wsBinding.isRpcLiteral()){
+ // add the response wrapping element
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ 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.getBindingOutput().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();
+ }
+
+ QName operationResponseQName = new QName(wrapperNamespace,
+ msg.getOperation().getName() + "Response");
+ OMElement operationResponseElement = factory.createOMElement(operationResponseQName);
+ operationResponseElement.addChild(responseOM);
+ responseOM = operationResponseElement;
+ }
+
+ if (null != responseOM ) {
+ responseMC.getEnvelope().getBody().addChild(responseOM);
+ }
+ }
+
+ return response;
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public String getPhase() {
+ return Phase.SERVICE_BINDING_POLICY;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceInMessageReceiver.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceInMessageReceiver.java new file mode 100644 index 0000000000..d23dc7e8ca --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceInMessageReceiver.java @@ -0,0 +1,57 @@ +/* + * 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.axis2.provider; + +import java.lang.reflect.InvocationTargetException; + +import org.apache.axiom.om.OMElement; +import org.apache.axis2.AxisFault; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.receivers.AbstractInMessageReceiver; + +public class Axis2ServiceInMessageReceiver extends AbstractInMessageReceiver { + + private TuscanyServiceProvider provider; + + public Axis2ServiceInMessageReceiver(TuscanyServiceProvider provider) { + this.provider = provider; + } + + public Axis2ServiceInMessageReceiver() { + } + + @Override + public void invokeBusinessLogic(MessageContext inMC) throws AxisFault { + try { + OMElement requestOM = inMC.getEnvelope().getBody().getFirstElement(); + + provider.invoke(requestOM, inMC, null); + + } catch (InvocationTargetException e) { + Throwable t = e.getCause(); + if (t instanceof Exception) { + throw AxisFault.makeFault((Exception)t); + } + throw new RuntimeException(e); + } catch (Exception e) { + e.printStackTrace(); + throw AxisFault.makeFault(e); + } + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceInOutSyncMessageReceiver.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceInOutSyncMessageReceiver.java new file mode 100644 index 0000000000..802d962cd9 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceInOutSyncMessageReceiver.java @@ -0,0 +1,83 @@ +/* + * 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.axis2.provider; + +import java.lang.reflect.InvocationTargetException; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.soap.SOAPEnvelope; +import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.oasisopen.sca.ServiceRuntimeException; + +public class Axis2ServiceInOutSyncMessageReceiver extends AbstractInOutSyncMessageReceiver { + private static final Logger logger = Logger.getLogger(Axis2ServiceInOutSyncMessageReceiver.class.getName()); + + private TuscanyServiceProvider provider; + + public Axis2ServiceInOutSyncMessageReceiver(TuscanyServiceProvider provider) { + this.provider = provider; + } + + public Axis2ServiceInOutSyncMessageReceiver() { + } + + @Override + public void invokeBusinessLogic(MessageContext inMC, MessageContext outMC) throws AxisFault { + try { + OMElement requestOM = inMC.getEnvelope().getBody().getFirstElement(); + + // create the out soap message before the invoke so it's available to the message chain + // during response processing + SOAPEnvelope soapEnvelope = getSOAPFactory(inMC).getDefaultEnvelope(); + outMC.setEnvelope(soapEnvelope); + + provider.invoke(requestOM, inMC, outMC); + + outMC.getOperationContext().setProperty(Constants.RESPONSE_WRITTEN, Constants.VALUE_TRUE); + + } catch (InvocationTargetException e) { + Throwable t = e.getCause(); + if (t instanceof FaultException && ((FaultException)t).getFaultInfo() instanceof OMElement) { + OMElement faultDetail = (OMElement)((FaultException)t).getFaultInfo(); + inMC.setProperty(Constants.FAULT_NAME, faultDetail.getQName().getLocalPart()); + AxisFault f = new AxisFault(null, e.getMessage(), "faultNode", "faultRole", faultDetail); + throw f; + } + if (t instanceof Exception) { + throw AxisFault.makeFault((Exception)t); + } + logger.log(Level.SEVERE, e.getMessage(), t); + throw new ServiceRuntimeException(e); + } catch (Throwable e) { + if( "AsyncResponse".equals(e.getMessage()) ) { + // Do nothing for an async response exception - it is a signal that the service has been + // invoked asynchronously + } else { + logger.log(Level.SEVERE, e.getMessage(), e); + } // end if + throw AxisFault.makeFault(e); + } + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceServlet.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceServlet.java new file mode 100644 index 0000000000..2f6b396786 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceServlet.java @@ -0,0 +1,300 @@ +/* + * 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.axis2.provider; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Collections; +import java.util.Enumeration; +import java.util.Set; +import java.util.Vector; + +import javax.servlet.RequestDispatcher; +import javax.servlet.Servlet; +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.transport.http.AxisServlet; + +/** + * This overrides the Servlet init of the AxisServlet so Tuscany can use + * a single Axis2 ConfigurationContext instance shared between AxisServlet + * instances for each SCA service with a ws binding. + * TODO: need to review if thats really what we want to be doing + * + * @version $Rev$ $Date$ + */ +public class Axis2ServiceServlet extends AxisServlet { + + protected TuscanyListingAgent agent; + + private static final long serialVersionUID = 1L; + private static final ServletConfig DUMMY_CONFIG = createDummyServletConfig(); + + private boolean initCalled = false; + +//JIRA TUSCANY-1561 Port to Axis2 1.3 + private ConfigurationContext tmpconfigContext; + + public void init(ConfigurationContext configContext) { + this.tmpconfigContext = configContext; + //try { + //super.init(DUMMY_CONFIG); + //init(DUMMY_CONFIG); + //} catch (ServletException e) { + // throw new RuntimeException(e); + //} + agent = new TuscanyListingAgent(configContext); + } + + /** + * Override Axis2 Servlet method to avoid loop when init + * is called after servletConfig already initialized by + * this classes init(ConfigurationContext) method. + */ + @Override + public void init() throws ServletException { + } + + @Override + public void init(ServletConfig config) throws ServletException { + ServletContext servletContext = config.getServletContext(); + servletContext.setAttribute(CONFIGURATION_CONTEXT, tmpconfigContext); + + super.init(config); + } + + /** + * We've setup the Servlet by passing in a ConfigurationContext on our init method + * override this method to just return that + */ + @Override + protected ConfigurationContext initConfigContext(ServletConfig config) throws ServletException { + return this.tmpconfigContext; + } + + @Override + public ServletConfig getServletConfig() { + return DUMMY_CONFIG; + } + + @Override + public String getServletName() { + return "TuscanyAxis2Servlet"; + } + + /** + * The AxisServlet gets NPE during init without a ServletConfig so this is a mocked up one to prevent that. + */ + private static ServletConfig createDummyServletConfig() { + ServletConfig sc = new ServletConfig() { + + public String getServletName() { + return "TuscanyAxis2DummyServlet"; + } + + public ServletContext getServletContext() { + return new ServletContext() { + + public ServletContext getContext(String uripath) { + return null; + } + + @SuppressWarnings("unused") // it's on the Servlet 2.5 API so we need it + public String getContextPath() { + return null; + } + + public int getMajorVersion() { + return 0; + } + + public int getMinorVersion() { + return 0; + } + + public String getMimeType(String file) { + return null; + } + + public Set<?> getResourcePaths(String path) { + return Collections.emptySet(); + } + + public URL getResource(String path) throws MalformedURLException { + if("/".equals(path)) { + // HACK: To avoid NPE + return new URL("/axis2"); + } + return null; + } + + public InputStream getResourceAsStream(String path) { + return null; + } + + public RequestDispatcher getRequestDispatcher(String path) { + return null; + } + + public RequestDispatcher getNamedDispatcher(String arg0) { + return null; + } + + public Servlet getServlet(String arg0) throws ServletException { + return null; + } + + public Enumeration getServlets() { + return null; + } + + public Enumeration getServletNames() { + return null; + } + + public void log(String arg0) { + } + + public void log(Exception arg0, String arg1) { + } + + public void log(String arg0, Throwable arg1) { + } + + public String getRealPath(String arg0) { + return null; + } + + public String getServerInfo() { + return null; + } + + public String getInitParameter(String arg0) { + return null; + } + + public Enumeration getInitParameterNames() { + return null; + } + + public Object getAttribute(String arg0) { + return null; + } + + public Enumeration getAttributeNames() { + return null; + } + + public void setAttribute(String arg0, Object arg1) { + } + + public void removeAttribute(String arg0) { + } + + public String getServletContextName() { + return null; + } + }; + } + + public String getInitParameter(String arg0) { + return null; + } + + public Enumeration getInitParameterNames() { + return new Vector().elements(); + } + }; + return sc; + } + + @Override + public void destroy() { + try { + super.destroy(); + servletConfig = null; + if (tmpconfigContext.getListenerManager() != null){ + tmpconfigContext.getListenerManager().destroy(); + } + } catch (Exception e) { + e.printStackTrace(); + } + + } + + /** + * Override the AxisServlet doGet to use the TuscanyListingAgent for ?wsdl + */ + @Override + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + initContextRoot(request); + + String query = request.getQueryString(); + if ((query != null) && (query.indexOf("wsdl2") >= 0 || + query.indexOf("wsdl") >= 0 || query.indexOf("xsd") >= 0 || + query.indexOf("policy") >= 0)) { + agent.processListService(request, response); + } else { + super.doGet(request, response); + } + } + + /** + + /** + * Override the AxisServlet method so as to not add "/services" into the URL + * and to work with Tuscany service names. can go once moved to Axis2 1.3 + */ +/* + @Override + public EndpointReference[] getEPRsForService(String serviceName, String ip) throws AxisFault { + //RUNNING_PORT + String port = (String) configContext.getProperty(ListingAgent.RUNNING_PORT); + if (port == null) { + port = "8080"; + } + if (ip == null) { + try { + ip = HttpUtils.getIpAddress(); + if (ip == null) { + ip = "localhost"; + } + } catch (SocketException e) { +//TUSCANY-1561 Port to Axis2 1.3 +// throw new AxisFault.(e); + throw AxisFault.makeFault(e); + } + } + + URI epURI = URI.create("http://" + ip + ":" + port + "/" + serviceName).normalize(); + + return new EndpointReference[]{new EndpointReference(epURI.toString())}; + } + */ + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/TuscanyDispatcher.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/TuscanyDispatcher.java new file mode 100644 index 0000000000..0a20de5067 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/TuscanyDispatcher.java @@ -0,0 +1,104 @@ +/* + * 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.axis2.provider; + +import java.net.URI; +import java.util.HashMap; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.description.HandlerDescription; +import org.apache.axis2.engine.AxisConfiguration; +import org.apache.axis2.engine.RequestURIBasedDispatcher; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * A Tuscany specific Axis2 Dispatcher that enables using services + * exposed at the SCA defined service URI instead of /services/<serviceName> + * + * @version $Rev$ $Date$ + */ +public class TuscanyDispatcher extends RequestURIBasedDispatcher { + + public static final String NAME = "TuscanyDispatcher"; + private static final Log log = LogFactory.getLog(RequestURIBasedDispatcher.class); + private static final boolean isDebugEnabled = log.isDebugEnabled(); + + /* + * (non-Javadoc) + * + * @see org.apache.axis2.engine.AbstractDispatcher#findService(org.apache.axis2.context.MessageContext) + */ + @Override + public AxisService findService(MessageContext messageContext) throws AxisFault { + EndpointReference toEPR = messageContext.getTo(); + + if (toEPR != null) { + if(isDebugEnabled){ + log.debug("Checking for Service using target endpoint address : " + toEPR.getAddress()); + } + + String path = URI.create(toEPR.getAddress()).getPath(); + + ConfigurationContext configurationContext = messageContext.getConfigurationContext(); + AxisConfiguration registry = configurationContext.getAxisConfiguration(); + + String serviceName = findAxisServiceName(registry, path); + return registry.getService(serviceName); + + } else { + if(isDebugEnabled){ + log.debug("Attempted to check for Service using null target endpoint URI"); + } + return null; + } + } + + @Override + public void initDispatcher() { + init(new HandlerDescription(NAME)); + } + + protected String findAxisServiceName(AxisConfiguration registry, String path) { + HashMap services = registry.getServices(); + if (services == null) { + return null; + } + String[] parts = path.split("/"); + String serviceName = ""; + for (int i=parts.length-1; i>=0; i--) { + serviceName = parts[i] + serviceName; + if (services.containsKey(serviceName)) { + return serviceName; + } + serviceName = "/" + serviceName; + if (services.containsKey(serviceName)) { + return serviceName; + } + } + + return null; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/TuscanyListingAgent.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/TuscanyListingAgent.java new file mode 100644 index 0000000000..c44454196d --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/TuscanyListingAgent.java @@ -0,0 +1,232 @@ +/* + * 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.axis2.provider; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; + +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.description.Parameter; +import org.apache.axis2.transport.http.ListingAgent; +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaExternal; + +/** + * A Tuscany specific Axis2 ListingAgent as the Axis2 one does not work + * with the Tuscany service names which include slash ('/') characters. + * Unfortunately it ends up having to copy a fair amount of Axis2 code to do this. + * + * @version $Rev$ $Date$ + */ +public class TuscanyListingAgent extends ListingAgent { + + private static final String LIST_SINGLE_SERVICE_JSP_NAME = + "listSingleService.jsp"; + + public TuscanyListingAgent(ConfigurationContext aConfigContext) { + super(aConfigContext); + } + + /** + * This method overrides the Axis2 listing agent's computation of the + * service name. + */ + @Override + public String extractServiceName(String urlString) { + String serviceName = findAxisServiceName(urlString); + setContextRoot(urlString, serviceName); + return serviceName; + } + + /** + * Override ?xsd processing so that WSDL documents with XSD imports + * and includes work correctly. When we move to Axis2 1.4, we may + * be able to use SchemaSupplier to do this in a cleaner way. Also + * ensure that the correct IP address and port are returned by ?wsdl. + */ + @Override + public void processListService(HttpServletRequest req, + HttpServletResponse res) + throws IOException, ServletException { + + String url = req.getRequestURL().toString(); + String query = req.getQueryString(); + + // for ?wsdl requests, need to update the WSDL with correct IPaddr and port + int wsdl = query.indexOf("wsdl"); + if (wsdl >= 0) { + String serviceName = extractServiceName(url); + HashMap services = configContext.getAxisConfiguration().getServices(); + if ((services != null) && !services.isEmpty()) { + AxisService axisService = (AxisService)services.get(serviceName); + Parameter wsld4jdefinition = axisService.getParameter("wsdl4jDefinition"); + Definition definition = (Definition)wsld4jdefinition.getValue(); + for (Object s : definition.getServices().values()) { + for (Object p : ((Service)s).getPorts().values()) { + String endpointURL = Axis2EngineIntegration.getPortAddress((Port)p); + String modifiedURL = setIPAddress(endpointURL, url); + modifiedURL = addContextRoot(modifiedURL, serviceName); + Axis2EngineIntegration.setPortAddress((Port)p, modifiedURL); + } + } + } + } + + // handle ?xsd requests here + int xsd = query.indexOf("xsd"); + if (xsd >= 0) { + String serviceName = extractServiceName(url); + HashMap services = configContext.getAxisConfiguration().getServices(); + if ((services != null) && !services.isEmpty()) { + Object serviceObj = services.get(serviceName); + if (serviceObj != null) { + String xsds = req.getParameter("xsd"); + if (xsds != null && !"".equals(xsds)) { + // a schema name (perhaps with path) is present + AxisService axisService = (AxisService)serviceObj; + ArrayList schemas = axisService.getSchema(); + for (Object rootSchema : axisService.getSchema()) { + XmlSchema schema = getSchema(((XmlSchema)rootSchema), xsds); + if (schema != null) { + // found the schema + res.setContentType("text/xml"); + OutputStream out = res.getOutputStream(); + schema.write(new OutputStreamWriter(out, "UTF8")); + out.flush(); + out.close(); + return; + } + } + } + } + } + } + + // in all other cases, delegate to the Axis2 code + super.processListService(req, res); + } + + private String addContextRoot(String modifiedURL, String serviceName) { + if (!"/".equals(configContext.getContextRoot())) { + if (modifiedURL.endsWith(serviceName)) { + URI uri = URI.create(modifiedURL); + if (!uri.getPath().startsWith(configContext.getContextRoot())) { + modifiedURL = modifiedURL.substring(0, modifiedURL.length() - serviceName.length()) + configContext.getContextRoot() + serviceName; + } + } + } + return modifiedURL; + } + + private XmlSchema getSchema(XmlSchema parentSchema, String name) { + for (Iterator iter = parentSchema.getIncludes().getIterator(); iter.hasNext();) { + Object obj = iter.next(); + if (obj instanceof XmlSchemaExternal) { + XmlSchemaExternal extSchema = (XmlSchemaExternal)obj; + if (extSchema.getSchemaLocation().endsWith(name)) { + return extSchema.getSchema(); + } else { + XmlSchema schema = getSchema(extSchema.getSchema(), name); + if (schema != null) { + return schema; + } + } + } + } + return null; + } + + private String findAxisServiceName(String path) { + HashMap services = configContext.getAxisConfiguration().getServices(); + if (services == null) { + return null; + } + String[] parts = path.split("/"); + String serviceName = ""; + for (int i=parts.length-1; i>=0; i--) { + serviceName = parts[i] + serviceName; + if (services.containsKey(serviceName)) { + return serviceName; + } + serviceName = "/" + serviceName; + if (services.containsKey(serviceName)) { + return serviceName; + } + } + + return null; + } + + /** + * Hack for Tuscany to get ?wsdl working with Tuscany service names + * Can go once moved up to Axis2 1.3 + */ + private void setContextRoot(String filePart, String serviceName) { + String contextRoot = configContext.getContextRoot(); + if (contextRoot != null && contextRoot.length() > 0) { + if (contextRoot.equals("/")) { + configContext.setServicePath("/"); + } else { + int i = filePart.indexOf(contextRoot) + contextRoot.length(); + int j = filePart.lastIndexOf(serviceName); + if (i>=j || (i+1 == j)) { + configContext.setServicePath("/"); + } else { + String mapping = filePart.substring(i+1, j); + configContext.setServicePath(mapping); + } + } + configContext.setContextRoot(contextRoot); + } + } + + private static String setIPAddress(String wsdlURI, String requestURI) { + try { + URI wsdlURIObj = new URI(wsdlURI); + String wsdlHost = wsdlURIObj.getHost(); + int wsdlPort = wsdlURIObj.getPort(); + String wsdlAddr = wsdlHost + (wsdlPort != -1 ? ":" + Integer.toString(wsdlPort) : ""); + URI requestURIObj = new URI(requestURI); +// not in Axis2 1.5.1 +// String ipAddr = HttpUtils.getIpAddress(); +// int requestPort = requestURIObj.getPort(); +// String newAddr = ipAddr + (requestPort != -1 ? ":" + Integer.toString(requestPort) : ""); +// return wsdlURI.replace(wsdlAddr, newAddr); + return wsdlURI; + } catch (Exception e) { + // URI string not in expected format, so return the WSDL URI unmodified + return wsdlURI; + } + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/TuscanyServiceProvider.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/TuscanyServiceProvider.java new file mode 100644 index 0000000000..9b76f7e7ea --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/TuscanyServiceProvider.java @@ -0,0 +1,291 @@ +/*
+ * 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.axis2.provider;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.logging.Logger;
+
+import javax.wsdl.BindingOperation;
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.soap.SOAPHeader;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.addressing.AddressingFaultsHelper;
+import org.apache.axis2.context.MessageContext;
+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.binding.ws.axis2.context.WSAxis2BindingContext;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory;
+import org.apache.tuscany.sca.core.assembly.impl.RuntimeEndpointImpl;
+import org.apache.tuscany.sca.core.invocation.AsyncResponseInvoker;
+import org.apache.tuscany.sca.core.invocation.Constants;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+import org.oasisopen.sca.ServiceRuntimeException;
+
+public class TuscanyServiceProvider {
+ private static final Logger logger = Logger.getLogger(TuscanyServiceProvider.class.getName());
+
+ public static final QName QNAME_WSA_ADDRESS =
+ new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.EPR_ADDRESS);
+ public static final QName QNAME_WSA_FROM =
+ new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.WSA_FROM);
+ public static final QName QNAME_WSA_REPLYTO =
+ new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.WSA_REPLY_TO);
+ public static final QName QNAME_WSA_REFERENCE_PARAMETERS =
+ new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.EPR_REFERENCE_PARAMETERS);
+ public static final QName QNAME_WSA_MESSAGEID =
+ new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.WSA_MESSAGE_ID);
+ public static final QName QNAME_WSA_RELATESTO =
+ new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.WSA_RELATES_TO, AddressingConstants.WSA_DEFAULT_PREFIX);
+
+ private RuntimeEndpoint endpoint;
+ private WebServiceBinding wsBinding;
+ private MessageFactory messageFactory;
+ private FactoryExtensionPoint modelFactories;
+ private RuntimeAssemblyFactory assemblyFactory;
+ private WebServiceBindingFactory webServiceBindingFactory;
+ private Operation operation;
+
+ public TuscanyServiceProvider(ExtensionPointRegistry extensionPoints,
+ RuntimeEndpoint endpoint,
+ WebServiceBinding wsBinding,
+ Operation operation) {
+ this.endpoint = endpoint;
+ this.wsBinding = wsBinding;
+ this.operation = operation;
+ this.modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
+ this.messageFactory = modelFactories.getFactory(MessageFactory.class);
+ this.assemblyFactory = (RuntimeAssemblyFactory)modelFactories.getFactory(AssemblyFactory.class);
+ this.webServiceBindingFactory = (WebServiceBindingFactory)modelFactories.getFactory(WebServiceBindingFactory.class);
+ }
+
+ // 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, MessageContext inMC ) throws AxisFault {
+ // If the address is anonymous or none, throw a SOAP fault...
+ if( WS_ADDR_ANONYMOUS.equals(callbackAddress) || WS_ADDR_NONE.equals(callbackAddress) ) {
+ AddressingFaultsHelper.triggerOnlyNonAnonymousAddressSupportedFault(inMC, "wsa:From");
+ }
+ } // end method checkCallbackAddress
+
+ public OMElement invoke(OMElement requestOM, MessageContext inMC, MessageContext outMC) throws InvocationTargetException, AxisFault {
+ String callbackAddress = null;
+
+ // create a message object and set the args as its body
+ Message msg = messageFactory.createMessage();
+ msg.setOperation(operation);
+ WSAxis2BindingContext bindingContext = new WSAxis2BindingContext();
+ bindingContext.setAxisInMessageContext(inMC);
+ bindingContext.setAxisOutMessageContext(outMC); //TUSCANY-3881
+ msg.setBindingContext(bindingContext);
+
+
+ if (wsBinding.isRpcLiteral()){
+ // remove the wrapping element containing
+ // the operation name
+ Iterator iter = requestOM.getChildElements();
+ List<OMNode> list = new ArrayList<OMNode>();
+ while(iter.hasNext()){
+ OMNode node = (OMNode)iter.next();
+ list.add(node);
+ }
+
+ Object[] args = list.toArray();
+ msg.setBody(args);
+
+ } else if (wsBinding.isRpcEncoded()){
+ throw new ServiceRuntimeException("rpc/encoded WSDL style not supported for endpoint " + endpoint);
+ } else if (wsBinding.isDocEncoded()){
+ throw new ServiceRuntimeException("doc/encoded WSDL style not supported for endpoint " + endpoint);
+ //} else if (wsBinding.isDocLiteralUnwrapped()){
+ // throw new ServiceRuntimeException("doc/literal/unwrapped WSDL style not supported for endpoint " + endpoint);
+ } else if (wsBinding.isDocLiteralWrapped() ||
+ wsBinding.isDocLiteralUnwrapped()){
+ Object[] args = new Object[] {requestOM};
+ msg.setBody(args);
+ } else {
+ throw new ServiceRuntimeException("Unrecognized WSDL style for endpoint " + endpoint);
+ }
+
+ SOAPHeader header = inMC.getEnvelope().getHeader();
+ if (header != null) {
+ // Retrieve callback-related headers
+ callbackAddress = handleCallbackAddress( header, msg );
+ handleMessageIDHeader( header, msg );
+ handleRelatesToHeader( header, msg );
+ } // end if
+
+ // Create a from EPR to hold the details of the callback endpoint, if any
+ createCallbackEPR( callbackAddress, inMC, msg );
+
+ // Set up any async response EPR
+ setupAsyncResponse( msg, callbackAddress );
+
+ Message response = endpoint.invoke(msg);
+
+ if(response.isFault()) {
+ throw new InvocationTargetException((Throwable) response.getBody());
+ }
+
+ // The envelope has already been set up in Axis2ServiceBindingResponseInvoker
+ // so no need to return anything here
+ return null;
+ } // end method
+
+ /**
+ * Setup the necessary infrastructure for the Async response handling
+ * @param msg
+ * @param callbackAddress
+ */
+ private void setupAsyncResponse(Message msg, String callbackAddress) {
+ if( !endpoint.isAsyncInvocation() ) return;
+
+ endpoint.createAsyncServerCallback();
+ RuntimeEndpointReference asyncCallback = endpoint.getAsyncServerCallback();
+
+ // Create a response invoker, containing the callback address and add it to the message headers
+ AsyncResponseInvoker<String> respInvoker =
+ new AsyncResponseInvoker<String>(endpoint, asyncCallback,
+ callbackAddress,
+ (String)msg.getHeaders().get(Constants.MESSAGE_ID),
+ msg.getOperation().getName(), messageFactory);
+ msg.getHeaders().put(Constants.ASYNC_RESPONSE_INVOKER, respInvoker);
+ } // end method setupAsyncResponse
+
+ /**
+ * If there is a callback address, create an EPR for the callback with a referenced endpoint that contains
+ * the binding and the target callback address
+ * @param callbackAddress - the callback address - may be null
+ * @param inMC - the Axis incoming message context
+ * @param msg - the Tuscany message
+ * @throws AxisFault - if the callback address has any of the disallowed forms of callback address
+ */
+ private void createCallbackEPR( String callbackAddress, MessageContext inMC, Message msg ) throws AxisFault {
+ if (callbackAddress != null ) {
+ // Check for special (& not allowed!) WS_Addressing values
+ checkCallbackAddress( callbackAddress, inMC );
+ //
+ EndpointReference from = assemblyFactory.createEndpointReference();
+ Endpoint fromEndpoint = assemblyFactory.createEndpoint();
+ from.setTargetEndpoint(fromEndpoint);
+ from.setStatus(EndpointReference.Status.WIRED_TARGET_FOUND_AND_MATCHED);
+ msg.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);
+ } // end if
+ } // end method createCallbackEPR
+
+ private static String WS_REF_PARMS = "WS_REFERENCE_PARAMETERS";
+ /**
+ * Deal with any Callback address contained in the SOAP headers of the received message
+ * The callback address is contained in one of two headers (in the priority order stated by the SCA Web Service Binding spec):
+ * - wsa:From
+ * - wsa:ReplyTo
+ * Either of these headers should then contain a wsa:Address element containing the callback address
+ * A callback address may also be accompanied by wsa:ReferenceParameters
+ * - if present, ReferenceParameters must be read, stored unchanged and then sent in the header of any message sent to the
+ * callback address, as stated in the WSW-Addressing specification
+ * Any ReferenceParameters are stored into the headers of the Tuscany message under the key "WS_REFERENCE_PARAMETERS"
+ * @param header - the SOAP header for the message
+ * @param msg - the Tuscany message data structure
+ * @return - the callback address, as a String - null if no callback address is found
+ */
+ private String handleCallbackAddress( SOAPHeader header, Message msg ) {
+ String callbackAddress = null;
+
+ // See if there is a wsa:From element - if not search for a wsa:ReplyTo element
+ OMElement from = header.getFirstChildWithName(QNAME_WSA_FROM);
+ if( from == null ) from = header.getFirstChildWithName(QNAME_WSA_REPLYTO);
+
+ if (from != null) {
+ OMElement callbackAddrElement = from.getFirstChildWithName(QNAME_WSA_ADDRESS);
+ if (callbackAddrElement != null) {
+ callbackAddress = callbackAddrElement.getText();
+ OMElement refParms = from.getFirstChildWithName(QNAME_WSA_REFERENCE_PARAMETERS);
+ 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;
+ OMElement messageID = header.getFirstChildWithName(QNAME_WSA_MESSAGEID);
+ if (messageID != null) {
+ String idValue = messageID.getText();
+ // Store the value of the message ID element into the message under "WS_MESSAGE_ID"...
+ 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;
+ OMElement messageID = header.getFirstChildWithName(QNAME_WSA_RELATESTO);
+ if (messageID != null) {
+ String idValue = messageID.getText();
+ // Store the value of the message ID element into the message under "RELATES_TO"...
+ msg.getHeaders().put(Constants.RELATES_TO, idValue);
+ } // end if
+ } // end method handleMessageID
+} // end class AsyncResponseHandler
diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/transport/TransportReferenceInterceptor.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/transport/TransportReferenceInterceptor.java new file mode 100644 index 0000000000..888a9f6a79 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/transport/TransportReferenceInterceptor.java @@ -0,0 +1,141 @@ +/* + * 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.axis2.transport; + +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; + +import org.apache.axiom.om.OMElement; +import org.apache.axis2.AxisFault; +import org.apache.axis2.client.OperationClient; +import org.apache.axis2.client.Options; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.transport.http.HTTPConstants; +import org.apache.tuscany.sca.binding.ws.axis2.context.WSAxis2BindingContext; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +/** + * Use an Axis2 OperationClient to invoke a remote web service + * + * @version $Rev$ $Date$ + */ +public class TransportReferenceInterceptor implements Interceptor { + + private Invoker next; + + public TransportReferenceInterceptor() { + } + + public Message invoke(Message msg) { + try { + Object resp = null; + + if (msg.getOperation().isNonBlocking()) { + resp = invokeTargetOneWay(msg); + } else { + resp = invokeTarget(msg); + } + + msg.setBody(resp); + } catch (AxisFault e) { + if (e.getDetail() != null ) { + FaultException f = new FaultException(e.getMessage(), e.getDetail(), e); + f.setFaultName(e.getDetail().getQName()); + msg.setFaultBody(f); + } else { + msg.setFaultBody(e); + } + } catch (Throwable e) { + msg.setFaultBody(e); + } + + return msg; + } + + protected Object invokeTarget(Message msg) throws AxisFault { + WSAxis2BindingContext bindingContext = msg.getBindingContext(); + final OperationClient operationClient = bindingContext.getAxisOperationClient(); + + // ensure connections are tracked so that they can be closed by the reference binding + MessageContext requestMC = operationClient.getMessageContext("Out"); + requestMC.getOptions().setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE); + requestMC.getOptions().setTimeOutInMilliSeconds(240000L); + + + // Allow privileged access to read properties. Requires PropertiesPermission read in + // security policy. + try { + AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { + public Object run() throws AxisFault { + operationClient.execute(true); + return null; + } + }); + } catch (PrivilegedActionException e) { + operationClient.complete(requestMC); + throw (AxisFault)e.getException(); + } + + MessageContext responseMC = operationClient.getMessageContext("In"); + bindingContext.setAxisInMessageContext(responseMC); + + OMElement response = responseMC.getEnvelope().getBody().getFirstElement(); + + // FIXME: [rfeng] We have to pay performance penalty to build the complete OM as the operationClient.complete() will + // release the underlying HTTP connection. + // Force the response to be populated, see https://issues.apache.org/jira/browse/TUSCANY-1541 + if (response != null) { + response.build(); + } + + operationClient.complete(requestMC); + + return response; + } + + protected Object invokeTargetOneWay(Message msg) throws AxisFault { + WSAxis2BindingContext bindingContext = msg.getBindingContext(); + OperationClient operationClient = bindingContext.getAxisOperationClient(); + + // ensure connections are tracked so that they can be closed by the reference binding + MessageContext requestMC = operationClient.getMessageContext("Out"); + //requestMC.getOptions().setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE); + Options opt = requestMC.getOptions(); + opt.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE); + opt.setUseSeparateListener(true); + opt.setProperty(HTTPConstants.AUTO_RELEASE_CONNECTION,Boolean.TRUE); + + operationClient.execute(false); + + // REVIEW it seems ok to return null + return null; + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..a35f2502f4 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,21 @@ +# 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.
+
+# Implementation class for the binding extension
+org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2BindingProviderFactory;model=org.apache.tuscany.sca.binding.ws.WebServiceBinding,ranking=462
+
+
diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory new file mode 100644 index 0000000000..35a7eba505 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory @@ -0,0 +1,21 @@ +# 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.
+
+# Implementation class for binding-ws-runtime-axis2 specific policy extensions
+org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.basic.BasicAuthenticationPolicyProviderFactory;model=org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicy
+org.apache.tuscany.sca.binding.ws.axis2.policy.security.http.ssl.HTTPSPolicyProviderFactory;model=org.apache.tuscany.sca.policy.security.http.ssl.HTTPSPolicy
+org.apache.tuscany.sca.binding.ws.axis2.policy.wspolicy.WSPolicyProviderFactory;model=org.apache.tuscany.sca.policy.wspolicy.WSPolicy
diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/conf/tuscany-axis2.xml b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/conf/tuscany-axis2.xml new file mode 100644 index 0000000000..d1d1203bb9 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/conf/tuscany-axis2.xml @@ -0,0 +1,501 @@ +<?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. + --> + +<axisconfig name="AxisJava2.0"> + <!-- ================================================= --> + <!-- Parameters --> + <!-- ================================================= --> + <parameter name="hotdeployment">true</parameter> + <parameter name="hotupdate">false</parameter> + <parameter name="enableMTOM">false</parameter> + <parameter name="enableSwA">false</parameter> + + <!-- Customized by Tuscany --> + <!-- parameter name="OutflowSecurity"> + <action> + <items>Timestamp</items> + </action> + </parameter--> + + <!--Uncomment if you want to enable file caching for attachments --> + <!--parameter name="cacheAttachments">true</parameter> + <parameter name="attachmentDIR"></parameter> + <parameter name="sizeThreshold">4000</parameter--> + + <!--This will give out the timout of the configuration contexts, in milliseconds--> + <parameter name="ConfigContextTimeoutInterval">30000</parameter> + + <!--During a fault, stacktrace can be sent with the fault message. The following flag will control --> + <!--that behavior.--> + + <!-- Customized by Tuscany --> + <parameter name="sendStacktraceDetailsWithFaults">true</parameter> + + <!--If there aren't any information available to find out the fault reason, we set the message of the exception--> + <!--as the faultreason/Reason. But when a fault is thrown from a service or some where, it will be --> + <!--wrapped by different levels. Due to this the initial exception message can be lost. If this flag--> + <!--is set, then Axis2 tries to get the first exception and set its message as the faultreason/Reason.--> + <parameter name="DrillDownToRootCauseForFaultReason">false</parameter> + + <parameter name="userName">admin</parameter> + <parameter name="password">axis2</parameter> + + <!--To override repository/services you need to uncomment following parameter and value SHOULD be absolute file path.--> + <!--ServicesDirectory only works on the following cases--> + <!---File based configurator and in that case the value should be a file URL (http:// not allowed)--> + <!---When creating URL Based configurator with URL “file://†--> + <!--- War based configurator with expanded case , --> + + <!--All the other scenarios it will be ignored.--> + <!--<parameter name="ServicesDirectory">service</parameter>--> + <!--To override repository/modules you need to uncomment following parameter and value SHOULD be absolute file path--> + <!--<parameter name="ModulesDirectory">modules</parameter>--> + + + + <!--Following params will set the proper context paths for invocations. All the endpoints will have a commons context--> + <!--root which can configured using the following contextRoot parameter--> + <!--<parameter name="contextRoot">axis2</parameter>--> + + <!--Our HTTP endpoints can handle both REST and SOAP. Following parameters can be used to distinguiush those endpoints--> + <!--In case of a servlet, if you change this you have to manually change the settings of your servlet container to map this --> + <!--context path to proper Axis2 servlets--> + + <!-- Customized by Tuscany --> + <parameter name="servicePath">/</parameter> + + <!--<parameter name="restPath">rest</parameter>--> + + <!-- Following parameter will completely disable REST handling in Axis2--> + + <parameter name="disableREST" locked="true">false</parameter> + + <!--POJO deployer , this will allow users to drop .class file and make that into a service--> + <deployer extension=".class" directory="pojo" class="org.apache.axis2.deployment.POJODeployer"/> + + <!-- Following parameter will set the host name for the epr--> + <!--<parameter name="hostname" locked="true">myhost.com</parameter>--> + + <!-- If you have a frontend host which exposes this webservice using a different public URL --> + <!-- use this parameter to override autodetected url --> + <!--<parameter name="httpFrontendHostUrl">https://someotherhost/context</parameter>--> + + + <!-- The way of adding listener to the system--> + <!-- <listener class="org.apache.axis2.ObserverIMPL">--> + <!-- <parameter name="RSS_URL">http://127.0.0.1/rss</parameter>--> + <!-- </listener>--> + + <!-- ================================================= --> + <!-- Message Receivers --> + <!-- ================================================= --> + <!--This is the deafult MessageReceiver for the system , if you want to have MessageReceivers for --> + <!--all the other MEP implement it and add the correct entry to here , so that you can refer from--> + <!--any operation --> + <!--Note : You can ovrride this for a particular service by adding the same element with your requirement--> + <messageReceivers> + + <!-- Added by Tuscany --> + <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" + class="org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2ServiceInMessageReceiver"/> + + <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" + class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/> + <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" + class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/> + + <!-- Added by Tuscany --> + <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" + class="org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2ServiceInOutSyncMessageReceiver"/> + + <!-- Added by Tuscany --> + <messageReceiver mep="http://www.w3.org/2006/01/wsdl/in-only" + class="org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2ServiceInMessageReceiver"/> + + <messageReceiver mep="http://www.w3.org/2006/01/wsdl/in-only" + class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/> + <messageReceiver mep="http://www.w3.org/2006/01/wsdl/in-out" + class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/> + + <!-- Added by Tuscany --> + <messageReceiver mep="http://www.w3.org/2006/01/wsdl/in-out" + class="org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2ServiceInOutSyncMessageReceiver"/> + + </messageReceivers> + <!-- ================================================= --> + <!-- Message Formatter --> + <!-- ================================================= --> + <!--Following content type to message formatter mapping can be used to implement support for different message --> + <!--format serialization in Axis2. These message formats are expected to be resolved based on the content type. --> + <messageFormatters> + <messageFormatter contentType="application/x-www-form-urlencoded" + class="org.apache.axis2.transport.http.XFormURLEncodedFormatter"/> + <messageFormatter contentType="application/xml" + class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/> + </messageFormatters> + + <!-- ================================================= --> + <!-- Message Builders --> + <!-- ================================================= --> + <!--Following content type to builder mapping can be used to implement support for different message --> + <!--formats in Axis2. These message formats are expected to be resolved based on the content type. --> + <messageBuilders> + <messageBuilder contentType="application/xml" + class="org.apache.axis2.builder.ApplicationXMLBuilder"/> + <messageBuilder contentType="application/x-www-form-urlencoded" + class="org.apache.axis2.builder.XFormURLEncodedBuilder"/> + </messageBuilders> + + <!-- ================================================= --> + <!-- Transport Ins --> + <!-- ================================================= --> + <transportReceiver name="http" + class="org.apache.axis2.transport.http.AxisServletListener"> + + <!-- Customized by Tuscany --> + <parameter name="port" locked="false">6060</parameter> + + <!-- Here is the complete list of supported parameters (see example settings further below): + port: the port to listen on (default 6060) + hostname: if non-null, url prefix used in reply-to endpoint references (default null) + originServer: value of http Server header in outgoing messages (default "Simple-Server/1.1") + requestTimeout: value in millis of time that requests can wait for data (default 20000) + requestTcpNoDelay: true to maximize performance and minimize latency (default true) + false to minimize bandwidth consumption by combining segments + requestCoreThreadPoolSize: number of threads available for request processing (unless queue fills up) (default 25) + requestMaxThreadPoolSize: number of threads available for request processing if queue fills up (default 150) + note that default queue never fills up: see HttpFactory + threadKeepAliveTime: time to keep threads in excess of core size alive while inactive (default 180) + note that no such threads can exist with default unbounded request queue + threadKeepAliveTimeUnit: TimeUnit of value in threadKeepAliveTime (default SECONDS) (default SECONDS) + --> + <!-- <parameter name="hostname">http://www.myApp.com/ws</parameter> --> + <!-- <parameter name="originServer">My-Server/1.1</parameter> --> + <!-- <parameter name="requestTimeout">10000</parameter> --> + <!-- <parameter name="requestTcpNoDelay">false</parameter> --> + <!-- <parameter name="requestCoreThreadPoolSize">50</parameter> --> + <!-- <parameter name="RequestMaxThreadPoolSize">100</parameter> --> + <!-- <parameter name="threadKeepAliveTime">240000</parameter> --> + <!-- <parameter name="threadKeepAliveTimeUnit">MILLISECONDS</parameter> --> + </transportReceiver> + + <!-- Added by Tuscany --> + <!-- transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener" --> + <!-- These configuation parameters now come from the binding.ws uri + or from a policy set + <parameter name="myTopicConnectionFactory"> + <parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter> + <parameter name="java.naming.provider.url">tcp://localhost:61616</parameter> + <parameter name="transport.jms.ConnectionFactoryJNDIName">TopicConnectionFactory</parameter> + </parameter> + + <parameter name="myQueueConnectionFactory"> + <parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter> + <parameter name="java.naming.provider.url">tcp://localhost:61616</parameter> + <parameter name="transport.jms.ConnectionFactoryJNDIName">QueueConnectionFactory</parameter> + </parameter> + + <parameter name="default"> + <parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter> + <parameter name="java.naming.provider.url">tcp://localhost:61616</parameter> + <parameter name="transport.jms.ConnectionFactoryJNDIName">QueueConnectionFactory</parameter> + </parameter> + --> + <!-- /transportReceiver--> + + <!-- ================================================= --> + <!-- Non-blocking http/s Transport Listener --> + + <!-- the non blocking http transport based on HttpCore + NIO extensions + <transportReceiver name="http" class="org.apache.axis2.transport.nhttp.HttpCoreNIOListener"> + <parameter name="port" locked="false">9000</parameter> + <parameter name="non-blocking" locked="false">true</parameter> + </transportReceiver>--> + + <!-- the non blocking https transport based on HttpCore + SSL-NIO extensions + <transportReceiver name="https" class="org.apache.axis2.transport.nhttp.HttpCoreNIOSSLListener"> + <parameter name="port" locked="false">9002</parameter> + <parameter name="non-blocking" locked="false">true</parameter> + <parameter name="keystore" locked="false"> + <KeyStore> + <Location>identity.jks</Location> + <Type>JKS</Type> + <Password>password</Password> + <KeyPassword>password</KeyPassword> + </KeyStore> + </parameter> + <parameter name="truststore" locked="false"> + <TrustStore> + <Location>trust.jks</Location> + <Type>JKS</Type> + <Password>password</Password> + </TrustStore> + </parameter>--> + <!--<parameter name="SSLVerifyClient">require</parameter> + supports optional|require or defaults to none --> + <!--</transportReceiver>--> + + <!-- ================================================= --> + <!-- Mail Transport Listener --> + <!-- This is a sample configuration. It assumes a mail server running in localhost. + Listener pops messages that comes to the email address red@localhost. Users + password is red. Listener connect to the server every 3000 milliseconds. + Parameters with "transport." prefix is Axis2 specific. Others are all from Java Mail API. + http://people.apache.org/~pzf/SMTPBase64Binding-0.2.html + --> + <!-- ================================================= --> + <!--<transportReceiver name="mailto" class="org.apache.axis2.transport.mail.SimpleMailListener"> + <parameter name="mail.pop3.host">localhost</parameter> + <parameter name="mail.pop3.user">red</parameter> + <parameter name="mail.store.protocol">pop3</parameter> + <parameter name="transport.mail.pop3.password">red</parameter> + <parameter name="transport.mail.replyToAddress">red@localhost</parameter> + <parameter name="transport.listener.interval">3000</parameter> + </transportReceiver>--> + + <!--Uncomment if you want to have TCP transport support--> + <!--transportReceiver name="tcp" + class="org.apache.axis2.transport.tcp.TCPServer"> + <parameter name="port">6060</parameter-->> + <!--If you want to give your own host address for EPR generation--> + <!--uncomment the following paramter , and set it as you required.--> + <!--<parameter name="hostname">tcp://myApp.com/ws</parameter>--> + <!-- /transportReceiver --> + + <!-- ================================================= --> + <!-- Transport Outs --> + <!-- ================================================= --> + <!-- + <transportSender name="tcp" + class="org.apache.axis2.transport.tcp.TCPTransportSender"/> + --> + + <transportSender name="http" + class="org.apache.axis2.transport.http.CommonsHTTPTransportSender"> + <parameter name="PROTOCOL">HTTP/1.1</parameter> + <parameter name="Transfer-Encoding">chunked</parameter> + + <!-- If following is set to 'true', optional action part of the Content-Type will not be added to the SOAP 1.2 messages --> + <!-- <parameter name="OmitSOAP12Action">true</parameter> --> + </transportSender> + + <transportSender name="https" + class="org.apache.axis2.transport.http.CommonsHTTPTransportSender"> + <parameter name="PROTOCOL">HTTP/1.1</parameter> + <parameter name="Transfer-Encoding">chunked</parameter> + </transportSender> + + <!-- transportSender name="jms" + class="org.apache.axis2.transport.jms.JMSSender"/--> + + <!-- ================================================= --> + <!-- Non-blocking http/s Transport Sender --> + + <!-- the non-blocking http transport sender based on HttpCore + NIO extensions + <transportSender name="http" class="org.apache.axis2.transport.nhttp.HttpCoreNIOSender"> + <parameter name="non-blocking" locked="false">true</parameter> + </transportSender>--> + + <!-- the non-blocking https transport sender based on HttpCore + NIO SSL extensions + <transportSender name="https" class="org.apache.axis2.transport.nhttp.HttpCoreNIOSSLSender"> + <parameter name="non-blocking" locked="false">true</parameter> + <parameter name="keystore" locked="false"> + <KeyStore> + <Location>identity.jks</Location> + <Type>JKS</Type> + <Password>password</Password> + <KeyPassword>password</KeyPassword> + </KeyStore> + </parameter> + <parameter name="truststore" locked="false"> + <TrustStore> + <Location>trust.jks</Location> + <Type>JKS</Type> + <Password>password</Password> + </TrustStore> + </parameter>--> + <!--<parameter name="HostnameVerifier">DefaultAndLocalhost</parameter> + supports Strict|AllowAll|DefaultAndLocalhost or the default if none specified --> + <!--</transportSender>--> + + <!-- ================================================= --> + <!-- Mail Transport Sender --> + <!--Only need to uncomment the sender. Configuration is achieved with every client. + At any instant mail host should be given. Sample configuration has been given. + http://people.apache.org/~pzf/SMTPBase64Binding-0.2.html + --> + <!-- ================================================= --> + <!--<transportSender name="mailto" class="org.apache.axis2.transport.mail.MailTransportSender"> + <parameter name="mail.smtp.host">localhost</parameter> + </transportSender>--> + + <!-- ================================================= --> + <!-- Global Modules --> + <!-- ================================================= --> + <!-- Comment this to disable Addressing --> + + <!-- Commented out by Tuscany + <module ref="addressing"/> + --> + + <!-- Added by Tuscany --> + <!-- + <module ref="rampart"/> + --> + + <!-- wsp:Policy wsu:Id="UTOverTransport" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> + <wsp:ExactlyOne> + <wsp:All> + <sp:SignedSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"> + <wsp:Policy> + <sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient" /> + </wsp:Policy> + </sp:SignedSupportingTokens> + + <ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy"> + <ramp:user>TuscanyWsUser</ramp:user> + <ramp:passwordType>PasswordText</ramp:passwordType> + <ramp:passwordCallbackClass>org.apache.tuscany.sca.binding.ws.axis2.itests.policy.wspolicy.ClientPWCBHandler</ramp:passwordCallbackClass> + </ramp:RampartConfig> + </wsp:All> + </wsp:ExactlyOne> + </wsp:Policy--> + + <!--Configuring module , providing parameters for modules whether they refer or not--> + <!--<moduleConfig name="addressing">--> + <!--<parameter name="addressingPara">N/A</parameter>--> + <!--</moduleConfig>--> + + <!-- ================================================= --> + <!-- Clustering --> + <!-- ================================================= --> + <!-- Configure and uncomment following for preparing Axis2 to a clustered environment --> + <!-- + <cluster class="org.apache.axis2.cluster.tribes.TribesClusterManager"> + <parameter name="param1">value1</parameter> + <parameter name="domain">apache.axis2.domain</parameter> + <configurationManager class="org.apache.axis2.cluster.configuration.TribesConfigurationManager"> + <listener class="org.apache.axis2.cluster.configuration.DefaultConfigurationManagerListener"/> + </configurationManager> + <contextManager class="org.apache.axis2.cluster.context.TribesContextManager"> + <listener class="org.apache.axis2.cluster.context.DefaultContextManagerListener"/> + </contextManager> + </cluster> + --> + + <!-- ================================================= --> + <!-- Phases --> + <!-- ================================================= --> + <phaseOrder type="InFlow"> + <!-- System pre defined phases --> + <phase name="Transport"> + + <!-- Added by Tuscany --> + <handler name="TuscanyDispatcher" + class="org.apache.tuscany.sca.binding.ws.axis2.provider.TuscanyDispatcher"> + <order phase="Transport"/> + </handler> + + <handler name="RequestURIBasedDispatcher" + class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher"> + <order phase="Transport"/> + </handler> + <handler name="SOAPActionBasedDispatcher" + class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher"> + <order phase="Transport"/> + </handler> + </phase> + <phase name="Addressing"> + <handler name="AddressingBasedDispatcher" + class="org.apache.axis2.dispatchers.AddressingBasedDispatcher"> + <order phase="Addressing"/> + </handler> + </phase> + <phase name="Security"/> + <phase name="PreDispatch"/> + <phase name="Dispatch" class="org.apache.axis2.engine.DispatchPhase"> + <handler name="RequestURIBasedDispatcher" + class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher"/> + <handler name="SOAPActionBasedDispatcher" + class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher"/> + <handler name="RequestURIOperationDispatcher" + class="org.apache.axis2.dispatchers.RequestURIOperationDispatcher"/> + <handler name="SOAPMessageBodyBasedDispatcher" + class="org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher"/> +<!-- + <handler name="HTTPLocationBasedDispatcher" + class="org.apache.axis2.dispatchers.HTTPLocationBasedDispatcher"/> +--> + </phase> + <phase name="RMPhase"/> + <!-- System pre defined phases --> + <!-- After Postdispatch phase module author or service author can add any phase he want --> + <phase name="OperationInPhase"/> + <phase name="soapmonitorPhase"/> + </phaseOrder> + <phaseOrder type="OutFlow"> + <!-- user can add his own phases to this area --> + <phase name="soapmonitorPhase"/> + <phase name="OperationOutPhase"/> + <!--system predefined phase--> + <!--these phase will run irrespective of the service--> + <phase name="RMPhase"/> + <phase name="PolicyDetermination"/> + <phase name="MessageOut"/> + <phase name="Security"/> + </phaseOrder> + <phaseOrder type="InFaultFlow"> + <phase name="Addressing"> + <handler name="AddressingBasedDispatcher" + class="org.apache.axis2.dispatchers.AddressingBasedDispatcher"> + <order phase="Addressing"/> + </handler> + </phase> + <phase name="Security"/> + <phase name="PreDispatch"/> + <phase name="Dispatch" class="org.apache.axis2.engine.DispatchPhase"> + <handler name="RequestURIBasedDispatcher" + class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher"/> + <handler name="SOAPActionBasedDispatcher" + class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher"/> + <handler name="RequestURIOperationDispatcher" + class="org.apache.axis2.dispatchers.RequestURIOperationDispatcher"/> + <handler name="SOAPMessageBodyBasedDispatcher" + class="org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher"/> +<!-- + <handler name="HTTPLocationBasedDispatcher" + class="org.apache.axis2.dispatchers.HTTPLocationBasedDispatcher"/> +--> + </phase> + <phase name="RMPhase"/> + <!-- user can add his own phases to this area --> + <phase name="OperationInFaultPhase"/> + <phase name="soapmonitorPhase"/> + </phaseOrder> + <phaseOrder type="OutFaultFlow"> + <!-- user can add his own phases to this area --> + <phase name="soapmonitorPhase"/> + <phase name="OperationOutFaultPhase"/> + <phase name="RMPhase"/> + <phase name="PolicyDetermination"/> + <phase name="MessageOut"/> + <phase name="Security"/> + </phaseOrder> +</axisconfig> diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/repository/modules/modules.list b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/repository/modules/modules.list new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/repository/modules/modules.list diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/repository/modules/rampart-1.4.mar b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/repository/modules/rampart-1.4.mar Binary files differnew file mode 100644 index 0000000000..ec870734a5 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/repository/modules/rampart-1.4.mar diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/repository/services/services.list b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/repository/services/services.list new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/repository/services/services.list diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/HelloWorldTestCase.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/HelloWorldTestCase.java new file mode 100644 index 0000000000..a482477d3b --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/HelloWorldTestCase.java @@ -0,0 +1,51 @@ +/* + * 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.axis2; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.binding.ws.axis2.helloworld.HelloWorld; +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; + +public class HelloWorldTestCase extends TestCase { + + private Node node; + private HelloWorld helloWorld; + + public void testCalculator() throws Exception { + assertEquals("Hello petra", helloWorld.getGreetings("petra")); + } + + @Override + protected void setUp() throws Exception { + node = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/ws/axis2/helloworld/helloworld.composite", + new Contribution("test", "target/test-classes")); + node.start(); + helloWorld = node.getService(HelloWorld.class, "HelloWorldClient"); + } + + @Override + protected void tearDown() throws Exception { + node.stop(); + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/WSDLBindingTestCase.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/WSDLBindingTestCase.java new file mode 100644 index 0000000000..b55779fa25 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/WSDLBindingTestCase.java @@ -0,0 +1,51 @@ +/* + * 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.axis2; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.binding.ws.axis2.helloworld.HelloWorld; +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; + +public class WSDLBindingTestCase extends TestCase { + + private Node node; + private HelloWorld helloWorld; + + public void testCalculator() throws Exception { + assertEquals("Hello petra", helloWorld.getGreetings("petra")); + } + + @Override + protected void setUp() throws Exception { + node = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/ws/axis2/wsdlbinding/helloworld.composite", + new Contribution("test", "target/test-classes")); + node.start(); + helloWorld = node.getService(HelloWorld.class, "HelloWorldClient"); + } + + @Override + protected void tearDown() throws Exception { + node.stop(); + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/WSDLBindingURITestCase.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/WSDLBindingURITestCase.java new file mode 100644 index 0000000000..54f25694e1 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/WSDLBindingURITestCase.java @@ -0,0 +1,51 @@ +/* + * 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.axis2; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.binding.ws.axis2.helloworld.HelloWorld; +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; + +public class WSDLBindingURITestCase extends TestCase { + + private Node node; + private HelloWorld helloWorld; + + public void testCalculator() throws Exception { + assertEquals("Hello petra", helloWorld.getGreetings("petra")); + } + + @Override + protected void setUp() throws Exception { + node = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/ws/axis2/wsdlbindinguri/helloworld.composite", + new Contribution("test", "target/test-classes")); + node.start(); + helloWorld = node.getService(HelloWorld.class, "HelloWorldClient"); + } + + @Override + protected void tearDown() throws Exception { + node.stop(); + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/WSDLBindingWSATestCase.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/WSDLBindingWSATestCase.java new file mode 100644 index 0000000000..addcf67ac0 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/WSDLBindingWSATestCase.java @@ -0,0 +1,51 @@ +/* + * 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.axis2; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.binding.ws.axis2.helloworld.HelloWorld; +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; + +public class WSDLBindingWSATestCase extends TestCase { + + private Node node; + private HelloWorld helloWorld; + + public void testCalculator() throws Exception { + assertEquals("Hello petra", helloWorld.getGreetings("petra")); + } + + @Override + protected void setUp() throws Exception { + node = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/ws/axis2/wsdlbindingwsa/helloworld.composite", + new Contribution("test", "target/test-classes")); + node.start(); + helloWorld = node.getService(HelloWorld.class, "HelloWorldClient"); + } + + @Override + protected void tearDown() throws Exception { + node.stop(); + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/helloworld/HelloWorld.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/helloworld/HelloWorld.java new file mode 100644 index 0000000000..98eb6e361b --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/helloworld/HelloWorld.java @@ -0,0 +1,29 @@ +/* + * 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.axis2.helloworld; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface HelloWorld { + + String getGreetings(String s); + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/helloworld/HelloWorldClient.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/helloworld/HelloWorldClient.java new file mode 100644 index 0000000000..2c6c4fc92c --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/helloworld/HelloWorldClient.java @@ -0,0 +1,35 @@ +/* + * 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.axis2.helloworld; + +import org.oasisopen.sca.annotation.Reference; + +public class HelloWorldClient implements HelloWorld { + + @Reference + public HelloWorld helloWorldWS; + + public String getGreetings(String s) { + String response = helloWorldWS.getGreetings(s); + System.out.println("At client: " + response); + return response; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/helloworld/HelloWorldService.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/helloworld/HelloWorldService.java new file mode 100644 index 0000000000..3662007984 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/helloworld/HelloWorldService.java @@ -0,0 +1,30 @@ +/* + * 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.axis2.helloworld; + +public class HelloWorldService implements HelloWorld { + + public String getGreetings(String s) { + String response = "Hello " + s; + System.out.println("At service: " + response); + return response; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/helloworld/helloworld.composite b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/helloworld/helloworld.composite new file mode 100644 index 0000000000..fdbb68baea --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/helloworld/helloworld.composite @@ -0,0 +1,45 @@ +<?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. +--> +<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" + xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912" + targetNamespace="http://www.tuscany.apache.org/tests/binding/ws/axis2" + name="HelloWorld"> + + <component name="HelloWorldClient"> + <implementation.java class="org.apache.tuscany.sca.binding.ws.axis2.helloworld.HelloWorldClient"/> + <reference name="helloWorldWS"> + <interface.wsdl interface="http://helloworld#wsdl.interface(HelloWorld)" /> + <binding.ws wsdlElement="http://helloworld#wsdl.port(HelloWorldService/HelloWorldSoapPort1)"/> + </reference> + </component> + + <component name="HelloWorldService"> + <implementation.java class="org.apache.tuscany.sca.binding.ws.axis2.helloworld.HelloWorldService"/> + <service name="HelloWorld"> + <interface.wsdl interface="http://helloworld#wsdl.interface(HelloWorld)" /> + <binding.ws wsdlElement="http://helloworld#wsdl.binding(HelloWorldSoapBinding)"> + <wsa:EndpointReference xmlns:wsa="http://www.w3.org/2005/08/addressing"> + <wsa:Address>http://localhost:8085/services/HelloWorldWebService1</wsa:Address> + </wsa:EndpointReference> + </binding.ws> + </service> + </component> + +</composite> diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/helloworld/helloworld.wsdl b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/helloworld/helloworld.wsdl new file mode 100644 index 0000000000..0d5fd064ae --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/helloworld/helloworld.wsdl @@ -0,0 +1,86 @@ +<?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. +--> +<wsdl:definitions targetNamespace="http://helloworld" xmlns:tns="http://helloworld" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" + name="helloworld"> + + <wsdl:types> + <schema elementFormDefault="qualified" targetNamespace="http://helloworld" xmlns="http://www.w3.org/2001/XMLSchema"> + + <element name="getGreetings"> + <complexType> + <sequence> + <element name="name" type="xsd:string"/> + </sequence> + </complexType> + </element> + + <element name="getGreetingsResponse"> + <complexType> + <sequence> + <element name="getGreetingsReturn" type="xsd:string"/> + </sequence> + </complexType> + </element> + + </schema> + </wsdl:types> + + <wsdl:message name="getGreetingsRequest"> + <wsdl:part element="tns:getGreetings" name="parameters"/> + </wsdl:message> + + <wsdl:message name="getGreetingsResponse"> + <wsdl:part element="tns:getGreetingsResponse" name="parameters"/> + </wsdl:message> + + <wsdl:portType name="HelloWorld"> + <wsdl:operation name="getGreetings"> + <wsdl:input message="tns:getGreetingsRequest" name="getGreetingsRequest"/> + <wsdl:output message="tns:getGreetingsResponse" name="getGreetingsResponse"/> + </wsdl:operation> + </wsdl:portType> + + <wsdl:binding name="HelloWorldSoapBinding" type="tns:HelloWorld"> + <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> + <wsdl:operation name="getGreetings"> + <wsdlsoap:operation soapAction=""/> + <wsdl:input name="getGreetingsRequest"> + <wsdlsoap:body use="literal"/> + </wsdl:input> + <wsdl:output name="getGreetingsResponse"> + <wsdlsoap:body use="literal"/> + </wsdl:output> + </wsdl:operation> + + </wsdl:binding> + + <wsdl:service name="HelloWorldService"> + <wsdl:port binding="tns:HelloWorldSoapBinding" name="HelloWorldSoapPort1"> + <wsdlsoap:address location="http://localhost:8085/services/HelloWorldWebService1"/> + </wsdl:port> + <wsdl:port binding="tns:HelloWorldSoapBinding" name="HelloWorldSoapPort2"> + <wsdlsoap:address location="http://localhost:8085/services/HelloWorldWebService2"/> + </wsdl:port> + <wsdl:port binding="tns:HelloWorldSoapBinding" name="HelloWorldSoapPort3"> + <wsdlsoap:address location="http://localhost:8085/services/HelloWorldWebService3"/> + </wsdl:port> + </wsdl:service> + +</wsdl:definitions> diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlbinding/helloworld.composite b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlbinding/helloworld.composite new file mode 100644 index 0000000000..863d13b97e --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlbinding/helloworld.composite @@ -0,0 +1,41 @@ +<?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. +--> +<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" + xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912" + targetNamespace="http://www.tuscany.apache.org/tests/binding/ws/axis2" + name="wsdlbinding"> + + <component name="HelloWorldClient"> + <implementation.java class="org.apache.tuscany.sca.binding.ws.axis2.helloworld.HelloWorldClient"/> + <reference name="helloWorldWS"> + <interface.wsdl interface="http://helloworld#wsdl.interface(HelloWorld)" /> + <binding.ws uri="http://localhost:8080/HelloWorldService/HelloWorld"/> + </reference> + </component> + + <component name="HelloWorldService"> + <implementation.java class="org.apache.tuscany.sca.binding.ws.axis2.helloworld.HelloWorldService"/> + <service name="HelloWorld"> + <interface.wsdl interface="http://helloworld#wsdl.interface(HelloWorld)" /> + <binding.ws wsdlElement="http://helloworld#wsdl.binding(HelloWorldSoapBinding)"/> + </service> + </component> + +</composite> diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlbindinguri/helloworld.composite b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlbindinguri/helloworld.composite new file mode 100644 index 0000000000..a877f9be26 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlbindinguri/helloworld.composite @@ -0,0 +1,42 @@ +<?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. +--> +<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" + xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912" + targetNamespace="http://www.tuscany.apache.org/tests/binding/ws/axis2" + name="wsdlbindinguri"> + + <component name="HelloWorldClient"> + <implementation.java class="org.apache.tuscany.sca.binding.ws.axis2.helloworld.HelloWorldClient"/> + <reference name="helloWorldWS"> + <interface.wsdl interface="http://helloworld#wsdl.interface(HelloWorld)" /> + <binding.ws wsdlElement="http://helloworld#wsdl.port(HelloWorldService/HelloWorldSoapPort1)"/> + </reference> + </component> + + <component name="HelloWorldService"> + <implementation.java class="org.apache.tuscany.sca.binding.ws.axis2.helloworld.HelloWorldService"/> + <service name="HelloWorld"> + <interface.wsdl interface="http://helloworld#wsdl.interface(HelloWorld)" /> + <binding.ws uri="http://localhost:8085/services/HelloWorldWebService1" + wsdlElement="http://helloworld#wsdl.binding(HelloWorldSoapBinding)"/> + </service> + </component> + +</composite> diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlbindingwsa/helloworld.composite b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlbindingwsa/helloworld.composite new file mode 100644 index 0000000000..7b0263b019 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlbindingwsa/helloworld.composite @@ -0,0 +1,45 @@ +<?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. +--> +<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" + xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912" + targetNamespace="http://www.tuscany.apache.org/tests/binding/ws/axis2" + name="wsdlbindingwsa"> + + <component name="HelloWorldClient"> + <implementation.java class="org.apache.tuscany.sca.binding.ws.axis2.helloworld.HelloWorldClient"/> + <reference name="helloWorldWS"> + <interface.wsdl interface="http://helloworld#wsdl.interface(HelloWorld)" /> + <binding.ws wsdlElement="http://helloworld#wsdl.port(HelloWorldService/HelloWorldSoapPort1)"/> + </reference> + </component> + + <component name="HelloWorldService"> + <implementation.java class="org.apache.tuscany.sca.binding.ws.axis2.helloworld.HelloWorldService"/> + <service name="HelloWorld"> + <interface.wsdl interface="http://helloworld#wsdl.interface(HelloWorld)" /> + <binding.ws wsdlElement="http://helloworld#wsdl.binding(HelloWorldSoapBinding)"> + <wsa:EndpointReference xmlns:wsa="http://www.w3.org/2005/08/addressing"> + <wsa:Address>http://localhost:8085/services/HelloWorldWebService1</wsa:Address> + </wsa:EndpointReference> + </binding.ws> + </service> + </component> + +</composite> diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/LICENSE b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/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/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/META-INF/MANIFEST.MF b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..2bde2fad22 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/META-INF/MANIFEST.MF @@ -0,0 +1,54 @@ +Manifest-Version: 1.0
+Tool: Bnd-0.0.255
+Bundle-Name: Apache Tuscany SCA JAXWS RI 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.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.ri
+Bundle-DocURL: http://www.apache.org/
+Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6 diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/NOTICE b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/NOTICE new file mode 100644 index 0000000000..d69e595698 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2011 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/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/pom.xml b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/pom.xml new file mode 100644 index 0000000000..f5e10cc362 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/pom.xml @@ -0,0 +1,151 @@ +<?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-Beta3-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>tuscany-binding-ws-runtime-jaxws-ri</artifactId> + <name>Apache Tuscany SCA JAXWS RI based WS Binding Extension</name> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-core</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-interface-wsdl</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-assembly-xml</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-ws</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-ws-runtime-jaxws</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-ws-wsdlgen</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-core-databinding</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-databinding-jaxb</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-host-http</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>compile</scope> + </dependency> + + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-databinding</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-interface-java-jaxws</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-xsd</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + </dependency> + + + <!-- Test dependencies --> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-host-jetty</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-node-impl</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-implementation-java-runtime</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-jms_1.1_spec</artifactId> + <version>1.1.1</version> + <scope>provided</scope> + </dependency> + + </dependencies> + + <build> + + </build> + +</project> diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSBindingProviderFactory.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSBindingProviderFactory.java new file mode 100644 index 0000000000..45463fcd53 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSBindingProviderFactory.java @@ -0,0 +1,77 @@ +/* + * 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.ri; + +import java.util.List; + +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; +import org.apache.tuscany.sca.runtime.RuntimeProperties; + +/** + * JAXWSBindingProviderFactory + * + * @version $Rev$ $Date$ + */ + +public class JAXWSBindingProviderFactory implements BindingProviderFactory<WebServiceBinding> { + + private FactoryExtensionPoint modelFactories; + private ServletHost servletHost; + private DataBindingExtensionPoint dataBindings; + private String defaultPort = "8085"; + + public JAXWSBindingProviderFactory(ExtensionPointRegistry extensionPoints) { + ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class); + List<ServletHost> hosts = servletHosts.getServletHosts(); + if (!hosts.isEmpty()) { + this.servletHost = hosts.get(0); + } + modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); + dataBindings = extensionPoints.getExtensionPoint(DataBindingExtensionPoint.class); + + RuntimeProperties ps = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(RuntimeProperties.class); + String pp = ps.getProperties().getProperty(this.getClass().getName() + ".defaultPort"); + if (pp != null) { + this.defaultPort = ps.getProperties().getProperty(this.getClass().getName() + ".defaultPort"); + } + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeEndpointReference endpointReference) { + return new JAXWSReferenceBindingProvider(endpointReference, modelFactories, dataBindings); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeEndpoint endpoint) { + return new JAXWSServiceBindingProvider(endpoint, servletHost, modelFactories, dataBindings, defaultPort); + } + + public Class<WebServiceBinding> getModelType() { + return WebServiceBinding.class; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSReferenceBindingProvider.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSReferenceBindingProvider.java new file mode 100644 index 0000000000..7a1b8f356a --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSReferenceBindingProvider.java @@ -0,0 +1,77 @@ +/* + * 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.ri; + +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.jaxws.JAXWSBindingInvoker; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +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.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; +import org.oasisopen.sca.ServiceRuntimeException; +import org.w3c.dom.Node; + +public class JAXWSReferenceBindingProvider implements ReferenceBindingProvider { + + private javax.xml.soap.MessageFactory messageFactory; + private WebServiceBinding wsBinding; + private RuntimeEndpointReference endpointReference; + + public JAXWSReferenceBindingProvider(RuntimeEndpointReference endpointReference, + FactoryExtensionPoint modelFactories, + DataBindingExtensionPoint dataBindings) { + + this.endpointReference = endpointReference; + this.messageFactory = modelFactories.getFactory(javax.xml.soap.MessageFactory.class); + this.wsBinding = (WebServiceBinding) endpointReference.getBinding(); + + // A WSDL document should always be present in the binding + if (wsBinding.getGeneratedWSDLDocument() == null) { + throw new ServiceRuntimeException("No WSDL document for " + endpointReference.getURI()); + } + + // Set to use the DOM data binding + InterfaceContract contract = wsBinding.getBindingInterfaceContract(); + if (contract.getInterface() != null) { + contract.getInterface().resetDataBinding(Node.class.getName()); + } + } + + public void start() { + } + + public void stop() { + } + + public InterfaceContract getBindingInterfaceContract() { + return wsBinding.getBindingInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return true; + } + + public Invoker createInvoker(Operation operation) { + return new JAXWSBindingInvoker(operation, null, messageFactory, wsBinding, endpointReference); + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSServiceBindingProvider.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSServiceBindingProvider.java new file mode 100644 index 0000000000..a0096f6ca2 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSServiceBindingProvider.java @@ -0,0 +1,145 @@ +/* + * 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.ri; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLWriter; +import javax.xml.namespace.QName; +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; +import javax.xml.ws.Endpoint; +import javax.xml.ws.Service.Mode; +import javax.xml.ws.ServiceMode; +import javax.xml.ws.WebServiceProvider; +import javax.xml.ws.soap.SOAPBinding; + +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.jaxws.JAXWSBindingProvider; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; + +@WebServiceProvider +@ServiceMode(Mode.MESSAGE) +public class JAXWSServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeEndpoint endpoint; + private WebServiceBinding wsBinding; + + private JAXWSBindingProvider jaxwsBindingProvider; + + private Endpoint wsEndpoint; + + public JAXWSServiceBindingProvider(RuntimeEndpoint endpoint, + ServletHost servletHost, + FactoryExtensionPoint modelFactories, + DataBindingExtensionPoint dataBindings, String defaultPort) { + + this.endpoint = endpoint; + this.wsBinding = (WebServiceBinding)endpoint.getBinding(); + + jaxwsBindingProvider = new JAXWSBindingProvider(endpoint, + servletHost, + modelFactories, + dataBindings, + defaultPort); + } + + public void start() { + // create the JAXWS endpoint based on the provider + wsEndpoint = Endpoint.create(SOAPBinding.SOAP11HTTP_BINDING, jaxwsBindingProvider); + + // TODO - There is something odd in the way that service name is calculated in + // some circumstances + // sometimes getServiceName() returns null + // sometimes getService().getQName returns a QName namespace that doesn't match the WSDL + // sometimes getNamespace() returns null + // So here we delve directly into the WSDL4J model as the Tuscany model isn't up to date + String targetNamespace = wsBinding.getUserSpecifiedWSDLDefinition().getDefinition().getTargetNamespace(); + + //set up WSDL for Provider + List<Source> metadata = new ArrayList<Source>(); + + // WSDL DOM seems to be null here so went with writing out + // string version of WSDL and reading it back in again + //Node node = wsBinding.getWSDLDefinition().getDefinition().getDocumentationElement(); + //Source source = new DOMSource(node); + + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + try { + WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter(); + writer.writeWSDL(wsBinding.getUserSpecifiedWSDLDefinition().getDefinition(), outStream); + } catch (Exception ex){ + ex.printStackTrace(); + } + + //System.out.println(outStream.toString()); + ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray()); + Source source = new StreamSource(inStream); + source.setSystemId(targetNamespace); + + metadata.add(source); + + Map<String, Object> properties = new HashMap<String, Object>(); + + QName portName = new QName(targetNamespace, + wsBinding.getPort().getName()); + properties.put(Endpoint.WSDL_PORT, portName); + + QName bindingServiceName = wsBinding.getServiceName() == null ? wsBinding.getService().getQName() : wsBinding.getServiceName(); + QName serviceName = new QName(targetNamespace, + bindingServiceName.getLocalPart()); + properties.put(Endpoint.WSDL_SERVICE, serviceName); + + wsEndpoint.setMetadata(metadata); + wsEndpoint.setProperties(properties); + + // Start up the endpoint + + wsEndpoint.publish(wsBinding.getURI()); + + + jaxwsBindingProvider.start(); + endpoint.setDeployedURI(wsBinding.getURI()); + + } + + public void stop() { + jaxwsBindingProvider.stop(); + wsEndpoint.stop(); + } + + public InterfaceContract getBindingInterfaceContract() { + return wsBinding.getBindingInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return true; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..9a36d0e461 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,19 @@ +# 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.
+
+# Implementation class for the binding extension
+org.apache.tuscany.sca.binding.ws.jaxws.ri.JAXWSBindingProviderFactory;model=org.apache.tuscany.sca.binding.ws.WebServiceBinding
diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/WSDLPortTestCase.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/WSDLPortTestCase.java new file mode 100644 index 0000000000..80aa145098 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/WSDLPortTestCase.java @@ -0,0 +1,100 @@ +/* + * 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.axis2; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.List; +import java.util.Properties; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.binding.ws.axis2.helloworld.HelloWorld; +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; + +public class WSDLPortTestCase extends TestCase { + + private Node node; + private HelloWorld helloWorld; + + + @Override + protected void setUp() throws Exception { + node = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/ws/axis2/wsdlport/helloworld.composite", + new Contribution("test", "target/test-classes")); + node.start(); + helloWorld = node.getService(HelloWorld.class, "HelloWorldClient"); + } + + public void testMessageExchange() throws Exception { + assertEquals("Hello petra", helloWorld.getGreetings("petra")); + } + + public void testQuestionMarkWSDL() throws Exception { + InputStream inp = new URL("http://localhost:8085/HelloWorldService/HelloWorld?wsdl").openStream(); + BufferedReader br = new BufferedReader(new InputStreamReader(inp)); + String line; + while((line = br.readLine()) != null) { + System.out.println(line); + } + br.close(); + + WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); + wsdlReader.setFeature("javax.wsdl.verbose",false); + wsdlReader.setFeature("javax.wsdl.importDocuments",true); + + Definition definition = wsdlReader.readWSDL("http://localhost:8085/HelloWorldService/HelloWorld?wsdl"); + assertNotNull(definition); + Service service = definition.getService(new QName("http://helloworld", + "HelloWorldService")); + Port port = service.getPort("HelloWorldSoapPort"); + + String endpoint = getEndpoint(port); + assertEquals("http://localhost:8085/HelloWorldService/HelloWorld", endpoint); + } + + protected String getEndpoint(Port port) { + List wsdlPortExtensions = port.getExtensibilityElements(); + for (final Object extension : wsdlPortExtensions) { + if (extension instanceof SOAPAddress) { + return ((SOAPAddress) extension).getLocationURI(); + } + } + throw new RuntimeException("no SOAPAddress"); + } + + @Override + protected void tearDown() throws Exception { + node.stop(); + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/helloworld/HelloWorld.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/helloworld/HelloWorld.java new file mode 100644 index 0000000000..98eb6e361b --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/helloworld/HelloWorld.java @@ -0,0 +1,29 @@ +/* + * 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.axis2.helloworld; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface HelloWorld { + + String getGreetings(String s); + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/helloworld/HelloWorldClient.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/helloworld/HelloWorldClient.java new file mode 100644 index 0000000000..2c6c4fc92c --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/helloworld/HelloWorldClient.java @@ -0,0 +1,35 @@ +/* + * 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.axis2.helloworld; + +import org.oasisopen.sca.annotation.Reference; + +public class HelloWorldClient implements HelloWorld { + + @Reference + public HelloWorld helloWorldWS; + + public String getGreetings(String s) { + String response = helloWorldWS.getGreetings(s); + System.out.println("At client: " + response); + return response; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/helloworld/HelloWorldService.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/helloworld/HelloWorldService.java new file mode 100644 index 0000000000..3662007984 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/helloworld/HelloWorldService.java @@ -0,0 +1,30 @@ +/* + * 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.axis2.helloworld; + +public class HelloWorldService implements HelloWorld { + + public String getGreetings(String s) { + String response = "Hello " + s; + System.out.println("At service: " + response); + return response; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlport/helloworld.composite b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlport/helloworld.composite new file mode 100644 index 0000000000..9f74fc5c09 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlport/helloworld.composite @@ -0,0 +1,39 @@ +<?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. +--> +<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" + xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912" + targetNamespace="http://www.tuscany.apache.org/tests/binding/ws/axis2" + name="wsdlbinding"> + + <component name="HelloWorldClient"> + <implementation.java class="org.apache.tuscany.sca.binding.ws.axis2.helloworld.HelloWorldClient"/> + <reference name="helloWorldWS"> + <binding.ws wsdlElement="http://helloworld#wsdl.port(HelloWorldService/HelloWorldSoapPort)"/> + </reference> + </component> + + <component name="HelloWorldService"> + <implementation.java class="org.apache.tuscany.sca.binding.ws.axis2.helloworld.HelloWorldService"/> + <service name="HelloWorld"> + <binding.ws wsdlElement="http://helloworld#wsdl.port(HelloWorldService/HelloWorldSoapPort)"/> + </service> + </component> + +</composite> diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlport/helloworld.wsdl b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlport/helloworld.wsdl new file mode 100644 index 0000000000..c5b59f1462 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws-ri/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/wsdlport/helloworld.wsdl @@ -0,0 +1,80 @@ +<?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. +--> +<wsdl:definitions targetNamespace="http://helloworld" xmlns:tns="http://helloworld" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" + name="helloworld"> + + <wsdl:types> + <schema elementFormDefault="qualified" targetNamespace="http://helloworld" xmlns="http://www.w3.org/2001/XMLSchema"> + + <element name="getGreetings"> + <complexType> + <sequence> + <element name="name" type="xsd:string"/> + </sequence> + </complexType> + </element> + + <element name="getGreetingsResponse"> + <complexType> + <sequence> + <element name="getGreetingsReturn" type="xsd:string"/> + </sequence> + </complexType> + </element> + + </schema> + </wsdl:types> + + <wsdl:message name="getGreetingsRequest"> + <wsdl:part element="tns:getGreetings" name="parameters"/> + </wsdl:message> + + <wsdl:message name="getGreetingsResponse"> + <wsdl:part element="tns:getGreetingsResponse" name="parameters"/> + </wsdl:message> + + <wsdl:portType name="HelloWorld"> + <wsdl:operation name="getGreetings"> + <wsdl:input message="tns:getGreetingsRequest" name="getGreetingsRequest"/> + <wsdl:output message="tns:getGreetingsResponse" name="getGreetingsResponse"/> + </wsdl:operation> + </wsdl:portType> + + <wsdl:binding name="HelloWorldSoapBinding" type="tns:HelloWorld"> + <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> + <wsdl:operation name="getGreetings"> + <wsdlsoap:operation soapAction=""/> + <wsdl:input name="getGreetingsRequest"> + <wsdlsoap:body use="literal"/> + </wsdl:input> + <wsdl:output name="getGreetingsResponse"> + <wsdlsoap:body use="literal"/> + </wsdl:output> + </wsdl:operation> + + </wsdl:binding> + + <wsdl:service name="HelloWorldService"> + <wsdl:port binding="tns:HelloWorldSoapBinding" name="HelloWorldSoapPort"> + <wsdlsoap:address location="http://localhost:8085/HelloWorldService/HelloWorld"/> + </wsdl:port> + </wsdl:service> + +</wsdl:definitions> diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws/LICENSE b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/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/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws/META-INF/MANIFEST.MF b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..ac68264fcb --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws/META-INF/MANIFEST.MF @@ -0,0 +1,55 @@ +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.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/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws/NOTICE b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws/NOTICE new file mode 100644 index 0000000000..d69e595698 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2011 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/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws/pom.xml b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws/pom.xml new file mode 100644 index 0000000000..f938dfa66c --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws/pom.xml @@ -0,0 +1,194 @@ +<?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-Beta3-SNAPSHOT</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-Beta3-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-interface-wsdl</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-assembly-xml</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-ws</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-ws-wsdlgen</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-core-databinding</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-databinding-jaxb</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-host-http</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-databinding</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-interface-java-jaxws</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-xsd</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + </dependency> + + <!-- Test dependencies --> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-node-impl</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-implementation-java-runtime</artifactId> + <version>2.0-Beta3-SNAPSHOT</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.codehaus.mojo</groupId> + <artifactId>jaxws-maven-plugin</artifactId> + <version>1.10</version> +--> + <!-- Explicitly add the transitive dependencies for jaxws-api + http://jira.codehaus.org/browse/MEV-498 + --> +<!-- + <dependencies> + <dependency> + <groupId>javax.jws</groupId> + <artifactId>jsr181-api</artifactId> + <version>1.0-MR1</version> + </dependency> + <dependency> + <groupId>javax.annotation</groupId> + <artifactId>jsr250-api</artifactId> + <version>1.0</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/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingInvoker.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingInvoker.java new file mode 100644 index 0000000000..bf573f9970 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingInvoker.java @@ -0,0 +1,580 @@ +/* + * 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.Iterator; +import java.util.List; + +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.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.Node; + +/** + * 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_FROM = new QName(WSA_FINAL_NAMESPACE, "From", "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 Dispatch<SOAPMessage> dispatch; + private MessageFactory messageFactory; + private Operation operation; + private 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; + this.dispatch = createDispatch(wsBinding); + } + + private Dispatch<SOAPMessage> createDispatch(WebServiceBinding wsBinding) { + URL wsdlLocation = null; + try { + wsdlLocation = new URL(wsBinding.getGeneratedWSDLDocument().getDocumentBaseURI()); + } catch (Exception e) { + try { + if (wsBinding.getUserSpecifiedWSDLDefinition().getLocation() != null) { + wsdlLocation = wsBinding.getUserSpecifiedWSDLDefinition().getLocation().toURL(); + } + } catch (MalformedURLException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + + QName serviceName = null; + QName portName = null; + Service service = null; + + if (wsdlLocation != null) { + serviceName = wsBinding.getServiceName(); + portName = new QName(serviceName.getNamespaceURI(), wsBinding.getPortName()); + service = Service.create(wsdlLocation, serviceName); + } else { + serviceName = wsBinding.getService().getQName(); + portName = new QName(serviceName.getNamespaceURI(), wsBinding.getPort().getName()); + service = Service.create(serviceName); + service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, wsBinding.getURI()); + } + + return service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE); + } + + public Message invoke(Message msg) { + try { + SOAPMessage resp = invokeTarget(msg); + SOAPBody body = resp.getSOAPBody(); + if (body != null) { + SOAPFault fault = body.getFault(); + if (fault != null) { + // setFault(msg, fault); + } else { + // The 1st child element + msg.setBody(body.getChildElements().next()); + } + + } + } 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.getFirstChild(), e); + fe.setFaultName(entry.getElementQName()); + msg.setFaultBody(fe); + } + } + } + + 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(); + // 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(); + if (operation.isNonBlocking()) { + dispatch.invokeOneWay(soapMessage); + return null; + } + + if (action != null) { + dispatch.getRequestContext().put(Dispatch.SOAPACTION_USE_PROPERTY, true); + dispatch.getRequestContext().put(Dispatch.SOAPACTION_URI_PROPERTY, action); + } + SOAPMessage response = dispatch.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? + 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); + fromH.setTextContent(callbackEndpoint.getBinding().getURI()); + + addWSAActionHeader(sh, action); + + // requestMC.setFrom(fromEPR); + } // end if + + String toAddress = getToAddress(msg); + // requestMC.setTo( new EndpointReference(toAddress) ); + + if (isInvocationForCallback(msg)) { + addWSAToHeader(sh, toAddress, 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(wsBinding); + if (to == null) { + Endpoint ep = msg.getTo(); + if (ep != null && ep.getBinding() != null) { + address = ep.getBinding().getURI(); + } 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(WebServiceBinding binding) { + String ep = null; + if (binding.getPort() != null) { + List<?> wsdlPortExtensions = binding.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 = binding.getURI(); + } + 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); + + // Deal with Reference Parameters, if present - copy to the header + // without the wsa:ReferenceParameters wrapper + // OMElement refParms = (OMElement) msg.getHeaders().get(WS_REF_PARMS); + // Iterator ces = sh.getChildElements(new QName(WSA_FINAL_NAMESPACE, + // WS_REF_PARMS)); + Iterator<SOAPElement> ces = sh.getChildElements(); + while (ces.hasNext()) { + SOAPElement se = ces.next(); + if (WS_REF_PARMS.equals(se.getElementQName().getLocalPart())) { + // if( refParms != null ) { + Iterator<SOAPElement> children = se.getChildElements(); + while (children.hasNext()) { + SOAPElement node = (SOAPElement)children.next(); + toH.addChildElement(node); + } + // } // end if + } + } + + } // end method addWSAActionHeader + + 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 + + private static String WS_MESSAGE_ID = "WS_MESSAGE_ID"; + 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 { + String idValue = (String)msg.getHeaders().get(WS_MESSAGE_ID); + 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/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingProvider.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingProvider.java new file mode 100644 index 0000000000..5cc9277201 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-runtime-jaxws/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/JAXWSBindingProvider.java @@ -0,0 +1,314 @@ +/* + * 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.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.host.http.ServletHost; +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_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, + ServletHost servletHost, + 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 ); + } // 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); + Endpoint callbackEndpoint = 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 + + private static String WS_MESSAGE_ID = "WS_MESSAGE_ID"; + /** + * 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(); + // Store the value of the message ID element into the message under "WS_MESSAGE_ID"... + msg.getHeaders().put(WS_MESSAGE_ID, idValue); + } // end if + } // end method handleMessageID + // 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")); +// } + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/LICENSE b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/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/branches/2.0-Beta3/modules/binding-ws-wsdlgen/META-INF/MANIFEST.MF b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..c71dfdb8d8 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/META-INF/MANIFEST.MF @@ -0,0 +1,60 @@ +Manifest-Version: 1.0
+Export-Package: org.apache.tuscany.sca.binding.ws.wsdlgen;uses:="org.a
+ pache.tuscany.sca.databinding,org.apache.tuscany.sca.interfacedef.uti
+ l,org.apache.tuscany.sca.core,org.apache.tuscany.sca.policy,javax.wsd
+ l.extensions.schema,javax.xml.namespace,javax.wsdl.xml,javax.wsdl.ext
+ ensions,org.apache.tuscany.sca.contribution.resolver,org.oasisopen.sca,org
+ .apache.ws.commons.schema,javax.wsdl.factory,org.apache.tuscany.sca.a
+ ssembly,javax.wsdl.extensions.soap,javax.xml.parsers,org.apache.tusca
+ ny.sca.monitor,org.apache.tuscany.sca.interfacedef.java,org.apache.tu
+ scany.sca.interfacedef,org.w3c.dom,javax.wsdl,org.apache.tuscany.sca.
+ binding.ws,javax.wsdl.extensions.soap12,org.apache.tuscany.sca.databi
+ nding.jaxb,org.apache.tuscany.sca.interfacedef.wsdl,org.apache.ws.com
+ mons.schema.utils,org.apache.tuscany.sca.xsd";version="2.0.0"
+SCA-Version: 1.1
+Bundle-Name: Apache Tuscany SCA Web Service binding WSDL Generator
+Bundle-Vendor: The Apache Software Foundation
+Bundle-Version: 2.0.0
+Bundle-ManifestVersion: 2
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Bundle-Description: Apache Tuscany SCA Web Service binding WSDL Genera
+ tor
+Import-Package: javax.jws;resolution:=optional,
+ javax.wsdl,
+ javax.wsdl.extensions,
+ javax.wsdl.extensions.schema,
+ javax.wsdl.extensions.soap,
+ javax.wsdl.extensions.soap12,
+ javax.wsdl.factory,
+ javax.wsdl.xml,
+ javax.xml.bind.annotation;resolution:=optional,
+ javax.xml.namespace,
+ javax.xml.parsers,
+ javax.xml.ws;resolution:=optional,
+ org.apache.tuscany.sca.assembly;version="2.0.0",
+ org.apache.tuscany.sca.assembly.builder;version="2.0.0",
+ org.apache.tuscany.sca.binding.ws;version="2.0.0",
+ org.apache.tuscany.sca.binding.ws.wsdlgen;version="2.0.0",
+ org.apache.tuscany.sca.contribution;version="2.0.0";resolution:=optional,
+ org.apache.tuscany.sca.contribution.resolver;version="2.0.0",
+ org.apache.tuscany.sca.core;version="2.0.0",
+ org.apache.tuscany.sca.databinding;version="2.0.0",
+ org.apache.tuscany.sca.databinding.jaxb;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.impl;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.java;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.java.jaxws;version="2.0.0";resolution:=optional,
+ org.apache.tuscany.sca.interfacedef.util;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.wsdl;version="2.0.0",
+ org.apache.tuscany.sca.monitor;version="2.0.0",
+ org.apache.tuscany.sca.policy;version="2.0.0",
+ org.apache.tuscany.sca.xsd;version="2.0.0",
+ org.apache.tuscany.sca.xsd.xml;version="2.0.0";resolution:=optional,
+ org.apache.ws.commons.schema,
+ org.apache.ws.commons.schema.utils,
+ org.oasisopen.sca;version="2.0.0",
+ org.oasisopen.sca.annotation;version="2.0.0";resolution:=optional,
+ org.w3c.dom
+Bundle-SymbolicName: org.apache.tuscany.sca.binding.ws.wsdlgen
+Bundle-DocURL: http://www.apache.org/
+Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6 diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/NOTICE b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/NOTICE new file mode 100644 index 0000000000..f6ce2542c3 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/NOTICE @@ -0,0 +1,6 @@ +${pom.name}
+Copyright (c) 2005 - 2011 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/branches/2.0-Beta3/modules/binding-ws-wsdlgen/pom.xml b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/pom.xml new file mode 100644 index 0000000000..fac0565eb3 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/pom.xml @@ -0,0 +1,79 @@ +<?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-Beta3-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>tuscany-binding-ws-wsdlgen</artifactId> + <name>Apache Tuscany SCA Web Service binding WSDL Generator</name> + + <dependencies> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-ws</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-interface-wsdl</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-interface-java</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-interface-java-jaxws</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-xsd</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-databinding</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-core-databinding</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + </dependencies> + +</project> diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGenerator.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGenerator.java new file mode 100644 index 0000000000..516a62a556 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGenerator.java @@ -0,0 +1,359 @@ +/* + * 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.wsdlgen; + +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.wsdl.Definition; +import javax.wsdl.PortType; +import javax.wsdl.WSDLException; +import javax.wsdl.xml.WSDLWriter; +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ResolverExtension; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySubject; +import org.apache.tuscany.sca.xsd.XSDFactory; + +/** + * @version $Rev$ $Date$ + */ +public class BindingWSDLGenerator { + private static final Logger logger = Logger.getLogger(BindingWSDLGenerator.class.getName()); + private static final QName SOAP12_INTENT = new QName("http://docs.oasis-open.org/ns/opencsa/sca/200912", "SOAP.v1_2"); + + public static boolean printWSDL; // external code sets this to print generated WSDL + + private BindingWSDLGenerator() { + // this class has static methods only and cannot be instantiated + } + + /** + * Log a warning message. + * @param problem + */ + private static void logWarning(Problem problem) { + Logger problemLogger = Logger.getLogger(problem.getSourceClassName(), problem.getResourceBundleName()); + if (problemLogger != null){ + problemLogger.logp(Level.WARNING, problem.getSourceClassName(), null, problem.getMessageId(), problem.getMessageParams()); + } else { + logger.severe("Can't get logger " + problem.getSourceClassName()+ " with bundle " + problem.getResourceBundleName()); + } + } + + /** + * Report a warning. + * @param message + * @param binding + * @param parameters + */ + private static void warning(Monitor monitor, String message, WebServiceBinding wsBinding, String... messageParameters) { + Problem problem = monitor.createProblem(BindingWSDLGenerator.class.getName(), "wsdlgen-validation-messages", Severity.WARNING, wsBinding, message, (Object[])messageParameters); + if (monitor != null) { + monitor.problem(problem); + } else { + logWarning(problem); + } + } + + /** + * Report an error. + * @param message + * @param binding + * @param parameters + */ + private static void error(Monitor monitor, String message, WebServiceBinding wsBinding, String... messageParameters) { + Problem problem = monitor.createProblem(BindingWSDLGenerator.class.getName(), "wsdlgen-validation-messages", Severity.ERROR, wsBinding, message, (Object[])messageParameters); + if (monitor != null) { + monitor.problem(problem); + } else { + throw new WSDLGenerationException(problem.toString(), null, problem); + } + } + + /** + * Report an exception error. + * @param message + * @param binding + * @param exception + */ + private static void error(Monitor monitor, String message, WebServiceBinding wsBinding, Exception ex) { + Problem problem = monitor.createProblem(BindingWSDLGenerator.class.getName(), "wsdlgen-validation-messages", Severity.ERROR, wsBinding, message, ex); + if (monitor != null) { + monitor.problem(problem); + } else { + throw new WSDLGenerationException(problem.toString(), ex, problem); + } + } + + /** + * Report a fatal error. + * @param message + * @param binding + * @param exception + */ + private static void fatal(Monitor monitor, String message, WebServiceBinding wsBinding, String... messageParameters) { + Problem problem = monitor.createProblem(BindingWSDLGenerator.class.getName(), "wsdlgen-validation-messages", Severity.ERROR,wsBinding, message, (Object[])messageParameters); + throw new WSDLGenerationException(problem.toString(), null, problem); + } + + /** + * Report a fatal exception error. + * @param message + * @param binding + * @param exception + */ + private static void fatal(Monitor monitor, String message, WebServiceBinding wsBinding, Exception ex) { + Problem problem = monitor.createProblem(BindingWSDLGenerator.class.getName(), "wsdlgen-validation-messages", Severity.ERROR, wsBinding, message, ex); + throw new WSDLGenerationException(problem.toString(), ex, problem); + } + + /** + * This method can be called from the binding builder or from the runtime. + * Report problems and exceptions in the most appropriate way for both + * of these cases. + */ + public static void generateWSDL(Component component, + Contract contract, + WebServiceBinding wsBinding, + ExtensionPointRegistry extensionPoints, + Monitor monitor) { + if (monitor == null) { + monitor = new BuilderContext(extensionPoints).getMonitor(); + } + try { + createWSDLDocument(component, contract, wsBinding, extensionPoints, monitor); + } catch (WSDLGenerationException ex) { + if (ex.getProblem() != null) { + warning(monitor, "WsdlGenProblem", wsBinding, component.getName(), contract.getName()); + if (monitor != null) { + monitor.problem(ex.getProblem()); + } else { + throw ex; + } + } else if (ex.getCause() instanceof Exception) { + warning(monitor, "WsdlGenException", wsBinding, component.getName(), contract.getName()); + error(monitor, "WsdlGenException2", wsBinding, (Exception)ex.getCause()); + } else { // should never happen + throw new IllegalStateException(ex); + } + } catch (RuntimeException ex) { + warning(monitor, "WsdlGenException", wsBinding, component.getName(), contract.getName()); + error(monitor, "WsdlGenException2", wsBinding, component.getName(), contract.getName(), ex.getMessage()); + } + } + + private static void createWSDLDocument(Component component, + Contract contract, + WebServiceBinding wsBinding, + ExtensionPointRegistry extensionPoints, + Monitor monitor) { + FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); + DataBindingExtensionPoint dataBindings = extensionPoints.getExtensionPoint(DataBindingExtensionPoint.class); + WSDLFactory wsdlFactory = modelFactories.getFactory(WSDLFactory.class); + XSDFactory xsdFactory = modelFactories.getFactory(XSDFactory.class); + DocumentBuilderFactory documentBuilderFactory = modelFactories.getFactory(DocumentBuilderFactory.class); + + if (((Contract)contract).getInterfaceContract(wsBinding) == null) { + // can happen if incorrect component service name + fatal(monitor, "MissingInterfaceContract", wsBinding, component.getName(), contract.getName()); + } + + InterfaceContract icontract = wsBinding.getBindingInterfaceContract(); + if (icontract == null) { + icontract = ((Contract)contract).getInterfaceContract(wsBinding).makeUnidirectional(false); + if (icontract instanceof JavaInterfaceContract) { + ModelResolver resolver = component instanceof ResolverExtension ? + ((ResolverExtension)component).getModelResolver() : null; + icontract = createWSDLInterfaceContract( + (JavaInterfaceContract)icontract, + requiresSOAP12(wsBinding), + resolver, + dataBindings, + wsdlFactory, + xsdFactory, + documentBuilderFactory, + monitor); + } else { + try { + //TUSCANY-2316 Cloning the Interface Contract to avoid overriding data binding information + icontract = (InterfaceContract)icontract.clone(); + } catch (Exception e) { + //ignore + } + } + wsBinding.setBindingInterfaceContract(icontract); + } + + /* + // Look at all the Web Service bindings of the SCA service to see if any + // of them have an existing generated WSDL definitions document. If found, + // use it for this binding as well. If not found, generate a new document. + Definition definition = null; + for (Binding binding : contract.getBindings()) { + if (binding instanceof WebServiceBinding) { + definition = ((WebServiceBinding)binding).getWSDLDocument(); + if (definition != null) { + wsBinding.setWSDLDocument(definition); + break; + } + } + } + */ + // The above code is currently not used. Instead, we only look + // for a WSDL definitions document in this binding and don't + // attempt to share the same document across multiple bindings. + + // generate a WSDL definitions document if needed + Definition definition = wsBinding.getGeneratedWSDLDocument(); + if (definition == null) { + definition = WSDLServiceGenerator.configureWSDLDefinition(wsBinding, component, contract, monitor); + wsBinding.setGeneratedWSDLDocument(definition); + } + } + + protected static boolean requiresSOAP12(WebServiceBinding wsBinding) { + if (wsBinding instanceof PolicySubject) { + List<Intent> intents = ((PolicySubject)wsBinding).getRequiredIntents(); + for (Intent intent : intents) { + if (SOAP12_INTENT.equals(intent.getName())) { + return true; + } + } + } + return false; + } + + /** + * Create a WSDLInterfaceContract from a JavaInterfaceContract + */ + public static WSDLInterfaceContract createWSDLInterfaceContract(JavaInterfaceContract contract, + boolean requiresSOAP12, + ModelResolver resolver, + DataBindingExtensionPoint dataBindings, + WSDLFactory wsdlFactory, + XSDFactory xsdFactory, + DocumentBuilderFactory documentBuilderFactory, + Monitor monitor) { + + WSDLInterfaceContract wsdlContract = wsdlFactory.createWSDLInterfaceContract(); + + if (contract.getInterface() != null){ + WSDLInterface wsdlInterface = createWSDLInterface((JavaInterface)contract.getInterface(), + requiresSOAP12, + resolver, + dataBindings, + wsdlFactory, + xsdFactory, + documentBuilderFactory, + monitor); + wsdlContract.setInterface(wsdlInterface); + } + + if (contract.getCallbackInterface() != null){ + WSDLInterface wsdlInterface = createWSDLInterface((JavaInterface)contract.getCallbackInterface(), + requiresSOAP12, + resolver, + dataBindings, + wsdlFactory, + xsdFactory, + documentBuilderFactory, + monitor); + wsdlContract.setCallbackInterface(wsdlInterface); + } + + return wsdlContract; + } + + /** + * Create a WSDLInterface from a JavaInterface + */ + public static WSDLInterface createWSDLInterface(JavaInterface javaInterface, + boolean requiresSOAP12, + ModelResolver resolver, + DataBindingExtensionPoint dataBindings, + WSDLFactory wsdlFactory, + XSDFactory xsdFactory, + DocumentBuilderFactory documentBuilderFactory, + Monitor monitor) { + + WSDLInterface wsdlInterface = wsdlFactory.createWSDLInterface(); + WSDLDefinition wsdlDefinition = wsdlFactory.createWSDLDefinition(); + + Definition def = null; + try { + Interface2WSDLGenerator wsdlGenerator = + new Interface2WSDLGenerator(requiresSOAP12, resolver, dataBindings, xsdFactory, documentBuilderFactory, monitor); + def = wsdlGenerator.generate(javaInterface, wsdlDefinition); + } catch (WSDLException e) { + throw new WSDLGenerationException(e); + } + + // for debugging + if (printWSDL) { + try { + System.out.println("Generated WSDL for Java interface " + javaInterface.getName() + " class " + javaInterface.getJavaClass().getName()); + WSDLWriter writer = javax.wsdl.factory.WSDLFactory.newInstance().newWSDLWriter(); + writer.writeWSDL(def, System.out); + } catch (WSDLException e) { + throw new WSDLGenerationException(e); + } + } + + wsdlDefinition.setDefinition(def); + wsdlInterface.setWsdlDefinition(wsdlDefinition); + wsdlInterface.setRemotable(true); + wsdlInterface.setUnresolved(false); + wsdlInterface.setRemotable(true); + PortType portType = (PortType)def.getAllPortTypes().values().iterator().next(); + wsdlInterface.setPortType(portType); + + try { + wsdlFactory.createWSDLInterface(wsdlInterface, portType, wsdlDefinition, resolver, monitor); + } catch (InvalidInterfaceException e) { + throw new WSDLGenerationException(e); + } + + return wsdlInterface; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java new file mode 100644 index 0000000000..8d80898071 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java @@ -0,0 +1,909 @@ +/* + * 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.wsdlgen; + +import java.lang.reflect.Method; +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.wsdl.Definition; +import javax.wsdl.Fault; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.OperationType; +import javax.wsdl.Output; +import javax.wsdl.Part; +import javax.wsdl.PortType; +import javax.wsdl.Types; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.schema.Schema; +import javax.wsdl.factory.WSDLFactory; +import javax.xml.bind.annotation.XmlSeeAlso; +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.XMLTypeHelper; +import org.apache.tuscany.sca.databinding.jaxb.JAXBDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.ParameterMode; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaOperation; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper; +import org.apache.tuscany.sca.interfacedef.util.TypeInfo; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.xsd.XSDFactory; +import org.apache.tuscany.sca.xsd.XSDefinition; +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaCollection; +import org.apache.ws.commons.schema.XmlSchemaException; +import org.apache.ws.commons.schema.utils.NamespaceMap; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * @version $Rev$ $Date$ + */ +public class Interface2WSDLGenerator { + private static final Logger logger = Logger.getLogger(Interface2WSDLGenerator.class.getName()); + private static final String SCHEMA_NS = "http://www.w3.org/2001/XMLSchema"; + private static final String SCHEMA_NAME = "schema"; + private static final QName SCHEMA_QNAME = new QName(SCHEMA_NS, SCHEMA_NAME); + private static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/"; + + private static final String ANYTYPE_NAME = "anyType"; + private static final QName ANYTYPE_QNAME = new QName(SCHEMA_NS, ANYTYPE_NAME); + + + private WSDLFactory factory; + private DataBindingExtensionPoint dataBindings; + private WSDLDefinitionGenerator definitionGenerator; + private DocumentBuilderFactory documentBuilderFactory; + private boolean requiresSOAP12; + private ModelResolver resolver; + private XSDFactory xsdFactory; + private Monitor monitor; + + public Interface2WSDLGenerator(boolean requiresSOAP12, + ModelResolver resolver, + DataBindingExtensionPoint dataBindings, + XSDFactory xsdFactory, + DocumentBuilderFactory documentBuilderFactory, + Monitor monitor) throws WSDLException { + super(); + this.requiresSOAP12 = requiresSOAP12; + this.resolver = resolver; + this.documentBuilderFactory = documentBuilderFactory; + definitionGenerator = new WSDLDefinitionGenerator(requiresSOAP12); + this.dataBindings = dataBindings; + this.xsdFactory = xsdFactory; + this.monitor = monitor; + this.factory = WSDLFactory.newInstance(); + } + + /** + * Log a warning message. + * @param problem + */ + private static void logWarning(Problem problem) { + Logger problemLogger = Logger.getLogger(problem.getSourceClassName(), problem.getResourceBundleName()); + if (problemLogger != null){ + problemLogger.logp(Level.WARNING, problem.getSourceClassName(), null, problem.getMessageId(), problem.getMessageParams()); + } else { + logger.severe("Can't get logger " + problem.getSourceClassName()+ " with bundle " + problem.getResourceBundleName()); + } + } + + /** + * Report a warning. + * @param message + * @param binding + * @param parameters + */ + private void warning(String message, Interface interfaze, String... messageParameters) { + Problem problem = monitor.createProblem(this.getClass().getName(), "wsdlgen-validation-messages", Severity.WARNING, interfaze, message, (Object[])messageParameters); + if (monitor != null) { + monitor.problem(problem); + } else { + logWarning(problem); + } + } + + /** + * Report a fatal error. + * @param message + * @param binding + * @param parameters + */ + private void fatal(String message, Interface interfaze, String... messageParameters) { + Problem problem = monitor.createProblem(this.getClass().getName(), "wsdlgen-validation-messages", Severity.ERROR, interfaze, message, (Object[])messageParameters); + throw new WSDLGenerationException(problem.toString(), null, problem); + } + + private XMLTypeHelper getTypeHelper(DataType type, Map<String, XMLTypeHelper> helpers) { + if (type == null) { + return null; + } + String db = type.getDataBinding(); + if (db == null) { + return null; + } + if ("java:array".equals(db)) { + DataType dt = (DataType)type.getLogical(); + db = dt.getDataBinding(); + } + return helpers.get(db); + } + + private boolean inputTypesCompatible(DataType wrapperType, DataType<List<DataType>> inputType, Map<String, XMLTypeHelper> helpers) { + XMLTypeHelper wrapperHelper = getTypeHelper(wrapperType, helpers); + for (DataType dt : inputType.getLogical()) { + if (getTypeHelper(dt, helpers) != wrapperHelper) { + return false; + } + } + return true; + } + + private boolean outputTypeCompatible(DataType wrapperType, DataType outputType, Map<String, XMLTypeHelper> helpers) { + if (getTypeHelper(outputType, helpers) != getTypeHelper(wrapperType, helpers)) { + return false; + } else { + return true; + } + } + + private void addDataType(Map<XMLTypeHelper, List<DataType>> map, DataType type, Map<String, XMLTypeHelper> helpers) { + if (type == null) { + return; + } + String db = type.getDataBinding(); + if (db == null) { + return; + } + if ("java:array".equals(db)) { + DataType dt = (DataType)type.getLogical(); + db = dt.getDataBinding(); + } + XMLTypeHelper helper = helpers.get(db); + List<DataType> types = map.get(helper); + if (types == null) { + types = new ArrayList<DataType>(); + map.put(helper, types); + } + types.add(type); + } + + private Map<XMLTypeHelper, List<DataType>> getDataTypes(Interface intf, boolean useWrapper, Map<String, XMLTypeHelper> helpers) { + Map<XMLTypeHelper, List<DataType>> dataTypes = new HashMap<XMLTypeHelper, List<DataType>>(); + for (Operation op : intf.getOperations()) { + WrapperInfo wrapper = op.getWrapper(); + DataType dt1 = null; + boolean useInputWrapper = useWrapper & wrapper != null; + if (useInputWrapper) { + dt1 = wrapper.getInputWrapperType(); + useInputWrapper &= inputTypesCompatible(dt1, op.getInputType(), helpers); + } + if (useInputWrapper) { + addDataType(dataTypes, dt1, helpers); + } else { + for (DataType dt : op.getInputType().getLogical()) { + addDataType(dataTypes, dt, helpers); + } + } + + DataType dt2 = null; + boolean useOutputWrapper = useWrapper & wrapper != null; + if (useOutputWrapper) { + dt2 = wrapper.getOutputWrapperType(); + useOutputWrapper &= outputTypeCompatible(dt2, op.getOutputType(), helpers); + } + if (useOutputWrapper) { + addDataType(dataTypes, dt2, helpers); + } else { + if (op.getOutputType().getLogical().size() != 0) { + dt2 = op.getOutputType().getLogical().get(0); + } + addDataType(dataTypes, dt2, helpers); + } + + for (DataType<DataType> dt3 : op.getFaultTypes()) { + DataType dt4 = dt3.getLogical(); + addDataType(dataTypes, dt4, helpers); + } + } + // Adding classes referenced by @XmlSeeAlso in the java interface + if (intf instanceof JavaInterface) { + JavaInterface javaInterface = (JavaInterface)intf; + Class<?>[] seeAlso = getSeeAlso(javaInterface.getJavaClass()); + if (seeAlso != null) { + for (Class<?> cls : seeAlso) { + DataType dt = new DataTypeImpl<XMLType>(JAXBDataBinding.NAME, cls, XMLType.UNKNOWN); + addDataType(dataTypes, dt, helpers); + } + } + seeAlso = getSeeAlso(javaInterface.getCallbackClass()); + if (seeAlso != null) { + for (Class<?> cls : seeAlso) { + DataType dt = new DataTypeImpl<XMLType>(JAXBDataBinding.NAME, cls, XMLType.UNKNOWN); + addDataType(dataTypes, dt, helpers); + } + } + } + return dataTypes; + } + + private static Class<?>[] getSeeAlso(Class<?> interfaze) { + if (interfaze == null) { + return null; + } + XmlSeeAlso seeAlso = interfaze.getAnnotation(XmlSeeAlso.class); + if (seeAlso == null) { + return null; + } else { + return seeAlso.value(); + } + } + + + public Definition generate(Interface interfaze, WSDLDefinition wsdlDefinition) throws WSDLException { + if (interfaze == null) { + return null; + } + if (interfaze instanceof WSDLInterface) { + return ((WSDLInterface)interfaze).getWsdlDefinition().getDefinition(); + } + JavaInterface iface = (JavaInterface)interfaze; + if (!interfaze.isRemotable()) { + fatal("InterfaceNotRemotable", interfaze, iface.getName()); + } + QName name = getQName(iface); + Definition definition = factory.newDefinition(); + if (requiresSOAP12) { + definition.addNamespace("SOAP12", "http://schemas.xmlsoap.org/wsdl/soap12/"); + } else { + definition.addNamespace("SOAP", "http://schemas.xmlsoap.org/wsdl/soap/"); + } + definition.addNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl/"); + definition.addNamespace("xs", SCHEMA_NS); + + String namespaceURI = name.getNamespaceURI(); + definition.setTargetNamespace(namespaceURI); + definition.setQName(new QName(namespaceURI, name.getLocalPart() + "Service", name.getPrefix())); + definition.addNamespace(name.getPrefix(), namespaceURI); + + PortType portType = definition.createPortType(); + portType.setQName(name); + Binding binding = definitionGenerator.createBinding(definition, portType); + Map<String, XMLTypeHelper> helpers = new HashMap<String, XMLTypeHelper>(); + Map<QName, List<ElementInfo>> wrappers = new HashMap<QName, List<ElementInfo>>(); + for (Operation op : interfaze.getOperations()) { + javax.wsdl.Operation operation = generateOperation(definition, op, helpers, wrappers); + portType.addOperation(operation); + String action = ((JavaOperation)op).getAction(); + if ((action == null || "".equals(action)) && !op.isWrapperStyle() && op.getWrapper() == null) { + // Bare style + action = "urn:" + op.getName(); + } + BindingOperation bindingOp = definitionGenerator.createBindingOperation(definition, operation, action); + binding.addBindingOperation(bindingOp); + } + portType.setUndefined(false); + definition.addPortType(portType); + binding.setUndefined(false); + definition.addBinding(binding); + wsdlDefinition.setBinding(binding); + + // call each helper in turn to populate the wsdl.types element + XmlSchemaCollection schemaCollection = new XmlSchemaCollection(); + + for (Map.Entry<XMLTypeHelper, List<DataType>> en: getDataTypes(interfaze, false, helpers).entrySet()) { + XMLTypeHelper helper = en.getKey(); + if (helper == null) { + continue; + } + List<XSDefinition> xsDefinitions = helper.getSchemaDefinitions(xsdFactory, resolver, en.getValue()); + for (XSDefinition xsDef: xsDefinitions) { + addSchemaExtension(xsDef, schemaCollection, wsdlDefinition, definition); + } + } + + // remove global wrapper elements with schema definitions from generation list + for (QName wrapperName: new HashSet<QName>(wrappers.keySet())) { + if (wsdlDefinition.getXmlSchemaElement(wrapperName) != null) { + wrappers.remove(wrapperName); + } + } + + // generate schema elements for wrappers that aren't defined in the schemas + if (wrappers.size() > 0) { + int i = 0; + int index = 0; + Map<String, XSDefinition> wrapperXSDs = new HashMap<String, XSDefinition>(); + Map<Element, Map<String, String>> prefixMaps = new HashMap<Element, Map<String, String>>(); + for (Map.Entry<QName, List<ElementInfo>> entry: wrappers.entrySet()) { + String targetNS = entry.getKey().getNamespaceURI(); + Document schemaDoc = null; + Element schema = null; + XSDefinition xsDef = wrapperXSDs.get(targetNS); + if (xsDef != null) { + schemaDoc = xsDef.getDocument(); + schema = schemaDoc.getDocumentElement(); + } else { + schemaDoc = createDocument(); + schema = schemaDoc.createElementNS(SCHEMA_NS, "xs:schema"); + // The elementFormDefault should be set to unqualified, see TUSCANY-2388 + schema.setAttribute("elementFormDefault", "unqualified"); + schema.setAttribute("attributeFormDefault", "qualified"); + schema.setAttribute("targetNamespace", targetNS); + schema.setAttributeNS(XMLNS_NS, "xmlns:xs", SCHEMA_NS); + schemaDoc.appendChild(schema); + Schema schemaExt = createSchemaExt(definition); + schemaExt.setElement(schema); + prefixMaps.put(schema, new HashMap<String, String>()); + xsDef = xsdFactory.createXSDefinition(); + xsDef.setUnresolved(true); + xsDef.setNamespace(targetNS); + xsDef.setDocument(schemaDoc); + // TUSCANY-2465: Set the system id to avoid schema conflict + xsDef.setLocation(URI.create("xsd_" + index + ".xsd")); + index++; + wrapperXSDs.put(targetNS, xsDef); + } + Element wrapper = schemaDoc.createElementNS(SCHEMA_NS, "xs:element"); + schema.appendChild(wrapper); + wrapper.setAttribute("name", entry.getKey().getLocalPart()); + if (entry.getValue().size() == 1 && entry.getValue().get(0).getQName() == null) { + // special case for global fault element + QName typeName = entry.getValue().get(0).getType().getQName(); + String nsURI = typeName.getNamespaceURI(); + if ("".equals(nsURI)) { + wrapper.setAttribute("type", typeName.getLocalPart()); + addSchemaImport(schema, "", schemaDoc); + } else if (targetNS.equals(nsURI)) { + wrapper.setAttribute("type", typeName.getLocalPart()); + } else if (SCHEMA_NS.equals(nsURI)) { + wrapper.setAttribute("type", "xs:" + typeName.getLocalPart()); + } else { + Map<String, String> prefixMap = prefixMaps.get(schema); + String prefix = prefixMap.get(nsURI); + if (prefix == null) { + prefix = "ns" + i++; + prefixMap.put(nsURI, prefix); + schema.setAttributeNS(XMLNS_NS, "xmlns:" + prefix, nsURI); + addSchemaImport(schema, nsURI, schemaDoc); + } + wrapper.setAttribute("type", prefix + ":" + typeName.getLocalPart()); + } + } else { + // normal wrapper containing type definition inline + Element complexType = schemaDoc.createElementNS(SCHEMA_NS, "xs:complexType"); + wrapper.appendChild(complexType); + if (entry.getValue().size() > 0) { + Element sequence = schemaDoc.createElementNS(SCHEMA_NS, "xs:sequence"); + complexType.appendChild(sequence); + for (ElementInfo element: entry.getValue()) { + Element xsElement = schemaDoc.createElementNS(SCHEMA_NS, "xs:element"); + if (element.isMany()) { + xsElement.setAttribute("maxOccurs", "unbounded"); + } + xsElement.setAttribute("minOccurs", "0"); + xsElement.setAttribute("name", element.getQName().getLocalPart()); + if (element.isNillable()) { + xsElement.setAttribute("nillable", "true"); + } + QName typeName = element.getType().getQName(); + String nsURI = typeName.getNamespaceURI(); + if ("".equals(nsURI)) { + xsElement.setAttribute("type", typeName.getLocalPart()); + addSchemaImport(schema, "", schemaDoc); + } else if (SCHEMA_NS.equals(nsURI)) { + xsElement.setAttribute("type", "xs:" + typeName.getLocalPart()); + } else { + Map<String, String> prefixMap = prefixMaps.get(schema); + String prefix = prefixMap.get(nsURI); + if (prefix == null) { + if (targetNS.equals(nsURI)) { + prefix = "tns"; + } else { + prefix = "ns" + i++; + addSchemaImport(schema, nsURI, schemaDoc); + } + prefixMap.put(nsURI, prefix); + schema.setAttributeNS(XMLNS_NS, "xmlns:" + prefix, nsURI); + } + xsElement.setAttribute("type", prefix + ":" + typeName.getLocalPart()); + } + sequence.appendChild(xsElement); + } + } + } + } + + // resolve XSDefinitions containing generated wrappers + for (XSDefinition xsDef: wrapperXSDs.values()) { + loadXSD(schemaCollection, xsDef); + wsdlDefinition.getXmlSchemas().add(xsDef); + } + } + + return definition; + } + + private static void addSchemaImport(Element schema, String nsURI, Document schemaDoc) { + Element imp = schemaDoc.createElementNS(SCHEMA_NS, "xs:import"); + if (!"".equals(nsURI)) { + imp.setAttribute("namespace", nsURI); + } + // Scan all xs:import elements to match namespace + NodeList childNodes = schema.getElementsByTagNameNS(SCHEMA_NS, "import"); + for (int i = 0; i < childNodes.getLength(); i++) { + Node childNode = childNodes.item(i); + if (childNode instanceof Element) { + String ns = ((Element)childNode).getAttributeNS(SCHEMA_NS, "namespace"); + if (nsURI.equals(ns)) { + // The xs:import with the same namespace has been declared + return; + } + } + } + // Try to find the first node after the import elements + Node firstNodeAfterImport = null; + if (childNodes.getLength() > 0) { + firstNodeAfterImport = childNodes.item(childNodes.getLength() - 1).getNextSibling(); + } else { + firstNodeAfterImport = schema.getFirstChild(); + } + + if (firstNodeAfterImport == null) { + schema.appendChild(imp); + } else { + schema.insertBefore(imp, firstNodeAfterImport); + } + } + + private void addSchemaExtension(XSDefinition xsDef, + XmlSchemaCollection schemaCollection, + WSDLDefinition wsdlDefinition, + Definition definition) throws WSDLException { + if (xsDef.getAggregatedDefinitions() != null) { + for (XSDefinition xsd: xsDef.getAggregatedDefinitions()) { + addSchemaExtension(xsd, schemaCollection, wsdlDefinition, definition); + } + } else { + String nsURI = xsDef.getNamespace(); + Document document = xsDef.getDocument(); + if (document == null) { + try { + NamespaceMap prefixMap = new NamespaceMap(); + prefixMap.add("xs", SCHEMA_NS); + prefixMap.add("tns", nsURI); + XmlSchema schemaDef = xsDef.getSchema(); + schemaDef.setNamespaceContext(prefixMap); + Document[] docs = schemaDef.getAllSchemas(); + document = docs[docs.length-1]; + document.setDocumentURI(xsDef.getLocation().toString()); + xsDef.setDocument(document); + } catch (XmlSchemaException e) { + throw new RuntimeException(e); + } + } + loadXSD(schemaCollection, xsDef); + wsdlDefinition.getXmlSchemas().add(xsDef); + Element schema = document.getDocumentElement(); + Schema schemaExt = createSchemaExt(definition); + schemaExt.setDocumentBaseURI(document.getDocumentURI()); + schemaExt.setElement(schema); + } + } + + private static void loadXSD(XmlSchemaCollection schemaCollection, XSDefinition definition) { + if (definition.getSchema() != null) { + return; + } + if (definition.getDocument() != null) { + String uri = null; + if (definition.getLocation() != null) { + uri = definition.getLocation().toString(); + } + XmlSchema schema = schemaCollection.read(definition.getDocument(), uri, null); + if (definition.getSchemaCollection() == null) { + definition.setSchemaCollection(schemaCollection); + } + if (definition.getSchema() == null) { + definition.setSchema(schema); + } + } + } + + public Schema createSchemaExt(Definition definition) throws WSDLException { + Types types = definition.getTypes(); + if (types == null) { + types = definition.createTypes(); + definition.setTypes(types); + } + + Schema schemaExt = createSchema(definition); + types.addExtensibilityElement(schemaExt); + + return schemaExt; + } + + public Schema createSchema(Definition definition) throws WSDLException { + return (Schema)definition.getExtensionRegistry().createExtension(Types.class, SCHEMA_QNAME); + } + + public Document createDocument() { + Document document; + try { + if (documentBuilderFactory == null) { + documentBuilderFactory = DocumentBuilderFactory.newInstance(); + documentBuilderFactory.setNamespaceAware(true); + } + document = documentBuilderFactory.newDocumentBuilder().newDocument(); + } catch (ParserConfigurationException ex) { + throw new WSDLGenerationException(ex); + } + // document.setDocumentURI("http://"); + return document; + } + + protected QName getQName(Interface interfaze) { + JavaInterface iface = (JavaInterface)interfaze; + QName qname = iface.getQName(); + if (qname != null) { + return qname; + } else { + Class<?> javaClass = iface.getJavaClass(); + return new QName(JavaXMLMapper.getNamespace(javaClass), javaClass.getSimpleName(), "tns"); + } + } + + public javax.wsdl.Operation generateOperation(Definition definition, + Operation op, + Map<String, XMLTypeHelper> helpers, + Map<QName, List<ElementInfo>> wrappers) + throws WSDLException { + javax.wsdl.Operation operation = definition.createOperation(); + operation.setName(op.getName()); + operation.setUndefined(false); + + Input input = definition.createInput(); + Message inputMsg = definition.createMessage(); + String namespaceURI = definition.getQName().getNamespaceURI(); + QName inputMsgName = new QName(namespaceURI, op.getName()); + inputMsg.setQName(inputMsgName); + inputMsg.setUndefined(false); + definition.addMessage(inputMsg); + + List<ElementInfo> elements = null; + // FIXME: By default, java interface is mapped to doc-lit-wrapper style WSDL + if (op.getWrapper() != null) { + // Generate doc-lit-wrapper style + inputMsg.addPart(generateWrapperPart(definition, op, helpers, wrappers, true)); + } else { + // Bare style + int i = 0; + for (DataType d : op.getInputType().getLogical()) { + inputMsg.addPart(generatePart(definition, d, "arg" + i)); + elements = new ArrayList<ElementInfo>(); + ElementInfo element = getElementInfo(d.getPhysical(), d, null, helpers); + elements.add(element); + QName elementName = ((XMLType)d.getLogical()).getElementName(); + wrappers.put(elementName, elements); + i++; + } + } + input.setMessage(inputMsg); + operation.setInput(input); + + if (!op.isNonBlocking()) { + Output output = definition.createOutput(); + Message outputMsg = definition.createMessage(); + QName outputMsgName = new QName(namespaceURI, op.getName() + "Response"); + outputMsg.setQName(outputMsgName); + outputMsg.setUndefined(false); + definition.addMessage(outputMsg); + + if (op.getWrapper() != null) { + outputMsg.addPart(generateWrapperPart(definition, op, helpers, wrappers, false)); + } else { + + if ((op.getOutputType() != null) && ( op.getOutputType().getLogical().size() != 0)) { + DataType outputType = op.getOutputType().getLogical().get(0); + outputMsg.addPart(generatePart(definition, outputType, "return")); + elements = new ArrayList<ElementInfo>(); + ElementInfo element = getElementInfo(outputType.getPhysical(), outputType, null, helpers); + elements.add(element); + QName elementName = ((XMLType)outputType.getLogical()).getElementName(); + wrappers.put(elementName, elements); + } + } + output.setMessage(outputMsg); + + operation.setOutput(output); + operation.setStyle(OperationType.REQUEST_RESPONSE); + } else { + operation.setStyle(OperationType.ONE_WAY); + } + + for (DataType<DataType> faultType: op.getFaultTypes()) { + Fault fault = definition.createFault(); + // TUSCANY-3778 - use the definition namespace not the element namespace to create the fault message + QName faultName = ((XMLType)faultType.getLogical().getLogical()).getElementName(); + QName faultMsgName = new QName(namespaceURI, faultName.getLocalPart()); + fault.setName(faultName.getLocalPart()); + Message faultMsg = definition.getMessage(faultMsgName); + if (faultMsg == null) { + faultMsg = definition.createMessage(); + faultMsg.setQName(faultMsgName); + faultMsg.setUndefined(false); + definition.addMessage(faultMsg); + faultMsg.addPart(generatePart(definition, faultType.getLogical(), faultName.getLocalPart())); + } + fault.setMessage(faultMsg); + operation.addFault(fault); + if (faultType.getLogical().getPhysical() != faultType.getPhysical()) { + // create special wrapper for type indirection to real fault bean + DataType logical = faultType.getLogical(); + elements = new ArrayList<ElementInfo>(); + elements.add(getElementInfo(logical.getPhysical(), logical, null, helpers)); + } else { + // convert synthesized fault bean to a wrapper type + for (DataType<XMLType> propDT: op.getFaultBeans().get(faultName)) { + XMLType logical = propDT.getLogical(); + elements = new ArrayList<ElementInfo>(); + elements.add(getElementInfo(propDT.getPhysical(), propDT, logical.getElementName(), helpers)); + } + } + wrappers.put(faultName, elements); + } + + operation.setUndefined(false); + return operation; + } + + public Part generatePart(Definition definition, DataType arg, String partName) { + Part part = definition.createPart(); + part.setName(partName); + if (arg != null && arg.getLogical() instanceof XMLType) { + XMLType xmlType = (XMLType)arg.getLogical(); + QName elementName = xmlType.getElementName(); + part.setElementName(elementName); + addNamespace(definition, elementName); + if (xmlType.getElementName() == null) { + QName typeName = xmlType.getTypeName(); + part.setTypeName(typeName); + addNamespace(definition, typeName); + } + } + return part; + } + + public Part generateWrapperPart(Definition definition, + Operation operation, + Map<String, XMLTypeHelper> helpers, + Map<QName, List<ElementInfo>> wrappers, + boolean input) throws WSDLException { + Part part = definition.createPart(); + String partName = input ? operation.getName() : (operation.getName() + "Response"); + part.setName(partName); + WrapperInfo opWrapper = operation.getWrapper(); + if (opWrapper != null) { + ElementInfo elementInfo = + input ? opWrapper.getInputWrapperElement() : opWrapper.getOutputWrapperElement(); + List<ElementInfo> elements = + input ? opWrapper.getInputChildElements() : opWrapper.getOutputChildElements(); + QName wrapperName = elementInfo.getQName(); + part.setElementName(wrapperName); + addNamespace(definition, wrapperName); + wrappers.put(wrapperName, elements); + + // FIXME: [rfeng] Ideally, we should try to register the wrappers only. But we are + // expriencing the problem that we cannot handle XSD imports + /* + Class<?> wrapperClass = input ? opWrapper.getInputWrapperClass() : opWrapper.getOutputWrapperClass(); + DataType wrapperDT = input ? opWrapper.getInputWrapperType() : opWrapper.getOutputWrapperType(); + if (wrapperClass != null) { + getElementInfo(wrapperClass, wrapperDT, wrapperName, helpers); + return part; + } + */ + + Method method = ((JavaOperation)operation).getJavaMethod(); + + /* + * Making this change, though not understanding + * whether we can assume JAXWSJavaInterfaceProcessor was already used to process + */ + if (input) { + List<DataType> inputDTs = operation.getInputType().getLogical(); + for (int i = 0; i < inputDTs.size(); i++) { + DataType nextInput = inputDTs.get(i); + elements.set(i, getElementInfo(nextInput.getPhysical(), nextInput, elements.get(i).getQName(), helpers)); + } + + } else { + List<DataType> outputDTs = operation.getOutputType().getLogical(); + for (int i = 0; i < outputDTs.size(); i++) { + DataType nextOutput = outputDTs.get(i); + elements.set(i, getElementInfo(nextOutput.getPhysical(), nextOutput, elements.get(i).getQName(), helpers)); + } + } + } + return part; + } + + private ElementInfo getElementInfo(Class javaType, + DataType dataType, + QName name, + Map<String, XMLTypeHelper> helpers) { + String db = dataType.getDataBinding(); + while ("java:array".equals(db)) { + dataType = (DataType)dataType.getLogical(); + db = dataType.getDataBinding(); + } + XMLTypeHelper helper = helpers.get(db); + if (helper == null) { + DataBinding dataBinding = dataBindings.getDataBinding(db); + if (dataBinding == null) { + QName element = name; + if (element == null || dataType.getLogical() instanceof XMLType) { + XMLType xmlType = (XMLType)dataType.getLogical(); + if (xmlType.getElementName() != null) { + element = xmlType.getElementName(); + } + } + return new ElementInfo(element, new TypeInfo(ANYTYPE_QNAME, false, null)); + // throw new ServiceRuntimeException("No data binding for " + db); + } + + helper = dataBinding.getXMLTypeHelper(); + if (helper == null) { + // Default to JAXB + helper = helpers.get(JAXBDataBinding.NAME); + if (helper == null) { + helper = dataBindings.getDataBinding(JAXBDataBinding.NAME).getXMLTypeHelper(); + helpers.put(JAXBDataBinding.NAME, helper); + } + } + helpers.put(db, helper); + } + // TUSCANY-3616 - don't revert a byte[] to a byte type but retain the mapping to base64Binary + // which is carried in the dataType and the original javaType + TypeInfo typeInfo = null; + ElementInfo element = null; + if (byte[].class == javaType){ + typeInfo = helper.getTypeInfo(javaType, dataType.getLogical()); + element = new ElementInfo(name, typeInfo); + element.setMany(false); + } else { + typeInfo = helper.getTypeInfo(javaType.isArray() ? javaType.getComponentType() : javaType, dataType.getLogical()); + element = new ElementInfo(name, typeInfo); + element.setMany(javaType.isArray()); + } + + element.setNillable(!javaType.isPrimitive()); + return element; + } + + private static void addNamespace(Definition definition, QName name) { + String namespace = name.getNamespaceURI(); + if (definition.getPrefix(namespace) == null) { + definition.addNamespace("ns" + definition.getNamespaces().size(), namespace); + } + } + + /* + // currently not using the next three methods + public XmlSchemaType getXmlSchemaType(DataType type) { + return null; + } + + // FIXME: WE need to add databinding-specific Java2XSD generation + public Element generateXSD(DataType dataType) { + DataBinding dataBinding = dataBindings.getDataBinding(dataType.getDataBinding()); + if (dataBinding != null) { + // return dataBinding.generateSchema(dataType); + } + return null; + } + + public void generateWrapperElements(Operation op) { + XmlSchemaCollection collection = new XmlSchemaCollection(); + String ns = getQName(op.getInterface()).getNamespaceURI(); + XmlSchema schema = new XmlSchema(ns, collection); + schema.setAttributeFormDefault(new XmlSchemaForm(XmlSchemaForm.QUALIFIED)); + schema.setElementFormDefault(new XmlSchemaForm(XmlSchemaForm.QUALIFIED)); + + XmlSchemaElement inputElement = new XmlSchemaElement(); + inputElement.setQName(new QName(ns, op.getName())); + XmlSchemaComplexType inputType = new XmlSchemaComplexType(schema); + inputType.setName(""); + XmlSchemaSequence inputSeq = new XmlSchemaSequence(); + inputType.setParticle(inputSeq); + List<DataType> argTypes = op.getInputType().getLogical(); + for (DataType argType : argTypes) { + XmlSchemaElement child = new XmlSchemaElement(); + Object logical = argType.getLogical(); + if (logical instanceof XMLType) { + child.setName(((XMLType)logical).getElementName().getLocalPart()); + XmlSchemaType type = getXmlSchemaType(argType); + child.setType(type); + } + inputSeq.getItems().add(child); + } + inputElement.setType(inputType); + + XmlSchemaElement outputElement = new XmlSchemaElement(); + outputElement.setQName(new QName(ns, op.getName() + "Response")); + XmlSchemaComplexType outputType = new XmlSchemaComplexType(schema); + outputType.setName(""); + XmlSchemaSequence outputSeq = new XmlSchemaSequence(); + outputType.setParticle(outputSeq); + DataType returnType = op.getOutputType(); + XmlSchemaElement child = new XmlSchemaElement(); + Object logical = returnType.getLogical(); + if (logical instanceof XMLType) { + child.setName(((XMLType)logical).getElementName().getLocalPart()); + XmlSchemaType type = getXmlSchemaType(returnType); + child.setType(type); + } + outputSeq.getItems().add(child); + outputElement.setType(outputType); + + schema.getElements().add(inputElement.getQName(), inputElement); + schema.getElements().add(outputElement.getQName(), outputElement); + + } + */ + + public WSDLFactory getFactory() { + return factory; + } + + public void setFactory(WSDLFactory factory) { + this.factory = factory; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLContractBuilder.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLContractBuilder.java new file mode 100644 index 0000000000..291d42d71c --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLContractBuilder.java @@ -0,0 +1,90 @@ +/*
+ * 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.wsdlgen;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Contract;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.assembly.builder.BindingBuilder;
+import org.apache.tuscany.sca.assembly.builder.BuilderContext;
+import org.apache.tuscany.sca.assembly.builder.ContractBuilder;
+import org.apache.tuscany.sca.binding.ws.WebServiceBinding;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ResolverExtension;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+import org.apache.tuscany.sca.xsd.XSDFactory;
+
+/**
+ * Created WSDL contracts for Endpoints or EndpointReferences for use during
+ * interface contract mapping. The assmebly spec defines WSDL as the lowest
+ * common denominator for contract mapping.
+ */
+public class WSDLContractBuilder implements ContractBuilder {
+
+ private ExtensionPointRegistry extensionPoints;
+ private FactoryExtensionPoint modelFactories;
+ private DataBindingExtensionPoint dataBindings;
+ private WSDLFactory wsdlFactory;
+ private XSDFactory xsdFactory;
+ private DocumentBuilderFactory documentBuilderFactory;
+
+ public WSDLContractBuilder(ExtensionPointRegistry extensionPoints) {
+ this.extensionPoints = extensionPoints;
+
+ modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
+ dataBindings = extensionPoints.getExtensionPoint(DataBindingExtensionPoint.class);
+ wsdlFactory = modelFactories.getFactory(WSDLFactory.class);
+ xsdFactory = modelFactories.getFactory(XSDFactory.class);
+ documentBuilderFactory = modelFactories.getFactory(DocumentBuilderFactory.class);
+
+ }
+
+ public boolean build(InterfaceContract interfaceContract, BuilderContext context){
+// Uncomment the printWSDL = lines to see the WSDL that is generated
+// for interface matching purposes
+// BindingWSDLGenerator.printWSDL = true;
+ JavaInterfaceContract javaContract = (JavaInterfaceContract)interfaceContract;
+ WSDLInterfaceContract wsdlContract =
+ BindingWSDLGenerator.createWSDLInterfaceContract(javaContract,
+ false,
+ null,
+ dataBindings,
+ wsdlFactory,
+ xsdFactory,
+ documentBuilderFactory,
+ null);
+ javaContract.setNormalizedWSDLContract(wsdlContract);
+// BindingWSDLGenerator.printWSDL = false;
+ return true;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLDefinitionGenerator.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLDefinitionGenerator.java new file mode 100644 index 0000000000..5308b3c0e7 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLDefinitionGenerator.java @@ -0,0 +1,336 @@ +/* + * 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.wsdlgen; + +import java.util.Iterator; + +import javax.wsdl.Binding; +import javax.wsdl.BindingFault; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingOutput; +import javax.wsdl.Definition; +import javax.wsdl.Fault; +import javax.wsdl.Input; +import javax.wsdl.Operation; +import javax.wsdl.Output; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.Types; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPFault; +import javax.wsdl.extensions.soap.SOAPOperation; +import javax.wsdl.extensions.soap12.SOAP12Address; +import javax.wsdl.extensions.soap12.SOAP12Binding; +import javax.wsdl.extensions.soap12.SOAP12Body; +import javax.wsdl.extensions.soap12.SOAP12Fault; +import javax.wsdl.extensions.soap12.SOAP12Operation; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.w3c.dom.Element; + +/** + * + * @version $Rev$ $Date$ + */ +public class WSDLDefinitionGenerator { + private static final String SOAP_NS = "http://schemas.xmlsoap.org/wsdl/soap/"; + public static final QName SOAP_ADDRESS = new QName(SOAP_NS, "address"); + private static final QName SOAP_BINDING = new QName(SOAP_NS, "binding"); + private static final QName SOAP_BODY = new QName(SOAP_NS, "body"); + private static final QName SOAP_FAULT = new QName(SOAP_NS, "fault"); + private static final QName SOAP_OPERATION = new QName(SOAP_NS, "operation"); + private static final String SOAP12_NS = "http://schemas.xmlsoap.org/wsdl/soap12/"; + public static final QName SOAP12_ADDRESS = new QName(SOAP12_NS, "address"); + private static final QName SOAP12_BINDING = new QName(SOAP12_NS, "binding"); + private static final QName SOAP12_BODY = new QName(SOAP12_NS, "body"); + private static final QName SOAP12_FAULT = new QName(SOAP12_NS, "fault"); + private static final QName SOAP12_OPERATION = new QName(SOAP12_NS, "operation"); + + private static final String BINDING_SUFFIX = "Binding"; + private static final String SERVICE_SUFFIX = "Service"; + private static final String PORT_SUFFIX = "Port"; + + private boolean requiresSOAP12; + private QName soapAddress; + private QName soapBinding; + private QName soapBody; + private QName soapFault; + private QName soapOperation; + private String wsBindingName; + + public WSDLDefinitionGenerator(WebServiceBinding wsBinding) { + this(BindingWSDLGenerator.requiresSOAP12(wsBinding)); + wsBindingName = wsBinding.getName(); + } + + public WSDLDefinitionGenerator(boolean isSOAP12) { + super(); + this.requiresSOAP12 = isSOAP12; + soapAddress = requiresSOAP12 ? SOAP12_ADDRESS : SOAP_ADDRESS; + soapBinding = requiresSOAP12 ? SOAP12_BINDING : SOAP_BINDING; + soapBody = requiresSOAP12 ? SOAP12_BODY : SOAP_BODY; + soapFault = requiresSOAP12 ? SOAP12_FAULT : SOAP_FAULT; + soapOperation = requiresSOAP12 ? SOAP12_OPERATION : SOAP_OPERATION; + } + + public Definition cloneDefinition(WSDLFactory factory, Definition definition) throws WSDLException { + Element root = definition.getDocumentationElement(); + root = (Element)root.cloneNode(true); + WSDLReader reader = factory.newWSDLReader(); + return reader.readWSDL(definition.getDocumentBaseURI(), root); + } + + public Types createTypes(Definition definition) { + Types types = definition.createTypes(); + definition.setTypes(types); + return types; + } + + public Binding createBinding(Definition definition, PortType portType) { + try { + Binding binding = definition.createBinding(); + binding.setPortType(portType); + configureBinding(definition, binding, portType); + ExtensibilityElement bindingExtension = + definition.getExtensionRegistry().createExtension(Binding.class, soapBinding); + if (requiresSOAP12) { + ((SOAP12Binding)bindingExtension).setStyle("document"); + ((SOAP12Binding)bindingExtension).setTransportURI("http://schemas.xmlsoap.org/soap/http"); + } else { + ((SOAPBinding)bindingExtension).setStyle("document"); + ((SOAPBinding)bindingExtension).setTransportURI("http://schemas.xmlsoap.org/soap/http"); + } + binding.addExtensibilityElement(bindingExtension); + return binding; + } catch (WSDLException e) { + throw new WSDLGenerationException(e); + } + } + + protected void configureBinding(Definition definition, Binding binding, PortType portType) throws WSDLException { + if ( wsBindingName != null ) { + QName name = new QName(definition.getTargetNamespace(), wsBindingName + getSOAPVersionString() + BINDING_SUFFIX); + if ( definition.getBinding(name) == null ) { + binding.setQName(name); + return; + } + } + + QName portTypeName = portType.getQName(); + if (portTypeName != null) { + // Choose <porttype>Binding if available. If this name is in use, insert + // separating underscores until there is no clash. + for (String suffix = BINDING_SUFFIX; ; suffix = "_" + suffix) { + QName name = new QName(definition.getTargetNamespace(), portTypeName.getLocalPart() + suffix); + if (definition.getBinding(name) == null) { + binding.setQName(name); + break; + } + } + } + } + + @SuppressWarnings("unchecked") + public void createBindingOperations(Definition definition, Binding binding, PortType portType) { + try { + for (Iterator oi = portType.getOperations().iterator(); oi.hasNext();) { + Operation operation = (Operation)oi.next(); + BindingOperation bindingOperation = + createBindingOperation(definition, operation, "urn:" + operation.getName()); + binding.addBindingOperation(bindingOperation); + } + } catch (WSDLException e) { + throw new WSDLGenerationException(e); + } + } + + @SuppressWarnings("unchecked") + public BindingOperation createBindingOperation(Definition definition, Operation operation, String action) + throws WSDLException { + BindingOperation bindingOperation = definition.createBindingOperation(); + bindingOperation.setOperation(operation); + configureBindingOperation(bindingOperation, operation); + ExtensibilityElement operationExtension = + definition.getExtensionRegistry().createExtension(BindingOperation.class, soapOperation); + if (requiresSOAP12) { + ((SOAP12Operation)operationExtension).setSoapActionURI(action); + } else { + ((SOAPOperation)operationExtension).setSoapActionURI(action); + } + bindingOperation.addExtensibilityElement(operationExtension); + if (operation.getInput() != null) { + BindingInput bindingInput = definition.createBindingInput(); + configureBindingInput(bindingInput, operation.getInput()); + ExtensibilityElement inputExtension = + definition.getExtensionRegistry().createExtension(BindingInput.class, soapBody); + if (requiresSOAP12) { + ((SOAP12Body)inputExtension).setUse("literal"); + } else { + ((SOAPBody)inputExtension).setUse("literal"); + } + bindingInput.addExtensibilityElement(inputExtension); + bindingOperation.setBindingInput(bindingInput); + } + if (operation.getOutput() != null) { + BindingOutput bindingOutput = definition.createBindingOutput(); + configureBindingOutput(bindingOutput, operation.getOutput()); + ExtensibilityElement outputExtension = + definition.getExtensionRegistry().createExtension(BindingOutput.class, soapBody); + if (requiresSOAP12) { + ((SOAP12Body)outputExtension).setUse("literal"); + } else { + ((SOAPBody)outputExtension).setUse("literal"); + } + bindingOutput.addExtensibilityElement(outputExtension); + bindingOperation.setBindingOutput(bindingOutput); + } + for (Iterator fi = operation.getFaults().values().iterator(); fi.hasNext();) { + Fault fault = (Fault)fi.next(); + BindingFault bindingFault = definition.createBindingFault(); + ExtensibilityElement faultExtension = + definition.getExtensionRegistry().createExtension(BindingFault.class, soapFault); + configureBindingFault(bindingFault, faultExtension, fault); + bindingFault.addExtensibilityElement(faultExtension); + bindingOperation.addBindingFault(bindingFault); + } + return bindingOperation; + } + + protected void configureBindingOperation(BindingOperation bindingOperation, Operation operation) + throws WSDLException { + bindingOperation.setName(operation.getName()); + } + + protected void configureBindingInput(BindingInput bindingInput, Input input) throws WSDLException { + bindingInput.setName(input.getName()); + } + + protected void configureBindingOutput(BindingOutput bindingOutput, Output output) throws WSDLException { + bindingOutput.setName(output.getName()); + } + + protected void configureBindingFault(BindingFault bindingFault, + ExtensibilityElement faultExtension, + Fault fault) + throws WSDLException { + String faultName = fault.getName(); + bindingFault.setName(faultName); + if (requiresSOAP12) { + ((SOAP12Fault)faultExtension).setName(faultName); + ((SOAP12Fault)faultExtension).setUse("literal"); + } else { + ((SOAPFault)faultExtension).setName(faultName); + ((SOAPFault)faultExtension).setUse("literal"); + } + } + + public Service createService(Definition definition, PortType portType, String serviceName) { + try { + Service service = definition.createService(); + configureService(definition, service, portType, serviceName); + definition.addService(service); + return service; + } catch (WSDLException e) { + throw new WSDLGenerationException(e); + } + } + + public Service createService(Definition definition, Binding binding, String serviceName) { + try { + Service service = definition.createService(); + configureService(definition, service, binding.getPortType(), serviceName); + definition.addService(service); + return service; + } catch (WSDLException e) { + throw new WSDLGenerationException(e); + } + } + + protected void configureService(Definition definition, Service service, PortType portType, String serviceName) throws WSDLException { + if ( serviceName != null ) { + QName name = new QName(definition.getTargetNamespace(), serviceName); + if ( definition.getService(name) == null ) { + service.setQName(name); + return; + } + } + + QName portTypeName = portType.getQName(); + if (portTypeName != null) { + // Choose <porttype>Service if available. If this name is in use, insert + // separating underscores until there is no clash. + for (String suffix = SERVICE_SUFFIX; ; suffix = "_" + suffix) { + QName name = new QName(definition.getTargetNamespace(), portTypeName.getLocalPart() + suffix); + if (definition.getService(name) == null) { + service.setQName(name); + break; + } + } + } + } + + public Port createPort(Definition definition, Binding binding, Service service, String uri) { + try { + Port port = definition.createPort(); + port.setBinding(binding); + configurePort(port, binding); + if (uri != null) { + ExtensibilityElement portExtension = + definition.getExtensionRegistry().createExtension(Port.class, soapAddress); + if (requiresSOAP12) { + ((SOAP12Address)portExtension).setLocationURI(uri); + } else { + ((SOAPAddress)portExtension).setLocationURI(uri); + } + port.addExtensibilityElement(portExtension); + } + service.addPort(port); + return port; + } catch (WSDLException e) { + throw new WSDLGenerationException(e); + } + } + + protected void configurePort(Port port, Binding binding) throws WSDLException { + if ( wsBindingName != null ) { + port.setName(wsBindingName + getSOAPVersionString() + PORT_SUFFIX); + } else if (binding.getPortType() != null && binding.getPortType().getQName() != null) { + port.setName(binding.getPortType().getQName().getLocalPart() + PORT_SUFFIX); + } + } + + private String getSOAPVersionString() { + if ( requiresSOAP12 ) { + return "SOAP12"; + } else { + return "SOAP11"; + } + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLGenerationException.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLGenerationException.java new file mode 100644 index 0000000000..1a9b26d618 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLGenerationException.java @@ -0,0 +1,54 @@ +/* + * 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.wsdlgen; + +import org.apache.tuscany.sca.monitor.Problem; +import org.oasisopen.sca.ServiceRuntimeException; + +public class WSDLGenerationException extends ServiceRuntimeException { + private static final long serialVersionUID = 1L; + private Problem problem; + + public WSDLGenerationException() { + super(); + } + + public WSDLGenerationException(String message, Throwable cause) { + super(message, cause); + } + + public WSDLGenerationException(String message) { + super(message); + } + + public WSDLGenerationException(Throwable cause) { + super(cause); + } + + public WSDLGenerationException(String message, Throwable cause, Problem problem) { + super(message, cause); + this.problem = problem; + } + + public Problem getProblem() { + return problem; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLServiceGenerator.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLServiceGenerator.java new file mode 100644 index 0000000000..c6f1db4a3e --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLServiceGenerator.java @@ -0,0 +1,527 @@ +/* + * 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.wsdlgen; + +//FIXME: trim the import list down to what's really needed + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Import; +import javax.wsdl.Message; +import javax.wsdl.Part; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap12.SOAP12Address; +import javax.wsdl.extensions.soap12.SOAP12Binding; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLWriter; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.AbstractContract; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + +/** + * WSDLServiceGenerator generates a binding WSDL service document. + * + * @version $Rev$ $Date$ + */ +public class WSDLServiceGenerator { + // the following switch is temporary for debugging + public static boolean printWSDL; // external code sets this to print generated WSDL + + private static final Logger logger = Logger.getLogger(WSDLServiceGenerator.class.getName()); + private static final QName TRANSPORT_JMS_QUALIFIED_INTENT = + new QName("http://docs.oasis-open.org/ns/opencsa/sca/200912", "transport.jms"); + private static final String DEFAULT_QUEUE_CONNECTION_FACTORY = "TuscanyQueueConnectionFactory"; + private static final String ADDRESS = "Address"; + + private WSDLServiceGenerator() { + // this class has static methods only and cannot be instantiated + } + + /** + * Log a warning message. + * @param problem + */ + private static void logWarning(Problem problem) { + Logger problemLogger = Logger.getLogger(problem.getSourceClassName(), problem.getResourceBundleName()); + if (problemLogger != null){ + problemLogger.logp(Level.WARNING, problem.getSourceClassName(), null, problem.getMessageId(), problem.getMessageParams()); + } else { + logger.severe("Can't get logger " + problem.getSourceClassName()+ " with bundle " + problem.getResourceBundleName()); + } + } + + /** + * Report a warning. + * @param message + * @param binding + * @param parameters + */ + private static void warning(Monitor monitor, String message, WebServiceBinding wsBinding, String... messageParameters) { + Problem problem = monitor.createProblem(WSDLServiceGenerator.class.getName(), "wsdlgen-validation-messages", Severity.WARNING, wsBinding, message, (Object[])messageParameters); + if (monitor != null) { + monitor.problem(problem); + } else { + logWarning(problem); + } + } + + /** + * Report an error. + * @param message + * @param binding + * @param parameters + */ + private static void error(Monitor monitor, String message, WebServiceBinding wsBinding, String... messageParameters) { + Problem problem = monitor.createProblem(WSDLServiceGenerator.class.getName(), "wsdlgen-validation-messages", Severity.ERROR, wsBinding, message, (Object[])messageParameters); + if (monitor != null) { + monitor.problem(problem); + } else { + throw new WSDLGenerationException(problem.toString(), null, problem); + } + } + + /** + * Generate a suitably configured WSDL definition + */ + protected static Definition configureWSDLDefinition(WebServiceBinding wsBinding, + Component component, + AbstractContract contract, + Monitor monitor) { + + //[nash] changes to the builder sequence avoid calling this for a CompositeService + assert !(contract instanceof CompositeService); + + String contractName = contract.getName(); + + List<Port> ports = new ArrayList<Port>(); + WSDLDefinition wsdlDefinition = wsBinding.getUserSpecifiedWSDLDefinition(); + if (wsdlDefinition == null) { + error(monitor, "NoWsdlInterface", wsBinding, component.getName(), contract.getName()); + return null; + } + Definition def = wsdlDefinition.getDefinition(); + if (wsdlDefinition.getBinding() == null) { + // The WSDL document was provided by the user. Generate a new + // WSDL document with imports from the user-provided document. + WSDLFactory factory = null; + try { + factory = WSDLFactory.newInstance(); + } catch (WSDLException e) { + throw new WSDLGenerationException(e); + } + Definition newDef = factory.newDefinition(); + + // Construct a target namespace from the base URI of the user's + // WSDL document (is this what we should be using?) and a path + // computed according to the SCA Web Service binding spec. + String nsName = component.getName() + "/" + contractName; + String namespaceURI = null; + try { + URI userTNS = new URI(def.getTargetNamespace()); + namespaceURI = userTNS.resolve("/" + nsName).toString(); + } catch (URISyntaxException e1) { + throw new WSDLGenerationException(e1); + } catch (IllegalArgumentException e2) { + throw new WSDLGenerationException(e2); + } + + // set name and targetNamespace attributes on the definition + String defsName = component.getName() + "." + contractName; + newDef.setQName(new QName(namespaceURI, defsName)); + newDef.setTargetNamespace(namespaceURI); + newDef.addNamespace("tns", namespaceURI); + + // set wsdl namespace prefix on the definition + newDef.addNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl/"); + + // import the service or reference interface portType + List<WSDLDefinition> imports = new ArrayList<WSDLDefinition>(); + Interface interfaze = wsBinding.getBindingInterfaceContract().getInterface(); + if (interfaze instanceof WSDLInterface) { + PortType portType = ((WSDLInterface)interfaze).getPortType(); + boolean ok = importPortType(portType, wsdlDefinition, newDef, imports); + if (!ok) { + error(monitor, "PortTypeNotFound", wsBinding, portType.getQName().toString(), + component.getName(), contract.getName()); + } + } + + // import an existing binding if specified + Binding binding = wsBinding.getBinding(); + if (binding != null) { + boolean ok = importBinding(binding, wsdlDefinition, newDef, imports); + if (ok) { + boolean ok2 = importPortType(binding.getPortType(), wsdlDefinition, newDef, imports); + if (!ok2) { + error(monitor, "PortTypeNotFound", wsBinding, binding.getPortType().getQName().toString(), + component.getName(), contract.getName()); + } + } else { + error(monitor, "BindingNotFound", wsBinding, binding.getQName().toString(), + component.getName(), contract.getName()); + } + } + + // import bindings and portTypes needed by services and ports + QName serviceQName = wsBinding.getServiceName(); + String portName = wsBinding.getPortName(); + if (serviceQName != null) { + Service service = def.getService(serviceQName); + if (portName != null) { + Port port = service.getPort(portName); + Port newPort = copyPort(newDef, port, wsBinding); + if (newPort != null) { + importBinding(port.getBinding(), wsdlDefinition, newDef, imports); + ports.add(newPort); + } else { + error(monitor, "InvalidPort", wsBinding, serviceQName.toString(), portName, + component.getName(), contract.getName()); + } + } else { + for (Object port : service.getPorts().values()) { + Port newPort = copyPort(newDef, (Port)port, wsBinding); + if (newPort != null) { + importBinding(((Port)port).getBinding(), wsdlDefinition, newDef, imports); + ports.add(newPort); + } else { + // not an error, just ignore the port + warning(monitor, "IgnoringPort", wsBinding, serviceQName.toString(), ((Port)port).getName(), + component.getName(), contract.getName()); + } + } + if (ports.size() == 0) { + error(monitor, "NoValidPorts", wsBinding, serviceQName.toString(), + component.getName(), contract.getName()); + } + } + } + + // replace original WSDL definition by the generated definition + def = newDef; + + } else { + // The WSDL definition was generated by Interface2WSDLGenerator. + // Reuse it instead of creating a new definition here. + } + + // add a service and ports to the generated definition + WSDLDefinitionGenerator helper = + new WSDLDefinitionGenerator(wsBinding); + WSDLInterface wi = (WSDLInterface)wsBinding.getBindingInterfaceContract().getInterface(); + PortType portType = wi.getPortType(); + Service service = helper.createService(def, portType, contract.getName()); + if (wsBinding.getBinding() == null && ports.size() == 0) { + Binding binding = helper.createBinding(def, portType); + if (BindingWSDLGenerator.requiresSOAP12(wsBinding)) { + def.addNamespace("SOAP12", "http://schemas.xmlsoap.org/wsdl/soap12/"); + } else { + def.addNamespace("SOAP11", "http://schemas.xmlsoap.org/wsdl/soap/"); + } + helper.createBindingOperations(def, binding, portType); + binding.setUndefined(false); + + // set binding style based on the interface specified by the + // user if one is available + // TODO - set encoding style also currently default to literal + if (wsdlDefinition != null && wsdlDefinition.getDefinition() != null){ + Message firstMessage = (Message)wsdlDefinition.getDefinition().getMessages().values().iterator().next(); + Part firstPart = (Part)firstMessage.getParts().values().iterator().next(); + if (firstPart.getTypeName() != null){ + for (Object ext : binding.getExtensibilityElements()){ + if (ext instanceof SOAPBinding){ + ((SOAPBinding)ext).setStyle("rpc"); + break; + } + } + } + } + + def.addBinding(binding); + + String endpointURI = computeActualURI(wsBinding, null); + Port port = helper.createPort(def, binding, service, endpointURI); + wsBinding.setService(service); + wsBinding.setPort(port); + } else { + if (ports.size() > 0) { + // there are one or more user-specified valid ports + for (Port port : ports) { + service.addPort(port); + } + if (ports.size() == 1) { + // only one port, so use it + wsBinding.setPort(ports.get(0)); + } else { + // multiple ports, make them all available + wsBinding.setPort(null); + } + } else { + // no valid user-specified ports, so create a suitably configured port + String endpointURI = computeActualURI(wsBinding, null); + Port port = helper.createPort(def, wsBinding.getBinding(), service, endpointURI); + if (BindingWSDLGenerator.requiresSOAP12(wsBinding)) { + def.addNamespace("SOAP12", "http://schemas.xmlsoap.org/wsdl/soap12/"); + } else { + def.addNamespace("SOAP11", "http://schemas.xmlsoap.org/wsdl/soap/"); + } + wsBinding.setPort(port); + } + wsBinding.setService(service); + } + + // for debugging + if (printWSDL) { + try { + System.out.println("Generated WSDL for " + component.getName() + "/" + contractName); + WSDLWriter writer = javax.wsdl.factory.WSDLFactory.newInstance().newWSDLWriter(); + writer.writeWSDL(def, System.out); + } catch (WSDLException e) { + throw new WSDLGenerationException(e); + } + } + + return def; + } + + private static boolean importPortType(PortType portType, + WSDLDefinition wsdlDef, + Definition newDef, + List<WSDLDefinition> imports) { + return addImport(portType.getQName(), PortType.class, wsdlDef, newDef, imports); + } + + private static boolean importBinding(Binding binding, + WSDLDefinition wsdlDef, + Definition newDef, + List<WSDLDefinition> imports) { + boolean ok = addImport(binding.getQName(), Binding.class, wsdlDef, newDef, imports); + if (ok) { + List bindingExtensions = binding.getExtensibilityElements(); + for (final Object extension : bindingExtensions) { + if (extension instanceof SOAPBinding) { + newDef.addNamespace("SOAP11", "http://schemas.xmlsoap.org/wsdl/soap/"); + } + if (extension instanceof SOAP12Binding) { + newDef.addNamespace("SOAP12", "http://schemas.xmlsoap.org/wsdl/soap12/"); + } + } + } + return ok; + } + + private static boolean addImport(QName name, + Class type, + WSDLDefinition wsdlDef, + Definition newDef, + List<WSDLDefinition> imports) { + String namespace = name.getNamespaceURI(); + if (newDef.getImports(namespace) == null) { + WSDLDefinition impDef = findDefinition(wsdlDef, name, type); + if (impDef != null) { + Import imp = newDef.createImport(); + imp.setNamespaceURI(namespace); + imp.setLocationURI(impDef.getURI().toString()); + imp.setDefinition(impDef.getDefinition()); + newDef.addNamespace("ns" + imports.size(), namespace); + newDef.addImport(imp); + imports.add(impDef); + return true; + } else { + // import was not added because element not found + return false; + } + } + return true; + } + + private static WSDLDefinition findDefinition(WSDLDefinition wsdlDef, QName name, Class type) { + if (wsdlDef == null || name == null) { + return wsdlDef; + } + if (wsdlDef.getURI() != null) { // not a facade + Definition def = wsdlDef.getDefinition(); + Map types = type == PortType.class ? def.getPortTypes() : def.getBindings(); + if (types.get(name) != null) { + return wsdlDef; + } + } + for (WSDLDefinition impDef : wsdlDef.getImportedDefinitions()) { + WSDLDefinition d = findDefinition(impDef, name, type); + if (d != null) { + return d; + } + } + return null; + } + + private static Port copyPort(Definition def, Port port, WebServiceBinding wsBinding) { + Port newPort = def.createPort(); + newPort.setName(port.getName()); + newPort.setBinding(port.getBinding()); + List portExtensions = port.getExtensibilityElements(); + for (final Object extension : portExtensions) { + ExtensibilityElement newExt = null; + if (extension instanceof SOAPAddress) { + def.addNamespace("SOAP11", "http://schemas.xmlsoap.org/wsdl/soap/"); + try { + newExt = def.getExtensionRegistry().createExtension( + Port.class, WSDLDefinitionGenerator.SOAP_ADDRESS); + } catch (WSDLException e) { + } + String uri = computeActualURI(wsBinding, port); + ((SOAPAddress)newExt).setLocationURI(uri); + newPort.addExtensibilityElement(newExt); + } else if (extension instanceof SOAP12Address) { + def.addNamespace("SOAP12", "http://schemas.xmlsoap.org/wsdl/soap12/"); + try { + newExt = def.getExtensionRegistry().createExtension( + Port.class, WSDLDefinitionGenerator.SOAP12_ADDRESS); + } catch (WSDLException e) { + } + String uri = computeActualURI(wsBinding, port); + ((SOAP12Address)newExt).setLocationURI(uri); + newPort.addExtensibilityElement(newExt); + } else { + // we don't support ports with other extensibility elements such as HTTPAddress + return null; + } + } + return newPort; + } + + /** + * Compute the endpoint URI based on section 2.1.1 of the WS binding Specification + * 1. The URIs in the endpoint(s) of the referenced WSDL, which may be relative + * 2. The URI specified by the wsa:Address element of the + * wsa:EndpointReference, which may be relative + * 3. The explicitly stated URI in the "uri" attribute of the binding.ws element, + * which may be relative, + * 4. The implicit URI as defined by in section 1.7 in the SCA Assembly Specification + * If the <binding.ws> has no wsdlElement but does have a uri attribute then + * the uri takes precedence over any implicitly used WSDL. + * + */ + private static String computeActualURI(WebServiceBinding wsBinding, Port port) { + + URI eprURI = null; + if (wsBinding.getEndPointReference() != null) { + eprURI = getEPR(wsBinding); + } + + URI wsdlURI = null; + if (wsBinding.getServiceName() != null && wsBinding.getBindingName() == null) { + // <binding.ws> explicitly points at a WSDL port, may be a relative URI + wsdlURI = getEndpoint(port); + } + + // if the WSDL port/endpoint has an absolute URI use that + if (wsdlURI != null && wsdlURI.isAbsolute()) { + return wsdlURI.toString(); + } + + // if the wsa:EndpointReference has an address element with an absolute URI use that + if (eprURI != null && eprURI.isAbsolute()) { + return eprURI.toString(); + } + + // either there is no WSDL port endpoint URI or that URI is relative + String actualURI = wsBinding.getURI(); + if (eprURI != null && eprURI.toString().length() != 0) { + // there is a relative URI in the binding EPR + actualURI = actualURI + "/" + eprURI; + } + + if (wsdlURI != null && wsdlURI.toString().length() != 0) { + // there is a relative URI in the WSDL port + actualURI = actualURI + "/" + wsdlURI; + } + + if (actualURI != null) { + actualURI = URI.create(actualURI).normalize().toString(); + } + + return actualURI; + } + + private static URI getEPR(WebServiceBinding wsBinding) { + NodeList nodeList = wsBinding.getEndPointReference().getChildNodes(); + for (int i = 0; i < nodeList.getLength(); i++) { + Node childNode = nodeList.item(i); + if (childNode instanceof Element && ADDRESS.equals(childNode.getLocalName())) { + NodeList addrNodes = childNode.getChildNodes(); + for (int j = 0; j < addrNodes.getLength(); j++) { + Node addrNode = addrNodes.item(j); + if (addrNode instanceof Text) { + return URI.create(((Text)addrNode).getWholeText()); + } + } + } + } + return null; + } + + /** + * Returns the endpoint of a given port. + */ + private static URI getEndpoint(Port wsdlPort) { + if (wsdlPort != null) { + List<?> wsdlPortExtensions = wsdlPort.getExtensibilityElements(); + for (Object extension : wsdlPortExtensions) { + if (extension instanceof SOAPAddress) { + String uri = ((SOAPAddress)extension).getLocationURI(); + return (uri == null || "".equals(uri)) ? null : URI.create(uri); + } + if (extension instanceof SOAP12Address) { + SOAP12Address address = (SOAP12Address)extension; + String uri = address.getLocationURI(); + return (uri == null || "".equals(uri)) ? null : URI.create(uri); + } + } + } + return null; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WebServiceBindingBuilder.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WebServiceBindingBuilder.java new file mode 100644 index 0000000000..0117ee5d79 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WebServiceBindingBuilder.java @@ -0,0 +1,60 @@ +/* + * 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.wsdlgen; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.assembly.builder.BindingBuilder; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; + +/** + * A factory for the calculated WSDL document needed by Web Service bindings. + * + * @version $Rev$ $Date$ + */ +public class WebServiceBindingBuilder implements BindingBuilder<WebServiceBinding> { + + private ExtensionPointRegistry extensionPoints; + + public WebServiceBindingBuilder(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; + } + + /** + * Create a calculated WSDL document and save it in the Web Service binding. + */ + public void build(Component component, Contract contract, WebServiceBinding binding, BuilderContext context, boolean rebuild) { + // in some cases (callback service endpoint processing) we need to re-generate the + // WSDL doc from a ws binding that already has one. + if (rebuild == true){ + binding.setGeneratedWSDLDocument(null); + } + BindingWSDLGenerator.generateWSDL(component, contract, binding, extensionPoints, context.getMonitor()); + } + + public QName getBindingType() { + return WebServiceBinding.TYPE; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.BindingBuilder b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.BindingBuilder new file mode 100644 index 0000000000..e39d9352b3 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.BindingBuilder @@ -0,0 +1,18 @@ +# 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.
+org.apache.tuscany.sca.binding.ws.wsdlgen.WebServiceBindingBuilder;qname=http://docs.oasis-open.org/ns/opencsa/sca/200912#binding.ws
+
diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.ContractBuilder b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.ContractBuilder new file mode 100644 index 0000000000..01333bf670 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.ContractBuilder @@ -0,0 +1,18 @@ +# 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.
+org.apache.tuscany.sca.binding.ws.wsdlgen.WSDLContractBuilder
+
diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/resources/wsdlgen-validation-messages.properties b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/resources/wsdlgen-validation-messages.properties new file mode 100644 index 0000000000..42fffcc44f --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/main/resources/wsdlgen-validation-messages.properties @@ -0,0 +1,32 @@ +# +# +# 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. +# +# +WsdlGenProblem = Unable to generate WSDL for {0}/{1} +WsdlGenException = Exception while generating WSDL for {0}/{1} +WsdlGenException2 =[JCA90040] Exception while generating WSDL for {0}/{1} exception was: {2} +UnexpectedException = Exception thrown was: {0} +MissingInterfaceContract = No interface contract for {0}/{1} +InterfaceNotRemotable = Interface not remotable: {0} +IgnoringPort = Port {0}/{1} in {2}/{3} is not supported and was ignored +PortTypeNotFound = PortType {0} in {1}/{2} was not found +BindingNotFound = Binding {0} in {1}/{2} was not found +InvalidPort = Port {0}/{1} in {2}/{3} is not supported +NoValidPorts = No valid ports for service {0} in {1}/{2} +NoWsdlInterface = No WSDL interface definition for {0}/{1} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/other/Other.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/other/Other.java new file mode 100644 index 0000000000..7e6a1de546 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/other/Other.java @@ -0,0 +1,34 @@ +/* + * 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.other; + +/** + * + * @version $Rev$ $Date$ + */ +public class Other { + private String name; + + public String getName() { + return name; + } + public void setName(String name ) { + this.name = name; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/other/package-info.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/other/package-info.java new file mode 100644 index 0000000000..f10a2286e6 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/other/package-info.java @@ -0,0 +1,21 @@ +/* + * 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. + */ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://other.ws.binding.sca.tuscany.apache.org/") +package org.apache.tuscany.sca.binding.ws.other; + diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGeneratorTestCase.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGeneratorTestCase.java new file mode 100644 index 0000000000..f905c10bf7 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGeneratorTestCase.java @@ -0,0 +1,86 @@ +/* + * 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.wsdlgen; + +import javax.xml.parsers.DocumentBuilderFactory; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.DefaultFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.databinding.processor.DataBindingJavaInterfaceProcessor; +import org.apache.tuscany.sca.databinding.DefaultDataBindingExtensionPoint; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSFaultExceptionMapper; +import org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSJavaInterfaceProcessor; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract; +import org.apache.tuscany.sca.xsd.XSDFactory; +import org.apache.tuscany.sca.xsd.xml.XSDModelResolver; +import org.oasisopen.sca.annotation.Remotable; + +/** + * + * @version $Rev$ $Date$ + */ +public class BindingWSDLGeneratorTestCase extends TestCase { + + public void testCreateWSDLInterfaceContract() throws InvalidInterfaceException { + ExtensionPointRegistry registry = new DefaultExtensionPointRegistry(); + org.apache.tuscany.sca.core.FactoryExtensionPoint modelFactories = new DefaultFactoryExtensionPoint(registry); + WSDLFactory wsdlFactory = modelFactories.getFactory(WSDLFactory.class); + XSDFactory xsdFactory = modelFactories.getFactory(XSDFactory.class); + DocumentBuilderFactory documentBuilderFactory = modelFactories.getFactory(DocumentBuilderFactory.class); + JavaInterfaceFactory factory = new DefaultJavaInterfaceFactory(registry); + JavaInterfaceContract javaIC = factory.createJavaInterfaceContract(); + JavaInterface iface = factory.createJavaInterface(HelloWorld.class); + DefaultDataBindingExtensionPoint dataBindings = new DefaultDataBindingExtensionPoint(registry); + JAXWSFaultExceptionMapper faultExceptionMapper = new JAXWSFaultExceptionMapper(dataBindings, null); + new JAXWSJavaInterfaceProcessor(registry).visitInterface(iface); + new DataBindingJavaInterfaceProcessor(registry).visitInterface(iface); + javaIC.setInterface(iface); + WSDLInterfaceContract wsdlIC = BindingWSDLGenerator.createWSDLInterfaceContract(javaIC, false, new XSDModelResolver(null, null), dataBindings, wsdlFactory, xsdFactory, documentBuilderFactory, null); + assertNotNull(wsdlIC); + WSDLInterface wsdlInterface = (WSDLInterface)wsdlIC.getInterface(); + assertNotNull(wsdlInterface); + assertEquals(1, wsdlInterface.getOperations().size()); + assertEquals("sayHello", wsdlInterface.getOperations().get(0).getName()); + assertNotNull(wsdlInterface.getPortType()); + + JavaInterfaceContract javaIC2 = factory.createJavaInterfaceContract(); + JavaInterface iface2 = factory.createJavaInterface(TestJavaInterface.class); + new JAXWSJavaInterfaceProcessor(registry).visitInterface(iface2); + new DataBindingJavaInterfaceProcessor(registry).visitInterface(iface2); + javaIC2.setInterface(iface2); + WSDLInterfaceContract wsdlIC2 = BindingWSDLGenerator.createWSDLInterfaceContract(javaIC2, false, new XSDModelResolver(null, null), dataBindings, wsdlFactory, xsdFactory, documentBuilderFactory, null); + assertNotNull(wsdlIC2); + } + +} + +@Remotable +interface HelloWorld { + String sayHello(String s); +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGeneratorTestCase.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGeneratorTestCase.java new file mode 100644 index 0000000000..c80a929a90 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGeneratorTestCase.java @@ -0,0 +1,75 @@ +/* + * 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.wsdlgen; + +import java.io.StringWriter; + +import javax.wsdl.Definition; +import javax.wsdl.xml.WSDLWriter; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.DefaultFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.databinding.processor.DataBindingJavaInterfaceProcessor; +import org.apache.tuscany.sca.databinding.DefaultDataBindingExtensionPoint; +import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSFaultExceptionMapper; +import org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSJavaInterfaceProcessor; +import org.apache.tuscany.sca.interfacedef.wsdl.DefaultWSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.xsd.DefaultXSDFactory; +import org.apache.tuscany.sca.xsd.XSDFactory; +import org.apache.tuscany.sca.xsd.xml.XSDModelResolver; +import org.junit.Test; + +/** + * @version $Rev$ $Date$ + */ +public class Interface2WSDLGeneratorTestCase { + + @Test + public void testGenerate() throws Exception { + ExtensionPointRegistry registry = new DefaultExtensionPointRegistry(); + JavaInterfaceFactory iFactory = new DefaultJavaInterfaceFactory(registry); + JavaInterface iface = iFactory.createJavaInterface(TestJavaInterface.class); + DefaultDataBindingExtensionPoint dataBindings = new DefaultDataBindingExtensionPoint(new DefaultExtensionPointRegistry()); + JAXWSFaultExceptionMapper faultExceptionMapper = new JAXWSFaultExceptionMapper(dataBindings, null); + new JAXWSJavaInterfaceProcessor(registry).visitInterface(iface); + new DataBindingJavaInterfaceProcessor(registry).visitInterface(iface); + DefaultFactoryExtensionPoint modelFactories = new DefaultFactoryExtensionPoint(registry); + WSDLFactory wFactory = new DefaultWSDLFactory(registry); + DocumentBuilderFactory documentBuilderFactory = modelFactories.getFactory(DocumentBuilderFactory.class); + WSDLDefinition wsdlDefinition = wFactory.createWSDLDefinition(); + XSDFactory factory = new DefaultXSDFactory(); + Interface2WSDLGenerator generator = new Interface2WSDLGenerator(false, new XSDModelResolver(null, null), dataBindings, factory, documentBuilderFactory, null); + Definition definition = generator.generate(iface, wsdlDefinition); + + // print the generated WSDL file and inline schemas + WSDLWriter writer = generator.getFactory().newWSDLWriter(); + StringWriter sw = new StringWriter(); + writer.writeWSDL(definition, sw); + System.out.println(sw.toString()); + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestException.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestException.java new file mode 100644 index 0000000000..1e4f802e01 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestException.java @@ -0,0 +1,47 @@ +/* + * 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.wsdlgen; + +/** + * + * @version $Rev$ $Date$ + */ +public class TestException extends Exception { + + private String userdata; + + public TestException(String message) { + super(message); + } + + public TestException(String message, String userdata) { + super(message); + this.userdata = userdata; + } + + public String getUserdata() { + return userdata; + } + + public void setUserdata(String userdata) { + this.userdata = userdata; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestFault.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestFault.java new file mode 100644 index 0000000000..da2c285bac --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestFault.java @@ -0,0 +1,46 @@ +/* + * 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.wsdlgen; + +import javax.xml.ws.WebFault; + +/** + * + * @version $Rev$ $Date$ + */ +@WebFault(faultBean="org.apache.tuscany.sca.binding.ws.wsdlgen.TestFaultBean") +public class TestFault extends Exception { + + private TestFaultBean bean; + + public TestFault(TestFaultBean bean, String message) { + super(message); + this.bean = bean; + } + + public TestFault(TestFaultBean bean, String message, Throwable cause) { + super(message, cause); + this.bean = bean; + } + + public TestFaultBean getFaultInfo() { + return bean; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestFaultBean.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestFaultBean.java new file mode 100644 index 0000000000..64cce0e49d --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestFaultBean.java @@ -0,0 +1,54 @@ +/* + * 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.wsdlgen; + +/** + * + * @version $Rev$ $Date$ + */ +public class TestFaultBean { + private String lastName; + private String firstName; + private float age; + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public float getAge() { + return age; + } + + public void setAge(float age) { + this.age = age; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestJavaClass.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestJavaClass.java new file mode 100644 index 0000000000..3fd7361ae1 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestJavaClass.java @@ -0,0 +1,32 @@ +/* + * 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.wsdlgen; +import org.apache.tuscany.sca.binding.ws.other.Other; + +/** + * + * @version $Rev$ $Date$ + */ +public class TestJavaClass { + public Other other; + public String name; + public int number; + public float balance; +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestJavaInterface.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestJavaInterface.java new file mode 100644 index 0000000000..d60234fe7d --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestJavaInterface.java @@ -0,0 +1,72 @@ +/* + * 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.wsdlgen; + +import javax.jws.WebMethod; +import javax.jws.WebService; +import javax.jws.soap.SOAPBinding; +import javax.jws.soap.SOAPBinding.ParameterStyle; +import org.apache.tuscany.sca.binding.ws.other.Other; + +import org.oasisopen.sca.annotation.OneWay; +import org.oasisopen.sca.annotation.Remotable; + +/** + * + * @version $Rev$ $Date$ + */ +@Remotable +@WebService +public interface TestJavaInterface { + String m1(String str); + + @OneWay + @WebMethod + void m2(int i); + + @WebMethod + String m3(); + + void m4(); + + @WebMethod + String m5(String str, int i); + + @WebMethod(exclude = true) + void dummy(); + + @WebMethod + void m6(TestJavaClass info) throws TestException; + + @WebMethod + void m7(TestJavaClass info) throws TestFault; + + @WebMethod + @SOAPBinding(parameterStyle=ParameterStyle.BARE) + void m8(String str); + + @WebMethod + @SOAPBinding(parameterStyle=ParameterStyle.BARE) + int m9(String str); + + @WebMethod + @SOAPBinding(parameterStyle=ParameterStyle.BARE) + Other m10(Other other); +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/LICENSE b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/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/branches/2.0-Beta3/modules/binding-ws/META-INF/MANIFEST.MF b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..7d1ba0d044 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/META-INF/MANIFEST.MF @@ -0,0 +1,47 @@ +Manifest-Version: 1.0
+Export-Package: org.apache.tuscany.sca.binding.ws;version="2.0.0";
+ uses:="org.apache.tuscany.sca.assembly,
+ org.apache.tuscany.sca.interfacedef.wsdl,
+ org.apache.tuscany.sca.assembly.builder,
+ org.apache.tuscany.sca.interfacedef,
+ org.w3c.dom,
+ javax.wsdl,
+ javax.xml.namespace",
+ org.apache.tuscany.sca.binding.ws.addressing;version="2.0.0";uses:="javax.xml.namespace",
+ org.apache.tuscany.sca.binding.ws.xml
+Private-Package: org.apache.tuscany.sca.binding.ws.impl;version="2.0.0"
+SCA-Version: 1.1
+Bundle-Name: Apache Tuscany SCA WS Binding Model
+Bundle-Vendor: The Apache Software Foundation
+Bundle-Version: 2.0.0
+Bundle-ManifestVersion: 2
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Bundle-Description: Apache Tuscany SCA WS Binding Model
+Import-Package: javax.jws.soap,
+ javax.wsdl,
+ javax.wsdl.extensions;version="1.6.2",
+ javax.wsdl.extensions.soap;version="1.6.2",
+ javax.wsdl.extensions.soap12;version="1.6.2",
+ javax.xml.namespace,
+ javax.xml.parsers,
+ javax.xml.stream,
+ javax.xml.transform,
+ javax.xml.transform.dom,
+ org.apache.tuscany.sca.assembly;version="2.0.0",
+ org.apache.tuscany.sca.assembly.builder;version="2.0.0",
+ org.apache.tuscany.sca.assembly.xml;version="2.0.0",
+ org.apache.tuscany.sca.binding.ws;version="2.0.0",
+ org.apache.tuscany.sca.binding.ws.addressing;version="2.0.0",
+ org.apache.tuscany.sca.common.xml.stax;version="2.0.0",
+ org.apache.tuscany.sca.contribution.processor;version="2.0.0",
+ org.apache.tuscany.sca.contribution.resolver;version="2.0.0",
+ org.apache.tuscany.sca.core;version="2.0.0";resolution:=optional,
+ org.apache.tuscany.sca.interfacedef;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.wsdl;version="2.0.0",
+ org.apache.tuscany.sca.monitor;version="2.0.0",
+ org.apache.tuscany.sca.policy;version="2.0.0",
+ org.apache.tuscany.sca.xsd;version="2.0.0",
+ org.w3c.dom
+Bundle-SymbolicName: org.apache.tuscany.sca.binding.ws
+Bundle-DocURL: http://www.apache.org/
+Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6 diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/NOTICE b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/NOTICE new file mode 100644 index 0000000000..d69e595698 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2011 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/branches/2.0-Beta3/modules/binding-ws/pom.xml b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/pom.xml new file mode 100644 index 0000000000..e6115b909f --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/pom.xml @@ -0,0 +1,59 @@ +<?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-Beta3-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>tuscany-binding-ws</artifactId> + <name>Apache Tuscany SCA WS Binding Model</name> + + <dependencies> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-contribution</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-assembly-xml</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-interface-wsdl</artifactId> + <version>2.0-Beta3-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>wsdl4j</groupId> + <artifactId>wsdl4j</artifactId> + <version>1.6.2</version> + </dependency> + + </dependencies> + +</project> diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBinding.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBinding.java new file mode 100644 index 0000000000..b6bcb38645 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBinding.java @@ -0,0 +1,279 @@ +/* + * 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; + +import java.util.Map; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.w3c.dom.Element; + + +/** + * Represents a WebService binding. + * + * @version $Rev$ $Date$ + */ +public interface WebServiceBinding extends Binding { + QName TYPE = new QName(SCA11_NS, "binding.ws"); + + /** + * Sets the WSDL location. + * @param location the WSDL location + */ + void setLocation(String location); + + /** + * Returns the WSDL location + * @return the WSDL location + */ + String getLocation(); + + /** + * Returns the wsdli:location attribute namespace mappings + * @return a Map with key being namespace and value the location + */ + Map<String, String> getWsdliLocations(); + + /** + * Returns the name of the WSDL service. + * + * @return the name of the WSDL service + */ + QName getServiceName(); + + /** + * Sets the name of the WSDL service. + * + * @param serviceName the name of the WSDL service + */ + void setServiceName(QName serviceName); + + /** + * Returns the name of the WSDL port. + * + * @return the name of the WSDL port + */ + String getPortName(); + + /** + * Sets the name of the WSDL port. + * + * @param portName the name of the WSDL port + */ + void setPortName(String portName); + + /** + * Returns the name of the WSDL binding. + * + * @return the name of the WSDL binding + */ + QName getBindingName(); + + /** + * Sets the name of the WSDL binding. + * + * @param bindingName the name of the WSDL binding + */ + void setBindingName(QName bindingName); + + /** + * Returns the name of the WSDL endpoint. + * + * @return the name of the WSDL endpoint + */ + String getEndpointName(); + + /** + * Sets the name of the WSDL endpoint. + * + * @param endpointName the name of the WSDL endpoint + */ + void setEndpointName(String endpointName); + + /** + * Returns the WSDL service + * @return the WSDL service + */ + Service getService(); + + /** + * Sets the WSDL service. + * @param service the WSDL service + */ + void setService(Service service); + + /** + * Returns the WSDL port + * @return the WSDL port + */ + Port getPort(); + + /** + * Sets the WSDL endpoint + * @param endpoint the WSDL endpoint + */ + void setEndpoint(Port endpoint); + + /** + * Returns the WSDL endpoint + * @return the WSDL endpoint + */ + Port getEndpoint(); + + /** + * Sets the WSDL port + * @param port the WSDL port + */ + void setPort(Port port); + + /** + * Returns the WSDL binding. + * @return the WSDL binding + */ + javax.wsdl.Binding getBinding(); + + /** + * Sets the WSDL binding + * @param binding the WSDL binding + */ + void setBinding(javax.wsdl.Binding binding); + + /** + * Returns the WSDL definition that was specified by the + * user either via and interface.wsdl or via a wsdlElement + * on the binding. This may be empty if no WSDL was specified + * explicitly in which case the generated WSDL should contain + * a full WSDL description + * + * @return the WSDL definition + */ + WSDLDefinition getUserSpecifiedWSDLDefinition(); + + /** + * Sets the WSDL definition if one was specified by the user in the + * composite file either via and interface.wsdl or via a wsdlElement + * on the binding + * + * @param wsdlDefinition the WSDL definition + */ + void setUserSpecifiedWSDLDefinition(WSDLDefinition wsdlDefinition); + + /** + * Returns the WSDL namespace. + * @return the WSDL namespace + */ + String getNamespace(); + + /** + * Sets the WSDL namespace + * @param namespace the WSDL namespace + */ + void setNamespace(String namespace); + + /** + * Returns true if the model element is unresolved. + * + * @return true if the model element is unresolved. + */ + boolean isUnresolved(); + + /** + * Sets whether the model element is unresolved. + * + * @param unresolved whether the model element is unresolved + */ + void setUnresolved(boolean unresolved); + + InterfaceContract getBindingInterfaceContract(); + + void setBindingInterfaceContract(InterfaceContract bindingInterfaceContract); + + Element getEndPointReference(); + + void setEndPointReference(Element element); + + /** + * Returns the generated WSDL definitions document. + * @return the generated WSDL definitions document + */ + Definition getGeneratedWSDLDocument(); + + /** + * Sets the generated WSDL definitions document. The WSDL is generated + * from the component implementation + * + * @param definition the generated WSDL definitions document + */ + void setGeneratedWSDLDocument(Definition definition); + + /** + * Returns string from the WSDL that represents the SOAP binding transport + */ + String getBindingTransport(); + + /** + * Returns true if the WSDL style is rpc/encoded + */ + boolean isRpcEncoded(); + + /** + * Returns true if the WSDL style is rpc/literal + */ + boolean isRpcLiteral(); + + /** + * Returns true if the WSDL style is doc/encoded + */ + boolean isDocEncoded(); + + /** + * Returns true is the WSDL style is doc/literal + */ + boolean isDocLiteralUnwrapped(); + + /** + * Returns true if the WSDL style is doc/literal/wrapped + */ + boolean isDocLiteralWrapped(); + + /** + * Returns true if the WSDL style is doc/literal + * and the mapping to the interface is bare + */ + boolean isDocLiteralBare(); + + /** + * Returns true is the WSBinding is configured, via WSDL, + * to use an HTTP transport + */ + boolean isHTTPTransport(); + + /** + * Returns true is the WSBinding is configured, via WSDL, + * to use a JMS transport + */ + boolean isJMSTransport(); +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBindingFactory.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBindingFactory.java new file mode 100644 index 0000000000..1ad38c69e4 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBindingFactory.java @@ -0,0 +1,35 @@ +/* + * 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; + +/** + * Factory for the Web Service binding model. + * + * @version $Rev$ $Date$ + */ +public interface WebServiceBindingFactory { + + /** + * Creates a new WebService binding. + * + * @return a new WebService binding + */ + WebServiceBinding createWebServiceBinding(); + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/addressing/EndPointReference.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/addressing/EndPointReference.java new file mode 100644 index 0000000000..a13584a3c2 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/addressing/EndPointReference.java @@ -0,0 +1,62 @@ +/* + * 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.addressing; + +import java.net.URI; +import java.util.List; + +import javax.xml.namespace.QName; + +/** + * Defines a model for WS-Addressing + * <wsa:EndpointReference> + * <wsa:Address>xs:anyURI</wsa:Address> + * <wsa:ReferenceProperties>... </wsa:ReferenceProperties> ? + * <wsa:ReferenceParameters>... </wsa:ReferenceParameters> ? + * <wsa:PortType>xs:QName</wsa:PortType> ? + * <wsa:ServiceName PortName="xs:NCName"?>xs:QName</wsa:ServiceName> ? + * <wsp:Policy> ... </wsp:Policy>* + * </wsa:EndpointReference> + * @version $Rev$ $Date$ + */ +public interface EndPointReference { + URI getAddress(); + + void setAddress(URI address); + + QName getPortType(); + + void setPortType(QName portType); + + QName getServiceName(); + + void setServiceName(QName serviceName); + + QName getPortName(); + + void setPortName(QName portName); + + List<Object> getReferenceProperties(); + + List<Object> getReferenceParameters(); + + List<Object> getPolicies(); + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingFactoryImpl.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingFactoryImpl.java new file mode 100644 index 0000000000..055e2012dc --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingFactoryImpl.java @@ -0,0 +1,35 @@ +/* + * 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.impl; + +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; + +/** + * A factory for the WSDL model. + * + * @version $Rev$ $Date$ + */ +public class WebServiceBindingFactoryImpl implements WebServiceBindingFactory { + + public WebServiceBinding createWebServiceBinding() { + return new WebServiceBindingImpl(); + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java new file mode 100644 index 0000000000..21f7b73756 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java @@ -0,0 +1,457 @@ +/* + * 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.impl; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.wsdl.Binding; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.Definition; +import javax.wsdl.Message; +import javax.wsdl.Part; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Extensible; +import org.apache.tuscany.sca.assembly.Extension; +import org.apache.tuscany.sca.assembly.OperationSelector; +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.policy.ExtensionType; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySubject; +import org.w3c.dom.Element; + +/** + * Represents a WebService binding. + * + * @version $Rev$ $Date$ + */ +class WebServiceBindingImpl implements WebServiceBinding, PolicySubject, Extensible { + private String name; + private String uri; + private boolean unresolved; + private List<Object> extensions = new ArrayList<Object>(); + private List<Extension> attributeExtensions = new ArrayList<Extension>(); + private List<Intent> requiredIntents = new ArrayList<Intent>(); + private List<PolicySet> policySets = new ArrayList<PolicySet>(); + private ExtensionType extensionType; + private String location; + private Binding binding; + private Service service; + private Port port; + private Port endpoint; + private QName bindingName; + private String portName; + private QName serviceName; + private String endpointName; + private InterfaceContract bindingInterfaceContract; + private Element endPointReference; + private String wsdlNamespace; + private WSDLDefinition userSpecifiedWSDLDefinition; + private Definition generatedWSDLDocument; + private boolean isDocumentStyle; + private boolean isLiteralEncoding; + private boolean isMessageWrapped; + private Map<String, String> wsdliLocations = new HashMap<String, String>(); + + protected WebServiceBindingImpl() { + } + + /** + * Provide a meaningful representation of this Binding + */ + public String toString() { + return "Web Service Binding: " + name; + } // end method toString + + public String getName() { + return name; + } + + public String getURI() { + return uri; + } + + public void setName(String name) { + this.name = name; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean unresolved) { + this.unresolved = unresolved; + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public List<Object> getExtensions() { + return extensions; + } + + public List<Extension> getAttributeExtensions() { + return attributeExtensions; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public Binding getBinding() { + if (binding == null) { + if (getUserSpecifiedWSDLDefinition() != null && userSpecifiedWSDLDefinition.getBinding() != null) { + binding = userSpecifiedWSDLDefinition.getBinding(); + determineWSDLCharacteristics(); + } + } + return binding; + } + + public QName getBindingName() { + if (isUnresolved()) { + return bindingName; + } else if (binding != null) { + return binding.getQName(); + } else { + return null; + } + } + + public String getEndpointName() { + if (isUnresolved()) { + return endpointName; + } else if (endpoint != null) { + //TODO support WSDL 2.0 + return endpoint.getName(); + } else { + return null; + } + } + + public Port getEndpoint() { + return endpoint; + } + + public Port getPort() { + return port; + } + + public String getPortName() { + if (isUnresolved()) { + return portName; + } else if (port != null) { + return port.getName(); + } else { + return null; + } + } + + public Service getService() { + return service; + } + + public QName getServiceName() { + if (isUnresolved()) { + return serviceName; + } else if (service != null) { + return service.getQName(); + } else { + return null; + } + } + + public void setBinding(Binding binding) { + this.binding = binding; + determineWSDLCharacteristics(); + } + + public void setBindingName(QName bindingName) { + if (!isUnresolved()) { + throw new IllegalStateException(); + } + this.bindingName = bindingName; + } + + public void setEndpoint(Port endpoint) { + this.endpoint = endpoint; + } + + public void setEndpointName(String endpointName) { + if (!isUnresolved()) { + throw new IllegalStateException(); + } + this.endpointName = endpointName; + } + + public void setPort(Port port) { + this.port = port; + } + + public void setPortName(String portName) { + if (!isUnresolved()) { + throw new IllegalStateException(); + } + this.portName = portName; + } + + public void setService(Service service) { + this.service = service; + } + + public void setServiceName(QName serviceName) { + if (!isUnresolved()) { + throw new IllegalStateException(); + } + this.serviceName = serviceName; + } + + public WSDLDefinition getUserSpecifiedWSDLDefinition() { + if (userSpecifiedWSDLDefinition == null) { + Interface iface = bindingInterfaceContract.getInterface(); + if (iface instanceof WSDLInterface) { + userSpecifiedWSDLDefinition = ((WSDLInterface)iface).getWsdlDefinition(); + } + } + return userSpecifiedWSDLDefinition; + } + + public void setUserSpecifiedWSDLDefinition(WSDLDefinition wsdlDefinition) { + this.userSpecifiedWSDLDefinition = wsdlDefinition; + } + + public String getNamespace() { + return wsdlNamespace; + } + + public void setNamespace(String namespace) { + this.wsdlNamespace = namespace; + } + + public InterfaceContract getBindingInterfaceContract() { + return bindingInterfaceContract; + } + + public void setBindingInterfaceContract(InterfaceContract bindingInterfaceContract) { + this.bindingInterfaceContract = bindingInterfaceContract; + } + + public List<PolicySet> getPolicySets() { + return policySets; + } + + public List<Intent> getRequiredIntents() { + return requiredIntents; + } + + public ExtensionType getExtensionType() { + return extensionType; + } + + public void setExtensionType(ExtensionType intentAttachPointType) { + this.extensionType = intentAttachPointType; + } + + public Element getEndPointReference() { + return endPointReference; + } + + public void setEndPointReference(Element epr) { + this.endPointReference = epr; + } + + public Definition getGeneratedWSDLDocument() { + return generatedWSDLDocument; + } + + public void setGeneratedWSDLDocument(Definition definition) { + this.generatedWSDLDocument = definition; + determineWSDLCharacteristics(); + } + + public QName getType() { + return TYPE; + } + + public WireFormat getRequestWireFormat() { + return null; + } + + public void setRequestWireFormat(WireFormat wireFormat) { + } + + public WireFormat getResponseWireFormat() { + return null; + } + + public void setResponseWireFormat(WireFormat wireFormat) { + } + + public OperationSelector getOperationSelector() { + return null; + } + + public void setOperationSelector(OperationSelector operationSelector) { + } + + /** + * Some items get calculated and cached as they are used at runtime + * to decide what message processing is required + */ + protected void determineWSDLCharacteristics() { + setIsDocumentStyle(); + setIsLiteralEncoding(); + setIsMessageWrapped(); + } + + protected void setIsDocumentStyle() { + + if (binding == null) { + if (userSpecifiedWSDLDefinition != null && userSpecifiedWSDLDefinition.getDefinition() != null) { + Message firstMessage = + (Message)userSpecifiedWSDLDefinition.getDefinition().getMessages().values().iterator().next(); + Part firstPart = (Part)firstMessage.getParts().values().iterator().next(); + if (firstPart.getTypeName() != null) { + isDocumentStyle = false; + return; + } + } + + // default to document style + isDocumentStyle = true; + return; + } else { + for (Object ext : binding.getExtensibilityElements()) { + if (ext instanceof SOAPBinding) { + isDocumentStyle = !"rpc".equals(((SOAPBinding)ext).getStyle()); + return; + } + } + isDocumentStyle = true; + return; + } + + } + + protected void setIsLiteralEncoding() { + + if (binding == null) { + // default to literal encoding + isLiteralEncoding = true; + return; + } else { + for (Object bop : binding.getBindingOperations()) { + BindingInput bindingInput = ((BindingOperation)bop).getBindingInput(); + if (bindingInput != null) { + for (Object ext : bindingInput.getExtensibilityElements()) { + if (ext instanceof SOAPBody) { + isLiteralEncoding = "literal".equals(((SOAPBody)ext).getUse()); + return; + } + } + } + } + isLiteralEncoding = true; + return; + } + } + + protected void setIsMessageWrapped() { + if (getBindingInterfaceContract() != null) { + isMessageWrapped = getBindingInterfaceContract().getInterface().getOperations().get(0).isWrapperStyle(); + } + } + + public boolean isRpcEncoded() { + return (!isDocumentStyle) && (!isLiteralEncoding); + } + + public boolean isRpcLiteral() { + return (!isDocumentStyle) && (isLiteralEncoding); + } + + public boolean isDocEncoded() { + return (isDocumentStyle) && (!isLiteralEncoding); + } + + public boolean isDocLiteralUnwrapped() { + setIsMessageWrapped(); + return (isDocumentStyle) && (isLiteralEncoding) && (!isMessageWrapped); + } + + public boolean isDocLiteralWrapped() { + setIsMessageWrapped(); + return (isDocumentStyle) && (isLiteralEncoding) && (isMessageWrapped); + } + + public boolean isDocLiteralBare() { + setIsMessageWrapped(); + return (isDocumentStyle) && (isLiteralEncoding); + } + + public boolean isHTTPTransport() { + return getBindingTransport().equals("http://schemas.xmlsoap.org/soap/http"); + } + + public boolean isJMSTransport() { + return getBindingTransport().equals("http://schemas.xmlsoap.org/soap/jms"); + } + + public String getBindingTransport() { + if (binding != null) { + for (Object ext : binding.getExtensibilityElements()) { + if (ext instanceof SOAPBinding) { + return ((SOAPBinding)ext).getTransportURI(); + } + } + } + + // if no binding is explicitly specified by the user then default to http + return "http://schemas.xmlsoap.org/soap/http"; + } + + public Map<String, String> getWsdliLocations() { + return wsdliLocations; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/xml/EndPointReferenceHelper.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/xml/EndPointReferenceHelper.java new file mode 100644 index 0000000000..2041a0ff91 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/xml/EndPointReferenceHelper.java @@ -0,0 +1,221 @@ +/* + * 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.xml; + +import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI; + +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.common.xml.stax.StAXHelper; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; + +/** + * Helper methods to read and write a wsa:endpointReference + * TODO: almost direct copy of code for Assembly properties + * must be able to move to a common utility + * + * @version $Rev$ $Date$ + */ +public class EndPointReferenceHelper { + + /** + * Read a wsa:endpointReference into a DOM Element + */ + public static Element readEndPointReference(XMLStreamReader reader) { + try { + + return loadElement(reader); + + } catch (XMLStreamException e) { + throw new RuntimeException(e); + } catch (ParserConfigurationException e) { + throw new RuntimeException(e); + } + } + + /** + * Write a wsa:endpointReference from a DOM Element + */ + public static void writeEndPointReference(Element element, XMLStreamWriter writer, StAXHelper staxHelper) { + try { + + saveElement(element, writer, staxHelper); + + } catch (XMLStreamException e) { + throw new RuntimeException(e); + } + } + + private static Element loadElement(XMLStreamReader reader) throws XMLStreamException, ParserConfigurationException { + Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); + Node root = document; + Node current = root; + while (true) { + switch (reader.getEventType()) { + case XMLStreamConstants.START_ELEMENT: + QName name = reader.getName(); + Element child = createElement(document, name); + + // push the new element and make it the current one + current.appendChild(child); + current = child; + + int count = reader.getNamespaceCount(); + for (int i = 0; i < count; i++) { + String prefix = reader.getNamespacePrefix(i); + String ns = reader.getNamespaceURI(i); + declareNamespace(child, prefix, ns); + } + + if(!"".equals(name.getNamespaceURI())) + declareNamespace(child, name.getPrefix(), name.getNamespaceURI()); + + // add the attributes for this element + count = reader.getAttributeCount(); + for (int i = 0; i < count; i++) { + String ns = reader.getAttributeNamespace(i); + String prefix = reader.getAttributePrefix(i); + String qname = reader.getAttributeLocalName(i); + String value = reader.getAttributeValue(i); + if (prefix != null && prefix.length() != 0) { + qname = prefix + ":" + qname; + } + child.setAttributeNS(ns, qname, value); + if (ns != null) { + declareNamespace(child, prefix, ns); + } + } + + break; + case XMLStreamConstants.CDATA: + current.appendChild(document.createCDATASection(reader.getText())); + break; + case XMLStreamConstants.CHARACTERS: + current.appendChild(document.createTextNode(reader.getText())); + break; + case XMLStreamConstants.END_ELEMENT: + // if we are back at the root then we are done + if ("EndpointReference".equals(reader.getName().getLocalPart())) { + return document.getDocumentElement(); + } + + // pop the element off the stack + current = current.getParentNode(); + } + if ( reader.hasNext()) reader.next(); + } + } + + private static Element createElement(Document document, QName name) { + String prefix = name.getPrefix(); + String qname = + (prefix != null && prefix.length() > 0) ? prefix + ":" + name.getLocalPart() : name.getLocalPart(); + return document.createElementNS(name.getNamespaceURI(), qname); + } + + private static void declareNamespace(Element element, String prefix, String ns) { + if (ns == null) { + ns = ""; + } + if (prefix == null) { + prefix = ""; + } + String qname = null; + if ("".equals(prefix)) { + qname = "xmlns"; + } else { + qname = "xmlns:" + prefix; + } + Node node = element; + boolean declared = false; + while (node != null && node.getNodeType() == Node.ELEMENT_NODE) { + NamedNodeMap attrs = node.getAttributes(); + if (attrs == null) { + break; + } + Node attr = attrs.getNamedItem(qname); + if (attr != null) { + declared = ns.equals(attr.getNodeValue()); + break; + } + node = node.getParentNode(); + } + if (!declared) { + org.w3c.dom.Attr attr = element.getOwnerDocument().createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, qname); + attr.setValue(ns); + element.setAttributeNodeNS(attr); + } + } + + private static void saveElement(Element element, XMLStreamWriter writer, StAXHelper staxHelper) throws XMLStreamException{ + + XMLStreamReader reader = staxHelper.createXMLStreamReader(element); + + while (reader.hasNext()) { + switch (reader.next()) { + case XMLStreamConstants.START_ELEMENT: + QName name = reader.getName(); + writer.writeStartElement(name.getPrefix(), name.getLocalPart(), name.getNamespaceURI()); + + int namespaces = reader.getNamespaceCount(); + for (int i = 0; i < namespaces; i++) { + String prefix = reader.getNamespacePrefix(i); + String ns = reader.getNamespaceURI(i); + writer.writeNamespace(prefix, ns); + } + + if (!"".equals(name.getNamespaceURI())) { + writer.writeNamespace(name.getPrefix(), name.getNamespaceURI()); + } + + // add the attributes for this element + namespaces = reader.getAttributeCount(); + for (int i = 0; i < namespaces; i++) { + String ns = reader.getAttributeNamespace(i); + String prefix = reader.getAttributePrefix(i); + String qname = reader.getAttributeLocalName(i); + String value = reader.getAttributeValue(i); + + writer.writeAttribute(prefix, ns, qname, value); + } + + break; + case XMLStreamConstants.CDATA: + writer.writeCData(reader.getText()); + break; + case XMLStreamConstants.CHARACTERS: + writer.writeCharacters(reader.getText()); + break; + case XMLStreamConstants.END_ELEMENT: + writer.writeEndElement(); + break; + } + } + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java new file mode 100644 index 0000000000..f5384caf16 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java @@ -0,0 +1,529 @@ +/* + * 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.xml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; +import static org.apache.tuscany.sca.binding.ws.xml.WebServiceConstants.SCA11_NS; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.wsdl.Binding; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.extensions.soap12.SOAP12Address; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.Callback; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.xml.PolicySubjectProcessor; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; +import org.apache.tuscany.sca.common.xml.stax.StAXHelper; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLObject; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * This is the StAXArtifactProcessor for the Web Services Binding. + * + * @version $Rev$ $Date$ + */ +public class WebServiceBindingProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<WebServiceBinding>, WebServiceConstants { + + private ExtensionPointRegistry extensionPoints; + private WSDLFactory wsdlFactory; + private WebServiceBindingFactory wsFactory; + private PolicyFactory policyFactory; + private PolicySubjectProcessor policyProcessor; + //private PolicyFactory intentAttachPointTypeFactory; + private StAXHelper staxHelper; + + + public WebServiceBindingProcessor(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; + FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); + this.policyFactory = modelFactories.getFactory(PolicyFactory.class); + this.wsFactory = modelFactories.getFactory(WebServiceBindingFactory.class); + this.wsdlFactory = modelFactories.getFactory(WSDLFactory.class); + this.policyProcessor = new PolicySubjectProcessor(policyFactory); + staxHelper = StAXHelper.getInstance(extensionPoints); + } + + /** + * Report a warning. + * + * @param problems + * @param message + * @param model + */ + private void warning(Monitor monitor, String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = monitor.createProblem(this.getClass().getName(), "binding-wsxml-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(Monitor monitor, String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = monitor.createProblem(this.getClass().getName(), "binding-wsxml-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + public WebServiceBinding read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { + Monitor monitor = context.getMonitor(); + // Read a <binding.ws> + WebServiceBinding wsBinding = wsFactory.createWebServiceBinding(); + /*ExtensionType bindingType = intentAttachPointTypeFactory.createBindingType(); + bindingType.setName(getArtifactType()); + bindingType.setUnresolved(true); + ((PolicySubject)wsBinding).setType(bindingType);*/ + wsBinding.setUnresolved(true); + + // Read policies + policyProcessor.readPolicies(wsBinding, reader); + + // Read the binding name + String name = reader.getAttributeValue(null, NAME); + if (name != null) { + wsBinding.setName(name); + } + + // a collection of endpoint specifications so that we can test that + // only one is present + List<String> endpointSpecifications = new ArrayList<String>(); + + // Read URI + String uri = getURIString(reader, URI); + if (uri != null) { + wsBinding.setURI(uri); + + // BWS20001 + if (context.getParentModel() instanceof Reference){ + try { + URI tmpURI = new URI(uri); + + if (!tmpURI.isAbsolute()){ + error(monitor, "URINotAbsolute", reader, uri); + } + } catch (URISyntaxException ex){ + error(monitor, "InvalidURISyntax", reader, ex.getMessage()); + } + endpointSpecifications.add("uri"); + } + + // BWS20020 + if ((context.getParentModel() instanceof Callback) && + (((Callback)context.getParentModel()).getParentContract() instanceof org.apache.tuscany.sca.assembly.Service)){ + error(monitor, "URIFoundForServiceCallback", reader, uri); + } + } + + // Read a qname in the form: + // namespace#wsdl.???(name) + Boolean wsdlElementIsBinding = null; + String wsdlElement = getURIString(reader, WSDL_ELEMENT); + if (wsdlElement != null) { + int index = wsdlElement.indexOf('#'); + if (index == -1) { + error(monitor, "InvalidWsdlElementAttr", reader, wsdlElement); + //throw new ContributionReadException("Invalid WebService binding wsdlElement attribute: " + wsdlElement); + return wsBinding; + } + String namespace = wsdlElement.substring(0, index); + wsBinding.setNamespace(namespace); + String localName = wsdlElement.substring(index + 1); + if (localName.startsWith("wsdl.service")) { + + // BWS20003 + if (context.getParentModel() instanceof org.apache.tuscany.sca.assembly.Service){ + error(monitor, "WSDLServiceOnService", reader, wsdlElement); + } + + // Read a wsdl.service + localName = localName.substring("wsdl.service(".length(), localName.length() - 1); + wsBinding.setServiceName(new QName(namespace, localName)); + + endpointSpecifications.add("#wsdl.service"); + + } else if (localName.startsWith("wsdl.port")) { + + // Read a wsdl.port + localName = localName.substring("wsdl.port(".length(), localName.length() - 1); + int s = localName.indexOf('/'); + if (s == -1) { + error(monitor, "InvalidWsdlElementAttr", reader, wsdlElement); + //throw new ContributionReadException("Invalid WebService binding wsdlElement attribute: " + wsdlElement); + } else { + wsBinding.setServiceName(new QName(namespace, localName.substring(0, s))); + wsBinding.setPortName(localName.substring(s + 1)); + } + + endpointSpecifications.add("#wsdl.port"); + } else if (localName.startsWith("wsdl.endpoint")) { + + // Read a wsdl.endpoint + localName = localName.substring("wsdl.endpoint(".length(), localName.length() - 1); + int s = localName.indexOf('/'); + if (s == -1) { + error(monitor, "InvalidWsdlElementAttr", reader, wsdlElement); + //throw new ContributionReadException("Invalid WebService binding wsdlElement attribute: " + wsdlElement); + } else { + wsBinding.setServiceName(new QName(namespace, localName.substring(0, s))); + wsBinding.setEndpointName(localName.substring(s + 1)); + } + + } else if (localName.startsWith("wsdl.binding")) { + + // Read a wsdl.binding + localName = localName.substring("wsdl.binding(".length(), localName.length() - 1); + wsBinding.setBindingName(new QName(namespace, localName)); + + wsdlElementIsBinding = true; + + } else { + error(monitor, "InvalidWsdlElementAttr", reader, wsdlElement); + //throw new ContributionReadException("Invalid WebService binding wsdlElement attribute: " + wsdlElement); + } + } + + // Read wsdlLocation + String wsdliLocation = reader.getAttributeValue(WSDLI_NS, WSDL_LOCATION); + if (wsdliLocation != null) { + if (wsdlElement == null) { + error(monitor, "WsdliLocationMissingWsdlElement", reader); + } + String[] iris = wsdliLocation.split(" "); + if (iris.length % 2 != 0) { + error(monitor, "WsdliLocationNotIRIPairs", reader); + } + for (int i=0; i<iris.length-1; i=i+2) { + wsBinding.getWsdliLocations().put(iris[i], iris[i+1]); + } + } + + // Skip to end element + while (reader.hasNext()) { + int event = reader.next(); + switch (event) { + case START_ELEMENT: { + if (END_POINT_REFERENCE.equals(reader.getName().getLocalPart())) { + if (wsdlElement != null && (wsdlElementIsBinding == null || !wsdlElementIsBinding)) { + error(monitor, "MustUseWsdlBinding", reader, wsdlElement); + throw new ContributionReadException(wsdlElement + " must use wsdl.binding when using wsa:EndpointReference"); + } + + wsBinding.setEndPointReference(EndPointReferenceHelper.readEndPointReference(reader)); + endpointSpecifications.add("wsa:EndpointReference"); + } + } + break; + + } + + if (event == END_ELEMENT && BINDING_WS_QNAME.equals(reader.getName())) { + break; + } + } + + if (endpointSpecifications.size() > 1){ + error(monitor, "MultipleEndpointsSpecified", reader, endpointSpecifications.toString() ); + } + + return wsBinding; + } + + protected void processEndPointReference(XMLStreamReader reader, WebServiceBinding wsBinding) { + } + + public void write(WebServiceBinding wsBinding, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, + XMLStreamException { + + // Write a <binding.ws> + writer.writeStartElement(SCA11_NS, BINDING_WS); + policyProcessor.writePolicyAttributes(wsBinding, writer); + + // Write binding name + if (wsBinding.getName() != null) { + writer.writeAttribute(NAME, wsBinding.getName()); + } + + // Write binding URI + if (wsBinding.getURI() != null) { + writer.writeAttribute(URI, wsBinding.getURI()); + } + + // Write wsdlElement attribute + if (wsBinding.getPortName() != null) { + + // Write namespace#wsdl.port(service/port) + String wsdlElement = + wsBinding.getServiceName().getNamespaceURI() + "#wsdl.port(" + + wsBinding.getServiceName().getLocalPart() + + "/" + + wsBinding.getPortName() + + ")"; + writer.writeAttribute(WSDL_ELEMENT, wsdlElement); + + } else if (wsBinding.getEndpointName() != null) { + + // Write namespace#wsdl.endpoint(service/endpoint) + String wsdlElement = + wsBinding.getServiceName().getNamespaceURI() + "#wsdl.endpoint(" + + wsBinding.getServiceName().getLocalPart() + + "/" + + wsBinding.getEndpointName() + + ")"; + writer.writeAttribute(WSDL_ELEMENT, wsdlElement); + + } else if (wsBinding.getBindingName() != null) { + + // Write namespace#wsdl.binding(binding) + String wsdlElement = + wsBinding.getBindingName().getNamespaceURI() + "#wsdl.binding(" + + wsBinding.getBindingName().getLocalPart() + + ")"; + writer.writeAttribute(WSDL_ELEMENT, wsdlElement); + + } else if (wsBinding.getServiceName() != null) { + + // Write namespace#wsdl.service(service) + String wsdlElement = + wsBinding.getServiceName().getNamespaceURI() + "#wsdl.service(" + + wsBinding.getServiceName().getLocalPart() + + ")"; + writer.writeAttribute(WSDL_ELEMENT, wsdlElement); + } + + // Write wsdli:location + if (wsBinding.getWsdliLocations().size() > 0) { + StringBuilder wsdliLocation = new StringBuilder(); + Map<String, String> wl = wsBinding.getWsdliLocations(); + for (String ns : wl.keySet()) { + if (wsdliLocation.length() > 0) { + wsdliLocation.append(' '); + } + wsdliLocation.append(ns); + wsdliLocation.append(' '); + wsdliLocation.append(wl.get(ns)); + } + writer.writeAttribute(WSDLI_NS, WSDL_LOCATION, wsdliLocation.toString()); + } + + if (wsBinding.getEndPointReference() != null) { + EndPointReferenceHelper.writeEndPointReference(wsBinding.getEndPointReference(), writer, staxHelper); + } + + writer.writeEndElement(); + } + + public void resolve(WebServiceBinding model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { + + if (model == null || !model.isUnresolved()) + return; + Monitor monitor = context.getMonitor(); + WSDLDefinition wsdlDefinition = wsdlFactory.createWSDLDefinition(); + wsdlDefinition.setUnresolved(true); + wsdlDefinition.setNamespace(model.getNamespace()); + wsdlDefinition.setNameOfBindingToResolve(model.getBindingName()); + wsdlDefinition.setNameOfServiceToResolve(model.getServiceName()); + wsdlDefinition.getWsdliLocations().putAll(model.getWsdliLocations()); + WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, wsdlDefinition, context); + + if (!resolved.isUnresolved()) { + wsdlDefinition.setDefinition(resolved.getDefinition()); + wsdlDefinition.setLocation(resolved.getLocation()); + wsdlDefinition.setURI(resolved.getURI()); + wsdlDefinition.getImportedDefinitions().addAll(resolved.getImportedDefinitions()); + wsdlDefinition.getXmlSchemas().addAll(resolved.getXmlSchemas()); + wsdlDefinition.setUnresolved(false); + model.setUserSpecifiedWSDLDefinition(wsdlDefinition); + if (model.getBindingName() != null) { + WSDLObject<Binding> binding = wsdlDefinition.getWSDLObject(Binding.class, model.getBindingName()); + if (binding != null) { + wsdlDefinition.setDefinition(binding.getDefinition()); + model.setBinding(binding.getElement()); + } else { + error(monitor, "WsdlBindingDoesNotMatch", wsdlDefinition, model.getBindingName()); + } + } + if (model.getServiceName() != null) { + WSDLObject<Service> service = wsdlDefinition.getWSDLObject(Service.class, model.getServiceName()); + if (service != null) { + wsdlDefinition.setDefinition(service.getDefinition()); + model.setService(service.getElement()); + + Port port = null; + if (model.getPortName() != null) { + port = service.getElement().getPort(model.getPortName()); + } else { + // BWS20006 - no port specified so pick the first one + port = (Port)service.getElement().getPorts().values().iterator().next(); + } + + if (port != null) { + model.setPort(port); + model.setBinding(port.getBinding()); + + // if no URI specified set it from the WSDL port location + if (model.getURI() == null){ + model.setURI(getPortAddress(port)); + } + } else { + error(monitor, "WsdlPortTypeDoesNotMatch", wsdlDefinition, model.getPortName()); + } + } else { + error(monitor, "WsdlServiceDoesNotMatch", wsdlDefinition, model.getServiceName()); + } + } + + PortType portType = getPortType(model); + if (portType != null) { + WSDLInterfaceContract interfaceContract = wsdlFactory.createWSDLInterfaceContract(); + WSDLInterface wsdlInterface = null; + try { + wsdlInterface = wsdlFactory.createWSDLInterface(portType, wsdlDefinition, resolver, context.getMonitor()); + } catch (InvalidInterfaceException e) { + warning(monitor, "InvalidInterfaceException", wsdlFactory, model.getName(), e.getMessage()); + } + interfaceContract.setInterface(wsdlInterface); + interfaceContract.setCallbackInterface(wsdlInterface.getCallbackInterface()); + model.setBindingInterfaceContract(interfaceContract); + } + + validateWSDL(context, model); + } else { + if (model.getBindingName() != null){ + error(monitor, "WsdlBindingDoesNotMatch", model, model.getBindingName()); + } + + if (model.getServiceName() != null){ + error(monitor, "WsdlServiceDoesNotMatch", model, model.getServiceName()); + } + } + + policyProcessor.resolvePolicies(model, resolver, context); + } + + private void validateWSDL(ProcessorContext context, WebServiceBinding model) { + WSDLDefinition wsdlDefinition = model.getUserSpecifiedWSDLDefinition(); + + Port port = model.getPort(); + + if (port != null){ + validateWSDLPort(context, model, port); + } + + Binding binding = model.getBinding(); + + if (binding != null){ + validateWSDLBinding(context, model, binding); + } + } + + private void validateWSDLPort(ProcessorContext context, WebServiceBinding model, Port port){ + + validateWSDLBinding(context, model, port.getBinding()); + + } + + private void validateWSDLBinding(ProcessorContext context, WebServiceBinding model, Binding binding){ + // BWS20005 & BWS20010 + // Check that the WSDL binding is of a supported type + if (!model.isHTTPTransport() && !model.isJMSTransport()){ + error(context.getMonitor(), + "InvalidWSDLBindingTransport", + model, + model.getBindingTransport()); + } + } + + private PortType getPortType(WebServiceBinding model) { + PortType portType = null; + if (model.getPort() != null) { + portType = model.getPort().getBinding().getPortType(); + } else if (model.getEndpoint() != null) { + portType = model.getPort().getBinding().getPortType(); + } else if (model.getBinding() != null) { + portType = model.getBinding().getPortType(); + } else if (model.getService() != null) { + // FIXME: How to find the compatible port? + Map ports = model.getService().getPorts(); + if (!ports.isEmpty()) { + Port port = (Port)ports.values().iterator().next(); + portType = port.getBinding().getPortType(); + } + } + return portType; + } + + public static String getPortAddress(Port port) { + Object ext = port.getExtensibilityElements().get(0); + if (ext instanceof SOAPAddress) { + return ((SOAPAddress)ext).getLocationURI(); + } + if (ext instanceof SOAP12Address) { + return ((SOAP12Address)ext).getLocationURI(); + } + return null; + } + + public QName getArtifactType() { + return WebServiceConstants.BINDING_WS_QNAME; + } + + public Class<WebServiceBinding> getModelType() { + return WebServiceBinding.class; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceConstants.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceConstants.java new file mode 100644 index 0000000000..a7126a67ee --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceConstants.java @@ -0,0 +1,47 @@ +/* + * 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.xml; + +import javax.xml.namespace.QName; + +/** + * Constants for the Web Services Binding. + * + * @version $Rev$ $Date$ + */ +public interface WebServiceConstants { + String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200912"; + + String BINDING_WS = "binding.ws"; + QName BINDING_WS_QNAME = new QName(SCA11_NS, BINDING_WS); + + String WSDL_ELEMENT = "wsdlElement"; + QName WSDL_ELEMENT_QNAME = new QName(SCA11_NS, WSDL_ELEMENT); + + String WSDL_LOCATION = "wsdlLocation"; + String WSDLI_NS = "http://www.w3.org/ns/wsdl-instance"; + + QName WSDL_LOCATION_QNAME = new QName(WSDLI_NS, WSDL_LOCATION); + + String NAME = "name"; + String URI = "uri"; + String END_POINT_REFERENCE = "EndpointReference"; + + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory new file mode 100644 index 0000000000..29fa81e2af --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory @@ -0,0 +1,19 @@ +# 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. + +# Implementation class for the model factory +org.apache.tuscany.sca.binding.ws.impl.WebServiceBindingFactoryImpl
diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..75a0170373 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,20 @@ +# 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. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.binding.ws.xml.WebServiceBindingProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200912#binding.ws,model=org.apache.tuscany.sca.binding.ws.WebServiceBinding +
diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.xml.Definitions b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.xml.Definitions new file mode 100644 index 0000000000..3817fca40b --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.xml.Definitions @@ -0,0 +1,17 @@ +# 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.
+org/apache/tuscany/sca/binding/ws/definitions.xml
diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/resources/binding-wsxml-validation-messages.properties b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/resources/binding-wsxml-validation-messages.properties new file mode 100644 index 0000000000..4c2a857d6c --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/resources/binding-wsxml-validation-messages.properties @@ -0,0 +1,38 @@ +# +# +# 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. +# +# +InvalidWsdlElementAttr = Invalid WebService binding wsdlElement attribute: {0} +MustUseWsdlBinding = {0} must use wsdl.binding when using wsa:EndpointReference +InvalidInterfaceException = Exception creating interface from WSDL for binding {0} exception {1} +WsdlBindingDoesNotMatch = The #wsdl.binding({0}) not found in the available WSDL Definitions +WsdlServiceDoesNotMatch = [BWS20005] The #wsdl.service({0}) not found in the available WSDL Definitions +WsdlPortTypeDoesNotMatch = The #wsdl.port({0}) does not match with the WSDL Definitions +WsdliLocationMissingWsdlElement = [BWS20017] binding.ws has a @wsdli:wsdlLocation attribute but no @wsdlElement attribute +WsdliLocationNotIRIPairs = The binding.ws @wsdli:wsdlLocation attribute MUST be a list of pairs of IRIs +URINotAbsolute = [BWS20001] The URI value for binding.ws on an SCA reference must be absolute. Non-absolute value found {0} +InvalidURISyntax = The URI value {0} found on binding.ws has invalid syntax +WSDLServiceOnService = [BWS20003] The wsdlElement attribute of a binding.ws on an SCA service must not specify the wsdl.service form of URI. The following URI was found {0} +URIFoundForServiceCallback = [BWS20020] For the callback element of an SCA service, the binding must not specify an endpoint address URI or a WS-Addressing wsa:EndpointReference +InvalidWSDLBindingTransport = [BWS20005][BWS20010] The WSDL binding transport {0} is not supported by Tuscany +MultipleEndpointsSpecified = [BWS20019] with binding.ws you can only specify one of url, wsa:EndpointReference, #wsdl.service or #wsdl.port. The following were found {0} + + + + diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/resources/org/apache/tuscany/sca/binding/ws/definitions.xml b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/resources/org/apache/tuscany/sca/binding/ws/definitions.xml new file mode 100644 index 0000000000..13296ac65b --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/main/resources/org/apache/tuscany/sca/binding/ws/definitions.xml @@ -0,0 +1,44 @@ +<?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. +--> + +<!-- $Rev$ $Date$ --> + +<sca:definitions xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" + targetNamespace="http://tuscany.apache.org/xmlns/sca/1.1" + xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912" + xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"> + + <!-- MJE 22/06/2010 - add asyncInvocation to the @mayProvide list, for async services support --> + <sca:bindingType type="sca:binding.ws" + mayProvide="sca:SOAP sca:SOAP.v1_1 sca:SOAP.v1_2 tuscany:MTOM sca:asyncInvocation" + alwaysProvides=""/> + + <!-- see the file sca-policy-1.1-intents-definitions.xml in the --> + <!-- assembly-xsd module for spec defined intents --> + + <!-- PolicyIntents defined by the SCA Runtime Extension for WS Binding Axis 2 --> + + <sca:intent name="MTOM" constrains="sca:binding.ws"> + <sca:description> + Communication through this binding requires MTOM support + </sca:description> + </sca:intent> + + </sca:definitions> diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.java new file mode 100644 index 0000000000..85d41bd15c --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.java @@ -0,0 +1,106 @@ +/* + * 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.xml; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.fail; + +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Test reading WSDL interfaces. + * + * @version $Rev$ $Date$ + */ +public class ReadTestCase { + + private static XMLInputFactory inputFactory; + private static StAXArtifactProcessor<Object> staxProcessor; + private static ProcessorContext context; + + @BeforeClass + public static void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); + inputFactory = XMLInputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null); + } + + @Test + public void testReadComponentType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + ComponentType componentType = (ComponentType)staxProcessor.read(reader, context); + assertNotNull(componentType); + } + + @Test + public void testReadComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite composite = (Composite)staxProcessor.read(reader, context); + assertNotNull(composite); + } + + @Test + public void testReadPolicies() throws Exception { + InputStream is = getClass().getResourceAsStream("PoliciedCalculator.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite composite = (Composite)staxProcessor.read(reader, context); + assertNotNull(composite); + } + + /** + * This test makes sure that an exception is thrown when a bad wsdlElement is present along with EndpointReference. + * + * Ref: Web Service Binding Specification v1.0 - Sec 2.1 - Lines 61 to 65. + * When an EndpointReference is present along with the wsdlElement attribute on the parent element, the wsdlElement attribute value MUST + * be of the 'Binding' form. + */ + @Test + public void testReadBadWsdlElement() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator-bad-wsdlElement.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + try { + staxProcessor.read(reader, context); + fail("ContributionReadException expected."); + } catch(ContributionReadException e) { + // Expected + assertNotSame(-1, e.getMessage().indexOf("must use wsdl.binding when using wsa:EndpointReference")); + } + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/java/org/apache/tuscany/sca/binding/ws/xml/WriteTestCase.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/java/org/apache/tuscany/sca/binding/ws/xml/WriteTestCase.java new file mode 100644 index 0000000000..805b1862ce --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/java/org/apache/tuscany/sca/binding/ws/xml/WriteTestCase.java @@ -0,0 +1,82 @@ +/* + * 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.xml; + +import static org.junit.Assert.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; + +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Test reading/write WSDL interfaces. + * + * @version $Rev$ $Date$ + */ +public class WriteTestCase { + + private static XMLInputFactory inputFactory; + private static XMLOutputFactory outputFactory; + private static StAXArtifactProcessor<Object> staxProcessor; + private static ProcessorContext context; + + @BeforeClass + public static void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); + inputFactory = XMLInputFactory.newInstance(); + outputFactory = XMLOutputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory); + } + + @Test + public void testReadWriteComponentType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); + ComponentType componentType = (ComponentType)staxProcessor.read(inputFactory.createXMLStreamReader(is), context); + assertNotNull(componentType); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(componentType, outputFactory.createXMLStreamWriter(bos), context); + } + + @Test + public void testReadWriteComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is), context); + assertNotNull(composite); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); + System.out.println(bos.toString()); + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/Calculator-bad-wsdlElement.composite b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/Calculator-bad-wsdlElement.composite new file mode 100644 index 0000000000..2404e9ba28 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/Calculator-bad-wsdlElement.composite @@ -0,0 +1,59 @@ +<?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. +--> +<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" + xmlns:calc="http://sample.calculator" + targetNamespace="http://calc" + xmlns:wsdli="http://www.w3.org/2004/08/wsdl-instance" + name="Calculator-bad-wsdlElement"> + + <service name="CalculatorService" promote="CalculatorServiceComponent"> + <interface.wsdl interface="http://sample/calculator#wsdl.interface(Calculator)"/> + <binding.ws wsdlElement="http://sample/calculator#wsdl.port(CalculatorService/CalculatorPort)"> + <wsa:EndpointReference xmlns:wsa="http://www.w3.org/2005/08/addressing"> + <wsa:Address>http://localhost:8085/Calculator</wsa:Address> + </wsa:EndpointReference> + </binding.ws> + </service> + + <component name="CalculatorServiceComponent"> + <implementation.java class="calculator.CalculatorServiceImpl"/> + <reference name="addService" target="AddServiceComponent"/> + <reference name="subtractService" target="SubtractServiceComponent"/> + <reference name="multiplyService" target="MultiplyServiceComponent"/> + <reference name="divideService" target="DivideServiceComponent"/> + </component> + + <component name="AddServiceComponent"> + <implementation.java class="calculator.AddServiceImpl"/> + </component> + + <component name="SubtractServiceComponent"> + <implementation.java class="calculator.SubtractServiceImpl"/> + </component> + + <component name="MultiplyServiceComponent"> + <implementation.java class="calculator.MultiplyServiceImpl"/> + </component> + + <component name="DivideServiceComponent"> + <implementation.java class="calculator.DivideServiceImpl"/> + </component> + +</composite> diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/Calculator.composite b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/Calculator.composite new file mode 100644 index 0000000000..64965a689c --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/Calculator.composite @@ -0,0 +1,63 @@ +<?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. +--> +<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" + xmlns:calc="http://sample.calculator" + targetNamespace="http://calc" + xmlns:wsdli="http://www.w3.org/2004/08/wsdl-instance" + name="Calculator"> + + <service name="CalculatorService" promote="CalculatorServiceComponent"> + <interface.wsdl interface="http://sample/calculator#wsdl.interface(Calculator)"/> + <binding.ws uri="http://localhost:8085/Calculator" wsdlElement="http://sample/calculator#wsdl.service(CalculatorService)"/> + <binding.ws wsdli:wsdlLocation="http://tempuri.org" wsdlElement="http://sample/calculator#wsdl.binding(CalculatorBinding)"/> + <binding.ws wsdlElement="http://sample/calculator#wsdl.port(CalculatorService/CalculatorPort)"/> + <binding.ws wsdlElement="http://sample/calculator#wsdl.endpoint(CalculatorService/CalculatorEndpoint)"/> + <binding.ws wsdlElement="http://sample/calculator#wsdl.binding(CalculatorBinding)"> + <wsa:EndpointReference xmlns:wsa="http://www.w3.org/2005/08/addressing"> + <wsa:Address>http://localhost:8085/services/HelloWorldWebService</wsa:Address> + </wsa:EndpointReference> + </binding.ws> + </service> + + <component name="CalculatorServiceComponent"> + <implementation.java class="calculator.CalculatorServiceImpl"/> + <reference name="addService" target="AddServiceComponent"/> + <reference name="subtractService" target="SubtractServiceComponent"/> + <reference name="multiplyService" target="MultiplyServiceComponent"/> + <reference name="divideService" target="DivideServiceComponent"/> + </component> + + <component name="AddServiceComponent"> + <implementation.java class="calculator.AddServiceImpl"/> + </component> + + <component name="SubtractServiceComponent"> + <implementation.java class="calculator.SubtractServiceImpl"/> + </component> + + <component name="MultiplyServiceComponent"> + <implementation.java class="calculator.MultiplyServiceImpl"/> + </component> + + <component name="DivideServiceComponent"> + <implementation.java class="calculator.DivideServiceImpl"/> + </component> + +</composite> diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/CalculatorImpl.componentType b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/CalculatorImpl.componentType new file mode 100644 index 0000000000..b86683b79a --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/CalculatorImpl.componentType @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + * 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. +--> +<componentType xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" + xmlns:wsdli="http://www.w3.org/2004/08/wsdl-instance"> + + <service name="CalculatorService"> + <interface.wsdl interface="http://sample/calculator#wsdl.interface(Calculator)"/> + <binding.ws uri="http://localhost:8085/Calculator" wsdlElement="http://sample/calculator#wsdl.service(CalculatorService)"/> + <binding.ws wsdli:wsdlLocation="http://tempuri.org" wsdlElement="http://sample/calculator#wsdl.binding(CalculatorBinding)"/> + <binding.ws wsdlElement="http://sample/calculator#wsdl.port(CalculatorService/CalculatorPort)"/> + <binding.ws wsdlElement="http://sample/calculator#wsdl.endpoint(CalculatorService/CalculatorEndpoint)"/> + </service> + + <reference name="divideService"> + <interface.wsdl interface="http://sample/calculator#wsdl.interface(Divide)"/> + <binding.ws uri="tempuri.org" wsdlElement="http://sample/calculator#wsdl.service(DivideService)"/> + <binding.ws uri="tempuri.org" wsdlElement="http://sample/calculator#wsdl.binding(DivideBinding)"/> + <binding.ws uri="tempuri.org" wsdlElement="http://sample/calculator#wsdl.port(DivideService/DividePort)"/> + <binding.ws uri="tempuri.org" wsdlElement="http://sample/calculator#wsdl.endpoint(DivideService/DivideEndpoint)"/> + <binding.ws> + <wsa:EndpointReference xmlns:wsa="http://www.w3.org/2005/08/addressing"> + <wsa:Address>myURI</wsa:Address> + </wsa:EndpointReference> + </binding.ws> + </reference> + +</componentType> +
\ No newline at end of file diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/PoliciedCalculator.composite b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/PoliciedCalculator.composite new file mode 100644 index 0000000000..1b6423be1d --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/PoliciedCalculator.composite @@ -0,0 +1,60 @@ +<?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. +--> +<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" + xmlns:calc="http://sample.calculator" + targetNamespace="http://calc" + xmlns:wsdli="http://www.w3.org/2004/08/wsdl-instance" + name="Calculator"> + + <service name="CalculatorService" promote="CalculatorServiceComponent"> + <interface.wsdl interface="http://sample/calculator#wsdl.interface(Calculator)"/> + <binding.ws uri="http://localhost:8085/Calculator" wsdlElement="http://sample/calculator#wsdl.service(CalculatorService)"> + <operation name="add" requires="IntentOne IntentTwo"/> + </binding.ws> + <binding.ws wsdli:wsdlLocation="http://tempuri.org" wsdlElement="http://sample/calculator#wsdl.binding(CalculatorBinding)"/> + <binding.ws wsdlElement="http://sample/calculator#wsdl.port(CalculatorService/CalculatorPort)"/> + <binding.ws wsdlElement="http://sample/calculator#wsdl.endpoint(CalculatorService/CalculatorEndpoint)"/> + </service> + + <component name="CalculatorServiceComponent"> + <implementation.java class="calculator.CalculatorServiceImpl"/> + <reference name="addService" target="AddServiceComponent"/> + <reference name="subtractService" target="SubtractServiceComponent"/> + <reference name="multiplyService" target="MultiplyServiceComponent"/> + <reference name="divideService" target="DivideServiceComponent"/> + </component> + + <component name="AddServiceComponent"> + <implementation.java class="calculator.AddServiceImpl"/> + </component> + + <component name="SubtractServiceComponent"> + <implementation.java class="calculator.SubtractServiceImpl"/> + </component> + + <component name="MultiplyServiceComponent"> + <implementation.java class="calculator.MultiplyServiceImpl"/> + </component> + + <component name="DivideServiceComponent"> + <implementation.java class="calculator.DivideServiceImpl"/> + </component> + +</composite> diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/example.wsdl b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/example.wsdl new file mode 100644 index 0000000000..5e8e5dad0d --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/example.wsdl @@ -0,0 +1,26 @@ +<?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. +--> +<wsdl:definitions targetNamespace="http://www.example.org" + xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" + name="example"> + + <wsdl:portType name="HelloWorld"> + </wsdl:portType> +</wsdl:definitions> diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/invalid-stockquote.wsdl b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/invalid-stockquote.wsdl new file mode 100644 index 0000000000..ad81fc7867 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/invalid-stockquote.wsdl @@ -0,0 +1,58 @@ +<?xml version="1.0"?> +<!-- + * 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. +--> +<definitions name="StockQuote" targetNamespace="http://example.com/stockquote.wsdl" + xmlns:tns="http://example.com/stockquote.wsdl" xmlns:xsd1="http://example.com/stockquote.xsd" + xmlns="http://schemas.xmlsoap.org/wsdl/"> + + <types> + <schema targetNamespace="http://example.com/stockquote.xsd" xmlns="http://www.w3.org/2001/XMLSchema"> + <element name="getLastTradePrice1"> + <complexType> + <sequence> + <element name="tickerSymbol" type="string" /> + </sequence> + </complexType> + </element> + <element name="getLastTradePriceResponse"> + <complexType> + <sequence> + <element name="price" type="float" /> + </sequence> + </complexType> + </element> + </schema> + </types> + + <message name="GetLastTradePriceInput"> + <part name="body" element="xsd1:getLastTradePrice" /> + </message> + + <message name="GetLastTradePriceOutput"> + <part name="body" element="xsd1:getLastTradePriceResponse" /> + </message> + + <portType name="StockQuotePortType"> + <operation name="getLastTradePrice"> + <input message="tns:GetLastTradePriceInput" /> + <output message="tns:GetLastTradePriceOutput" /> + </operation> + </portType> + +</definitions>
\ No newline at end of file diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/ipo.xsd b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/ipo.xsd new file mode 100644 index 0000000000..241ec15d36 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/ipo.xsd @@ -0,0 +1,136 @@ +<!-- + * 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. +--> +<schema targetNamespace="http://www.example.com/IPO" + xmlns="http://www.w3.org/2001/XMLSchema" + xmlns:ipo="http://www.example.com/IPO"> + + <annotation> + <documentation xml:lang="en"> + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + </documentation> + </annotation> + + + <element name="purchaseOrder" type="ipo:PurchaseOrderType" /> + + <element name="comment" type="string" /> + + <complexType name="PurchaseOrderType"> + <sequence> + <element name="shipTo" type="ipo:Address" /> + <element name="billTo" type="ipo:Address" /> + <element ref="ipo:comment" minOccurs="0" /> + <element name="items" type="ipo:Items" /> + </sequence> + <attribute name="orderDate" type="date" /> + </complexType> + + <complexType name="Items"> + <sequence> + <element name="item" minOccurs="0" maxOccurs="unbounded"> + <complexType> + <sequence> + <element name="productName" type="string" /> + <element name="quantity"> + <simpleType> + <restriction base="positiveInteger"> + <maxExclusive value="100" /> + </restriction> + </simpleType> + </element> + <element name="USPrice" type="decimal" /> + <element ref="ipo:comment" minOccurs="0" /> + <element name="shipDate" type="date" + minOccurs="0" /> + </sequence> + <attribute name="partNum" type="ipo:SKU" + use="required" /> + </complexType> + </element> + </sequence> + </complexType> + + <simpleType name="SKU"> + <restriction base="string"> + <pattern value="\d{3}-[A-Z]{2}" /> + </restriction> + </simpleType> + + <complexType name="Address"> + <sequence> + <element name="name" type="string" /> + <element name="street" type="string" /> + <element name="city" type="string" /> + </sequence> + </complexType> + + <complexType name="USAddress"> + <complexContent> + <extension base="ipo:Address"> + <sequence> + <element name="state" type="ipo:USState" /> + <element name="zip" type="positiveInteger" /> + </sequence> + </extension> + </complexContent> + </complexType> + + <complexType name="UKAddress"> + <complexContent> + <extension base="ipo:Address"> + <sequence> + <element name="postcode" type="ipo:UKPostcode" /> + </sequence> + <attribute name="exportCode" type="positiveInteger" + fixed="1" /> + </extension> + </complexContent> + </complexType> + + <!-- other Address derivations for more countries --> + + <simpleType name="USState"> + <restriction base="string"> + <enumeration value="AK" /> + <enumeration value="AL" /> + <enumeration value="AR" /> + <enumeration value="CA" /> + <enumeration value="PA" /> + <!-- and so on ... --> + </restriction> + </simpleType> + + <simpleType name="Postcode"> + <restriction base="string"> + <length value="7" fixed="true" /> + </restriction> + </simpleType> + + + <simpleType name="UKPostcode"> + <restriction base="ipo:Postcode"> + <pattern value="[A-Z]{2}\d\s\d[A-Z]{2}" /> + </restriction> + </simpleType> + + + +</schema> + diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/stockquote.wsdl b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/stockquote.wsdl new file mode 100644 index 0000000000..39cd5547d9 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/stockquote.wsdl @@ -0,0 +1,58 @@ +<?xml version="1.0"?> +<!-- + * 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. +--> +<definitions name="StockQuote" targetNamespace="http://example.com/stockquote.wsdl" + xmlns:tns="http://example.com/stockquote.wsdl" xmlns:xsd1="http://example.com/stockquote.xsd" + xmlns="http://schemas.xmlsoap.org/wsdl/"> + + <types> + <schema targetNamespace="http://example.com/stockquote.xsd" xmlns="http://www.w3.org/2001/XMLSchema"> + <element name="getLastTradePrice"> + <complexType> + <sequence> + <element name="tickerSymbol" type="string" /> + </sequence> + </complexType> + </element> + <element name="getLastTradePriceResponse"> + <complexType> + <sequence> + <element name="price" type="float" /> + </sequence> + </complexType> + </element> + </schema> + </types> + + <message name="GetLastTradePriceInput"> + <part name="body" element="xsd1:getLastTradePrice" /> + </message> + + <message name="GetLastTradePriceOutput"> + <part name="body" element="xsd1:getLastTradePriceResponse" /> + </message> + + <portType name="StockQuotePortType"> + <operation name="getLastTradePrice"> + <input message="tns:GetLastTradePriceInput" /> + <output message="tns:GetLastTradePriceOutput" /> + </operation> + </portType> + +</definitions>
\ No newline at end of file diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.wsdl b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.wsdl new file mode 100644 index 0000000000..d53104b0ca --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.wsdl @@ -0,0 +1,45 @@ +<?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. +--> +<wsdl:definitions targetNamespace="http://helloworld" xmlns:tns="http://helloworld" + xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="helloworld"> + + <wsdl:import location="test2.wsdl" namespace="http://helloworld"></wsdl:import> + + <wsdl:binding name="HelloWorldSoapBinding" type="tns:HelloWorld"> + <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> + <wsdl:operation name="getGreetings"> + <wsdlsoap:operation soapAction="" /> + <wsdl:input name="getGreetingsRequest"> + <wsdlsoap:body use="literal" /> + </wsdl:input> + <wsdl:output name="getGreetingsResponse"> + <wsdlsoap:body use="literal" /> + </wsdl:output> + </wsdl:operation> + </wsdl:binding> + + <wsdl:service name="HelloWorldService"> + <wsdl:port binding="tns:HelloWorldSoapBinding" name="HelloWorldSoapPort"> + <wsdlsoap:address location="http://localhost:8085/sample-helloworldws/services/HelloWorldWebService" /> + </wsdl:port> + </wsdl:service> + +</wsdl:definitions> diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.xsd b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.xsd new file mode 100644 index 0000000000..c2210f4a94 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.xsd @@ -0,0 +1,33 @@ +<!-- + * 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. +--> +<schema targetNamespace="http://www.example.com/Customer" xmlns="http://www.w3.org/2001/XMLSchema" + xmlns:ipo="http://www.example.com/IPO" xmlns:tns="http://www.example.com/Customer"> + <import namespace="http://www.example.com/IPO" schemaLocation="ipo.xsd" /> + + <complexType name="Customer"> + <sequence> + <element name="customerID" type="string"></element> + <element name="name" type="string"></element> + <element name="order" type="ipo:PurchaseOrderType" /> + </sequence> + </complexType> + <element name="customer" type="tns:Customer"></element> + +</schema> + diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test2.wsdl b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test2.wsdl new file mode 100644 index 0000000000..529b395fd5 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test2.wsdl @@ -0,0 +1,63 @@ +<?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. +--> +<wsdl:definitions targetNamespace="http://helloworld" xmlns:tns="http://helloworld" + xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="helloworld"> + + <wsdl:types> + <schema elementFormDefault="qualified" targetNamespace="http://helloworld" xmlns="http://www.w3.org/2001/XMLSchema"> + + <import namespace="http://www.example.com/IPO" schemaLocation="ipo.xsd" /> + + <element name="getGreetings"> + <complexType> + <sequence> + <element name="name" type="xsd:string" /> + </sequence> + </complexType> + </element> + + <element name="getGreetingsResponse"> + <complexType> + <sequence> + <element name="getGreetingsReturn" type="xsd:string" /> + </sequence> + </complexType> + </element> + + </schema> + </wsdl:types> + + <wsdl:message name="getGreetingsRequest"> + <wsdl:part element="tns:getGreetings" name="parameters" /> + </wsdl:message> + + <wsdl:message name="getGreetingsResponse"> + <wsdl:part element="tns:getGreetingsResponse" name="parameters" /> + </wsdl:message> + + <wsdl:portType name="HelloWorld"> + <wsdl:operation name="getGreetings"> + <wsdl:input message="tns:getGreetingsRequest" name="getGreetingsRequest" /> + <wsdl:output message="tns:getGreetingsResponse" name="getGreetingsResponse" /> + </wsdl:operation> + </wsdl:portType> + +</wsdl:definitions> diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/unwrapped-stockquote.wsdl b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/unwrapped-stockquote.wsdl new file mode 100644 index 0000000000..666a7e4069 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/binding-ws/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/unwrapped-stockquote.wsdl @@ -0,0 +1,76 @@ +<?xml version="1.0"?> +<!-- + * 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. +--> +<definitions name="StockQuote" targetNamespace="http://example.com/stockquote.wsdl" + xmlns:tns="http://example.com/stockquote.wsdl" xmlns:xsd1="http://example.com/stockquote.xsd" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns="http://schemas.xmlsoap.org/wsdl/"> + + <types> + <schema targetNamespace="http://example.com/stockquote.xsd" xmlns="http://www.w3.org/2001/XMLSchema"> + <element name="getLastTradePrice"> + <complexType> + <sequence> + <element name="tickerSymbol" type="string" /> + </sequence> + </complexType> + </element> + <element name="getLastTradePriceResponse"> + <complexType> + <sequence> + <element name="price" type="float" /> + </sequence> + </complexType> + </element> + </schema> + </types> + + <message name="GetLastTradePriceInput1"> + <part name="body" element="xsd1:getLastTradePrice" /> + </message> + + <message name="GetLastTradePriceOutput1"> + <part name="body" element="xsd1:getLastTradePriceResponse" /> + </message> + + <message name="GetLastTradePriceInput2"> + <part name="body" element="xsd1:getLastTradePrice" /> + <part name="other" type="xsd:string"/> + </message> + + <message name="GetLastTradePriceOutput2"> + <part name="body" element="xsd1:getLastTradePriceResponse" /> + </message> + + <portType name="StockQuotePortType"> + <operation name="getLastTradePrice"> + <input message="tns:GetLastTradePriceInput1" /> + <output message="tns:GetLastTradePriceOutput1" /> + </operation> + <operation name="getLastTradePrice1"> + <input message="tns:GetLastTradePriceInput1" /> + <output message="tns:GetLastTradePriceOutput1" /> + </operation> + <operation name="getLastTradePrice2"> + <input message="tns:GetLastTradePriceInput2" /> + <output message="tns:GetLastTradePriceOutput2" /> + </operation> + </portType> + +</definitions>
\ No newline at end of file |