summaryrefslogtreecommitdiffstats
path: root/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/Domain.java
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/Domain.java')
-rw-r--r--sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/Domain.java145
1 files changed, 145 insertions, 0 deletions
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
new file mode 100644
index 0000000000..a8625e91a2
--- /dev/null
+++ b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/Domain.java
@@ -0,0 +1,145 @@
+/*
+ * 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 java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+
+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
+ * from the domain ragistry
+ *
+ */
+@Service(Domain.class)
+public class Domain implements Servlet {
+ public String getDomainComposite(){
+ NodeImpl node = (NodeImpl)Tuscany.node;
+ String domainComposite = node.dumpDomainComposite();
+ return domainComposite;
+ }
+
+ public String getComponent(){
+ NodeImpl node = (NodeImpl)Tuscany.node;
+ String domainComposite = node.dumpDomainComposite();
+ return domainComposite;
+ }
+
+ public void init(ServletConfig config) throws ServletException {
+ }
+
+ public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
+ HttpServletRequest httpRequest = (HttpServletRequest)request;
+ ServletOutputStream os = response.getOutputStream();
+
+ String pathInfo = httpRequest.getPathInfo();
+
+ if (pathInfo == null || pathInfo.length() < 1){
+ os.print("<html><body><p>URL should include at least a domain name, e.g. http://localhost/sca/mydomain</body></html>");
+ return;
+ }
+
+ pathInfo = pathInfo.substring(1);
+ 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("<html><body>");
+
+ if ( action.equals("composite")){
+ String domainComposite = getDomainComposite();
+ domainComposite = domainComposite.replaceAll("<", "&lt;");
+ domainComposite = domainComposite.replaceAll(">", "&gt;");
+ os.print("<html><body><p>" + domainComposite + "</body></html>");
+ return;
+ } else {
+ try {
+ File domainDir = new File("target/test-classes/" + domainName);
+
+ URI domainDirURI = domainDir.toURI();
+ URI domainResourceURI = domainDirURI.resolve(pathInfo);
+
+ os.print("<p/>contributions");
+
+ for (File subDir : domainDir.listFiles()){
+ if (!subDir.isDirectory()){
+ os.print("<p/><a href=\"" + subDir.toURI().toString() + "\">" + subDir.getName());
+ }
+ }
+
+ os.print("<p/>nodes");
+ os.print("<p/><a href=\"" + domainName + "/composite\">domainComposite</a>");
+
+ os.print("</body></html>");
+
+ return;
+ } catch (Exception ex){
+ ex.printStackTrace();
+ }
+ }
+
+ os.print("<html><body><p>no processing</body></html>");
+
+ }
+
+ public void destroy() {
+ }
+
+ public ServletConfig getServletConfig() {
+ return null;
+ }
+
+ public String getServletInfo() {
+ return null;
+ }
+
+ public void writeResource(ServletOutputStream os, URL url) throws Exception {
+ URLConnection connection = url.openConnection();
+ connection.setUseCaches(false);
+
+ InputStream is = connection.getInputStream();
+ int aChar;
+ while(( aChar = is.read()) != -1){
+ os.write(aChar);
+ }
+ }
+
+} \ No newline at end of file