summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2008-08-18 19:59:14 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2008-08-18 19:59:14 +0000
commit400713c5c4c89dfcc7e77f502003af63e1098c15 (patch)
tree1965c0b682d58f90155c1b0e27ecb0a2d35659d7 /java
parent9baa2dd9ba3cb463b412ea874058a93b00b1dfde (diff)
Fix the webapp regression where the no explicit deployable composite is passed into the Node API
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@686861 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java108
-rw-r--r--java/sca/modules/node2-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java51
-rw-r--r--java/sca/modules/node2-impl/src/test/resources/META-INF/sca-contribution.xml23
3 files changed, 105 insertions, 77 deletions
diff --git a/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java b/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
index fc16257bff..835829db1a 100644
--- a/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
+++ b/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
@@ -51,7 +51,6 @@ import org.apache.tuscany.sca.assembly.xml.CompositeDocumentProcessor;
import org.apache.tuscany.sca.contribution.Artifact;
import org.apache.tuscany.sca.contribution.Contribution;
import org.apache.tuscany.sca.contribution.ContributionFactory;
-import org.apache.tuscany.sca.contribution.ContributionMetadata;
import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
@@ -101,8 +100,6 @@ public class NodeImpl implements SCANode2, SCAClient {
private Monitor monitor;
private List<Contribution> contributions;
- private ContributionMetadata metadata;
-
// The composite loaded into this node
private Composite composite;
@@ -168,12 +165,20 @@ public class NodeImpl implements SCANode2, SCAClient {
}
}
+ /**
+ * Discover the contribution on the classpath
+ * @param compositeURI
+ * @param classLoader
+ * @return A configured node implementation
+ * @throws Exception
+ */
private ConfiguredNodeImplementation findNodeConfiguration(final String compositeURI, ClassLoader classLoader)
throws Exception {
NodeImplementationFactory nodeImplementationFactory =
modelFactories.getFactory(NodeImplementationFactory.class);
ConfiguredNodeImplementation config = nodeImplementationFactory.createConfiguredNodeImplementation();
+ // Default to thread context classloader
if (classLoader == null) {
classLoader = Thread.currentThread().getContextClassLoader();
}
@@ -188,43 +193,25 @@ public class NodeImpl implements SCANode2, SCAClient {
Composite composite = createComposite(compositeURI);
config.setComposite(composite);
} else {
-
- // Here the SCADomain was started without any reference to a composite file
- // We are going to look for an sca-contribution.xml or sca-contribution-generated.xml
-
- // Look for META-INF/sca-contribution.xml
+ // No composite is specified, tring to search the SCA metadata files
contributionArtifactPath = Contribution.SCA_CONTRIBUTION_META;
- contributionArtifactURL = getResource(classLoader, contributionArtifactPath);
+ contributionArtifactURL = getResource(classLoader, Contribution.SCA_CONTRIBUTION_META);
- // Look for META-INF/sca-contribution-generated.xml
if (contributionArtifactURL == null) {
contributionArtifactPath = Contribution.SCA_CONTRIBUTION_GENERATED_META;
- contributionArtifactURL = getResource(classLoader, contributionArtifactPath);
+ contributionArtifactURL = getResource(classLoader, Contribution.SCA_CONTRIBUTION_GENERATED_META);
}
-
- // Look for META-INF/sca-deployables directory
if (contributionArtifactURL == null) {
contributionArtifactPath = Contribution.SCA_CONTRIBUTION_DEPLOYABLES;
- contributionArtifactURL = getResource(classLoader, contributionArtifactPath);
- } else {
- StAXArtifactProcessor<ContributionMetadata> processor =
- artifactProcessors.getProcessor(ContributionMetadata.class);
- XMLStreamReader reader = inputFactory.createXMLStreamReader(contributionArtifactURL.openStream());
- reader.nextTag();
- metadata = processor.read(reader);
- reader.close();
- if (metadata.getDeployables().isEmpty()) {
- throw new IllegalArgumentException(
- "No deployable composite is declared in " + contributionArtifactPath);
- }
- Composite composite = metadata.getDeployables().get(0);
- config.setComposite(composite);
+ contributionArtifactURL = getResource(classLoader, Contribution.SCA_CONTRIBUTION_DEPLOYABLES);
}
- }
-
- if (contributionArtifactURL == null) {
- throw new IllegalArgumentException(
- "Can't determine contribution deployables. Either specify a composite file, or use an sca-contribution.xml file to specify the deployables.");
+
+ // No contribution can be discovered
+ if (contributionArtifactURL == null) {
+ throw new IllegalArgumentException("No default contribution can be discovered on the classpath");
+ }
+
+ // No composite will be created, all deployable composites will be used later
}
Contribution c = getContribution(contributionArtifactURL, contributionArtifactPath);
@@ -314,10 +301,10 @@ public class NodeImpl implements SCANode2, SCAClient {
// Initialize the runtime
initRuntime();
- URI uri = URI.create(compositeURI);
+ URI uri = compositeURI == null ? null : URI.create(compositeURI);
ConfiguredNodeImplementation configuration = null;
if (contributions == null || contributions.length == 0) {
- if (uri.getScheme() != null) {
+ if (uri != null && uri.getScheme() != null) {
throw new IllegalArgumentException("No SCA contributions are provided");
}
configuration = findNodeConfiguration(compositeURI, null);
@@ -328,8 +315,9 @@ public class NodeImpl implements SCANode2, SCAClient {
modelFactories.getFactory(NodeImplementationFactory.class);
configuration = nodeImplementationFactory.createConfiguredNodeImplementation();
- Composite composite = createComposite(compositeURI);
+ Composite composite = compositeURI == null ? null : createComposite(compositeURI);
configuration.setComposite(composite);
+
// Create contribution models
ContributionFactory contributionFactory = modelFactories.getFactory(ContributionFactory.class);
@@ -498,32 +486,14 @@ public class NodeImpl implements SCANode2, SCAClient {
composite = configuration.getComposite();
- // Resolve the metadata within the context of the contribution
- // FIXME The deployable composite should have been picked by the SCA Domain Manager already and we should not
- // pollute the Node impl to deal with this
- if (metadata != null) {
- StAXArtifactProcessor<ContributionMetadata> processor =
- artifactProcessors.getProcessor(ContributionMetadata.class);
+ // FIXME: This is a hack to get a list of deployable composites. By design, the deployment composite should
+ // has been configured
+ if (composite == null) {
+ List<Composite> deployables = new ArrayList<Composite>();
for (Contribution c : contributions) {
- processor.resolve(metadata, c.getModelResolver());
- if (!metadata.isUnresolved()) {
- break;
- }
- }
- List<Composite> composites = metadata.getDeployables();
- if (composites.size() == 0) {
- throw new IllegalArgumentException("No deployable composite is declared");
- } else if (composites.size() == 1) {
- composite = composites.get(0);
- } else {
- // This is temporary to include all composites
- AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
- Composite tempComposite = assemblyFactory.createComposite();
- tempComposite.setName(new QName("http://tempuri.org", "aggregated"));
- tempComposite.setURI("http://tempuri.org/aggregated");
- tempComposite.getIncludes().addAll(composites);
- composite = tempComposite;
+ deployables.addAll(c.getDeployables());
}
+ aggregate(deployables);
configuration.setComposite(composite);
}
@@ -592,6 +562,26 @@ public class NodeImpl implements SCANode2, SCAClient {
}
/**
+ * Create a deployment composite that includes a list of deployable composites
+ * @param composites
+ */
+ private void aggregate(List<Composite> composites) {
+ if (composites.size() == 0) {
+ throw new IllegalArgumentException("No deployable composite is declared");
+ } else if (composites.size() == 1) {
+ composite = composites.get(0);
+ } else {
+ // Include all composites
+ AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
+ Composite aggregated = assemblyFactory.createComposite();
+ aggregated.setName(new QName("http://tempuri.org", "aggregated"));
+ aggregated.setURI("http://tempuri.org/aggregated");
+ aggregated.getIncludes().addAll(composites);
+ composite = aggregated;
+ }
+ }
+
+ /**
* Returns the artifact representing the given composite.
*
* @param contribution
diff --git a/java/sca/modules/node2-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java b/java/sca/modules/node2-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
index bdf3dfca4f..38fe211e7d 100644
--- a/java/sca/modules/node2-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
+++ b/java/sca/modules/node2-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
@@ -48,24 +48,33 @@ public class NodeImplTestCase {
@Test
public void testNodeWithCompositeContent() {
SCANode2Factory factory = new NodeFactoryImpl();
- SCAContribution contribution = new SCAContribution("c1", new File("target/classes").toURI().toString());
+ SCAContribution contribution = new SCAContribution("c1", new File("target/test-classes").toURI().toString());
SCANode2 node = factory.createSCANode("HelloWorld.composite", composite, contribution);
- node.start();
- HelloWorld hw = ((SCAClient)node).getService(HelloWorld.class, "HelloWorld");
- Assert.assertEquals("Hello, Node", hw.hello("Node"));
- node.stop();
+ testNode(node);
}
+
+ @Test
+ public void testNodeWithCompositeContentAndNoContribution() {
+ SCANode2Factory factory = new NodeFactoryImpl();
+ SCANode2 node = factory.createSCANode("HelloWorld.composite", composite);
+ testNode(node);
+ }
@Test
+ public void testNodeWithoutCompositeURI() {
+ SCANode2Factory factory = new NodeFactoryImpl();
+ SCAContribution contribution = new SCAContribution("c1", new File("target/test-classes").toURI().toString());
+ SCANode2 node = factory.createSCANode(null, contribution);
+ testNode(node);
+ }
+
+ @Test
public void testNodeWithCompositeURI() {
SCANode2Factory factory = new NodeFactoryImpl();
- SCAContribution contribution = new SCAContribution("c1", new File("target/classes").toURI().toString());
+ SCAContribution contribution = new SCAContribution("c1", new File("target/test-classes").toURI().toString());
String compositeURI = new File("target/test-classes/HelloWorld.composite").toURI().toString();
SCANode2 node = factory.createSCANode(compositeURI, contribution);
- node.start();
- HelloWorld hw = ((SCAClient)node).getService(HelloWorld.class, "HelloWorld");
- Assert.assertEquals("Hello, Node", hw.hello("Node"));
- node.stop();
+ testNode(node);
}
@Test
@@ -74,10 +83,7 @@ public class NodeImplTestCase {
SCAContribution contribution = new SCAContribution("c1", new File("target/test-classes").toURI().toString());
String compositeURI = "HelloWorld.composite";
SCANode2 node = factory.createSCANode(compositeURI, contribution);
- node.start();
- HelloWorld hw = ((SCAClient)node).getService(HelloWorld.class, "HelloWorld");
- Assert.assertEquals("Hello, Node", hw.hello("Node"));
- node.stop();
+ testNode(node);
}
@Test
@@ -85,10 +91,7 @@ public class NodeImplTestCase {
SCANode2Factory factory = new NodeFactoryImpl();
String compositeURI = "HelloWorld.composite";
SCANode2 node = factory.createSCANode(compositeURI, new SCAContribution[0]);
- node.start();
- HelloWorld hw = ((SCAClient)node).getService(HelloWorld.class, "HelloWorld");
- Assert.assertEquals("Hello, Node", hw.hello("Node"));
- node.stop();
+ testNode(node);
}
@Test
@@ -96,9 +99,21 @@ public class NodeImplTestCase {
SCANode2Factory factory = new NodeFactoryImpl();
String compositeURI = "HelloWorld.composite";
SCANode2 node = factory.createSCANodeFromClassLoader(compositeURI, HelloWorld.class.getClassLoader());
+ testNode(node);
+ }
+
+ @Test
+ public void testNodeWithClassLoaderAndNullComposite() {
+ SCANode2Factory factory = new NodeFactoryImpl();
+ SCANode2 node = factory.createSCANodeFromClassLoader(null, HelloWorld.class.getClassLoader());
+ testNode(node);
+ }
+
+ private void testNode(SCANode2 node) {
node.start();
HelloWorld hw = ((SCAClient)node).getService(HelloWorld.class, "HelloWorld");
Assert.assertEquals("Hello, Node", hw.hello("Node"));
node.stop();
}
+
}
diff --git a/java/sca/modules/node2-impl/src/test/resources/META-INF/sca-contribution.xml b/java/sca/modules/node2-impl/src/test/resources/META-INF/sca-contribution.xml
new file mode 100644
index 0000000000..1d37bcebe0
--- /dev/null
+++ b/java/sca/modules/node2-impl/src/test/resources/META-INF/sca-contribution.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+* 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.
+-->
+
+<contribution xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:sc="http://sample/composite">
+ <deployable composite="sc:HelloWorld" />
+</contribution>