From 9ea6686aa690c68a7bdc875351c076b69a6f0fb2 Mon Sep 17 00:00:00 2001 From: slaws Date: Wed, 11 May 2011 15:50:08 +0000 Subject: Changes to exercise some of the new functions Ant is adding to the registry git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1101928 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tuscany/sca/domain/interop/Domain.java | 98 +++++++++++++--------- .../tuscany/sca/domain/interop/DomainView.java | 56 +++++++++++++ .../apache/tuscany/sca/domain/interop/Tuscany.java | 27 +----- .../main/resources/META-INF/sca-contribution.xml | 2 +- .../src/main/resources/domain.composite | 2 +- .../src/test/resources/domain1/nodeClient/node.xml | 5 +- .../test/resources/domain1/nodeService/node.xml | 5 +- 7 files changed, 123 insertions(+), 72 deletions(-) create mode 100644 sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/DomainView.java (limited to 'sandbox/slaws') diff --git a/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/Domain.java b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/Domain.java index a8625e91a2..754966b9a3 100644 --- a/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/Domain.java +++ b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/Domain.java @@ -26,6 +26,7 @@ import java.io.InputStream; import java.net.URI; import java.net.URL; import java.net.URLConnection; +import java.util.List; import javax.servlet.Servlet; import javax.servlet.ServletConfig; @@ -35,8 +36,8 @@ import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; +import org.apache.tuscany.sca.impl.NodeImpl; import org.oasisopen.sca.annotation.Service; -import org.apache.tuscany.sca.node.impl.NodeImpl; /** * Some hand crafted HTTP code to help me think about what info is missing @@ -45,16 +46,38 @@ import org.apache.tuscany.sca.node.impl.NodeImpl; */ @Service(Domain.class) public class Domain implements Servlet { + public String getDomainComposite(){ - NodeImpl node = (NodeImpl)Tuscany.node; - String domainComposite = node.dumpDomainComposite(); - return domainComposite; + NodeImpl node = (NodeImpl)DomainView.domainAccessPointNode; + return node.getDomainLevelCompositeAsString(); } + public String getContributions(){ + NodeImpl node = (NodeImpl)DomainView.domainAccessPointNode; + List contributions = node.getInstalledContributionURIs(); + return contributions.toString(); + } + + public String getEndpoints(){ + NodeImpl node = (NodeImpl)DomainView.domainAccessPointNode; + return node.getEndpointRegistry().getEndpoints().toString(); + } + + public String getNodes(String domainName){ + // use the domain on the file system in lieu of info in the registry + File domainDir = new File("target/test-classes/" + domainName); + String nodes = ""; + + for (File subDir : domainDir.listFiles()){ + if (subDir.isDirectory()){ + nodes += subDir.getName() + "\n"; + } + } + return nodes; + } + public String getComponent(){ - NodeImpl node = (NodeImpl)Tuscany.node; - String domainComposite = node.dumpDomainComposite(); - return domainComposite; + return null; } public void init(ServletConfig config) throws ServletException { @@ -75,48 +98,35 @@ public class Domain implements Servlet { String[] pathElements = pathInfo.split("/"); String domainName = pathElements[0]; - String action = "none"; - if (pathElements.length == 2){ - action = pathElements[1]; - } // Just some hand crafted code to help me visualize resources os.print(""); - if ( action.equals("composite")){ - String domainComposite = getDomainComposite(); - domainComposite = domainComposite.replaceAll("<", "<"); - domainComposite = domainComposite.replaceAll(">", ">"); - os.print("

" + domainComposite + ""); - return; - } else { - try { - File domainDir = new File("target/test-classes/" + domainName); - - URI domainDirURI = domainDir.toURI(); - URI domainResourceURI = domainDirURI.resolve(pathInfo); - - os.print("

contributions"); - - for (File subDir : domainDir.listFiles()){ - if (!subDir.isDirectory()){ - os.print("

" + subDir.getName()); - } - } - - os.print("

nodes"); - os.print("

domainComposite"); - - os.print(""); - - return; - } catch (Exception ex){ - ex.printStackTrace(); + if (pathElements.length > 1){ + String action = "none"; + action = pathElements[1]; + + if ( action.equals("composite")){ + os.print(prettyPrintXMLString(getDomainComposite())); + } else if ( action.equals("contribution")){ + os.print(prettyPrintXMLString(getContributions())); + } else if ( action.equals("endpoint")){ + os.print(prettyPrintXMLString(getEndpoints())); + } else if ( action.equals("node")){ + os.print(prettyPrintXMLString(getNodes(domainName))); + } else { + os.print("URL path component " + action + "is invalid"); } + + } else { + os.print("

contributions"); + os.print("

domainComposite"); + os.print("

endpoints"); + os.print("

nodes"); } - os.print("

no processing"); + os.print(""); } @@ -141,5 +151,11 @@ public class Domain implements Servlet { os.write(aChar); } } + + public String prettyPrintXMLString(String inXML){ + return inXML.replaceAll("<", "<").replaceAll(">", ">"); + + // etc. need to read and write a structured version + } } \ No newline at end of file diff --git a/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/DomainView.java b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/DomainView.java new file mode 100644 index 0000000000..882f10756e --- /dev/null +++ b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/DomainView.java @@ -0,0 +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.domain.interop; + +import org.apache.tuscany.sca.Node; +import org.apache.tuscany.sca.TuscanyRuntime; + +/** + * Main class for Tuscany. Just looking at what it means to read config from a directory structure. + * + */ +public class DomainView { + + public static Node domainAccessPointNode = null; + private static Node domainViewNode = null; + + public static void main(String[] args) throws Exception { + String domainName = args[0]; + + TuscanyRuntime tuscanyRuntime = TuscanyRuntime.newInstance(); + + // a node to access the specified domain + domainAccessPointNode = tuscanyRuntime.createNode("uri:" + domainName); + + // a node to run the domain view app. Just starts in the local domain "domainview" + domainViewNode = tuscanyRuntime.createNode("domainview"); + domainViewNode.installContribution("target/classes"); + + System.out.print("Press a key to stop"); + try{ + System.in.read(); + } catch(Exception ex){ + // do nothing + } + + domainViewNode.stop(); + } + +} \ No newline at end of file diff --git a/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/Tuscany.java b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/Tuscany.java index bafd818355..aac7ce7aaa 100644 --- a/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/Tuscany.java +++ b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/Tuscany.java @@ -26,9 +26,8 @@ import java.net.ServerSocket; import java.net.Socket; import java.net.URL; -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; +import org.apache.tuscany.sca.TuscanyRuntime; /** * Main class for Tuscany. Just looking at what it means to read config from a directory structure. @@ -37,7 +36,6 @@ import org.apache.tuscany.sca.node.NodeFactory; public class Tuscany { public static Node node = null; - private static Node domain = null; public static void main(String[] args) throws Exception { String domainName = args[0]; @@ -57,29 +55,13 @@ public class Tuscany { File nodeDirectory = findDirectory(currentDirectory, nodeName); System.out.println("Node: " + nodeDirectory.getPath()); - // start a node with the node configuration -/* don't know how to start the node using the following TuscanyRuntime tuscanyRuntime = TuscanyRuntime.newInstance(); - Node node = tuscanyRuntime.createNodeFromXML(nodeDirectory.getPath() + - File.separator + - "node.xml"); -*/ - NodeFactory nodeFactory = NodeFactory.newInstance(); - - // temporarily use the Tuscany runtime to expose domain services - // for looking at the domain in a RESTful way. Replace with more - // integrated code! - domain = nodeFactory.createNode(new Contribution("domain", "target/classes")); - domain.start(); URL nodeConfigURL = nodeDirectory.toURI().resolve("node.xml").toURL(); - node = nodeFactory.createNode(nodeConfigURL); - + node = tuscanyRuntime.createNodeFromXML(nodeConfigURL.toString()); try { - node.start(); - - // Use ? to provide web access to the domain details. + //node.start(); // for testing we're going to set up a deamon that listens for // a shutdown message on a specified port (well it actually just @@ -111,7 +93,6 @@ public class Tuscany { } finally { node.stop(); - domain.stop(); } } diff --git a/sandbox/slaws/domain-view/src/main/resources/META-INF/sca-contribution.xml b/sandbox/slaws/domain-view/src/main/resources/META-INF/sca-contribution.xml index 370fe9903c..276a1cadcc 100644 --- a/sandbox/slaws/domain-view/src/main/resources/META-INF/sca-contribution.xml +++ b/sandbox/slaws/domain-view/src/main/resources/META-INF/sca-contribution.xml @@ -20,6 +20,6 @@ - + diff --git a/sandbox/slaws/domain-view/src/main/resources/domain.composite b/sandbox/slaws/domain-view/src/main/resources/domain.composite index 316c1693ec..de236611f6 100644 --- a/sandbox/slaws/domain-view/src/main/resources/domain.composite +++ b/sandbox/slaws/domain-view/src/main/resources/domain.composite @@ -20,7 +20,7 @@ + name="domainview"> diff --git a/sandbox/slaws/domain-view/src/test/resources/domain1/nodeClient/node.xml b/sandbox/slaws/domain-view/src/test/resources/domain1/nodeClient/node.xml index 81f82a9590..f6756ad187 100644 --- a/sandbox/slaws/domain-view/src/test/resources/domain1/nodeClient/node.xml +++ b/sandbox/slaws/domain-view/src/test/resources/domain1/nodeClient/node.xml @@ -20,9 +20,8 @@ + uri="http://sample/domain1/nodeClient" + domain="uri:domain1"> diff --git a/sandbox/slaws/domain-view/src/test/resources/domain1/nodeService/node.xml b/sandbox/slaws/domain-view/src/test/resources/domain1/nodeService/node.xml index 2bb0bc7558..38274a1a62 100644 --- a/sandbox/slaws/domain-view/src/test/resources/domain1/nodeService/node.xml +++ b/sandbox/slaws/domain-view/src/test/resources/domain1/nodeService/node.xml @@ -20,9 +20,8 @@ + uri="http://sample/domain1/nodeService" + domain="uri:domain1"> -- cgit v1.2.3