summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2012-02-09 17:46:50 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2012-02-09 17:46:50 +0000
commit59412d176cd4e7950cb48e48580a6de6fb8fec70 (patch)
tree2b41f3020605fe14c7ec709aa9b241dfcd8c7d0d /sca-java-2.x/trunk
parenta9891d03be69d7daab14d273f3209c178fcb086e (diff)
TUSCANY-4011 - stop the SCDL callback binding configuration from being overwritten. The JMS binding strangely relied on this so required some surgery. I've also simplified CallbackServiceReference and added a CALLBACK message header and CallbackHandler object to make is simpler to pass the callback address down the message chain. The existing approach of creating a CallbackEndpoint model is still supported at the moment.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1242412 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk')
-rw-r--r--sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListenerFactory.java6
-rw-r--r--sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingInvoker.java9
-rw-r--r--sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java5
-rw-r--r--sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java30
-rw-r--r--sca-java-2.x/trunk/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBinding.java56
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallbackServiceReferenceImpl.java254
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackHandler.java53
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/Constants.java1
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKCallbackInvocationHandler.java3
-rw-r--r--sca-java-2.x/trunk/testing/itest/ws/contribution-callback-fullspec/src/main/java/org/apache/tuscany/sca/binding/ws/HelloWorldCallbackServiceImpl.java12
-rw-r--r--sca-java-2.x/trunk/testing/itest/ws/contribution-callback-fullspec/src/main/java/org/apache/tuscany/sca/binding/ws/HelloWorldImpl.java26
-rw-r--r--sca-java-2.x/trunk/testing/itest/ws/contribution-callback-fullspec/src/main/resources/META-INF/definitions.xml36
-rw-r--r--sca-java-2.x/trunk/testing/itest/ws/contribution-callback-fullspec/src/main/resources/helloworld.composite5
-rw-r--r--sca-java-2.x/trunk/testing/itest/ws/launcher-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/launcher/axis2/CallbackFullSpecTestCase.java22
14 files changed, 409 insertions, 109 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListenerFactory.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListenerFactory.java
index 1976d687b6..f829e15f04 100644
--- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListenerFactory.java
+++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListenerFactory.java
@@ -43,10 +43,8 @@ public class DefaultJMSServiceListenerFactory implements JMSServiceListenerFacto
RuntimeComponentService service = (RuntimeComponentService) jmsSLD.getEndpoint().getService();
MessageListener listener = new DefaultServiceInvoker(jmsSLD.getEndpoint(), jmsSLD.getTargetBinding(), jmsSLD.getMessageFactory(), rf);
-
-// return new ASFListener(listener, service.getName(), service.isCallback(), jmsSLD.getJmsBinding(), workScheduler, rf);
-// TODO: 2.x migration, service.isCallback()
- return new DefaultJMSServiceListener(listener, service.getName(), false, jmsSLD.getJmsBinding(), workScheduler, rf);
+
+ return new DefaultJMSServiceListener(listener, service.getName(), service.isForCallback(), jmsSLD.getJmsBinding(), workScheduler, rf);
} catch (NamingException e) {
throw new JMSBindingException(e);
diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingInvoker.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingInvoker.java
index 610be6cc56..ff96f56759 100644
--- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingInvoker.java
+++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingInvoker.java
@@ -29,6 +29,8 @@ import org.apache.tuscany.sca.binding.jms.JMSBinding;
import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
import org.apache.tuscany.sca.binding.jms.JMSBindingException;
import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.core.invocation.CallbackHandler;
+import org.apache.tuscany.sca.core.invocation.Constants;
import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.interfacedef.util.FaultException;
@@ -274,6 +276,13 @@ public class RRBJMSBindingInvoker extends InterceptorAsyncImpl {
if (tuscanyMsg.getFrom().getTargetEndpoint() != null) {
if (tuscanyMsg.getFrom().getTargetEndpoint().getBinding() != null) {
this.jmsBinding = (JMSBinding)tuscanyMsg.getFrom().getTargetEndpoint().getBinding();
+
+/* TUSCANY-4011 - we could delay until this point until setting the callback destination
+ CallbackHandler callbackHandler = (CallbackHandler)tuscanyMsg.getHeaders().get(Constants.CALLBACK);
+ if (callbackHandler != null && callbackHandler.getCallbackTargetURI() != null){
+ this.jmsBinding.setDestinationName(callbackHandler.getCallbackTargetURI());
+ }
+*/
requestDestination = lookupDestination();
}
}
diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java
index 0dc137cf5e..549be1552d 100644
--- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java
+++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java
@@ -126,11 +126,6 @@ public class TransportServiceInterceptor extends InterceptorAsyncImpl {
from.setTargetEndpoint(fromEndpoint);
from.setStatus(EndpointReference.Status.WIRED_TARGET_FOUND_AND_MATCHED);
msg.setFrom(from);
- Endpoint callbackEndpoint = assemblyFactory.createEndpoint();
- // binding is set into the callback endpoint in the CallbackDesitnationInterceptor
- callbackEndpoint.setUnresolved(true);
- from.setCallbackEndpoint(callbackEndpoint);
-
return msg;
} // end method invokeRequest
diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java
index 1bce6e8842..8eaa414ae3 100644
--- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java
+++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java
@@ -27,6 +27,8 @@ import org.apache.tuscany.sca.binding.jms.JMSBinding;
import org.apache.tuscany.sca.binding.jms.JMSBindingConstants;
import org.apache.tuscany.sca.binding.jms.JMSBindingException;
import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.core.invocation.CallbackHandler;
+import org.apache.tuscany.sca.core.invocation.Constants;
import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.invocation.Message;
@@ -81,15 +83,20 @@ public class CallbackDestinationInterceptor extends InterceptorAsyncImpl {
if (!callbackdestName.startsWith("jms:jndi:")) {
throw new JMSBindingException("message property " + JMSBindingConstants.CALLBACK_Q_PROPERTY + " does not start with 'jms:jndi:' found: " + callbackdestName);
} else {
- callbackdestName = callbackdestName.substring(9);
- } // end if
+ callbackdestName = "jms:queue:" + callbackdestName.substring(9);
+ }
} else {
// If there is no Callback destination name header present, but the service is a callback, use the JMS ReplyTo header
+ // as per the spec this will override anything specified by the user in SCDL
if (service.getInterfaceContract().getCallbackInterface() != null) {
if ( ( jmsMsg.getJMSReplyTo() != null ) && msg.getOperation().isNonBlocking() ) {
Destination replyTo = jmsMsg.getJMSReplyTo();
if (replyTo != null) {
- callbackdestName = (replyTo instanceof Queue) ? ((Queue) replyTo).getQueueName() : ((Topic) replyTo).getTopicName();
+ if (replyTo instanceof Queue){
+ callbackdestName = "jms:queue:" + ((Queue) replyTo).getQueueName();
+ } else {
+ callbackdestName = "jms:topic:" + ((Topic) replyTo).getTopicName();
+ }
}
} // end if
} // end if
@@ -97,22 +104,7 @@ public class CallbackDestinationInterceptor extends InterceptorAsyncImpl {
// Place the Callback destination name into the Callback EPRs for the service endpoint
if (callbackdestName != null) {
- for (Binding b : service.getCallback().getBindings()) {
- if (b instanceof JMSBinding) {
- JMSBinding callbackBinding;
- try {
- callbackBinding = (JMSBinding)((JMSBinding)b).clone();
- } catch (CloneNotSupportedException e) {
- throw new RuntimeException(e);
- }
- callbackBinding.setDestinationName(callbackdestName);
- // the "from" EPR model is created in the TransportServiceInterceptor
- // not sure which this destination calculation is not performed
- // there as well
- msg.getFrom().getCallbackEndpoint().setBinding(callbackBinding);
-// msg.getHeaders().put("CALLBACK_BINDING", callbackBinding);
- }
- }
+ msg.getHeaders().put(Constants.CALLBACK, new CallbackHandler(callbackdestName));
} // end if
// Callback ID not used at present
diff --git a/sca-java-2.x/trunk/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBinding.java b/sca-java-2.x/trunk/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBinding.java
index d8e7b24a36..7d91df8e09 100644
--- a/sca-java-2.x/trunk/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBinding.java
+++ b/sca-java-2.x/trunk/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBinding.java
@@ -24,6 +24,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.StringTokenizer;
import java.util.TreeSet;
import javax.xml.namespace.QName;
@@ -35,6 +36,9 @@ import org.apache.tuscany.sca.assembly.Extension;
import org.apache.tuscany.sca.assembly.OperationSelector;
import org.apache.tuscany.sca.assembly.OperationsConfigurator;
import org.apache.tuscany.sca.assembly.WireFormat;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
import org.apache.tuscany.sca.policy.ExtensionType;
import org.apache.tuscany.sca.policy.Intent;
import org.apache.tuscany.sca.policy.PolicySet;
@@ -180,6 +184,11 @@ public class JMSBinding implements Binding, PolicySubject, OperationsConfigurato
public void setURI(String uri) {
this.uri = uri;
+ if (uri != null){
+ parseURI(uri);
+ } else {
+ setDestinationName(null);
+ }
}
public String getName() {
@@ -1108,5 +1117,52 @@ public class JMSBinding implements Binding, PolicySubject, OperationsConfigurato
public List<Extension> getAttributeExtensions() {
return attributeExtensions;
}
+
+ public void parseURI(String uri) {
+ JMSBinding jmsBinding = this;
+ if (uri == null ||
+ !(uri.startsWith("jms:jndi:") || uri.startsWith("jms:queue:") || uri.startsWith("jms:topic:"))) {
+ return;
+ }
+
+ int i = uri.indexOf('?');
+ if (i >= 0) {
+ StringTokenizer st = new StringTokenizer(uri.substring(i+1),"&");
+ while (st.hasMoreTokens()) {
+ String s = st.nextToken();
+ if (s.startsWith("jndiConnectionFactoryName=")) {
+ jmsBinding.setConnectionFactoryName(s.substring(26));
+ } else if (s.startsWith("deliveryMode=")) {
+ jmsBinding.setURIJMSDeliveryMode("persistent".equals(s.substring(13)));
+ } else if (s.startsWith("priority=")) {
+ jmsBinding.setURIJMSPriority(Integer.parseInt(s.substring(9)));
+ } else if (s.startsWith("timeToLive=")) {
+ jmsBinding.setURIJMSTimeToLive(Long.parseLong(s.substring(11)));
+ } else if (s.startsWith("selector='")) {
+ String selector = s.substring(10);
+ if (selector.startsWith("\"") || selector.startsWith("'")) {
+ selector = selector.substring(1, selector.length());
+ }
+ if (selector.endsWith("\"") || selector.endsWith("'")) {
+ selector = selector.substring(0, selector.length() - 1);
+ }
+ jmsBinding.setURIJMSSelector(selector);
+ } else if (s.startsWith("type")) {
+ String type = s.substring(5);
+ jmsBinding.setJMSURIType(type);
+ } else {
+ return;
+ }
+ }
+ int j=uri.indexOf(':', 4);
+ jmsBinding.setDestinationName(uri.substring(j+1, i));
+ jmsBinding.setDestinationType(uri.substring(4, j));
+ } else {
+ int j=uri.indexOf(':', 4);
+ jmsBinding.setDestinationName(uri.substring(j+1));
+ jmsBinding.setDestinationType(uri.substring(4, j));
+ }
+ jmsBinding.setJMSURI(uri);
+ }
}
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallbackServiceReferenceImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallbackServiceReferenceImpl.java
index 61f9b7e2cb..b0561303a8 100644
--- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallbackServiceReferenceImpl.java
+++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallbackServiceReferenceImpl.java
@@ -18,8 +18,9 @@
*/
package org.apache.tuscany.sca.core.context.impl;
-import java.net.URI;
import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.apache.tuscany.sca.assembly.Binding;
import org.apache.tuscany.sca.assembly.Endpoint;
@@ -29,28 +30,86 @@ import org.apache.tuscany.sca.assembly.builder.BindingBuilder;
import org.apache.tuscany.sca.assembly.builder.BuilderContext;
import org.apache.tuscany.sca.context.CompositeContext;
import org.apache.tuscany.sca.context.ThreadMessageContext;
+import org.apache.tuscany.sca.core.invocation.CallbackHandler;
import org.apache.tuscany.sca.core.invocation.Constants;
import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
import org.oasisopen.sca.ServiceRuntimeException;
+/**
+ * Represent the reference to the callback service. This class basically wraps a Tuscany EndpointReference.
+ * The callback EPR is selected based on the are 3 basic scenarios we are trying to cater for
+ *
+ * A/ <component name="MyComponent">
+ * <service name="MyService>
+ * blank OR <binding.sca/>
+ * </service>
+ * </component>
+ *
+ * B/ <component name="MyComponent">
+ * <service name="MyService>
+ * <binding.someremotebinding/>
+ * </service>
+ * </component>
+ *
+ * C/ <component name="MyComponent">
+ * <service name="MyService>
+ * some binding
+ * <callback>
+ * <binding.someremotebinding/>
+ * </callback>
+ * </service>
+ * </component>
+ *
+ * A - the callback binding will default to binding.sca and the expectation is that
+ * the callback endpoint will be established by looking it up in the registry
+ * hence the forward call must contain the SCA target name referring to the
+ * callback service
+ *
+ * B - the callback binding defaults to be the forward binding taking all of its
+ * configuration. The callback target URI is taken from the forward message and
+ * put into the callback binding URI
+ *
+ * C - the callback binding is as specified by the user. If the user has not specified
+ * a binding URI then the URI from the forward message will be placed in the
+ * callback binding URI. This may or may not lead to happiness depending on whether
+ * the forward and callback bindings are compatible
+ *
+ * The callback proxy, and this class, is instantiated whenever a new callback proxy is
+ * required as follows:
+ *
+ * If the service component implementation is STATELESS then each incoming message
+ * creates a new service instance and hence a new set of callback proxies
+ *
+ * If the service component implementation is COMPOSITE then only a single instance
+ * of the component implementation will exist and the callback proxy will be retrieved
+ * via the RequestContext.
+ *
+ * Following the Tuscany runtime model for normal references we don't cache callback
+ * proxies across component implementation instances. Hence there will be one
+ * instance of this class for each callback proxy, however created, and the class
+ * will refer to a single callback service. To put it another way, messages from
+ * multiple clients (presenting different callback services) will be called back to
+ * via different callback proxies and hence a single instance of this class will
+ * not be required to handle more than one callback address.
+ *
+ */
public class CallbackServiceReferenceImpl<B> extends ServiceReferenceImpl<B> {
+ private static final Logger logger = Logger.getLogger(CallbackServiceReferenceImpl.class.getName());
private RuntimeEndpointReference callbackEPR;
private List<? extends EndpointReference> callbackEPRs;
private Endpoint resolvedEndpoint;
// Holds the ID of the Message that caused the creation of this CallbackServiceReference
private String msgID;
-
- /**
- * Gets the message ID associated with this callback reference
- * @return the message ID
- */
- public String getMsgID() {
- return msgID;
- }
+
+ // Holds the URI of the target callback service from the Message that caused the
+ // creation of this CallbackServiceReference
+ private CallbackHandler callbackHandler;
/*
* Public constructor for Externalizable serialization/deserialization
+ * TODO - we need to serialize the msgID and callbackURI
*/
public CallbackServiceReferenceImpl() {
super();
@@ -60,9 +119,69 @@ public class CallbackServiceReferenceImpl<B> extends ServiceReferenceImpl<B> {
List<? extends EndpointReference> callbackEPRs) {
super(interfaze, null, getCompositeContext(callbackEPRs));
this.callbackEPRs = callbackEPRs;
- init();
+
+ Message msgContext = ThreadMessageContext.getMessageContext();
+
+ // Capture the Message ID from the message which caused the creation of this
+ // CallBackServiceReference
+ this.msgID = (String) msgContext.getHeaders().get(Constants.MESSAGE_ID);
+
+ // Capture the callback URI from the message which caused the creation of this
+ // CallBackServiceReference. This code is more complex that needs be for the time being
+ // to cater for bindings that still use the approach of constructing a callback endpoint
+ // to model the callback URI. With these changes the binding can just set a CallbackHandler
+ // in the forward message to get the same effect. Some bindings don't do that hence
+ // the various checks
+ this.resolvedEndpoint = msgContext.getFrom().getCallbackEndpoint();
+ if (resolvedEndpoint != null && resolvedEndpoint.getBinding() != null){
+ if (resolvedEndpoint.getBinding().getType().equals(SCABinding.TYPE)){
+ this.callbackHandler = new CallbackHandler(resolvedEndpoint.getURI());
+ } else {
+ this.callbackHandler = new CallbackHandler(resolvedEndpoint.getBinding().getURI());
+ }
+ } else {
+ this.callbackHandler = (CallbackHandler)msgContext.getHeaders().get(Constants.CALLBACK);
+
+ if (callbackHandler == null){
+ this.callbackHandler = new CallbackHandler(null);
+ }
+ }
+
+ if (callbackHandler.getCallbackTargetURI() != null){
+ logger.log(Level.FINE, "Selecting callback EPR using address from forward message: " + callbackHandler.getCallbackTargetURI());
+ } else {
+ logger.log(Level.FINE, "Selecting callback EPR using address but callback URI is null");
+ }
+
+ // Work out which callback EPR to use
+ callbackEPR = selectCallbackEPR(msgContext);
+ if (callbackEPR == null) {
+ throw new ServiceRuntimeException("No callback binding found for " + msgContext.getTo().toString());
+ }
+
+ // configure the callback EPR with the callback address
+ if (callbackHandler.getCallbackTargetURI() != null) {
+ callbackEPR = setCallbackAddress(callbackEPR);
+ }
+
+ this.resolvedEndpoint = callbackEPR.getTargetEndpoint();
+ }
+
+ public CallbackHandler getCallbackHandler() {
+ return callbackHandler;
}
+ /**
+ * Gets the message ID associated with this callback reference. All calls through the proxy backed by
+ * this CallbackServiceReference will use the same msgID
+ *
+ * @return the message ID
+ */
+ public String getMsgID() {
+ return msgID;
+ }
+
+
private static CompositeContext getCompositeContext(List<? extends EndpointReference> callbackEPRs) {
if(!callbackEPRs.isEmpty()) {
RuntimeEndpointReference epr = (RuntimeEndpointReference) callbackEPRs.get(0);
@@ -71,29 +190,13 @@ public class CallbackServiceReferenceImpl<B> extends ServiceReferenceImpl<B> {
return null;
}
- public void init() {
- Message msgContext = ThreadMessageContext.getMessageContext();
- callbackEPR = selectCallbackEPR(msgContext);
- if (callbackEPR == null) {
- throw new ServiceRuntimeException("No callback binding found for " + msgContext.getTo().toString());
- }
- resolvedEndpoint = msgContext.getFrom().getCallbackEndpoint();
-
- // Capture the Message ID from the message which caused the creation of this CallBackServiceReference
- this.msgID = (String) msgContext.getHeaders().get(Constants.MESSAGE_ID);
- }
-
@Override
protected B createProxy() throws Exception {
return proxyFactory.createCallbackProxy(this);
}
public RuntimeEndpointReference getCallbackEPR() {
- if (resolvedEndpoint == null) {
- return null;
- } else {
- return cloneAndBind(callbackEPR);
- }
+ return callbackEPR;
}
public Endpoint getResolvedEndpoint() {
@@ -101,6 +204,7 @@ public class CallbackServiceReferenceImpl<B> extends ServiceReferenceImpl<B> {
}
private RuntimeEndpointReference selectCallbackEPR(Message msgContext) {
+
// look for callback binding with same name as service binding
Endpoint to = msgContext.getTo();
if (to == null) {
@@ -124,56 +228,58 @@ public class CallbackServiceReferenceImpl<B> extends ServiceReferenceImpl<B> {
return null;
}
- private RuntimeEndpointReference cloneAndBind(RuntimeEndpointReference endpointReference) {
- if (resolvedEndpoint != null) {
-
- try {
- RuntimeEndpointReference epr = (RuntimeEndpointReference)endpointReference.clone();
- epr.setTargetEndpoint(resolvedEndpoint);
+ private RuntimeEndpointReference setCallbackAddress(RuntimeEndpointReference endpointReference) {
+ try {
+
+ RuntimeEndpointReference epr = endpointReference;
+
+ if (callbackHandler.getCloneCallbackWire()){
+ epr = (RuntimeEndpointReference)endpointReference.clone();
+ }
+
+ // TUSCANY-3932
+ // If it's the default binding then we're going to look the callback endpoint
+ // up in the registry. Most remote protocols, which may be used as delegates
+ // for binding.sca, will expect to deal with absolute URLs so flip the
+ // callback endpoint back to force the lookup to happen
+ if (epr.getBinding().getType().equals(SCABinding.TYPE)){
+ // A/ create a callback endpoint to allow the
+ // callback lookup to take place
+ epr.setStatus(EndpointReference.Status.WIRED_TARGET_NOT_FOUND);
+
+ // if an endpoint it provided in the forward message use it or
+ // if not create one
+ if (resolvedEndpoint == null ){
+ RuntimeEndpoint callbackEndpoint = (RuntimeEndpoint)assemblyFactory.createEndpoint();
+ callbackEndpoint.setURI(callbackHandler.getCallbackTargetURI());
+ callbackEndpoint.setUnresolved(true);
+ epr.setTargetEndpoint(callbackEndpoint);
+ } else {
+ epr.setTargetEndpoint(resolvedEndpoint);
+ }
+ } else {
+ // B/ and C/ assume that the callback EPR is already resolved
+ // and set the binding URI if one is provided with the
+ // forward message. Some bindings may want to do other
+ // things to determine the callback URI to the
+ // CallbackHandler will be sent in the callback message
+ // header. This is particularly true if the clone isn't
+ // called above because resetting the URI will not
+ // be thread safe.
+ epr.setStatus(EndpointReference.Status.RESOLVED_BINDING);
- // TUSCANY-3932
- // If it's the default binding then we're going to look the callback endpoint
- // up in the registry. Most remote protocols, which may be used as delegates
- // for binding.sca, will expect to deal with absolute URLs so flip the
- // callback endpoint back to force the lookup to happen
- if (epr.getBinding().getType().equals(SCABinding.TYPE)){
- epr.setStatus(EndpointReference.Status.WIRED_TARGET_NOT_FOUND);
+ if ( callbackHandler.getCallbackTargetURI() != null ){
+ epr.getBinding().setURI(callbackHandler.getCallbackTargetURI());
} else {
- // just copy the callback binding from the callback endpoint to the
- // callback EPR as the EPR is effectively already resolved
- epr.setStatus(EndpointReference.Status.RESOLVED_BINDING);
- Binding callbackBinding = resolvedEndpoint.getBinding();
- if ( callbackBinding != null){
- epr.setBinding(callbackBinding);
- // make sure that the chains are recreated for
- // this new binding
- epr.setBindingProvider(null);
- epr.rebuild();
- } else {
- // do nothing and rely on whatever the user has configured
- // in the SCDL
- }
+ // do nothing and rely on whatever the user has configured
+ // in the SCDL
}
-
- return epr;
- } catch (CloneNotSupportedException e) {
- // will not happen
- throw new ServiceRuntimeException(e);
}
- } else {
- return null;
- }
- }
-
- private void build(EndpointReference endpointReference) {
- BindingBuilder builder = builders.getBindingBuilder(endpointReference.getBinding().getType());
- if (builder != null) {
- builder.build(endpointReference.getComponent(),
- endpointReference.getReference(),
- endpointReference.getBinding(),
- new BuilderContext(registry),
- false);
+
+ return epr;
+ } catch (CloneNotSupportedException e) {
+ // will not happen
+ throw new ServiceRuntimeException(e);
}
- }
-
+ }
}
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackHandler.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackHandler.java
new file mode 100644
index 0000000000..bccce0d20a
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackHandler.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.invocation;
+
+/**
+ * Models callback information arriving in the forward message
+ */
+public class CallbackHandler {
+ private String callbackTargetURI;
+ private boolean cloneCallbackWire = true;
+
+ public CallbackHandler(String callbackTargetURI){
+ setCallbackTargetURI(callbackTargetURI);
+ }
+
+ public CallbackHandler(String callbackTargetURI, boolean cloneCallbackWire){
+ setCallbackTargetURI(callbackTargetURI);
+ setCloneCallbackWire(cloneCallbackWire);
+ }
+
+ public String getCallbackTargetURI() {
+ return callbackTargetURI;
+ }
+
+ public boolean getCloneCallbackWire() {
+ return cloneCallbackWire;
+ }
+
+ public void setCallbackTargetURI(String callbackTargetURI) {
+ this.callbackTargetURI = callbackTargetURI;
+ }
+
+ public void setCloneCallbackWire(boolean cloneCallbackWire) {
+ this.cloneCallbackWire = cloneCallbackWire;
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/Constants.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/Constants.java
index d84ef752ac..00c650ada6 100644
--- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/Constants.java
+++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/Constants.java
@@ -28,6 +28,7 @@ public interface Constants {
public static final String RELATES_TO = "RELATES_TO";
public static final String ASYNC_RESPONSE_INVOKER = "ASYNC_RESPONSE_INVOKER";
public static final String ASYNC_CALLBACK = "ASYNC_CALLBACK";
+ public static final String CALLBACK = "CALLBACK";
/**
* If you've set the TCCL in your binding impl according to OASIS rules you can prevent
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKCallbackInvocationHandler.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKCallbackInvocationHandler.java
index c35b70ad74..bde3e92c27 100644
--- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKCallbackInvocationHandler.java
+++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKCallbackInvocationHandler.java
@@ -105,6 +105,9 @@ public class JDKCallbackInvocationHandler extends JDKInvocationHandler {
msg.setTo(((RuntimeEndpointReference)source).getTargetEndpoint());
}
}
+
+ msg.getHeaders().put(Constants.CALLBACK, ((CallbackServiceReferenceImpl)callableReference).getCallbackHandler());
+
Invoker headInvoker = chain.getHeadInvoker();
Operation operation = null;
diff --git a/sca-java-2.x/trunk/testing/itest/ws/contribution-callback-fullspec/src/main/java/org/apache/tuscany/sca/binding/ws/HelloWorldCallbackServiceImpl.java b/sca-java-2.x/trunk/testing/itest/ws/contribution-callback-fullspec/src/main/java/org/apache/tuscany/sca/binding/ws/HelloWorldCallbackServiceImpl.java
index 057b884bc9..0cbc421f23 100644
--- a/sca-java-2.x/trunk/testing/itest/ws/contribution-callback-fullspec/src/main/java/org/apache/tuscany/sca/binding/ws/HelloWorldCallbackServiceImpl.java
+++ b/sca-java-2.x/trunk/testing/itest/ws/contribution-callback-fullspec/src/main/java/org/apache/tuscany/sca/binding/ws/HelloWorldCallbackServiceImpl.java
@@ -32,7 +32,11 @@ public class HelloWorldCallbackServiceImpl implements HelloWorldCallbackService
public String getGreetings(String s) {
System.out.println("Entering SCA HelloWorldCallbackService.getGreetings: " + s);
- String response = helloWorldCallback.getGreetingsCallback(s);
+ String response = null;
+ for (int i = 0; i < 5 ; i++){
+ System.out.println("In SCA HelloWorldCallbackService.getGreetings: calling helloWorldCallback.getGreetingsCallback(s) interation " + i);
+ response = helloWorldCallback.getGreetingsCallback(s);
+ }
System.out.println("Leaving SCA HelloWorldCallbackService.getGreetings: " + response);
return response;
}
@@ -46,7 +50,11 @@ public class HelloWorldCallbackServiceImpl implements HelloWorldCallbackService
public Foo getGreetingsComplex(Foo foo){
System.out.println("Entering SCA HelloWorldCallbackService.getGreetingsComplex: " + foo.getBars().get(0).getS());
- Foo response = helloWorldCallback.getGreetingsComplexCallback(foo);
+ Foo response = null;
+ for (int i = 0; i < 5 ; i++){
+ System.out.println("In SCA HelloWorldCallbackService.getGreetingsComplex: calling helloWorldCallback.getGreetingsComplexCallback(s) interation " + i);
+ response = helloWorldCallback.getGreetingsComplexCallback(foo);
+ }
System.out.println("Leaving SCA HelloWorldCallbackService.getGreetingsComplex: " + foo.getBars().get(0).getS());
return response;
}
diff --git a/sca-java-2.x/trunk/testing/itest/ws/contribution-callback-fullspec/src/main/java/org/apache/tuscany/sca/binding/ws/HelloWorldImpl.java b/sca-java-2.x/trunk/testing/itest/ws/contribution-callback-fullspec/src/main/java/org/apache/tuscany/sca/binding/ws/HelloWorldImpl.java
index 1ff58a29b0..39ef3c2032 100644
--- a/sca-java-2.x/trunk/testing/itest/ws/contribution-callback-fullspec/src/main/java/org/apache/tuscany/sca/binding/ws/HelloWorldImpl.java
+++ b/sca-java-2.x/trunk/testing/itest/ws/contribution-callback-fullspec/src/main/java/org/apache/tuscany/sca/binding/ws/HelloWorldImpl.java
@@ -20,10 +20,13 @@
package org.apache.tuscany.sca.binding.ws;
import javax.jws.WebService;
+import javax.security.auth.Subject;
import org.apache.tuscany.sca.binding.ws.jaxws.external.service.iface.Foo;
import org.apache.tuscany.sca.binding.ws.jaxws.external.service.iface.HelloWorldService;
+import org.oasisopen.sca.RequestContext;
import org.oasisopen.sca.ServiceRuntimeException;
+import org.oasisopen.sca.annotation.Context;
import org.oasisopen.sca.annotation.Reference;
@WebService
@@ -35,25 +38,36 @@ public class HelloWorldImpl implements HelloWorld, HelloWorldCallback {
@Reference
public HelloWorldCallbackService helloWorldCallbackService;
+ @Context
+ protected RequestContext requestContext;
+
// HelloWorld operations
public String getGreetings(String s) {
System.out.println("Entering SCA HelloWorld.getGreetings: " + s);
- String response = helloWorldCallbackService.getGreetings(s);
+ String response = null;
+ for (int i = 0; i < 5 ; i++){
+ System.out.println("In SCA HelloWorld.getGreetings: calling helloWorldCallbackService.getGreetings(s) interation " + i);
+ response = helloWorldCallbackService.getGreetings(s);
+ }
System.out.println("Leaving SCA HelloWorld.getGreetings: " + response);
return response;
}
public String getGreetingsException(String s) throws ServiceRuntimeException {
System.out.println("Entering SCA HelloWorld.getGreetingsException: " + s);
- String response = helloWorldCallbackService.getGreetings(s);
+ String response = helloWorldCallbackService.getGreetings(s);
System.out.println("Leaving SCA HelloWorld.getGreetings: " + response);
throw new ServiceRuntimeException(response);
}
public Foo getGreetingsComplex(Foo foo){
System.out.println("Entering SCA HelloWorld.getGreetingsComplex: " + foo.getBars().get(0).getS());
- Foo response = helloWorldCallbackService.getGreetingsComplex(foo);
+ Foo response = null;
+ for (int i = 0; i < 5 ; i++){
+ System.out.println("In SCA HelloWorld.getGreetingsComplex: calling helloWorldCallbackService.getGreetingsComplex(foo) interation " + i);
+ response = helloWorldCallbackService.getGreetingsComplex(foo);
+ }
System.out.println("Leaving SCA HelloWorld.getGreetingsComplex: " + foo.getBars().get(0).getS());
return response;
}
@@ -63,6 +77,12 @@ public class HelloWorldImpl implements HelloWorld, HelloWorldCallback {
public String getGreetingsCallback(String s) {
System.out.println("Entering SCA HelloWorld.getGreetingsCallback: " + s);
String response = helloWorldExternal.getGreetings(s);
+
+ Subject subject = requestContext.getSecuritySubject();
+ if (subject == null){
+ response = "No Security Subject";
+ }
+
System.out.println("Leaving SCA HelloWorld.getGreetingsCallback: " + response);
return response;
}
diff --git a/sca-java-2.x/trunk/testing/itest/ws/contribution-callback-fullspec/src/main/resources/META-INF/definitions.xml b/sca-java-2.x/trunk/testing/itest/ws/contribution-callback-fullspec/src/main/resources/META-INF/definitions.xml
new file mode 100644
index 0000000000..cce5bbe403
--- /dev/null
+++ b/sca-java-2.x/trunk/testing/itest/ws/contribution-callback-fullspec/src/main/resources/META-INF/definitions.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ * 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.
+-->
+<definitions xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/1.1"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
+ xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912" >
+
+
+ <sca:policySet name="BasicAuthenticationPolicySet"
+ provides="clientAuthentication.transport"
+ appliesTo="//sca:binding.ws">
+ <tuscany:basicAuthentication>
+ <tuscany:userName>myname</tuscany:userName>
+ <tuscany:password>mypassword</tuscany:password>
+ </tuscany:basicAuthentication>
+ </sca:policySet>
+
+
+</definitions> \ No newline at end of file
diff --git a/sca-java-2.x/trunk/testing/itest/ws/contribution-callback-fullspec/src/main/resources/helloworld.composite b/sca-java-2.x/trunk/testing/itest/ws/contribution-callback-fullspec/src/main/resources/helloworld.composite
index 31414beb47..fc64de7b8a 100644
--- a/sca-java-2.x/trunk/testing/itest/ws/contribution-callback-fullspec/src/main/resources/helloworld.composite
+++ b/sca-java-2.x/trunk/testing/itest/ws/contribution-callback-fullspec/src/main/resources/helloworld.composite
@@ -19,6 +19,7 @@
-->
<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
targetNamespace="http://www.tuscany.apache.org/itests/binding/ws/axis2"
name="HelloWorld">
@@ -33,7 +34,7 @@
<reference name="helloWorldCallbackService">
<binding.ws uri="http://localhost:8084/HelloWorldCallbackService"/>
<callback>
- <binding.ws uri="http://localhost:8085/HelloWorldService/HelloWorldCallback"/>
+ <binding.ws uri="http://localhost:8085/HelloWorldService/HelloWorldCallback" policySets="tuscany:BasicAuthenticationPolicySet"/>
</callback>
</reference>
</component>
@@ -43,7 +44,7 @@
<service name="HelloWorldCallbackService">
<binding.ws uri="http://localhost:8084/HelloWorldCallbackService"/>
<callback>
- <binding.ws/>
+ <binding.ws policySets="tuscany:BasicAuthenticationPolicySet"/>
</callback>
</service>
</component>
diff --git a/sca-java-2.x/trunk/testing/itest/ws/launcher-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/launcher/axis2/CallbackFullSpecTestCase.java b/sca-java-2.x/trunk/testing/itest/ws/launcher-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/launcher/axis2/CallbackFullSpecTestCase.java
index a8980c8031..d5cfbb9c0e 100644
--- a/sca-java-2.x/trunk/testing/itest/ws/launcher-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/launcher/axis2/CallbackFullSpecTestCase.java
+++ b/sca-java-2.x/trunk/testing/itest/ws/launcher-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/launcher/axis2/CallbackFullSpecTestCase.java
@@ -22,13 +22,22 @@ package org.apache.tuscany.sca.binding.ws.launcher.axis2;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.binding.ws.WebServiceBinding;
import org.apache.tuscany.sca.binding.ws.jaxws.external.client.HelloWorldClientLauncher;
import org.apache.tuscany.sca.binding.ws.jaxws.external.service.HelloWorldServiceLauncher;
import org.apache.tuscany.sca.binding.ws.jaxws.sca.Bar;
import org.apache.tuscany.sca.binding.ws.jaxws.sca.Foo;
+import org.apache.tuscany.sca.node.impl.NodeImpl;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
+import org.apache.tuscany.sca.policy.PolicySubject;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
@@ -71,6 +80,7 @@ public class CallbackFullSpecTestCase {
@Test
public void testGetGreetings() throws Exception {
assertEquals("Hello Fred", externalClient.getGreetings("Fred"));
+ assertEquals("Hello Fred", externalClient.getGreetings("Fred"));
}
@Test
@@ -101,6 +111,18 @@ public class CallbackFullSpecTestCase {
assertTrue(f2.getBars().get(2).isB().booleanValue());
}
+ @Test
+ public void testCallbackBindingConfig() throws Exception {
+ Component helloWorldCallbackServiceComponent = ((NodeImpl)node).getDomainComposite().getComponent("HelloWorldCallbackService");
+ Service helloWorldService = helloWorldCallbackServiceComponent.getService("HelloWorldCallbackService");
+ Reference callbackReference = ((RuntimeComponentService)helloWorldService).getCallbackReference();
+ for (EndpointReference epr : callbackReference.getEndpointReferences()){
+ Binding callbackBinding = epr.getBinding();
+ assertEquals(WebServiceBinding.TYPE, callbackBinding.getType());
+ assertEquals(1, ((PolicySubject)callbackBinding).getPolicySets().size());
+ }
+ }
+
@After
public void tearDown() throws Exception {
node.stop();