diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-05-17 17:27:54 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-05-17 17:27:54 +0000 |
commit | 53b98fd7f18aae43f32a3ed11131b5876e90f887 (patch) | |
tree | 2ff5561feb0f7e20e6ac8c21878d44b114d4cea2 /sca-java-2.x/trunk/modules/core/src | |
parent | 4bb8e8e5de317bb63ace92ed763557f92a3195f4 (diff) |
Make sure callback endpoints are created
When a component is invoked from a non bidirectional interface, inject null to the fields/setters with @Callback
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@945259 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/core/src')
6 files changed, 79 insertions, 19 deletions
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java index 470ed168cc..999854a822 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java @@ -251,8 +251,8 @@ public class ComponentContextImpl implements RuntimeComponentContext { String bindingName = null; int index = serviceName.indexOf('/'); if (index != -1) { - serviceName = serviceName.substring(0, index); bindingName = serviceName.substring(index + 1); + serviceName = serviceName.substring(0, index); } for (ComponentService service : component.getServices()) { if (serviceName.equals(service.getName())) { diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java index ed781b7ab1..cb2c01f7d6 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java @@ -35,6 +35,7 @@ import org.apache.tuscany.sca.core.invocation.impl.JDKInvocationHandler; import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.runtime.Invocable; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; import org.oasisopen.sca.ServiceReference; /** @@ -51,8 +52,15 @@ public class CglibProxyFactory implements ProxyFactory { } - public <T> T createProxy(Class<T> interfaze, Invocable wire) throws ProxyCreationException { - ServiceReference<T> serviceReference = new ServiceReferenceImpl(interfaze, wire, null); + public <T> T createProxy(final Class<T> interfaze, Invocable invocable) throws ProxyCreationException { + if (invocable instanceof RuntimeEndpoint) { + Enhancer enhancer = new Enhancer(); + enhancer.setSuperclass(interfaze); + enhancer.setCallback(new CglibMethodInterceptor<T>(interfaze, invocable)); + Object proxy = enhancer.create(); + return interfaze.cast(proxy); + } + ServiceReference<T> serviceReference = new ServiceReferenceImpl(interfaze, invocable, null); return createProxy(serviceReference); } @@ -123,6 +131,10 @@ public class CglibProxyFactory implements ProxyFactory { invocationHandler = new JDKInvocationHandler(messageFactory, callableReference); } + public CglibMethodInterceptor(Class<?> interfaze, Invocable invocable) { + invocationHandler = new JDKInvocationHandler(messageFactory, interfaze, invocable); + } + public CglibMethodInterceptor(ServiceReferenceImpl<T> callbackReference) { invocationHandler = new JDKCallbackInvocationHandler(messageFactory, callbackReference); } diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncJDKInvocationHandler.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncJDKInvocationHandler.java index aeccfa8b05..67b1b923eb 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncJDKInvocationHandler.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncJDKInvocationHandler.java @@ -27,15 +27,23 @@ import javax.xml.ws.AsyncHandler; import javax.xml.ws.Response;
import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.runtime.Invocable;
import org.oasisopen.sca.ServiceReference;
public class AsyncJDKInvocationHandler extends JDKInvocationHandler {
+
private static final long serialVersionUID = 1L;
public AsyncJDKInvocationHandler(MessageFactory messageFactory, ServiceReference<?> callableReference) {
super(messageFactory, callableReference);
}
+ public AsyncJDKInvocationHandler(MessageFactory messageFactory,
+ Class<?> businessInterface,
+ Invocable source) {
+ super(messageFactory, businessInterface, source);
+ }
+
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (isAsyncCallback(method)) {
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java index 77b72ed1d1..d34d9c8638 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java @@ -38,6 +38,7 @@ import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.runtime.Invocable; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; import org.oasisopen.sca.ServiceReference; import org.oasisopen.sca.ServiceRuntimeException; @@ -48,10 +49,9 @@ import org.oasisopen.sca.ServiceRuntimeException; public class JDKInvocationHandler implements InvocationHandler, Serializable { private static final long serialVersionUID = -3366410500152201371L; - protected boolean conversational; protected MessageFactory messageFactory; protected Endpoint target; - protected RuntimeEndpointReference source; + protected Invocable source; protected ServiceReferenceExt<?> callableReference; protected Class<?> businessInterface; @@ -59,7 +59,7 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { protected transient Map<Method, InvocationChain> chains = new IdentityHashMap<Method, InvocationChain>(); - public JDKInvocationHandler(MessageFactory messageFactory, Class<?> businessInterface, RuntimeEndpointReference source) { + public JDKInvocationHandler(MessageFactory messageFactory, Class<?> businessInterface, Invocable source) { this.messageFactory = messageFactory; this.source = source; this.businessInterface = businessInterface; @@ -91,9 +91,12 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { throw new ServiceRuntimeException("No runtime source is available"); } - if (source.isOutOfDate()) { - source.rebuild(); - chains.clear(); + if (source instanceof RuntimeEndpointReference) { + RuntimeEndpointReference epr = (RuntimeEndpointReference)source; + if (epr.isOutOfDate()) { + epr.rebuild(); + chains.clear(); + } } InvocationChain chain = getInvocationChain(method, source); @@ -188,6 +191,16 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { } protected synchronized InvocationChain getInvocationChain(Method method, Invocable source) { + if (source instanceof RuntimeEndpoint) { + InvocationChain invocationChain = source.getBindingInvocationChain(); + for (InvocationChain chain : source.getInvocationChains()) { + Operation operation = chain.getTargetOperation(); + if (method.getName().equals(operation.getName())) { + invocationChain.setTargetOperation(operation); + } + } + return source.getBindingInvocationChain(); + } if (fixedWire && chains.containsKey(method)) { return chains.get(method); } @@ -213,14 +226,18 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { this.target = endpoint; } - protected Object invoke(InvocationChain chain, Object[] args, RuntimeEndpointReference source) + protected Object invoke(InvocationChain chain, Object[] args, Invocable source) throws Throwable { Message msg = messageFactory.createMessage(); - msg.setFrom(source); + if (source instanceof RuntimeEndpointReference) { + msg.setFrom((RuntimeEndpointReference)source); + } if (target != null) { msg.setTo(target); } else { - msg.setTo(source.getTargetEndpoint()); + if (source instanceof RuntimeEndpointReference) { + msg.setTo(((RuntimeEndpointReference)source).getTargetEndpoint()); + } } Invoker headInvoker = chain.getHeadInvoker(); Operation operation = chain.getTargetOperation(); diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKProxyFactory.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKProxyFactory.java index 13d4040b8e..a162110835 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKProxyFactory.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKProxyFactory.java @@ -40,7 +40,9 @@ import org.apache.tuscany.sca.core.invocation.ProxyFactory; import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.runtime.Invocable; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; import org.oasisopen.sca.ServiceReference; +import org.oasisopen.sca.ServiceRuntimeException; /** @@ -61,8 +63,24 @@ public class JDKProxyFactory implements ProxyFactory, LifeCycleListener { * The original createProxy method assumes that the proxy doesn't want to * share conversation state so sets the conversation object to null */ - public <T> T createProxy(Class<T> interfaze, Invocable wire) throws ProxyCreationException { - ServiceReference<T> serviceReference = new ServiceReferenceImpl<T>(interfaze, wire, null); + public <T> T createProxy(final Class<T> interfaze, Invocable invocable) throws ProxyCreationException { + if (invocable instanceof RuntimeEndpoint) { + InvocationHandler handler; + if (isAsync(interfaze)) { + handler = new AsyncJDKInvocationHandler(messageFactory, interfaze, invocable); + } else { + handler = new JDKInvocationHandler(messageFactory, interfaze, invocable); + } + // Allow privileged access to class loader. Requires RuntimePermission in security policy. + ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { + public ClassLoader run() { + return interfaze.getClassLoader(); + } + }); + T proxy = interfaze.cast(newProxyInstance(cl, new Class[] {interfaze}, handler)); + return proxy; + } + ServiceReference<T> serviceReference = new ServiceReferenceImpl<T>(interfaze, invocable, null); return createProxy(serviceReference); } @@ -105,7 +123,13 @@ public class JDKProxyFactory implements ProxyFactory, LifeCycleListener { } public <T> T createCallbackProxy(Class<T> interfaze, List<? extends Invocable> wires) throws ProxyCreationException { - ServiceReferenceImpl<T> callbackReference = new CallbackServiceReferenceImpl(interfaze, wires); + ServiceReferenceImpl<T> callbackReference = null; + try { + callbackReference = new CallbackServiceReferenceImpl(interfaze, wires); + } catch (ServiceRuntimeException e) { + // [rfeng] In case that the call is not from a bidirectional interface, the field should be injected with null + callbackReference = null; + } return callbackReference != null ? createCallbackProxy(callbackReference) : null; } diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java index 1d2a4f9436..7b0f50ebd0 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java @@ -40,7 +40,6 @@ import org.apache.tuscany.sca.assembly.builder.PolicyBuilder; 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.core.assembly.impl.RuntimeEndpointImpl; import org.apache.tuscany.sca.definitions.Definitions; import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.monitor.Monitor; @@ -202,9 +201,9 @@ public class EndpointReferenceBinderImpl implements EndpointReferenceBinder { // a remote binding // still need to check that the callback endpoint is set correctly - if (hasCallback(endpointReference) && - endpointReference.getCallbackEndpoint() != null && - endpointReference.getCallbackEndpoint().isUnresolved() == true ){ + if (hasCallback(endpointReference) && + (endpointReference.getCallbackEndpoint() == null + || endpointReference.getCallbackEndpoint().isUnresolved())) { selectCallbackEndpoint(endpointReference, endpointReference.getReference().getCallbackService().getEndpoints(), matchAudit); |