Author: rfeng
Date: Mon May 17 17:27:54 2010
New Revision: 945259

URL: http://svn.apache.org/viewvc?rev=945259&view=rev
Log:
Make sure callback endpoints are created
When a component is invoked from a non bidirectional interface, inject null to 
the fields/setters with @Callback

Modified:
    tuscany/sca-java-2.x/trunk/modules/builder/META-INF/MANIFEST.MF
    
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointReferenceBuilderImpl.java
    
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java
    
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java
    
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncJDKInvocationHandler.java
    
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java
    
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKProxyFactory.java
    
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java

Modified: tuscany/sca-java-2.x/trunk/modules/builder/META-INF/MANIFEST.MF
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/builder/META-INF/MANIFEST.MF?rev=945259&r1=945258&r2=945259&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/builder/META-INF/MANIFEST.MF (original)
+++ tuscany/sca-java-2.x/trunk/modules/builder/META-INF/MANIFEST.MF Mon May 17 
17:27:54 2010
@@ -31,6 +31,7 @@ Import-Package: javax.xml.namespace,
  org.apache.tuscany.sca.policy;version="2.0.0",
  org.apache.tuscany.sca.runtime;version="2.0.0",
  org.apache.tuscany.sca.xsd;version="2.0.0",
+ org.apache.ws.commons.schema,
  org.oasisopen.sca;version="2.0.0",
  org.w3c.dom
 Bundle-SymbolicName: org.apache.tuscany.sca.builder

Modified: 
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointReferenceBuilderImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointReferenceBuilderImpl.java?rev=945259&r1=945258&r2=945259&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointReferenceBuilderImpl.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointReferenceBuilderImpl.java
 Mon May 17 17:27:54 2010
@@ -314,6 +314,13 @@ public class EndpointReferenceBuilderImp
                             
endpointRef.setTargetEndpoint(createEndpoint(false));
                             
endpointRef.setStatus(EndpointReference.Status.RESOLVED_BINDING);
                         }
+                        
+                        if (reference.getCallbackService() != null) {
+                            Endpoint callbackEndpoint =
+                                createEndpoint(component, 
reference.getCallbackService(), false);
+                            endpointRef.setCallbackEndpoint(callbackEndpoint);
+                        }
+                        
                         reference.getEndpointReferences().add(endpointRef);
                         continue;
                     } // end if
@@ -345,6 +352,11 @@ public class EndpointReferenceBuilderImp
                     }
                     
                     endpointRef.setTargetEndpoint(endpoint);   
+                    if (reference.getCallbackService() != null) {
+                        Endpoint callbackEndpoint =
+                            createEndpoint(component, 
reference.getCallbackService(), false);
+                        endpointRef.setCallbackEndpoint(callbackEndpoint);
+                    }
                     reference.getEndpointReferences().add(endpointRef);
                 }
             }

Modified: 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java?rev=945259&r1=945258&r2=945259&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java
 Mon May 17 17:27:54 2010
@@ -251,8 +251,8 @@ public class ComponentContextImpl implem
             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())) {

Modified: 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java?rev=945259&r1=945258&r2=945259&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java
 Mon May 17 17:27:54 2010
@@ -35,6 +35,7 @@ import org.apache.tuscany.sca.core.invoc
 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 implement
 
     }
 
-    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 implement
             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);
         }

Modified: 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncJDKInvocationHandler.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncJDKInvocationHandler.java?rev=945259&r1=945258&r2=945259&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncJDKInvocationHandler.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncJDKInvocationHandler.java
 Mon May 17 17:27:54 2010
@@ -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)) {

Modified: 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java?rev=945259&r1=945258&r2=945259&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java
 Mon May 17 17:27:54 2010
@@ -38,6 +38,7 @@ import org.apache.tuscany.sca.invocation
 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.ServiceRuntimeE
 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 implem
 
     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 implem
             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 implem
     }
 
     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 implem
         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();

Modified: 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKProxyFactory.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKProxyFactory.java?rev=945259&r1=945258&r2=945259&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKProxyFactory.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKProxyFactory.java
 Mon May 17 17:27:54 2010
@@ -40,7 +40,9 @@ import org.apache.tuscany.sca.core.invoc
 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 
      * 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 
     }
 
     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;
     }
 

Modified: 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java?rev=945259&r1=945258&r2=945259&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
 Mon May 17 17:27:54 2010
@@ -40,7 +40,6 @@ import org.apache.tuscany.sca.assembly.b
 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
             // 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);


Reply via email to