summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--java/sca/itest/contribution-folder/src/test/java/test/ContributionFolderTestCase.java (renamed from java/sca/itest/contribution-folder/src/test/java/ContributionFolderTestCase.java)10
-rw-r--r--java/sca/itest/contribution-zip/src/test/java/org/apache/tuscany/sca/contribution/zip/ContributionZIPTestCase.java111
-rw-r--r--java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/ServletHostHelper.java45
-rw-r--r--java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/ContributionLocationHelper.java61
-rw-r--r--java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java195
-rw-r--r--java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeMain2.java18
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeUtil.java43
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java62
-rw-r--r--java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java4
-rw-r--r--java/sca/samples/calculator/src/test/java/calculator/CalculatorTestCase.java19
10 files changed, 368 insertions, 200 deletions
diff --git a/java/sca/itest/contribution-folder/src/test/java/ContributionFolderTestCase.java b/java/sca/itest/contribution-folder/src/test/java/test/ContributionFolderTestCase.java
index 582b9cf5c1..184738554c 100644
--- a/java/sca/itest/contribution-folder/src/test/java/ContributionFolderTestCase.java
+++ b/java/sca/itest/contribution-folder/src/test/java/test/ContributionFolderTestCase.java
@@ -1,4 +1,4 @@
-
+package test;
import junit.framework.TestCase;
@@ -8,20 +8,18 @@ import org.apache.tuscany.sca.node.NodeFactory;
import calculator.CalculatorService;
-
-
/**
* Test SCADomain.newInstance and invocation of a service.
- *
+ *
* @version $Rev: 608205 $ $Date: 2008-01-02 20:29:05 +0000 (Wed, 02 Jan 2008) $
*/
public class ContributionFolderTestCase extends TestCase {
private Node node;
-
+
@Override
protected void setUp() throws Exception {
- node = NodeFactory.newInstance().createNode(null, new Contribution("foo", "src/test/resources/repository"));
+ node = NodeFactory.newInstance().createNode(new Contribution("foo", "src/test/resources/repository"));
node.start();
}
diff --git a/java/sca/itest/contribution-zip/src/test/java/org/apache/tuscany/sca/contribution/zip/ContributionZIPTestCase.java b/java/sca/itest/contribution-zip/src/test/java/org/apache/tuscany/sca/contribution/zip/ContributionZIPTestCase.java
index 7ad7e98a91..303e2a6d9a 100644
--- a/java/sca/itest/contribution-zip/src/test/java/org/apache/tuscany/sca/contribution/zip/ContributionZIPTestCase.java
+++ b/java/sca/itest/contribution-zip/src/test/java/org/apache/tuscany/sca/contribution/zip/ContributionZIPTestCase.java
@@ -1,55 +1,56 @@
-/*
- * 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.contribution.zip;
-
-import junit.framework.TestCase;
-
-import org.apache.tuscany.sca.node.Contribution;
-import org.apache.tuscany.sca.node.Node;
-import org.apache.tuscany.sca.node.NodeFactory;
-
-import calculator.CalculatorService;
-
-
-/**
- * Test SCADomain.newInstance and invocation of a service.
- *
- * @version $Rev: 608205 $ $Date: 2008-01-02 20:29:05 +0000 (Wed, 02 Jan 2008) $
- */
-public class ContributionZIPTestCase extends TestCase {
-
- private Node node;
-
- @Override
- protected void setUp() throws Exception {
- node = NodeFactory.newInstance().createNode(null, new Contribution("foo", "src/test/resources/repository/contribution.zip"));
- node.start();
- }
-
- public void testInvoke() throws Exception {
- CalculatorService service = node.getService(CalculatorService.class, "CalculatorServiceComponent");
- assertEquals(3.0, service.add(1, 2));
- }
-
- @Override
- protected void tearDown() throws Exception {
- node.stop();
- }
-
-}
+/*
+ * 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.contribution.zip;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+
+import calculator.CalculatorService;
+
+/**
+ * Test SCADomain.newInstance and invocation of a service.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ContributionZIPTestCase extends TestCase {
+
+ private Node node;
+
+ @Override
+ protected void setUp() throws Exception {
+ node =
+ NodeFactory.newInstance().createNode(new Contribution("foo",
+ "src/test/resources/repository/contribution.zip"));
+ node.start();
+ }
+
+ public void testInvoke() throws Exception {
+ CalculatorService service = node.getService(CalculatorService.class, "CalculatorServiceComponent");
+ assertEquals(3.0, service.add(1, 2));
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ node.stop();
+ }
+
+}
diff --git a/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/ServletHostHelper.java b/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/ServletHostHelper.java
index fd6a3ed22b..5fcb453f10 100644
--- a/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/ServletHostHelper.java
+++ b/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/ServletHostHelper.java
@@ -6,24 +6,21 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.host.webapp;
-import java.io.BufferedReader;
import java.io.File;
-import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
@@ -45,7 +42,6 @@ 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.node.impl.NodeImpl;
-import org.oasisopen.sca.ServiceRuntimeException;
public class ServletHostHelper {
private static final Logger logger = Logger.getLogger(ServletHostHelper.class.getName());
@@ -55,7 +51,7 @@ public class ServletHostHelper {
public static void init(ServletConfig servletConfig) {
init(servletConfig.getServletContext());
}
-
+
public static ServletHost init(final ServletContext servletContext) {
Node node = (Node)servletContext.getAttribute(SCA_NODE_ATTRIBUTE);
if (node == null) {
@@ -81,7 +77,7 @@ public class ServletHostHelper {
}
return getServletHost(node);
}
-
+
private static WebAppServletHost getServletHost(Node node) {
NodeImpl nodeImpl = (NodeImpl) node;
ExtensionPointRegistry eps = nodeImpl.getExtensionPoints();
@@ -98,36 +94,17 @@ public class ServletHostHelper {
}
private static Node createNode(final ServletContext servletContext) throws ServletException {
- String contextPath = initContextPath(servletContext);
+ // String contextPath = initContextPath(servletContext);
String contributionRoot = getContributionRoot(servletContext);
NodeFactory factory = NodeFactory.newInstance();
- String webComposite = getWebComposite(servletContext);
- Node node = factory.createNode(contextPath, webComposite, new Contribution(contributionRoot, contributionRoot));
+ InputStream webComposite = getWebComposite(servletContext);
+ Node node = factory.createNode(webComposite, new Contribution(contributionRoot, contributionRoot));
node.start();
return node;
}
-
- private static String getWebComposite(ServletContext servletContext) {
- InputStream stream = servletContext.getResourceAsStream("/WEB-INF/web.composite");
- BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
- StringBuilder sb = new StringBuilder();
- String s = null;
- try {
- while ((s = reader.readLine()) != null) {
- sb.append(s + "\n");
- }
- } catch (IOException e) {
- throw new ServiceRuntimeException(e);
- } finally {
- try {
- stream.close();
- } catch (IOException e) {
- throw new ServiceRuntimeException(e);
- }
- }
-
- return sb.toString();
+ private static InputStream getWebComposite(ServletContext servletContext) {
+ return servletContext.getResourceAsStream("/WEB-INF/web.composite");
}
private static String getContributionRoot(ServletContext servletContext) {
@@ -144,7 +121,7 @@ public class ServletHostHelper {
// ignore exception and use default location
try {
-
+
String root = servletContext.getInitParameter("contributionRoot");
if (root == null || root.length() < 1) {
root = "/";
diff --git a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/ContributionLocationHelper.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/ContributionLocationHelper.java
index 96a25dfa63..f891f1e329 100644
--- a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/ContributionLocationHelper.java
+++ b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/ContributionLocationHelper.java
@@ -6,22 +6,28 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.node;
+import java.io.IOException;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+
+import org.oasisopen.sca.ServiceRuntimeException;
/**
* ContributionLocationHelper
@@ -32,7 +38,7 @@ public class ContributionLocationHelper {
/**
* Returns the location of the SCA contribution containing the given class.
- *
+ *
* @param anchorClass
* @return
*/
@@ -53,6 +59,15 @@ public class ContributionLocationHelper {
*/
public static String getContributionLocation(String resourceName) {
return getContributionLocation(null, resourceName);
+ }
+
+ /**
+ * Find the contribution locations by seraching a resource on the classpath
+ * @param resourceName
+ * @return
+ */
+ public static List<String> getContributionLocations(String resourceName) {
+ return getContributionLocations(null, resourceName);
}
@@ -74,6 +89,32 @@ public class ContributionLocationHelper {
if (resourceURL == null) {
return null;
}
+ return getRootLocation(resourceURL, resourceName);
+ }
+
+ /**
+ * Find the contribution locations by seraching a resource using the given classloader
+ * @param classLoader The classloader that is used to call getResources()
+ * @param resourceName The name of the resource
+ * @return A list of locations that contain the resource
+ */
+ public static List<String> getContributionLocations(ClassLoader classLoader, String resourceName) {
+ if (classLoader == null) {
+ classLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+ public ClassLoader run() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+ Enumeration<URL> resourceURLs = getResources(classLoader, resourceName);
+ List<String> locations = new ArrayList<String>();
+ while (resourceURLs != null && resourceURLs.hasMoreElements()) {
+ locations.add(getRootLocation(resourceURLs.nextElement(), resourceName));
+ }
+ return locations;
+ }
+
+ private static String getRootLocation(URL resourceURL, String resourceName) {
String location = null;
// "jar:file://....../something.jar!/a/b/c/app.composite"
String url = resourceURL.toExternalForm();
@@ -98,4 +139,16 @@ public class ContributionLocationHelper {
});
}
+ private static Enumeration<URL> getResources(final ClassLoader classLoader, final String compositeURI) {
+ return AccessController.doPrivileged(new PrivilegedAction<Enumeration<URL>>() {
+ public Enumeration<URL> run() {
+ try {
+ return classLoader.getResources(compositeURI);
+ } catch (IOException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+ });
+ }
+
}
diff --git a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java
index 1f30045bd1..485c159287 100644
--- a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java
+++ b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java
@@ -19,11 +19,22 @@
package org.apache.tuscany.sca.node;
+import static org.apache.tuscany.sca.node.ContributionLocationHelper.getContributionLocations;
+
+import java.io.IOException;
import java.io.InputStream;
+import java.io.Reader;
import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.List;
import org.apache.tuscany.sca.node.configuration.DefaultNodeConfigurationFactory;
import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
+import org.apache.tuscany.sca.node.configuration.NodeConfigurationFactory;
import org.oasisopen.sca.CallableReference;
import org.oasisopen.sca.ServiceReference;
import org.oasisopen.sca.ServiceRuntimeException;
@@ -35,6 +46,15 @@ import org.oasisopen.sca.ServiceRuntimeException;
* @version $Rev$ $Date$
*/
public abstract class NodeFactory extends DefaultNodeConfigurationFactory {
+ /**
+ * Default location of contribution metadata in an SCA contribution.
+ */
+ private static final String SCA_CONTRIBUTION_META = "META-INF/sca-contribution.xml";
+
+ /**
+ * Default location of a generated contribution metadata in an SCA contribution.
+ */
+ private static final String SCA_CONTRIBUTION_GENERATED_META = "META-INF/sca-contribution-generated.xml";
protected static NodeFactory nodeFactory;
@@ -174,33 +194,109 @@ public abstract class NodeFactory extends DefaultNodeConfigurationFactory {
}
/**
- * Creates a new SCA node using defaults for the contribution location and runnable composite
- *
- * @return a new SCA node.
+ * Open a URL connection without cache
+ * @param url
+ * @return
+ * @throws IOException
+ */
+ private static InputStream openStream(URL url) throws IOException {
+ InputStream is = null;
+ URLConnection connection = url.openConnection();
+ connection.setUseCaches(false);
+ is = connection.getInputStream();
+ return is;
+ }
+
+ /**
+ * Escape the space in URL string
+ * @param uri
+ * @return
*/
- public abstract Node createNode();
+ private static URI createURI(String uri) {
+ int index = uri.indexOf(':');
+ String scheme = null;
+ String ssp = uri;
+ if (index != -1) {
+ scheme = uri.substring(0, index);
+ ssp = uri.substring(index + 1);
+ }
+ try {
+ return new URI(scheme, ssp, null);
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
/**
* Creates a new SCA node from the configuration URL
*
- * @param configurationURL the URL of the node configuration which is the ATOM feed
+ * @param configurationURL the URL of the node configuration which is the XML document
* that contains the URI of the composite and a collection of URLs for the contributions
*
* @return a new SCA node.
*/
- public abstract Node createNode(String configurationURL);
+ public Node createNode(URL configurationURL) {
+ try {
+ InputStream is = openStream(configurationURL);
+ return createNode(is);
+ } catch (IOException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ /**
+ * Creates a new SCA node from the XML configuration of the node
+ * @param is The input stream that the XML configuration can be read. The stream will be closed
+ * after this call.
+ * @return a new SCA node
+ */
+ public Node createNode(InputStream is) {
+ try {
+ NodeConfiguration configuration = loadConfiguration(is);
+ is.close();
+ return createNode(configuration);
+ } catch (IOException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
/**
* Creates a new SCA node.
*
- * @param compositeURI the URI of the composite to use
+ * @param deploymentCompositeURI the URI of the deployment composite. If the URI is relative, it should
+ * be resolved against the first contribution. Otherwise, the absolute URI is used to load the XML
+ * description of the composite. The deployment composite will be attached to the first contribution.
+ *
* @param contributions the URI of the contributions that provides the composites and related
* artifacts. If the list is empty, then we will use the thread context classloader to discover
* the contribution on the classpath
*
* @return a new SCA node.
*/
- public abstract Node createNode(String compositeURI, Contribution... contributions);
+ public Node createNode(String deploymentCompositeURI, Contribution... contributions) {
+ if (contributions == null || contributions.length == 0) {
+ if (deploymentCompositeURI == null || deploymentCompositeURI.indexOf(':') != -1) {
+ throw new ServiceRuntimeException("No SCA contribution is provided or discovered");
+ }
+ // Try to find contributions on the classpath by the composite URI
+ contributions = getContributions(getContributionLocations(null, deploymentCompositeURI));
+ }
+ NodeConfiguration configuration = createConfiguration(contributions);
+ if (deploymentCompositeURI != null && configuration.getContributions().size() > 0) {
+ configuration.getContributions().get(0).addDeploymentComposite(createURI(deploymentCompositeURI));
+ }
+ return createNode(configuration);
+ }
+
+ /**
+ * Create a new SCA node using the list of SCA contributions
+ * @param contributions
+ * @return
+ */
+ public Node createNode(Contribution... contributions) {
+ NodeConfiguration configuration = createConfiguration(contributions);
+ return createNode(configuration);
+ }
/**
* Creates a new SCA node.
@@ -209,8 +305,87 @@ public abstract class NodeFactory extends DefaultNodeConfigurationFactory {
* @param compositeContent the XML content of the composite to use
* @param contributions the URI of the contributions that provides the composites and related artifacts
* @return a new SCA node.
+ *
+ * @deprecated Please use createNode(InputStream compositeContent, Contribution... contributions) or
+ * createNode(Reader compositeContent, Contribution... contributions)
+ */
+ @Deprecated
+ public Node createNode(String compositeURI, String compositeContent, Contribution... contributions) {
+ NodeConfiguration configuration = createConfiguration(contributions);
+ if (compositeContent != null && configuration.getContributions().size() > 0) {
+ configuration.getContributions().get(0).addDeploymentComposite(compositeContent);
+ }
+ return createNode(configuration);
+ }
+
+ /**
+ * Creates a new SCA node.
+ *
+ * @param compositeContent the XML content of the deployment composite
+ * @param contributions the URI of the contributions that provides the composites and related artifacts
+ * @return a new SCA node.
+ */
+ public Node createNode(InputStream compositeContent, Contribution... contributions) {
+ NodeConfiguration configuration = createConfiguration(contributions);
+ if (compositeContent != null && configuration.getContributions().size() > 0) {
+ configuration.getContributions().get(0).addDeploymentComposite(compositeContent);
+ }
+ return createNode(configuration);
+ }
+
+ /**
+ * Creates a new SCA node.
+ *
+ * @param compositeContent the XML content of the deployment composite
+ * @param contributions the URI of the contributions that provides the composites and related artifacts
+ * @return a new SCA node.
*/
- public abstract Node createNode(String compositeURI, String compositeContent, Contribution... contributions);
+ public Node createNode(Reader compositeContent, Contribution... contributions) {
+ NodeConfiguration configuration = createConfiguration(contributions);
+ if (compositeContent != null && configuration.getContributions().size() > 0) {
+ configuration.getContributions().get(0).addDeploymentComposite(compositeContent);
+ }
+ return createNode(configuration);
+ }
+
+ private NodeConfiguration createConfiguration(Contribution... contributions) {
+ NodeConfigurationFactory factory = this;
+ NodeConfiguration configuration = factory.createNodeConfiguration();
+ if (contributions != null) {
+ for (Contribution c : contributions) {
+ configuration.addContribution(c.getURI(), c.getLocation());
+ }
+ }
+ return configuration;
+ }
+
+ /**
+ * Creates a new SCA node using defaults for the contribution location and deployable composites.
+ * By default, it uses the Thread context classloader to find META-INF/sca-contribution.xml or
+ * META-INF/sca-contribution-generated.xml on the classpath. The locations that contain such resources
+ * are taken as the SCA contributions.
+ *
+ * @return a new SCA node.
+ */
+ public Node createNode() {
+ List<String> locations = new ArrayList<String>();
+ locations.addAll(getContributionLocations(null, SCA_CONTRIBUTION_META));
+ locations.addAll(getContributionLocations(null, SCA_CONTRIBUTION_GENERATED_META));
+ Contribution[] contributions = getContributions(locations);
+ return createNode(contributions);
+ }
+
+ private Contribution[] getContributions(List<String> locations) {
+ if (locations.isEmpty()) {
+ throw new ServiceRuntimeException("No SCA contributions are found on the classpath");
+ }
+ Contribution[] contributions = new Contribution[locations.size()];
+ int index = 0;
+ for (String location : locations) {
+ contributions[index++] = new Contribution(location, location);
+ }
+ return contributions;
+ }
/**
* Create a new SCA node based on the configuration
@@ -225,4 +400,6 @@ public abstract class NodeFactory extends DefaultNodeConfigurationFactory {
* @return The node configuration
*/
public abstract NodeConfiguration loadConfiguration(InputStream xml);
+
+
}
diff --git a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeMain2.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeMain2.java
index 6c26db5a25..9bbf77a2a9 100644
--- a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeMain2.java
+++ b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeMain2.java
@@ -6,15 +6,15 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.node;
@@ -24,13 +24,13 @@ import java.io.File;
public class NodeMain2 {
/**
- * Start an SCA node
+ * Start an SCA node
* @param args a list of contribution jars for the node to run
*/
public static void main(String[] args) throws Exception {
Contribution[] contributions = new Contribution[args.length];
- for (int i=0; i<args.length; i++) {
+ for (int i = 0; i < args.length; i++) {
File f = new File(args[i]);
if (!f.exists()) {
System.err.println("contribution not found: " + f);
@@ -39,18 +39,18 @@ public class NodeMain2 {
contributions[i] = new Contribution(f.toURI().toString(), f.toURI().toString());
}
- Node node = NodeFactory.newInstance().createNode(null, contributions);
- node.start();
-
+ Node node = NodeFactory.newInstance().createNode(contributions).start();
+
System.out.println("Hit enter to stop node...");
if (System.in.read() == -1) {
// no sysin so wait for ever letting caller do the terminate
Object lock = new Object();
- synchronized(lock) {
+ synchronized (lock) {
lock.wait();
}
}
node.stop();
+ node.destroy();
}
}
diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeUtil.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeUtil.java
index 63324bf4c4..b944e01095 100644
--- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeUtil.java
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeUtil.java
@@ -6,21 +6,25 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.node.osgi.impl;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.URI;
-import java.util.logging.Logger;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
import org.apache.tuscany.sca.contribution.Contribution;
import org.apache.tuscany.sca.contribution.ContributionFactory;
@@ -31,7 +35,8 @@ import org.apache.tuscany.sca.contribution.ContributionFactory;
* @version $Rev: $ $Date: $
*/
public class NodeUtil {
- private static final Logger logger = Logger.getLogger(NodeFactoryImpl.class.getName());
+ private NodeUtil() {
+ }
static Contribution contribution(ContributionFactory contributionFactory, org.apache.tuscany.sca.node.Contribution c) {
Contribution contribution = contributionFactory.createContribution();
@@ -42,15 +47,37 @@ public class NodeUtil {
}
/**
+ * Open a URL connection without cache
+ * @param url
+ * @return
+ * @throws IOException
+ */
+ static InputStream openStream(URL url) throws IOException {
+ InputStream is = null;
+ URLConnection connection = url.openConnection();
+ connection.setUseCaches(false);
+ is = connection.getInputStream();
+ return is;
+ }
+
+ /**
* Escape the space in URL string
* @param uri
* @return
*/
static URI createURI(String uri) {
- if (uri.indexOf(' ') != -1) {
- uri = uri.replace(" ", "%20");
+ int index = uri.indexOf(':');
+ String scheme = null;
+ String ssp = uri;
+ if (index != -1) {
+ scheme = uri.substring(0, index);
+ ssp = uri.substring(index + 1);
+ }
+ try {
+ return new URI(scheme, ssp, null);
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException(e);
}
- return URI.create(uri);
}
}
diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java
index 38376a584f..24836c67fb 100644
--- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java
+++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java
@@ -19,11 +19,7 @@
package org.apache.tuscany.sca.node.impl;
-import static org.apache.tuscany.sca.node.impl.NodeUtil.openStream;
-
-import java.io.IOException;
import java.io.InputStream;
-import java.net.URL;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
@@ -31,12 +27,9 @@ import javax.xml.stream.XMLStreamReader;
import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
-import org.apache.tuscany.sca.node.Contribution;
-import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
-import org.apache.tuscany.sca.node.configuration.NodeConfigurationFactory;
import org.apache.tuscany.sca.node.configuration.xml.NodeConfigurationProcessor;
import org.oasisopen.sca.ServiceRuntimeException;
@@ -50,61 +43,6 @@ public class NodeFactoryImpl extends NodeFactory {
}
@Override
- public Node createNode(String configurationURI) {
- try {
- URL url = new URL(configurationURI);
- InputStream is = openStream(url);
- NodeConfiguration configuration = loadConfiguration(is);
- is.close();
- return new NodeImpl(configuration);
- } catch (IOException e) {
- throw new ServiceRuntimeException(e);
- }
- }
-
- @Override
- public Node createNode(String compositeURI, Contribution... contributions) {
- NodeConfigurationFactory factory = this;
- NodeConfiguration configuration = factory.createNodeConfiguration();
- for (Contribution c : contributions) {
- configuration.addContribution(c.getURI(), c.getLocation());
- }
- if (compositeURI != null && configuration.getContributions().size() > 0) {
- configuration.getContributions().get(0).addDeploymentComposite(NodeUtil.createURI(compositeURI));
- }
- return new NodeImpl(configuration);
- }
-
- @Override
- public Node createNode(String compositeURI, String compositeContent, Contribution... contributions) {
- NodeConfigurationFactory factory = this;
- NodeConfiguration configuration = factory.createNodeConfiguration();
- for (Contribution c : contributions) {
- configuration.addContribution(c.getURI(), c.getLocation());
- }
- if (compositeContent != null && configuration.getContributions().size() > 0) {
- configuration.getContributions().get(0).addDeploymentComposite(compositeContent);
- }
- return new NodeImpl(configuration);
- }
-
- @Override
- public Node createNode() {
- String location =
- ContributionLocationHelper
- .getContributionLocation(org.apache.tuscany.sca.contribution.Contribution.SCA_CONTRIBUTION_META);
- if (location == null) {
- location =
- ContributionLocationHelper
- .getContributionLocation(org.apache.tuscany.sca.contribution.Contribution.SCA_CONTRIBUTION_GENERATED_META);
- }
- if (location == null) {
- throw new ServiceRuntimeException("No SCA contributions are found on the classpath");
- }
- return createNode(null, new Contribution("http://contributions/default", location));
- }
-
- @Override
public Node createNode(NodeConfiguration configuration) {
return new NodeImpl(configuration);
}
diff --git a/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java b/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
index 877e4e3643..da869e78e6 100644
--- a/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
+++ b/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
@@ -22,6 +22,7 @@ package org.apache.tuscany.sca.node.impl;
import hello.HelloWorld;
import java.io.File;
+import java.io.StringReader;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
@@ -47,8 +48,7 @@ public class NodeImplTestCase {
public void testNodeWithCompositeContent() {
NodeFactory factory = new NodeFactoryImpl();
Contribution contribution = new Contribution("c1", new File("target/test-classes").toURI().toString());
- String compositeURI = "HelloWorld.composite";
- Node node = factory.createNode(compositeURI, composite, contribution);
+ Node node = factory.createNode(new StringReader(composite), contribution);
testNode2(node);
}
diff --git a/java/sca/samples/calculator/src/test/java/calculator/CalculatorTestCase.java b/java/sca/samples/calculator/src/test/java/calculator/CalculatorTestCase.java
index 27a424b1cc..73c7d872b9 100644
--- a/java/sca/samples/calculator/src/test/java/calculator/CalculatorTestCase.java
+++ b/java/sca/samples/calculator/src/test/java/calculator/CalculatorTestCase.java
@@ -6,15 +6,15 @@
* 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.
+ * under the License.
*/
package calculator;
@@ -28,25 +28,22 @@ import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.oasisopen.sca.annotation.EagerInit;
-import org.oasisopen.sca.annotation.Scope;
/**
* This shows how to test the Calculator service component.
*/
-@Scope("COMPOSITE") @EagerInit
public class CalculatorTestCase{
- private static Node node;
+ private static Node node;
private static CalculatorService calculatorService;
-
+
@BeforeClass
public static void setUpBeforeClass() throws Exception {
NodeFactory factory = NodeFactory.newInstance();
String contribution = ContributionLocationHelper.getContributionLocation(CalculatorClient.class);
- node = factory.createNode("Calculator.composite", new Contribution("calculator", contribution));
- node.start();
-
+ node = factory.createNode("Calculator.composite", new Contribution("calculator", contribution)).start();
+ // node = factory.createNode().start();
+
calculatorService = ((Client)node).getService(CalculatorService.class, "CalculatorServiceComponent");
}