diff options
Diffstat (limited to '')
3 files changed, 0 insertions, 231 deletions
diff --git a/sandbox/sca-cloud-tutorial/expertise-rest-appengine-webapp/src/org/apache/tuscany/expertise/restfull/ExpertRegistry.java b/sandbox/sca-cloud-tutorial/expertise-rest-appengine-webapp/src/org/apache/tuscany/expertise/restfull/ExpertRegistry.java deleted file mode 100644 index 04dc7424a6..0000000000 --- a/sandbox/sca-cloud-tutorial/expertise-rest-appengine-webapp/src/org/apache/tuscany/expertise/restfull/ExpertRegistry.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.expertise.restfull; - -import java.util.List; - -import org.apache.tuscany.expertise.Expert; - -public interface ExpertRegistry { - - void addExpert(Expert expert); - - void removeExpert(Expert expert); - - List<Expert> getExperts(); - - List<Expert> getExpertsByExpertise(String expertise); -}
\ No newline at end of file diff --git a/sandbox/sca-cloud-tutorial/expertise-rest-appengine-webapp/src/org/apache/tuscany/expertise/restfull/ExpertRegistryImpl.java b/sandbox/sca-cloud-tutorial/expertise-rest-appengine-webapp/src/org/apache/tuscany/expertise/restfull/ExpertRegistryImpl.java deleted file mode 100644 index 800dc101a0..0000000000 --- a/sandbox/sca-cloud-tutorial/expertise-rest-appengine-webapp/src/org/apache/tuscany/expertise/restfull/ExpertRegistryImpl.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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.expertise.restfull; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.expertise.Expert; -import org.oasisopen.sca.annotation.Init; -import org.oasisopen.sca.annotation.Service; - -@Service(ExpertRegistry.class) -public class ExpertRegistryImpl implements ExpertRegistry { - private List<Expert> experts = new ArrayList<Expert>(); - - public ExpertRegistryImpl() { - - } - - @Init - public void init() { - Expert expert; - - expert = new Expert(); - expert.setId("1"); - expert.setName("John Smith"); - expert.setLocation("CA"); - expert.getExpertise().add("SOA"); - expert.getExpertise().add("SCA"); - expert.getExpertise().add("WAS"); - - experts.add(expert); - - expert = new Expert(); - expert.setId("2"); - expert.setName("Ken Johnson"); - expert.setLocation("NY"); - expert.getExpertise().add("Search"); - - experts.add(expert); - - expert = new Expert(); - expert.setId("3"); - expert.setName("Mark Smith"); - expert.setLocation("CA"); - expert.getExpertise().add("SCA"); - expert.getExpertise().add("WASCE"); - - experts.add(expert); - } - - public void addExpert(Expert expert) { - experts.add(expert); - } - - public void removeExpert(Expert expert) { - experts.remove(expert); - } - - public List<Expert> getExperts() { - return experts; - } - - public List<Expert> getExpertsByExpertise(String expertise) { - List<Expert> expertsByExpertise = new ArrayList<Expert>(); - - for (Expert expert : experts) { - if (expert.getExpertise().contains(expertise)) { - expertsByExpertise.add(expert); - } - } - - return expertsByExpertise; - } -} diff --git a/sandbox/sca-cloud-tutorial/expertise-rest-appengine-webapp/src/org/apache/tuscany/expertise/restfull/RestfulExpertiseLocator.java b/sandbox/sca-cloud-tutorial/expertise-rest-appengine-webapp/src/org/apache/tuscany/expertise/restfull/RestfulExpertiseLocator.java deleted file mode 100644 index 73828c639f..0000000000 --- a/sandbox/sca-cloud-tutorial/expertise-rest-appengine-webapp/src/org/apache/tuscany/expertise/restfull/RestfulExpertiseLocator.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * 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.expertise.restfull; - -import java.io.IOException; -import java.net.URLDecoder; -import java.util.List; - -import javax.servlet.Servlet; -import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.tuscany.expertise.Expert; -import org.oasisopen.sca.annotation.Reference; -import org.oasisopen.sca.annotation.Scope; -import org.oasisopen.sca.annotation.Service; - -@Service(Servlet.class) -@Scope("COMPOSITE") -public class RestfulExpertiseLocator extends HttpServlet implements Servlet { - - private static final long serialVersionUID = 4021701701436888369L; - - @Reference - protected ExpertRegistry experts; - - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - String path = URLDecoder.decode(getRequestPath(request), "UTF-8"); - String expertise = path.substring(1); - - if (expertise != null && expertise.length() > 0 ) { - printExperts(response.getOutputStream(), experts.getExpertsByExpertise(expertise)); - } else { - printExperts(response.getOutputStream(), experts.getExperts()); - } - - } - - - private void printExperts(ServletOutputStream out, List<Expert> experts) throws IOException { - out.print("<html><body>"); - out.print("<h2>Expertise Locator</h2>"); - - if (experts.size() > 0) { - for (Expert expert: experts) { - out.print("<b>Location:</b> " + expert.getLocation() + " - " + expert.getName() +" ==> "); - for (String expertise : expert.getExpertise()) { - out.print(expertise + ";"); - } - out.print("<br/>"); - } - } else { - out.println("No experts found"); - } - out.print("</body></html>"); - } - - /** - * - * @param request - * @return - */ - private static String getRequestPath(HttpServletRequest request) { - // Get the request path - String contextPath = request.getContextPath(); - String servletPath = request.getServletPath(); - String requestURI = request.getRequestURI(); - - int contextPathLength = request.getContextPath().length(); - int servletPathLenght = servletPath.contains(contextPath) ? servletPath.length() - contextPath.length() : servletPath.length(); - - String requestPath = requestURI.substring(contextPathLength + servletPathLenght); - - if (requestURI.startsWith("/")) { - requestPath = requestPath.substring(1); - } - - return requestPath; - } - - -} |