From 132aa8a77685ec92bc90c03f987650d275a7b639 Mon Sep 17 00:00:00 2001 From: lresende Date: Mon, 30 Sep 2013 06:59:11 +0000 Subject: 2.0.1 RC1 release tag git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1527464 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/binding/jms/context/JMSBindingContext.java | 161 +++++++++ .../jms/headers/HeaderReferenceInterceptor.java | 198 +++++++++++ .../jms/headers/HeaderServiceInterceptor.java | 125 +++++++ .../jms/host/AsyncResponseJMSServiceListener.java | 272 ++++++++++++++ .../jms/host/DefaultJMSHostExtensionPoint.java | 40 +++ .../jms/host/DefaultJMSServiceListener.java | 283 +++++++++++++++ .../jms/host/DefaultJMSServiceListenerFactory.java | 53 +++ .../binding/jms/host/DefaultServiceInvoker.java | 112 ++++++ .../binding/jms/host/JMSAsyncResponseInvoker.java | 98 +++++ .../binding/jms/host/JMSHostExtensionPoint.java | 27 ++ .../sca/binding/jms/host/JMSServiceListener.java | 29 ++ .../jms/host/JMSServiceListenerDetails.java | 37 ++ .../jms/host/JMSServiceListenerFactory.java | 27 ++ ...OperationSelectorJMSDefaultProviderFactory.java | 60 ++++ ...rationSelectorJMSDefaultServiceInterceptor.java | 201 +++++++++++ ...OperationSelectorJMSDefaultServiceProvider.java | 53 +++ ...perationSelectorJMSUserPropProviderFactory.java | 56 +++ ...ationSelectorJMSUserPropServiceInterceptor.java | 115 ++++++ ...perationSelectorJMSUserPropServiceProvider.java | 47 +++ ...MSTokenAuthenticationPolicyProviderFactory.java | 74 ++++ ...enAuthenticationReferencePolicyInterceptor.java | 104 ++++++ ...TokenAuthenticationReferencePolicyProvider.java | 57 +++ ...okenAuthenticationServicePolicyInterceptor.java | 106 ++++++ ...MSTokenAuthenticationServicePolicyProvider.java | 57 +++ .../provider/JMSHeaderPolicyProviderFactory.java | 83 +++++ .../JMSHeaderReferencePolicyInterceptor.java | 88 +++++ .../provider/JMSHeaderReferencePolicyProvider.java | 58 +++ .../jms/provider/AbstractMessageProcessor.java | 161 +++++++++ .../jms/provider/BytesMessageProcessor.java | 120 +++++++ .../DefaultJMSResourceFactoryExtensionPoint.java | 30 ++ .../jms/provider/DefaultMessageProcessor.java | 265 ++++++++++++++ .../provider/JMSBindingAsyncResponseInvoker.java | 44 +++ .../jms/provider/JMSBindingProviderFactory.java | 76 ++++ .../JMSBindingReferenceBindingProvider.java | 223 ++++++++++++ .../provider/JMSBindingServiceBindingProvider.java | 268 ++++++++++++++ .../binding/jms/provider/JMSMessageProcessor.java | 55 +++ .../jms/provider/JMSMessageProcessorUtil.java | 127 +++++++ .../binding/jms/provider/JMSResourceFactory.java | 101 ++++++ .../provider/JMSResourceFactoryExtensionPoint.java | 28 ++ .../jms/provider/JMSResourceFactoryImpl.java | 305 ++++++++++++++++ .../jms/provider/ObjectMessageProcessor.java | 231 ++++++++++++ .../binding/jms/provider/RRBJMSBindingInvoker.java | 394 +++++++++++++++++++++ .../binding/jms/provider/TextMessageProcessor.java | 80 +++++ .../jms/provider/XMLBytesMessageProcessor.java | 131 +++++++ .../jms/provider/XMLTextMessageProcessor.java | 126 +++++++ .../binding/jms/provider/xml/AXIOMXMLHelper.java | 101 ++++++ .../sca/binding/jms/provider/xml/DOMXMLHelper.java | 102 ++++++ .../sca/binding/jms/provider/xml/XMLHelper.java | 37 ++ .../binding/jms/provider/xml/XMLHelperFactory.java | 48 +++ .../transport/TransportReferenceInterceptor.java | 187 ++++++++++ .../jms/transport/TransportServiceInterceptor.java | 302 ++++++++++++++++ .../wire/AsyncResponseDestinationInterceptor.java | 208 +++++++++++ .../jms/wire/CallbackDestinationInterceptor.java | 130 +++++++ .../jms/wire/OperationPropertiesInterceptor.java | 80 +++++ .../runtime/WireFormatJMSBytesProviderFactory.java | 66 ++++ .../WireFormatJMSBytesReferenceInterceptor.java | 133 +++++++ .../WireFormatJMSBytesReferenceProvider.java | 92 +++++ .../WireFormatJMSBytesServiceInterceptor.java | 137 +++++++ .../runtime/WireFormatJMSBytesServiceProvider.java | 101 ++++++ .../WireFormatJMSBytesXMLProviderFactory.java | 64 ++++ .../WireFormatJMSBytesXMLReferenceInterceptor.java | 133 +++++++ .../WireFormatJMSBytesXMLReferenceProvider.java | 101 ++++++ .../WireFormatJMSBytesXMLServiceInterceptor.java | 131 +++++++ .../WireFormatJMSBytesXMLServiceProvider.java | 109 ++++++ .../WireFormatJMSDefaultProviderFactory.java | 66 ++++ .../WireFormatJMSDefaultReferenceInterceptor.java | 184 ++++++++++ .../WireFormatJMSDefaultReferenceProvider.java | 195 ++++++++++ .../WireFormatJMSDefaultServiceInterceptor.java | 189 ++++++++++ .../WireFormatJMSDefaultServiceProvider.java | 189 ++++++++++ .../WireFormatJMSObjectProviderFactory.java | 66 ++++ .../WireFormatJMSObjectReferenceInterceptor.java | 152 ++++++++ .../WireFormatJMSObjectReferenceProvider.java | 113 ++++++ .../WireFormatJMSObjectServiceInterceptor.java | 162 +++++++++ .../WireFormatJMSObjectServiceProvider.java | 122 +++++++ .../runtime/WireFormatJMSTextProviderFactory.java | 66 ++++ .../WireFormatJMSTextReferenceInterceptor.java | 134 +++++++ .../WireFormatJMSTextReferenceProvider.java | 101 ++++++ .../WireFormatJMSTextServiceInterceptor.java | 137 +++++++ .../runtime/WireFormatJMSTextServiceProvider.java | 107 ++++++ .../WireFormatJMSTextXMLProviderFactory.java | 66 ++++ .../WireFormatJMSTextXMLReferenceInterceptor.java | 139 ++++++++ .../WireFormatJMSTextXMLReferenceProvider.java | 114 ++++++ .../WireFormatJMSTextXMLServiceInterceptor.java | 138 ++++++++ .../WireFormatJMSTextXMLServiceProvider.java | 109 ++++++ 84 files changed, 10197 insertions(+) create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/context/JMSBindingContext.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderReferenceInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderServiceInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/AsyncResponseJMSServiceListener.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSHostExtensionPoint.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListener.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListenerFactory.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultServiceInvoker.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSAsyncResponseInvoker.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSHostExtensionPoint.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSServiceListener.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSServiceListenerDetails.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSServiceListenerFactory.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultProviderFactory.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceProvider.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropProviderFactory.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceProvider.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationPolicyProviderFactory.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationReferencePolicyInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationReferencePolicyProvider.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationServicePolicyInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationServicePolicyProvider.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/provider/JMSHeaderPolicyProviderFactory.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/provider/JMSHeaderReferencePolicyInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/provider/JMSHeaderReferencePolicyProvider.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/AbstractMessageProcessor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/BytesMessageProcessor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultJMSResourceFactoryExtensionPoint.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultMessageProcessor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingAsyncResponseInvoker.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingProviderFactory.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorUtil.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactory.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryExtensionPoint.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingInvoker.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/TextMessageProcessor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLBytesMessageProcessor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLTextMessageProcessor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/xml/AXIOMXMLHelper.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/xml/DOMXMLHelper.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/xml/XMLHelper.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/xml/XMLHelperFactory.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportReferenceInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/AsyncResponseDestinationInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/OperationPropertiesInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesProviderFactory.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceProvider.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceProvider.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLProviderFactory.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceProvider.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceProvider.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultProviderFactory.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceProvider.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceProvider.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectProviderFactory.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceProvider.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceProvider.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextProviderFactory.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceProvider.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceProvider.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLProviderFactory.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceProvider.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceInterceptor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceProvider.java (limited to 'sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java') diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/context/JMSBindingContext.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/context/JMSBindingContext.java new file mode 100644 index 0000000000..6ed6ee997c --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/context/JMSBindingContext.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.context; + +import java.util.Hashtable; + +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; + private long requestTimeout; + private Hashtable properties = new Hashtable(); + + 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; + } + + public void setRequestTimeout(long l) { + this.requestTimeout = l; + } + + public void setProperty(String key, Object value){ + properties.put(key, value); + } + + public Object getProperty(String key){ + return properties.get(key); + } + + public void removeProperty(String key){ + properties.remove(key); + } +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderReferenceInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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 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 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderServiceInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderServiceInterceptor.java new file mode 100644 index 0000000000..6f1c6ed10e --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderServiceInterceptor.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.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.binding.jms.provider.JMSMessageProcessor; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; +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; + +public class HeaderServiceInterceptor extends InterceptorAsyncImpl { + + private Invoker next; + private JMSBinding jmsBinding; + private JMSMessageProcessor responseMessageProcessor; + + public HeaderServiceInterceptor(ExtensionPointRegistry extensions, JMSBinding jmsBinding) { + super(); + this.jmsBinding = jmsBinding; + this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(extensions, 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(); + + responseMessageProcessor.setOperationName(operationName, jmsMsg); + + for (String propName : jmsBinding.getPropertyNames()) { + Object value = jmsBinding.getProperty(propName); + jmsMsg.setObjectProperty(propName, value); + } // end for + + Map 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/AsyncResponseJMSServiceListener.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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. + *

+ * What happens in the look up will depend on the create mode specified for the JMS Binding: + *

    + *
  • always - the JMS queue is always created. It is an error if the queue already exists + *
  • ifnotexist - the JMS queue is created if it does not exist. It is not an error if the queue already exists + *
  • never - the JMS queue is never created. It is an error if the queue does not exist + *
+ * See the SCA JMS Binding specification for more information. + *

+ * @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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSHostExtensionPoint.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListener.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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. + *

+ * What happens in the look up will depend on the create mode specified for the JMS Binding: + *

    + *
  • always - the JMS queue is always created. It is an error if the queue already exists + *
  • ifnotexist - the JMS queue is created if it does not exist. It is not an error if the queue already exists + *
  • never - the JMS queue is never created. It is an error if the queue does not exist + *
+ * See the SCA JMS Binding specification for more information. + *

+ * + * @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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListenerFactory.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListenerFactory.java new file mode 100644 index 0000000000..f829e15f04 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListenerFactory.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.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 DefaultJMSServiceListener(listener, service.getName(), service.isForCallback(), jmsSLD.getJmsBinding(), workScheduler, rf); + + } catch (NamingException e) { + throw new JMSBindingException(e); + } + } +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultServiceInvoker.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSAsyncResponseInvoker.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSHostExtensionPoint.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSServiceListener.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSServiceListenerDetails.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSServiceListenerFactory.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultProviderFactory.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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 { + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceInterceptor.java new file mode 100644 index 0000000000..352141682d --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceInterceptor.java @@ -0,0 +1,201 @@ +/* + * 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.provider.xml.XMLHelper; +import org.apache.tuscany.sca.binding.jms.provider.xml.XMLHelperFactory; +import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytesXML; +import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSDefault; +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.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +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 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 serviceOperations; + private XMLHelper xmlHelper; + + 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.xmlHelper = XMLHelperFactory.createXMLHelper(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 + || jmsBinding.getRequestWireFormat() instanceof WireFormatJMSBytesXML) { + + String operationFromPayload; + + try { + if (jmsMsg instanceof TextMessage) { + String xmlPayload = ((TextMessage) jmsMsg).getText(); + + if (xmlPayload != null) { + Object rootElement = xmlHelper.load(xmlPayload); + operationFromPayload = xmlHelper.getOperationName(rootElement); + if (operationFromPayload != null) { + 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) { + Object rootElement = xmlHelper.load(new String(bytes)); + operationFromPayload = xmlHelper.getOperationName(rootElement); + if (operationFromPayload != null) { + 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 (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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceProvider.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropProviderFactory.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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 { + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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 + * + * + * + */ +public class OperationSelectorJMSUserPropServiceInterceptor extends InterceptorAsyncImpl { + + private Invoker next; + private RuntimeEndpoint endpoint; + private JMSBinding jmsBinding; + private OperationSelectorJMSUserProp operationSelector; + private RuntimeComponentService service; + private List 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceProvider.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationPolicyProviderFactory.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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 { + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationReferencePolicyInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationReferencePolicyProvider.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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 { + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationServicePolicyInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/provider/JMSTokenAuthenticationServicePolicyProvider.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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 { + + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/provider/JMSHeaderPolicyProviderFactory.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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 { + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/provider/JMSHeaderReferencePolicyInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/provider/JMSHeaderReferencePolicyProvider.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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 { + + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/AbstractMessageProcessor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/AbstractMessageProcessor.java new file mode 100644 index 0000000000..9a5ac8598c --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/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 { + if (message != null) { + 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.getClass().getName() + ": " + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/BytesMessageProcessor.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultJMSResourceFactoryExtensionPoint.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultMessageProcessor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultMessageProcessor.java new file mode 100644 index 0000000000..0288ecb5ba --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultMessageProcessor.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.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 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.xml.XMLHelper; +import org.apache.tuscany.sca.binding.jms.provider.xml.XMLHelperFactory; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.util.FaultException; + +/** + * 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 XMLHelper xmlHelper; + + public DefaultMessageProcessor(JMSBinding jmsBinding, ExtensionPointRegistry registry) { + super(jmsBinding); + this.xmlHelper = XMLHelperFactory.createXMLHelper(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, Object wrapper) { + if (msg instanceof TextMessage) { + try { + String xml = ((TextMessage) msg).getText(); + + Object os; + if (xml != null && xml.length() > 0) { + os = xmlHelper.load(xml); + } else { + os = null; + } + + if (wrapper != null){ + return xmlHelper.wrap(wrapper, os); + } + + return os; + + } catch (JMSException e) { + throw new JMSBindingException(e); + } catch (IOException 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 Object[])) { + if (unwrap){ + Object firstElement = xmlHelper.getFirstChild(((Object[])o)[0]); + if (firstElement == null ) { + message.setText(null); + } else { + message.setText(xmlHelper.saveAsString(firstElement)); + } + }else { + message.setText(xmlHelper.saveAsString(((Object[])o)[0])); + } + } else if (o != null) { + if (unwrap){ + Object firstElement = xmlHelper.getFirstChild(o); + if (firstElement == null ) { + message.setText(""); + } else { + message.setText(xmlHelper.saveAsString(firstElement)); + } + }else { + message.setText(xmlHelper.saveAsString(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(xmlHelper.saveAsString(((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, Object 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 = xmlHelper.load(new String(bytes)); + } else { + os = null; + } + + if (wrapper != null){ + return xmlHelper.wrap(wrapper, os); + } + + return os; + + } catch (JMSException e) { + throw new JMSBindingException(e); + } catch (IOException 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 Object[])) { + if (unwrap){ + Object firstElement = xmlHelper.getFirstChild(((Object[])o)[0]); + if (firstElement == null ) { + //do nothing, the message will just be set with a byte[0] + } else { + message.writeBytes(xmlHelper.saveAsString(firstElement).getBytes()); + } + + }else { + message.writeBytes(xmlHelper.saveAsString(((Object[]) o)[0]).getBytes()); + } + } else if (o != null) { + if (unwrap) { + Object firstElement = xmlHelper.getFirstChild(o); + if (firstElement == null ) { + //do nothing, the message will just be set with a byte[0] + } else { + message.writeBytes(xmlHelper.saveAsString(firstElement).getBytes()); + } + + } else { + message.writeBytes(xmlHelper.saveAsString(o).getBytes()); + } + } + + 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 = xmlHelper.saveAsString(((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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingAsyncResponseInvoker.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingAsyncResponseInvoker.java new file mode 100644 index 0000000000..1df3403451 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingAsyncResponseInvoker.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.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) { + // Deliberately left null since in JMS the TransportServiceInterceptor does all the work + } // end method invokeAsyncResponse + +} // end class JMSBindingAsyncResponseInvoker \ No newline at end of file diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingProviderFactory.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingProviderFactory.java new file mode 100644 index 0000000000..174b9de825 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/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 { + + protected ExtensionPointRegistry extensionPoints; + protected JMSResourceFactoryExtensionPoint jmsRFEP; + protected 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 getModelType() { + return JMSBinding.class; + } + +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java new file mode 100644 index 0000000000..33588f75fc --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java @@ -0,0 +1,223 @@ +/* + * 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 { + + protected RuntimeEndpointReference endpointReference; + protected RuntimeComponentReference reference; + protected JMSBinding jmsBinding; + protected JMSResourceFactory jmsResourceFactory; + protected InterfaceContract interfaceContract; + protected ExtensionPointRegistry extensions; + + protected ProviderFactoryExtensionPoint providerFactories; + + protected WireFormatProviderFactory requestWireFormatProviderFactory; + protected WireFormatProvider requestWireFormatProvider; + + protected WireFormatProviderFactory responseWireFormatProviderFactory; + protected WireFormatProvider responseWireFormatProvider; + + protected 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 + + public JMSResourceFactory getJMSResourceFactory() { + return jmsResourceFactory; + } + +} // end class diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java new file mode 100644 index 0000000000..bbc43ba26f --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java @@ -0,0 +1,268 @@ +/* + * 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.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()); + + protected ExtensionPointRegistry registry; + protected RuntimeEndpoint endpoint; + protected RuntimeComponentService service; + protected Binding targetBinding; + protected JMSBinding jmsBinding; + protected JMSResourceFactory jmsResourceFactory; + protected JMSServiceListenerFactory serviceListenerFactory; + protected JMSServiceListener serviceListener; + + protected RuntimeComponent component; + protected InterfaceContract interfaceContract; + + protected ProviderFactoryExtensionPoint providerFactories; + protected FactoryExtensionPoint modelFactories; + + protected MessageFactory messageFactory; + + protected OperationSelectorProviderFactory operationSelectorProviderFactory; + protected OperationSelectorProvider operationSelectorProvider; + + protected WireFormatProviderFactory requestWireFormatProviderFactory; + protected WireFormatProvider requestWireFormatProvider; + + protected WireFormatProviderFactory responseWireFormatProviderFactory; + protected 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"); + } + + initBindingName(); + + // 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(); + } + } + + protected void initBindingName() { + // 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()); +// } + } + } + + 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(registry, jmsBinding)); + + // add async response interceptor after header interceptor + bindingChain.addInterceptor(Phase.SERVICE_BINDING_WIREFORMAT, + new AsyncResponseDestinationInterceptor(endpoint, registry) ); + + // 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessor.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorUtil.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorUtil.java new file mode 100644 index 0000000000..e96f273d4a --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorUtil.java @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.provider; + +import java.lang.reflect.Constructor; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.security.PrivilegedExceptionAction; +import java.security.PrivilegedActionException; + +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.apache.tuscany.sca.extensibility.ServiceDeclaration; + +/** + * 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, final String className, final JMSBinding binding) { + Object instance; + if (cl == null) { + cl = cl = AccessController.doPrivileged(new PrivilegedAction() { + public ClassLoader run() { + return binding.getClass().getClassLoader(); + } + }); + } + + try { + Class clazz; + + try { + clazz = cl.loadClass(className); + } catch (ClassNotFoundException e) { + try{ + clazz = AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Class run() throws ClassNotFoundException{ + return binding.getClass().getClassLoader().loadClass(className); + } + }); + } catch (PrivilegedActionException ex) { + throw (ClassNotFoundException) ex.getException(); + } + + } + + 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) { + try { + for (ServiceDeclaration sd : registry.getServiceDiscovery().getServiceDeclarations(JMSMessageProcessor.class)) { + if (className.equals(sd.getClassName())) { + final Class clazz = sd.loadClass(); + Constructor constructor; + try { + constructor = AccessController.doPrivileged(new PrivilegedExceptionAction>() { + public Constructor run() throws NoSuchMethodException{ + return clazz.getDeclaredConstructor(new Class[] {JMSBinding.class, ExtensionPointRegistry.class}); + } + }); + } catch (PrivilegedActionException ex) { + throw (NoSuchMethodException) ex.getException(); + } + return constructor.newInstance(binding, registry); + } + + } + throw new JMSBindingException("Class not found: " + className); + } catch (Throwable e) { + throw new JMSBindingException("Exception instantiating OperationAndDataBinding class", e); + } + } + + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactory.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactory.java new file mode 100644 index 0000000000..77009157f6 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactory.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.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); + + public abstract long getDefaultRequestTimeout(); +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryExtensionPoint.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java new file mode 100644 index 0000000000..0ff7f14e95 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java @@ -0,0 +1,305 @@ +/* + * 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.resource.spi.ActivationSpec; + +import org.apache.tuscany.sca.binding.jms.JMSBindingException; + +/** + * 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); + context = new InitialContext(props); + + } + return context; + } + + /** + * 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()); + } + + @Override + public long getDefaultRequestTimeout() { + return 0; + } + +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingInvoker.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingInvoker.java new file mode 100644 index 0000000000..ff96f56759 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingInvoker.java @@ -0,0 +1,394 @@ +/* + * 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.CallbackHandler; +import org.apache.tuscany.sca.core.invocation.Constants; +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. + *

+ * What happens in the look up will depend on the create mode specified for the JMS Binding: + *

    + *
  • always - the JMS queue is always created. It is an error if the queue already exists + *
  • ifnotexist - the JMS queue is created if it does not exist. It is not an error if the queue already exists + *
  • never - the JMS queue is never created. It is an error if the queue does not exist + *
+ * See the SCA JMS Binding specification for more information. + *

+ * + * @param isReponseQueue true if we are creating a response queue. + * false 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)); + Long ttl = jmsBinding.getOperationJMSTimeToLive(operationName); + if (ttl != null) { + context.setTimeToLive(ttl); + } + + // For twoway operations, determine a request timeout. + // The SCA specs do not address how to do this. We use the following approach. + // - If JMSTimeToLive is specified, use double that value. + // Doubling is basically arbitrary. JMSTimeToLive expresses request + // transmission and queue time. Doubling it allows request execution + // and response delivery to take up to the same amount of time. + // Note that explicitly coding a JMSTimeToLive of 0 results in + // a message that doesn't expire and an indefinite wait. + // - If JMSTimeToLive is not specified, get the default request + // timeout from the JMS resource factory and simply use that for the + // request timeout and JMSTimeToLive value. + if (!operation.isNonBlocking()) { + if (ttl != null) { + context.setRequestTimeout(ttl * 2); + } else { + long timeout = jmsResourceFactory.getDefaultRequestTimeout(); + context.setRequestTimeout(timeout); + context.setTimeToLive(timeout); + } + } + + 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 = null; + + if (endpointReference.getReference().isForCallback()) { + + // Check if the CallbackDestinationInterceptor set a callback destination from the request msg + if (tuscanyMsg.getFrom().getTargetEndpoint() != null) { + if (tuscanyMsg.getFrom().getTargetEndpoint().getBinding() != null) { + this.jmsBinding = (JMSBinding)tuscanyMsg.getFrom().getTargetEndpoint().getBinding(); + +/* TUSCANY-4011 - we could delay until this point until setting the callback destination + CallbackHandler callbackHandler = (CallbackHandler)tuscanyMsg.getHeaders().get(Constants.CALLBACK); + if (callbackHandler != null && callbackHandler.getCallbackTargetURI() != null){ + this.jmsBinding.setDestinationName(callbackHandler.getCallbackTargetURI()); + } +*/ + requestDestination = lookupDestination(); + } + } + } + + if (requestDestination == null) { + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/TextMessageProcessor.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLBytesMessageProcessor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLBytesMessageProcessor.java new file mode 100644 index 0000000000..5ca47da2c5 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLBytesMessageProcessor.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.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.binding.jms.provider.xml.XMLHelper; +import org.apache.tuscany.sca.binding.jms.provider.xml.XMLHelperFactory; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.util.FaultException; + +/** + * 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 XMLHelper xmlHelper; + + public XMLBytesMessageProcessor(JMSBinding jmsBinding, ExtensionPointRegistry registry) { + super(jmsBinding); + this.xmlHelper = XMLHelperFactory.createXMLHelper(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 = xmlHelper.load(new String(bytes)); + } else { + os = null; + } + return os; + } catch (JMSException e) { + throw new JMSBindingException(e); + } catch (IOException 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 Object[])) { + message.writeBytes(xmlHelper.saveAsString(((Object[])o)[0]).getBytes()); + } else if (o != null) { + message.writeBytes(xmlHelper.saveAsString(o).getBytes()); + } + + 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(xmlHelper.saveAsString(((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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLTextMessageProcessor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLTextMessageProcessor.java new file mode 100644 index 0000000000..44588dfb7d --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLTextMessageProcessor.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.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.binding.jms.provider.xml.XMLHelper; +import org.apache.tuscany.sca.binding.jms.provider.xml.XMLHelperFactory; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.util.FaultException; + +/** + * 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 XMLHelper xmlHelper; + + public XMLTextMessageProcessor(JMSBinding jmsBinding, ExtensionPointRegistry registry) { + super(jmsBinding); + this.xmlHelper = XMLHelperFactory.createXMLHelper(registry); + } + + @Override + protected Object extractPayload(Message msg) { + try { + + String xml = ((TextMessage)msg).getText(); + Object os; + if (xml != null) { + os = xmlHelper.load(xml); + } else { + os = null; + } + return os; + + } catch (IOException e) { + throw new JMSBindingException(e); + } catch (JMSException 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 Object[]) { + message.setText(xmlHelper.saveAsString(((Object[])o)[0])); + } else { + message.setText(xmlHelper.saveAsString(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(xmlHelper.saveAsString(((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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/xml/AXIOMXMLHelper.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/xml/AXIOMXMLHelper.java new file mode 100644 index 0000000000..4e71fd21f0 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/xml/AXIOMXMLHelper.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.provider.xml; + +import java.io.IOException; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.tuscany.sca.common.xml.stax.StAXHelper; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.util.FaultException; + +public class AXIOMXMLHelper implements XMLHelper { + + private OMFactory factory; + private StAXHelper staxhelper; + + public AXIOMXMLHelper(ExtensionPointRegistry epr) { + this.staxhelper = StAXHelper.getInstance(epr); + this.factory = OMAbstractFactory.getOMFactory(); + } + + @Override + public OMElement load(String xml) throws IOException { + StAXOMBuilder builder; + try { + builder = new StAXOMBuilder(staxhelper.createXMLStreamReader(xml)); + } catch (XMLStreamException e) { + throw new IOException(e); + } + return builder.getDocumentElement(); + } + + @Override + public String saveAsString(OMElement t) { + // TODO: The JMS compliance tests require the XML prefix but AXIOM doesn't include that + return "" + t.toString(); + } + + @Override + public String getOperationName(OMElement t) { + return t.getLocalName(); + } + + @Override + public Object wrap(OMElement template, OMElement os) { + OMElement wrapper; + if (os != null) { + OMNamespace ns = os.declareNamespace(template.getNamespace().getNamespaceURI(), ""); + wrapper = factory.createOMElement(template.getLocalName(), ns); + wrapper.addChild(os); + } else { + wrapper = template.cloneOMElement(); + } + return wrapper; + } + + @Override + public OMElement createWrapper(QName qname) { + return factory.createOMElement(qname); + } + + @Override + public String getDataBindingName() { + return OMElement.class.getName(); + } + + @Override + public OMElement getFirstChild(OMElement o) { + return o.getFirstElement(); + } + + @Override + public void setFaultName(FaultException e, Object o) { + OMElement om = (OMElement)o; + e.setFaultName(new QName(om.getNamespace().getNamespaceURI(), om.getLocalName())); + } +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/xml/DOMXMLHelper.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/xml/DOMXMLHelper.java new file mode 100644 index 0000000000..f0bed9833c --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/xml/DOMXMLHelper.java @@ -0,0 +1,102 @@ +/* + * 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.xml; + +import java.io.IOException; + +import javax.xml.namespace.QName; + +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; + +public class DOMXMLHelper implements XMLHelper { + + private DOMHelper domHelper; + + public DOMXMLHelper(ExtensionPointRegistry epr) { + this.domHelper = DOMHelper.getInstance(epr); + } + + @Override + public Document load(String xml) throws IOException { + try { + return domHelper.load(xml); + } catch (SAXException e) { + throw new IOException(e); + } + } + + @Override + public String saveAsString(Node t) { + return domHelper.saveAsString(t); + } + + @Override + public String getOperationName(Node t) { + Node firstChild = t.getFirstChild(); + if (firstChild != null) { + return firstChild.getLocalName(); + } + return null; + } + + @Override + public Object wrap(Node wrapper, Node os) { + //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; + } + + @Override + public Node createWrapper(QName qname) { + Document document = domHelper.newDocument(); + Element wrapper = DOMHelper.createElement(document, qname); + return wrapper; + } + + @Override + public String getDataBindingName() { + return Node.class.getName(); + } + + @Override + public Node getFirstChild(Node o) { + return o.getFirstChild(); + } + @Override + public void setFaultName(FaultException e, Object response) { + Node n = ((Node)response).getFirstChild(); + e.setFaultName(new QName(n.getNamespaceURI(), n.getLocalName())); + } +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/xml/XMLHelper.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/xml/XMLHelper.java new file mode 100644 index 0000000000..3fbe561c60 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/xml/XMLHelper.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.provider.xml; + +import java.io.IOException; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.interfacedef.util.FaultException; + +public interface XMLHelper { + T load(String xml) throws IOException; + String saveAsString(T t); + String getOperationName(T t); + Object wrap(T template, T t); + T createWrapper(QName qname); + String getDataBindingName(); + T getFirstChild(T object); + void setFaultName(FaultException e, Object response); +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/xml/XMLHelperFactory.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/xml/XMLHelperFactory.java new file mode 100644 index 0000000000..3533e9182a --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/xml/XMLHelperFactory.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.provider.xml; + +import java.util.Properties; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.runtime.RuntimeProperties; + +public class XMLHelperFactory { + + public static XMLHelper createXMLHelper(ExtensionPointRegistry epr) { + + XMLHelper xmlHelper = epr.getExtensionPoint(UtilityExtensionPoint.class).getUtility(XMLHelper.class); + if (xmlHelper != null) { + return xmlHelper; + } + if (useAXIOM(epr)) { + return new AXIOMXMLHelper(epr); + } else { + return new DOMXMLHelper(epr); + } + } + + private static boolean useAXIOM(ExtensionPointRegistry epr) { + Properties runtimeProps = epr.getExtensionPoint(UtilityExtensionPoint.class).getUtility(RuntimeProperties.class).getProperties(); + return Boolean.parseBoolean(runtimeProps.getProperty(RuntimeProperties.USE_AXIOM)); + } + +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportReferenceInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java new file mode 100644 index 0000000000..214e2b7324 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.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.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) { + try { + // Normally only runtime exceptions (whether thrown by the application or the runtime) + // reach this catch block. Business exceptions are handled in the normal invokeResponse path. + logger.log(Level.SEVERE, "Exception invoking service '" + service.getName(), e); + + Operation operation = msg.getOperation(); + if (operation == null || !operation.isNonBlocking()) { + JMSBindingContext context = msg.getBindingContext(); + Session session = context.getJmsResponseSession(); + javax.jms.Message replyJMSMsg = responseMessageProcessor.createFaultMessage(session, e); + msg.setBody(replyJMSMsg); + invokeResponse(msg); + } + + } catch (Throwable e2) {} + // Rethrow a runtime exception so that the JMS resource adapter can rollback + // the message (if delivery is transacted) and increment the failed delivery count. + if (e instanceof Error) { + throw (Error)e; + } + if (e instanceof RuntimeException) { + throw (RuntimeException)e; + } + return msg; + } finally { + try { + try { + ((JMSBindingContext)msg.getBindingContext()).closeJmsResponseSession(); + } catch (Throwable e) { + } + // Use the resource factory in the binding context to close the response connection, + // to ensure we use same resource factory used to close response session. + JMSResourceFactory rf = ((JMSBindingContext)msg.getBindingContext()).getJmsResourceFactory(); + if (rf.isConnectionClosedAfterUse()) + rf.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); + 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. + producer.setDeliveryMode(responseJMSMsg.getJMSDeliveryMode()); + producer.setPriority(responseJMSMsg.getJMSPriority()); + producer.setTimeToLive(responseJMSMsg.getJMSExpiration()); + + 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(); + Destination replyDest = context.getReplyToDestination(); + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/AsyncResponseDestinationInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/AsyncResponseDestinationInterceptor.java new file mode 100644 index 0000000000..0ecee7777c --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/AsyncResponseDestinationInterceptor.java @@ -0,0 +1,208 @@ +/* + * 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.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +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.invocation.MessageFactory; +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; + private ExtensionPointRegistry registry; + + public AsyncResponseDestinationInterceptor(RuntimeEndpoint endpoint, ExtensionPointRegistry registry) { + super(); + this.service = (RuntimeComponentService) endpoint.getService(); + this.endpoint = endpoint; + this.registry = registry; + } + + 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"); + + String operationName = msg.getOperation().getName(); + + // Create a response invoker and add it to the message headers + AsyncResponseInvoker respInvoker = + new AsyncResponseInvoker(endpoint, null, asyncRespAddr, msgID, operationName, getMessageFactory()); + 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 respInvoker = (AsyncResponseInvoker)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 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 + + private MessageFactory getMessageFactory() { + FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); + return modelFactories.getFactory(MessageFactory.class); + } // end method getMessageFactory + +} // end class \ No newline at end of file diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java new file mode 100644 index 0000000000..8eaa414ae3 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java @@ -0,0 +1,130 @@ +/* + * 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 javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Queue; +import javax.jms.Topic; + +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.CallbackHandler; +import org.apache.tuscany.sca.core.invocation.Constants; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; +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.apache.tuscany.sca.assembly.Binding; + +/** + * 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 = "jms:queue:" + callbackdestName.substring(9); + } + } else { + // If there is no Callback destination name header present, but the service is a callback, use the JMS ReplyTo header + // as per the spec this will override anything specified by the user in SCDL + if (service.getInterfaceContract().getCallbackInterface() != null) { + if ( ( jmsMsg.getJMSReplyTo() != null ) && msg.getOperation().isNonBlocking() ) { + Destination replyTo = jmsMsg.getJMSReplyTo(); + if (replyTo != null) { + if (replyTo instanceof Queue){ + callbackdestName = "jms:queue:" + ((Queue) replyTo).getQueueName(); + } else { + callbackdestName = "jms:topic:" + ((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) { + msg.getHeaders().put(Constants.CALLBACK, new CallbackHandler(callbackdestName)); + } // 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/OperationPropertiesInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/OperationPropertiesInterceptor.java new file mode 100644 index 0000000000..e665e03795 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/OperationPropertiesInterceptor.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.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 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.getOpNameFromNativeOperationName(operationName); + + if (operationNameOverride != null) { + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesProviderFactory.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesProviderFactory.java new file mode 100644 index 0000000000..e6ef82e55d --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesProviderFactory.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.jmsbytes.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; + +/** + * @version $Rev$ $Date$ + */ +public class WireFormatJMSBytesProviderFactory implements WireFormatProviderFactory { + private ExtensionPointRegistry registry; + private JMSResourceFactoryExtensionPoint jmsRFEP; + + public WireFormatJMSBytesProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + jmsRFEP = (JMSResourceFactoryExtensionPoint)registry.getExtensionPoint(JMSResourceFactoryExtensionPoint.class); + } + + /** + */ + public WireFormatProvider createReferenceWireFormatProvider(RuntimeEndpointReference endpointReference) { + return new WireFormatJMSBytesReferenceProvider(registry, endpointReference); + } + + /** + */ + public WireFormatProvider createServiceWireFormatProvider(RuntimeEndpoint endpoint) { + JMSResourceFactory jmsRF = jmsRFEP.createJMSResourceFactory((JMSBinding)endpoint.getBinding()); + return new WireFormatJMSBytesServiceProvider(registry, endpoint, jmsRF); + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceProvider.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceInterceptor.java new file mode 100644 index 0000000000..f8d88f6809 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceInterceptor.java @@ -0,0 +1,137 @@ +/* + * 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(); + // 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); + } + + 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; + } + + private JMSBindingContext createBindingContext() { + JMSBindingContext context = new JMSBindingContext(); + context.setJmsResourceFactory(jmsResourceFactory); + return context; + } + + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceProvider.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceProvider.java new file mode 100644 index 0000000000..fee2ac7748 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceProvider.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.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.provider.JMSResourceFactory; +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; + private JMSResourceFactory jmsResourceFactory; + + public WireFormatJMSBytesServiceProvider(ExtensionPointRegistry registry, + RuntimeEndpoint endpoint, + JMSResourceFactory jmsResourceFactory) { + super(); + this.registry = registry; + this.endpoint = endpoint; + this.endpoint = endpoint; + this.jmsResourceFactory = jmsResourceFactory; + 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, jmsResourceFactory, endpoint); + } + + /** + */ + public String getPhase() { + return Phase.SERVICE_BINDING_WIREFORMAT; + } + + public InterfaceContract getWireFormatInterfaceContract() { + return interfaceContract; + } +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLProviderFactory.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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 { + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceInterceptor.java new file mode 100644 index 0000000000..53b5ac11df --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/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 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.provider.xml.XMLHelper; +import org.apache.tuscany.sca.binding.jms.provider.xml.XMLHelperFactory; +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.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; + + +public class WireFormatJMSBytesXMLReferenceInterceptor extends InterceptorAsyncImpl { + + private Invoker next; + private RuntimeEndpointReference endpointReference; + private JMSResourceFactory jmsResourceFactory; + private JMSBinding jmsBinding; + private JMSMessageProcessor requestMessageProcessor; + private JMSMessageProcessor responseMessageProcessor; + private XMLHelper xmlhelper; + + 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); + this.xmlhelper = XMLHelperFactory.createXMLHelper(registry); + } + + 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); + xmlhelper.setFaultName(e, response); + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceProvider.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceProvider.java new file mode 100644 index 0000000000..abaa21f572 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceProvider.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.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.xml.XMLHelperFactory; +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(XMLHelperFactory.createXMLHelper(registry).getDataBindingName()); + } + + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceInterceptor.java new file mode 100644 index 0000000000..d5bbbec369 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceInterceptor.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.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(); + // 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); + } + + 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; + } + + private JMSBindingContext createBindingContext() { + JMSBindingContext context = new JMSBindingContext(); + context.setJmsResourceFactory(jmsResourceFactory); + return context; + } + + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceProvider.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceProvider.java new file mode 100644 index 0000000000..797b0e45de --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceProvider.java @@ -0,0 +1,109 @@ +/* + * 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.provider.xml.XMLHelperFactory; +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 send 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(XMLHelperFactory.createXMLHelper(registry).getDataBindingName()); + } + + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultProviderFactory.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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 { + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceInterceptor.java new file mode 100644 index 0000000000..ba1002fab2 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/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 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.provider.xml.XMLHelper; +import org.apache.tuscany.sca.binding.jms.provider.xml.XMLHelperFactory; +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.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; + +/** + * + * @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 inputWrapperMap; + private HashMap outputWrapperMap; + private XMLHelper xmlhelper; + + public WireFormatJMSDefaultReferenceInterceptor(ExtensionPointRegistry registry, JMSResourceFactory jmsResourceFactory, RuntimeEndpointReference endpointReference, HashMap inputWrapperMap, + HashMap 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; + this.xmlhelper = XMLHelperFactory.createXMLHelper(registry); + } + + 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 { + + Object 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); + xmlhelper.setFaultName(e, response); + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceProvider.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceProvider.java new file mode 100644 index 0000000000..b04072c992 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceProvider.java @@ -0,0 +1,195 @@ +/* + * 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 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.provider.xml.XMLHelper; +import org.apache.tuscany.sca.binding.jms.provider.xml.XMLHelperFactory; +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.core.ExtensionPointRegistry; +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; + +/** + * @version $Rev$ $Date$ + */ +public class WireFormatJMSDefaultReferenceProvider implements WireFormatProvider { + private ExtensionPointRegistry registry; + private RuntimeEndpointReference endpointReference; + private ComponentReference reference; + private JMSBinding binding; + private InterfaceContract interfaceContract; + private XMLHelper xmlHelper; + private HashMap inputWrapperMap; + private HashMap outputWrapperMap; + + public WireFormatJMSDefaultReferenceProvider(ExtensionPointRegistry registry, RuntimeEndpointReference endpointReference) { + super(); + this.registry = registry; + this.endpointReference = endpointReference; + this.binding = (JMSBinding) endpointReference.getBinding(); + + this.xmlHelper = XMLHelperFactory.createXMLHelper(registry); + this.inputWrapperMap = new HashMap(); + this.outputWrapperMap = new HashMap(); + + // 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 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(XMLHelperFactory.createXMLHelper(registry).getDataBindingName()); + + List 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.isInputWrapperStyle()) { + 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.isOutputWrapperStyle()) { + // 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.getOutputWrapper().getWrapperElement(); + this.outputWrapperMap.put(name, xmlHelper.createWrapper(ei.getQName())); + } + } + } else { + interfaceContract = reference.getReference().getInterfaceContract(); + } + + } + + protected boolean isAsIs() { + InterfaceContract ic = reference.getInterfaceContract(); + if (ic.getInterface().getOperations().size() != 1) { + return false; + } + + List 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceInterceptor.java new file mode 100644 index 0000000000..6804333541 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceInterceptor.java @@ -0,0 +1,189 @@ +/* + * 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.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 WireFormatJMSDefaultServiceInterceptor extends InterceptorAsyncImpl { + private RuntimeEndpoint endpoint; + private JMSResourceFactory jmsResourceFactory; + private JMSBinding jmsBinding; + private DefaultMessageProcessor requestMessageProcessor; + private DefaultMessageProcessor responseMessageProcessor; + private HashMap inputWrapperMap; + private HashMap outputWrapperMap; + + public WireFormatJMSDefaultServiceInterceptor(ExtensionPointRegistry registry, JMSResourceFactory jmsResourceFactory, RuntimeEndpoint endpoint, HashMap inputWrapperMap, + HashMap 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 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 + Object 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); + } + } + + + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceProvider.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceProvider.java new file mode 100644 index 0000000000..408aba9bbb --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceProvider.java @@ -0,0 +1,189 @@ +/* + * 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 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.provider.xml.XMLHelper; +import org.apache.tuscany.sca.binding.jms.provider.xml.XMLHelperFactory; +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.core.ExtensionPointRegistry; +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; + +/** + * @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 XMLHelper xmlHelper; + private HashMap inputWrapperMap; + private HashMap 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.xmlHelper = XMLHelperFactory.createXMLHelper(registry); + this.inputWrapperMap = new HashMap(); + this.outputWrapperMap = new HashMap(); + + // 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 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(XMLHelperFactory.createXMLHelper(registry).getDataBindingName()); + + List 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.isInputWrapperStyle()) { + 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.getInputWrapper().getWrapperElement(); + this.inputWrapperMap.put(name, xmlHelper.createWrapper(ei.getQName())); + } + } + + if (matchingWsdlOp.isOutputWrapperStyle()) { + 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 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectProviderFactory.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectProviderFactory.java new file mode 100644 index 0000000000..3b033004c4 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectProviderFactory.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.jmsobject.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.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 { + private ExtensionPointRegistry registry; + private JMSResourceFactoryExtensionPoint jmsRFEP; + + public WireFormatJMSObjectProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + jmsRFEP = (JMSResourceFactoryExtensionPoint) registry.getExtensionPoint(JMSResourceFactoryExtensionPoint.class); + } + + /** + */ + public WireFormatProvider createReferenceWireFormatProvider(RuntimeEndpointReference endpointReference) { + return new WireFormatJMSObjectReferenceProvider(registry, endpointReference); + } + + /** + */ + public WireFormatProvider createServiceWireFormatProvider(RuntimeEndpoint endpoint) { + JMSResourceFactory jmsResourceFactory = jmsRFEP.createJMSResourceFactory((JMSBinding) endpoint.getBinding()); + return new WireFormatJMSObjectServiceProvider(registry, endpoint, jmsResourceFactory); + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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 singleArgMap; + + public WireFormatJMSObjectReferenceInterceptor(ExtensionPointRegistry registry, JMSResourceFactory jmsResourceFactory, RuntimeEndpointReference endpointReference, HashMap 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceProvider.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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 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(); + 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 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceInterceptor.java new file mode 100644 index 0000000000..d4bc99aa7b --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceInterceptor.java @@ -0,0 +1,162 @@ +/* + * 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> singleArgMap; + private boolean wrapSingle; + + public WireFormatJMSObjectServiceInterceptor(ExtensionPointRegistry registry, JMSResourceFactory jmsResourceFactory, + RuntimeEndpoint endpoint, HashMap> 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(); + + // 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); + } + + 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; + } + + private JMSBindingContext createBindingContext() { + JMSBindingContext context = new JMSBindingContext(); + context.setJmsResourceFactory(jmsResourceFactory); + return context; + } + + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceProvider.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceProvider.java new file mode 100644 index 0000000000..2b16ba650e --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceProvider.java @@ -0,0 +1,122 @@ +/* + * 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.provider.JMSResourceFactory; +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> singleArgMap; + private boolean wrapSingle = true; + private JMSResourceFactory jmsResourceFactory ; + + public WireFormatJMSObjectServiceProvider(ExtensionPointRegistry registry, RuntimeEndpoint endpoint, JMSResourceFactory jmsResourceFactory) { + super(); + this.registry = registry; + this.endpoint = endpoint; + this.jmsResourceFactory = jmsResourceFactory; + this.binding = (JMSBinding)endpoint.getBinding(); + this.singleArgMap = new HashMap>(); + + 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 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, jmsResourceFactory, endpoint, this.singleArgMap, wrapSingle); + } + + /** + */ + public String getPhase() { + return Phase.SERVICE_BINDING_WIREFORMAT; + } + + public InterfaceContract getWireFormatInterfaceContract() { + return interfaceContract; + } +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextProviderFactory.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextProviderFactory.java new file mode 100644 index 0000000000..de76dbbdb8 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextProviderFactory.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.jmstext.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.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 { + private ExtensionPointRegistry registry; + private JMSResourceFactoryExtensionPoint jmsRFEP; + + public WireFormatJMSTextProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + jmsRFEP = (JMSResourceFactoryExtensionPoint) registry.getExtensionPoint(JMSResourceFactoryExtensionPoint.class); + } + + /** + */ + public WireFormatProvider createReferenceWireFormatProvider(RuntimeEndpointReference endpointReference) { + return new WireFormatJMSTextReferenceProvider(registry, endpointReference); + } + + /** + */ + public WireFormatProvider createServiceWireFormatProvider(RuntimeEndpoint endpoint) { + JMSResourceFactory jmsResourceFactory = jmsRFEP.createJMSResourceFactory((JMSBinding) endpoint.getBinding()); + return new WireFormatJMSTextServiceProvider(registry, endpoint, jmsResourceFactory); + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceProvider.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceInterceptor.java new file mode 100644 index 0000000000..1d3d4e7a42 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceInterceptor.java @@ -0,0 +1,137 @@ +/* + * 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(); + // 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); + } + + 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; + } + + private JMSBindingContext createBindingContext() { + JMSBindingContext context = new JMSBindingContext(); + context.setJmsResourceFactory(jmsResourceFactory); + return context; + } + + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceProvider.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceProvider.java new file mode 100644 index 0000000000..adc5845a49 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceProvider.java @@ -0,0 +1,107 @@ +/* + * 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.provider.JMSResourceFactory; +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; + private JMSResourceFactory jmsResourceFactory; + + public WireFormatJMSTextServiceProvider(ExtensionPointRegistry registry, + RuntimeEndpoint endpoint, + JMSResourceFactory jmsResourceFactory) { + super(); + this.registry = registry; + this.endpoint = endpoint; + this.jmsResourceFactory = jmsResourceFactory; + 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, jmsResourceFactory, endpoint); + } + + /** + */ + public String getPhase() { + return Phase.SERVICE_BINDING_WIREFORMAT; + } + + public InterfaceContract getWireFormatInterfaceContract() { + return interfaceContract; + } +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLProviderFactory.java b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/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 { + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceInterceptor.java new file mode 100644 index 0000000000..8201e94133 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/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 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.provider.xml.XMLHelper; +import org.apache.tuscany.sca.binding.jms.provider.xml.XMLHelperFactory; +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.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; + +/** + * + * @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; + private XMLHelper xmlhelper; + + + 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); + this.xmlhelper = XMLHelperFactory.createXMLHelper(registry); + } + + 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); + xmlhelper.setFaultName(e, response); + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceProvider.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceProvider.java new file mode 100644 index 0000000000..48b377607e --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceProvider.java @@ -0,0 +1,114 @@ +/* + * 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.xml.XMLHelperFactory; +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 send 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(XMLHelperFactory.createXMLHelper(registry).getDataBindingName()); + } + + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceInterceptor.java new file mode 100644 index 0000000000..7766469271 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceInterceptor.java @@ -0,0 +1,138 @@ +/* + * 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(); + // 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); + } + + 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; + } + + private JMSBindingContext createBindingContext() { + JMSBindingContext context = new JMSBindingContext(); + context.setJmsResourceFactory(jmsResourceFactory); + return context; + } + + 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/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceProvider.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceProvider.java new file mode 100644 index 0000000000..89fe2c7c39 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceProvider.java @@ -0,0 +1,109 @@ +/* + * 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.provider.xml.XMLHelperFactory; +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 send 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(XMLHelperFactory.createXMLHelper(registry).getDataBindingName()); + } + + 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; + } + +} -- cgit v1.2.3