diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2008-10-23 15:42:42 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2008-10-23 15:42:42 +0000 |
commit | 3336ce7cd343c5b5ec51c1762f3133d044cff3be (patch) | |
tree | fab70d14ee4ea840beeff82759c1b01628f0de5a /java/sca/modules | |
parent | 3a62e18e7392a2a4ef9eca611443fa1966f31360 (diff) |
Merge the runtime wire changes to add a binding invocation wire with the jms binding changes to exploit the binding wire. Still early days so see the ongoing conversation on the ML. This function is only enabled if you include a wire format in a jms service binding element.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@707394 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules')
26 files changed, 796 insertions, 170 deletions
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/BindingRRB.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/BindingRRB.java index 0eccdbabb9..5bcbdd40eb 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/BindingRRB.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/BindingRRB.java @@ -28,9 +28,13 @@ package org.apache.tuscany.sca.assembly; */ public interface BindingRRB extends Binding { - public WireFormat getWireFormat(); + public WireFormat getRequestWireFormat(); - public void setWireFormat(WireFormat wireFormat); + public void setRequestWireFormat(WireFormat wireFormat); + + public WireFormat getResponseWireFormat(); + + public void setResponseWireFormat(WireFormat wireFormat); public OperationSelector getOperationSelector(); diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefault.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefault.java index 74a5368dc6..71d1298c9b 100644 --- a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefault.java +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefault.java @@ -21,7 +21,7 @@ package org.apache.tuscany.sca.binding.jms.operationselector.jmsdefault; import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.xml.Constants; -import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.assembly.OperationSelector; /** * Implementation for policies that could be injected as parameter @@ -29,7 +29,7 @@ import org.apache.tuscany.sca.assembly.WireFormat; * * @version $Rev$ $Date$ */ -public class OperationSelectorJMSDefault implements WireFormat { +public class OperationSelectorJMSDefault implements OperationSelector { public static final QName OPERATION_SELECTOR_JMS_DEFAULT_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "operationSelector.JMSDefault"); public QName getSchemaName() { diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultProcessor.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultProcessor.java index be483c66dd..4a8e4a1bd2 100644 --- a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultProcessor.java +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultProcessor.java @@ -18,8 +18,6 @@ */ package org.apache.tuscany.sca.binding.jms.operationselector.jmsdefault; -import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; -import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamException; @@ -27,7 +25,6 @@ import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.assembly.xml.Constants; -import org.apache.tuscany.sca.binding.jms.policy.header.JMSHeaderPolicy; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultProviderFactory.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultProviderFactory.java new file mode 100644 index 0000000000..cf9e55a54d --- /dev/null +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultProviderFactory.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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; + +import org.apache.tuscany.sca.assembly.Binding; +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.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class OperationSelectorJMSDefaultProviderFactory implements OperationSelectorProviderFactory<OperationSelectorJMSDefault> { + private ExtensionPointRegistry registry; + + public OperationSelectorJMSDefaultProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + /** + */ + public OperationSelectorProvider createReferenceOperationSelectorProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + return new OperationSelectorJMSDefaultReferenceProvider(component, reference, binding); + } + + /** + */ + public OperationSelectorProvider createServiceOperationSelectorProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + return new OperationSelectorJMSDefaultServiceProvider(component, service, binding); + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultReferenceInterceptor.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultReferenceInterceptor.java index fbe4bd048d..52433ed3ca 100644 --- a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultReferenceInterceptor.java +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultReferenceInterceptor.java @@ -20,21 +20,12 @@ package org.apache.tuscany.sca.binding.jms.operationselector.jmsdefault; import java.util.List; -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.OperationSelector; import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; -import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; -import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; 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.interfacedef.Operation; -import org.apache.tuscany.sca.invocation.BindingInterceptor; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; @@ -47,10 +38,11 @@ import org.apache.tuscany.sca.runtime.RuntimeWire; * * @version $Rev$ $Date$ */ -public class OperationSelectorJMSDefaultReferenceInterceptor implements BindingInterceptor { +public class OperationSelectorJMSDefaultReferenceInterceptor implements Interceptor { private static final String ON_MESSAGE_METHOD_NAME = "onMessage"; + private Invoker next; private OperationSelectorJMSDefault operationSelector; private RuntimeWire runtimeWire; private JMSResourceFactory jmsResourceFactory; @@ -85,5 +77,13 @@ public class OperationSelectorJMSDefaultReferenceInterceptor implements BindingI public Message invokeResponse(Message msg) { // TODO binding interceptor iface TBD return null; - } + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } } diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultReferenceProvider.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultReferenceProvider.java new file mode 100644 index 0000000000..e7e1fff0ca --- /dev/null +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultReferenceProvider.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.operationselector.jmsdefault; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +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.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * @version $Rev$ $Date$ + */ +public class OperationSelectorJMSDefaultReferenceProvider implements OperationSelectorProvider { + private RuntimeComponent component; + private RuntimeComponentReference reference; + private Binding binding; + + public OperationSelectorJMSDefaultReferenceProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + super(); + this.component = component; + this.reference = reference; + this.binding = binding; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#createInterceptor(org.apache.tuscany.sca.interfacedef.Operation) + */ + public Interceptor createInterceptor() { + return new OperationSelectorJMSDefaultReferenceInterceptor((JMSBinding)binding, + null, + reference.getRuntimeWire(binding)); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#getPhase() + */ + public String getPhase() { + return Phase.REFERENCE_BINDING_TRANSPORT; + } + +} diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultServiceInterceptor.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultServiceInterceptor.java index 8fdcc355aa..6791bc4641 100644 --- a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultServiceInterceptor.java +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultServiceInterceptor.java @@ -23,29 +23,18 @@ import java.util.List; import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.MessageProducer; -import javax.jms.Queue; import javax.jms.Session; -import javax.jms.Topic; -import javax.security.auth.Subject; -import org.apache.tuscany.sca.assembly.OperationSelector; import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; 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.assembly.EndpointReferenceImpl; -import org.apache.tuscany.sca.core.invocation.MessageImpl; import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.invocation.BindingInterceptor; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; -import org.apache.tuscany.sca.policy.SecurityUtil; -import org.apache.tuscany.sca.policy.authentication.token.TokenPrincipal; -import org.apache.tuscany.sca.runtime.EndpointReference; -import org.apache.tuscany.sca.runtime.ReferenceParameters; import org.apache.tuscany.sca.runtime.RuntimeComponentService; import org.apache.tuscany.sca.runtime.RuntimeWire; @@ -55,10 +44,11 @@ import org.apache.tuscany.sca.runtime.RuntimeWire; * * @version $Rev$ $Date$ */ -public class OperationSelectorJMSDefaultServiceInterceptor implements BindingInterceptor { +public class OperationSelectorJMSDefaultServiceInterceptor implements Interceptor { private static final String ON_MESSAGE_METHOD_NAME = "onMessage"; + private Invoker next; private RuntimeWire runtimeWire; private JMSResourceFactory jmsResourceFactory; private JMSBinding jmsBinding; @@ -80,8 +70,7 @@ public class OperationSelectorJMSDefaultServiceInterceptor implements BindingInt } public Message invoke(Message msg) { - // TODO binding interceptor iface TBD - return null; + return invokeResponse(next.invoke(invokeRequest(msg))); } public Message invokeRequest(Message msg) { @@ -153,5 +142,13 @@ public class OperationSelectorJMSDefaultServiceInterceptor implements BindingInt return operation; } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } } diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultServiceProvider.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultServiceProvider.java new file mode 100644 index 0000000000..a1cfa02072 --- /dev/null +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultServiceProvider.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +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.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class OperationSelectorJMSDefaultServiceProvider implements OperationSelectorProvider { + private RuntimeComponent component; + private RuntimeComponentService service; + private Binding binding; + + public OperationSelectorJMSDefaultServiceProvider(RuntimeComponent component, RuntimeComponentService service, Binding binding) { + super(); + this.component = component; + this.service = service; + this.binding = binding; + } + + /** + */ + public Interceptor createInterceptor() { + return new OperationSelectorJMSDefaultServiceInterceptor((JMSBinding)binding, + null, + service.getRuntimeWire(binding)); + } + + /** + */ + public String getPhase() { + return Phase.SERVICE_BINDING_TRANSPORT; + } + +} diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingProviderFactory.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingProviderFactory.java index 39e4cf0558..a96e53d9e1 100644 --- a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingProviderFactory.java +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingProviderFactory.java @@ -49,6 +49,7 @@ public class JMSBindingProviderFactory implements BindingProviderFactory<JMSBind jmsRFEP = (JMSResourceFactoryExtensionPoint)extensionPoints.getExtensionPoint(JMSResourceFactoryExtensionPoint.class); if (jmsRFEP == null) { jmsRFEP = new DefaultJMSResourceFactoryExtensionPoint(); + extensionPoints.addExtensionPoint(jmsRFEP); } } diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java index e32d298967..9d64c4a16b 100644 --- a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java @@ -35,21 +35,35 @@ import javax.naming.NamingException; import org.apache.axiom.om.OMElement; import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.OperationSelector; +import org.apache.tuscany.sca.assembly.WireFormat; import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.binding.jms.operationselector.jmsdefault.OperationSelectorJMSDefault; import org.apache.tuscany.sca.binding.jms.operationselector.jmsdefault.OperationSelectorJMSDefaultReferenceInterceptor; import org.apache.tuscany.sca.binding.jms.operationselector.jmsdefault.OperationSelectorJMSDefaultServiceInterceptor; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.WireFormatJMSDefault; import org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.WireFormatJMSDefaultReferenceInterceptor; import org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.WireFormatJMSDefaultServiceInterceptor; 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.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.interfacedef.InterfaceContract; +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.BindingProviderFactory; +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.ServiceBindingProvider; import org.apache.tuscany.sca.provider.ServiceBindingProviderRRB; +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.RuntimeWire; @@ -77,6 +91,21 @@ public class JMSBindingServiceBindingProvider implements ServiceBindingProviderR private RuntimeComponent component; private InterfaceContract wsdlInterfaceContract; + + + private ProviderFactoryExtensionPoint providerFactories; + private ModelFactoryExtensionPoint modelFactories; + + private MessageFactory messageFactory; + + private OperationSelectorProviderFactory operationSelectorProviderFactory; + private OperationSelectorProvider operationSelectorProvider; + + private WireFormatProviderFactory requestWireFormatProviderFactory; + private WireFormatProvider requestWireFormatProvider; + + private WireFormatProviderFactory responseWireFormatProviderFactory; + private WireFormatProvider responseWireFormatProvider; public JMSBindingServiceBindingProvider(RuntimeComponent component, RuntimeComponentService service, Binding targetBinding, JMSBinding binding, WorkScheduler workScheduler, ExtensionPointRegistry extensionPoints, JMSResourceFactory jmsResourceFactory) { this.component = component; @@ -99,7 +128,42 @@ public class JMSBindingServiceBindingProvider implements ServiceBindingProviderR setXMLDataBinding(service); } } + + // Get Message factory + modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + messageFactory = modelFactories.getFactory(MessageFactory.class); + // Get the factories/providers for operation selection + + // if no operation selector is specified then assume the default + if (jmsBinding.getOperationSelector() == null){ + jmsBinding.setOperationSelector(new OperationSelectorJMSDefault()); + } + + this.providerFactories = extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class); + this.operationSelectorProviderFactory = + (OperationSelectorProviderFactory)providerFactories.getProviderFactory(jmsBinding.getOperationSelector().getClass()); + this.operationSelectorProvider = operationSelectorProviderFactory.createServiceOperationSelectorProvider(component, service, jmsBinding); + + // Get the factories/providers for wire format + + // if no request wire format specified then assume the default + if (jmsBinding.getRequestWireFormat() == null){ + jmsBinding.setRequestWireFormat(new WireFormatJMSDefault()); + } + + // if no response wire format specific then assume the default + if (jmsBinding.getResponseWireFormat() == null){ + jmsBinding.setResponseWireFormat(new WireFormatJMSDefault()); + } + + this.requestWireFormatProviderFactory = + (WireFormatProviderFactory)providerFactories.getProviderFactory(jmsBinding.getRequestWireFormat().getClass()); + this.requestWireFormatProvider = requestWireFormatProviderFactory.createServiceWireFormatProvider(component, service, jmsBinding); + + this.responseWireFormatProviderFactory = + (WireFormatProviderFactory)providerFactories.getProviderFactory(jmsBinding.getResponseWireFormat().getClass()); + this.responseWireFormatProvider = responseWireFormatProviderFactory.createServiceWireFormatProvider(component, service, jmsBinding); } protected boolean isOnMessage() { @@ -194,8 +258,8 @@ public class JMSBindingServiceBindingProvider implements ServiceBindingProviderR * TODO a test to allow RRB experiments to take place without breaking everything else * RRB stuff only happens if you add a wireFormat to a composite file */ - if (jmsBinding.getWireFormat() != null ){ - tmpListener = new RRBJMSBindingListener(jmsBinding, jmsResourceFactory, service, targetBinding); + if (jmsBinding.getRequestWireFormat() != null ){ + tmpListener = new RRBJMSBindingListener(jmsBinding, jmsResourceFactory, service, targetBinding, messageFactory); } else { tmpListener = new DefaultJMSBindingListener(jmsBinding, jmsResourceFactory, service, targetBinding); } @@ -332,14 +396,19 @@ public class JMSBindingServiceBindingProvider implements ServiceBindingProviderR * pick up the appropriate interceptor based on wireFormat and operationSelector * elements in the SCDL */ - public void configureServiceBindingRequestChain(List<Invoker> bindingRequestChain, RuntimeWire runtimeWire) { - - bindingRequestChain.add(new OperationSelectorJMSDefaultServiceInterceptor(jmsBinding, jmsResourceFactory, runtimeWire)); - bindingRequestChain.add(new WireFormatJMSDefaultServiceInterceptor(jmsBinding, jmsResourceFactory, runtimeWire)); - } - - public void configureServiceBindingResponseChain(List<Invoker> bindingResponseChain, RuntimeWire runtimeWire) { - bindingResponseChain.add(new WireFormatJMSDefaultServiceInterceptor(jmsBinding, jmsResourceFactory, runtimeWire)); - bindingResponseChain.add(new OperationSelectorJMSDefaultServiceInterceptor(jmsBinding, jmsResourceFactory, runtimeWire)); + public void configureBindingChain(RuntimeWire runtimeWire) { + + InvocationChain bindingChain = runtimeWire.getBindingInvocationChain(); + + // add operation selector interceptor + bindingChain.addInterceptor(operationSelectorProvider.getPhase(), operationSelectorProvider.createInterceptor()); + + // 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()); + } } } diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingListener.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingListener.java index c61552299d..615251610c 100644 --- a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingListener.java +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingListener.java @@ -43,8 +43,9 @@ import org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAu import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl; import org.apache.tuscany.sca.core.invocation.MessageImpl; import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.invocation.BindingInterceptor; +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.policy.PolicySet; import org.apache.tuscany.sca.policy.PolicySetAttachPoint; import org.apache.tuscany.sca.policy.SecurityUtil; @@ -73,6 +74,7 @@ public class RRBJMSBindingListener implements MessageListener { private JMSMessageProcessor responseMessageProcessor; private String correlationScheme; private List<Operation> serviceOperations; + private MessageFactory messageFactory; protected JMSTokenAuthenticationPolicy jmsTokenAuthenticationPolicy = null; /* @@ -82,11 +84,13 @@ public class RRBJMSBindingListener implements MessageListener { private List<Invoker> bindingRequestChain; private List<Invoker> bindingResponseChain; - public RRBJMSBindingListener(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeComponentService service, Binding targetBinding) throws NamingException { + public RRBJMSBindingListener(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeComponentService service, Binding targetBinding, MessageFactory messageFactory) throws NamingException { this.jmsBinding = jmsBinding; this.jmsResourceFactory = jmsResourceFactory; this.service = service; this.targetBinding = targetBinding; + this.messageFactory = messageFactory; + requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding); responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(jmsBinding); correlationScheme = jmsBinding.getCorrelationScheme(); @@ -105,15 +109,6 @@ public class RRBJMSBindingListener implements MessageListener { } } } - - // Set up request/response chains for RRB - bindingRequestChain = new ArrayList<Invoker>(); - bindingResponseChain = new ArrayList<Invoker>(); - - ServiceBindingProviderRRB provider = (ServiceBindingProviderRRB)service.getBindingProvider(jmsBinding); - provider.configureServiceBindingRequestChain(bindingRequestChain, service.getRuntimeWire(targetBinding)); - provider.configureServiceBindingResponseChain(bindingResponseChain, service.getRuntimeWire(targetBinding)); - } public void onMessage(Message requestJMSMsg) { @@ -143,40 +138,23 @@ public class RRBJMSBindingListener implements MessageListener { protected void invokeService(Message requestJMSMsg) throws JMSException, InvocationTargetException { // create the tuscany message - MessageImpl tuscanyMsg = new MessageImpl(); + org.apache.tuscany.sca.invocation.Message tuscanyMsg = messageFactory.createMessage(); // populate the message context with JMS binding information tuscanyMsg.getHeaders().add(requestJMSMsg); - - // call the request wire - for (Invoker invoker : bindingRequestChain){ - ((BindingInterceptor)invoker).invokeRequest(tuscanyMsg); - } + tuscanyMsg.setBody(requestJMSMsg); // call the runtime wire setHeaderProperties(requestJMSMsg, tuscanyMsg, tuscanyMsg.getOperation()); - Object response = service.getRuntimeWire(targetBinding).invoke(tuscanyMsg.getOperation(), tuscanyMsg); + InvocationChain chain = service.getRuntimeWire(targetBinding).getBindingInvocationChain(); + chain.getHeadInvoker().invoke(tuscanyMsg); - tuscanyMsg.setBody(response); - - if (requestJMSMsg.getJMSReplyTo() == null) { - // assume no reply is expected - if (response != null) { - logger.log(Level.FINE, "JMS service '" + service.getName() + "' dropped response as request has no replyTo"); - } - return; - } - - // call the response wire - for (Invoker invoker : bindingResponseChain){ - ((BindingInterceptor)invoker).invokeResponse(tuscanyMsg); - } } /** * TODO - RRB experiment. Needs refactoring */ - protected void setHeaderProperties(javax.jms.Message requestJMSMsg, MessageImpl tuscanyMsg, Operation operation) throws JMSException { + protected void setHeaderProperties(javax.jms.Message requestJMSMsg, org.apache.tuscany.sca.invocation.Message tuscanyMsg, Operation operation) throws JMSException { EndpointReference from = new EndpointReferenceImpl(null); tuscanyMsg.setFrom(from); diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefault.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefault.java index 8cce4b0d10..6edb6f8b33 100644 --- a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefault.java +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefault.java @@ -40,4 +40,9 @@ public class WireFormatJMSDefault implements WireFormat { public void setUnresolved(boolean unresolved) { } + + @Override + public boolean equals(Object obj) { + return this.getClass() == obj.getClass(); + } } diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultProviderFactory.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultProviderFactory.java new file mode 100644 index 0000000000..c89638736b --- /dev/null +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultProviderFactory.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactoryExtensionPoint; +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.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class WireFormatJMSDefaultProviderFactory implements WireFormatProviderFactory<WireFormatJMSDefault> { + private ExtensionPointRegistry registry; + private JMSResourceFactoryExtensionPoint jmsRFEP; + + public WireFormatJMSDefaultProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + jmsRFEP = (JMSResourceFactoryExtensionPoint)registry.getExtensionPoint(JMSResourceFactoryExtensionPoint.class); + + } + + /** + */ + public WireFormatProvider createReferenceWireFormatProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + return new WireFormatJMSDefaultReferenceProvider(component, reference, binding); + } + + /** + */ + public WireFormatProvider createServiceWireFormatProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + JMSResourceFactory jmsRF = jmsRFEP.createJMSResourceFactory((JMSBinding)binding); + return new WireFormatJMSDefaultServiceProvider(component, service, binding, jmsRF); + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultReferenceInterceptor.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultReferenceInterceptor.java index e17c9a8c9b..8df0349a21 100644 --- a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultReferenceInterceptor.java +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultReferenceInterceptor.java @@ -19,18 +19,13 @@ package org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault; -import javax.jms.JMSException; -import javax.jms.Session; -import javax.naming.NamingException; + import org.apache.tuscany.sca.assembly.WireFormat; import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; -import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; -import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; 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.invocation.BindingInterceptor; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; @@ -40,7 +35,7 @@ import org.apache.tuscany.sca.runtime.RuntimeWire; * * @version $Rev$ $Date$ */ -public class WireFormatJMSDefaultReferenceInterceptor implements BindingInterceptor { +public class WireFormatJMSDefaultReferenceInterceptor implements Interceptor { private Invoker next; private RuntimeWire runtimeWire; @@ -49,6 +44,8 @@ public class WireFormatJMSDefaultReferenceInterceptor implements BindingIntercep private JMSMessageProcessor requestMessageProcessor; private JMSMessageProcessor responseMessageProcessor; private String correlationScheme; + private WireFormat requestWireFormat; + private WireFormat responseWireFormat; public WireFormatJMSDefaultReferenceInterceptor(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeWire runtimeWire) { super(); @@ -58,11 +55,28 @@ public class WireFormatJMSDefaultReferenceInterceptor implements BindingIntercep this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding); this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(jmsBinding); this.correlationScheme = jmsBinding.getCorrelationScheme(); + + if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSDefault){ + this.requestWireFormat = jmsBinding.getRequestWireFormat(); + } + + if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSDefault){ + this.responseWireFormat = jmsBinding.getResponseWireFormat(); + } } public Message invoke(Message msg) { - // TODO binding interceptor iface TBD - return null; + if (requestWireFormat != null){ + msg = invokeRequest(msg); + } + + msg = getNext().invoke(msg); + + if (responseWireFormat != null){ + msg = invokeRequest(msg); + } + + return msg; } public Message invokeRequest(Message msg) { diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultReferenceProvider.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultReferenceProvider.java new file mode 100644 index 0000000000..5d3dcd9dd3 --- /dev/null +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultReferenceProvider.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +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.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.apache.tuscany.sca.policy.util.PolicyHandler; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * @version $Rev$ $Date$ + */ +public class WireFormatJMSDefaultReferenceProvider implements WireFormatProvider { + private RuntimeComponent component; + private RuntimeComponentReference reference; + private Binding binding; + + public WireFormatJMSDefaultReferenceProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + super(); + this.component = component; + this.reference = reference; + this.binding = binding; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#createInterceptor(org.apache.tuscany.sca.interfacedef.Operation) + */ + public Interceptor createInterceptor() { + return new WireFormatJMSDefaultReferenceInterceptor((JMSBinding)binding, + null, + reference.getRuntimeWire(binding)); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#getPhase() + */ + public String getPhase() { + return Phase.REFERENCE_BINDING_WIREFORMAT; + } + +} diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultServiceInterceptor.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultServiceInterceptor.java index 5c53bcf009..7c7c44f627 100644 --- a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultServiceInterceptor.java +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultServiceInterceptor.java @@ -29,7 +29,6 @@ import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; 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.invocation.BindingInterceptor; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; @@ -41,7 +40,7 @@ import org.apache.tuscany.sca.runtime.RuntimeWire; * * @version $Rev$ $Date$ */ -public class WireFormatJMSDefaultServiceInterceptor implements BindingInterceptor { +public class WireFormatJMSDefaultServiceInterceptor implements Interceptor { private Invoker next; private RuntimeWire runtimeWire; private JMSResourceFactory jmsResourceFactory; @@ -49,6 +48,8 @@ public class WireFormatJMSDefaultServiceInterceptor implements BindingIntercepto private JMSMessageProcessor requestMessageProcessor; private JMSMessageProcessor responseMessageProcessor; private String correlationScheme; + private WireFormat requestWireFormat; + private WireFormat responseWireFormat; public WireFormatJMSDefaultServiceInterceptor(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeWire runtimeWire) { super(); @@ -58,11 +59,29 @@ public class WireFormatJMSDefaultServiceInterceptor implements BindingIntercepto this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding); this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(jmsBinding); this.correlationScheme = jmsBinding.getCorrelationScheme(); + + if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSDefault){ + this.requestWireFormat = jmsBinding.getRequestWireFormat(); + } + + if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSDefault){ + this.responseWireFormat = jmsBinding.getResponseWireFormat(); + } } public Message invoke(Message msg) { - // TODO binding interceptor iface TBD - return null; + + if (requestWireFormat != null){ + msg = invokeRequest(msg); + } + + msg = getNext().invoke(msg); + + if (responseWireFormat != null){ + msg = invokeResponse(msg); + } + + return msg; } public Message invokeRequest(Message msg) { @@ -76,11 +95,7 @@ public class WireFormatJMSDefaultServiceInterceptor implements BindingIntercepto msg.setBody(requestPayload); } - if (next != null){ - return getNext().invoke(msg); - } else { - return msg; - } + return msg; } public Message invokeResponse(Message msg) { @@ -109,11 +124,7 @@ public class WireFormatJMSDefaultServiceInterceptor implements BindingIntercepto msg.setBody(responseJMSMsg); - if (next != null){ - return getNext().invoke(msg); - } else { - return msg; - } + return msg; } catch (JMSException e) { throw new JMSBindingException(e); } catch (NamingException e) { diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultServiceProvider.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultServiceProvider.java new file mode 100644 index 0000000000..9bf355c27b --- /dev/null +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultServiceProvider.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +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.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.apache.tuscany.sca.policy.util.PolicyHandler; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class WireFormatJMSDefaultServiceProvider implements WireFormatProvider { + private RuntimeComponent component; + private RuntimeComponentService service; + private Binding binding; + private JMSResourceFactory jmsResourceFactory; + + public WireFormatJMSDefaultServiceProvider(RuntimeComponent component, RuntimeComponentService service, Binding binding, JMSResourceFactory jmsResourceFactory) { + super(); + this.component = component; + this.service = service; + this.binding = binding; + this.jmsResourceFactory = jmsResourceFactory; + } + + /** + */ + public Interceptor createInterceptor() { + return new WireFormatJMSDefaultServiceInterceptor((JMSBinding)binding, + jmsResourceFactory, + service.getRuntimeWire(binding)); + } + + /** + */ + public String getPhase() { + return Phase.SERVICE_BINDING_WIREFORMAT; + } + +} diff --git a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java index 76a57b92d0..90b4d2488b 100644 --- a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java +++ b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java @@ -119,7 +119,8 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint { private JMSBinding requestConnectionBinding; private JMSBinding responseConnectionBinding; - private WireFormat wireFormat; + private WireFormat requestWireFormat; + private WireFormat responseWireFormat; private OperationSelector operationSelector; public JMSBinding() { @@ -155,14 +156,22 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint { return extensions; } - public WireFormat getWireFormat() { - return wireFormat; + public WireFormat getRequestWireFormat() { + return requestWireFormat; } - public void setWireFormat(WireFormat wireFormat) { - this.wireFormat = wireFormat; + public void setRequestWireFormat(WireFormat wireFormat) { + this.requestWireFormat = wireFormat; } + public WireFormat getResponseWireFormat() { + return responseWireFormat; + } + + public void setResponseWireFormat(WireFormat wireFormat) { + this.responseWireFormat = wireFormat; + } + public OperationSelector getOperationSelector() { return operationSelector; } diff --git a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java index 2981e8de61..120bc2735e 100644 --- a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java +++ b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java @@ -30,7 +30,6 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; -import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.OperationSelector; import org.apache.tuscany.sca.assembly.WireFormat; import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl; @@ -44,7 +43,6 @@ import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.contribution.service.ContributionReadException; import org.apache.tuscany.sca.contribution.service.ContributionResolveException; import org.apache.tuscany.sca.contribution.service.ContributionWriteException; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.Problem; import org.apache.tuscany.sca.monitor.Problem.Severity; @@ -259,7 +257,7 @@ public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> { Object extension = extensionProcessor.read(reader); if (extension != null) { if (extension instanceof WireFormat) { - jmsBinding.setWireFormat((WireFormat)extension); + jmsBinding.setRequestWireFormat((WireFormat)extension); } else if (extension instanceof OperationSelector) { jmsBinding.setOperationSelector((OperationSelector)extension); } else { diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/BindingInterceptor.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/BindingInterceptor.java deleted file mode 100644 index 9aad2dd458..0000000000 --- a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/BindingInterceptor.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.invocation; - -/** - * TODO RRB experiment to allow the request and respose side of the - * invoke to be called independently - * Synchronous mediation associated with a client- or target- side wire. - * - * @version $Rev$ $Date$ - */ -public interface BindingInterceptor extends Invoker { - - /** - * Process a synchronous request - * - * @param msg The request Message for the wire - * @return The response Message from the wire - */ - Message invokeRequest(Message msg); - - /** - * Process a synchronous response - * - * @param msg The request Message for the wire - * @return The response Message from the wire - */ - Message invokeResponse(Message msg); - -} diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java index dfc3ddb468..1edf612780 100644 --- a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java +++ b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java @@ -113,6 +113,8 @@ public class DefaultProviderFactoryExtensionPoint implements ProviderFactoryExte loadProviderFactories(BindingProviderFactory.class); loadProviderFactories(ImplementationProviderFactory.class); loadProviderFactories(PolicyProviderFactory.class); + loadProviderFactories(WireFormatProviderFactory.class); + loadProviderFactories(OperationSelectorProviderFactory.class); loaded = true; } @@ -171,6 +173,26 @@ public class DefaultProviderFactoryExtensionPoint implements ProviderFactoryExte new LazyPolicyProviderFactory(registry, modelTypeName, factoryDeclaration); factoryExtensionPoint.addProviderFactory(factory); factories.add(factory); + } else if (factoryClass == WireFormatProviderFactory.class) { + + // Load a wire format provider factory + String modelTypeName = attributes.get("model"); + + // Create a provider factory wrapper and register it + WireFormatProviderFactory factory = + new LazyWireFormatProviderFactory(registry, modelTypeName, factoryDeclaration); + factoryExtensionPoint.addProviderFactory(factory); + factories.add(factory); + } else if (factoryClass == OperationSelectorProviderFactory.class) { + + // Load a wire format provider factory + String modelTypeName = attributes.get("model"); + + // Create a provider factory wrapper and register it + OperationSelectorProviderFactory factory = + new LazyOperationSelectorProviderFactory(registry, modelTypeName, factoryDeclaration); + factoryExtensionPoint.addProviderFactory(factory); + factories.add(factory); } } return factories; @@ -356,7 +378,132 @@ public class DefaultProviderFactoryExtensionPoint implements ProviderFactoryExte } return modelType; } + } + /** + * A wrapper around a wire format provider factory allowing lazy + * loading and initialization of wire format providers. + */ + private class LazyWireFormatProviderFactory implements WireFormatProviderFactory { + + private ExtensionPointRegistry registry; + private String modelTypeName; + private ServiceDeclaration providerClass; + private WireFormatProviderFactory factory; + private Class modelType; + + private LazyWireFormatProviderFactory(ExtensionPointRegistry registry, + String modelTypeName, + ServiceDeclaration providerClass) { + this.registry = registry; + this.modelTypeName = modelTypeName; + this.providerClass = providerClass; + } + + @SuppressWarnings("unchecked") + private WireFormatProviderFactory getFactory() { + if (factory == null) { + try { + Class<WireFormatProviderFactory> factoryClass = + (Class<WireFormatProviderFactory>)providerClass.loadClass(); + Constructor<WireFormatProviderFactory> constructor = + factoryClass.getConstructor(ExtensionPointRegistry.class); + factory = constructor.newInstance(registry); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return factory; + } + + @SuppressWarnings("unchecked") + public WireFormatProvider createReferenceWireFormatProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding){ + return getFactory().createReferenceWireFormatProvider(component, reference, binding); + } + + @SuppressWarnings("unchecked") + public WireFormatProvider createServiceWireFormatProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding){ + return getFactory().createServiceWireFormatProvider(component, service, binding); + } + + public Class getModelType() { + if (modelType == null) { + try { + + modelType = providerClass.loadClass(modelTypeName); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return modelType; + } } + /** + * A wrapper around a operation selector provider factory allowing lazy + * loading and initialization of operation selector providers. + */ + private class LazyOperationSelectorProviderFactory implements OperationSelectorProviderFactory { + + private ExtensionPointRegistry registry; + private String modelTypeName; + private ServiceDeclaration providerClass; + private OperationSelectorProviderFactory factory; + private Class modelType; + + private LazyOperationSelectorProviderFactory(ExtensionPointRegistry registry, + String modelTypeName, + ServiceDeclaration providerClass) { + this.registry = registry; + this.modelTypeName = modelTypeName; + this.providerClass = providerClass; + } + + @SuppressWarnings("unchecked") + private OperationSelectorProviderFactory getFactory() { + if (factory == null) { + try { + Class<OperationSelectorProviderFactory> factoryClass = + (Class<OperationSelectorProviderFactory>)providerClass.loadClass(); + Constructor<OperationSelectorProviderFactory> constructor = + factoryClass.getConstructor(ExtensionPointRegistry.class); + factory = constructor.newInstance(registry); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return factory; + } + + @SuppressWarnings("unchecked") + public OperationSelectorProvider createReferenceOperationSelectorProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding){ + return getFactory().createReferenceOperationSelectorProvider(component, reference, binding); + } + + @SuppressWarnings("unchecked") + public OperationSelectorProvider createServiceOperationSelectorProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding){ + return getFactory().createServiceOperationSelectorProvider(component, service, binding); + } + + public Class getModelType() { + if (modelType == null) { + try { + + modelType = providerClass.loadClass(modelTypeName); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return modelType; + } + } + } diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/OperationSelectortProviderFactory.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/OperationSelectorProviderFactory.java index 21d36e5078..183b38cb33 100644 --- a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/OperationSelectortProviderFactory.java +++ b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/OperationSelectorProviderFactory.java @@ -28,7 +28,7 @@ import org.apache.tuscany.sca.runtime.RuntimeComponentService; /** * @version $Rev$ $Date$ */ -public interface OperationSelectortProviderFactory<M extends OperationSelector> extends ProviderFactory<M> { +public interface OperationSelectorProviderFactory<M extends OperationSelector> extends ProviderFactory<M> { /** * Create wire format provider for a given reference binding * @param component @@ -36,9 +36,9 @@ public interface OperationSelectortProviderFactory<M extends OperationSelector> * @param binding * @return */ - PolicyProvider createReferenceOperationSelectorProvider(RuntimeComponent component, - RuntimeComponentReference reference, - Binding binding); + OperationSelectorProvider createReferenceOperationSelectorProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding); /** * Create policy provider for a given service binding @@ -47,7 +47,7 @@ public interface OperationSelectortProviderFactory<M extends OperationSelector> * @param binding * @return */ - PolicyProvider createServiceOperationSelectorProvider(RuntimeComponent component, - RuntimeComponentService service, - Binding binding); + OperationSelectorProvider createServiceOperationSelectorProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding); } diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProviderRRB.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProviderRRB.java index cad31cb2b7..e23a37360a 100644 --- a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProviderRRB.java +++ b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProviderRRB.java @@ -34,7 +34,6 @@ import org.apache.tuscany.sca.runtime.RuntimeWire; */ public interface ServiceBindingProviderRRB extends ServiceBindingProvider { - void configureServiceBindingRequestChain(List<Invoker> bindingRequestChain, RuntimeWire runtimeWire); - void configureServiceBindingResponseChain(List<Invoker> bindingResponseChain, RuntimeWire runtimeWire); + void configureBindingChain(RuntimeWire runtimeWire); } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java index 991aa57abe..2a4b4d1ec9 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java @@ -45,6 +45,7 @@ import org.apache.tuscany.sca.provider.ImplementationProvider; import org.apache.tuscany.sca.provider.PolicyProvider; import org.apache.tuscany.sca.provider.ReferenceBindingProvider; import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProviderRRB; import org.apache.tuscany.sca.runtime.EndpointReference; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeComponentReference; @@ -76,7 +77,7 @@ public class RuntimeWireImpl implements RuntimeWire { private RuntimeWireImpl clonedFrom; private List<InvocationChain> chains; - private InvocationChain binidngInvocationChain; + private InvocationChain bindingInvocationChain; /** * @param source @@ -113,15 +114,16 @@ public class RuntimeWireImpl implements RuntimeWire { } public synchronized InvocationChain getBindingInvocationChain() { - if (binidngInvocationChain == null) { + if (bindingInvocationChain == null) { Contract source = wireSource.getContract(); if (source instanceof RuntimeComponentReference) { - binidngInvocationChain = new InvocationChainImpl(null, null, true); + bindingInvocationChain = new InvocationChainImpl(null, null, true); } else { - binidngInvocationChain = new InvocationChainImpl(null, null, false); + bindingInvocationChain = new InvocationChainImpl(null, null, false); + initServiceBindingInvocationChains(); } } - return binidngInvocationChain; + return bindingInvocationChain; } public InvocationChain getInvocationChain(Operation operation) { @@ -180,6 +182,7 @@ public class RuntimeWireImpl implements RuntimeWire { addReferenceBindingInterceptor(reference, refBinding, chain, operation); chains.add(chain); } + } else { // It's the service wire RuntimeComponentService service = (RuntimeComponentService)wireTarget.getContract(); @@ -202,9 +205,31 @@ public class RuntimeWireImpl implements RuntimeWire { addImplementationInterceptor(serviceComponent, service, chain, targetOperation); chains.add(chain); } + } wireProcessor.process(this); } + + private void initServiceBindingInvocationChains() { + RuntimeComponentService service = (RuntimeComponentService)wireTarget.getContract(); + Binding serviceBinding = wireTarget.getBinding(); + + // add the binding interceptors to the service binding wire + ServiceBindingProvider provider = service.getBindingProvider(serviceBinding); + if ((provider != null) && + (provider instanceof ServiceBindingProviderRRB)){ + ((ServiceBindingProviderRRB)provider).configureBindingChain(this); + } + + // add the policy interceptors to the service binding wire + + + // TODO - add something on the end of the wire to invoke the + // invocation chain. Need to split out the runtime + // wire invoker into conversation, callback interceptors etc + bindingInvocationChain.addInvoker(invoker); + + } public EndpointReference getSource() { return wireSource; diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java index c26501e7d7..c559a42bdc 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java @@ -45,8 +45,9 @@ public class InvocationChainImpl implements InvocationChain { private boolean allowsPassByReference; public InvocationChainImpl(Operation sourceOperation, Operation targetOperation, boolean forReference) { - assert sourceOperation != null; - assert targetOperation != null; + // TODO - binding invocation chain doesn't provide operations + //assert sourceOperation != null; + //assert targetOperation != null; this.targetOperation = targetOperation; this.sourceOperation = sourceOperation; this.forReference = forReference; diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java index c007669bdf..925a7c10a5 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java @@ -47,7 +47,7 @@ import org.osoa.sca.ServiceRuntimeException; /** * @version $Rev$ $Date$ */ -public class RuntimeWireInvoker { +public class RuntimeWireInvoker implements Invoker{ protected ConversationManager conversationManager; protected boolean conversational; protected ExtendedConversation conversation; @@ -74,6 +74,25 @@ public class RuntimeWireInvoker { this.conversational = contract.getInterface().isConversational(); } } + + /* + * TODO - Introduced to allow the RuntimeWireInvoker to sit on the end of the + * service binding chain. Runtime wire invoke needs splitting up into + * separate conversation, callback interceptors etc. + */ + public Message invoke(Message msg) { + + try { + Object response = invoke(msg.getOperation(),msg); + // Hack to put the response back in a message. + // shouldn't take it out of the response message in the first place + msg.setBody(response); + } catch (InvocationTargetException e) { + throw new ServiceRuntimeException(e); + } + + return msg; + } public Object invoke(Operation operation, Message msg) throws InvocationTargetException { return invoke(wire, operation, msg); |