From 9425990f532b1152c2d73db96c0f07ef5216a3d1 Mon Sep 17 00:00:00 2001 From: lresende Date: Thu, 12 Nov 2009 00:43:48 +0000 Subject: Moving 2.x contribs git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835178 13f79535-47bb-0310-9956-ffa450edef68 --- .../binding-rest-runtime/META-INF/MANIFEST.MF | 18 -- .../modules/binding-rest-runtime/pom.xml | 154 ------------------ .../sca/binding/rest/RESTBindingForJersey.java | 181 --------------------- .../binding/rest/provider/RESTBindingInvoker.java | 45 ----- .../rest/provider/RESTBindingProviderFactory.java | 64 -------- .../provider/RESTReferenceBindingProvider.java | 70 -------- .../rest/provider/RESTServiceBindingProvider.java | 148 ----------------- .../binding/rest/provider/RESTServiceServlet.java | 138 ---------------- ...che.tuscany.sca.provider.BindingProviderFactory | 19 --- 9 files changed, 837 deletions(-) delete mode 100644 java/sca-contrib/modules/binding-rest-runtime/META-INF/MANIFEST.MF delete mode 100644 java/sca-contrib/modules/binding-rest-runtime/pom.xml delete mode 100644 java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/RESTBindingForJersey.java delete mode 100644 java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingInvoker.java delete mode 100644 java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingProviderFactory.java delete mode 100644 java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTReferenceBindingProvider.java delete mode 100644 java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java delete mode 100644 java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceServlet.java delete mode 100644 java/sca-contrib/modules/binding-rest-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory (limited to 'java/sca-contrib/modules/binding-rest-runtime') diff --git a/java/sca-contrib/modules/binding-rest-runtime/META-INF/MANIFEST.MF b/java/sca-contrib/modules/binding-rest-runtime/META-INF/MANIFEST.MF deleted file mode 100644 index 41ae005380..0000000000 --- a/java/sca-contrib/modules/binding-rest-runtime/META-INF/MANIFEST.MF +++ /dev/null @@ -1,18 +0,0 @@ -Manifest-Version: 1.0 -Export-Package: org.apache.tuscany.sca.binding.rest.runtime;version="2.0.0";uses:="org.apache.tuscany.sca.assembly" -Tool: Bnd-0.0.255 -Bundle-Name: Apache Tuscany SCA REST Binding Runtime -Created-By: 1.6.0_07 (Sun Microsystems Inc.) -Bundle-Vendor: The Apache Software Foundation -Bundle-Version: 2.0.0 -Bnd-LastModified: 1225397320062 -Bundle-ManifestVersion: 2 -Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt -Bundle-Description: Apache Tuscany SCA REST Binding Model -Import-Package: org.apache.tuscany.sca.assembly;version="2.0.0", - org.apache.tuscany.sca.assembly.xml;version="2.0.0";resolution:=optional, - org.apache.tuscany.sca.binding.jsonp.runtime;version="2.0.0", - org.apache.tuscany.sca.binding.jsonp;version="2.0.0" -Bundle-SymbolicName: org.apache.tuscany.sca.binding.rest.runtime -Bundle-DocURL: http://www.apache.org/ -Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6 diff --git a/java/sca-contrib/modules/binding-rest-runtime/pom.xml b/java/sca-contrib/modules/binding-rest-runtime/pom.xml deleted file mode 100644 index 5fb8fb12e2..0000000000 --- a/java/sca-contrib/modules/binding-rest-runtime/pom.xml +++ /dev/null @@ -1,154 +0,0 @@ - - - - 4.0.0 - - org.apache.tuscany.sca - tuscany-modules - 2.0-SNAPSHOT - ../pom.xml - - - tuscany-binding-rest-runtime - Apache Tuscany SCA REST Binding Runtime - - - - maven2-repository.dev.java.net - Java.net Repository for Maven - http://download.java.net/maven/2/ - default - - - maven-repository.dev.java.net - Java.net Maven 1 Repository (legacy) - http://download.java.net/maven/1 - legacy - - - - - org.apache.tuscany.sca - tuscany-binding-rest - 2.0-SNAPSHOT - - - com.sun.jersey - jersey-bundle - 1.0.3 - compile - - - org.apache.tuscany.sca - tuscany-core-spi - 2.0-SNAPSHOT - - - - org.apache.tuscany.sca - tuscany-core - 2.0-SNAPSHOT - - - - org.apache.tuscany.sca - tuscany-databinding - 2.0-SNAPSHOT - - - - org.apache.tuscany.sca - tuscany-host-http - 2.0-SNAPSHOT - - - - org.apache.tuscany.sca - tuscany-host-webapp - 2.0-SNAPSHOT - - - - org.apache.tuscany.sca - tuscany-host-jetty - 2.0-SNAPSHOT - test - - - - javax.servlet - servlet-api - 2.5 - provided - - - - commons-logging - commons-logging - 1.1.1 - - - commons-logging - commons-logging - - - javax.servlet - servlet-api - - - - - - - - org.apache.tuscany.sca - tuscany-node-impl - 2.0-SNAPSHOT - test - - - - org.apache.tuscany.sca - tuscany-implementation-java-runtime - 2.0-SNAPSHOT - test - - - - junit - junit - 4.5 - test - - - - httpunit - httpunit - 1.6.1 - test - - - - - - - - - diff --git a/java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/RESTBindingForJersey.java b/java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/RESTBindingForJersey.java deleted file mode 100644 index c25a629829..0000000000 --- a/java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/RESTBindingForJersey.java +++ /dev/null @@ -1,181 +0,0 @@ -package org.apache.tuscany.sca.binding.rest; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.binding.rest.provider.RESTServiceServlet; - -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.runtime.RuntimeComponentService; -import org.apache.tuscany.sca.runtime.RuntimeWire; - -import com.sun.jersey.tuscany.common.CommonInterface; - -public class RESTBindingForJersey implements CommonInterface{ - - /** - * This map will save the mappings between the serviceInterface - * and the HttpServlet instance which will be passed by RESTServiceServlet - * - */ - private static HashMap interfacenameServletMap = new HashMap(); - - /** - * This is used to store the contextPath for the web application. - * It will be set in RESTServiceServlet - * It is currently being used by org.apache.tuscany.sca.implementation.java.invocation.JavaImplementationInvoker - * - */ - private static String contextPath; - - /** - * updateInterfacenameServletMap() is called from RESTServiceServlet. - */ - public static void updateInterfacenameServletMap(String interfaceName, RESTServiceServlet restServiceServlet){ - - //check if the class name already exists. if it does, do not add it. - Set set = interfacenameServletMap.entrySet(); - Iterator hashIt = set.iterator(); - boolean classFoundFlag = false; - while(hashIt.hasNext()){ - Map.Entry me = (Map.Entry)hashIt.next(); - if(interfaceName.equals( (String)me.getKey() )){ - classFoundFlag = true; - } - } - - //if it is not already in map, add it to the map - if(classFoundFlag == false){ - interfacenameServletMap.put(interfaceName, restServiceServlet); - } - - } - - /** - * @param clazz The class whose method has been invoked - * @return restServiceServlet - * Find the matching interface for the class in the hashMap and return the corresponding RESTServiceServlet instance - */ - public static RESTServiceServlet findRESTServiceServletFromClass(Class clazz){ - RESTServiceServlet restServiceServlet = null; - Set set = interfacenameServletMap.entrySet(); - Iterator hashIt = set.iterator(); - while(hashIt.hasNext()){ - Map.Entry me = (Map.Entry)hashIt.next(); - if( (clazz.getSimpleName()).equals( (String)me.getKey() ) ) - { - restServiceServlet = (RESTServiceServlet)me.getValue(); - break; - } - } - return restServiceServlet; - } - - /** - * @param interfaceList This will contain the list of all the interfaces the class (which declares the method) implements - * @return restServiceServlet - * Go through the interfaceList array and find the matching interface in the hashMap and return the corresponding RESTServiceServlet instance - */ - - public static RESTServiceServlet findRESTServiceServletFromInterfaceList(Class[] interfaceList){ - RESTServiceServlet restServiceServlet = null; - Set set = interfacenameServletMap.entrySet(); - Iterator hashIt = set.iterator(); - //label the outer for loop so that when a match is found, just break out of the whole thing - outerForLoop: - for(int i=0; i operations = serviceContract.getInterface().getOperations(); - //componentService.getBindingProvider(binding).getBindingInterfaceContract().getInterface().getOperations(); - - - Operation result = null; - for (Operation o : operations) { - if (o.getName().equalsIgnoreCase(method)) { - result = o; - break; - } - } - - return result; - } - - public static String getContextPath() { - return contextPath; - } - - public static void setContextPath(String contextPath) { - RESTBindingForJersey.contextPath = contextPath; - } - -} - diff --git a/java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingInvoker.java b/java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingInvoker.java deleted file mode 100644 index 9b3f78133d..0000000000 --- a/java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingInvoker.java +++ /dev/null @@ -1,45 +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.sca.binding.rest.provider; - -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.invocation.Invoker; -import org.apache.tuscany.sca.invocation.Message; - -/** - * Invoker for the REST Binding - * - * @version $Rev: 665897 $ $Date: 2008-06-09 22:31:03 +0100 (Mon, 09 Jun 2008) $ - */ -public class RESTBindingInvoker implements Invoker { - Operation operation; - String uri; - - public RESTBindingInvoker(Operation operation, String uri) { - this.operation = operation; - this.uri = uri; - } - - public Message invoke(Message msg) { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingProviderFactory.java b/java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingProviderFactory.java deleted file mode 100644 index cf6b51e5bf..0000000000 --- a/java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingProviderFactory.java +++ /dev/null @@ -1,64 +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.sca.binding.rest.provider; - -import org.apache.tuscany.sca.binding.rest.RESTBinding; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.host.http.ServletHost; -import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; -import org.apache.tuscany.sca.provider.BindingProviderFactory; -import org.apache.tuscany.sca.provider.ReferenceBindingProvider; -import org.apache.tuscany.sca.provider.ServiceBindingProvider; -import org.apache.tuscany.sca.runtime.RuntimeComponent; -import org.apache.tuscany.sca.runtime.RuntimeComponentReference; -import org.apache.tuscany.sca.runtime.RuntimeComponentService; - -/** - * REST Provider Factory - * - * @version $Rev: 665897 $ $Date: 2008-06-09 22:31:03 +0100 (Mon, 09 Jun 2008) $ - */ -public class RESTBindingProviderFactory implements BindingProviderFactory { - - private ServletHost servletHost; - - public RESTBindingProviderFactory(ExtensionPointRegistry extensionPoints) { - ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class); - this.servletHost = servletHosts.getServletHosts().get(0); - } - - public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, - RuntimeComponentReference reference, - RESTBinding binding) { - - return new RESTReferenceBindingProvider(component, reference, binding); - } - - public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, - RuntimeComponentService service, - RESTBinding binding) { - return new RESTServiceBindingProvider(component, service, binding, servletHost); - } - - public Class getModelType() { - return RESTBinding.class; - } - -} diff --git a/java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTReferenceBindingProvider.java b/java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTReferenceBindingProvider.java deleted file mode 100644 index 0770934769..0000000000 --- a/java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTReferenceBindingProvider.java +++ /dev/null @@ -1,70 +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.sca.binding.rest.provider; - -import org.apache.tuscany.sca.binding.rest.RESTBinding; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.invocation.Invoker; -import org.apache.tuscany.sca.provider.ReferenceBindingProvider; -import org.apache.tuscany.sca.runtime.RuntimeComponent; -import org.apache.tuscany.sca.runtime.RuntimeComponentReference; - -/** - * Implementation of the REST Binding Provider for References - * - * @version $Rev: 665897 $ $Date: 2008-06-09 22:31:03 +0100 (Mon, 09 Jun 2008) $ - */ -public class RESTReferenceBindingProvider implements ReferenceBindingProvider { - - private RuntimeComponentReference reference; - private RESTBinding binding; - - public RESTReferenceBindingProvider(RuntimeComponent component, - RuntimeComponentReference reference, - RESTBinding binding) { - this.reference = reference; - this.binding = binding; - - } - - public InterfaceContract getBindingInterfaceContract() { - return reference.getInterfaceContract(); - } - - public Invoker createInvoker(Operation operation) { - return new RESTBindingInvoker(operation, binding.getURI()); - } - - public void start() { - // TODO Auto-generated method stub - - } - - public void stop() { - // TODO Auto-generated method stub - - } - - public boolean supportsOneWayInvocation() { - return false; - } - -} diff --git a/java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java b/java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java deleted file mode 100644 index 67604832fc..0000000000 --- a/java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java +++ /dev/null @@ -1,148 +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.sca.binding.rest.provider; - -import java.net.URI; -import java.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.sca.binding.rest.RESTBinding; -import org.apache.tuscany.sca.host.http.ServletHost; -import org.apache.tuscany.sca.interfacedef.Interface; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.interfacedef.java.JavaInterface; -import org.apache.tuscany.sca.provider.ServiceBindingProvider; -import org.apache.tuscany.sca.runtime.RuntimeComponent; -import org.apache.tuscany.sca.runtime.RuntimeComponentService; - -/** - * Implementation of the REST Binding Provider for Services - * - * @version $Rev: 683451 $ $Date: 2008-08-07 00:59:24 +0100 (Thu, 07 Aug 2008) $ - */ -public class RESTServiceBindingProvider implements ServiceBindingProvider { - - - - - private RuntimeComponent component; - private RuntimeComponentService service; - private InterfaceContract serviceContract; - private RESTBinding binding; - private ServletHost servletHost; - private List servletMappings = new ArrayList(); - - public RESTServiceBindingProvider(RuntimeComponent component, - RuntimeComponentService service, - RESTBinding binding, - ServletHost servletHost) { - this.component = component; - this.service = service; - this.binding = binding; - this.servletHost = servletHost; - - //clone the service contract to avoid databinding issues - try { - this.serviceContract = (InterfaceContract)service.getInterfaceContract().clone(); - } catch(CloneNotSupportedException e) { - this.serviceContract = service.getInterfaceContract(); - } - - } - - public InterfaceContract getBindingInterfaceContract() { - return service.getInterfaceContract(); - } - - public boolean supportsOneWayInvocation() { - return false; - } - - public void start() { - - // Determine the service business interface - Class serviceInterface = getTargetJavaClass(serviceContract.getInterface()); - - // Create a Java proxy to the target service - //ProxyFactory proxyFactory = new JDKProxyFactory(); - Object proxy = component.getComponentContext().createSelfReference(serviceInterface, service).getService(); - //Object proxy = proxyFactory.createProxy(serviceInterface, service.getRuntimeWire(binding)); - - // Create and register a servlet for this service - RESTServiceServlet serviceServlet = - new RESTServiceServlet(binding, service, serviceContract, serviceInterface, proxy); - - //Prateek: to add 'rest/' before the name of the service so that it could be added to url-pattern for the filter -// String tempURI = binding.getURI(); -// binding.setURI("rest" + tempURI); - - String mapping = binding.getURI(); - if (!mapping.endsWith("/")) { - mapping += "/"; - } - if (!mapping.endsWith("*")) { - mapping += "*"; - } - - servletHost.addServletMapping(mapping, serviceServlet); - servletMappings.add(mapping); - servletHost.addServletMapping(binding.getURI(), serviceServlet); - servletMappings.add(binding.getURI()); - - //Prateek: add /rest for reverse-compatibility - servletHost.addServletMapping("/rest" + mapping, serviceServlet); - servletMappings.add("/rest" + mapping); - servletHost.addServletMapping("/rest" + binding.getURI(), serviceServlet); - servletMappings.add("/rest" + binding.getURI()); - - // Save the actual binding URI - binding.setURI(servletHost.getURLMapping(binding.getURI()).toString()); - - // Register service to scaDomain.js - int port; - URI uri = URI.create(binding.getURI()); - port = uri.getPort(); - if (port == -1) { - port = servletHost.getDefaultPort(); - } - } - - public void stop() { - - // Remove the servlet mappings we've added - for (String mapping: servletMappings) { - servletHost.removeServletMapping(mapping); - - //Prateek: for /rest - servletHost.removeServletMapping("/rest" + mapping); - } - - } - - private Class getTargetJavaClass(Interface targetInterface) { - // TODO: right now assume that the target is always a Java - // Implementation. Need to figure out how to generate Java - // Interface in cases where the target is not a Java Implementation - return ((JavaInterface)targetInterface).getJavaClass(); - } - - - -} diff --git a/java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceServlet.java b/java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceServlet.java deleted file mode 100644 index 6a73f55649..0000000000 --- a/java/sca-contrib/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceServlet.java +++ /dev/null @@ -1,138 +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.sca.binding.rest.provider; - -import java.io.IOException; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpServlet; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.binding.rest.RESTBindingForJersey; -import org.apache.tuscany.sca.host.webapp.WebAppServletHost; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.runtime.RuntimeComponentService; - - -import com.sun.jersey.impl.container.servlet.ServletAdaptor; - -import com.sun.jersey.tuscany.common.CommonDataStructures; -import com.sun.jersey.tuscany.common.CommonInterface; -/** - * Servlet that handles REST requests invoking SCA services. - * - * There is an instance of this Servlet for each - */ -public class RESTServiceServlet extends HttpServlet { - private static final long serialVersionUID = 1L; - - transient Binding binding; - transient String serviceName; - transient Object serviceInstance; - transient RuntimeComponentService componentService; - transient InterfaceContract serviceContract; - transient Class serviceInterface; - - private ServletConfig servletConfig; - private ServletContext servletContext; - - private static ServletAdaptor jerseyServletContainer; - - public RESTServiceServlet(Binding binding, - RuntimeComponentService componentService, - InterfaceContract serviceContract, - Class serviceInterface, - Object serviceInstance) { - this.binding = binding; - this.serviceName = binding.getName(); - this.componentService = componentService; - this.serviceContract = serviceContract; - this.serviceInterface = serviceInterface; - this.serviceInstance = serviceInstance; - - //The interface name will be stored in a HashMap in the RESTBindingForJersey class along with a - //reference to this servlet - RESTBindingForJersey.updateInterfacenameServletMap(serviceInterface.getSimpleName(), this); - - } - - - /* (non-Javadoc) - * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig) - */ - @Override - public void init(ServletConfig config) { - try{ - - servletConfig = config; - servletContext = servletConfig.getServletContext(); - String contextPath = servletContext.getContextPath(); - RESTBindingForJersey.setContextPath(contextPath); - - //The following code has been moved to the host-webapp modlue. - //(org.apache.tuscany.sca.host.webapp.WebAppServletHost) - - //jerseyServletContainer.init(config); - - //Setting the reference below in CommonDataStructures for - //com.sun.jersey.impl.model.method.dispatch.EntityParamDispatchProvider - //to be able to invoke the method returnResult() method. - CommonInterface commonInterface = new RESTBindingForJersey(); - CommonDataStructures.setCommonInterface(commonInterface); - - }catch(Exception e){ - e.printStackTrace(System.out); - } - } - - @Override - public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { - try{ - jerseyServletContainer = WebAppServletHost.getJerseyServletContainer(); - jerseyServletContainer.service(request, response); - }catch(ServletException e){ - e.printStackTrace(System.out); - } - } - - public Binding getBinding() { - return binding; - } - - - public RuntimeComponentService getComponentService() { - return componentService; - } - - - public InterfaceContract getServiceContract() { - return serviceContract; - } - - - public static void setJerseyServletContainer( - ServletAdaptor jerseyServletContainer) { - RESTServiceServlet.jerseyServletContainer = jerseyServletContainer; - } - -} diff --git a/java/sca-contrib/modules/binding-rest-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/java/sca-contrib/modules/binding-rest-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory deleted file mode 100644 index 4a682c1cb6..0000000000 --- a/java/sca-contrib/modules/binding-rest-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory +++ /dev/null @@ -1,19 +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. - -# Implementation class for the binding extension -org.apache.tuscany.sca.binding.rest.provider.RESTBindingProviderFactory;model=org.apache.tuscany.sca.binding.rest.RESTBinding -- cgit v1.2.3