diff options
7 files changed, 185 insertions, 3 deletions
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 263fdcecbe..c1eaf98e66 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 @@ -244,7 +244,8 @@ public class EndpointReferenceBinderImpl implements EndpointReferenceBinder { selectForwardEndpoint(endpointReference, endpointReference.getTargetEndpoint().getService().getEndpoints(), matchAudit, - builderContext); + builderContext, + runtime); if (hasCallback(endpointReference)){ selectCallbackEndpoint(endpointReference, @@ -265,7 +266,8 @@ public class EndpointReferenceBinderImpl implements EndpointReferenceBinder { selectForwardEndpoint(endpointReference, endpoints, matchAudit, - builderContext); + builderContext, + runtime); // If the reference was matched try to match the callback if (endpointReference.getStatus().equals(EndpointReference.Status.WIRED_TARGET_FOUND_AND_MATCHED) && @@ -402,7 +404,7 @@ public class EndpointReferenceBinderImpl implements EndpointReferenceBinder { * @param endpointReference * @param endpoints */ - private void selectForwardEndpoint(EndpointReference endpointReference, List<Endpoint> endpoints, Audit matchAudit, BuilderContext builderContext) { + private void selectForwardEndpoint(EndpointReference endpointReference, List<Endpoint> endpoints, Audit matchAudit, BuilderContext builderContext, boolean runtime) { Endpoint matchedEndpoint = null; @@ -415,6 +417,48 @@ public class EndpointReferenceBinderImpl implements EndpointReferenceBinder { } } else { // find the first endpoint that matches this endpoint reference + + // TUSCANY-4005 - raise an error if a reference target that only specifies the + // component name matches more than one component service + if (endpointReference.getTargetEndpoint().getService() == null && + endpointReference.getTargetEndpoint().getBinding() == null && + endpoints.size() > 1 ) { + + String serviceName = null; + for (Endpoint endpoint : endpoints){ + // ignore service names called "default" as these indicate dynamic services + // created for the likes of implementation.python + if (serviceName == null && + !endpoint.getService().getName().equals("default")){ + serviceName = endpoint.getService().getName(); + } + + if (serviceName != null && + !endpoint.getService().getName().equals("default") && + !endpoint.getService().getName().equals(serviceName)){ + if (runtime){ + Monitor.error(monitor, + this, + "endpoint-validation-messages", + "TooManyTargetServices", + endpointReference.toString(), + endpointReference.getTargetEndpoint().toString(), + matchAudit); + throw new ServiceRuntimeException("Unable to bind " + + monitor.getLastProblem().toString()); + } else { + Monitor.warning(monitor, + this, + "endpoint-validation-messages", + "TooManyTargetServices", + endpointReference.toString(), + endpointReference.getTargetEndpoint().toString()); + return; + } + } + } + } + boolean findTargetSCABinding = false; // TUSCANY-3941 check for the case where the user has provided a diff --git a/sca-java-2.x/trunk/modules/core/src/main/resources/endpoint-validation-messages.properties b/sca-java-2.x/trunk/modules/core/src/main/resources/endpoint-validation-messages.properties index 5c9e01ffdc..f300010bd4 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/resources/endpoint-validation-messages.properties +++ b/sca-java-2.x/trunk/modules/core/src/main/resources/endpoint-validation-messages.properties @@ -22,3 +22,4 @@ NoEndpointsFound = No endpoints found in the domain that match the reference {0} EndpointReferenceCantBeMatched = Unable to match the endpoint reference {0} with the policy of the service to which it refers, matching process was {1} # Single quote (we'll) needs to be escaped as we''ll ComponentReferenceTargetNotFound = Component reference target not found at deployment time, it might be a remote service elsewhere in the SCA Domain so we''ll try and resolve it again at runtime: {0} +TooManyTargetServices = [ASM60048] A component reference {0} with only the target component service name specified {1} matches more than one service
\ No newline at end of file diff --git a/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/HelloworldServiceAgain.java b/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/HelloworldServiceAgain.java new file mode 100644 index 0000000000..614232c01e --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/HelloworldServiceAgain.java @@ -0,0 +1,25 @@ +/*
+ * 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 itest;
+
+public interface HelloworldServiceAgain {
+
+ String sayHelloAgain(String name);
+
+}
diff --git a/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceClientImpl.java b/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceClientImpl.java new file mode 100644 index 0000000000..9313500e72 --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceClientImpl.java @@ -0,0 +1,38 @@ +/*
+ * 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 itest;
+
+import org.oasisopen.sca.annotation.EagerInit;
+import org.oasisopen.sca.annotation.Reference;
+import org.oasisopen.sca.annotation.Scope;
+import org.oasisopen.sca.annotation.Service;
+
+@EagerInit
+@Scope("COMPOSITE")
+@Service(HelloworldService.class)
+public class MultipleServiceClientImpl implements HelloworldService {
+
+ @Reference
+ public HelloworldServiceAgain helloWorld;
+
+ public String sayHello(String name) {
+ return "Hello " + helloWorld.sayHelloAgain(name);
+ }
+
+}
diff --git a/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceImpl.java b/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceImpl.java new file mode 100644 index 0000000000..a7001c327d --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceImpl.java @@ -0,0 +1,37 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package itest;
+
+import org.oasisopen.sca.annotation.EagerInit;
+import org.oasisopen.sca.annotation.Scope;
+import org.oasisopen.sca.annotation.Service;
+
+@EagerInit
+@Scope("COMPOSITE")
+@Service({HelloworldService.class, HelloworldServiceAgain.class})
+public class MultipleServiceImpl implements HelloworldService, HelloworldServiceAgain {
+
+ public String sayHello(String name) {
+ return "Hello " + name;
+ }
+
+ public String sayHelloAgain(String name) {
+ return "Hello again " + name;
+ }
+}
diff --git a/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/resources/Helloworld.composite b/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/resources/Helloworld.composite index 70248d0a0c..b2b2509ce9 100644 --- a/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/resources/Helloworld.composite +++ b/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/resources/Helloworld.composite @@ -29,6 +29,15 @@ <component name="SingleServiceComponent"> <implementation.java class="itest.SingleServiceImpl"/> </component> + + <component name="MultipleServiceClientComponent"> + <implementation.java class="itest.MultipleServiceClientImpl"/> + <reference name="helloWorld" target="MultipleServiceComponent"/> + </component> + + <component name="MultipleServiceComponent"> + <implementation.java class="itest.MultipleServiceImpl"/> + </component> <component name="OnlyWSBindingComponent"> <implementation.java class="itest.HelloworldServiceImpl"/> diff --git a/sca-java-2.x/trunk/testing/itest/scaclient-api/src/test/java/test/scaclient/SCAClientTestCase.java b/sca-java-2.x/trunk/testing/itest/scaclient-api/src/test/java/test/scaclient/SCAClientTestCase.java index e15d5a2157..6016f101e8 100644 --- a/sca-java-2.x/trunk/testing/itest/scaclient-api/src/test/java/test/scaclient/SCAClientTestCase.java +++ b/sca-java-2.x/trunk/testing/itest/scaclient-api/src/test/java/test/scaclient/SCAClientTestCase.java @@ -95,6 +95,34 @@ public class SCAClientTestCase extends TestCase { HelloworldService service = clientFactory.getService(HelloworldService.class, "SingleServiceComponent"); assertEquals("Hello petra", service.sayHello("petra")); } + + @Test + public void testWithoutServiceNameMultipleService() throws Exception { + node = NodeFactory.getInstance().createNode(URI.create("myFooDomain"), new String[] {"target/classes"}); + node.start(); + + SCAClientFactory clientFactory = SCAClientFactory.newInstance(URI.create("myFooDomain")); + + // test multiple service error reported at the SCAClient wire + try { + HelloworldService service = clientFactory.getService(HelloworldService.class, "MultipleServiceComponent"); + assertEquals("Hello petra", service.sayHello("petra")); + fail(); + } catch (ServiceRuntimeException e) { + // expected + } + + // test multiple service error reported at the wire associated with a reference of + // the component the SCAClient is talking to + HelloworldService service = clientFactory.getService(HelloworldService.class, "MultipleServiceClientComponent"); + + try { + assertEquals("Hello Hello again petra", service.sayHello("petra")); + fail(); + } catch (ServiceRuntimeException e) { + // expected + } + } @Test public void testWithBadServiceName() throws Exception { |