/* * 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("

URL should include at least a domain name, e.g. http://localhost/sca/mydomain"); 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(""); 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(); } } os.print("

no processing"); } 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); } } }