Author: slaws
Date: Thu Feb 2 13:14:54 2012
New Revision: 1239597
URL: http://svn.apache.org/viewvc?rev=1239597&view=rev
Log:
TUSCANY-4005 - raise an error if a reference target containing only a component
name matches a component with multiple services.
Added:
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/HelloworldServiceAgain.java
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceClientImpl.java
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceImpl.java
Modified:
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
tuscany/sca-java-2.x/trunk/modules/core/src/main/resources/endpoint-validation-messages.properties
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/resources/Helloworld.composite
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/test/java/test/scaclient/SCAClientTestCase.java
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=1239597&r1=1239596&r2=1239597&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
Thu Feb 2 13:14:54 2012
@@ -244,7 +244,8 @@ public class EndpointReferenceBinderImpl
selectForwardEndpoint(endpointReference,
endpointReference.getTargetEndpoint().getService().getEndpoints(),
matchAudit,
- builderContext);
+ builderContext,
+ runtime);
if (hasCallback(endpointReference)){
selectCallbackEndpoint(endpointReference,
@@ -265,7 +266,8 @@ public class EndpointReferenceBinderImpl
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
* @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
}
} 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
Modified:
tuscany/sca-java-2.x/trunk/modules/core/src/main/resources/endpoint-validation-messages.properties
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/resources/endpoint-validation-messages.properties?rev=1239597&r1=1239596&r2=1239597&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/core/src/main/resources/endpoint-validation-messages.properties
(original)
+++
tuscany/sca-java-2.x/trunk/modules/core/src/main/resources/endpoint-validation-messages.properties
Thu Feb 2 13:14:54 2012
@@ -22,3 +22,4 @@ NoEndpointsFound = No endpoints found in
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
Added:
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/HelloworldServiceAgain.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/HelloworldServiceAgain.java?rev=1239597&view=auto
==============================================================================
---
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/HelloworldServiceAgain.java
(added)
+++
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/HelloworldServiceAgain.java
Thu Feb 2 13:14:54 2012
@@ -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);
+
+}
Added:
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceClientImpl.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceClientImpl.java?rev=1239597&view=auto
==============================================================================
---
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceClientImpl.java
(added)
+++
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceClientImpl.java
Thu Feb 2 13:14:54 2012
@@ -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);
+ }
+
+}
Added:
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceImpl.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceImpl.java?rev=1239597&view=auto
==============================================================================
---
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceImpl.java
(added)
+++
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/java/itest/MultipleServiceImpl.java
Thu Feb 2 13:14:54 2012
@@ -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;
+ }
+}
Modified:
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/resources/Helloworld.composite
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/resources/Helloworld.composite?rev=1239597&r1=1239596&r2=1239597&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/resources/Helloworld.composite
(original)
+++
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/main/resources/Helloworld.composite
Thu Feb 2 13:14:54 2012
@@ -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"/>
Modified:
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/test/java/test/scaclient/SCAClientTestCase.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/test/java/test/scaclient/SCAClientTestCase.java?rev=1239597&r1=1239596&r2=1239597&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/test/java/test/scaclient/SCAClientTestCase.java
(original)
+++
tuscany/sca-java-2.x/trunk/testing/itest/scaclient-api/src/test/java/test/scaclient/SCAClientTestCase.java
Thu Feb 2 13:14:54 2012
@@ -95,6 +95,34 @@ public class SCAClientTestCase extends T
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 {