summaryrefslogtreecommitdiffstats
path: root/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/sebastien/java/wrapped/modules/binding-jms-runtime')
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/LICENSE205
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/META-INF/MANIFEST.MF46
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/NOTICE6
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/pom.xml85
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/context/JMSBindingContext.java141
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderReferenceInterceptor.java198
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderServiceInterceptor.java118
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/AsyncResponseJMSServiceListener.java272
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSHostExtensionPoint.java40
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListener.java283
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListenerFactory.java55
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultServiceInvoker.java112
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSAsyncResponseInvoker.java98
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSHostExtensionPoint.java27
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSServiceListener.java29
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSServiceListenerDetails.java37
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSServiceListenerFactory.java27
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultProviderFactory.java60
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceInterceptor.java206
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceProvider.java53
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropProviderFactory.java56
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceInterceptor.java115
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceProvider.java47
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationPolicyProviderFactory.java74
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationReferencePolicyInterceptor.java104
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationReferencePolicyProvider.java57
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationServicePolicyInterceptor.java106
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationServicePolicyProvider.java57
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/provider/JMSHeaderPolicyProviderFactory.java83
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/provider/JMSHeaderReferencePolicyInterceptor.java88
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/provider/JMSHeaderReferencePolicyProvider.java58
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/AbstractMessageProcessor.java161
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/BytesMessageProcessor.java120
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultJMSResourceFactoryExtensionPoint.java30
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultMessageProcessor.java302
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingAsyncResponseInvoker.java43
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingProviderFactory.java76
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java219
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java265
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessor.java55
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorUtil.java113
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactory.java99
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryExtensionPoint.java28
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java359
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java231
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingInvoker.java357
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/TextMessageProcessor.java80
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLBytesMessageProcessor.java136
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLTextMessageProcessor.java132
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportReferenceInterceptor.java187
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java284
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/AsyncResponseDestinationInterceptor.java194
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java131
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/OperationPropertiesInterceptor.java77
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesProviderFactory.java60
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceInterceptor.java133
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceProvider.java92
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceInterceptor.java125
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceProvider.java96
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLProviderFactory.java64
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceInterceptor.java133
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceProvider.java100
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceInterceptor.java119
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceProvider.java108
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultProviderFactory.java66
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceInterceptor.java184
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceProvider.java204
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceInterceptor.java200
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceProvider.java198
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectProviderFactory.java60
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java152
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceProvider.java113
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceInterceptor.java149
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceProvider.java119
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextProviderFactory.java60
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceInterceptor.java134
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceProvider.java101
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceInterceptor.java125
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceProvider.java103
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLProviderFactory.java66
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceInterceptor.java139
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceProvider.java113
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceInterceptor.java126
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceProvider.java108
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory20
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory21
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory19
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory25
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldClientImpl.java43
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldService.java31
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldServiceImpl.java32
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/OperationSelectionTestCaseFIXME.java229
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/resources/simple/client.composite38
-rw-r--r--sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/resources/simple/service.composite35
94 files changed, 10665 insertions, 0 deletions
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/LICENSE b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/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/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/META-INF/MANIFEST.MF b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..985d99f457
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/META-INF/MANIFEST.MF
@@ -0,0 +1,46 @@
+Manifest-Version: 1.0
+SCA-Version: 1.1
+Bundle-Name: Apache Tuscany SCA JMS Binding Runtime
+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 JMS Binding Runtime
+Import-Package: javax.jms,
+ javax.naming,
+ javax.resource.spi,
+ javax.security.auth,
+ javax.xml.namespace,
+ javax.xml.stream,
+ org.apache.activemq.jndi;resolution:=optional,
+ org.apache.axiom.om,
+ org.apache.axiom.om.impl.builder,
+ org.apache.tuscany.sca.assembly;version="2.0.0",
+ org.apache.tuscany.sca.binding.jms;version="2.0.0",
+ org.apache.tuscany.sca.binding.jms.operationselector;version="2.0.0",
+ org.apache.tuscany.sca.binding.jms.policy.authentication.token;version="2.0.0",
+ org.apache.tuscany.sca.binding.jms.policy.header;version="2.0.0",
+ org.apache.tuscany.sca.binding.jms.wireformat;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.common.xml.dom;version="2.0.0",
+ org.apache.tuscany.sca.core;version="2.0.0",
+ org.apache.tuscany.sca.core.invocation;version="2.0.0",
+ org.apache.tuscany.sca.databinding.xml;version="2.0.0",
+ org.apache.tuscany.sca.extensibility;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.util;version="2.0.0",
+ org.apache.tuscany.sca.invocation;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.policy.authentication.token;version="2.0.0",
+ org.apache.tuscany.sca.policy.security;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.work;version="2.0.0",
+ org.oasisopen.sca;version="2.0.0",
+ org.oasisopen.sca.annotation;version="2.0.0"
+Bundle-SymbolicName: org.apache.tuscany.sca.binding.jms.runtime
+Bundle-DocURL: http://www.apache.org/
+Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/NOTICE b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/pom.xml b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/pom.xml
new file mode 100644
index 0000000000..5cdfb78d3e
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/pom.xml
@@ -0,0 +1,85 @@
+<?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-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-binding-jms-runtime</artifactId>
+ <name>Apache Tuscany SCA JMS Binding Runtime</name>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-base-runtime-pom</artifactId>
+ <type>pom</type>
+ <version>2.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-binding-jms</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ <scope>provided</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>
+
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-j2ee-connector_1.5_spec</artifactId>
+ <version>2.0.0</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Add the dependency for ActiveMQ as the JMS runtime to use -->
+ <!-- TODO - why is this here and not in the ActiveMQ specific module?-->
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-core</artifactId>
+ <version>5.3.0</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <!-- end of addition for ActiveMQ -->
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/context/JMSBindingContext.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/context/JMSBindingContext.java
new file mode 100644
index 0000000000..e38a9d0c60
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/context/JMSBindingContext.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.jms.context;
+
+import javax.jms.Destination;
+import javax.jms.Message;
+import javax.jms.Session;
+
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+
+
+/**
+ * Context that the JMS binding puts on the Tuscany wire
+ *
+ * @version $Rev$ $Date$
+ */
+public class JMSBindingContext {
+
+ private Message jmsMsg;
+ private Session jmsSession;
+ private Session jmsResponseSession;
+ private Destination requestDestination;
+ private Destination replyToDestination;
+ private JMSResourceFactory jmsResourceFactory;
+ private long timeToLive;
+ private boolean useBytesForWFJMSDefaultResponse;
+
+ public Message getJmsMsg() {
+ return jmsMsg;
+ }
+
+ public void setJmsMsg(Message jmsMsg) {
+ this.jmsMsg = jmsMsg;
+ }
+
+ public synchronized Session getJmsSession() {
+ if (jmsSession == null) {
+ try {
+ jmsSession = getJmsResourceFactory().createSession();
+ } catch (Exception e) {
+ throw new JMSBindingException(e);
+ }
+ }
+ return jmsSession;
+ }
+
+ public synchronized void closeJmsSession() {
+ if (jmsSession != null) {
+ try {
+ getJmsResourceFactory().closeSession(jmsSession);
+ } catch (Exception e) {
+ throw new JMSBindingException(e);
+ } finally {
+ jmsSession = null;
+ }
+ }
+ }
+
+ public synchronized Session getJmsResponseSession() {
+ if (jmsResponseSession == null) {
+ try {
+ jmsResponseSession = getJmsResourceFactory().createResponseSession();
+ } catch (Exception e) {
+ throw new JMSBindingException(e);
+ }
+ }
+ return jmsResponseSession;
+ }
+
+ public synchronized void closeJmsResponseSession() {
+ if (jmsResponseSession != null) {
+ try {
+ getJmsResourceFactory().closeResponseSession(jmsResponseSession);
+ } catch (Exception e) {
+ throw new JMSBindingException(e);
+ } finally {
+ jmsResponseSession = null;
+ }
+ }
+ }
+
+ public Destination getRequestDestination() {
+ return requestDestination;
+ }
+
+ public void setRequestDestination(Destination requestDestination) {
+ this.requestDestination = requestDestination;
+ }
+
+ public Destination getReplyToDestination() {
+ return replyToDestination;
+ }
+
+ public void setReplyToDestination(Destination replyToDestination) {
+ this.replyToDestination = replyToDestination;
+ }
+
+ // TODO - difficult to get the resource factory into all the JMS providers
+ // so it's here for the moment
+ public JMSResourceFactory getJmsResourceFactory() {
+ return jmsResourceFactory;
+ }
+
+ public void setJmsResourceFactory(JMSResourceFactory jmsResourceFactory) {
+ this.jmsResourceFactory = jmsResourceFactory;
+ }
+
+ public long getTimeToLive() {
+ return timeToLive;
+ }
+
+ public void setTimeToLive(long timeToLive) {
+ this.timeToLive = timeToLive;
+ }
+
+ public boolean isUseBytesForWFJMSDefaultResponse() {
+ return useBytesForWFJMSDefaultResponse;
+ }
+
+ public void setUseBytesForWFJMSDefaultResponse(
+ boolean useBytesForWFJMSDefaultResponse) {
+ this.useBytesForWFJMSDefaultResponse = useBytesForWFJMSDefaultResponse;
+ }
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderReferenceInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderReferenceInterceptor.java
new file mode 100644
index 0000000000..87c6ddd08b
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderReferenceInterceptor.java
@@ -0,0 +1,198 @@
+/*
+ * 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.jms.headers;
+
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.jms.DeliveryMode;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.naming.NamingException;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.provider.JMSBindingServiceBindingProvider;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class HeaderReferenceInterceptor extends InterceptorAsyncImpl {
+
+ private RuntimeEndpointReference runtimeWire;
+ private JMSBinding jmsBinding;
+ private JMSMessageProcessor requestMessageProcessor;
+ private List<Operation> operations;
+
+
+ public HeaderReferenceInterceptor(ExtensionPointRegistry extensions, JMSBinding jmsBinding,
+ JMSResourceFactory jmsResourceFactory, RuntimeEndpointReference runtimeWire) {
+ super();
+ this.jmsBinding = jmsBinding;
+ this.runtimeWire = runtimeWire;
+ this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(extensions, jmsBinding);
+ this.operations = runtimeWire.getReference().getInterfaceContract().getInterface().getOperations();
+ } // end constructor
+
+ public Message invoke(Message msg) {
+ return next.invoke(invokeRequest(msg));
+ } // end method invoke
+
+ public Message invokeRequest(Message tuscanyMsg) {
+ try {
+ // Get the JMS context
+ JMSBindingContext context = tuscanyMsg.getBindingContext();
+ javax.jms.Message jmsMsg = tuscanyMsg.getBody();
+
+ Operation operation = tuscanyMsg.getOperation();
+ String operationName = operation.getName();
+ RuntimeEndpointReference reference = runtimeWire;
+
+ // OASIS spec suggests we do not need to do anything with
+ // @nativeOperation here on the reference side.
+ requestMessageProcessor.setOperationName(operationName, jmsMsg);
+
+ if (jmsBinding.getEffectiveJMSDeliveryMode(operationName) != null) {
+ if (jmsBinding.getEffectiveJMSDeliveryMode(operationName)) {
+ jmsMsg.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
+ } else {
+ jmsMsg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ }
+ }
+
+ if (jmsBinding.getEffectiveJMSPriority(operationName) != null) {
+ jmsMsg.setJMSPriority(jmsBinding.getEffectiveJMSPriority(operationName));
+ }
+
+ if ( jmsBinding.getEffectiveJMSType(operationName) != null ) {
+ jmsMsg.setJMSType(jmsBinding.getEffectiveJMSType(operationName));
+ }
+
+ if ( jmsBinding.getEffectiveJMSTimeToLive(operationName) != null ) {
+ jmsMsg.setJMSExpiration(jmsBinding.getEffectiveJMSTimeToLive(operationName));
+ }
+
+ if (jmsBinding.getOperationJMSCorrelationId(operationName) != null) {
+ jmsMsg.setJMSCorrelationID(jmsBinding.getOperationJMSCorrelationId(operationName));
+ } else if (JMSBindingConstants.CORRELATE_CORRELATION_ID.equals(jmsBinding.getCorrelationScheme())) {
+ jmsMsg.setJMSCorrelationID(UUID.randomUUID().toString());
+ }
+
+ if (tuscanyMsg.getFrom().getCallbackEndpoint() != null) {
+
+ String callbackDestName = getCallbackDestinationName(reference);
+ if (callbackDestName != null) {
+ jmsMsg.setStringProperty(JMSBindingConstants.CALLBACK_Q_PROPERTY, "jms:jndi:" + callbackDestName);
+ if (operation.isNonBlocking()) {
+ Destination dest = context.getJmsResourceFactory().lookupDestination(callbackDestName);
+ jmsMsg.setJMSReplyTo(dest);
+ }
+ }
+ }
+
+ for (String propName : jmsBinding.getPropertyNames()) {
+ Object value = jmsBinding.getProperty(propName);
+ jmsMsg.setObjectProperty(propName, value);
+ }
+
+ Map<String, Object> operationProperties = jmsBinding.getOperationProperties(operationName);
+ if (operationProperties != null) {
+ for (String propName : operationProperties.keySet()) {
+ Object value = operationProperties.get(propName);
+ jmsMsg.setObjectProperty(propName, value);
+ }
+ }
+
+ if (jmsBinding.getEffectiveJMSTimeToLive(operationName) != null) {
+ context.setTimeToLive(jmsBinding.getEffectiveJMSTimeToLive(operationName) * 2);
+ } else {
+ context.setTimeToLive(JMSBindingConstants.DEFAULT_TIME_TO_LIVE);
+ }
+
+ // Adding MESSAGE_ID field to the JMS message, which is used to correlate async callbacks
+ String msgID = (String)tuscanyMsg.getHeaders().get("MESSAGE_ID");
+ if( msgID != null ) {
+ jmsMsg.setObjectProperty("MESSAGE_ID", msgID);
+ } // end if
+ //
+
+ return tuscanyMsg;
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ } catch (NamingException e) {
+ throw new JMSBindingException(e);
+ }
+ } // end method invokeRequest
+
+ protected String getCallbackDestinationName(RuntimeEndpointReference reference) {
+ RuntimeEndpoint endpoint = (RuntimeEndpoint) reference.getCallbackEndpoint();
+ if (endpoint != null) {
+ JMSBindingServiceBindingProvider bp = (JMSBindingServiceBindingProvider)endpoint.getBindingProvider();
+ return bp.getDestinationName();
+ }
+ return null;
+ }
+
+ public Message processRequest(Message msg) {
+ return invokeRequest(msg);
+ } // end method processRequest
+
+ public Message processResponse(Message msg) {
+ // When the response message arrives, there may be information about the
+ // operation and the related request message ID in the headers - extract it into the
+ // Tuscany message
+
+ javax.jms.Message responseMsg = msg.getBody();
+ try {
+ // Operation name...
+ String operationName = responseMsg.getStringProperty("scaOperationName");
+ for( Operation op : operations ) {
+ if( operationName.equals(op.getName())) {
+ msg.setOperation(op);
+ break;
+ } // end if
+ } // end for
+
+ // Relates to header...
+ String relatesTo = responseMsg.getStringProperty("RELATES_TO");
+ if( relatesTo != null ) {
+ msg.getHeaders().put("RELATES_TO", relatesTo);
+ } // end if
+ } catch (JMSException e) {
+ // TODO Auto-generated catch block
+ } // end try
+ return msg;
+ } // end method processResponse
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderServiceInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderServiceInterceptor.java
new file mode 100644
index 0000000000..6dac182d9a
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderServiceInterceptor.java
@@ -0,0 +1,118 @@
+/*
+ * 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.jms.headers;
+
+import java.util.Map;
+
+import javax.jms.JMSException;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+
+public class HeaderServiceInterceptor extends InterceptorAsyncImpl {
+
+ private Invoker next;
+ private JMSBinding jmsBinding;
+
+ public HeaderServiceInterceptor(JMSBinding jmsBinding) {
+ super();
+ this.jmsBinding = jmsBinding;
+ }
+
+ public Message invoke(Message msg) {
+ msg = invokeRequest( msg );
+ return invokeResponse(next.invoke(msg));
+ }
+
+ public Message invokeRequest(Message tuscanyMsg) {
+
+ try {
+
+ javax.jms.Message jmsMsg = tuscanyMsg.getBody();
+
+ // Handle MESSAGE_ID field of the JMS message, which is used to correlate async callbacks
+ String msgID = (String)jmsMsg.getObjectProperty("MESSAGE_ID");
+ if( msgID != null ) {
+ tuscanyMsg.getHeaders().put("MESSAGE_ID", msgID);
+ } // end if
+ //
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ } // end try
+
+ return tuscanyMsg;
+ } // end method invokeRequest
+
+ public Message invokeResponse(Message tuscanyMsg) {
+ try {
+
+ javax.jms.Message jmsMsg = tuscanyMsg.getBody();
+
+ Operation operation = tuscanyMsg.getOperation();
+ String operationName = operation.getName();
+
+ for (String propName : jmsBinding.getPropertyNames()) {
+ Object value = jmsBinding.getProperty(propName);
+ jmsMsg.setObjectProperty(propName, value);
+ } // end for
+
+ Map<String, Object> operationProperties = jmsBinding.getOperationProperties(operationName);
+ if (operationProperties != null) {
+ for (String propName : operationProperties.keySet()) {
+ Object value = operationProperties.get(propName);
+ jmsMsg.setObjectProperty(propName, value);
+ } // end for
+ } // end if
+
+ // Put a "RELATES_TO" property into the response message
+ String relatesTo = (String)tuscanyMsg.getHeaders().get("RELATES_TO");
+ if( relatesTo != null ) {
+ jmsMsg.setStringProperty("RELATES_TO", relatesTo);
+ } // end if
+
+ return tuscanyMsg;
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ } // end try
+ } // end method invokeResponse
+
+ public Invoker getNext() {
+ return next;
+ } // end method getNext
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Message processRequest(Message msg) {
+ return invokeRequest(msg);
+ } // end method processRequest
+
+ public Message processResponse(Message msg) {
+ return invokeResponse(msg);
+ } // end method processResponse
+
+} // end class
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/AsyncResponseJMSServiceListener.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/AsyncResponseJMSServiceListener.java
new file mode 100644
index 0000000000..1aa316f81b
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/AsyncResponseJMSServiceListener.java
@@ -0,0 +1,272 @@
+/*
+ * 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.jms.host;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.naming.NamingException;
+import javax.resource.spi.ActivationSpec;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.work.WorkScheduler;
+
+/**
+ * Implementation of a JMS response queue handler for async responses
+ *
+ * @version $Rev$ $Date$
+ */
+public class AsyncResponseJMSServiceListener implements JMSServiceListener {
+ private static final Logger logger = Logger.getLogger(AsyncResponseJMSServiceListener.class.getName());
+
+ private MessageListener listener;
+ private String serviceName;
+ private JMSBinding jmsBinding;
+ private WorkScheduler workScheduler;
+
+ private JMSResourceFactory jmsResourceFactory;
+ private MessageConsumer consumer;
+ private boolean running;
+
+ private Destination destination;
+
+ public AsyncResponseJMSServiceListener(MessageListener listener, String serviceName,
+ JMSBinding jmsBinding, WorkScheduler workScheduler, JMSResourceFactory rf) {
+ this.listener = listener;
+ this.serviceName = serviceName;
+ this.jmsBinding = jmsBinding;
+ this.workScheduler = workScheduler;
+ this.jmsResourceFactory = rf;
+ }
+
+ public void start() {
+ this.running = true;
+
+ try {
+ registerListener();
+ } catch (Exception e) {
+ if (e instanceof JMSBindingException) throw (JMSBindingException)e;
+ throw new JMSBindingException("Error starting JMSAsyncResponse endpoint", e);
+ }
+ } // end start
+
+ public void stop() {
+ this.running = false;
+ try {
+ consumer.close();
+ jmsResourceFactory.closeConnection();
+ jmsResourceFactory.closeResponseConnection();
+ } catch (Exception e) {
+ // if using an embedded broker then when shutting down Tuscany the broker may get closed
+ // before this stop method is called. I can't see how to detect that so for now just
+ // ignore the exception if the message is that the transport is already disposed
+ if ((e.getMessage() == null) || !e.getMessage().contains("disposed")) {
+ throw new JMSBindingException("Error stopping JMSServiceBinding", e);
+ }
+ }
+ } // end stop
+
+ private void registerListener() throws NamingException, JMSException {
+
+ Session session = jmsResourceFactory.createSession();
+ lookupActivationSpec();
+ destination = lookupQueue( jmsBinding.getResponseDestinationName() );
+ if (destination == null) {
+ throw new JMSBindingException("Unable to create Async Response queue");
+ } // end if
+
+ if (jmsBinding.getJMSSelector() != null) {
+ consumer = session.createConsumer(destination, jmsBinding.getJMSSelector());
+ } else {
+ consumer = session.createConsumer(destination);
+ } // end if
+
+ try {
+
+ consumer.setMessageListener(listener);
+ jmsResourceFactory.startConnection();
+
+ } catch (javax.jms.JMSException e) {
+
+ // setMessageListener not allowed in JEE container so use Tuscany threads
+
+ jmsResourceFactory.startConnection();
+ workScheduler.scheduleWork(new Runnable() {
+ public void run() {
+ try {
+ while (running) {
+ final Message msg = consumer.receive();
+ workScheduler.scheduleWork(new Runnable() {
+ public void run() {
+ try {
+ listener.onMessage(msg);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } // end try
+ } // end method run
+ });
+ } // end while
+ } catch (Exception e) {
+ e.printStackTrace();
+ } // end try
+ } // end method run
+ });
+ } // end try
+ logger.log(Level.INFO, "JMS AsyncResponse handler '"
+ + serviceName
+ + "' listening on destination "
+ + ((destination instanceof Queue) ? ((Queue)destination).getQueueName() : ((Topic)destination).getTopicName()));
+ } // end method registerListener
+
+ // Stub code for ActivationSpec support that throws appropriate errors
+ private void lookupActivationSpec() {
+ if ( jmsBinding.getActivationSpecName() != null ) {
+ String createMode = jmsBinding.getActivationSpecCreate();
+ if ( JMSBindingConstants.CREATE_ALWAYS.equals(createMode) ) {
+ ActivationSpec spec = jmsResourceFactory.lookupActivationSpec(jmsBinding.getActivationSpecName());
+ if ( spec != null ) {
+ throw new JMSBindingException("ActivationSpec specifies create mode of \"always\" but resource already exists.");
+ }
+ throw new JMSBindingException("Can not create ActivationSpec");
+ } else if ( JMSBindingConstants.CREATE_IF_NOT_EXIST.equals(createMode)) {
+ ActivationSpec spec = jmsResourceFactory.lookupActivationSpec(jmsBinding.getActivationSpecName());
+ if ( spec == null ) {
+ throw new JMSBindingException("Can not create ActivationSpec");
+ }
+ } else if ( JMSBindingConstants.CREATE_NEVER.equals(createMode)) {
+ ActivationSpec spec = jmsResourceFactory.lookupActivationSpec(jmsBinding.getActivationSpecName());
+ if ( spec == null )
+ throw new JMSBindingException("ActivationSpec specifies create mode of \"never\" but resource does not exist at jndiName " + jmsBinding.getActivationSpecName());
+
+ } // end if
+ } // end if
+ } // end method lookupActivationSpec
+
+ /**
+ * Looks up the Async Response Queue for the JMS Binding.
+ * <p>
+ * What happens in the look up will depend on the create mode specified for the JMS Binding:
+ * <ul>
+ * <li>always - the JMS queue is always created. It is an error if the queue already exists
+ * <li>ifnotexist - the JMS queue is created if it does not exist. It is not an error if the queue already exists
+ * <li>never - the JMS queue is never created. It is an error if the queue does not exist
+ * </ul>
+ * See the SCA JMS Binding specification for more information.
+ * <p>
+ * @param queueName - the name of the Async Response queue
+ * @return The Async Response queue.
+ * @throws NamingException Failed to lookup JMS queue
+ * @throws JMSBindingException Failed to lookup JMS Queue. Probable cause is that the JMS queue's current existence/non-existence is not
+ * compatible with the create mode specified on the binding
+ */
+ private Destination lookupQueue(String queueName ) throws NamingException, JMSBindingException {
+
+ Destination destination = jmsResourceFactory.lookupDestination(queueName);
+
+ String qCreateMode = jmsBinding.getDestinationCreate();
+ if (qCreateMode.equals(JMSBindingConstants.CREATE_ALWAYS)) {
+ // In this mode, the queue must not already exist as we are creating it
+ if (destination != null) {
+ throw new JMSBindingException("JMS Destination " + queueName
+ + " already exists but has create mode of \""
+ + qCreateMode
+ + "\" while registering service "
+ + serviceName
+ + " listener");
+ } // end if
+
+ // Create the queue
+ destination = jmsResourceFactory.createDestination(queueName);
+
+ } else if (qCreateMode.equals(JMSBindingConstants.CREATE_IF_NOT_EXIST)) {
+ // In this mode, the queue may nor may not exist. It will be created if it does not exist
+ // but don't create when using jms:jndi uri format
+ if (destination == null && !"jndi".equals(jmsBinding.getDestinationType())) {
+ destination = jmsResourceFactory.createDestination(queueName);
+ } // end if
+
+ } else if (qCreateMode.equals(JMSBindingConstants.CREATE_NEVER)) {
+ // In this mode, the queue must have already been created.
+ if (destination == null) {
+ throw new JMSBindingException("JMS Destination " + queueName
+ + " not found but create mode of \""
+ + qCreateMode
+ + "\" while registering service "
+ + serviceName
+ + " listener");
+ } // end if
+ } // end if
+
+ // Make sure we ended up with a queue
+ if (destination == null) {
+ throw new JMSBindingException("JMS Destination " + queueName
+ + " not found with create mode of \""
+ + qCreateMode
+ + "\" while registering service "
+ + serviceName
+ + " listener");
+ } // end if
+
+ // Make sure its the expected type (queue or topic)
+ String type = (destination instanceof Queue) ? JMSBindingConstants.DESTINATION_TYPE_QUEUE : JMSBindingConstants.DESTINATION_TYPE_TOPIC;
+ if ("jndi".equals(jmsBinding.getDestinationType())) {
+ jmsBinding.setDestinationType(type);
+ } else {
+ if (!type.equals(jmsBinding.getDestinationType())) {
+ throw new JMSBindingException("JMS Destination " + queueName
+ + " expecting type of "
+ + jmsBinding.getDestinationType()
+ + " but found "
+ + type
+ + " while registering service "
+ + serviceName
+ + " listener");
+ } // end if
+ } // end if
+
+ return destination;
+ } // end method lookupDestinationQueue(String)
+
+ public String getDestinationName() {
+ try {
+ if (destination instanceof Queue) {
+ return ((Queue)destination).getQueueName();
+ } else if (destination instanceof Topic) {
+ return ((Topic)destination).getTopicName();
+ } else {
+ return null;
+ }
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ } // end method getDestinationName
+
+} // end class AsyncResponseJMSServiceListener
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSHostExtensionPoint.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSHostExtensionPoint.java
new file mode 100644
index 0000000000..cac346adf4
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSHostExtensionPoint.java
@@ -0,0 +1,40 @@
+/*
+ * 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.jms.host;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.work.WorkScheduler;
+
+public class DefaultJMSHostExtensionPoint implements JMSHostExtensionPoint {
+
+ private JMSServiceListenerFactory jmsServiceListenerFactory;
+
+ public DefaultJMSHostExtensionPoint(ExtensionPointRegistry extensionPoints) {
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ WorkScheduler workScheduler = utilities.getUtility(WorkScheduler.class);
+ this.jmsServiceListenerFactory = new DefaultJMSServiceListenerFactory(workScheduler);
+ }
+
+ public JMSServiceListenerFactory getJMSServiceListenerFactory() {
+ return jmsServiceListenerFactory;
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListener.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListener.java
new file mode 100644
index 0000000000..94728699a2
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListener.java
@@ -0,0 +1,283 @@
+/*
+ * 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.jms.host;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.naming.NamingException;
+import javax.resource.spi.ActivationSpec;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.work.WorkScheduler;
+
+/**
+ * Implementation of the JMS service binding provider.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultJMSServiceListener implements JMSServiceListener {
+ private static final Logger logger = Logger.getLogger(DefaultJMSServiceListener.class.getName());
+
+ private MessageListener listener;
+ private String serviceName;
+ private boolean isCallbackService;
+ private JMSBinding jmsBinding;
+ private WorkScheduler workScheduler;
+
+ private JMSResourceFactory jmsResourceFactory;
+ private MessageConsumer consumer;
+ private boolean running;
+
+ private Destination destination;
+
+ public DefaultJMSServiceListener(MessageListener listener, String serviceName, boolean isCallbackService, JMSBinding jmsBinding, WorkScheduler workScheduler, JMSResourceFactory rf) {
+ this.listener = listener;
+ this.serviceName = serviceName;
+ this.isCallbackService = isCallbackService;
+ this.jmsBinding = jmsBinding;
+ this.workScheduler = workScheduler;
+ this.jmsResourceFactory = rf;
+ }
+
+ public void start() {
+ this.running = true;
+
+ try {
+ registerListener();
+ } catch (Exception e) {
+ if (e instanceof JMSBindingException) throw (JMSBindingException)e;
+ throw new JMSBindingException("Error starting JMSServiceBinding", e);
+ }
+ }
+
+ public void stop() {
+ this.running = false;
+ try {
+ consumer.close();
+ jmsResourceFactory.closeConnection();
+ jmsResourceFactory.closeResponseConnection();
+ } catch (Exception e) {
+ // if using an embedded broker then when shutting down Tuscany the broker may get closed
+ // before this stop method is called. I can't see how to detect that so for now just
+ // ignore the exception if the message is that the transport is already disposed
+ if ((e.getMessage() == null) || !e.getMessage().contains("disposed")) {
+ throw new JMSBindingException("Error stopping JMSServiceBinding", e);
+ }
+ }
+ }
+
+ private void registerListener() throws NamingException, JMSException {
+
+ Session session = jmsResourceFactory.createSession();
+ lookupActivationSpec();
+ destination = lookupDestinationQueue();
+ if (destination == null) {
+ destination = session.createTemporaryQueue();
+ }
+
+ if (jmsBinding.getJMSSelector() != null) {
+ consumer = session.createConsumer(destination, jmsBinding.getJMSSelector());
+ } else {
+ consumer = session.createConsumer(destination);
+ }
+
+ try {
+
+ consumer.setMessageListener(listener);
+ jmsResourceFactory.startConnection();
+
+ } catch (javax.jms.JMSException e) {
+
+ // setMessageListener not allowed in JEE container so use Tuscany threads
+
+ jmsResourceFactory.startConnection();
+ workScheduler.scheduleWork(new Runnable() {
+ public void run() {
+ try {
+ while (running) {
+ final Message msg = consumer.receive();
+ workScheduler.scheduleWork(new Runnable() {
+ public void run() {
+ try {
+ listener.onMessage(msg);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+ logger.log(Level.INFO, "JMS " + (isCallbackService ? "callback service" : "service")
+ + " '"
+ + serviceName
+ + "' listening on destination "
+ + ((destination instanceof Queue) ? ((Queue)destination).getQueueName() : ((Topic)destination).getTopicName()));
+ }
+
+ // Stub code for ActivationSpec support that throws appropriate errors
+ private void lookupActivationSpec() {
+ if ( jmsBinding.getActivationSpecName() != null ) {
+ String createMode = jmsBinding.getActivationSpecCreate();
+ if ( JMSBindingConstants.CREATE_ALWAYS.equals(createMode) ) {
+ ActivationSpec spec = jmsResourceFactory.lookupActivationSpec(jmsBinding.getActivationSpecName());
+ if ( spec != null ) {
+ throw new JMSBindingException("ActivationSpec specifies create mode of \"always\" but resource already exists.");
+ }
+ throw new JMSBindingException("Can not create ActivationSpec");
+ } else if ( JMSBindingConstants.CREATE_IF_NOT_EXIST.equals(createMode)) {
+ ActivationSpec spec = jmsResourceFactory.lookupActivationSpec(jmsBinding.getActivationSpecName());
+ if ( spec == null ) {
+ throw new JMSBindingException("Can not create ActivationSpec");
+ }
+ } else if ( JMSBindingConstants.CREATE_NEVER.equals(createMode)) {
+ ActivationSpec spec = jmsResourceFactory.lookupActivationSpec(jmsBinding.getActivationSpecName());
+ if ( spec == null )
+ throw new JMSBindingException("ActivationSpec specifies create mode of \"never\" but resource does not exist at jndiName " + jmsBinding.getActivationSpecName());
+
+ }
+
+
+ }
+ }
+
+ /**
+ * Looks up the Destination Queue for the JMS Binding.
+ * <p>
+ * What happens in the look up will depend on the create mode specified for the JMS Binding:
+ * <ul>
+ * <li>always - the JMS queue is always created. It is an error if the queue already exists
+ * <li>ifnotexist - the JMS queue is created if it does not exist. It is not an error if the queue already exists
+ * <li>never - the JMS queue is never created. It is an error if the queue does not exist
+ * </ul>
+ * See the SCA JMS Binding specification for more information.
+ * <p>
+ *
+ * @return The Destination queue.
+ * @throws NamingException Failed to lookup JMS queue
+ * @throws JMSBindingException Failed to lookup JMS Queue. Probable cause is that the JMS queue's current existence/non-existence is not
+ * compatible with the create mode specified on the binding
+ */
+ private Destination lookupDestinationQueue() throws NamingException, JMSBindingException {
+
+ if (isCallbackService && (jmsBinding.getDestinationName() == null)) {
+ // if its a callback service returning null indicates to use a temporary queue
+ return null;
+ }
+
+ Destination destination = jmsResourceFactory.lookupDestination(jmsBinding.getDestinationName());
+
+ String qCreateMode = jmsBinding.getDestinationCreate();
+ if (qCreateMode.equals(JMSBindingConstants.CREATE_ALWAYS)) {
+ // In this mode, the queue must not already exist as we are creating it
+ if (destination != null) {
+ throw new JMSBindingException("JMS Destination " + jmsBinding.getDestinationName()
+ + " already exists but has create mode of \""
+ + qCreateMode
+ + "\" while registering service "
+ + serviceName
+ + " listener");
+ }
+
+ // Create the queue
+ destination = jmsResourceFactory.createDestination(jmsBinding.getDestinationName());
+
+ } else if (qCreateMode.equals(JMSBindingConstants.CREATE_IF_NOT_EXIST)) {
+ // In this mode, the queue may nor may not exist. It will be created if it does not exist
+ // but don't create when using jms:jndi uri format
+ if (destination == null && !"jndi".equals(jmsBinding.getDestinationType())) {
+ destination = jmsResourceFactory.createDestination(jmsBinding.getDestinationName());
+ }
+
+ } else if (qCreateMode.equals(JMSBindingConstants.CREATE_NEVER)) {
+ // In this mode, the queue must have already been created.
+ if (destination == null) {
+ throw new JMSBindingException("JMS Destination " + jmsBinding.getDestinationName()
+ + " not found but create mode of \""
+ + qCreateMode
+ + "\" while registering service "
+ + serviceName
+ + " listener");
+ }
+ }
+
+ // Make sure we ended up with a queue
+ if (destination == null) {
+ throw new JMSBindingException("JMS Destination " + jmsBinding.getDestinationName()
+ + " not found with create mode of \""
+ + qCreateMode
+ + "\" while registering service "
+ + serviceName
+ + " listener");
+ }
+
+ // Make sure its the expected type (queue or topic)
+ String type = (destination instanceof Queue) ? JMSBindingConstants.DESTINATION_TYPE_QUEUE : JMSBindingConstants.DESTINATION_TYPE_TOPIC;
+ if ("jndi".equals(jmsBinding.getDestinationType())) {
+ jmsBinding.setDestinationType(type);
+ } else {
+ if (!type.equals(jmsBinding.getDestinationType())) {
+ throw new JMSBindingException("JMS Destination " + jmsBinding.getDestinationName()
+ + " expecting type of "
+ + jmsBinding.getDestinationType()
+ + " but found "
+ + type
+ + " while registering service "
+ + serviceName
+ + " listener");
+ }
+ }
+
+ return destination;
+ }
+
+
+
+ public String getDestinationName() {
+ try {
+ if (destination instanceof Queue) {
+ return ((Queue)destination).getQueueName();
+ } else if (destination instanceof Topic) {
+ return ((Topic)destination).getTopicName();
+ } else {
+ return null;
+ }
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListenerFactory.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListenerFactory.java
new file mode 100644
index 0000000000..1976d687b6
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListenerFactory.java
@@ -0,0 +1,55 @@
+/*
+ * 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.jms.host;
+
+import javax.jms.MessageListener;
+import javax.naming.NamingException;
+
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.provider.JMSBindingServiceBindingProvider;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.work.WorkScheduler;
+
+public class DefaultJMSServiceListenerFactory implements JMSServiceListenerFactory {
+
+ private WorkScheduler workScheduler;
+
+ public DefaultJMSServiceListenerFactory(WorkScheduler workScheduler) {
+ this.workScheduler = workScheduler;
+ }
+
+ public JMSServiceListener createJMSServiceListener(JMSServiceListenerDetails jmsSLD) {
+ try {
+
+ JMSResourceFactory rf = ((JMSBindingServiceBindingProvider)jmsSLD).getResourceFactory();
+
+ RuntimeComponentService service = (RuntimeComponentService) jmsSLD.getEndpoint().getService();
+ MessageListener listener = new DefaultServiceInvoker(jmsSLD.getEndpoint(), jmsSLD.getTargetBinding(), jmsSLD.getMessageFactory(), rf);
+
+// return new ASFListener(listener, service.getName(), service.isCallback(), jmsSLD.getJmsBinding(), workScheduler, rf);
+// TODO: 2.x migration, service.isCallback()
+ return new DefaultJMSServiceListener(listener, service.getName(), false, jmsSLD.getJmsBinding(), workScheduler, rf);
+
+ } catch (NamingException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultServiceInvoker.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultServiceInvoker.java
new file mode 100644
index 0000000000..566284fda6
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultServiceInvoker.java
@@ -0,0 +1,112 @@
+/*
+ * 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.jms.host;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.naming.NamingException;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ * TODO RRB experiement
+ * Listener for the JMSBinding.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultServiceInvoker implements MessageListener {
+
+ private static final Logger logger = Logger.getLogger(DefaultServiceInvoker.class.getName());
+
+ private RuntimeEndpoint endpoint;
+ private JMSBinding jmsBinding;
+ private Binding targetBinding;
+ private JMSResourceFactory jmsResourceFactory;
+ private RuntimeComponentService service;
+ private MessageFactory messageFactory;
+
+ public DefaultServiceInvoker(RuntimeEndpoint endpoint, Binding targetBinding, MessageFactory messageFactory, JMSResourceFactory rf) throws NamingException {
+ this.endpoint = endpoint;
+ this.jmsBinding = (JMSBinding) endpoint.getBinding();
+ this.jmsResourceFactory = rf;
+ this.service = (RuntimeComponentService) endpoint.getService();
+ this.targetBinding = targetBinding;
+ this.messageFactory = messageFactory;
+
+ }
+
+ public void onMessage(Message requestJMSMsg) {
+ logger.log(Level.FINE, "JMS service '" + service.getName() + "' received message " + requestJMSMsg);
+ try {
+ invokeService(requestJMSMsg);
+ } catch (Throwable e) {
+ logger.log(Level.SEVERE, "Exception send fault response '" + service.getName(), e);
+ }
+ }
+
+ protected void invokeService(Message requestJMSMsg) throws JMSException, InvocationTargetException {
+
+ // create the tuscany message
+ org.apache.tuscany.sca.invocation.Message tuscanyMsg = messageFactory.createMessage();
+
+ // populate the message context with JMS binding information
+ JMSBindingContext context = new JMSBindingContext();
+ tuscanyMsg.setBindingContext(context);
+
+ context.setJmsMsg(requestJMSMsg);
+ context.setJmsResourceFactory(jmsResourceFactory);
+ context.setReplyToDestination(requestJMSMsg.getJMSReplyTo());
+
+ // set the message body
+ tuscanyMsg.setBody(requestJMSMsg);
+
+ // call the runtime wire - the response is handled by the
+ // transport interceptor
+ //getEndpoint(targetBinding).invoke(tuscanyMsg);
+ RuntimeEndpoint endpoint = getEndpoint(targetBinding);
+ if( endpoint.isAsyncInvocation() ) {
+ endpoint.invokeAsync(tuscanyMsg);
+ } else {
+ endpoint.invoke(tuscanyMsg);
+ } // end if
+
+ } // end method invokeService
+
+ private RuntimeEndpoint getEndpoint(Binding targetBinding) {
+ for(Endpoint ep: service.getEndpoints()) {
+ if(ep.getBinding() == targetBinding) {
+ return (RuntimeEndpoint) ep;
+ }
+ }
+ return endpoint;
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSAsyncResponseInvoker.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSAsyncResponseInvoker.java
new file mode 100644
index 0000000000..386cb54700
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSAsyncResponseInvoker.java
@@ -0,0 +1,98 @@
+/*
+ * 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.jms.host;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.naming.NamingException;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+/**
+ * TODO RRB experiement
+ * Listener for the JMSBinding.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JMSAsyncResponseInvoker implements MessageListener {
+
+ private static final Logger logger = Logger.getLogger(JMSAsyncResponseInvoker.class.getName());
+
+ private RuntimeEndpointReference endpointReference;
+ private JMSBinding jmsBinding;
+ private JMSResourceFactory jmsResourceFactory;
+ private RuntimeComponentReference reference;
+ private MessageFactory messageFactory;
+
+ public JMSAsyncResponseInvoker(RuntimeEndpointReference endpointReference,
+ MessageFactory messageFactory,
+ JMSResourceFactory rf) throws NamingException {
+ this.endpointReference = endpointReference;
+ this.jmsBinding = (JMSBinding) endpointReference.getBinding();
+ this.jmsResourceFactory = rf;
+ this.reference = (RuntimeComponentReference) endpointReference.getReference();
+ this.messageFactory = messageFactory;
+ }
+
+ public void onMessage(Message requestJMSMsg) {
+ logger.log(Level.FINE, "JMS reference '" + reference.getName() + "' received message " + requestJMSMsg);
+ try {
+ invokeReference(requestJMSMsg);
+ } catch (Throwable e) {
+ logger.log(Level.SEVERE, "Exception send fault response '" + reference.getName(), e);
+ }
+ } // end method onMessage
+
+ protected void invokeReference(Message requestJMSMsg) throws JMSException, InvocationTargetException {
+
+ // create the Tuscany message
+ org.apache.tuscany.sca.invocation.Message tuscanyMsg = messageFactory.createMessage();
+
+ // populate the message context with JMS binding information
+ JMSBindingContext context = new JMSBindingContext();
+ tuscanyMsg.setBindingContext(context);
+
+ context.setJmsMsg(requestJMSMsg);
+ context.setJmsResourceFactory(jmsResourceFactory);
+ context.setReplyToDestination(requestJMSMsg.getJMSReplyTo());
+
+
+
+ // set the message body
+ tuscanyMsg.setBody(requestJMSMsg);
+
+ // call the runtime wire - the response is handled by the
+ // transport interceptor
+ endpointReference.invokeAsyncResponse(tuscanyMsg);
+
+ } // end method invokeReference
+
+} // end class AsyncResponseInvoker
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSHostExtensionPoint.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSHostExtensionPoint.java
new file mode 100644
index 0000000000..a15a84b60e
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSHostExtensionPoint.java
@@ -0,0 +1,27 @@
+/*
+ * 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.jms.host;
+
+
+public interface JMSHostExtensionPoint {
+
+ JMSServiceListenerFactory getJMSServiceListenerFactory();
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSServiceListener.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSServiceListener.java
new file mode 100644
index 0000000000..444d796b12
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSServiceListener.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.jms.host;
+
+public interface JMSServiceListener {
+
+ void start();
+
+ void stop();
+
+ String getDestinationName();
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSServiceListenerDetails.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSServiceListenerDetails.java
new file mode 100644
index 0000000000..451f3680d6
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSServiceListenerDetails.java
@@ -0,0 +1,37 @@
+/*
+ * 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.jms.host;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+public interface JMSServiceListenerDetails {
+
+ JMSBinding getJmsBinding();
+
+ Binding getTargetBinding();
+
+ RuntimeEndpoint getEndpoint();
+
+ MessageFactory getMessageFactory();
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSServiceListenerFactory.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSServiceListenerFactory.java
new file mode 100644
index 0000000000..9dc23f1d8d
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSServiceListenerFactory.java
@@ -0,0 +1,27 @@
+/*
+ * 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.jms.host;
+
+
+public interface JMSServiceListenerFactory {
+
+ JMSServiceListener createJMSServiceListener(JMSServiceListenerDetails jmsServiceBindingProvider);
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultProviderFactory.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultProviderFactory.java
new file mode 100644
index 0000000000..61a2a076de
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultProviderFactory.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.jms.operationselector.jmsdefault.runtime;
+
+import org.apache.tuscany.sca.binding.jms.operationselector.OperationSelectorJMSDefault;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.provider.OperationSelectorProvider;
+import org.apache.tuscany.sca.provider.OperationSelectorProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class OperationSelectorJMSDefaultProviderFactory implements OperationSelectorProviderFactory<OperationSelectorJMSDefault> {
+ private ExtensionPointRegistry registry;
+
+ public OperationSelectorJMSDefaultProviderFactory(ExtensionPointRegistry registry) {
+ super();
+ this.registry = registry;
+ }
+
+ /**
+ */
+ public OperationSelectorProvider createReferenceOperationSelectorProvider(RuntimeEndpointReference endpointReference) {
+ return null;
+ }
+
+ /**
+ */
+ public OperationSelectorProvider createServiceOperationSelectorProvider(RuntimeEndpoint endpoint) {
+ return new OperationSelectorJMSDefaultServiceProvider(registry, endpoint);
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType()
+ */
+ public Class getModelType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceInterceptor.java
new file mode 100644
index 0000000000..b9c4166233
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceInterceptor.java
@@ -0,0 +1,206 @@
+/*
+ * 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.jms.operationselector.jmsdefault.runtime;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.jms.BytesMessage;
+import javax.jms.JMSException;
+import javax.jms.TextMessage;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSDefault;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSTextXML;
+import org.apache.tuscany.sca.common.xml.dom.DOMHelper;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
+/**
+ * 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 OperationSelectorJMSDefaultServiceInterceptor extends InterceptorAsyncImpl {
+
+ private static final String ON_MESSAGE_METHOD_NAME = "onMessage";
+
+ private Invoker next;
+ private RuntimeEndpoint endpint;
+ private JMSResourceFactory jmsResourceFactory;
+ private JMSBinding jmsBinding;
+ private JMSMessageProcessor requestMessageProcessor;
+ private JMSMessageProcessor responseMessageProcessor;
+ private RuntimeComponentService service;
+ private List<Operation> serviceOperations;
+ private DOMHelper domHelper;
+
+ public OperationSelectorJMSDefaultServiceInterceptor(ExtensionPointRegistry registry, JMSResourceFactory jmsResourceFactory, RuntimeEndpoint endpoint) {
+ super();
+ this.endpint = endpoint;
+ this.jmsBinding = (JMSBinding) endpoint.getBinding();
+ this.jmsResourceFactory = jmsResourceFactory;
+ this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(registry, jmsBinding);
+ this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(registry, jmsBinding);
+ this.service = (RuntimeComponentService)endpoint.getService();
+ this.serviceOperations = service.getInterfaceContract().getInterface().getOperations();
+ this.domHelper = DOMHelper.getInstance(registry);
+ }
+
+ public Message invoke(Message msg) {
+ return next.invoke(invokeRequest(msg));
+ }
+
+ public Message invokeRequest(Message msg) {
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ javax.jms.Message jmsMsg = context.getJmsMsg();
+
+ String operationName = requestMessageProcessor.getOperationName(jmsMsg);
+ Operation operation = getTargetOperation(operationName, jmsMsg);
+ msg.setOperation(operation);
+
+ return msg;
+ }
+
+ protected Operation getTargetOperation(String operationName, javax.jms.Message jmsMsg) {
+ Operation operation = null;
+
+ if (serviceOperations.size() == 1) {
+
+ // SCA JMS Binding Specification - Rule 1.5.1 line 203
+ operation = serviceOperations.get(0);
+
+ } else if (operationName != null) {
+
+ // SCA JMS Binding Specification - Rule 1.5.1 line 205
+ for (Operation op : serviceOperations) {
+ if (op.getName().equals(operationName)) {
+ operation = op;
+ break;
+ } else {
+ String nativeName = jmsBinding.getNativeOperationName(op.getName());
+ if (( nativeName != null ) && ( nativeName.equals(operationName)) ) {
+ operation = op;
+ break;
+ }
+ }
+ }
+ } else if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSDefault
+ || jmsBinding.getRequestWireFormat() instanceof WireFormatJMSTextXML) {
+
+ Node rootElement;
+ String operationFromPayload;
+
+ try {
+ if (jmsMsg instanceof TextMessage) {
+ String xmlPayload = ((TextMessage) jmsMsg).getText();
+
+ if (xmlPayload != null) {
+ rootElement = domHelper.load(xmlPayload);
+ Node firstChild = rootElement.getFirstChild();
+ if (firstChild != null) {
+ operationFromPayload = firstChild.getLocalName();
+ for (Operation op : serviceOperations) {
+ if (op.getName().equals(operationFromPayload)) {
+ operation = op;
+ break;
+ }
+ }
+ }
+ }
+ } else if (jmsMsg instanceof BytesMessage) {
+ long noOfBytes = ((BytesMessage) jmsMsg).getBodyLength();
+ byte[] bytes = new byte[(int) noOfBytes];
+ ((BytesMessage) jmsMsg).readBytes(bytes);
+ ((BytesMessage) jmsMsg).reset();
+
+ if (bytes != null) {
+ rootElement = domHelper.load(new String(bytes));
+ Node firstChild = rootElement.getFirstChild();
+ if (firstChild != null) {
+ operationFromPayload = firstChild.getLocalName();
+ for (Operation op : serviceOperations) {
+ if (op.getName().equals(operationFromPayload)) {
+ operation = op;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ } catch (IOException e) {
+ //let's ignore this in case the client doesn't want to use a wrapped xml message
+ } catch (SAXException e) {
+ //let's ignore this in case the client doesn't want to use a wrapped xml message
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+
+ // If operation is still null we attempt the last rule
+ if (operation == null) {
+
+ // SCA JMS Binding Specification - Rule 1.5.1 line 207
+ for (Operation op : serviceOperations) {
+ if (op.getName().equals(ON_MESSAGE_METHOD_NAME)) {
+ operation = op;
+ break;
+ }
+ }
+ }
+ }
+
+ if (operation == null) {
+ throw new JMSBindingException("Cannot determine service operation");
+ }
+
+ return operation;
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Message processRequest(Message msg) {
+ return invokeRequest(msg);
+ } // end method processRequest
+
+ public Message processResponse(Message msg) {
+ return msg;
+ } // end method processResponse
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceProvider.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceProvider.java
new file mode 100644
index 0000000000..da120ac6c1
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceProvider.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.jms.operationselector.jmsdefault.runtime;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.OperationSelectorProvider;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class OperationSelectorJMSDefaultServiceProvider implements OperationSelectorProvider {
+ private RuntimeEndpoint endpoint;
+ private ExtensionPointRegistry registry;
+
+ public OperationSelectorJMSDefaultServiceProvider(ExtensionPointRegistry registry, RuntimeEndpoint endpoint) {
+ super();
+ this.endpoint = endpoint;
+ this.registry = registry;
+ }
+
+ /**
+ */
+ public Interceptor createInterceptor() {
+ return new OperationSelectorJMSDefaultServiceInterceptor(registry, null, endpoint);
+ }
+
+ /**
+ */
+ public String getPhase() {
+ return Phase.SERVICE_BINDING_OPERATION_SELECTOR;
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropProviderFactory.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropProviderFactory.java
new file mode 100644
index 0000000000..4352f5d416
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropProviderFactory.java
@@ -0,0 +1,56 @@
+/*
+ * 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.jms.operationselector.jmsuserprop.runtime;
+
+import org.apache.tuscany.sca.binding.jms.operationselector.OperationSelectorJMSUserProp;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.provider.OperationSelectorProvider;
+import org.apache.tuscany.sca.provider.OperationSelectorProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+public class OperationSelectorJMSUserPropProviderFactory implements OperationSelectorProviderFactory<OperationSelectorJMSUserProp> {
+ private ExtensionPointRegistry registry;
+
+ public OperationSelectorJMSUserPropProviderFactory(ExtensionPointRegistry registry) {
+ super();
+ this.registry = registry;
+ }
+
+ /**
+ */
+ public OperationSelectorProvider createReferenceOperationSelectorProvider(RuntimeEndpointReference endpointReference) {
+ return null;
+ }
+
+ /**
+ */
+ public OperationSelectorProvider createServiceOperationSelectorProvider(RuntimeEndpoint endpoint) {
+ return new OperationSelectorJMSUserPropServiceProvider(endpoint);
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType()
+ */
+ public Class getModelType() {
+ return null;
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceInterceptor.java
new file mode 100644
index 0000000000..52a7c58027
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceInterceptor.java
@@ -0,0 +1,115 @@
+/*
+ * 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.jms.operationselector.jmsuserprop.runtime;
+
+import java.util.List;
+
+import javax.jms.JMSException;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.operationselector.OperationSelectorJMSUserProp;
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ * Interceptor for user property based operation selection
+ *
+ * <operationSelector.jmsUser propertName="MyHeaderProperty"/>
+ *
+ */
+public class OperationSelectorJMSUserPropServiceInterceptor extends InterceptorAsyncImpl {
+
+ private Invoker next;
+ private RuntimeEndpoint endpoint;
+ private JMSBinding jmsBinding;
+ private OperationSelectorJMSUserProp operationSelector;
+ private RuntimeComponentService service;
+ private List<Operation> serviceOperations;
+
+ public OperationSelectorJMSUserPropServiceInterceptor(RuntimeEndpoint endpoint) {
+ super();
+ this.jmsBinding = (JMSBinding) endpoint.getBinding();
+ this.operationSelector = (OperationSelectorJMSUserProp)jmsBinding.getOperationSelector();
+ this.endpoint = endpoint;
+ this.service = (RuntimeComponentService) endpoint.getService();
+ this.serviceOperations = service.getInterfaceContract().getInterface().getOperations();
+ }
+
+ public Message invoke(Message msg) {
+ return next.invoke(invokeRequest(msg));
+ }
+
+ public Message invokeRequest(Message msg) {
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ javax.jms.Message jmsMsg = context.getJmsMsg();
+
+ Operation operation = getTargetOperation(jmsMsg);
+ msg.setOperation(operation);
+
+ return msg;
+ }
+
+ protected Operation getTargetOperation(javax.jms.Message jmsMsg) {
+ String operationName = null;
+ String opSelectorPropertyName = operationSelector.getPropertyName();
+
+ try {
+ operationName = jmsMsg.getStringProperty(opSelectorPropertyName);
+ } catch(JMSException e) {
+ throw new JMSBindingException(e);
+ }
+
+ if (operationName == null){
+ throw new JMSBindingException("Property " + opSelectorPropertyName + " not found in message header");
+ }
+
+ for (Operation op : serviceOperations) {
+ if (op.getName().equals(operationName)) {
+ return op;
+ }
+ }
+
+ throw new JMSBindingException("Can't find operation " + operationName);
+ }
+
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Message processRequest(Message msg) {
+ return invokeRequest(msg);
+ } // end method processRequest
+
+ public Message processResponse(Message msg) {
+ return msg;
+ } // end method processResponse
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceProvider.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceProvider.java
new file mode 100644
index 0000000000..a151688c36
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceProvider.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.jms.operationselector.jmsuserprop.runtime;
+
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.OperationSelectorProvider;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+public class OperationSelectorJMSUserPropServiceProvider implements OperationSelectorProvider {
+ private RuntimeEndpoint endpoint;
+
+ public OperationSelectorJMSUserPropServiceProvider(RuntimeEndpoint endpoint) {
+ super();
+ this.endpoint = endpoint;
+ }
+
+ /**
+ */
+ public Interceptor createInterceptor() {
+ return new OperationSelectorJMSUserPropServiceInterceptor(endpoint);
+ }
+
+ /**
+ */
+ public String getPhase() {
+ return Phase.SERVICE_BINDING_OPERATION_SELECTOR;
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationPolicyProviderFactory.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationPolicyProviderFactory.java
new file mode 100644
index 0000000000..edecc18d2d
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationPolicyProviderFactory.java
@@ -0,0 +1,74 @@
+/*
+ * 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.jms.policy.authentication.token.provider;
+
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAuthenticationPolicy;
+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 JMSTokenAuthenticationPolicyProviderFactory implements PolicyProviderFactory<JMSTokenAuthenticationPolicy> {
+ private ExtensionPointRegistry registry;
+
+ public JMSTokenAuthenticationPolicyProviderFactory(ExtensionPointRegistry registry) {
+ super();
+ this.registry = registry;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createImplementationPolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.assembly.Implementation)
+ */
+ public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component, Implementation implementation) {
+ return null;//new TokenAuthenticationImplementationPolicyProvider(component, implementation);
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createReferencePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentReference, org.apache.tuscany.sca.assembly.Binding)
+ */
+ public PolicyProvider createReferencePolicyProvider(EndpointReference endpointReference) {
+ return new JMSTokenAuthenticationReferencePolicyProvider(endpointReference);
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createServicePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentService, org.apache.tuscany.sca.assembly.Binding)
+ */
+ public PolicyProvider createServicePolicyProvider(Endpoint endpoint) {
+ return new JMSTokenAuthenticationServicePolicyProvider(endpoint);
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType()
+ */
+ public Class getModelType() {
+ return null;
+ }
+
+ public PolicyProvider createImplementationPolicyProvider(RuntimeComponent arg0) {
+ return null;
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationReferencePolicyInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationReferencePolicyInterceptor.java
new file mode 100644
index 0000000000..c5d0705eb6
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationReferencePolicyInterceptor.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.jms.policy.authentication.token.provider;
+
+
+import javax.jms.JMSException;
+import javax.security.auth.Subject;
+
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAuthenticationPolicy;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.PhasedInterceptor;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.authentication.token.TokenPrincipal;
+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 JMSTokenAuthenticationReferencePolicyInterceptor implements PhasedInterceptor {
+
+ private Invoker next;
+ private PolicySet policySet = null;
+ private String context;
+ private JMSTokenAuthenticationPolicy policy;
+ private String phase;
+
+ public JMSTokenAuthenticationReferencePolicyInterceptor(String context, PolicySet policySet, String phase) {
+ super();
+ this.policySet = policySet;
+ this.context = context;
+ this.phase = phase;
+ init();
+ }
+
+ private void init() {
+ if (policySet != null) {
+ for (Object policyObject : policySet.getPolicies()){
+ if (policyObject instanceof JMSTokenAuthenticationPolicy){
+ policy = (JMSTokenAuthenticationPolicy)policyObject;
+ break;
+ }
+ }
+ }
+ }
+
+ public Message invoke(Message msg) {
+ try {
+ javax.jms.Message jmsMsg = msg.getBody();
+
+ if ( policy.getTokenName() != null){
+
+ Subject subject = SecurityUtil.getSubject(msg);
+ TokenPrincipal principal = SecurityUtil.getPrincipal(subject, TokenPrincipal.class);
+
+ if (principal == null){
+ // should call out here to some 3rd party system to get credentials
+ // and correct token. Here we are just putting in the token name
+ principal = new TokenPrincipal("DummyTokenID");
+ subject.getPrincipals().add(principal);
+ }
+
+ jmsMsg.setStringProperty(policy.getTokenName().toString(), principal.getName());
+ }
+
+ return getNext().invoke(msg);
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public String getPhase() {
+ return phase;
+ }
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationReferencePolicyProvider.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationReferencePolicyProvider.java
new file mode 100644
index 0000000000..b3c7f40c55
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationReferencePolicyProvider.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.jms.policy.authentication.token.provider;
+
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAuthenticationPolicy;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.invocation.PhasedInterceptor;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.provider.BasePolicyProvider;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JMSTokenAuthenticationReferencePolicyProvider extends BasePolicyProvider<JMSTokenAuthenticationPolicy> {
+ private EndpointReference endpointReference;
+
+ public JMSTokenAuthenticationReferencePolicyProvider(EndpointReference endpointReference) {
+ super(JMSTokenAuthenticationPolicy.class, endpointReference);
+ this.endpointReference = endpointReference;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.provider.PolicyProvider#createInterceptor(org.apache.tuscany.sca.interfacedef.Operation)
+ */
+ public PhasedInterceptor createInterceptor(Operation operation) {
+ PolicySet ps = findPolicySet();
+ return ps == null ? null : new JMSTokenAuthenticationReferencePolicyInterceptor(getContext(), ps, getPhase());
+
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.provider.PolicyProvider#getPhase()
+ */
+ public String getPhase() {
+ return Phase.REFERENCE_BINDING_POLICY;
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationServicePolicyInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationServicePolicyInterceptor.java
new file mode 100644
index 0000000000..c570354981
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationServicePolicyInterceptor.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.jms.policy.authentication.token.provider;
+
+
+
+import javax.jms.JMSException;
+import javax.security.auth.Subject;
+
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAuthenticationPolicy;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.PhasedInterceptor;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.authentication.token.TokenPrincipal;
+import org.apache.tuscany.sca.policy.security.SecurityUtil;
+
+/**
+ * Policy handler to handle token based authentication
+ * {http://tuscany.apache.org/xmlns/sca/1.1/impl/java}LoggingPolicy
+ *
+ * @version $Rev$ $Date$
+ */
+public class JMSTokenAuthenticationServicePolicyInterceptor implements PhasedInterceptor {
+ private Invoker next;
+ private PolicySet policySet = null;
+ private String context;
+ private JMSTokenAuthenticationPolicy policy;
+ private String phase;
+
+ public JMSTokenAuthenticationServicePolicyInterceptor(String context, PolicySet policySet, String phase) {
+ super();
+ this.policySet = policySet;
+ this.context = context;
+ this.phase = phase;
+ init();
+ }
+
+ private void init() {
+ if (policySet != null) {
+ for (Object policyObject : policySet.getPolicies()){
+ if (policyObject instanceof JMSTokenAuthenticationPolicy){
+ policy = (JMSTokenAuthenticationPolicy)policyObject;
+ break;
+ }
+ }
+ }
+ }
+
+ public Message invoke(Message msg) {
+ try{
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ javax.jms.Message jmsMsg = context.getJmsMsg();
+
+ String token = jmsMsg.getStringProperty(policy.getTokenName().toString());
+
+ Subject subject = SecurityUtil.getSubject(msg);
+ TokenPrincipal principal = SecurityUtil.getPrincipal(subject, TokenPrincipal.class);
+
+ if (principal == null){
+ principal = new TokenPrincipal(token);
+ subject.getPrincipals().add(principal);
+ }
+
+ System.out.println("JMS service received token: " + principal.getName());
+
+ // call out here to some 3rd party system to do whatever you
+ // need to authenticate the principal
+
+ return getNext().invoke(msg);
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public String getPhase() {
+ return phase;
+ }
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationServicePolicyProvider.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationServicePolicyProvider.java
new file mode 100644
index 0000000000..351b1c3f0f
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationServicePolicyProvider.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.jms.policy.authentication.token.provider;
+
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAuthenticationPolicy;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.invocation.PhasedInterceptor;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.provider.BasePolicyProvider;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JMSTokenAuthenticationServicePolicyProvider extends BasePolicyProvider<JMSTokenAuthenticationPolicy> {
+
+ private Endpoint endpoint;
+
+ public JMSTokenAuthenticationServicePolicyProvider(Endpoint endpoint) {
+ super(JMSTokenAuthenticationPolicy.class, endpoint);
+ this.endpoint = endpoint;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.provider.PolicyProvider#createInterceptor(org.apache.tuscany.sca.interfacedef.Operation)
+ */
+ public PhasedInterceptor createInterceptor(Operation operation) {
+ PolicySet ps = findPolicySet();
+ return ps == null ? null : new JMSTokenAuthenticationServicePolicyInterceptor(getContext(), ps, getPhase());
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.provider.PolicyProvider#getPhase()
+ */
+ public String getPhase() {
+ return Phase.SERVICE_BINDING_POLICY;
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/provider/JMSHeaderPolicyProviderFactory.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/provider/JMSHeaderPolicyProviderFactory.java
new file mode 100644
index 0000000000..4a199bcdff
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/provider/JMSHeaderPolicyProviderFactory.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.jms.policy.header.provider;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.binding.jms.policy.header.JMSHeaderPolicy;
+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;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JMSHeaderPolicyProviderFactory implements PolicyProviderFactory<JMSHeaderPolicy> {
+ private ExtensionPointRegistry registry;
+
+ public JMSHeaderPolicyProviderFactory(ExtensionPointRegistry registry) {
+ super();
+ this.registry = registry;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createImplementationPolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.assembly.Implementation)
+ */
+ public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component, Implementation implementation) {
+ return null;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createReferencePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentReference, org.apache.tuscany.sca.assembly.Binding)
+ */
+ public PolicyProvider createReferencePolicyProvider(EndpointReference endpointReference) {
+ return new JMSHeaderReferencePolicyProvider(endpointReference);
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createServicePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentService, org.apache.tuscany.sca.assembly.Binding)
+ */
+ public PolicyProvider createServicePolicyProvider(RuntimeComponent component,
+ RuntimeComponentService service,
+ Binding binding) {
+ return null;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType()
+ */
+ public Class getModelType() { // TODO Auto-generated method stub
+ return null;
+ }
+
+ public PolicyProvider createImplementationPolicyProvider(RuntimeComponent arg0) {
+ return null; // Not used for a Binding
+ }
+
+ public PolicyProvider createServicePolicyProvider(Endpoint arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/provider/JMSHeaderReferencePolicyInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/provider/JMSHeaderReferencePolicyInterceptor.java
new file mode 100644
index 0000000000..967614f9b9
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/provider/JMSHeaderReferencePolicyInterceptor.java
@@ -0,0 +1,88 @@
+/*
+ * 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.jms.policy.header.provider;
+
+
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.policy.header.JMSHeaderPolicy;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.PhasedInterceptor;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/**
+ * 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 JMSHeaderReferencePolicyInterceptor implements PhasedInterceptor {
+
+ private Invoker next;
+ private PolicySet policySet = null;
+ private String context;
+ private JMSHeaderPolicy jmsHeaderPolicy;
+ private String phase;
+ private EndpointReference endpointReference;
+
+ public JMSHeaderReferencePolicyInterceptor(String context, EndpointReference endpointReference, PolicySet policySet, String phase) {
+ super();
+ this.endpointReference = endpointReference;
+ this.policySet = policySet;
+ this.context = context;
+ this.phase = phase;
+
+ init();
+ }
+
+ private void init() {
+ if (policySet != null) {
+ for (Object policyObject : policySet.getPolicies()){
+ if (policyObject instanceof JMSHeaderPolicy){
+ jmsHeaderPolicy = (JMSHeaderPolicy)policyObject;
+ break;
+ }
+ }
+ }
+ }
+
+ public Message invoke(Message msg) {
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+
+ javax.jms.Message jmsMsg = msg.getBody();
+
+ // JMS header attrs set on MessageProducer via interceptors.
+
+ return getNext().invoke(msg);
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public String getPhase() {
+ return phase;
+ }
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/provider/JMSHeaderReferencePolicyProvider.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/provider/JMSHeaderReferencePolicyProvider.java
new file mode 100644
index 0000000000..b3d7b584aa
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/provider/JMSHeaderReferencePolicyProvider.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.jms.policy.header.provider;
+
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.binding.jms.policy.header.JMSHeaderPolicy;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.invocation.PhasedInterceptor;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.provider.BasePolicyProvider;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JMSHeaderReferencePolicyProvider extends BasePolicyProvider<JMSHeaderPolicy> {
+
+ private EndpointReference endpointReference;
+
+ public JMSHeaderReferencePolicyProvider(EndpointReference endpointReference) {
+ super(JMSHeaderPolicy.class, endpointReference);
+ this.endpointReference = endpointReference;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.provider.PolicyProvider#createInterceptor(org.apache.tuscany.sca.interfacedef.Operation)
+ */
+ public PhasedInterceptor createInterceptor(Operation operation) {
+ PolicySet ps = findPolicySet();
+ return ps == null ? null : new JMSHeaderReferencePolicyInterceptor(getContext(), endpointReference, ps, getPhase());
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.provider.PolicyProvider#getPhase()
+ */
+ public String getPhase() {
+ return Phase.REFERENCE_BINDING_POLICY;
+ }
+
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/AbstractMessageProcessor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/AbstractMessageProcessor.java
new file mode 100644
index 0000000000..6c6339c88e
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/AbstractMessageProcessor.java
@@ -0,0 +1,161 @@
+/*
+ * 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.jms.provider;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.lang.reflect.InvocationTargetException;
+import java.util.logging.Logger;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.ObjectMessage;
+import javax.jms.Session;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.oasisopen.sca.ServiceRuntimeException;
+
+/**
+ * Base MessageProcessor for the JMSBinding.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractMessageProcessor implements JMSMessageProcessor {
+ private static final Logger logger = Logger.getLogger(AbstractMessageProcessor.class.getName());
+
+ protected String operationPropertyName;
+ protected boolean xmlFormat = true;
+
+ public AbstractMessageProcessor(JMSBinding jmsBinding) {
+ this.operationPropertyName = jmsBinding.getOperationSelectorPropertyName();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.tuscany.binding.jms.OperationAndDataBinding#getOperationName(javax.jms.Message)
+ */
+ public String getOperationName(Message message) {
+ try {
+
+ return message.getStringProperty(operationPropertyName);
+
+ } catch (JMSException e) {
+ throw new JMSBindingException("Exception retreiving operation name from message", e);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.tuscany.binding.jms.OperationAndDataBinding#setOperationName(javax.jms.Message, java.lang.String)
+ */
+ public void setOperationName(String operationName, Message message) {
+ try {
+
+ message.setStringProperty(operationPropertyName, operationName);
+
+ } catch (JMSException e) {
+ throw new JMSBindingException("Exception setting the operation name on message", e);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.tuscany.binding.jms.OperationAndDataBinding#extractPayload(javax.jms.Session, java.lang.Object)
+ */
+ public Message insertPayloadIntoJMSMessage(Session session, Object o) {
+ return createJMSMessage(session, o);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.tuscany.binding.jms.OperationAndDataBinding#extractPayload(javax.jms.Message)
+ */
+ public Object extractPayloadFromJMSMessage(Message msg) {
+ try {
+ if (msg.getBooleanProperty(JMSBindingConstants.FAULT_PROPERTY)) {
+ Object exc = ((ObjectMessage)msg).getObject();
+ if (exc instanceof RuntimeException) {
+ throw new ServiceRuntimeException("remote service exception, see nested exception", (Throwable)exc);
+ } else {
+ return new InvocationTargetException((Throwable) exc);
+ }
+ }
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ return extractPayload(msg);
+ }
+
+ public Message createFaultMessage(Session session, Throwable o) {
+ if (session == null) {
+ logger.fine("no response session to create fault message: " + String.valueOf(o));
+ return null;
+ }
+ try {
+
+ ObjectMessage message = session.createObjectMessage();
+ if (o instanceof RuntimeException || o instanceof Error) {
+ int recursionKlugeDetector = 20;
+ Throwable rootCause = o;
+ Throwable deepRootCause = rootCause.getCause();
+ do {
+ if (rootCause == deepRootCause) {
+ break;
+ } else if (deepRootCause != null) {
+ rootCause = deepRootCause;
+ }
+
+ if (recursionKlugeDetector-- <= 0) {
+ break;
+ }
+ } while (deepRootCause != null);
+
+ final StringWriter sw = new StringWriter();
+ final PrintWriter pw = new PrintWriter(sw);
+ pw.print("Message = " + o.getMessage());
+ StackTraceElement[] stackElements = o.getStackTrace();
+ for (int i = 0; i < stackElements.length; i++) {
+ pw.print("\t>> \t at ");
+ pw.println(stackElements[i].toString());
+ }
+ pw.flush();
+
+ message.setObject(new RuntimeException( sw.toString() ));
+ } else {
+ message.setObject(o);
+ }
+ message.setBooleanProperty(JMSBindingConstants.FAULT_PROPERTY, true);
+ return message;
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ protected abstract Object extractPayload(Message msg);
+
+ protected abstract Message createJMSMessage(Session session, Object o);
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/BytesMessageProcessor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/BytesMessageProcessor.java
new file mode 100644
index 0000000000..7b14d29dfa
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/BytesMessageProcessor.java
@@ -0,0 +1,120 @@
+/*
+ * 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.jms.provider;
+
+import java.util.logging.Logger;
+
+import javax.jms.BytesMessage;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Session;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+
+/**
+ * MessageProcessor for sending/receiving javax.jms.BytesMessage with the JMSBinding.
+ *
+ * @version $Rev$ $Date$
+ */
+public class BytesMessageProcessor extends AbstractMessageProcessor {
+ private static final Logger logger = Logger.getLogger(AbstractMessageProcessor.class.getName());
+
+ public BytesMessageProcessor(JMSBinding jmsBinding, ExtensionPointRegistry registry) {
+ super(jmsBinding);
+ }
+
+/* TUSCANY-2967 - disable this change while we decide what to do and
+ * return faults as JMSObject messages to be consistent
+ * again with other wire formats
+ @Override
+ public Object extractPayloadFromJMSMessage(Message msg) {
+ byte [] bytes = (byte [])extractPayload(msg);
+
+ try {
+ if (msg.getBooleanProperty(JMSBindingConstants.FAULT_PROPERTY)) {
+ return new InvocationTargetException(new ServiceRuntimeException(new String(bytes)));
+ } else {
+ return bytes;
+ }
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+*/
+
+ @Override
+ protected Object extractPayload(Message msg) {
+ try {
+
+ if (!(msg instanceof BytesMessage)) {
+ throw new IllegalStateException("expecting JMS BytesMessage: " + msg);
+ }
+
+ long noOfBytes = ((BytesMessage)msg).getBodyLength();
+ byte [] bytes = new byte[(int)noOfBytes];
+ ((BytesMessage)msg).readBytes(bytes);
+ ((BytesMessage)msg).reset();
+ return bytes;
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+/* TUSCANY-2967 - disable this change while we decide what to do and
+ * return faults as JMSObject messages to be consistent
+ * again with other wire formats
+ @Override
+ public Message createFaultMessage(Session session, Throwable o) {
+ try {
+ Message message = createJMSMessage(session, o.toString().getBytes());
+ message.setBooleanProperty(JMSBindingConstants.FAULT_PROPERTY, true);
+ return message;
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+*/
+
+ @Override
+ protected Message createJMSMessage(Session session, Object o) {
+ if (session == null) {
+ logger.fine("no response session to create message: " + String.valueOf(o));
+ return null;
+ }
+ try {
+
+ // TODO - an experiment. How to enforce a single
+ // byte array parameter
+ BytesMessage message = session.createBytesMessage();
+
+ if (o != null){
+ message.writeBytes((byte[])o);
+ }
+
+ return message;
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultJMSResourceFactoryExtensionPoint.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultJMSResourceFactoryExtensionPoint.java
new file mode 100644
index 0000000000..32531fa6c3
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultJMSResourceFactoryExtensionPoint.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.jms.provider;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+
+public class DefaultJMSResourceFactoryExtensionPoint implements JMSResourceFactoryExtensionPoint {
+
+ public JMSResourceFactory createJMSResourceFactory(JMSBinding binding) {
+ return new JMSResourceFactoryImpl(binding.getConnectionFactoryName(), binding.getResponseConnectionFactoryName(), binding.getInitialContextFactoryName(), binding.getJndiURL());
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultMessageProcessor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultMessageProcessor.java
new file mode 100644
index 0000000000..c538dd01da
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultMessageProcessor.java
@@ -0,0 +1,302 @@
+/*
+ * 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.jms.provider;
+
+import java.io.IOException;
+import java.util.logging.Logger;
+
+import javax.jms.BytesMessage;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.common.xml.dom.DOMHelper;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.interfacedef.util.FaultException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
+/**
+ * MessageProcessor for sending/receiving XML over javax.jms.TextMessage or javax.jms.BytesMessage
+ * with the JMSBinding.
+ * This is very specific to the default wire format and is not tied into the usual hierarchy
+ * of message processors
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultMessageProcessor extends AbstractMessageProcessor {
+ private static final Logger logger = Logger.getLogger(DefaultMessageProcessor.class.getName());
+
+ private DOMHelper domHelper;
+
+ public DefaultMessageProcessor(JMSBinding jmsBinding, ExtensionPointRegistry registry) {
+ super(jmsBinding);
+ this.domHelper = DOMHelper.getInstance(registry);
+ }
+
+ // inherited methods that don't do anything useful
+ @Override
+ protected Message createJMSMessage(Session session, Object o) {
+ // should not be used
+ return null;
+ }
+
+ @Override
+ protected Object extractPayload(Message msg) {
+ // if it's not a text/bytes message or a fault then we don;t know what to do with it
+ return null;
+ }
+
+ // TODO - This makes the assumption that whatever the text/bytes configuration of the
+ // jms binding, unchecked faults will be sent as bytes.
+ @Override
+ public Message createFaultMessage(Session session, Throwable o) {
+ return createFaultJMSBytesMessage(session, o);
+ }
+
+ // handle text messages
+
+ public Object extractPayloadFromJMSTextMessage(Message msg, Node wrapper) {
+ if (msg instanceof TextMessage) {
+ try {
+ String xml = ((TextMessage) msg).getText();
+
+ Object os;
+ if (xml != null && xml.length() > 0) {
+ os = domHelper.load(xml);
+ } else {
+ os = null;
+ }
+
+ if (wrapper != null){
+ //don't modify the original wrapper since it will be reused
+ //clone the wrapper
+ Node node = ((Node)os);
+ if (node == null) {
+ node = domHelper.newDocument();
+ }
+ Element newWrapper = DOMHelper.createElement((Document)node, new QName(wrapper.getNamespaceURI(), wrapper.getLocalName()));
+ if (os != null){
+ Node child = node.getFirstChild();
+ newWrapper.appendChild(child);
+ }
+ return newWrapper;
+ }
+
+ return os;
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ } catch (IOException e) {
+ throw new JMSBindingException(e);
+ } catch (SAXException e) {
+ throw new JMSBindingException(e);
+ }
+ } else {
+ // handle the non-text fault case
+ return super.extractPayloadFromJMSMessage(msg);
+ }
+ }
+
+ public Message insertPayloadIntoJMSTextMessage(Session session, Object o, boolean unwrap) {
+
+ try {
+
+ TextMessage message = session.createTextMessage();
+
+ if (o instanceof Node) {
+
+ if (unwrap){
+ Node firstElement = ((Node)o).getFirstChild();
+ if (firstElement == null ) {
+ message.setText("");
+ } else {
+ message.setText(domHelper.saveAsString(firstElement));
+ }
+ }else {
+ message.setText(domHelper.saveAsString((Node)o));
+ }
+ } else if ((o instanceof Object[]) && ((Object[]) o)[0] instanceof Node) {
+ if (unwrap){
+ Node firstElement = ((Node)((Object[]) o)[0]).getFirstChild();
+ if (firstElement == null ) {
+ message.setText(null);
+ } else {
+ message.setText(domHelper.saveAsString(firstElement));
+ }
+ }else {
+ message.setText(domHelper.saveAsString((Node)((Object[])o)[0]));
+ }
+ } else if (o != null) {
+ throw new IllegalStateException("expecting Node payload: " + o);
+ }
+
+ return message;
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ public Message createFaultJMSTextMessage(Session session, Throwable o) {
+
+ if (session == null) {
+ logger.fine("no response session to create fault message: " + String.valueOf(o));
+ return null;
+ }
+ if (o instanceof FaultException) {
+ try {
+
+ TextMessage message = session.createTextMessage();
+ message.setText(domHelper.saveAsString((Node)((FaultException)o).getFaultInfo()));
+ message.setBooleanProperty(JMSBindingConstants.FAULT_PROPERTY, true);
+ return message;
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ } else {
+ // handle the non XML fault case
+ return super.createFaultMessage(session, o);
+ }
+ }
+
+ // handle bytes messages
+
+ public Object extractPayloadFromJMSBytesMessage(Message msg, Node wrapper) {
+
+ if (msg instanceof BytesMessage) {
+ try {
+ Object os;
+
+ long noOfBytes = ((BytesMessage) msg).getBodyLength();
+ byte[] bytes = new byte[(int) noOfBytes];
+ ((BytesMessage) msg).readBytes(bytes);
+ ((BytesMessage)msg).reset();
+
+ if ((bytes != null) && (bytes.length > 0)) {
+ os = domHelper.load(new String(bytes));
+ } else {
+ os = null;
+ }
+
+ if (wrapper != null){
+ //don't modify the original wrapper since it will be reused
+ //clone the wrapper
+ Node node = ((Node)os);
+ if (node == null) {
+ node = domHelper.newDocument();
+ }
+ Element newWrapper = DOMHelper.createElement((Document)node, new QName(wrapper.getNamespaceURI(), wrapper.getLocalName()));
+ if (os != null){
+ Node child = node.getFirstChild();
+ newWrapper.appendChild(child);
+ }
+ return newWrapper;
+ }
+
+ return os;
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ } catch (IOException e) {
+ throw new JMSBindingException(e);
+ } catch (SAXException e) {
+ throw new JMSBindingException(e);
+ }
+ } else {
+ // trap the non-bytes fault case
+ return super.extractPayloadFromJMSMessage(msg);
+ }
+ }
+
+ public Message insertPayloadIntoJMSBytesMessage(Session session, Object o, boolean unwrap) {
+
+ try {
+
+ BytesMessage message = session.createBytesMessage();
+
+
+ if (o instanceof Node) {
+ if (unwrap) {
+ Node firstElement = ((Node)o).getFirstChild();
+ if (firstElement == null ) {
+ //do nothing, the message will just be set with a byte[0]
+ } else {
+ message.writeBytes(domHelper.saveAsString(firstElement).getBytes());
+ }
+
+ } else {
+ message.writeBytes(domHelper.saveAsString((Node)o).getBytes());
+ }
+
+ } else if ((o instanceof Object[]) && ((Object[]) o)[0] instanceof Node) {
+ if (unwrap){
+ Node firstElement = ((Node)((Object[]) o)[0]).getFirstChild();
+ if (firstElement == null ) {
+ //do nothing, the message will just be set with a byte[0]
+ } else {
+ message.writeBytes(domHelper.saveAsString(firstElement).getBytes());
+ }
+
+ }else {
+ message.writeBytes(domHelper.saveAsString((Node)((Object[]) o)[0]).getBytes());
+ }
+ } else if (o != null) {
+ throw new IllegalStateException("expecting Node payload: " + o);
+ }
+
+ return message;
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ public Message createFaultJMSBytesMessage(Session session, Throwable o) {
+
+ if (session == null) {
+ logger.fine("no response session to create fault message: " + String.valueOf(o));
+ return null;
+ }
+
+ if (o instanceof FaultException) {
+ try {
+
+ BytesMessage message = session.createBytesMessage();
+ String s = domHelper.saveAsString((Node)((FaultException)o).getFaultInfo());
+ message.writeBytes(s.getBytes());
+ message.setBooleanProperty(JMSBindingConstants.FAULT_PROPERTY, true);
+ return message;
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ } else {
+ return super.createFaultMessage(session, o);
+ }
+ }
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingAsyncResponseInvoker.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingAsyncResponseInvoker.java
new file mode 100644
index 0000000000..f07e9de29f
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingAsyncResponseInvoker.java
@@ -0,0 +1,43 @@
+/*
+ * 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.jms.provider;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.invocation.InvokerAsyncResponse;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JMSBindingAsyncResponseInvoker implements InvokerAsyncResponse {
+
+ RuntimeEndpoint endpoint;
+
+ public JMSBindingAsyncResponseInvoker(ExtensionPointRegistry extensionPoints,
+ RuntimeEndpoint endpoint) {
+ this.endpoint = endpoint;
+ } // end constructor
+
+ public void invokeAsyncResponse(Message msg) {
+ // TODO
+ } // end method invokeAsyncResponse
+} // end class JMSBindingAsyncResponseInvoker \ No newline at end of file
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingProviderFactory.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingProviderFactory.java
new file mode 100644
index 0000000000..15bd8713f2
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingProviderFactory.java
@@ -0,0 +1,76 @@
+/*
+ * 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.jms.provider;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.host.DefaultJMSHostExtensionPoint;
+import org.apache.tuscany.sca.binding.jms.host.JMSHostExtensionPoint;
+import org.apache.tuscany.sca.binding.jms.host.JMSServiceListenerFactory;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+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;
+
+/**
+ * A factory from creating the JMS binding provider.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JMSBindingProviderFactory implements BindingProviderFactory<JMSBinding> {
+
+ private ExtensionPointRegistry extensionPoints;
+ private JMSResourceFactoryExtensionPoint jmsRFEP;
+ private JMSServiceListenerFactory serviceListenerFactory;
+
+ public JMSBindingProviderFactory(ExtensionPointRegistry extensionPoints) {
+ this.extensionPoints = extensionPoints;
+
+ jmsRFEP = (JMSResourceFactoryExtensionPoint)extensionPoints.getExtensionPoint(JMSResourceFactoryExtensionPoint.class);
+ if (jmsRFEP == null) {
+ jmsRFEP = new DefaultJMSResourceFactoryExtensionPoint();
+ extensionPoints.addExtensionPoint(jmsRFEP);
+ }
+
+ JMSHostExtensionPoint jmsHostExtensionPoint = (JMSHostExtensionPoint)extensionPoints.getExtensionPoint(JMSHostExtensionPoint.class);
+ if (jmsHostExtensionPoint == null) {
+ jmsHostExtensionPoint = new DefaultJMSHostExtensionPoint(extensionPoints);
+ extensionPoints.addExtensionPoint(jmsHostExtensionPoint);
+ }
+ serviceListenerFactory = jmsHostExtensionPoint.getJMSServiceListenerFactory();
+ }
+
+ public ReferenceBindingProvider createReferenceBindingProvider(RuntimeEndpointReference endpointReference) {
+ JMSResourceFactory jmsRF = jmsRFEP.createJMSResourceFactory((JMSBinding)endpointReference.getBinding());
+ return new JMSBindingReferenceBindingProvider(endpointReference, extensionPoints, jmsRF);
+ }
+
+ public ServiceBindingProvider createServiceBindingProvider(RuntimeEndpoint endpoint) {
+ JMSBinding binding = (JMSBinding)endpoint.getBinding();
+ JMSResourceFactory jmsRF = jmsRFEP.createJMSResourceFactory(binding);
+ return new JMSBindingServiceBindingProvider(extensionPoints, endpoint, serviceListenerFactory, extensionPoints, jmsRF);
+ }
+
+ public Class<JMSBinding> getModelType() {
+ return JMSBinding.class;
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java
new file mode 100644
index 0000000000..3471e68d6f
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java
@@ -0,0 +1,219 @@
+/*
+ * 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.jms.provider;
+
+import javax.jms.JMSException;
+import javax.jms.MessageListener;
+import javax.naming.NamingException;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.headers.HeaderReferenceInterceptor;
+import org.apache.tuscany.sca.binding.jms.host.AsyncResponseJMSServiceListener;
+import org.apache.tuscany.sca.binding.jms.host.JMSAsyncResponseInvoker;
+import org.apache.tuscany.sca.binding.jms.transport.TransportReferenceInterceptor;
+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.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.MessageFactory;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.EndpointReferenceAsyncProvider;
+import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.provider.WireFormatProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+import org.apache.tuscany.sca.work.WorkScheduler;
+
+/**
+ * Implementation of the JMS reference binding provider.
+ *
+ * This version supports native async service invocations
+ *
+ * @version $Rev$ $Date$
+ */
+public class JMSBindingReferenceBindingProvider implements EndpointReferenceAsyncProvider {
+
+ private RuntimeEndpointReference endpointReference;
+ private RuntimeComponentReference reference;
+ private JMSBinding jmsBinding;
+ private JMSResourceFactory jmsResourceFactory;
+ private InterfaceContract interfaceContract;
+ private ExtensionPointRegistry extensions;
+
+ private ProviderFactoryExtensionPoint providerFactories;
+
+ private WireFormatProviderFactory requestWireFormatProviderFactory;
+ private WireFormatProvider requestWireFormatProvider;
+
+ private WireFormatProviderFactory responseWireFormatProviderFactory;
+ private WireFormatProvider responseWireFormatProvider;
+
+ private AsyncResponseJMSServiceListener responseQueue = null;
+
+ public JMSBindingReferenceBindingProvider(RuntimeEndpointReference endpointReference, ExtensionPointRegistry extensions, JMSResourceFactory jmsResourceFactory) {
+ this.endpointReference = endpointReference;
+ this.reference = (RuntimeComponentReference) endpointReference.getReference();
+ this.jmsBinding = (JMSBinding) endpointReference.getBinding();
+ this.extensions = extensions;
+ this.jmsResourceFactory = jmsResourceFactory;
+
+ // Get the factories/providers for operation selection
+ this.providerFactories = extensions.getExtensionPoint(ProviderFactoryExtensionPoint.class);
+
+ // Get the factories/providers for wire format
+ this.requestWireFormatProviderFactory =
+ (WireFormatProviderFactory)providerFactories.getProviderFactory(jmsBinding.getRequestWireFormat().getClass());
+ if (this.requestWireFormatProviderFactory != null){
+ this.requestWireFormatProvider = requestWireFormatProviderFactory.createReferenceWireFormatProvider(endpointReference);
+ }
+
+ this.responseWireFormatProviderFactory =
+ (WireFormatProviderFactory)providerFactories.getProviderFactory(jmsBinding.getResponseWireFormat().getClass());
+ if (this.responseWireFormatProviderFactory != null){
+ this.responseWireFormatProvider = responseWireFormatProviderFactory.createReferenceWireFormatProvider(endpointReference);
+ }
+
+ // create an interface contract that reflects both request and response
+ // wire formats
+ try {
+ interfaceContract = (InterfaceContract)reference.getInterfaceContract().clone();
+
+ requestWireFormatProvider.configureWireFormatInterfaceContract(interfaceContract);
+ responseWireFormatProvider.configureWireFormatInterfaceContract(interfaceContract);
+ } catch (CloneNotSupportedException ex){
+ interfaceContract = reference.getInterfaceContract();
+ } // end try
+
+ // If the service is asyncInvocation, then create a fixed response location
+ if( endpointReference.isAsyncInvocation() ) {
+ String asyncCallbackName = endpointReference.getReference().getName() + "_asyncResponse";
+ jmsBinding.setResponseDestinationName(asyncCallbackName);
+ } // end if
+
+ } // end constructor
+
+ public Invoker createInvoker(Operation operation) {
+
+ if (jmsBinding.getDestinationName() == null) {
+ throw new JMSBindingException("No destination specified for reference " + reference.getName());
+ } // end if
+
+ if ( jmsBinding.getActivationSpecName() != null ) {
+ throw new JMSBindingException("Activation spec can not be specified on an SCA reference binding.");
+ }
+ Invoker invoker = null;
+ invoker = new RRBJMSBindingInvoker(operation, jmsResourceFactory, endpointReference);
+
+ return invoker;
+ } // end method createInvoker
+
+ public boolean supportsOneWayInvocation() {
+ return true;
+ }
+
+ public InterfaceContract getBindingInterfaceContract() {
+ return interfaceContract;
+ }
+
+ public void start() {
+ // If the reference is async invocation, then a response queue handler and associated JMS listener must be created
+ // and started
+ if (endpointReference.isAsyncInvocation()) {
+ // Create the JMS listener
+ FactoryExtensionPoint modelFactories = extensions.getExtensionPoint(FactoryExtensionPoint.class);
+ MessageFactory messageFactory = modelFactories.getFactory(MessageFactory.class);
+ MessageListener listener;
+ try {
+ listener = new JMSAsyncResponseInvoker(endpointReference, messageFactory, jmsResourceFactory);
+ } catch (NamingException e) {
+ throw new JMSBindingException("Unable to create JMSResponseInvoker", e);
+ } // end try
+
+ // Create the response queue handler
+ UtilityExtensionPoint utilities = extensions.getExtensionPoint(UtilityExtensionPoint.class);
+ WorkScheduler workScheduler = utilities.getUtility(WorkScheduler.class);
+
+ responseQueue = new AsyncResponseJMSServiceListener(listener,
+ jmsBinding.getResponseDestinationName(),
+ jmsBinding, workScheduler, jmsResourceFactory);
+ responseQueue.start();
+ } // end if
+
+ } // end method start
+
+ public void stop() {
+ try {
+ if( responseQueue != null ) {
+ responseQueue.stop();
+ } // end if
+
+ jmsResourceFactory.closeConnection();
+ jmsResourceFactory.closeResponseConnection();
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ } // end method stop
+
+ /*
+ * set up the reference binding wire with the right set of jms reference
+ * interceptors
+ */
+ public void configure() {
+
+ InvocationChain bindingChain = endpointReference.getBindingInvocationChain();
+
+ // add transport interceptor
+ bindingChain.addInterceptor(Phase.REFERENCE_BINDING_TRANSPORT,
+ new TransportReferenceInterceptor(jmsBinding,
+ jmsResourceFactory,
+ endpointReference) );
+
+ // add request wire format
+ bindingChain.addInterceptor(requestWireFormatProvider.getPhase(),
+ requestWireFormatProvider.createInterceptor());
+
+ // add response wire format, but only add it if it's different from the request
+ if (!jmsBinding.getRequestWireFormat().equals(jmsBinding.getResponseWireFormat())){
+ bindingChain.addInterceptor(responseWireFormatProvider.getPhase(),
+ responseWireFormatProvider.createInterceptor());
+ }
+
+ // add the header processor that comes after the wire formatter but before the
+ // policy interceptors
+ bindingChain.addInterceptor(Phase.REFERENCE_BINDING_WIREFORMAT,
+ new HeaderReferenceInterceptor(extensions,
+ jmsBinding,
+ jmsResourceFactory,
+ endpointReference) );
+ }
+
+ /**
+ * Indicates that this binding supports async invocations natively
+ */
+ public boolean supportsNativeAsync() {
+ return true;
+ } // end method supportsNativeAsync
+
+} // end class
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java
new file mode 100644
index 0000000000..b96376eb15
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java
@@ -0,0 +1,265 @@
+/*
+ * 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.jms.provider;
+
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.headers.HeaderServiceInterceptor;
+import org.apache.tuscany.sca.binding.jms.host.JMSServiceListener;
+import org.apache.tuscany.sca.binding.jms.host.JMSServiceListenerDetails;
+import org.apache.tuscany.sca.binding.jms.host.JMSServiceListenerFactory;
+import org.apache.tuscany.sca.binding.jms.transport.TransportServiceInterceptor;
+import org.apache.tuscany.sca.binding.jms.wire.AsyncResponseDestinationInterceptor;
+import org.apache.tuscany.sca.binding.jms.wire.CallbackDestinationInterceptor;
+import org.apache.tuscany.sca.binding.jms.wire.OperationPropertiesInterceptor;
+import org.apache.tuscany.sca.binding.sca.provider.SCABindingAsyncResponseInvoker;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.InvokerAsyncResponse;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.EndpointAsyncProvider;
+import org.apache.tuscany.sca.provider.EndpointProvider;
+import org.apache.tuscany.sca.provider.OperationSelectorProvider;
+import org.apache.tuscany.sca.provider.OperationSelectorProviderFactory;
+import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.provider.WireFormatProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ * Implementation of the JMS service binding provider.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JMSBindingServiceBindingProvider implements EndpointAsyncProvider, JMSServiceListenerDetails {
+ private static final Logger logger = Logger.getLogger(JMSBindingServiceBindingProvider.class.getName());
+
+ private ExtensionPointRegistry registry;
+ private RuntimeEndpoint endpoint;
+ private RuntimeComponentService service;
+ private Binding targetBinding;
+ private JMSBinding jmsBinding;
+ private JMSResourceFactory jmsResourceFactory;
+ private JMSServiceListenerFactory serviceListenerFactory;
+ private JMSServiceListener serviceListener;
+
+ private RuntimeComponent component;
+ private InterfaceContract interfaceContract;
+
+ private ProviderFactoryExtensionPoint providerFactories;
+ private FactoryExtensionPoint modelFactories;
+
+ private MessageFactory messageFactory;
+
+ private OperationSelectorProviderFactory operationSelectorProviderFactory;
+ private OperationSelectorProvider operationSelectorProvider;
+
+ private WireFormatProviderFactory requestWireFormatProviderFactory;
+ private WireFormatProvider requestWireFormatProvider;
+
+ private WireFormatProviderFactory responseWireFormatProviderFactory;
+ private WireFormatProvider responseWireFormatProvider;
+
+ public JMSBindingServiceBindingProvider(ExtensionPointRegistry registry, RuntimeEndpoint endpoint, JMSServiceListenerFactory serviceListenerFactory, ExtensionPointRegistry extensionPoints, JMSResourceFactory jmsResourceFactory) {
+ this.endpoint = endpoint;
+ this.component = (RuntimeComponent) endpoint.getComponent();
+ this.service = (RuntimeComponentService) endpoint.getService();
+ this.jmsBinding = (JMSBinding) endpoint.getBinding();
+ this.serviceListenerFactory = serviceListenerFactory;
+ this.targetBinding = jmsBinding;
+ this.jmsResourceFactory = jmsResourceFactory;
+ this.registry = registry;
+
+ if (jmsBinding.getResponseActivationSpecName() != null && jmsBinding.getResponseActivationSpecName().length() > 0) {
+ throw new JMSBindingException("[BJM30023] response/activationSpec element MUST NOT be present when the binding is being used for an SCA service");
+ }
+
+ // Set the default destination when using a connection factory.
+ // If an activation spec is being used, do not set the destination
+ // because the activation spec provides the destination.
+ if (jmsBinding.getDestinationName() == null &&
+ (jmsBinding.getActivationSpecName() == null || jmsBinding.getActivationSpecName().equals(""))) {
+// if (!service.isCallback()) { // TODO: 2.x migration, is this check needed?
+ // use the SCA service name as the default destination name
+ jmsBinding.setDestinationName(service.getName());
+// }
+ }
+
+ // Get Message factory
+ modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
+ messageFactory = modelFactories.getFactory(MessageFactory.class);
+
+ // Get the factories/providers for operation selection
+ this.providerFactories = extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class);
+ this.operationSelectorProviderFactory =
+ (OperationSelectorProviderFactory)providerFactories.getProviderFactory(jmsBinding.getOperationSelector().getClass());
+ if (this.operationSelectorProviderFactory != null){
+ this.operationSelectorProvider = operationSelectorProviderFactory.createServiceOperationSelectorProvider(endpoint);
+ }
+
+ // Get the factories/providers for wire format
+ this.requestWireFormatProviderFactory =
+ (WireFormatProviderFactory)providerFactories.getProviderFactory(jmsBinding.getRequestWireFormat().getClass());
+ if (this.requestWireFormatProviderFactory != null){
+ this.requestWireFormatProvider = requestWireFormatProviderFactory.createServiceWireFormatProvider(endpoint);
+ }
+
+ this.responseWireFormatProviderFactory =
+ (WireFormatProviderFactory)providerFactories.getProviderFactory(jmsBinding.getResponseWireFormat().getClass());
+ if (this.responseWireFormatProviderFactory != null){
+ this.responseWireFormatProvider = responseWireFormatProviderFactory.createServiceWireFormatProvider(endpoint);
+ }
+
+ // create an interface contract that reflects both request and response
+ // wire formats
+ try {
+ interfaceContract = (InterfaceContract)service.getInterfaceContract().clone();
+
+ requestWireFormatProvider.configureWireFormatInterfaceContract(interfaceContract);
+ responseWireFormatProvider.configureWireFormatInterfaceContract(interfaceContract);
+ } catch (CloneNotSupportedException ex){
+ interfaceContract = service.getInterfaceContract();
+ }
+ }
+
+ public InterfaceContract getBindingInterfaceContract() {
+ return interfaceContract;
+ }
+
+ public boolean supportsOneWayInvocation() {
+ return true;
+ }
+
+ public void start() {
+ try {
+
+ this.serviceListener = serviceListenerFactory.createJMSServiceListener(this);
+ serviceListener.start();
+
+ } catch (Exception e) {
+ if (e instanceof JMSBindingException) throw (JMSBindingException)e;
+ throw new JMSBindingException("Error starting JMSServiceBinding", e);
+ }
+ }
+
+ public void stop() {
+ try {
+ serviceListener.stop();
+ } catch (Exception e) {
+ if (e instanceof JMSBindingException) throw (JMSBindingException)e;
+ throw new JMSBindingException("Error stopping JMSServiceBinding", e);
+ }
+ }
+
+ public String getDestinationName() {
+ return serviceListener.getDestinationName();
+ }
+
+ /*
+ * Adds JMS specific interceptors to the binding chain
+ */
+ public void configure() {
+
+ InvocationChain bindingChain = endpoint.getBindingInvocationChain();
+
+ // add transport interceptor
+ bindingChain.addInterceptor(Phase.SERVICE_BINDING_TRANSPORT,
+ new TransportServiceInterceptor(registry, jmsBinding,
+ jmsResourceFactory,
+ endpoint) );
+
+ // add operation selector interceptor
+ bindingChain.addInterceptor(operationSelectorProvider.getPhase(),
+ operationSelectorProvider.createInterceptor());
+
+ // add operationProperties interceptor after operation selector
+ bindingChain.addInterceptor(Phase.SERVICE_BINDING_OPERATION_SELECTOR,
+ new OperationPropertiesInterceptor(jmsBinding, endpoint));
+
+ // add callback destination interceptor after operation selector
+ bindingChain.addInterceptor(Phase.SERVICE_BINDING_WIREFORMAT,
+ new CallbackDestinationInterceptor(endpoint));
+
+ bindingChain.addInterceptor(Phase.SERVICE_BINDING_WIREFORMAT, new HeaderServiceInterceptor(jmsBinding));
+
+ // add async response interceptor after header interceptor
+ bindingChain.addInterceptor(Phase.SERVICE_BINDING_WIREFORMAT,
+ new AsyncResponseDestinationInterceptor(endpoint));
+
+ // add request wire format
+ bindingChain.addInterceptor(requestWireFormatProvider.getPhase(),
+ requestWireFormatProvider.createInterceptor());
+
+ // add response wire format, but only add it if it's different from the request
+ if (!jmsBinding.getRequestWireFormat().equals(jmsBinding.getResponseWireFormat())){
+ bindingChain.addInterceptor(responseWireFormatProvider.getPhase(),
+ responseWireFormatProvider.createInterceptor());
+ }
+
+ }
+
+ public RuntimeComponent getComponent() {
+ return component;
+ }
+
+ public RuntimeComponentService getService() {
+ return service;
+ }
+
+ public Binding getTargetBinding() {
+ return targetBinding;
+ }
+
+ public JMSBinding getJmsBinding() {
+ return jmsBinding;
+ }
+
+ public MessageFactory getMessageFactory() {
+ return messageFactory;
+ }
+
+ public JMSResourceFactory getResourceFactory() {
+ return jmsResourceFactory;
+ }
+
+ public RuntimeEndpoint getEndpoint() {
+ return endpoint;
+ }
+
+ /**
+ * Indicates that this service binding does support native async service invocations
+ */
+ public boolean supportsNativeAsync() {
+ return true;
+ } // end method supportsNativeAsync
+
+ public InvokerAsyncResponse createAsyncResponseInvoker() {
+ return new JMSBindingAsyncResponseInvoker(null, endpoint);
+ } // end method createAsyncResponseInvoker
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessor.java
new file mode 100644
index 0000000000..821b9d7873
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessor.java
@@ -0,0 +1,55 @@
+/*
+ * 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.jms.provider;
+
+import javax.jms.Message;
+import javax.jms.Session;
+
+/**
+ * Interface for a component that does operation selection and message payload processing
+ *
+ * @version $Rev$ $Date$
+ */
+public interface JMSMessageProcessor {
+
+ /**
+ * Get the operation name from a JMS Message
+ */
+ String getOperationName(Message message);
+
+ /**
+ * Set the operation name on a JMS Message
+ */
+ void setOperationName(String operationName, Message message);
+
+ /**
+ * Extracts the payload from a JMS Message
+ */
+ Object extractPayloadFromJMSMessage(Message msg);
+
+ /**
+ * Create a JMS Message containing the payload
+ */
+ Message insertPayloadIntoJMSMessage(Session session, Object payload);
+
+ /**
+ * Create a JMS Message for reporting an exception
+ */
+ Message createFaultMessage(Session session, Throwable responsePayload);
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorUtil.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorUtil.java
new file mode 100644
index 0000000000..4b96f23d65
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorUtil.java
@@ -0,0 +1,113 @@
+/*
+ * 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.jms.provider;
+
+import java.lang.reflect.Constructor;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+
+/**
+ * Utility methods to load JMS message processors.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JMSMessageProcessorUtil {
+
+ /**
+ * Used to create instances of the JMSResourceFactory and RequestMessageProcessor and ResponseMessageProcessor from
+ * string based class name provided in the configuration
+ *
+ * @param cl ClassLoader
+ * @param className the string based class name to load and instantiate
+ * @return the new object
+ */
+ private static Object instantiate(ClassLoader cl, String className, JMSBinding binding) {
+ Object instance;
+ if (cl == null) {
+ cl = binding.getClass().getClassLoader();
+ }
+
+ try {
+ Class<?> clazz;
+
+ try {
+ clazz = cl.loadClass(className);
+ } catch (ClassNotFoundException e) {
+ clazz = binding.getClass().getClassLoader().loadClass(className);
+ }
+
+ Constructor<?> constructor = clazz.getDeclaredConstructor(new Class[] {JMSBinding.class});
+ instance = constructor.newInstance(binding);
+
+ } catch (Throwable e) {
+ throw new JMSBindingException("Exception instantiating OperationAndDataBinding class", e);
+ }
+
+ return instance;
+ }
+
+// public static JMSMessageProcessor getRequestMessageProcessor(JMSBinding binding) {
+// return (JMSMessageProcessor)instantiate(null, binding.getRequestMessageProcessorName(), binding);
+// }
+//
+// public static JMSMessageProcessor getResponseMessageProcessor(JMSBinding binding) {
+// return (JMSMessageProcessor)instantiate(null, binding.getResponseMessageProcessorName(), binding);
+// }
+//
+ private static Object instantiate(ClassLoader cl, String className, JMSBinding binding, ExtensionPointRegistry registry) {
+ Object instance;
+ if (cl == null) {
+ cl = binding.getClass().getClassLoader();
+ }
+
+ try {
+ Class<?> clazz;
+
+ try {
+ clazz = cl.loadClass(className);
+ } catch (ClassNotFoundException e) {
+ // MJE 07/12/2010 - for OSGi the default message processor belongs to the same bundle as
+ // this JMSMessageProcessorUtil itself and so the "correct" classloader to use is the classloader
+ // for THIS class, and not the binding class (which is a different bundle)
+ // clazz = binding.getClass().getClassLoader().loadClass(className);
+ clazz = JMSMessageProcessorUtil.class.getClassLoader().loadClass(className);
+ }
+
+ Constructor<?> constructor = clazz.getDeclaredConstructor(new Class[] {JMSBinding.class, ExtensionPointRegistry.class});
+ instance = constructor.newInstance(binding, registry);
+
+ } catch (Throwable e) {
+ throw new JMSBindingException("Exception instantiating OperationAndDataBinding class", e);
+ }
+
+ return instance;
+ }
+
+ public static JMSMessageProcessor getRequestMessageProcessor(ExtensionPointRegistry registry, JMSBinding binding) {
+ return (JMSMessageProcessor)instantiate(null, binding.getRequestMessageProcessorName(), binding, registry);
+ }
+
+ public static JMSMessageProcessor getResponseMessageProcessor(ExtensionPointRegistry registry, JMSBinding binding) {
+ return (JMSMessageProcessor)instantiate(null, binding.getResponseMessageProcessorName(), binding, registry);
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactory.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactory.java
new file mode 100644
index 0000000000..5aaeca4ebc
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactory.java
@@ -0,0 +1,99 @@
+/*
+ * 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.jms.provider;
+
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.naming.NamingException;
+import javax.resource.spi.ActivationSpec;
+
+public interface JMSResourceFactory {
+
+ /*
+ * This is a simple implementation where a connection is created per binding Ideally the resource factory should be
+ * able to leverage the host environment to provide connection pooling if it can. E.g. if Tuscany is running inside
+ * an AppServer Then we could leverage the JMS resources it provides
+ *
+ * @see org.apache.tuscany.binding.jms.JMSResourceFactory#getConnection()
+ */
+ public abstract Connection getConnection() throws NamingException, JMSException;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.tuscany.binding.jms.JMSResourceFactory#createSession()
+ */
+ public abstract Session createSession() throws JMSException, NamingException;
+
+ public abstract void closeSession(Session session) throws JMSException;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.tuscany.binding.jms.JMSResourceFactory#startConnection()
+ */
+ public abstract void startConnection() throws JMSException, NamingException;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.tuscany.binding.jms.JMSResourceFactory#closeConnection()
+ */
+ public abstract void closeConnection() throws JMSException;
+
+ public abstract Destination lookupDestination(String destName) throws NamingException;
+
+ /**
+ * You can create a destination in ActiveMQ (and have it appear in JNDI) by putting "dynamicQueues/" in front of the queue name being looked up
+ */
+ public abstract Destination createDestination(String jndiName) throws NamingException;
+
+ /*
+ * This is a simple implementation where a connection is created per binding Ideally the resource factory should be
+ * able to leverage the host environment to provide connection pooling if it can. E.g. if Tuscany is running inside
+ * an AppServer Then we could leverage the JMS resources it provides
+ *
+ * @see org.apache.tuscany.binding.jms.JMSResourceFactory#getConnection()
+ */
+ public abstract Connection getResponseConnection() throws NamingException, JMSException;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.tuscany.binding.jms.JMSResourceFactory#createSession()
+ */
+ public abstract Session createResponseSession() throws JMSException, NamingException;
+
+ public abstract void closeResponseSession(Session session) throws JMSException;
+
+ public abstract void closeResponseConnection() throws JMSException;
+
+ /*
+ * Indicates whether connections obtained using getConnection() or getResponseConnection()
+ * must be closed after each use. This is necessary in environments where connections are
+ * shared with other users, or where connections cannot be held across transaction boundaries.
+ */
+ public abstract boolean isConnectionClosedAfterUse();
+
+ public abstract ActivationSpec lookupActivationSpec(
+ String activationSpecName);
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryExtensionPoint.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryExtensionPoint.java
new file mode 100644
index 0000000000..afd2508043
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryExtensionPoint.java
@@ -0,0 +1,28 @@
+/*
+ * 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.jms.provider;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+
+public interface JMSResourceFactoryExtensionPoint {
+
+ JMSResourceFactory createJMSResourceFactory(JMSBinding binding);
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java
new file mode 100644
index 0000000000..7e56fb2329
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.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.jms.provider;
+
+import java.util.Properties;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.naming.NoInitialContextException;
+import javax.resource.spi.ActivationSpec;
+
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.extensibility.ClassLoaderContext;
+import org.apache.activemq.jndi.ActiveMQInitialContextFactory;
+
+/**
+ * Abstracts away any JMS provide specific feature from the JMS binding
+ *
+ * @version $Rev$ $Date$
+ */
+public class JMSResourceFactoryImpl implements JMSResourceFactory {
+
+ protected String initialContextFactoryName;
+ protected String connectionFactoryName = "ConnectionFactory";
+ protected String jndiURL;
+
+ protected Connection connection;
+ protected Context context;
+ protected boolean isConnectionStarted;
+ private Connection responseConnection;
+ private String responseConnectionFactoryName;
+
+ public JMSResourceFactoryImpl(String connectionFactoryName, String responseConnectionFactoryName, String initialContextFactoryName, String jndiURL) {
+ if (connectionFactoryName != null && connectionFactoryName.trim().length() > 0) {
+ this.connectionFactoryName = connectionFactoryName.trim();
+ }
+ if (responseConnectionFactoryName != null && responseConnectionFactoryName.trim().length() > 0) {
+ this.responseConnectionFactoryName = responseConnectionFactoryName.trim();
+ }
+ if (initialContextFactoryName != null && initialContextFactoryName.trim().length() > 0) {
+ this.initialContextFactoryName = initialContextFactoryName.trim();
+ }
+ if (jndiURL != null) {
+ this.jndiURL = jndiURL.trim();
+ }
+ }
+
+ /*
+ * This is a simple implementation where a connection is created per binding Ideally the resource factory should be
+ * able to leverage the host environment to provide connection pooling if it can. E.g. if Tuscany is running inside
+ * an AppServer Then we could leverage the JMS resources it provides
+ *
+ * @see org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory#getConnection()
+ */
+ public Connection getConnection() throws NamingException, JMSException {
+ if (connection == null) {
+ createConnection();
+ }
+ return connection;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory#createSession()
+ */
+ public Session createSession() throws JMSException, NamingException {
+ return getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory#closeSession(javax.jms.Session)
+ */
+ public void closeSession(Session session) throws JMSException {
+ session.close();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory#startConnection()
+ */
+ public void startConnection() throws JMSException, NamingException {
+ if (!isConnectionStarted) {
+ getConnection().start();
+ isConnectionStarted = true;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory#closeConnection()
+ */
+ public void closeConnection() throws JMSException {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (JMSException e) {
+ // if using an embedded broker then when shutting down Tuscany the broker may get closed
+ // before this stop method is called. I can't see how to detect that so for now just
+ // ignore the exception if the message is that the transport is already disposed
+ if (!e.getMessage().contains("disposed")) {
+ throw e;
+ }
+ }
+ }
+ }
+
+ protected void createConnection() throws NamingException, JMSException {
+ Object o = jndiLookUp(connectionFactoryName);
+ if (o == null) {
+ throw new JMSBindingException("connection factory not found: " + connectionFactoryName);
+ }
+ if (!(o instanceof ConnectionFactory)) {
+ throw new JMSBindingException("JNDI resource '" + connectionFactoryName +"' is not a JMS ConnectionFactory");
+ }
+ ConnectionFactory connectionFactory = (ConnectionFactory)o;
+ connection = connectionFactory.createConnection();
+ }
+
+ protected synchronized Context getInitialContext() throws NamingException {
+ if (context == null) {
+ Properties props = new Properties();
+
+ if (initialContextFactoryName != null) {
+ props.setProperty(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName);
+ }
+ if (jndiURL != null) {
+ props.setProperty(Context.PROVIDER_URL, jndiURL);
+ }
+
+ initJREEnvironment(props);
+
+ try {
+ // Load the JNDI InitialContext (will load the InitialContextFactory, if present)
+ context = new InitialContext(props);
+ if( context == null ) {
+ throw new NamingException();
+ } else if ( context.getEnvironment().get(InitialContext.INITIAL_CONTEXT_FACTORY) == null ) {
+ throw new NamingException();
+ } // end if
+ } catch (NamingException e ) {
+ context = getInitialContextOsgi( props );
+ } // end try
+ // In the case where the InitialContext fails, check whether performing an OSGi based load succeeds...
+
+
+ }
+ return context;
+ } // end method getInitialContext
+
+ static final String ACTIVEMQ_FACTORY = "org.apache.activemq.jndi.ActiveMQInitialContextFactory";
+ private Context getInitialContextOsgi( Properties props ) throws NamingException {
+ /**
+ * For OSGi, need to provide access to the InitialContextFactory for the JMS provider that is going to be used.
+ *
+ * The situation is that the InitialContext constructor instantiates an instance of the InitialContextFactory by
+ * calling "new" using the TCCL - thus there is a need to prepare the TCCL.
+ * 03/12/2010 MJE - for the present, only worry about ActiveMQ - other providers can be added later
+ * 10/12/2010 MJE - the following code attempts to get the classloader for the ActiveMQ initial context factory
+ * it will fail if the ActiveMQ classes are not available in the runtime, but the code will still
+ * execute (although under OSGi the new InitialContext() operation will fail to find a suitable
+ * InitialContextFactory object...)
+ */
+
+ String contextFactoryName = (String)props.get(Context.INITIAL_CONTEXT_FACTORY);
+
+ ClassLoader ActiveMQCl = null;
+ try {
+ if( contextFactoryName == null || ACTIVEMQ_FACTORY.equals(contextFactoryName) ) {
+ ActiveMQCl = ActiveMQInitialContextFactory.class.getClassLoader();
+ props.setProperty(Context.INITIAL_CONTEXT_FACTORY, ACTIVEMQ_FACTORY);
+ if( props.getProperty(Context.PROVIDER_URL) == null ) {
+ props.setProperty(Context.PROVIDER_URL, "vm://localhost?broker.persistent=false" );
+ } // end if
+ } // end if
+ } catch (Exception e) {
+ // Nothing to do in this case - the ActiveMQCl classloader will simply be null
+ } // end try
+
+ ClassLoader tccl = ClassLoaderContext.setContextClassLoader(JMSResourceFactoryImpl.class.getClassLoader(),
+ ActiveMQCl,
+ Thread.currentThread().getContextClassLoader() );
+ try {
+ // Load the JNDI InitialContext (will load the InitialContextFactory, if present)
+ return new InitialContext(props);
+ } finally {
+ // Restore the TCCL if we changed it
+ if( tccl != null ) Thread.currentThread().setContextClassLoader(tccl);
+ } // end try
+
+ } // end method getInitialContextOsgi
+
+
+ /**
+ * If using the WAS JMS Client with a non-IBM JRE then an additional
+ * environment property needs to be set to initialize the ORB correctly.
+ * See: http://www-1.ibm.com/support/docview.wss?uid=swg24012804
+ */
+ protected void initJREEnvironment(Properties props) {
+ if ("com.ibm.websphere.naming.WsnInitialContextFactory".equals(props.get(Context.INITIAL_CONTEXT_FACTORY))) {
+ String vendor = System.getProperty("java.vendor");
+ if (vendor == null || !vendor.contains("IBM")) {
+ props.setProperty("com.ibm.CORBA.ORBInit", "com.ibm.ws.sib.client.ORB");
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory#lookupDestination(java.lang.String)
+ */
+ public Destination lookupDestination(String destName) throws NamingException {
+ if (destName == null) {
+ return null;
+ }
+
+ Destination dest = (Destination)jndiLookUp(destName);
+ if (dest == null) {
+ dest = lookupPhysical(destName);
+ }
+ return dest;
+ }
+
+ protected Destination lookupPhysical(String jndiName) {
+
+ // TODO: the SCA JMS spec says a destination name may be a non-jndi plain destination name
+
+// Session session = null;
+// try {
+//
+// Destination dest;
+// session = createSession();
+// dest = session.createQueue(jndiName);
+// return dest;
+//
+// } catch (JMSException e) {
+// throw new JMSBindingException(e);
+// } catch (NamingException e) {
+// throw new JMSBindingException(e);
+// } finally {
+// if (session != null) {
+// try {
+// session.close();
+// } catch (JMSException e) {
+// throw new JMSBindingException(e);
+// }
+// }
+// }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory#createDestination(java.lang.String)
+ */
+ public Destination createDestination(String jndiName) throws NamingException {
+ if ( jndiName == null )
+ return null;
+
+ return lookupDestination("dynamicQueues/" + jndiName);
+ }
+
+ protected Object jndiLookUp(String name) {
+ Object o = null;
+ try {
+ o = getInitialContext().lookup("java:comp/env/" + name);
+ } catch (Exception ex) {
+ // ignore
+ }
+ if (o == null) {
+ try {
+ o = getInitialContext().lookup(name);
+ } catch (NamingException ex) {
+ // ignore
+ }
+ }
+ return o;
+ }
+
+ public Session createResponseSession() throws JMSException, NamingException {
+ return getResponseConnection().createSession(false, Session.AUTO_ACKNOWLEDGE);
+ }
+
+ public void closeResponseSession(Session session) throws JMSException {
+ session.close();
+ }
+
+ public Connection getResponseConnection() throws NamingException, JMSException {
+ if (responseConnection == null) {
+ if (responseConnectionFactoryName != null) {
+ ConnectionFactory connectionFactory = (ConnectionFactory)jndiLookUp(responseConnectionFactoryName);
+ if (connectionFactory == null) {
+ throw new JMSBindingException("connection factory not found: " + responseConnectionFactoryName);
+ }
+ responseConnection = connectionFactory.createConnection();
+ } else {
+ // if no response connection is defined in the SCDL use the request connection
+ responseConnection = getConnection();
+ }
+ }
+ return responseConnection;
+ }
+
+ public void closeResponseConnection() throws JMSException {
+ if (responseConnection != null && !responseConnection.equals(connection)) {
+ try {
+ responseConnection.close();
+ } catch (JMSException e) {
+ // if using an embedded broker then when shutting down Tuscany the broker may get closed
+ // before this stop method is called. I can't see how to detect that so for now just
+ // ignore the exception if the message is that the transport is already disposed
+ if (!e.getMessage().contains("disposed")) {
+ throw e;
+ }
+ }
+ }
+ }
+
+ public boolean isConnectionClosedAfterUse() {
+ // It is assumed this resource factory is used in an environment
+ // where the connection can be held for the life of the binding.
+ return false;
+ }
+
+ public ActivationSpec lookupActivationSpec(String activationSpecName) {
+ Object o = jndiLookUp(activationSpecName);
+ if ( o == null )
+ return null;
+ else if (o instanceof ActivationSpec)
+ return (ActivationSpec) o;
+
+ throw new JMSBindingException("Incorrect resource type for ActivationSpec: " + o.getClass().getName());
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java
new file mode 100644
index 0000000000..db0b94dce1
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java
@@ -0,0 +1,231 @@
+/*
+ * 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.jms.provider;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+import java.util.logging.Logger;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.ObjectMessage;
+import javax.jms.Session;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.oasisopen.sca.ServiceRuntimeException;
+
+/**
+ * MessageProcessor for sending/receiving Serializable objects with the JMSBinding.
+ *
+ */
+public class ObjectMessageProcessor extends AbstractMessageProcessor {
+ private static final Logger logger = Logger.getLogger(ObjectMessageProcessor.class.getName());
+
+ public ObjectMessageProcessor(JMSBinding jmsBinding, ExtensionPointRegistry registry) {
+ super(jmsBinding);
+ }
+
+ @Override
+ protected Message createJMSMessage(Session session, Object o) {
+ if (session == null) {
+ logger.fine("no response session to create message: " + String.valueOf(o));
+ return null;
+ }
+ try {
+
+ ObjectMessage message = session.createObjectMessage();
+
+ if (o != null){
+ if (!(o instanceof Serializable)) {
+ throw new IllegalStateException("JMS ObjectMessage payload not Serializable: " + o);
+ }
+
+ message.setObject((Serializable)o);
+ }
+
+ return message;
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ @Override
+ public Object extractPayloadFromJMSMessage(Message msg) {
+ try {
+ Object o = ((ObjectMessage)msg).getObject();
+ if (o instanceof Throwable ) {
+ if (o instanceof RuntimeException) {
+ throw new ServiceRuntimeException("remote service exception, see nested exception", (RuntimeException)o);
+ } else {
+ return new InvocationTargetException((Throwable) o);
+ }
+ }
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ return extractPayload(msg);
+ }
+
+ @Override
+ protected Object extractPayload(Message msg) {
+ try {
+
+ return ((ObjectMessage)msg).getObject();
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ // special methods for handling operations with single parameters
+
+ public Message createJMSMessageForSingleParamOperation(Session session, Object o, boolean wrapSingleInput) {
+ if (session == null) {
+ logger.fine("no response session to create message: " + String.valueOf(o));
+ return null;
+ }
+ try {
+
+ ObjectMessage message = session.createObjectMessage();
+
+ if (o != null) {
+ if (!(o instanceof Serializable)) {
+ throw new IllegalStateException("JMS ObjectMessage payload not Serializable: " + o);
+ }
+
+ // If the user has specifically requests that single parameters
+ // be wrapped then leave is as is as it will have already been
+ // wrapped by Tuscany. Otherwise unwrap it.
+ if (wrapSingleInput) {
+ message.setObject((Serializable) o);
+ } else { // unwrap from array
+ message.setObject((Serializable) ((Object[]) o)[0]);
+ }
+
+ }
+
+ return message;
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ public Object extractPayloadFromJMSMessageForSingleParamOperation(Message msg, Class<?> argType, boolean wrapSingle) {
+ // We always have a one arg operation if this method is called so we need to
+ // decide if the data on the wire is wrapped or not. This is the algorithm.
+ //
+ // If the payload is null then create an empty array and pass it on
+ // If the payload is not an array then it must represent an unwrapped
+ // single arg. Wrap it up and pass it on
+ // If the payload is an array then determine if it's a wrapped single arg or not
+ // If the service interface arg type matches the type of the array and not it's contents
+ // then it's an unwrapped argument so wrap it and pass it on
+ // If the service interface arg type matches the type of the contents and not the type
+ // of the array then the parameter is already wrapped so pass it on as is
+ // If the service interface arg type matches both the type of the
+ // array and the type of its contents then assume that the whole array is the
+ // parameter and decide whether to unwrap it or pass it on as is based on the
+ // setting of the wrapSingle attribute
+ //
+
+ try {
+ Object payload = ((ObjectMessage) msg).getObject();
+
+ if (payload instanceof Throwable) {
+ if (payload instanceof RuntimeException) {
+ throw new ServiceRuntimeException("remote service exception, see nested exception", (RuntimeException) payload);
+ } else {
+ return new InvocationTargetException((Throwable) payload);
+ }
+ }
+
+ if (payload == null) {
+ // methodA(null) was not wrapped on wire so wrap it here in order
+ // that it passes through the rest of the Tuscany wire successfully
+ return new Object[] { payload };
+ }
+
+ boolean payloadIsArray = payload.getClass().isArray();
+
+ // Non-array payload is single arg
+ if (!payloadIsArray) {
+ // methodB(arg) wasn't wrapped on wire so wrap it here in order
+ // that it passes through the rest of the Tuscany wire successfully
+ return new Object[] { payload };
+ } else {
+ int size = ((Object[]) payload).length;
+
+ // An initial quick check to determine whether the payload is not
+ // wrapped. If the array has anything other than a single entry
+ // then it's not the result of reference side wrapping so wrap it
+ // here and pass it on
+ if (size != 1) {
+ return new Object[] { payload };
+ }
+
+ // we know the array has only one entry now so get it
+ Object arrayContents = ((Object[]) payload)[0];
+
+ // Is the operation argument the same type as the array itself?
+ if (argType.isAssignableFrom(payload.getClass())) {
+
+ // So we believe that the whole array is the argument but need
+ // to check what is in the array to be sure
+ if (arrayContents == null) {
+ // There is nothing in the array so it could be an accident that
+ // the array type matches the argument type, e.g. op(Object)
+ // so rely on the wrapSingle setting to choose
+ if (wrapSingle) {
+ return payload;
+ } else {
+ return new Object[] { payload };
+ }
+ } else if (argType.isAssignableFrom(arrayContents.getClass())) {
+ // We can't tell as the argument type matches both the array type and
+ // the array contents type so use the wrapSingle setting to choose
+ if (wrapSingle) {
+ return payload;
+ } else {
+ return new Object[] { payload };
+ }
+ } else {
+ // So by now we know the whole array is intended to be the
+ // parameter to wrap it and send it on
+ return new Object[] { payload };
+ }
+
+ } else {
+ // The array type doesn't match the argument type so assume that the
+ // array contents will match the argument type and that hence the
+ // parameter is already wrapped so just send it as is. If the contents
+ // type doesn't match the argument type a exception will be thrown further
+ // along the wire
+ return payload;
+ }
+ }
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingInvoker.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingInvoker.java
new file mode 100644
index 0000000000..0e88b283dc
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingInvoker.java
@@ -0,0 +1,357 @@
+/*
+ * 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.jms.provider;
+
+import java.lang.reflect.InvocationTargetException;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.naming.NamingException;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.FaultException;
+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;
+
+/**
+ * Invoker for the JMS binding.
+ *
+ * @version $Rev$ $Date$
+ */
+public class RRBJMSBindingInvoker extends InterceptorAsyncImpl {
+
+ protected Operation operation;
+ protected String operationName;
+
+ protected JMSBinding jmsBinding;
+ protected JMSResourceFactory jmsResourceFactory;
+ protected Destination bindingRequestDest;
+ protected Destination bindingReplyDest;
+ protected RuntimeEndpointReference endpointReference;
+
+ public RRBJMSBindingInvoker(Operation operation, JMSResourceFactory jmsResourceFactory, RuntimeEndpointReference epr) {
+
+ this.operation = operation;
+ operationName = operation.getName();
+
+ this.endpointReference = epr;
+ this.jmsBinding = (JMSBinding) epr.getBinding();
+ this.jmsResourceFactory = jmsResourceFactory;
+
+ try {
+ // If this is a callback reference, the destination is determined dynamically based on
+ // properties of the inbound service request. We should not look for or require a
+ // statically-configured destination unless a message is received that does not have
+ // the necessary properties.
+ bindingRequestDest = lookupDestination();
+ bindingReplyDest = lookupResponseDestination();
+ } catch (NamingException e) {
+ throw new JMSBindingException(e);
+ } // end try
+ } // end constructor
+
+ /**
+ * Looks up the Destination Queue for the JMS Binding
+ *
+ * @return The Destination Queue
+ * @throws NamingException Failed to lookup Destination Queue
+ * @throws JMSBindingException Failed to lookup Destination Queue
+ * @see #lookupDestinationQueue(boolean)
+ */
+ protected Destination lookupDestination() throws NamingException, JMSBindingException {
+ return lookupDestinationQueue(false);
+ }
+
+ /**
+ * Looks up the Destination Response Queue for the JMS Binding
+ *
+ * @return The Destination Response Queue
+ * @throws NamingException Failed to lookup Destination Response Queue
+ * @throws JMSBindingException Failed to lookup Destination Response Queue
+ * @see #lookupDestinationQueue(boolean)
+ */
+ protected Destination lookupResponseDestination() throws NamingException, JMSBindingException {
+ return lookupDestinationQueue(true);
+ }
+
+ /**
+ * Looks up the Destination Queue for the JMS Binding.
+ * <p>
+ * What happens in the look up will depend on the create mode specified for the JMS Binding:
+ * <ul>
+ * <li>always - the JMS queue is always created. It is an error if the queue already exists
+ * <li>ifnotexist - the JMS queue is created if it does not exist. It is not an error if the queue already exists
+ * <li>never - the JMS queue is never created. It is an error if the queue does not exist
+ * </ul>
+ * See the SCA JMS Binding specification for more information.
+ * <p>
+ *
+ * @param isReponseQueue <code>true</code> if we are creating a response queue.
+ * <code>false</code> if we are creating a request queue
+ * @return The Destination queue.
+ * @throws NamingException Failed to lookup JMS queue
+ * @throws JMSBindingException Failed to lookup JMS Queue. Probable cause is that
+ * the JMS queue's current existence/non-existence is not compatible with
+ * the create mode specified on the binding
+ */
+ protected Destination lookupDestinationQueue(boolean isReponseQueue) throws NamingException, JMSBindingException {
+ String queueName;
+ String queueType;
+ String qCreateMode;
+
+ if (isReponseQueue) {
+ queueName = jmsBinding.getResponseDestinationName();
+ queueType = "JMS Response Destination ";
+ qCreateMode = jmsBinding.getResponseDestinationCreate();
+ if (queueName == null) {
+ return null;
+ }
+ } else {
+ queueName = jmsBinding.getDestinationName();
+ queueType = "JMS Destination ";
+ qCreateMode = jmsBinding.getDestinationCreate();
+ }
+
+ // Remove jms:jndi: prefix if present
+ if (queueName.startsWith("jms:jndi:")) {
+ queueName = queueName.substring("jms:jndi:".length());
+ }
+
+ Destination dest = jmsResourceFactory.lookupDestination(queueName);
+
+ if (qCreateMode.equals(JMSBindingConstants.CREATE_ALWAYS)) {
+ // In this mode, the queue must not already exist as we are creating it
+ if (dest != null) {
+ throw new JMSBindingException(queueType + queueName
+ + " already exists but has create mode of \""
+ + qCreateMode
+ + "\" while registering binding "
+ + jmsBinding.getName()
+ + " invoker");
+ }
+ // Create the queue
+ dest = jmsResourceFactory.createDestination(queueName);
+
+ } else if (qCreateMode.equals(JMSBindingConstants.CREATE_IF_NOT_EXIST)) {
+ // In this mode, the queue may nor may not exist. It will be created if it does not exist
+ // but don't create when using jms:jndi uri format
+ if (dest == null && !"jndi".equals(jmsBinding.getDestinationType())) {
+ dest = jmsResourceFactory.createDestination(queueName);
+ }
+
+ } else if (qCreateMode.equals(JMSBindingConstants.CREATE_NEVER)) {
+ // In this mode, the queue must have already been created.
+ if (dest == null) {
+ throw new JMSBindingException(queueType + queueName
+ + " not found but create mode of \""
+ + qCreateMode
+ + "\" while registering binding "
+ + jmsBinding.getName()
+ + " invoker");
+ }
+ }
+
+ // Make sure we ended up with a queue
+ if (dest == null) {
+ throw new JMSBindingException(queueType + queueName
+ + " not found with create mode of \""
+ + qCreateMode
+ + "\" while registering binding "
+ + jmsBinding.getName()
+ + " invoker");
+ }
+
+ return dest;
+ } // end method lookupDestinationQueue
+
+ /**
+ * Get the next in the chain from the binding invocation chain
+ */
+ public Invoker getNext() {
+ return (Invoker)endpointReference.getBindingInvocationChain().getHeadInvoker();
+ } // end method getNext
+
+
+ public org.apache.tuscany.sca.invocation.Message invoke(org.apache.tuscany.sca.invocation.Message tuscanyMsg) {
+ try {
+ // populate the message context with JMS binding information
+ JMSBindingContext context = new JMSBindingContext();
+ context.setJmsResourceFactory(jmsResourceFactory);
+ tuscanyMsg.setBindingContext(context);
+
+ // get a jms session to cover the creation and sending of the message
+ Session session = context.getJmsSession();
+
+ context.setRequestDestination(getRequestDestination(tuscanyMsg, session));
+ context.setReplyToDestination(getReplyToDestination(session));
+
+ try {
+ tuscanyMsg = endpointReference.getBindingInvocationChain().getHeadInvoker().invoke(tuscanyMsg);
+ } catch (ServiceRuntimeException e) {
+ if (e.getCause() instanceof InvocationTargetException) {
+ if ((e.getCause().getCause() instanceof RuntimeException)) {
+ tuscanyMsg.setFaultBody(e.getCause());
+ } else {
+ tuscanyMsg.setFaultBody(((InvocationTargetException)e.getCause()).getTargetException());
+ }
+ } else if (e.getCause() instanceof FaultException) {
+ tuscanyMsg.setFaultBody(e.getCause());
+ } else {
+ tuscanyMsg.setFaultBody(e);
+ }
+ } catch (IllegalStateException e) {
+ tuscanyMsg.setFaultBody(e);
+ } catch (Throwable e) {
+ tuscanyMsg.setFaultBody(e);
+ } finally {
+ context.closeJmsSession();
+ if (jmsResourceFactory.isConnectionClosedAfterUse()) {
+ jmsResourceFactory.closeConnection();
+ }
+ }
+
+ return tuscanyMsg;
+ } catch (Exception e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ protected Destination getRequestDestination(org.apache.tuscany.sca.invocation.Message tuscanyMsg, Session session) throws JMSBindingException, NamingException, JMSException {
+ Destination requestDestination;
+// if (!reference.isCallback()) { // TODO: 2.x migration, is this check needed?
+// String toURI = tuscanyMsg.getTo().getURI();
+// if (toURI != null && toURI.startsWith("jms:")) {
+// // the msg to uri contains the callback destination name
+// // this is an jms physical name not a jndi name so need to use session.createQueue
+// requestDestination = session.createQueue(toURI.substring(4));
+// } else {
+// requestDestination = lookupDestination();
+// }
+// } else {
+ requestDestination = bindingRequestDest;
+// }
+
+ return requestDestination;
+ }
+
+ protected Destination getReplyToDestination(Session session) throws JMSException, JMSBindingException, NamingException {
+ Destination replyToDest;
+ // [rfeng] If the oneway operation is part of bi-directional interface, the JMSReplyTo should be set
+ if (operation.isNonBlocking() && endpointReference.getComponentReferenceInterfaceContract()
+ .getCallbackInterface() == null) {
+ replyToDest = null;
+ } else {
+ if (bindingReplyDest != null) {
+ replyToDest = bindingReplyDest;
+ } else {
+ replyToDest = session.createTemporaryQueue();
+ }
+ }
+ return replyToDest;
+ }
+
+ /**
+ * Process forward request message
+ * @param tuscanyMsg - the request message
+ * @return the processed version of the request message
+ */
+ public Message processRequest(Message tuscanyMsg) {
+ try {
+ // populate the message context with JMS binding information
+ JMSBindingContext context = new JMSBindingContext();
+ context.setJmsResourceFactory(jmsResourceFactory);
+ tuscanyMsg.setBindingContext(context);
+
+ // get a JMS session to cover the creation and sending of the message
+ Session session = context.getJmsSession();
+
+ context.setRequestDestination(getRequestDestination(tuscanyMsg, session));
+ context.setReplyToDestination(getReplyToDestination(session));
+
+ return tuscanyMsg;
+ } catch (Exception e) {
+ throw new JMSBindingException(e);
+ } // end try
+ } // end method processRequest
+
+ /**
+ * Post processing for a request message where an error occurred
+ * @param tuscanyMsg
+ * @return the post processed message
+ */
+ public Message postProcessRequest(Message tuscanyMsg, Throwable e) {
+ // Exception handling
+ if ( e instanceof ServiceRuntimeException ) {
+ if (e.getCause() instanceof InvocationTargetException) {
+ if ((e.getCause().getCause() instanceof RuntimeException)) {
+ tuscanyMsg.setFaultBody(e.getCause());
+ } else {
+ tuscanyMsg.setFaultBody(((InvocationTargetException)e.getCause()).getTargetException());
+ } // end if
+ } else if (e.getCause() instanceof FaultException) {
+ tuscanyMsg.setFaultBody(e.getCause());
+ } else {
+ tuscanyMsg.setFaultBody(e);
+ } // end if
+ } else {
+ tuscanyMsg.setFaultBody(e);
+ } // end if
+
+ return postProcessRequest( tuscanyMsg );
+ } // end method postProcessRequest
+
+ /**
+ * General post processing for a request message
+ * - close out the JMS session & connection
+ * @param tuscanyMsg
+ * @return the post processed message
+ */
+ public Message postProcessRequest(Message tuscanyMsg) {
+ // Close of JMS session
+ try {
+ JMSBindingContext context = tuscanyMsg.getBindingContext();
+ context.closeJmsSession();
+ if (jmsResourceFactory.isConnectionClosedAfterUse()) {
+ jmsResourceFactory.closeConnection();
+ } // end if
+ } catch (JMSException ex) {
+ throw new JMSBindingException(ex);
+ } // end try
+ return tuscanyMsg;
+ } // end method postProcessRequest
+
+ /**
+ * Process response message
+ * @param tuscanyMsg - the response message
+ * @return the processed version of the response message
+ */
+ public Message processResponse(Message tuscanyMsg) {
+ // For async handling, there is nothing to do here
+ return tuscanyMsg;
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/TextMessageProcessor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/TextMessageProcessor.java
new file mode 100644
index 0000000000..b468c73e7a
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/TextMessageProcessor.java
@@ -0,0 +1,80 @@
+/*
+ * 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.jms.provider;
+
+import java.util.logging.Logger;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+
+/**
+ * MessageProcessor for sending/receiving javax.jms.TextMessage with the JMSBinding.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TextMessageProcessor extends AbstractMessageProcessor {
+ private static final Logger logger = Logger.getLogger(TextMessageProcessor.class.getName());
+
+ public TextMessageProcessor(JMSBinding jmsBinding, ExtensionPointRegistry registry) {
+ super(jmsBinding);
+ }
+
+ @Override
+ protected Object extractPayload(Message msg) {
+ try {
+
+ if (!(msg instanceof TextMessage)) {
+ throw new IllegalStateException("expecting JMS TextMessage: " + msg);
+ }
+
+ return ((TextMessage)msg).getText();
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ @Override
+ protected Message createJMSMessage(Session session, Object o) {
+ if (session == null) {
+ logger.fine("no response session to create message: " + String.valueOf(o));
+ return null;
+ }
+ try {
+
+ TextMessage message = session.createTextMessage();
+
+ if (o != null){
+ message.setText(String.valueOf(o));
+ }
+
+ return message;
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLBytesMessageProcessor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLBytesMessageProcessor.java
new file mode 100644
index 0000000000..69a69064d0
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLBytesMessageProcessor.java
@@ -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.
+ */
+package org.apache.tuscany.sca.binding.jms.provider;
+
+import java.io.IOException;
+import java.util.logging.Logger;
+
+import javax.jms.BytesMessage;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Session;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.common.xml.dom.DOMHelper;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.interfacedef.util.FaultException;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
+/**
+ * MessageProcessor for sending/receiving XML javax.jms.BytesMessage with the JMSBinding.
+ */
+public class XMLBytesMessageProcessor extends AbstractMessageProcessor {
+ private static final Logger logger = Logger.getLogger(XMLBytesMessageProcessor.class.getName());
+
+ private DOMHelper domHelper;
+
+ public XMLBytesMessageProcessor(JMSBinding jmsBinding, ExtensionPointRegistry registry) {
+ super(jmsBinding);
+ this.domHelper = DOMHelper.getInstance(registry);
+ }
+
+ @Override
+ protected Object extractPayload(Message msg) {
+ try {
+
+ if (!(msg instanceof BytesMessage)) {
+ throw new IllegalStateException("expecting JMS BytesMessage: " + msg);
+ }
+
+ long noOfBytes = ((BytesMessage)msg).getBodyLength();
+ byte [] bytes = new byte[(int)noOfBytes];
+ ((BytesMessage)msg).readBytes(bytes);
+ ((BytesMessage)msg).reset();
+
+ Object os;
+ if (noOfBytes > 0) {
+ os = domHelper.load(new String(bytes));
+ } else {
+ os = null;
+ }
+ return os;
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ } catch (IOException e) {
+ throw new JMSBindingException(e);
+ } catch (SAXException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ @Override
+ public Object extractPayloadFromJMSMessage(Message msg) {
+ if (msg instanceof BytesMessage) {
+ return extractPayload(msg);
+ } else {
+ return super.extractPayloadFromJMSMessage(msg);
+ }
+ }
+
+ @Override
+ protected Message createJMSMessage(Session session, Object o) {
+ if (session == null) {
+ logger.fine("no response session to create message: " + String.valueOf(o));
+ return null;
+ }
+ try {
+ BytesMessage message = session.createBytesMessage();
+
+ if (o instanceof Node) {
+ message.writeBytes(domHelper.saveAsString((Node)o).getBytes());
+ } else if ((o instanceof Object[]) && ((Object[])o)[0] instanceof Node) {
+ message.writeBytes(domHelper.saveAsString((Node)((Object[])o)[0]).getBytes());
+ } else if (o != null) {
+ throw new IllegalStateException("expecting Node payload: " + o);
+ }
+
+ return message;
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ @Override
+ public Message createFaultMessage(Session session, Throwable o) {
+
+ if (session == null) {
+ logger.fine("no response session to create fault message: " + String.valueOf(o));
+ return null;
+ }
+ if (o instanceof FaultException) {
+ try {
+
+ BytesMessage message = session.createBytesMessage();
+ message.writeBytes(domHelper.saveAsString((Node)((FaultException)o).getFaultInfo()).getBytes());
+ message.setBooleanProperty(JMSBindingConstants.FAULT_PROPERTY, true);
+ return message;
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ } else {
+ return super.createFaultMessage(session, o);
+ }
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLTextMessageProcessor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLTextMessageProcessor.java
new file mode 100644
index 0000000000..5031f55c6b
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLTextMessageProcessor.java
@@ -0,0 +1,132 @@
+/*
+ * 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.jms.provider;
+
+import java.io.IOException;
+import java.util.logging.Logger;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.common.xml.dom.DOMHelper;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.interfacedef.util.FaultException;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
+/**
+ * MessageProcessor for sending/receiving XML javax.jms.TextMessage with the JMSBinding.
+ *
+ * @version $Rev$ $Date$
+ */
+public class XMLTextMessageProcessor extends AbstractMessageProcessor {
+ private static final Logger logger = Logger.getLogger(XMLTextMessageProcessor.class.getName());
+
+ private DOMHelper domHelper;
+
+ public XMLTextMessageProcessor(JMSBinding jmsBinding, ExtensionPointRegistry registry) {
+ super(jmsBinding);
+ this.domHelper = DOMHelper.getInstance(registry);
+ }
+
+ @Override
+ protected Object extractPayload(Message msg) {
+ try {
+
+ String xml = ((TextMessage)msg).getText();
+ Object os;
+ if (xml != null) {
+ os = domHelper.load(xml);
+ } else {
+ os = null;
+ }
+ return os;
+
+ } catch (IOException e) {
+ throw new JMSBindingException(e);
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ } catch (SAXException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ @Override
+ public Object extractPayloadFromJMSMessage(Message msg) {
+ if (msg instanceof TextMessage) {
+ return extractPayload(msg);
+ } else {
+ return super.extractPayloadFromJMSMessage(msg);
+ }
+ }
+
+ @Override
+ protected Message createJMSMessage(Session session, Object o) {
+ if (session == null) {
+ logger.fine("no response session to create message: " + String.valueOf(o));
+ return null;
+ }
+ try {
+
+ TextMessage message = session.createTextMessage();
+
+ if (o instanceof Element) {
+ message.setText(domHelper.saveAsString((Node)o));
+ } else if ((o instanceof Object[]) && ((Object[])o)[0] instanceof Node) {
+ message.setText(domHelper.saveAsString((Node)((Object[])o)[0]));
+ } else if (o != null) {
+ throw new IllegalStateException("expecting Node payload: " + o);
+ }
+
+ return message;
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ @Override
+ public Message createFaultMessage(Session session, Throwable o) {
+ if (session == null) {
+ logger.fine("no response session to create fault message: " + String.valueOf(o));
+ return null;
+ }
+ if (o instanceof FaultException) {
+ try {
+
+ TextMessage message = session.createTextMessage();
+ message.setText(domHelper.saveAsString((Node)((FaultException)o).getFaultInfo()));
+ message.setBooleanProperty(JMSBindingConstants.FAULT_PROPERTY, true);
+ return message;
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ } else {
+ return super.createFaultMessage(session, o);
+ }
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportReferenceInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportReferenceInterceptor.java
new file mode 100644
index 0000000000..cba6022fb1
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportReferenceInterceptor.java
@@ -0,0 +1,187 @@
+/*
+ * 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.jms.transport;
+
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.naming.NamingException;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+/**
+ * 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 TransportReferenceInterceptor extends InterceptorAsyncImpl {
+
+ private Invoker next;
+ private JMSResourceFactory jmsResourceFactory;
+ private JMSBinding jmsBinding;
+
+ public TransportReferenceInterceptor(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeEndpointReference runtimeWire) {
+ super();
+ this.jmsBinding = jmsBinding;
+ this.jmsResourceFactory = jmsResourceFactory;
+ }
+
+ public Message invoke(Message msg) {
+ Message responseMsg = invokeRequest(msg);
+
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+
+ // [rfeng] For oneway operation as part of the bi-directional interface, the JMSReplyTo is present
+ if (context.getReplyToDestination() == null || msg.getOperation().isNonBlocking()) {
+ responseMsg.setBody(null);
+ } else {
+ responseMsg = invokeResponse(msg);
+ }
+
+ return responseMsg;
+ }
+
+ public Message invokeRequest(Message msg) {
+ try {
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ Session session = context.getJmsSession();
+
+ MessageProducer producer = session.createProducer(context.getRequestDestination());
+
+ // Set JMS header attributes in producer, not message.
+ String opName = msg.getOperation().getName();
+ if (jmsBinding.getEffectiveJMSTimeToLive(opName) != null) {
+ producer.setTimeToLive(jmsBinding.getEffectiveJMSTimeToLive(msg.getOperation().getName()).longValue());
+ }
+
+ Integer priority = jmsBinding.getEffectiveJMSPriority(opName);
+ if (priority != null) {
+ producer.setPriority(priority.intValue());
+ }
+
+ Boolean deliveryModePersistent = jmsBinding.getEffectiveJMSDeliveryMode(opName);
+ if (deliveryModePersistent != null) {
+ producer.setDeliveryMode( deliveryModePersistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
+ }
+
+ try {
+ producer.send((javax.jms.Message)msg.getBody());
+ } finally {
+ producer.close();
+ }
+ return msg;
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ } // end try
+ } // end method invokeRequest
+
+ public Message invokeResponse(Message msg) {
+ JMSBindingContext context = msg.getBindingContext();
+ try {
+ Session session = context.getJmsResponseSession();
+
+ javax.jms.Message requestMessage = (javax.jms.Message)msg.getBody();
+
+ String msgSelector = null;
+ String correlationScheme = jmsBinding.getCorrelationScheme();
+ if (correlationScheme == null || JMSBindingConstants.CORRELATE_MSG_ID.equalsIgnoreCase(correlationScheme)) {
+ msgSelector = "JMSCorrelationID = '" + requestMessage.getJMSMessageID() + "'";
+ } else if (JMSBindingConstants.CORRELATE_CORRELATION_ID.equalsIgnoreCase(correlationScheme)) {
+ msgSelector = "JMSCorrelationID = '" + requestMessage.getJMSCorrelationID() + "'";
+ }
+
+ MessageConsumer consumer;
+ if (msgSelector != null) {
+ consumer = session.createConsumer(context.getReplyToDestination(), msgSelector);
+ } else {
+ consumer = session.createConsumer(context.getReplyToDestination());
+ }
+
+ javax.jms.Message replyMsg;
+ try {
+ context.getJmsResourceFactory().startConnection();
+ //jmsResourceFactory.startConnection();
+ replyMsg = consumer.receive(context.getTimeToLive());
+ } finally {
+ consumer.close();
+ }
+ if (replyMsg == null) {
+ throw new JMSBindingException("No reply message received on " +
+ context.getReplyToDestination() +
+ " for message id " +
+ requestMessage.getJMSMessageID());
+ }
+
+ msg.setBody(replyMsg);
+ return msg;
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ } catch (NamingException e) {
+ throw new JMSBindingException(e);
+ } finally {
+ try {
+ context.closeJmsResponseSession();
+ if (jmsResourceFactory.isConnectionClosedAfterUse())
+ jmsResourceFactory.closeResponseConnection();
+ } catch (JMSException e) {
+ }
+ }
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ /**
+ * Process forward request message
+ * @param tuscanyMsg - the request message
+ * @return the processed version of the request message
+ */
+ public Message processRequest(Message tuscanyMsg) {
+ return invokeRequest(tuscanyMsg);
+ } // end method processRequest
+
+ /**
+ * Process response message
+ * @param tuscanyMsg - the response message
+ * @return the processed version of the response message
+ */
+ public Message processResponse(Message tuscanyMsg) {
+ // TODO Auto-generated method stub
+ return tuscanyMsg;
+ } // end method processResponse
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java
new file mode 100644
index 0000000000..df8f33bac3
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java
@@ -0,0 +1,284 @@
+/*
+ * 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.jms.transport;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.jms.DeliveryMode;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.naming.NamingException;
+
+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.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class TransportServiceInterceptor extends InterceptorAsyncImpl {
+ private static final Logger logger = Logger.getLogger(TransportServiceInterceptor.class.getName());
+
+ private Invoker next;
+ private JMSResourceFactory jmsResourceFactory;
+ private JMSBinding jmsBinding;
+ private JMSMessageProcessor responseMessageProcessor;
+ private RuntimeComponentService service;
+ private String correlationScheme;
+ private AssemblyFactory assemblyFactory;
+
+
+ public TransportServiceInterceptor(ExtensionPointRegistry registry, JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeEndpoint endpoint) {
+ super();
+ this.jmsBinding = jmsBinding;
+ this.jmsResourceFactory = jmsResourceFactory;
+ this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(registry, jmsBinding);
+ this.service = (RuntimeComponentService)endpoint.getService();
+ this.correlationScheme = jmsBinding.getCorrelationScheme();
+ FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ this.assemblyFactory = factories.getFactory(AssemblyFactory.class);
+ }
+
+ public Message invoke(Message msg) {
+ try {
+ return invokeResponse(next.invoke(invokeRequest(msg)));
+ } catch (Throwable e) {
+ logger.log(Level.SEVERE, "Exception invoking service '" + service.getName(), e);
+ JMSBindingContext context = msg.getBindingContext();
+ javax.jms.Message replyJMSMsg = responseMessageProcessor.createFaultMessage(context.getJmsResponseSession(),
+ (Throwable)e);
+ msg.setBody(replyJMSMsg);
+ invokeResponse(msg);
+ return msg;
+ } finally {
+ try {
+ ((JMSBindingContext)msg.getBindingContext()).closeJmsResponseSession();
+ if (jmsResourceFactory.isConnectionClosedAfterUse())
+ jmsResourceFactory.closeResponseConnection();
+ } catch (JMSException e) {
+ }
+ }
+ }
+
+ public Message invokeRequest(Message msg) {
+
+ EndpointReference from = assemblyFactory.createEndpointReference();
+ Endpoint fromEndpoint = assemblyFactory.createEndpoint();
+ from.setTargetEndpoint(fromEndpoint);
+ from.setStatus(EndpointReference.Status.WIRED_TARGET_FOUND_AND_MATCHED);
+ msg.setFrom(from);
+ Endpoint callbackEndpoint = assemblyFactory.createEndpoint();
+// callbackEndpoint.setURI(callbackAddress); // TODO: is this needed? Seems to work without it
+ callbackEndpoint.setUnresolved(true);
+ from.setCallbackEndpoint(callbackEndpoint);
+
+ return msg;
+
+ } // end method invokeRequest
+
+ public Message invokeResponse(Message msg) {
+ JMSBindingContext context = msg.getBindingContext();
+ try {
+
+ //if operation is oneway, return back.
+ Operation operation = msg.getOperation();
+ if (operation != null && operation.isNonBlocking()) {
+ return msg;
+ }
+
+ Session session = context.getJmsResponseSession();
+ javax.jms.Message requestJMSMsg = context.getJmsMsg();
+ javax.jms.Message responseJMSMsg = msg.getBody();
+
+ Destination replyDest = requestJMSMsg.getJMSReplyTo();
+ if (replyDest == null) {
+ if (jmsBinding.getResponseDestinationName() != null) {
+ try {
+ replyDest = jmsResourceFactory.lookupDestination(jmsBinding.getResponseDestinationName());
+ } catch (NamingException e) {
+ throw new JMSBindingException("Exception lookingup response destination", e);
+ }
+ }
+ }
+
+ if (replyDest == null) {
+ // assume no reply is expected
+ if (msg.getBody() != null) {
+ logger.log(Level.FINE, "JMS service '" + service.getName() + "' dropped response as request has no replyTo");
+ }
+ return msg;
+ }
+
+ if ((msg.getOperation() != null)) {
+ String operationName = msg.getOperation().getName();
+ if (jmsBinding.getEffectiveJMSPriority(operationName) != null) {
+ responseJMSMsg.setJMSPriority(jmsBinding.getEffectiveJMSPriority(operationName));
+ }
+
+ if ( jmsBinding.getEffectiveJMSType(operationName) != null) {
+ responseJMSMsg.setJMSType(jmsBinding.getEffectiveJMSType(operationName));
+ }
+
+ if ((jmsBinding.getEffectiveJMSDeliveryMode(operationName) != null)) {
+ responseJMSMsg.setJMSDeliveryMode(jmsBinding.getEffectiveJMSDeliveryMode(operationName) ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
+ }
+
+ if ((jmsBinding.getEffectiveJMSTimeToLive(operationName) != null)) {
+ responseJMSMsg.setJMSExpiration(jmsBinding.getEffectiveJMSTimeToLive(operationName).longValue());
+ }
+ }
+
+ if (correlationScheme == null ||
+ JMSBindingConstants.CORRELATE_MSG_ID.equalsIgnoreCase(correlationScheme)) {
+ responseJMSMsg.setJMSCorrelationID(requestJMSMsg.getJMSMessageID());
+ } else if (JMSBindingConstants.CORRELATE_CORRELATION_ID.equalsIgnoreCase(correlationScheme)) {
+ responseJMSMsg.setJMSCorrelationID(requestJMSMsg.getJMSCorrelationID());
+ }
+
+ MessageProducer producer = session.createProducer(replyDest);
+
+ // Set jms header attributes in producer, not message.
+ int deliveryMode = requestJMSMsg.getJMSDeliveryMode();
+ producer.setDeliveryMode(deliveryMode);
+ int deliveryPriority = requestJMSMsg.getJMSPriority();
+ producer.setPriority(deliveryPriority);
+ long timeToLive = requestJMSMsg.getJMSExpiration();
+ producer.setTimeToLive(timeToLive);
+
+ producer.send((javax.jms.Message)msg.getBody());
+
+ producer.close();
+
+ return msg;
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ } finally {
+ context.closeJmsResponseSession();
+ }
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Message processRequest(Message msg) {
+ return invokeRequest( msg );
+ } // end method processRequest
+
+ public Message processResponse(Message msg) {
+ JMSBindingContext context = msg.getBindingContext();
+ try {
+ Session session = context.getJmsResponseSession();
+ javax.jms.Message requestJMSMsg = context.getJmsMsg();
+ javax.jms.Message responseJMSMsg = msg.getBody();
+
+ Destination replyDest = requestJMSMsg.getJMSReplyTo();
+ if (replyDest == null) {
+ if (jmsBinding.getResponseDestinationName() != null) {
+ try {
+ replyDest = jmsResourceFactory.lookupDestination(jmsBinding.getResponseDestinationName());
+ } catch (NamingException e) {
+ throw new JMSBindingException("Exception lookingup response destination", e);
+ }
+ }
+ } // end if
+
+ if (replyDest == null) {
+ // assume no reply is expected
+ if (msg.getBody() != null) {
+ logger.log(Level.FINE, "JMS service '" + service.getName() + "' dropped response as request has no replyTo");
+ }
+ return msg;
+ } // end if
+
+ if ((msg.getOperation() != null)) {
+ String operationName = msg.getOperation().getName();
+ if (jmsBinding.getEffectiveJMSPriority(operationName) != null) {
+ responseJMSMsg.setJMSPriority(jmsBinding.getEffectiveJMSPriority(operationName));
+ }
+
+ if ( jmsBinding.getEffectiveJMSType(operationName) != null) {
+ responseJMSMsg.setJMSType(jmsBinding.getEffectiveJMSType(operationName));
+ }
+
+ if ((jmsBinding.getEffectiveJMSDeliveryMode(operationName) != null)) {
+ responseJMSMsg.setJMSDeliveryMode(jmsBinding.getEffectiveJMSDeliveryMode(operationName) ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
+ }
+
+ if ((jmsBinding.getEffectiveJMSTimeToLive(operationName) != null)) {
+ responseJMSMsg.setJMSExpiration(jmsBinding.getEffectiveJMSTimeToLive(operationName).longValue());
+ }
+ }
+
+ if (correlationScheme == null ||
+ JMSBindingConstants.CORRELATE_MSG_ID.equalsIgnoreCase(correlationScheme)) {
+ responseJMSMsg.setJMSCorrelationID(requestJMSMsg.getJMSMessageID());
+ } else if (JMSBindingConstants.CORRELATE_CORRELATION_ID.equalsIgnoreCase(correlationScheme)) {
+ responseJMSMsg.setJMSCorrelationID(requestJMSMsg.getJMSCorrelationID());
+ }
+
+ MessageProducer producer = session.createProducer(replyDest);
+
+ // Set jms header attributes in producer, not message.
+ int deliveryMode = requestJMSMsg.getJMSDeliveryMode();
+ producer.setDeliveryMode(deliveryMode);
+ int deliveryPriority = requestJMSMsg.getJMSPriority();
+ producer.setPriority(deliveryPriority);
+ long timeToLive = requestJMSMsg.getJMSExpiration();
+ producer.setTimeToLive(timeToLive);
+
+ producer.send((javax.jms.Message)msg.getBody());
+
+ producer.close();
+
+ return msg;
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ } finally {
+ context.closeJmsResponseSession();
+ } // end try
+ } // end method processResponse
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/AsyncResponseDestinationInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/AsyncResponseDestinationInterceptor.java
new file mode 100644
index 0000000000..43bf090796
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/AsyncResponseDestinationInterceptor.java
@@ -0,0 +1,194 @@
+/*
+ * 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.jms.wire;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.Topic;
+import javax.naming.NamingException;
+
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.core.invocation.AsyncResponseInvoker;
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ * JMS Binding Interceptor class that deals with destination address & ID for an async response on the service side
+ *
+ */
+public class AsyncResponseDestinationInterceptor extends InterceptorAsyncImpl {
+ private Invoker next;
+ private RuntimeComponentService service;
+ private RuntimeEndpoint endpoint;
+
+ public AsyncResponseDestinationInterceptor(RuntimeEndpoint endpoint) {
+ super();
+ this.service = (RuntimeComponentService) endpoint.getService();
+ this.endpoint = endpoint;
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Message invoke(Message msg) {
+ return next.invoke(invokeRequest(msg));
+ }
+
+ /**
+ * Handle an invocation request messaage
+ * @param msg the message
+ * @return the updated message
+ */
+ public Message invokeRequest(Message msg) {
+ try {
+ // Get the JMS context
+ JMSBindingContext context = msg.getBindingContext();
+ javax.jms.Message jmsMsg = context.getJmsMsg();
+
+ // Extract the Callback destination name header, if present
+ String asyncRespAddr = jmsMsg.getStringProperty(JMSBindingConstants.CALLBACK_Q_PROPERTY);
+
+ if (asyncRespAddr != null) {
+ asyncRespAddr = stripJMSPrefix( asyncRespAddr );
+ } else {
+ // If there is no Callback destination name header present, but the service is async, use the JMS ReplyTo header
+ if ( isAsync(service) ) {
+ if ( ( jmsMsg.getJMSReplyTo() != null ) ) {
+ Destination replyTo = jmsMsg.getJMSReplyTo();
+ if (replyTo != null) {
+ asyncRespAddr = (replyTo instanceof Queue) ? ((Queue) replyTo).getQueueName() : ((Topic) replyTo).getTopicName();
+ }
+ } // end if
+ } // end if
+ } // end if
+
+ // If there is no response address, we're done
+ if( asyncRespAddr == null ) return msg;
+
+ // Get the message ID - assume that the interceptor for obtaining the message ID is earlier in the chain
+ // than this interceptor
+ String msgID = (String)msg.getHeaders().get("MESSAGE_ID");
+
+ // Create a response invoker and add it to the message headers
+ AsyncResponseInvoker<String> respInvoker = new AsyncResponseInvoker<String>(endpoint, null, asyncRespAddr, msgID);
+ msg.getHeaders().put("ASYNC_RESPONSE_INVOKER", respInvoker);
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ } // end try
+
+ return msg;
+ } // end method invokeRequest
+
+ public Message processRequest(Message msg) {
+ return invokeRequest(msg);
+ } // end method processRequest
+
+ /**
+ * Process a response message
+ * - if it is an async response, there will be a header "ASYNC_RESPONSE_INVOKER" which contains
+ * the address of the JMS queue to reply to plus a message ID of the original message
+ * These values are used to create the Destination for the JMS message and to add a "RELATES_TO"
+ * header which is sent with the response message to allow the client to correlate the response
+ * to the original request
+ * @param msg - the Tuscany message
+ * @returns - the updated Tuscany message
+ */
+ public Message processResponse(Message msg) {
+ @SuppressWarnings("unchecked")
+ AsyncResponseInvoker<String> respInvoker = (AsyncResponseInvoker<String>)msg.getHeaders().get("ASYNC_RESPONSE_INVOKER");
+ if ( respInvoker == null ) return msg;
+
+ String responseAddress = respInvoker.getResponseTargetAddress();
+ String relatedMsg = respInvoker.getRelatesToMsgID();
+
+ // Get the JMS context
+ JMSBindingContext context = msg.getBindingContext();
+ JMSResourceFactory jmsResourceFactory = context.getJmsResourceFactory();
+ Destination dest;
+ try {
+ dest = jmsResourceFactory.lookupDestination(responseAddress);
+ if( dest == null ) {
+ dest = jmsResourceFactory.createDestination(responseAddress);
+ } // end if
+ } catch (NamingException e) {
+ throw new JMSBindingException(e);
+ }
+ context.setReplyToDestination(dest);
+ msg.getHeaders().put("RELATES_TO", relatedMsg);
+
+ return msg;
+ } // end method processResponse
+
+ /**
+ * Utility that strips the leading "jms:jndi:" prefix from a JMS address
+ * @param asyncRespAddr - the JMS address
+ * @return - the JMS address with the prefix removed
+ * @throws JMSBindingException if the JMS address does not have a prefix
+ */
+ private String stripJMSPrefix(String asyncRespAddr) {
+ // If present, strip any leading "jms:jndi:" string
+ if (!asyncRespAddr.startsWith("jms:jndi:")) {
+ throw new JMSBindingException("message property " + JMSBindingConstants.CALLBACK_Q_PROPERTY + " does not start with 'jms:jndi:' found: " + asyncRespAddr);
+ } else {
+ return asyncRespAddr.substring(9);
+ } // end if
+ } // end method stripJMSPrefix
+
+ /**
+ * Determines if a service has an interface that is async invocation
+ * @param service - the service
+ * @return true if the service is async, false otherwise
+ */
+ private boolean isAsync( RuntimeComponentService service ) {
+ service.getInterfaceContract().getInterface();
+
+ Iterator<Intent> intents = service.getRequiredIntents().iterator();
+ while ( intents.hasNext() ) {
+ Intent intent = intents.next();
+ if ( intent.getName().getLocalPart().equals("asyncInvocation") ) return true;
+ } // end while
+
+ intents = service.getInterfaceContract().getInterface().getRequiredIntents().iterator();
+ while ( intents.hasNext() ) {
+ Intent intent = intents.next();
+ if ( intent.getName().getLocalPart().equals("asyncInvocation") ) return true;
+ } // end while
+ return false;
+ } // end method isAsync
+} // end class \ No newline at end of file
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java
new file mode 100644
index 0000000000..9e14ad0b1a
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.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.jms.wire;
+
+import java.util.List;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.Topic;
+
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ * JMS Binding Interceptor class that deals with a callback destination address on the service side
+ *
+ */
+public class CallbackDestinationInterceptor extends InterceptorAsyncImpl {
+ private Invoker next;
+ private RuntimeComponentService service;
+ private RuntimeEndpoint endpoint;
+
+ public CallbackDestinationInterceptor(RuntimeEndpoint endpoint) {
+ super();
+ this.service = (RuntimeComponentService) endpoint.getService();
+ this.endpoint = endpoint;
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Message invoke(Message msg) {
+ return next.invoke(invokeRequest(msg));
+ }
+
+ /**
+ * Handle an invocation request messaage
+ * @param msg the message
+ * @return the updated message
+ */
+ public Message invokeRequest(Message msg) {
+ try {
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ javax.jms.Message jmsMsg = context.getJmsMsg();
+
+ // Extract the Callback destination name header, if present
+ String callbackdestName = jmsMsg.getStringProperty(JMSBindingConstants.CALLBACK_Q_PROPERTY);
+
+ if (callbackdestName != null) {
+ // If present, strip any leading "jms:jndi:" string
+ if (!callbackdestName.startsWith("jms:jndi:")) {
+ throw new JMSBindingException("message property " + JMSBindingConstants.CALLBACK_Q_PROPERTY + " does not start with 'jms:jndi:' found: " + callbackdestName);
+ } else {
+ callbackdestName = callbackdestName.substring(9);
+ } // end if
+ } else {
+ // If there is no Callback destination name header present, but the service is a callback, use the JMS ReplyTo header
+ if (service.getInterfaceContract().getCallbackInterface() != null) {
+ if ( ( jmsMsg.getJMSReplyTo() != null ) && msg.getOperation().isNonBlocking() ) {
+ Destination replyTo = jmsMsg.getJMSReplyTo();
+ if (replyTo != null) {
+ callbackdestName = (replyTo instanceof Queue) ? ((Queue) replyTo).getQueueName() : ((Topic) replyTo).getTopicName();
+ }
+ } // end if
+ } // end if
+ } // end if
+
+ // Place the Callback destination name into the Callback EPRs for the service endpoint
+ if (callbackdestName != null) {
+ List<EndpointReference> refs = endpoint.getCallbackEndpointReferences();
+ for (EndpointReference ref : refs ) {
+ if (ref.getBinding() instanceof JMSBinding ) {
+ JMSBinding callbackBinding = (JMSBinding) ref.getBinding();
+ callbackBinding.setDestinationName(callbackdestName);
+ } // end if
+ } // end for
+ } // end if
+
+// Callback ID not used at present
+// String callbackID = jmsMsg.getStringProperty(JMSBindingConstants.CALLBACK_ID_PROPERTY);
+// if (callbackID != null) {
+// parameters.setCallbackID(callbackID);
+// }
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ } // end try
+
+ return msg;
+ } // end method invokeRequest
+
+ public Message processRequest(Message msg) {
+ return invokeRequest(msg);
+ } // end method processRequest
+
+ public Message processResponse(Message msg) {
+ return msg;
+ } // end method processResponse
+} // end class \ No newline at end of file
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/OperationPropertiesInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/OperationPropertiesInterceptor.java
new file mode 100644
index 0000000000..682c9ee48c
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/OperationPropertiesInterceptor.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.jms.wire;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+public class OperationPropertiesInterceptor extends InterceptorAsyncImpl {
+ private Invoker next;
+ private JMSBinding jmsBinding;
+ private RuntimeComponentService service;
+ private List<Operation> serviceOperations;
+
+ public OperationPropertiesInterceptor(JMSBinding jmsBinding, RuntimeEndpoint endpoint) {
+ super();
+ this.jmsBinding = jmsBinding;
+ this.service = (RuntimeComponentService) endpoint.getService();
+ this.serviceOperations = service.getInterfaceContract().getInterface().getOperations();
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Message invoke(Message msg) {
+ return next.invoke(invokeRequest(msg));
+ }
+
+ public Message invokeRequest(Message msg) {
+ // TODO - could probably optimize this better
+ String operationName = msg.getOperation().getName();
+ String operationNameOverride = jmsBinding.getNativeOperationName(operationName);
+ for (Operation op : serviceOperations) {
+ if (op.getName().equals(operationNameOverride)) {
+ msg.setOperation(op);
+ break;
+ }
+ }
+ return msg;
+ }
+
+ public Message processRequest(Message msg) {
+ return invokeRequest(msg);
+ } // end method processRequest
+
+ public Message processResponse(Message msg) {
+ return msg;
+ } // end method processResponse
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesProviderFactory.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesProviderFactory.java
new file mode 100644
index 0000000000..7675698cc7
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesProviderFactory.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.jms.wireformat.jmsbytes.runtime;
+
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytes;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.provider.WireFormatProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireFormatJMSBytesProviderFactory implements WireFormatProviderFactory<WireFormatJMSBytes> {
+ private ExtensionPointRegistry registry;
+
+ public WireFormatJMSBytesProviderFactory(ExtensionPointRegistry registry) {
+ super();
+ this.registry = registry;
+ }
+
+ /**
+ */
+ public WireFormatProvider createReferenceWireFormatProvider(RuntimeEndpointReference endpointReference) {
+ return new WireFormatJMSBytesReferenceProvider(registry, endpointReference);
+ }
+
+ /**
+ */
+ public WireFormatProvider createServiceWireFormatProvider(RuntimeEndpoint endpoint) {
+ return new WireFormatJMSBytesServiceProvider(registry, endpoint);
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType()
+ */
+ public Class getModelType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceInterceptor.java
new file mode 100644
index 0000000000..0b2bcbd7b3
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceInterceptor.java
@@ -0,0 +1,133 @@
+/*
+ * 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.jms.wireformat.jmsbytes.runtime;
+
+
+import java.lang.reflect.InvocationTargetException;
+
+import javax.jms.JMSException;
+import javax.jms.Session;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytes;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class WireFormatJMSBytesReferenceInterceptor extends InterceptorAsyncImpl {
+
+ private Invoker next;
+ private RuntimeEndpointReference endpointReference;
+ private JMSResourceFactory jmsResourceFactory;
+ private JMSBinding jmsBinding;
+ private JMSMessageProcessor requestMessageProcessor;
+ private JMSMessageProcessor responseMessageProcessor;
+
+ public WireFormatJMSBytesReferenceInterceptor(ExtensionPointRegistry registry, JMSResourceFactory jmsResourceFactory, RuntimeEndpointReference endpointReference) {
+ super();
+ this.endpointReference = endpointReference;
+ this.jmsBinding = (JMSBinding) endpointReference.getBinding();
+ this.jmsResourceFactory = jmsResourceFactory;
+ this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(registry, jmsBinding);
+ this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(registry, jmsBinding);
+ }
+
+ public Message invoke(Message msg) {
+ if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSBytes){
+ msg = invokeRequest(msg);
+ }
+
+ msg = getNext().invoke(msg);
+
+ if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSBytes){
+ msg = invokeResponse(msg);
+ }
+
+ return msg;
+ }
+
+ public Message invokeRequest(Message msg) {
+ try {
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ Session session = context.getJmsSession();
+
+ Object[] requestParams = msg.getBody();
+ javax.jms.Message requestMsg = null;
+ if (requestParams != null && requestParams.length > 0 ){
+ requestMsg = requestMessageProcessor.insertPayloadIntoJMSMessage(session, requestParams[0]);
+ } else {
+ requestMsg = requestMessageProcessor.insertPayloadIntoJMSMessage(session, null);
+ }
+ msg.setBody(requestMsg);
+
+ requestMsg.setJMSReplyTo(context.getReplyToDestination());
+
+ return msg;
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ public Message invokeResponse(Message msg) {
+ if (msg.getBody() != null){
+ Object response = responseMessageProcessor.extractPayloadFromJMSMessage((javax.jms.Message)msg.getBody());
+ if (response instanceof InvocationTargetException) {
+ msg.setFaultBody(((InvocationTargetException) response).getCause());
+ } else {
+ if (response != null){
+ msg.setBody(response);
+ } else {
+ msg.setBody(null);
+ }
+ }
+ }
+
+ return msg;
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Message processRequest(Message msg) {
+ return invokeRequest(msg);
+ } // end method processRequest
+
+ public Message processResponse(Message msg) {
+ return invokeResponse(msg);
+ } // end method processResponse
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceProvider.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceProvider.java
new file mode 100644
index 0000000000..3d2c8ec18c
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceProvider.java
@@ -0,0 +1,92 @@
+/*
+ * 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.jms.wireformat.jmsbytes.runtime;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytes;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireFormatJMSBytesReferenceProvider implements WireFormatProvider {
+ private ExtensionPointRegistry registry;
+ private RuntimeEndpointReference endpointReference;
+ private JMSBinding binding;
+ private InterfaceContract interfaceContract;
+
+ public WireFormatJMSBytesReferenceProvider(ExtensionPointRegistry registry,
+ RuntimeEndpointReference endpointReference) {
+ super();
+ this.registry = registry;
+ this.endpointReference = endpointReference;
+ this.binding = (JMSBinding) endpointReference.getBinding();
+
+ // configure the reference based on this wire format
+
+ // currently maintaining the message processor structure which
+ // contains the details of jms message processing however overried
+ // any message processors specied in the SCDL in this case
+ if (this.binding.getRequestWireFormat() instanceof WireFormatJMSBytes){
+ this.binding.setRequestMessageProcessorName(JMSBindingConstants.BYTES_MP_CLASSNAME);
+ }
+ if (this.binding.getResponseWireFormat() instanceof WireFormatJMSBytes){
+ this.binding.setResponseMessageProcessorName(JMSBindingConstants.BYTES_MP_CLASSNAME);
+ }
+
+ // just point to the reference interface contract so no
+ // databinding transformation takes place
+ interfaceContract = endpointReference.getReference().getReference().getInterfaceContract();
+ }
+
+ public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){
+
+ if (this.interfaceContract != null ) {
+ if (this.binding.getRequestWireFormat() instanceof WireFormatJMSBytes){
+ // set the request data transformation
+ interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface());
+ }
+ if (this.binding.getResponseWireFormat() instanceof WireFormatJMSBytes){
+ // set the response data transformation
+ interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface());
+ }
+ }
+
+ return interfaceContract;
+ }
+
+ public Interceptor createInterceptor() {
+ return new WireFormatJMSBytesReferenceInterceptor(registry, null, endpointReference);
+ }
+
+ public String getPhase() {
+ return Phase.REFERENCE_BINDING_WIREFORMAT;
+ }
+
+ public InterfaceContract getWireFormatInterfaceContract() {
+ return interfaceContract;
+ }
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceInterceptor.java
new file mode 100644
index 0000000000..835734f45e
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceInterceptor.java
@@ -0,0 +1,125 @@
+/*
+ * 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.jms.wireformat.jmsbytes.runtime;
+
+import javax.jms.Session;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytes;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ * 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 WireFormatJMSBytesServiceInterceptor extends InterceptorAsyncImpl {
+ private Invoker next;
+ private RuntimeEndpoint endpoint;
+ private JMSResourceFactory jmsResourceFactory;
+ private JMSBinding jmsBinding;
+ private JMSMessageProcessor requestMessageProcessor;
+ private JMSMessageProcessor responseMessageProcessor;
+
+ public WireFormatJMSBytesServiceInterceptor(ExtensionPointRegistry registry, JMSResourceFactory jmsResourceFactory, RuntimeEndpoint endpoint) {
+ super();
+ this.endpoint = endpoint;
+ this.jmsBinding = (JMSBinding) endpoint.getBinding();
+ this.jmsResourceFactory = jmsResourceFactory;
+ this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(registry, jmsBinding);
+ this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(registry, jmsBinding);
+ }
+
+ public Message invoke(Message msg) {
+ if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSBytes){
+ msg = invokeRequest(msg);
+ }
+
+ msg = getNext().invoke(msg);
+
+ //if it's oneway return back
+ Operation operation = msg.getOperation();
+ if (operation != null && operation.isNonBlocking()) {
+ return msg;
+ }
+
+ if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSBytes){
+ msg = invokeResponse(msg);
+ }
+
+ return msg;
+ }
+
+ public Message invokeRequest(Message msg) {
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ javax.jms.Message jmsMsg = context.getJmsMsg();
+
+ Object requestPayload = requestMessageProcessor.extractPayloadFromJMSMessage(jmsMsg);
+ msg.setBody(new Object[]{requestPayload});
+
+ return msg;
+ }
+
+ public Message invokeResponse(Message msg) {
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ Session session = context.getJmsResponseSession();
+
+ javax.jms.Message responseJMSMsg;
+ if (msg.isFault()) {
+ responseJMSMsg = responseMessageProcessor.createFaultMessage(session, (Throwable)msg.getBody());
+ } else {
+ Object response = msg.getBody();
+ responseJMSMsg = responseMessageProcessor.insertPayloadIntoJMSMessage(session, response);
+ }
+
+ msg.setBody(responseJMSMsg);
+
+ return msg;
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Message processRequest(Message msg) {
+ return invokeRequest(msg);
+ } // end method processRequest
+
+ public Message processResponse(Message msg) {
+ return invokeResponse(msg);
+ } // end method processResponse
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceProvider.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceProvider.java
new file mode 100644
index 0000000000..ef3530640f
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceProvider.java
@@ -0,0 +1,96 @@
+/*
+ * 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.jms.wireformat.jmsbytes.runtime;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytes;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireFormatJMSBytesServiceProvider implements WireFormatProvider {
+ private ExtensionPointRegistry registry;
+ private RuntimeEndpoint endpoint;
+ private JMSBinding binding;
+ private InterfaceContract interfaceContract;
+
+ public WireFormatJMSBytesServiceProvider(ExtensionPointRegistry registry,
+ RuntimeEndpoint endpoint) {
+ super();
+ this.registry = registry;
+ this.endpoint = endpoint;
+ this.binding = (JMSBinding) endpoint.getBinding();
+
+ // configure the service based on this wire format
+
+ // currently maintaining the message processor structure which
+ // contains the details of jms message processing however override
+ // any message processors specified in the SCDL in this case
+ if (this.binding.getRequestWireFormat() instanceof WireFormatJMSBytes){
+ this.binding.setRequestMessageProcessorName(JMSBindingConstants.BYTES_MP_CLASSNAME);
+ }
+ if (this.binding.getResponseWireFormat() instanceof WireFormatJMSBytes){
+ this.binding.setResponseMessageProcessorName(JMSBindingConstants.BYTES_MP_CLASSNAME);
+ }
+
+ // just point to the reference interface contract so no
+ // databinding transformation takes place
+ interfaceContract = endpoint.getService().getService().getInterfaceContract();
+ }
+
+ public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){
+
+ if (this.interfaceContract != null ) {
+ if (this.binding.getRequestWireFormat() instanceof WireFormatJMSBytes){
+ // set the request data transformation
+ interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface());
+ }
+ if (this.binding.getResponseWireFormat() instanceof WireFormatJMSBytes){
+ // set the response data transformation
+ interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface());
+ }
+ }
+
+ return interfaceContract;
+ }
+
+ /**
+ */
+ public Interceptor createInterceptor() {
+ return new WireFormatJMSBytesServiceInterceptor(registry, null, endpoint);
+ }
+
+ /**
+ */
+ public String getPhase() {
+ return Phase.SERVICE_BINDING_WIREFORMAT;
+ }
+
+ public InterfaceContract getWireFormatInterfaceContract() {
+ return interfaceContract;
+ }
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLProviderFactory.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLProviderFactory.java
new file mode 100644
index 0000000000..a791c5f0b9
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLProviderFactory.java
@@ -0,0 +1,64 @@
+/*
+ * 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.jms.wireformat.jmsbytesxml.runtime;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactoryExtensionPoint;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytes;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.provider.WireFormatProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+
+public class WireFormatJMSBytesXMLProviderFactory implements WireFormatProviderFactory<WireFormatJMSBytes> {
+ private ExtensionPointRegistry registry;
+ private JMSResourceFactoryExtensionPoint jmsRFEP;
+
+ public WireFormatJMSBytesXMLProviderFactory(ExtensionPointRegistry registry) {
+ super();
+ this.registry = registry;
+ jmsRFEP = (JMSResourceFactoryExtensionPoint)registry.getExtensionPoint(JMSResourceFactoryExtensionPoint.class);
+ }
+
+ /**
+ */
+ public WireFormatProvider createReferenceWireFormatProvider(RuntimeEndpointReference endpointReference) {
+ return new WireFormatJMSBytesXMLReferenceProvider(registry, endpointReference);
+ }
+
+ /**
+ */
+ public WireFormatProvider createServiceWireFormatProvider(RuntimeEndpoint endpoint) {
+ JMSResourceFactory jmsRF = jmsRFEP.createJMSResourceFactory((JMSBinding)endpoint.getBinding());
+ return new WireFormatJMSBytesXMLServiceProvider(registry, endpoint, jmsRF);
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType()
+ */
+ public Class getModelType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceInterceptor.java
new file mode 100644
index 0000000000..6a32344f94
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceInterceptor.java
@@ -0,0 +1,133 @@
+/*
+ * 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.jms.wireformat.jmsbytesxml.runtime;
+
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytesXML;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+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;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+import org.w3c.dom.Node;
+
+
+public class WireFormatJMSBytesXMLReferenceInterceptor extends InterceptorAsyncImpl {
+
+ private Invoker next;
+ private RuntimeEndpointReference endpointReference;
+ private JMSResourceFactory jmsResourceFactory;
+ private JMSBinding jmsBinding;
+ private JMSMessageProcessor requestMessageProcessor;
+ private JMSMessageProcessor responseMessageProcessor;
+
+ public WireFormatJMSBytesXMLReferenceInterceptor(ExtensionPointRegistry registry, JMSResourceFactory jmsResourceFactory, RuntimeEndpointReference endpointReference) {
+ super();
+ this.jmsBinding = (JMSBinding) endpointReference.getBinding();
+ this.endpointReference = endpointReference;
+ this.jmsResourceFactory = jmsResourceFactory;
+ this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(registry, jmsBinding);
+ this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(registry, jmsBinding);
+ }
+
+ public Message invoke(Message msg) {
+ if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSBytesXML){
+ msg = invokeRequest(msg);
+ }
+
+ msg = getNext().invoke(msg);
+
+ if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSBytesXML){
+ msg = invokeResponse(msg);
+ }
+
+ return msg;
+ }
+
+ public Message invokeRequest(Message msg) {
+ try {
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ Session session = context.getJmsSession();
+
+ javax.jms.Message requestMsg = requestMessageProcessor.insertPayloadIntoJMSMessage(session, msg.getBody());
+
+ msg.setBody(requestMsg);
+
+ requestMsg.setJMSReplyTo(context.getReplyToDestination());
+
+ return msg;
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ public Message invokeResponse(Message msg) {
+ if (msg.getBody() != null){
+ javax.jms.Message jmsMsg = (javax.jms.Message)msg.getBody();
+ Object response = responseMessageProcessor.extractPayloadFromJMSMessage(jmsMsg);
+ if (response != null ){
+ msg.setBody(response);
+ try {
+ if (jmsMsg.getBooleanProperty(JMSBindingConstants.FAULT_PROPERTY)) {
+ FaultException e = new FaultException("remote exception", response);
+ Node om = ((Node)response).getFirstChild();
+ e.setFaultName(new QName(om.getNamespaceURI(), om.getLocalName()));
+ msg.setFaultBody(e);
+ }
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ } else {
+ msg.setBody(null);
+ }
+ }
+
+ return msg;
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Message processRequest(Message msg) {
+ return invokeRequest(msg);
+ } // end method processRequest
+
+ public Message processResponse(Message msg) {
+ return invokeResponse(msg);
+ } // end method processResponse
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceProvider.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceProvider.java
new file mode 100644
index 0000000000..e0f928de12
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceProvider.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.jms.wireformat.jmsbytesxml.runtime;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytesXML;
+import org.apache.tuscany.sca.binding.ws.WebServiceBinding;
+import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory;
+import org.apache.tuscany.sca.binding.ws.wsdlgen.BindingWSDLGenerator;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.databinding.xml.DOMDataBinding;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+public class WireFormatJMSBytesXMLReferenceProvider implements WireFormatProvider {
+ private ExtensionPointRegistry registry;
+ private RuntimeEndpointReference endpointReference;
+ private JMSBinding binding;
+ private InterfaceContract interfaceContract;
+
+ public WireFormatJMSBytesXMLReferenceProvider(ExtensionPointRegistry registry,
+ RuntimeEndpointReference endpointReference) {
+ super();
+ this.registry = registry;
+ this.endpointReference = endpointReference;
+ this.binding = (JMSBinding)endpointReference.getBinding();
+
+ // configure the reference based on this wire format
+
+ // currently maintaining the message processor structure which
+ // contains the details of jms message processing however overried
+ // any message processors specied in the SCDL in this case
+ if (this.binding.getRequestWireFormat() instanceof WireFormatJMSBytesXML){
+ this.binding.setRequestMessageProcessorName(JMSBindingConstants.XML_BYTES_MP_CLASSNAME);
+ }
+ if (this.binding.getResponseWireFormat() instanceof WireFormatJMSBytesXML){
+ this.binding.setResponseMessageProcessorName(JMSBindingConstants.XML_BYTES_MP_CLASSNAME);
+ }
+
+ // create a local interface contract that is configured specifically to
+ // deal with the data format that this wire format is expecting to sent to
+ // and receive from the databinding interceptor. The request/response parts of
+ // this interface contract will be copied into the binding interface contract
+ // as required
+ WebServiceBindingFactory wsFactory = registry.getExtensionPoint(WebServiceBindingFactory.class);
+ WebServiceBinding wsBinding = wsFactory.createWebServiceBinding();
+ BindingWSDLGenerator.generateWSDL(endpointReference.getComponent(), endpointReference.getContract(), wsBinding, registry, null);
+ interfaceContract = wsBinding.getBindingInterfaceContract();
+ interfaceContract.getInterface().resetDataBinding(DOMDataBinding.NAME);
+ }
+
+ public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){
+
+ if (this.interfaceContract != null ) {
+ if (this.binding.getRequestWireFormat() instanceof WireFormatJMSBytesXML){
+ // set the request data transformation
+ interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface());
+ }
+ if (this.binding.getResponseWireFormat() instanceof WireFormatJMSBytesXML){
+ // set the response data transformation
+ interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface());
+ }
+ }
+
+ return interfaceContract;
+ }
+
+ public Interceptor createInterceptor() {
+ return new WireFormatJMSBytesXMLReferenceInterceptor(registry, null, endpointReference);
+ }
+
+ public String getPhase() {
+ return Phase.REFERENCE_BINDING_WIREFORMAT;
+ }
+
+ public InterfaceContract getWireFormatInterfaceContract() {
+ return interfaceContract;
+ }
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceInterceptor.java
new file mode 100644
index 0000000000..6ff27d4660
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceInterceptor.java
@@ -0,0 +1,119 @@
+/*
+ * 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.jms.wireformat.jmsbytesxml.runtime;
+
+import javax.jms.Session;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytesXML;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+public class WireFormatJMSBytesXMLServiceInterceptor extends InterceptorAsyncImpl {
+ private Invoker next;
+ private RuntimeEndpoint endpoint;
+ private JMSResourceFactory jmsResourceFactory;
+ private JMSBinding jmsBinding;
+ private JMSMessageProcessor requestMessageProcessor;
+ private JMSMessageProcessor responseMessageProcessor;
+
+ public WireFormatJMSBytesXMLServiceInterceptor(ExtensionPointRegistry registry, JMSResourceFactory jmsResourceFactory, RuntimeEndpoint endpoint) {
+ super();
+ this.jmsBinding = (JMSBinding) endpoint.getBinding();
+ this.endpoint = endpoint;
+ this.jmsResourceFactory = jmsResourceFactory;
+ this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(registry, jmsBinding);
+ this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(registry, jmsBinding);
+ }
+
+ public Message invoke(Message msg) {
+ if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSBytesXML){
+ msg = invokeRequest(msg);
+ }
+
+ msg = getNext().invoke(msg);
+
+ //if it's oneway return back
+ Operation operation = msg.getOperation();
+ if (operation != null && operation.isNonBlocking()) {
+ return msg;
+ }
+
+ if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSBytesXML){
+ msg = invokeResponse(msg);
+ }
+
+ return msg;
+ }
+
+ public Message invokeRequest(Message msg) {
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ javax.jms.Message jmsMsg = context.getJmsMsg();
+
+ Object requestPayload = requestMessageProcessor.extractPayloadFromJMSMessage(jmsMsg);
+ msg.setBody(new Object[]{requestPayload});
+
+ return msg;
+ }
+
+ public Message invokeResponse(Message msg) {
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ Session session = context.getJmsResponseSession();
+
+ javax.jms.Message responseJMSMsg;
+ if (msg.isFault()) {
+ responseJMSMsg = responseMessageProcessor.createFaultMessage(session, (Throwable)msg.getBody());
+ } else {
+ Object response = msg.getBody();
+ responseJMSMsg = responseMessageProcessor.insertPayloadIntoJMSMessage(session, response);
+ }
+
+ msg.setBody(responseJMSMsg);
+
+ return msg;
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Message processRequest(Message msg) {
+ return invokeRequest(msg);
+ } // end method processRequest
+
+ public Message processResponse(Message msg) {
+ return invokeResponse(msg);
+ } // end method processResponse
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceProvider.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceProvider.java
new file mode 100644
index 0000000000..d2ff153227
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceProvider.java
@@ -0,0 +1,108 @@
+/*
+ * 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.jms.wireformat.jmsbytesxml.runtime;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytesXML;
+import org.apache.tuscany.sca.binding.ws.WebServiceBinding;
+import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory;
+import org.apache.tuscany.sca.binding.ws.wsdlgen.BindingWSDLGenerator;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.databinding.xml.DOMDataBinding;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+public class WireFormatJMSBytesXMLServiceProvider implements WireFormatProvider {
+ private ExtensionPointRegistry registry;
+ private RuntimeEndpoint endpoint;
+ private JMSBinding binding;
+ private JMSResourceFactory jmsResourceFactory;
+ private InterfaceContract interfaceContract;
+
+ public WireFormatJMSBytesXMLServiceProvider(ExtensionPointRegistry registry,
+ RuntimeEndpoint endpoint,
+ JMSResourceFactory jmsResourceFactory) {
+ super();
+ this.registry = registry;
+ this.endpoint = endpoint;
+ this.binding = (JMSBinding)endpoint.getBinding();
+ this.jmsResourceFactory = jmsResourceFactory;
+
+ // configure the service based on this wire format
+
+ // currently maintaining the message processor structure which
+ // contains the details of jms message processing however override
+ // any message processors specified in the SCDL in this case
+ if (this.binding.getRequestWireFormat() instanceof WireFormatJMSBytesXML){
+ this.binding.setRequestMessageProcessorName(JMSBindingConstants.XML_BYTES_MP_CLASSNAME);
+ }
+ if (this.binding.getResponseWireFormat() instanceof WireFormatJMSBytesXML){
+ this.binding.setResponseMessageProcessorName(JMSBindingConstants.XML_BYTES_MP_CLASSNAME);
+ }
+
+ // create a local interface contract that is configured specifically to
+ // deal with the data format that this wire format is expecting to sent to
+ // and receive from the databinding interceptor. The request/response parts of
+ // this interface contract will be copied into the binding interface contract
+ // as required
+ WebServiceBindingFactory wsFactory = registry.getExtensionPoint(WebServiceBindingFactory.class);
+ WebServiceBinding wsBinding = wsFactory.createWebServiceBinding();
+ BindingWSDLGenerator.generateWSDL(endpoint.getComponent(), endpoint.getService(), wsBinding, registry, null);
+ interfaceContract = wsBinding.getBindingInterfaceContract();
+ interfaceContract.getInterface().resetDataBinding(DOMDataBinding.NAME);
+ }
+
+ public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){
+
+ if (this.interfaceContract != null ) {
+ if (this.binding.getRequestWireFormat() instanceof WireFormatJMSBytesXML){
+ // set the request data transformation
+ interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface());
+ }
+ if (this.binding.getResponseWireFormat() instanceof WireFormatJMSBytesXML){
+ // set the response data transformation
+ interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface());
+ }
+ }
+
+ return interfaceContract;
+ }
+
+ /**
+ */
+ public Interceptor createInterceptor() {
+ return new WireFormatJMSBytesXMLServiceInterceptor(registry, jmsResourceFactory, endpoint);
+ }
+
+ /**
+ */
+ public String getPhase() {
+ return Phase.SERVICE_BINDING_WIREFORMAT;
+ }
+
+ public InterfaceContract getWireFormatInterfaceContract() {
+ return interfaceContract;
+ }
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultProviderFactory.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultProviderFactory.java
new file mode 100644
index 0000000000..adf8c03c10
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultProviderFactory.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.jms.wireformat.jmsdefault.runtime;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactoryExtensionPoint;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSDefault;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.provider.WireFormatProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireFormatJMSDefaultProviderFactory implements WireFormatProviderFactory<WireFormatJMSDefault> {
+ private ExtensionPointRegistry registry;
+ private JMSResourceFactoryExtensionPoint jmsRFEP;
+
+ public WireFormatJMSDefaultProviderFactory(ExtensionPointRegistry registry) {
+ super();
+ this.registry = registry;
+ jmsRFEP = (JMSResourceFactoryExtensionPoint) registry.getExtensionPoint(JMSResourceFactoryExtensionPoint.class);
+ }
+
+ /**
+ */
+ public WireFormatProvider createReferenceWireFormatProvider(RuntimeEndpointReference endpointReference) {
+ return new WireFormatJMSDefaultReferenceProvider(registry, endpointReference);
+ }
+
+ /**
+ */
+ public WireFormatProvider createServiceWireFormatProvider(RuntimeEndpoint endpoint) {
+ JMSResourceFactory jmsRF = jmsRFEP.createJMSResourceFactory((JMSBinding) endpoint.getBinding());
+ return new WireFormatJMSDefaultServiceProvider(registry, endpoint, jmsRF);
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType()
+ */
+ public Class getModelType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceInterceptor.java
new file mode 100644
index 0000000000..33e73a69ef
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceInterceptor.java
@@ -0,0 +1,184 @@
+/*
+ * 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.jms.wireformat.jmsdefault.runtime;
+
+import java.util.HashMap;
+
+import javax.jms.BytesMessage;
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.provider.DefaultMessageProcessor;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSDefault;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+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;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+import org.w3c.dom.Node;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class WireFormatJMSDefaultReferenceInterceptor extends InterceptorAsyncImpl {
+
+ private Invoker next;
+ private RuntimeEndpointReference endpointReference;
+ private JMSResourceFactory jmsResourceFactory;
+ private JMSBinding jmsBinding;
+ private DefaultMessageProcessor requestMessageProcessor;
+ private DefaultMessageProcessor responseMessageProcessor;
+ private HashMap<String, Boolean> inputWrapperMap;
+ private HashMap<String, Node> outputWrapperMap;
+
+ public WireFormatJMSDefaultReferenceInterceptor(ExtensionPointRegistry registry, JMSResourceFactory jmsResourceFactory, RuntimeEndpointReference endpointReference, HashMap<String, Boolean> inputWrapperMap,
+ HashMap<String, Node> outputWrapperMap) {
+ super();
+ this.jmsBinding = (JMSBinding) endpointReference.getBinding();
+ this.endpointReference = endpointReference;
+ this.jmsResourceFactory = jmsResourceFactory;
+ // Note the default processor doesn't follow the normal processor pattern
+ // as it has to handle both text and bytes messages
+ this.requestMessageProcessor = new DefaultMessageProcessor(jmsBinding, registry);
+ this.responseMessageProcessor = new DefaultMessageProcessor(jmsBinding, registry);
+ this.inputWrapperMap = inputWrapperMap;
+ this.outputWrapperMap = outputWrapperMap;
+ }
+
+ public Message invoke(Message msg) {
+
+ if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSDefault) {
+ msg = invokeRequest(msg);
+ }
+
+ msg = getNext().invoke(msg);
+
+ if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSDefault) {
+ msg = invokeResponse(msg);
+ }
+
+ return msg;
+ }
+
+ public Message invokeRequest(Message msg) {
+ try {
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ Session session = context.getJmsSession();
+
+ javax.jms.Message requestMsg;
+
+ if (((WireFormatJMSDefault) jmsBinding.getRequestWireFormat()).isUseBytesMessage()) {
+ requestMsg = requestMessageProcessor.insertPayloadIntoJMSBytesMessage(session, msg.getBody(), this.inputWrapperMap.get(msg.getOperation().getName()));
+ } else {
+ requestMsg = requestMessageProcessor.insertPayloadIntoJMSTextMessage(session, msg.getBody(), this.inputWrapperMap.get(msg.getOperation().getName()));
+ }
+
+ msg.setBody(requestMsg);
+
+ requestMsg.setJMSReplyTo(context.getReplyToDestination());
+
+ return msg;
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ public Message invokeResponse(Message msg) {
+ if (msg.getBody() != null) {
+ javax.jms.Message jmsMsg = (javax.jms.Message) msg.getBody();
+
+ Operation op = msg.getOperation();
+ DataType outputDataType = op.getOutputType();
+
+ Class<?> outputType = null;
+ if (outputDataType != null) {
+ outputType = outputDataType.getPhysical();
+ }
+
+ if (outputType != null && javax.jms.Message.class.isAssignableFrom(outputType)) {
+ msg.setBody(jmsMsg);
+ } else {
+
+ Node wrapper = null;
+ // if we have a fault no need to wrap the response
+ try {
+ if (!jmsMsg.getBooleanProperty(JMSBindingConstants.FAULT_PROPERTY)) {
+ // If there is only one arg we must add a wrapper if the operation is wrapper style
+ wrapper = this.outputWrapperMap.get(msg.getOperation().getName());
+ }
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+
+ Object response;
+ if (jmsMsg instanceof BytesMessage) {
+ response = responseMessageProcessor.extractPayloadFromJMSBytesMessage(jmsMsg, wrapper);
+ } else {
+ response = responseMessageProcessor.extractPayloadFromJMSTextMessage(jmsMsg, wrapper);
+ }
+
+ if (response != null) {
+ msg.setBody(response);
+ try {
+ if (jmsMsg.getBooleanProperty(JMSBindingConstants.FAULT_PROPERTY)) {
+ FaultException e = new FaultException("remote exception", response);
+ Node om = ((Node)response).getFirstChild();
+ e.setFaultName(new QName(om.getNamespaceURI(), om.getLocalName()));
+ msg.setFaultBody(e);
+ }
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ } else {
+ msg.setBody(null);
+ }
+ }
+ }
+
+ return msg;
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Message processRequest(Message msg) {
+ return invokeRequest(msg);
+ } // end method processRequest
+
+ public Message processResponse(Message msg) {
+ return invokeResponse(msg);
+ } // end method processResponse
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceProvider.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceProvider.java
new file mode 100644
index 0000000000..127680c283
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceProvider.java
@@ -0,0 +1,204 @@
+/*
+ * 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.jms.wireformat.jmsdefault.runtime;
+
+import java.util.HashMap;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSDefault;
+import org.apache.tuscany.sca.binding.ws.WebServiceBinding;
+import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory;
+import org.apache.tuscany.sca.binding.ws.wsdlgen.BindingWSDLGenerator;
+import org.apache.tuscany.sca.common.xml.dom.DOMHelper;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.databinding.xml.DOMDataBinding;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.ElementInfo;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireFormatJMSDefaultReferenceProvider implements WireFormatProvider {
+ private ExtensionPointRegistry registry;
+ private RuntimeEndpointReference endpointReference;
+ private ComponentReference reference;
+ private JMSBinding binding;
+ private InterfaceContract interfaceContract;
+ private DOMHelper domHelper;
+ private HashMap<String, Boolean> inputWrapperMap;
+ private HashMap<String, Node> outputWrapperMap;
+
+ public WireFormatJMSDefaultReferenceProvider(ExtensionPointRegistry registry, RuntimeEndpointReference endpointReference) {
+ super();
+ this.registry = registry;
+ this.endpointReference = endpointReference;
+ this.binding = (JMSBinding) endpointReference.getBinding();
+
+ this.domHelper = DOMHelper.getInstance(registry);
+ this.inputWrapperMap = new HashMap<String, Boolean>();
+ this.outputWrapperMap = new HashMap<String, Node>();
+
+ // configure the reference based on this wire format
+
+ // currently maintaining the message processor structure which
+ // contains the details of jms message processing so set the message
+ // type here if not set explicitly in SCDL
+ if (this.binding.getRequestWireFormat() instanceof WireFormatJMSDefault){
+ this.binding.setRequestMessageProcessorName(JMSBindingConstants.DEFAULT_MP_CLASSNAME);
+ }
+ if (this.binding.getResponseWireFormat() instanceof WireFormatJMSDefault){
+ this.binding.setResponseMessageProcessorName(JMSBindingConstants.DEFAULT_MP_CLASSNAME);
+ }
+
+ this.reference = endpointReference.getReference();
+ // TODO - can be null if it's a $self$ reference. Need to decide if
+ // that's valid
+ if (reference.getReference() == null){
+ interfaceContract = reference.getInterfaceContract();
+ return;
+ }
+
+ List<Operation> opList = reference.getReference().getInterfaceContract().getInterface().getOperations();
+
+ // Go through each operation and add wrapper info
+
+ // set the binding interface contract to represent the WSDL for the
+ // xml messages that will be sent
+ // I think we have to check for asIs because the Java2WSDL will blow up when using javax.jms.Message
+ if (reference.getInterfaceContract() != null && !isAsIs()) {
+ WebServiceBindingFactory wsFactory = registry.getExtensionPoint(WebServiceBindingFactory.class);
+ WebServiceBinding wsBinding = wsFactory.createWebServiceBinding();
+ BindingWSDLGenerator.generateWSDL(endpointReference.getComponent(), reference, wsBinding, registry, null);
+ interfaceContract = wsBinding.getBindingInterfaceContract();
+ interfaceContract.getInterface().resetDataBinding(DOMDataBinding.NAME);
+
+ List<Operation> wsdlOpList = interfaceContract.getInterface().getOperations();
+
+ for (Operation op : opList) {
+
+ String name = op.getName();
+ Operation matchingWsdlOp = null;
+
+ // find the matching wsdlop
+ for (Operation wsdlOp : wsdlOpList) {
+ if (name.equals(wsdlOp.getName())) {
+ matchingWsdlOp = wsdlOp;
+
+ break;
+ }
+ }
+
+ // only add operations that need to be wrapped/unwrapped
+ // we need to look at the wsdl interface to determine if the op is wrapped or not
+
+ // TODO - not sure we really support viewing the input/output as separately wrapped
+ // like the separate code paths imply. Not sure how many @OneWay tests we have, this might
+ // not be an issue.
+
+ if (matchingWsdlOp.isWrapperStyle()) {
+ if (op.getInputType().getLogical().size() == 1) {
+ this.inputWrapperMap.put(name, true);
+ } else {
+ this.inputWrapperMap.put(name, false);
+ }
+ } else {
+ this.inputWrapperMap.put(name, false);
+ }
+
+ if (matchingWsdlOp.isWrapperStyle()) {
+ // we only need to know what the wrapper is on the deserialization
+ // might need to change this when there input/output wrapper style is different
+ ElementInfo ei = op.getWrapper().getOutputWrapperElement();
+ String namespace = ei.getQName().getNamespaceURI();
+ String opName = ei.getQName().getLocalPart();
+ Document document = domHelper.newDocument();
+ Element wrapper = DOMHelper.createElement(document, new QName(namespace, opName));
+ this.outputWrapperMap.put(name, wrapper);
+ }
+ }
+ } else {
+ interfaceContract = reference.getReference().getInterfaceContract();
+ }
+
+ }
+
+ protected boolean isAsIs() {
+ InterfaceContract ic = reference.getInterfaceContract();
+ if (ic.getInterface().getOperations().size() != 1) {
+ return false;
+ }
+
+ List<DataType> inputDataTypes = ic.getInterface().getOperations().get(0).getInputType().getLogical();
+
+ if (inputDataTypes.size() != 1) {
+ return false;
+ }
+
+ Class<?> inputType = inputDataTypes.get(0).getPhysical();
+
+ if (javax.jms.Message.class.isAssignableFrom(inputType)) {
+ return true;
+ }
+ return false;
+ }
+
+ public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){
+
+ if (this.interfaceContract != null &&
+ !isAsIs()) {
+ if (this.binding.getRequestWireFormat() instanceof WireFormatJMSDefault){
+ // set the request data transformation
+ interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface());
+ }
+ if (this.binding.getResponseWireFormat() instanceof WireFormatJMSDefault){
+ // set the response data transformation
+ interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface());
+ }
+ }
+
+ return interfaceContract;
+ }
+
+ public Interceptor createInterceptor() {
+ return new WireFormatJMSDefaultReferenceInterceptor(registry, null, endpointReference, inputWrapperMap, outputWrapperMap);
+ }
+
+ public String getPhase() {
+ return Phase.REFERENCE_BINDING_WIREFORMAT;
+ }
+
+ public InterfaceContract getWireFormatInterfaceContract() {
+ return interfaceContract;
+ }
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceInterceptor.java
new file mode 100644
index 0000000000..b66dd0154f
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceInterceptor.java
@@ -0,0 +1,200 @@
+/*
+ * 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.jms.wireformat.jmsdefault.runtime;
+
+import java.util.HashMap;
+import java.util.List;
+
+import javax.jms.BytesMessage;
+import javax.jms.JMSException;
+import javax.jms.Session;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.provider.DefaultMessageProcessor;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSDefault;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.w3c.dom.Node;
+
+/**
+ * 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 WireFormatJMSDefaultServiceInterceptor extends InterceptorAsyncImpl {
+ private RuntimeEndpoint endpoint;
+ private JMSResourceFactory jmsResourceFactory;
+ private JMSBinding jmsBinding;
+ private DefaultMessageProcessor requestMessageProcessor;
+ private DefaultMessageProcessor responseMessageProcessor;
+ private HashMap<String, Node> inputWrapperMap;
+ private HashMap<String, Boolean> outputWrapperMap;
+
+ public WireFormatJMSDefaultServiceInterceptor(ExtensionPointRegistry registry, JMSResourceFactory jmsResourceFactory, RuntimeEndpoint endpoint, HashMap<String, Node> inputWrapperMap,
+ HashMap<String, Boolean> outputWrapperMap) {
+ super();
+ this.jmsBinding = (JMSBinding) endpoint.getBinding();
+ this.endpoint = endpoint;
+ this.jmsResourceFactory = jmsResourceFactory;
+ // Note the default processor doesn't follow the normal processor pattern
+ // as it has to handle both text and bytes messages
+ this.requestMessageProcessor = new DefaultMessageProcessor(jmsBinding, registry);
+ this.responseMessageProcessor = new DefaultMessageProcessor(jmsBinding, registry);
+ this.inputWrapperMap = inputWrapperMap;
+ this.outputWrapperMap = outputWrapperMap;
+
+ }
+
+ public Message invoke(Message msg) {
+
+ if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSDefault) {
+ msg = invokeRequest(msg);
+ }
+
+ msg = getNext().invoke(msg);
+
+ // if it's oneway return back
+ Operation operation = msg.getOperation();
+ if (operation != null && operation.isNonBlocking()) {
+ return msg;
+ }
+
+ if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSDefault) {
+ msg = invokeResponse(msg);
+ }
+
+ return msg;
+ }
+
+ public Message invokeRequest(Message msg) {
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ javax.jms.Message jmsMsg = context.getJmsMsg();
+
+ Operation op = msg.getOperation();
+ List<DataType> inputDataTypes = op.getInputType().getLogical();
+
+ Class<?> inputType = null;
+ if (inputDataTypes.size() == 1) {
+ inputType = inputDataTypes.get(0).getPhysical();
+ }
+ if (inputType != null && javax.jms.Message.class.isAssignableFrom(inputType)) {
+ msg.setBody(new Object[] { jmsMsg });
+
+ if (jmsMsg instanceof BytesMessage) {
+ context.setUseBytesForWFJMSDefaultResponse(true);
+ } else {
+ context.setUseBytesForWFJMSDefaultResponse(false);
+ }
+ } else {
+
+ // If there is only one arg we must add a wrapper if the operation is wrapper style
+ Node wrapper = this.inputWrapperMap.get(msg.getOperation().getName());
+
+ Object requestPayload;
+ if (jmsMsg instanceof BytesMessage) {
+ requestPayload = responseMessageProcessor.extractPayloadFromJMSBytesMessage(jmsMsg, wrapper);
+ context.setUseBytesForWFJMSDefaultResponse(true);
+ } else {
+ requestPayload = responseMessageProcessor.extractPayloadFromJMSTextMessage(jmsMsg, wrapper );
+ context.setUseBytesForWFJMSDefaultResponse(false);
+ }
+
+ msg.setBody(new Object[] { requestPayload });
+ }
+
+ return msg;
+
+ }
+
+ public Message invokeResponse(Message msg) {
+
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ // The Binding Context may be null on an asynchronous response - in which case, create a new one
+ if(context == null) {
+ context = createBindingContext();
+ msg.setBindingContext(context);
+ } // end if
+ Session session = context.getJmsResponseSession();
+
+ javax.jms.Message responseJMSMsg;
+
+ boolean respondBytesMessage = context.isUseBytesForWFJMSDefaultResponse();
+
+ if (msg.isFault()) {
+ if (respondBytesMessage == true) {
+ responseJMSMsg = requestMessageProcessor.createFaultJMSBytesMessage(session, (Throwable) msg.getBody());
+ } else {
+ responseJMSMsg = responseMessageProcessor.createFaultJMSTextMessage(session, (Throwable) msg.getBody());
+ }
+ } else {
+ boolean unwrap = false;
+
+ if (this.outputWrapperMap.get(msg.getOperation().getName()) != null){
+ unwrap = this.outputWrapperMap.get(msg.getOperation().getName());
+ }
+
+ if (respondBytesMessage == true) {
+ responseJMSMsg = requestMessageProcessor.insertPayloadIntoJMSBytesMessage(session, msg.getBody(), unwrap);
+ } else {
+ responseJMSMsg = requestMessageProcessor.insertPayloadIntoJMSTextMessage(session, msg.getBody(), unwrap);
+ }
+ }
+
+
+ try {
+ responseJMSMsg.setStringProperty(JMSBindingConstants.DEFAULT_OPERATION_PROP_NAME, msg.getOperation().getName());
+ } catch (JMSException e) {
+ // Not sure what to do at this point.. it doesn't make sense to create a fault message.
+ // Throwing a runtime exception for now.
+ throw new JMSBindingException(e);
+ }
+
+ msg.setBody(responseJMSMsg);
+
+ return msg;
+ }
+
+ private JMSBindingContext createBindingContext() {
+ JMSBindingContext context = new JMSBindingContext();
+ context.setJmsResourceFactory(jmsResourceFactory);
+
+ return context;
+ } // end method createBindingContext
+
+ public Message processRequest(Message msg) {
+ return invokeRequest( msg );
+ } // end method processRequest
+
+ public Message processResponse(Message msg) {
+ return invokeResponse( msg );
+ } // end method processResponse
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceProvider.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceProvider.java
new file mode 100644
index 0000000000..3541666007
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceProvider.java
@@ -0,0 +1,198 @@
+/*
+ * 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.jms.wireformat.jmsdefault.runtime;
+
+import java.util.HashMap;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSDefault;
+import org.apache.tuscany.sca.binding.ws.WebServiceBinding;
+import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory;
+import org.apache.tuscany.sca.binding.ws.wsdlgen.BindingWSDLGenerator;
+import org.apache.tuscany.sca.common.xml.dom.DOMHelper;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.databinding.xml.DOMDataBinding;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.ElementInfo;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireFormatJMSDefaultServiceProvider implements WireFormatProvider {
+ private ExtensionPointRegistry registry;
+ private RuntimeEndpoint endpoint;
+ private ComponentService service;
+ private JMSBinding binding;
+ private JMSResourceFactory jmsResourceFactory;
+ private InterfaceContract interfaceContract;
+ private DOMHelper domHelper;
+ private HashMap<String, Node> inputWrapperMap;
+ private HashMap<String, Boolean> outputWrapperMap;
+
+ public WireFormatJMSDefaultServiceProvider(ExtensionPointRegistry registry, RuntimeEndpoint endpoint, JMSResourceFactory jmsResourceFactory) {
+ super();
+ this.registry = registry;
+ this.endpoint = endpoint;
+ this.binding = (JMSBinding) endpoint.getBinding();
+ this.service = endpoint.getService();
+ this.jmsResourceFactory = jmsResourceFactory;
+
+ this.domHelper = DOMHelper.getInstance(registry);
+ this.inputWrapperMap = new HashMap<String, Node>();
+ this.outputWrapperMap = new HashMap<String, Boolean>();
+
+ // configure the service based on this wire format
+
+ // currently maintaining the message processor structure which
+ // contains the details of jms message processing so set the message
+ // type here if not set explicitly in SCDL
+ if (this.binding.getRequestWireFormat() instanceof WireFormatJMSDefault){
+ this.binding.setRequestMessageProcessorName(JMSBindingConstants.DEFAULT_MP_CLASSNAME);
+ }
+ if (this.binding.getResponseWireFormat() instanceof WireFormatJMSDefault){
+ this.binding.setResponseMessageProcessorName(JMSBindingConstants.DEFAULT_MP_CLASSNAME);
+ }
+
+ List<Operation> opList = service.getService().getInterfaceContract().getInterface().getOperations();
+
+ // Go through each operation and add wrapper info
+
+ // set the binding interface contract to represent the WSDL for the
+ // xml messages that will be sent
+
+ // I think we have to check for asIs because the Java2WSDL will blow up when using javax.jms.Message
+ if (service.getInterfaceContract() != null && !isAsIs()) {
+ WebServiceBindingFactory wsFactory = registry.getExtensionPoint(WebServiceBindingFactory.class);
+ WebServiceBinding wsBinding = wsFactory.createWebServiceBinding();
+ BindingWSDLGenerator.generateWSDL(endpoint.getComponent(), service, wsBinding, registry, null);
+ interfaceContract = wsBinding.getBindingInterfaceContract();
+ interfaceContract.getInterface().resetDataBinding(DOMDataBinding.NAME);
+
+ List<Operation> wsdlOpList = interfaceContract.getInterface().getOperations();
+
+ for (Operation op : opList) {
+ String name = op.getName();
+
+ Operation matchingWsdlOp = null;
+
+ // find the matching wsdlop
+ for (Operation wsdlOp : wsdlOpList) {
+ if (name.equals(wsdlOp.getName())) {
+ matchingWsdlOp = wsdlOp;
+ break;
+ }
+ }
+
+ // only add operations that need to be wrapped/unwrapped
+
+ // TODO - not sure we really support viewing the input/output as separately wrapped
+ // like the separate code paths imply. Not sure how many @OneWay tests we have, this might
+ // not be an issue.
+ if (matchingWsdlOp.isWrapperStyle()) {
+ if (op.getInputType().getLogical().size() == 1) {
+ // we only need to know what the wrapper is on the deserialization
+ // might need to change this when the input/output wrapper style is different
+ ElementInfo ei = op.getWrapper().getInputWrapperElement();
+ String namespace = ei.getQName().getNamespaceURI();
+ String opName = ei.getQName().getLocalPart();
+ Document document = domHelper.newDocument();
+ Element wrapper = DOMHelper.createElement(document, new QName(namespace, opName));
+ this.inputWrapperMap.put(name, wrapper);
+ }
+ }
+
+ if (matchingWsdlOp.isWrapperStyle()) {
+ this.outputWrapperMap.put(name, true);
+ } else {
+ this.outputWrapperMap.put(name, false);
+ }
+
+ }
+
+ } else {
+ interfaceContract = service.getService().getInterfaceContract();
+ }
+ }
+
+ protected boolean isAsIs() {
+ InterfaceContract ic = service.getInterfaceContract();
+ if (ic.getInterface().getOperations().size() != 1) {
+ return false;
+ }
+
+ List<DataType> inputDataTypes = ic.getInterface().getOperations().get(0).getInputType().getLogical();
+
+ if (inputDataTypes.size() != 1) {
+ return false;
+ }
+
+ Class<?> inputType = inputDataTypes.get(0).getPhysical();
+
+ if (javax.jms.Message.class.isAssignableFrom(inputType)) {
+ return true;
+ }
+ return false;
+ }
+
+ public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){
+
+ if (this.interfaceContract != null &&
+ !isAsIs()) {
+ if (this.binding.getRequestWireFormat() instanceof WireFormatJMSDefault){
+ // set the request data transformation
+ interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface());
+ }
+ if (this.binding.getResponseWireFormat() instanceof WireFormatJMSDefault){
+ // set the response data transformation
+ interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface());
+ }
+ }
+
+ return interfaceContract;
+ }
+
+
+ public Interceptor createInterceptor() {
+ return new WireFormatJMSDefaultServiceInterceptor(registry, jmsResourceFactory, endpoint, this.inputWrapperMap, this.outputWrapperMap);
+ }
+
+ public String getPhase() {
+ return Phase.SERVICE_BINDING_WIREFORMAT;
+ }
+
+ public InterfaceContract getWireFormatInterfaceContract() {
+ return interfaceContract;
+ }
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectProviderFactory.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectProviderFactory.java
new file mode 100644
index 0000000000..1e445f1b11
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectProviderFactory.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.jms.wireformat.jmsobject.runtime;
+
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSObject;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.provider.WireFormatProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireFormatJMSObjectProviderFactory implements WireFormatProviderFactory<WireFormatJMSObject> {
+ private ExtensionPointRegistry registry;
+
+ public WireFormatJMSObjectProviderFactory(ExtensionPointRegistry registry) {
+ super();
+ this.registry = registry;
+ }
+
+ /**
+ */
+ public WireFormatProvider createReferenceWireFormatProvider(RuntimeEndpointReference endpointReference) {
+ return new WireFormatJMSObjectReferenceProvider(registry, endpointReference);
+ }
+
+ /**
+ */
+ public WireFormatProvider createServiceWireFormatProvider(RuntimeEndpoint endpoint) {
+ return new WireFormatJMSObjectServiceProvider(registry, endpoint);
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType()
+ */
+ public Class getModelType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java
new file mode 100644
index 0000000000..842bb791d6
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java
@@ -0,0 +1,152 @@
+/*
+ * 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.jms.wireformat.jmsobject.runtime;
+
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+
+import javax.jms.JMSException;
+import javax.jms.Session;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.binding.jms.provider.ObjectMessageProcessor;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSObject;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class WireFormatJMSObjectReferenceInterceptor extends InterceptorAsyncImpl {
+
+ private Invoker next;
+ private RuntimeEndpointReference endpointReference;
+ private JMSResourceFactory jmsResourceFactory;
+ private JMSBinding jmsBinding;
+ private JMSMessageProcessor requestMessageProcessor;
+ private JMSMessageProcessor responseMessageProcessor;
+
+ private HashMap<String, String> singleArgMap;
+
+ public WireFormatJMSObjectReferenceInterceptor(ExtensionPointRegistry registry, JMSResourceFactory jmsResourceFactory, RuntimeEndpointReference endpointReference, HashMap<String, String> hashMap) {
+ super();
+ this.jmsBinding = (JMSBinding) endpointReference.getBinding();
+ this.endpointReference = endpointReference;
+ this.jmsResourceFactory = jmsResourceFactory;
+ this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(registry, jmsBinding);
+ this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(registry, jmsBinding);
+ this.singleArgMap = hashMap;
+ }
+
+ public Message invoke(Message msg) {
+ if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSObject){
+ msg = invokeRequest(msg);
+ }
+
+ msg = getNext().invoke(msg);
+
+ if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSObject){
+ msg = invokeResponse(msg);
+ }
+
+ return msg;
+ }
+
+ public Message invokeRequest(Message msg) {
+ try {
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ Session session = context.getJmsSession();
+
+ javax.jms.Message requestMsg;
+
+ // Tuscany automatically wraps operation arguments in an array before we
+ // get to this point so here we need to decide how they are going to appear
+ // on the wire.
+ //
+ // If the operation has a single parameter and the user has set @wrapSingle=false
+ // then
+ // send the single parameter out onto the wire unwrapped
+ // else
+ // send out the message as is
+ //
+ if (singleArgMap.get(msg.getOperation().getName()) == null) {
+ requestMsg = requestMessageProcessor.insertPayloadIntoJMSMessage(session, msg.getBody());
+ } else {
+ // we know that wrapSinle is set to false here as the provider only
+ // populates singleArgMap if it is set false
+ requestMsg = ((ObjectMessageProcessor) requestMessageProcessor).createJMSMessageForSingleParamOperation(session, msg.getBody(), false);
+ }
+
+ msg.setBody(requestMsg);
+
+ requestMsg.setJMSReplyTo(context.getReplyToDestination());
+
+ return msg;
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ public Message invokeResponse(Message msg) {
+ if (msg.getBody() != null){
+ Object response = responseMessageProcessor.extractPayloadFromJMSMessage((javax.jms.Message)msg.getBody());
+
+ if (response instanceof InvocationTargetException) {
+ msg.setFaultBody(((InvocationTargetException) response).getCause());
+ } else {
+ if (response != null){
+ msg.setBody(response);
+ } else {
+ msg.setBody(null);
+ }
+ }
+ }
+
+ return msg;
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Message processRequest(Message msg) {
+ return invokeRequest(msg);
+ } // end method processRequest
+
+ public Message processResponse(Message msg) {
+ return invokeResponse(msg);
+ } // end method processResponse
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceProvider.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceProvider.java
new file mode 100644
index 0000000000..44e59a0226
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceProvider.java
@@ -0,0 +1,113 @@
+/*
+ * 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.jms.wireformat.jmsobject.runtime;
+
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSObject;
+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.Interceptor;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireFormatJMSObjectReferenceProvider implements WireFormatProvider {
+ private ExtensionPointRegistry registry;
+ private RuntimeEndpointReference endpointReference;
+ private JMSBinding binding;
+ private InterfaceContract interfaceContract;
+
+ private HashMap<String,String> singleArgMap; //map of one arg operations, leave empty if wrapSingleInput is true
+
+ public WireFormatJMSObjectReferenceProvider(ExtensionPointRegistry registry,
+ RuntimeEndpointReference endpointReference) {
+ super();
+ this.registry = registry;
+ this.endpointReference = endpointReference;
+ this.binding = (JMSBinding)endpointReference.getBinding();
+
+ this.singleArgMap = new HashMap<String,String>();
+ ComponentReference reference = endpointReference.getReference();
+
+ // configure the reference based on this wire format
+
+ // currently maintaining the message processor structure which
+ // contains the details of jms message processing however override
+ // any message processors specified in the SCDL in this case
+ if (this.binding.getRequestWireFormat() instanceof WireFormatJMSObject){
+ this.binding.setRequestMessageProcessorName(JMSBindingConstants.OBJECT_MP_CLASSNAME);
+
+ //we don't need to create this map if wrapSingleInput is true
+ if (!((WireFormatJMSObject) this.binding.getRequestWireFormat()).isWrappedSingleInput()){
+ List<Operation> opList = reference.getReference().getInterfaceContract().getInterface().getOperations();
+
+ for (Operation op: opList) {
+ if (op.getInputType().getLogical().size() == 1){
+ this.singleArgMap.put(op.getName(), "");
+ }
+ }
+ }
+ }
+ if (this.binding.getResponseWireFormat() instanceof WireFormatJMSObject){
+ this.binding.setResponseMessageProcessorName(JMSBindingConstants.OBJECT_MP_CLASSNAME);
+ }
+
+ // just point to the reference interface contract so no
+ // databinding transformation takes place
+ interfaceContract = reference.getReference().getInterfaceContract();
+ }
+
+ public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){
+
+ if (this.interfaceContract != null ) {
+ if (this.binding.getRequestWireFormat() instanceof WireFormatJMSObject){
+ // set the request data transformation
+ interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface());
+ }
+ if (this.binding.getResponseWireFormat() instanceof WireFormatJMSObject){
+ // set the response data transformation
+ interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface());
+ }
+ }
+
+ return interfaceContract;
+ }
+
+ public Interceptor createInterceptor() {
+ return new WireFormatJMSObjectReferenceInterceptor(registry, null, endpointReference, this.singleArgMap);
+ }
+
+ public String getPhase() {
+ return Phase.REFERENCE_BINDING_WIREFORMAT;
+ }
+
+ public InterfaceContract getWireFormatInterfaceContract() {
+ return interfaceContract;
+ }
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceInterceptor.java
new file mode 100644
index 0000000000..e04501e8b7
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceInterceptor.java
@@ -0,0 +1,149 @@
+/*
+ * 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.jms.wireformat.jmsobject.runtime;
+
+import java.util.HashMap;
+
+import javax.jms.Session;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.binding.jms.provider.ObjectMessageProcessor;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSObject;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ * 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 WireFormatJMSObjectServiceInterceptor extends InterceptorAsyncImpl {
+ private Invoker next;
+ private RuntimeEndpoint endpoint;
+ private JMSResourceFactory jmsResourceFactory;
+ private JMSBinding jmsBinding;
+ private JMSMessageProcessor requestMessageProcessor;
+ private JMSMessageProcessor responseMessageProcessor;
+ private HashMap<String,Class<?>> singleArgMap;
+ private boolean wrapSingle;
+
+ public WireFormatJMSObjectServiceInterceptor(ExtensionPointRegistry registry, JMSResourceFactory jmsResourceFactory,
+ RuntimeEndpoint endpoint, HashMap<String, Class<?>> singleArgMap, boolean wrapSingle) {
+ super();
+ this.jmsBinding = (JMSBinding) endpoint.getBinding();
+ this.endpoint = endpoint;
+ this.jmsResourceFactory = jmsResourceFactory;
+ this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(registry, jmsBinding);
+ this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(registry, jmsBinding);
+ this.singleArgMap = singleArgMap;
+ this.wrapSingle = wrapSingle;
+ }
+
+ public Message invoke(Message msg) {
+ if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSObject){
+ msg = invokeRequest(msg);
+ }
+
+ msg = getNext().invoke(msg);
+
+ //if it's oneway return back
+ Operation operation = msg.getOperation();
+ if (operation != null && operation.isNonBlocking()) {
+ return msg;
+ }
+
+ if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSObject){
+ msg = invokeResponse(msg);
+ }
+
+ return msg;
+ }
+
+ public Message invokeRequest(Message msg) {
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ javax.jms.Message jmsMsg = context.getJmsMsg();
+ Object requestPayload;
+
+ // If the service interface has a single argument then we need
+ // to check if the object from the wire is expected
+ // to be unwrapped or not
+ //
+ Class<?> argType = this.singleArgMap.get(msg.getOperation().getName());
+ if (argType == null) {
+ requestPayload = requestMessageProcessor.extractPayloadFromJMSMessage(jmsMsg);
+ }else {
+ requestPayload = ((ObjectMessageProcessor)requestMessageProcessor).extractPayloadFromJMSMessageForSingleParamOperation(jmsMsg, argType, wrapSingle);
+ }
+
+ if (requestPayload != null && requestPayload.getClass().isArray()) {
+ msg.setBody(requestPayload);
+ } else if (requestPayload == null) {
+ msg.setBody(new Object[0]);
+ } else {
+ msg.setBody(new Object[] {requestPayload});
+ }
+
+ return msg;
+ }
+
+ public Message invokeResponse(Message msg) {
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ Session session = context.getJmsResponseSession();
+
+ javax.jms.Message responseJMSMsg = null;
+ if (msg.isFault()) {
+ responseJMSMsg = responseMessageProcessor.createFaultMessage(session, (Throwable)msg.getBody());
+ } else {
+ responseJMSMsg = responseMessageProcessor.insertPayloadIntoJMSMessage(session, msg.getBody());
+ }
+
+ msg.setBody(responseJMSMsg);
+
+ return msg;
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Message processRequest(Message msg) {
+ return invokeRequest(msg);
+ } // end method processRequest
+
+ public Message processResponse(Message msg) {
+ return invokeResponse(msg);
+ } // end method processResponse
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceProvider.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceProvider.java
new file mode 100644
index 0000000000..2e50f27a47
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceProvider.java
@@ -0,0 +1,119 @@
+/*
+ * 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.jms.wireformat.jmsobject.runtime;
+
+
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSObject;
+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.Interceptor;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireFormatJMSObjectServiceProvider implements WireFormatProvider {
+ private ExtensionPointRegistry registry;
+ private RuntimeEndpoint endpoint;
+ private JMSBinding binding;
+ private InterfaceContract interfaceContract;
+ private HashMap<String,Class<?>> singleArgMap;
+ private boolean wrapSingle = true;
+
+ public WireFormatJMSObjectServiceProvider(ExtensionPointRegistry registry, RuntimeEndpoint endpoint) {
+ super();
+ this.registry = registry;
+ this.endpoint = endpoint;
+ this.binding = (JMSBinding)endpoint.getBinding();
+ this.singleArgMap = new HashMap<String,Class<?>>();
+
+ ComponentService service = endpoint.getService();
+ // configure the service based on this wire format
+
+ // currently maintaining the message processor structure which
+ // contains the details of jms message processing however override
+ // any message processors specified in the SCDL in this case
+ if (this.binding.getRequestWireFormat() instanceof WireFormatJMSObject){
+ this.binding.setRequestMessageProcessorName(JMSBindingConstants.OBJECT_MP_CLASSNAME);
+
+ List<Operation> opList = service.getService().getInterfaceContract().getInterface().getOperations();
+
+ for (Operation op: opList) {
+ if (op.getInputType().getLogical().size() == 1){
+ this.singleArgMap.put(op.getName(), op.getInputType().getLogical().get(0).getPhysical());
+ }
+ }
+
+ wrapSingle = ((WireFormatJMSObject) this.binding.getRequestWireFormat()).isWrappedSingleInput();
+
+ }
+ if (this.binding.getResponseWireFormat() instanceof WireFormatJMSObject){
+ this.binding.setResponseMessageProcessorName(JMSBindingConstants.OBJECT_MP_CLASSNAME);
+ }
+
+ // just point to the reference interface contract so no
+ // databinding transformation takes place
+ interfaceContract = service.getService().getInterfaceContract();
+
+
+ }
+
+ public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){
+
+ if (this.interfaceContract != null ) {
+ if (this.binding.getRequestWireFormat() instanceof WireFormatJMSObject){
+ // set the request data transformation
+ interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface());
+ }
+ if (this.binding.getResponseWireFormat() instanceof WireFormatJMSObject){
+ // set the response data transformation
+ interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface());
+ }
+ }
+
+ return interfaceContract;
+ }
+
+ /**
+ */
+ public Interceptor createInterceptor() {
+
+ return new WireFormatJMSObjectServiceInterceptor(registry, null, endpoint, this.singleArgMap, wrapSingle);
+ }
+
+ /**
+ */
+ public String getPhase() {
+ return Phase.SERVICE_BINDING_WIREFORMAT;
+ }
+
+ public InterfaceContract getWireFormatInterfaceContract() {
+ return interfaceContract;
+ }
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextProviderFactory.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextProviderFactory.java
new file mode 100644
index 0000000000..e3522616c0
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextProviderFactory.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.jms.wireformat.jmstext.runtime;
+
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSText;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.provider.WireFormatProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireFormatJMSTextProviderFactory implements WireFormatProviderFactory<WireFormatJMSText> {
+ private ExtensionPointRegistry registry;
+
+ public WireFormatJMSTextProviderFactory(ExtensionPointRegistry registry) {
+ super();
+ this.registry = registry;
+ }
+
+ /**
+ */
+ public WireFormatProvider createReferenceWireFormatProvider(RuntimeEndpointReference endpointReference) {
+ return new WireFormatJMSTextReferenceProvider(registry, endpointReference);
+ }
+
+ /**
+ */
+ public WireFormatProvider createServiceWireFormatProvider(RuntimeEndpoint endpoint) {
+ return new WireFormatJMSTextServiceProvider(registry, endpoint);
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType()
+ */
+ public Class getModelType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceInterceptor.java
new file mode 100644
index 0000000000..c2b6881c91
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceInterceptor.java
@@ -0,0 +1,134 @@
+/*
+ * 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.jms.wireformat.jmstext.runtime;
+
+
+import java.lang.reflect.InvocationTargetException;
+
+import javax.jms.JMSException;
+import javax.jms.Session;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSText;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class WireFormatJMSTextReferenceInterceptor extends InterceptorAsyncImpl {
+
+ private Invoker next;
+ private RuntimeEndpointReference endpointReference;
+ private JMSResourceFactory jmsResourceFactory;
+ private JMSBinding jmsBinding;
+ private JMSMessageProcessor requestMessageProcessor;
+ private JMSMessageProcessor responseMessageProcessor;
+
+ public WireFormatJMSTextReferenceInterceptor(ExtensionPointRegistry registry, JMSResourceFactory jmsResourceFactory, RuntimeEndpointReference endpointReference) {
+ super();
+ this.jmsBinding = (JMSBinding) endpointReference.getBinding();
+ this.endpointReference = endpointReference;
+ this.jmsResourceFactory = jmsResourceFactory;
+ this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(registry, jmsBinding);
+ this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(registry, jmsBinding);
+ }
+
+ public Message invoke(Message msg) {
+ if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSText){
+ msg = invokeRequest(msg);
+ }
+
+ msg = getNext().invoke(msg);
+
+ if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSText){
+ msg = invokeResponse(msg);
+ }
+
+ return msg;
+ }
+
+ public Message invokeRequest(Message msg) {
+ try {
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ Session session = context.getJmsSession();
+
+ Object[] requestParams = msg.getBody();
+ javax.jms.Message requestMsg = null;
+ if (requestParams != null && requestParams.length > 0 ){
+ requestMsg = requestMessageProcessor.insertPayloadIntoJMSMessage(session, requestParams[0]);
+ } else {
+ requestMsg = requestMessageProcessor.insertPayloadIntoJMSMessage(session, null);
+ }
+ msg.setBody(requestMsg);
+
+ requestMsg.setJMSReplyTo(context.getReplyToDestination());
+
+ return msg;
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ public Message invokeResponse(Message msg) {
+ if (msg.getBody() != null){
+ Object response = responseMessageProcessor.extractPayloadFromJMSMessage((javax.jms.Message)msg.getBody());
+
+ if (response instanceof InvocationTargetException) {
+ msg.setFaultBody(((InvocationTargetException) response).getCause());
+ } else {
+ if (response != null){
+ msg.setBody(response);
+ } else {
+ msg.setBody(null);
+ }
+ }
+ }
+
+ return msg;
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Message processRequest(Message msg) {
+ return invokeRequest(msg);
+ } // end method processRequest
+
+ public Message processResponse(Message msg) {
+ return invokeResponse(msg);
+ } // end method processResponse
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceProvider.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceProvider.java
new file mode 100644
index 0000000000..5baffd48dd
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceProvider.java
@@ -0,0 +1,101 @@
+/*
+ * 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.jms.wireformat.jmstext.runtime;
+
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSText;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireFormatJMSTextReferenceProvider implements WireFormatProvider {
+ private ExtensionPointRegistry registry;
+ private RuntimeEndpointReference endpointReference;
+ private JMSBinding binding;
+ private InterfaceContract interfaceContract;
+
+ public WireFormatJMSTextReferenceProvider(ExtensionPointRegistry registry,
+ RuntimeEndpointReference endpointReference) {
+ super();
+ this.registry = registry;
+ this.endpointReference = endpointReference;
+ this.binding = (JMSBinding)endpointReference.getBinding();
+
+ // configure the reference based on this wire format
+
+ // currently maintaining the message processor structure which
+ // contains the details of jms message processing however override
+ // any message processors specified in the SCDL in this case
+
+ // this wire format doubles up as the execution logic for user defined
+ // message processors so check the processor name is still set to default
+ // before overwriting
+
+ if ((this.binding.getRequestWireFormat() instanceof WireFormatJMSText) &&
+ (this.binding.getRequestMessageProcessorName().equals(JMSBindingConstants.DEFAULT_MP_CLASSNAME))){
+ this.binding.setRequestMessageProcessorName(JMSBindingConstants.TEXT_MP_CLASSNAME);
+ }
+ if ((this.binding.getResponseWireFormat() instanceof WireFormatJMSText) &&
+ (this.binding.getResponseMessageProcessorName().equals(JMSBindingConstants.DEFAULT_MP_CLASSNAME))){
+ this.binding.setResponseMessageProcessorName(JMSBindingConstants.TEXT_MP_CLASSNAME);
+ }
+
+
+ // just point to the reference interface contract so no
+ // databinding transformation takes place
+ interfaceContract = endpointReference.getReference().getReference().getInterfaceContract();
+ }
+
+ public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){
+
+ if (this.interfaceContract != null ) {
+ if (this.binding.getRequestWireFormat() instanceof WireFormatJMSText){
+ // set the request data transformation
+ interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface());
+ }
+ if (this.binding.getResponseWireFormat() instanceof WireFormatJMSText){
+ // set the response data transformation
+ interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface());
+ }
+ }
+
+ return interfaceContract;
+ }
+
+ public Interceptor createInterceptor() {
+ return new WireFormatJMSTextReferenceInterceptor(registry, null, endpointReference);
+ }
+
+ public String getPhase() {
+ return Phase.REFERENCE_BINDING_WIREFORMAT;
+ }
+
+ public InterfaceContract getWireFormatInterfaceContract() {
+ return interfaceContract;
+ }
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceInterceptor.java
new file mode 100644
index 0000000000..1ba0744593
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceInterceptor.java
@@ -0,0 +1,125 @@
+/*
+ * 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.jms.wireformat.jmstext.runtime;
+
+import javax.jms.Session;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSText;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ * 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 WireFormatJMSTextServiceInterceptor extends InterceptorAsyncImpl {
+ private Invoker next;
+ private RuntimeEndpoint endpoint;
+ private JMSResourceFactory jmsResourceFactory;
+ private JMSBinding jmsBinding;
+ private JMSMessageProcessor requestMessageProcessor;
+ private JMSMessageProcessor responseMessageProcessor;
+
+ public WireFormatJMSTextServiceInterceptor(ExtensionPointRegistry registry, JMSResourceFactory jmsResourceFactory, RuntimeEndpoint endpoint) {
+ super();
+ this.jmsBinding = (JMSBinding) endpoint.getBinding();
+ this.endpoint = endpoint;
+ this.jmsResourceFactory = jmsResourceFactory;
+ this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(registry, jmsBinding);
+ this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(registry, jmsBinding);
+ }
+
+ public Message invoke(Message msg) {
+ if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSText){
+ msg = invokeRequest(msg);
+ }
+
+ msg = getNext().invoke(msg);
+
+ //if it's oneway return back
+ Operation operation = msg.getOperation();
+ if (operation != null && operation.isNonBlocking()) {
+ return msg;
+ }
+
+ if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSText){
+ msg = invokeResponse(msg);
+ }
+
+ return msg;
+ }
+
+ public Message invokeRequest(Message msg) {
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ javax.jms.Message jmsMsg = context.getJmsMsg();
+
+ Object requestPayload = requestMessageProcessor.extractPayloadFromJMSMessage(jmsMsg);
+ msg.setBody(new Object[]{requestPayload});
+
+ return msg;
+ }
+
+ public Message invokeResponse(Message msg) {
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ Session session = context.getJmsResponseSession();
+
+ javax.jms.Message responseJMSMsg;
+ if (msg.isFault()) {
+ responseJMSMsg = responseMessageProcessor.createFaultMessage(session, (Throwable)msg.getBody());
+ } else {
+ Object response = msg.getBody();
+ responseJMSMsg = responseMessageProcessor.insertPayloadIntoJMSMessage(session, response);
+ }
+
+ msg.setBody(responseJMSMsg);
+
+ return msg;
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Message processRequest(Message msg) {
+ return invokeRequest(msg);
+ } // end method processRequest
+
+ public Message processResponse(Message msg) {
+ return invokeResponse(msg);
+ } // end method processResponse
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceProvider.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceProvider.java
new file mode 100644
index 0000000000..f4ee1226c5
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceProvider.java
@@ -0,0 +1,103 @@
+/*
+ * 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.jms.wireformat.jmstext.runtime;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSText;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireFormatJMSTextServiceProvider implements WireFormatProvider {
+ private ExtensionPointRegistry registry;
+ private RuntimeEndpoint endpoint;
+ private JMSBinding binding;
+ private InterfaceContract interfaceContract;
+
+ public WireFormatJMSTextServiceProvider(ExtensionPointRegistry registry,
+ RuntimeEndpoint endpoint) {
+ super();
+ this.registry = registry;
+ this.endpoint = endpoint;
+ this.binding = (JMSBinding)endpoint.getBinding();
+
+ // configure the service based on this wire format
+
+ // currently maintaining the message processor structure which
+ // contains the details of jms message processing however override
+ // any message processors specified in the SCDL in this case
+
+ // this wire format doubles up as the execution logic for user defined
+ // message processors so check the processor name is still set to default
+ // before overwriting
+
+ if ((this.binding.getRequestWireFormat() instanceof WireFormatJMSText) &&
+ (this.binding.getRequestMessageProcessorName().equals(JMSBindingConstants.DEFAULT_MP_CLASSNAME))){
+ this.binding.setRequestMessageProcessorName(JMSBindingConstants.TEXT_MP_CLASSNAME);
+ }
+ if ((this.binding.getResponseWireFormat() instanceof WireFormatJMSText) &&
+ (this.binding.getResponseMessageProcessorName().equals(JMSBindingConstants.DEFAULT_MP_CLASSNAME))){
+ this.binding.setResponseMessageProcessorName(JMSBindingConstants.TEXT_MP_CLASSNAME);
+ }
+
+ // just point to the reference interface contract so no
+ // databinding transformation takes place
+ interfaceContract = endpoint.getService().getService().getInterfaceContract();
+ }
+
+ public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){
+
+ if (this.interfaceContract != null ) {
+ if (this.binding.getRequestWireFormat() instanceof WireFormatJMSText){
+ // set the request data transformation
+ interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface());
+ }
+ if (this.binding.getResponseWireFormat() instanceof WireFormatJMSText){
+ // set the response data transformation
+ interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface());
+ }
+ }
+
+ return interfaceContract;
+ }
+
+ /**
+ */
+ public Interceptor createInterceptor() {
+ return new WireFormatJMSTextServiceInterceptor(registry, null, endpoint);
+ }
+
+ /**
+ */
+ public String getPhase() {
+ return Phase.SERVICE_BINDING_WIREFORMAT;
+ }
+
+ public InterfaceContract getWireFormatInterfaceContract() {
+ return interfaceContract;
+ }
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLProviderFactory.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLProviderFactory.java
new file mode 100644
index 0000000000..fb119078d1
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLProviderFactory.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.jms.wireformat.jmstextxml.runtime;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactoryExtensionPoint;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSTextXML;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.provider.WireFormatProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireFormatJMSTextXMLProviderFactory implements WireFormatProviderFactory<WireFormatJMSTextXML> {
+ private ExtensionPointRegistry registry;
+ private JMSResourceFactoryExtensionPoint jmsRFEP;
+
+ public WireFormatJMSTextXMLProviderFactory(ExtensionPointRegistry registry) {
+ super();
+ this.registry = registry;
+ jmsRFEP = (JMSResourceFactoryExtensionPoint)registry.getExtensionPoint(JMSResourceFactoryExtensionPoint.class);
+ }
+
+ /**
+ */
+ public WireFormatProvider createReferenceWireFormatProvider(RuntimeEndpointReference endpointReference) {
+ return new WireFormatJMSTextXMLReferenceProvider(registry, endpointReference);
+ }
+
+ /**
+ */
+ public WireFormatProvider createServiceWireFormatProvider(RuntimeEndpoint endpoint) {
+ JMSResourceFactory jmsRF = jmsRFEP.createJMSResourceFactory((JMSBinding)endpoint.getBinding());
+ return new WireFormatJMSTextXMLServiceProvider(registry, endpoint, jmsRF);
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType()
+ */
+ public Class getModelType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceInterceptor.java
new file mode 100644
index 0000000000..25e476f837
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceInterceptor.java
@@ -0,0 +1,139 @@
+/*
+ * 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.jms.wireformat.jmstextxml.runtime;
+
+
+
+
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSTextXML;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+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;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+import org.w3c.dom.Node;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class WireFormatJMSTextXMLReferenceInterceptor extends InterceptorAsyncImpl {
+
+ private Invoker next;
+ private RuntimeEndpointReference endpointReference;
+ private JMSResourceFactory jmsResourceFactory;
+ private JMSBinding jmsBinding;
+ private JMSMessageProcessor requestMessageProcessor;
+ private JMSMessageProcessor responseMessageProcessor;
+
+
+ public WireFormatJMSTextXMLReferenceInterceptor(ExtensionPointRegistry registry, JMSResourceFactory jmsResourceFactory, RuntimeEndpointReference endpointReference) {
+ super();
+ this.jmsBinding = (JMSBinding) endpointReference.getBinding();
+ this.endpointReference = endpointReference;
+ this.jmsResourceFactory = jmsResourceFactory;
+ this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(registry, jmsBinding);
+ this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(registry, jmsBinding);
+ }
+
+ public Message invoke(Message msg) {
+ if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSTextXML){
+ msg = invokeRequest(msg);
+ }
+
+ msg = getNext().invoke(msg);
+
+ if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSTextXML){
+ msg = invokeResponse(msg);
+ }
+
+ return msg;
+ }
+
+ public Message invokeRequest(Message msg) {
+ try {
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ Session session = context.getJmsSession();
+
+ javax.jms.Message requestMsg = requestMessageProcessor.insertPayloadIntoJMSMessage(session, msg.getBody());
+ msg.setBody(requestMsg);
+
+ requestMsg.setJMSReplyTo(context.getReplyToDestination());
+
+ return msg;
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ public Message invokeResponse(Message msg) {
+ if (msg.getBody() != null){
+ javax.jms.Message jmsMsg = (javax.jms.Message)msg.getBody();
+ Object response = responseMessageProcessor.extractPayloadFromJMSMessage(jmsMsg);
+ if (response != null ){
+ msg.setBody(response);
+ try {
+ if (jmsMsg.getBooleanProperty(JMSBindingConstants.FAULT_PROPERTY)) {
+ FaultException e = new FaultException("remote exception", response);
+ Node node = ((Node)response).getFirstChild();
+ e.setFaultName(new QName(node.getNamespaceURI(), node.getLocalName()));
+ msg.setFaultBody(e);
+ }
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ } else {
+ msg.setBody(null);
+ }
+ }
+
+ return msg;
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Message processRequest(Message msg) {
+ return invokeRequest(msg);
+ } // end method processRequest
+
+ public Message processResponse(Message msg) {
+ return invokeResponse(msg);
+ } // end method processResponse
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceProvider.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceProvider.java
new file mode 100644
index 0000000000..957994a146
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceProvider.java
@@ -0,0 +1,113 @@
+/*
+ * 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.jms.wireformat.jmstextxml.runtime;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSTextXML;
+import org.apache.tuscany.sca.binding.ws.WebServiceBinding;
+import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory;
+import org.apache.tuscany.sca.binding.ws.wsdlgen.BindingWSDLGenerator;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.databinding.xml.DOMDataBinding;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireFormatJMSTextXMLReferenceProvider implements WireFormatProvider {
+ private ExtensionPointRegistry registry;
+ private RuntimeEndpointReference endpointReference;
+ private JMSBinding binding;
+ private InterfaceContract interfaceContract;
+
+ public WireFormatJMSTextXMLReferenceProvider(ExtensionPointRegistry registry,
+ RuntimeEndpointReference endpointReference) {
+ super();
+ this.registry = registry;
+ this.endpointReference = endpointReference;
+ this.binding = (JMSBinding)endpointReference.getBinding();
+
+ // configure the reference based on this wire format
+
+ // currently maintaining the message processor structure which
+ // contains the details of jms message processing so set the message
+ // type here if not set explicitly in SCDL
+
+ if (this.binding.getRequestWireFormat() instanceof WireFormatJMSTextXML){
+ this.binding.setRequestMessageProcessorName(JMSBindingConstants.XML_MP_CLASSNAME);
+ }
+ if (this.binding.getResponseWireFormat() instanceof WireFormatJMSTextXML){
+ this.binding.setResponseMessageProcessorName(JMSBindingConstants.XML_MP_CLASSNAME);
+ }
+
+ // create a local interface contract that is configured specifically to
+ // deal with the data format that this wire format is expecting to sent to
+ // and receive from the databinding interceptor. The request/response parts of
+ // this interface contract will be copied into the binding interface contract
+ // as required
+ WebServiceBindingFactory wsFactory = registry.getExtensionPoint(WebServiceBindingFactory.class);
+ WebServiceBinding wsBinding = wsFactory.createWebServiceBinding();
+ BindingWSDLGenerator.generateWSDL(endpointReference.getComponent(), endpointReference.getReference(), wsBinding, registry, null);
+ interfaceContract = wsBinding.getBindingInterfaceContract();
+ interfaceContract.getInterface().resetDataBinding(DOMDataBinding.NAME);
+ }
+
+ protected boolean isOnMessage() {
+ InterfaceContract ic = endpointReference.getReference().getInterfaceContract();
+ if (ic.getInterface().getOperations().size() != 1) {
+ return false;
+ }
+ return "onMessage".equals(ic.getInterface().getOperations().get(0).getName());
+ }
+
+ public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){
+
+ if (this.interfaceContract != null && !isOnMessage()) {
+ if (this.binding.getRequestWireFormat() instanceof WireFormatJMSTextXML){
+ // set the request data transformation
+ interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface());
+ }
+ if (this.binding.getResponseWireFormat() instanceof WireFormatJMSTextXML){
+ // set the response data transformation
+ interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface());
+ }
+ }
+
+ return interfaceContract;
+ }
+
+ public Interceptor createInterceptor() {
+ return new WireFormatJMSTextXMLReferenceInterceptor(registry, null, endpointReference);
+ }
+
+ public String getPhase() {
+ return Phase.REFERENCE_BINDING_WIREFORMAT;
+ }
+
+ public InterfaceContract getWireFormatInterfaceContract() {
+ return interfaceContract;
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceInterceptor.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceInterceptor.java
new file mode 100644
index 0000000000..d914bd9e2e
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceInterceptor.java
@@ -0,0 +1,126 @@
+/*
+ * 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.jms.wireformat.jmstextxml.runtime;
+
+import javax.jms.Session;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor;
+import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSTextXML;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ * 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 WireFormatJMSTextXMLServiceInterceptor extends InterceptorAsyncImpl {
+ private Invoker next;
+ private RuntimeEndpoint endpoint;
+ private JMSResourceFactory jmsResourceFactory;
+ private JMSBinding jmsBinding;
+ private JMSMessageProcessor requestMessageProcessor;
+ private JMSMessageProcessor responseMessageProcessor;
+
+ public WireFormatJMSTextXMLServiceInterceptor(ExtensionPointRegistry registry, JMSResourceFactory jmsResourceFactory, RuntimeEndpoint endpoint) {
+ super();
+ this.jmsBinding = (JMSBinding) endpoint.getBinding();
+ this.endpoint = endpoint;
+ this.jmsResourceFactory = jmsResourceFactory;
+ this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(registry, jmsBinding);
+ this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(registry, jmsBinding);
+ }
+
+ public Message invoke(Message msg) {
+
+ if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSTextXML){
+ msg = invokeRequest(msg);
+ }
+
+ msg = getNext().invoke(msg);
+
+ //if it's oneway return back
+ Operation operation = msg.getOperation();
+ if (operation != null && operation.isNonBlocking()) {
+ return msg;
+ }
+
+ if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSTextXML){
+ msg = invokeResponse(msg);
+ }
+
+ return msg;
+ }
+
+ public Message invokeRequest(Message msg) {
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ javax.jms.Message jmsMsg = context.getJmsMsg();
+
+ Object requestPayload = requestMessageProcessor.extractPayloadFromJMSMessage(jmsMsg);
+ msg.setBody(new Object[] { requestPayload });
+
+ return msg;
+ }
+
+ public Message invokeResponse(Message msg) {
+
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ Session session = context.getJmsResponseSession();
+
+ javax.jms.Message responseJMSMsg;
+ if (msg.isFault()) {
+ responseJMSMsg = responseMessageProcessor.createFaultMessage(session, (Throwable)msg.getBody());
+ } else {
+ responseJMSMsg = responseMessageProcessor.insertPayloadIntoJMSMessage(session, msg.getBody());
+ }
+
+ msg.setBody(responseJMSMsg);
+
+ return msg;
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Message processRequest(Message msg) {
+ return invokeRequest(msg);
+ } // end method processRequest
+
+ public Message processResponse(Message msg) {
+ return invokeResponse(msg);
+ } // end method processResponse
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceProvider.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceProvider.java
new file mode 100644
index 0000000000..c56a9e0e50
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceProvider.java
@@ -0,0 +1,108 @@
+/*
+ * 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.jms.wireformat.jmstextxml.runtime;
+
+import org.apache.tuscany.sca.binding.jms.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSTextXML;
+import org.apache.tuscany.sca.binding.ws.WebServiceBinding;
+import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory;
+import org.apache.tuscany.sca.binding.ws.wsdlgen.BindingWSDLGenerator;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.databinding.xml.DOMDataBinding;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireFormatJMSTextXMLServiceProvider implements WireFormatProvider {
+ private ExtensionPointRegistry registry;
+ private RuntimeEndpoint endpoint;
+ private JMSBinding binding;
+ private JMSResourceFactory jmsResourceFactory;
+ private InterfaceContract interfaceContract;
+
+ public WireFormatJMSTextXMLServiceProvider(ExtensionPointRegistry registry,
+ RuntimeEndpoint endpoint,
+ JMSResourceFactory jmsResourceFactory) {
+ super();
+ this.endpoint = endpoint;
+ this.binding = (JMSBinding)endpoint.getBinding();
+ this.jmsResourceFactory = jmsResourceFactory;
+ this.registry = registry;
+
+ // configure the service based on this wire format
+
+ // currently maintaining the message processor structure which
+ // contains the details of jms message processing so set the message
+ // type here if not set explicitly in SCDL
+ if (this.binding.getRequestWireFormat() instanceof WireFormatJMSTextXML){
+ this.binding.setRequestMessageProcessorName(JMSBindingConstants.XML_MP_CLASSNAME);
+ }
+ if (this.binding.getResponseWireFormat() instanceof WireFormatJMSTextXML){
+ this.binding.setResponseMessageProcessorName(JMSBindingConstants.XML_MP_CLASSNAME);
+ }
+
+ // create a local interface contract that is configured specifically to
+ // deal with the data format that this wire format is expecting to sent to
+ // and receive from the databinding interceptor. The request/response parts of
+ // this interface contract will be copied into the binding interface contract
+ // as required
+ WebServiceBindingFactory wsFactory = registry.getExtensionPoint(WebServiceBindingFactory.class);
+ WebServiceBinding wsBinding = wsFactory.createWebServiceBinding();
+ BindingWSDLGenerator.generateWSDL(endpoint.getComponent(), endpoint.getService(), wsBinding, registry, null);
+ interfaceContract = wsBinding.getBindingInterfaceContract();
+ interfaceContract.getInterface().resetDataBinding(DOMDataBinding.NAME);
+ }
+
+ public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){
+
+ if (this.interfaceContract != null) {
+ if (this.binding.getRequestWireFormat() instanceof WireFormatJMSTextXML){
+ // set the request data transformation
+ interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface());
+ }
+ if (this.binding.getResponseWireFormat() instanceof WireFormatJMSTextXML){
+ // set the response data transformation
+ interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface());
+ }
+ }
+
+ return interfaceContract;
+ }
+
+ public Interceptor createInterceptor() {
+ return new WireFormatJMSTextXMLServiceInterceptor(registry, jmsResourceFactory, endpoint);
+ }
+
+ public String getPhase() {
+ return Phase.SERVICE_BINDING_WIREFORMAT;
+ }
+
+ public InterfaceContract getWireFormatInterfaceContract() {
+ return interfaceContract;
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory
new file mode 100644
index 0000000000..1781985232
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory
@@ -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 binding extension
+org.apache.tuscany.sca.binding.jms.provider.JMSBindingProviderFactory;model=org.apache.tuscany.sca.binding.jms.JMSBinding
+
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory
new file mode 100644
index 0000000000..b5d5117b84
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory
@@ -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.jms.operationselector.jmsdefault.runtime.OperationSelectorJMSDefaultProviderFactory;model=org.apache.tuscany.sca.binding.jms.operationselector.OperationSelectorJMSDefault
+org.apache.tuscany.sca.binding.jms.operationselector.jmsuserprop.runtime.OperationSelectorJMSUserPropProviderFactory;model=org.apache.tuscany.sca.binding.jms.operationselector.OperationSelectorJMSUserProp
+
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory
new file mode 100644
index 0000000000..a54b133da6
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory
@@ -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 policy extension
+org.apache.tuscany.sca.binding.jms.policy.authentication.token.provider.JMSTokenAuthenticationPolicyProviderFactory;model=org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAuthenticationPolicy
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory
new file mode 100644
index 0000000000..4baf7ff14e
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory
@@ -0,0 +1,25 @@
+# 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.jms.wireformat.jmsdefault.runtime.WireFormatJMSDefaultProviderFactory;model=org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSDefault
+org.apache.tuscany.sca.binding.jms.wireformat.jmstextxml.runtime.WireFormatJMSTextXMLProviderFactory;model=org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSTextXML
+org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.runtime.WireFormatJMSBytesProviderFactory;model=org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytes
+org.apache.tuscany.sca.binding.jms.wireformat.jmsbytesxml.runtime.WireFormatJMSBytesXMLProviderFactory;model=org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytesXML
+org.apache.tuscany.sca.binding.jms.wireformat.jmstext.runtime.WireFormatJMSTextProviderFactory;model=org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSText
+org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.runtime.WireFormatJMSObjectProviderFactory;model=org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSObject
+
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldClientImpl.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldClientImpl.java
new file mode 100644
index 0000000000..a3a2f0bf1e
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldClientImpl.java
@@ -0,0 +1,43 @@
+/*
+ * 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.jms;
+
+import org.oasisopen.sca.annotation.Reference;
+import org.oasisopen.sca.annotation.Service;
+
+/**
+ * This class implements the HelloWorld service.
+ *
+ * @version $Rev$ $Date$
+ */
+@Service(HelloWorldService.class)
+public class HelloWorldClientImpl implements HelloWorldService {
+
+ private HelloWorldService serviceA;
+
+ @Reference
+ public void setServiceA(HelloWorldService service) {
+ this.serviceA = service;
+ }
+
+ public String sayHello(String name) {
+ return serviceA.sayHello(name);
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldService.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldService.java
new file mode 100644
index 0000000000..d68270f7df
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldService.java
@@ -0,0 +1,31 @@
+/*
+ * 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.jms;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * Interface for the HelloWorld Service.
+ *
+ * @version $Rev$ $Date$
+ */
+@Remotable
+public interface HelloWorldService {
+ String sayHello(String name);
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldServiceImpl.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldServiceImpl.java
new file mode 100644
index 0000000000..a8808c1bd1
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldServiceImpl.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.jms;
+
+/**
+ * Implementation of the HelloWorldService.
+ *
+ * @version $Rev$ $Date$
+ */
+public class HelloWorldServiceImpl implements HelloWorldService {
+
+ public String sayHello(String name) {
+ return "jmsHello " + name;
+ }
+
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/OperationSelectionTestCaseFIXME.java b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/OperationSelectionTestCaseFIXME.java
new file mode 100644
index 0000000000..5b59389a18
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/OperationSelectionTestCaseFIXME.java
@@ -0,0 +1,229 @@
+/*
+ * 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.jms;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.impl.OperationImpl;
+import org.junit.Test;
+
+/**
+ * This unit test is used to ensure that a JMS Message delivered to a Component will select the correct operation based
+ * on the details in section 1.5 of the JMS Binding specification.
+ *
+ * @version $Rev$ $Date$
+ */
+public class OperationSelectionTestCaseFIXME {
+ /**
+ * This test attempts to invoke a Service with a Single method where scaOperationName is not specified in the JMS
+ * Message
+ * <p>
+ * Expected behaviour is that the single method will be invoked as scaOperationName is ignored
+ *
+ * @throws Exception Failed
+ */
+ @Test
+ public void testServiceWithOnlyOneOperationScaOperationNameNotSpecified() throws Exception {
+ // Create the operation we should match
+ final Operation expectedOperation = newOperation("myOperation");
+
+ // Create the list of operations for the Service
+ final List<Operation> operations = new ArrayList<Operation>();
+ operations.add(expectedOperation);
+
+ // The name of the Operation in the JMS Message - not specified
+ final String scaOperationName = null;
+
+ // Do the test
+ doTestJMSBinding(expectedOperation, operations, scaOperationName);
+ }
+
+ /**
+ * This test attempts to invoke a Service with a Single method where scaOperationName in the JMS Message matches the
+ * method name on the Service
+ * <p>
+ * Expected behaviour is that the single method will be invoked as scaOperationName is ignored
+ *
+ * @throws Exception Failed
+ */
+ @Test
+ public void testServiceWithOnlyOneOperationScaOperationNameMatches() throws Exception {
+ // Create the operation we should match
+ final Operation expectedOperation = newOperation("myOperation");
+
+ // Create the list of operations for the Service
+ final List<Operation> operations = new ArrayList<Operation>();
+ operations.add(expectedOperation);
+
+ // The name of the Operation in the JMS Message - matches operation name
+ final String scaOperationName = expectedOperation.getName();
+
+ // Do the test
+ doTestJMSBinding(expectedOperation, operations, scaOperationName);
+ }
+
+ /**
+ * This test attempts to invoke a Service with a Single method where scaOperationName in the JMS Message is
+ * different the method name on the Service
+ * <p>
+ * Expected behaviour is that the single method will be invoked as scaOperationName is ignored
+ *
+ * @throws Exception Failed
+ */
+ @Test
+ public void testServiceWithOnlyOneOperationScaOperationNameDifferent() throws Exception {
+ // Create the operation we should match
+ final Operation expectedOperation = newOperation("myOperation");
+
+ // Create the list of operations for the Service
+ final List<Operation> operations = new ArrayList<Operation>();
+ operations.add(expectedOperation);
+
+ // The name of the Operation in the JMS Message - different to operation name
+ final String scaOperationName = "Does Not Match Opeation Name";
+
+ // Do the test
+ doTestJMSBinding(expectedOperation, operations, scaOperationName);
+ }
+
+ /**
+ * This test attempts to invoke a Service with a multiple operations where scaOperationName specified in the JMS
+ * Message matches an operation name
+ * <p>
+ * Expected behaviour is that the named method will be invoked.
+ *
+ * @throws Exception Failed
+ */
+ @Test
+ public void testServiceWithMultipleOperationsScaOperationNameSpecified() throws Exception {
+ // Create the list of operations for the Service
+ final List<Operation> operations = new ArrayList<Operation>();
+ for (int i = 0; i < 5; i++) {
+ operations.add(newOperation("operation" + i));
+ }
+
+ // Now try and invoke each operation
+ for (Operation expectedOperation : operations) {
+ // The name of the Operation in the JMS Message
+ final String scaOperationName = expectedOperation.getName();
+
+ // Do the test
+ doTestJMSBinding(expectedOperation, operations, scaOperationName);
+ }
+ }
+
+ /**
+ * This test attempts to invoke a Service with a multiple operations where scaOperationName specified in the JMS
+ * Message is not set so we invoke the onMessage() method
+ * <p>
+ * Expected behaviour is that the onMessage() method should be used instead
+ *
+ * @throws Exception Failed
+ */
+ @Test
+ public void testServiceWithMultipleOperationsScaOperationNotSpecified() throws Exception {
+ // Create the list of operations for the Service
+ final List<Operation> operations = new ArrayList<Operation>();
+ for (int i = 0; i < 5; i++) {
+ operations.add(newOperation("operation" + i));
+ }
+
+ // Add the onMessage operation to the Service Contract
+ final Operation onMessageOperation = newOperation("onMessage");
+ operations.add(onMessageOperation);
+
+ // The name of the Operation in the JMS Message is not set so it will attempt
+ // to invoke the onMessage() method
+ final String scaOperationName = null;
+
+ // Do the test
+ doTestJMSBinding(onMessageOperation, operations, scaOperationName);
+ }
+
+ /**
+ * This is the test method that will attempt to unit test invoking a Service with the specified operations using a
+ * JMS Message with the specified scaOperationName to ensure that it invokes the expectedOperation
+ *
+ * @param expectedOperation The Operation we are expecting to be invoked over JMS
+ * @param operations The list of Operations supported by the Service
+ * @param scaOperationName The value to set scaOperationName in the JMS Message
+ * @throws Exception Failed
+ */
+ private void doTestJMSBinding(Operation expectedOperation, List<Operation> operations, String scaOperationName)
+ throws Exception {
+ // Create the test JMS Binding
+ final JMSBinding jmsBinding = new JMSBinding();
+ JMSResourceFactory jmsResourceFactory = null;
+
+ // Extra information for the method we are invoking
+ final String operationParams = "Hello";
+ final Object operationReturnValue = "Operation Success";
+
+ // Mock up the Service. Basically, it is going to call:
+ // List<Operation> opList = service.getInterfaceContract().getInterface().getOperations();
+// final InterfaceContract ifaceContract = EasyMock.createStrictMock(InterfaceContract.class);
+// final RuntimeComponentService service = EasyMock.createStrictMock(RuntimeComponentService.class);
+// final Interface iface = EasyMock.createStrictMock(Interface.class);
+// EasyMock.expect(iface.getOperations()).andReturn(operations);
+// EasyMock.expect(ifaceContract.getInterface()).andReturn(iface);
+// EasyMock.expect(service.getInterfaceContract()).andReturn(ifaceContract);
+//
+// // Mock up getting and invoking the RuntimeWire. It is going to call:
+// // service.getRuntimeWire(jmsBinding).invoke(operation, (Object[])requestPayload);
+// final RuntimeWire runtimeWire = EasyMock.createStrictMock(RuntimeWire.class);
+// EasyMock.expect(service.getRuntimeWire(jmsBinding)).andReturn(runtimeWire);
+// EasyMock.expect(runtimeWire.invoke(expectedOperation, new Object[] {operationParams}))
+// .andReturn(operationReturnValue);
+//
+// // Create the JMS Binding Listener
+// // final DefaultJMSBindingListener bindingListener = new DefaultJMSBindingListener(jmsBinding, jmsResourceFactory, service, null);
+//
+// // Simulate a message
+// final TextMessage requestJMSMsg = EasyMock.createStrictMock(TextMessage.class);
+// EasyMock.expect(requestJMSMsg.getStringProperty("scaOperationName")).andReturn(scaOperationName);
+// EasyMock.expect(requestJMSMsg.getText()).andReturn(operationParams);
+// EasyMock.expect(requestJMSMsg.getJMSReplyTo()).andReturn(null);
+//
+// // Lets put all the mocks into replay mode
+// // EasyMock.replay(iface);
+// EasyMock.replay(ifaceContract);
+// EasyMock.replay(service);
+// EasyMock.replay(requestJMSMsg);
+// EasyMock.replay(runtimeWire);
+
+ // Do the test
+ // bindingListener.onMessage(requestJMSMsg);
+
+ // Verify our Mock objects
+ // EasyMock.verify(iface);
+ // EasyMock.verify(ifaceContract);
+ // EasyMock.verify(service);
+ // EasyMock.verify(requestJMSMsg);
+ // EasyMock.verify(runtimeWire);
+ }
+
+ private static Operation newOperation(String name) {
+ Operation operation = new OperationImpl();
+ operation.setName(name);
+ return operation;
+ }
+}
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/resources/simple/client.composite b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/resources/simple/client.composite
new file mode 100644
index 0000000000..dcea428493
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/resources/simple/client.composite
@@ -0,0 +1,38 @@
+<?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://www.osoa.org/xmlns/sca/1.0"
+ name="RPCComposite">
+
+ <component name="HelloWorldClient">
+ <implementation.java class="org.apache.tuscany.sca.binding.jms.HelloWorldClientImpl"/>
+ <reference name="serviceA" />
+ </component>
+
+ <reference name="serviceA" promote="HelloWorldClient/serviceA">
+ <interface.java interface="org.apache.tuscany.sca.binding.jms.HelloWorldService" />
+ <binding.jms initialContextFactory="org.apache.activemq.jndi.ActiveMQInitialContextFactory" jndiURL="tcp://localhost:61616">
+ <destination name="DestQueueA"/>
+ <response>
+ <destination name="RespQueueA"/>
+ </response>
+ </binding.jms>
+ </reference>
+
+</composite>
diff --git a/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/resources/simple/service.composite b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/resources/simple/service.composite
new file mode 100644
index 0000000000..44b7b29610
--- /dev/null
+++ b/sandbox/sebastien/java/wrapped/modules/binding-jms-runtime/src/test/resources/simple/service.composite
@@ -0,0 +1,35 @@
+<?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://www.osoa.org/xmlns/sca/1.0"
+ name="RPCComposite">
+
+ <component name="HelloWorldService">
+ <implementation.java class="org.apache.tuscany.sca.binding.jms.HelloWorldServiceImpl"/>
+ <service name="HelloWorldService">
+ <binding.jms initialContextFactory="org.apache.activemq.jndi.ActiveMQInitialContextFactory" jndiURL="tcp://localhost:61616">
+ <destination name="DestQueueA" create="always"/>
+ <response>
+ <destination name="RespQueueA" create="always"/>
+ </response>
+ </binding.jms>
+ </service>
+ </component>
+
+</composite>