diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2008-08-11 07:29:53 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2008-08-11 07:29:53 +0000 |
commit | 23297fa3b1f66d74325c8352cb8f5aae599a3090 (patch) | |
tree | 2c3017479edf2ae3f45e656975db5a53eed71b10 /branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat | |
parent | c5ab90dd4248519034478db64a9c32a0c3f91f3a (diff) |
Start branch for 1.3.1, the only changes in this commit are for the version
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@684661 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat')
7 files changed, 792 insertions, 0 deletions
diff --git a/branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/EndpointResolverFactoryImpl.java b/branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/EndpointResolverFactoryImpl.java new file mode 100644 index 0000000000..45ea279889 --- /dev/null +++ b/branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/EndpointResolverFactoryImpl.java @@ -0,0 +1,49 @@ +/* + * 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.runtime.tomcat; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.endpointresolver.EndpointResolver; +import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory; + +/** + * The factory for creating endpoint Binding providers + * + * @version $Rev$ $Date$ + */ +public class EndpointResolverFactoryImpl implements EndpointResolverFactory<Endpoint> { + + private ExtensionPointRegistry extensionPoints; + + public EndpointResolverFactoryImpl(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; + } + + public EndpointResolver createEndpointResolver(Endpoint endpoint, Binding binding) { + + return new EndpointResolverImpl(extensionPoints, endpoint); + } + + public Class<Endpoint> getModelType() { + return Endpoint.class; + } +} diff --git a/branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/EndpointResolverImpl.java b/branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/EndpointResolverImpl.java new file mode 100644 index 0000000000..e05004160c --- /dev/null +++ b/branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/EndpointResolverImpl.java @@ -0,0 +1,136 @@ +/* + * 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.runtime.tomcat; + + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; + +import org.apache.catalina.core.StandardContext; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.builder.DefaultEndpointBuilder; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.endpointresolver.EndpointResolver; +import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory; +import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactoryExtensionPoint; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.apache.tuscany.sca.host.embedded.impl.DefaultSCADomain; +import org.apache.tuscany.sca.host.webapp.WebAppServletHost; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; + + +/** + * The endpoint resolver allows unresolved endpoints to be plumbed into + * the runtime start and message send processing as a hook to late resolution + * of target services + * + * @version $Rev$ $Date$ + */ +public class EndpointResolverImpl implements EndpointResolver { + + private final static Logger logger = Logger.getLogger(EndpointResolverImpl.class.getName()); + + private Endpoint endpoint; + private List<EndpointResolver> endpointResolvers = new ArrayList<EndpointResolver>(); + + public EndpointResolverImpl(ExtensionPointRegistry extensionPoints, + Endpoint endpoint) { + this.endpoint = endpoint; + + EndpointResolverFactoryExtensionPoint resolverFactories = + extensionPoints.getExtensionPoint(EndpointResolverFactoryExtensionPoint.class); + + for (Binding binding : endpoint.getCandidateBindings()){ + EndpointResolverFactory resolverFactory = resolverFactories.getEndpointResolverFactory(binding.getClass()); + + // if the binding in question has a endpoint resolver factory they try and + // create an endpoint resolver + if (resolverFactory != null){ + EndpointResolver resolver = resolverFactory.createEndpointResolver(endpoint, binding); + + if (resolver != null){ + endpointResolvers.add(resolver); + } + } + } + } + + public void start(){ + // do nothing + } + + public void resolve() { + if (endpoint.isUnresolved()){ + logger.info("resolving endpoint: " + endpoint.getTargetName()); + + Component target = findTarget(); + if (target != null) { + logger.info("endpoint target found: " + endpoint.getTargetName() + " component " + target); + resolveEndpoint(target); + } else { + logger.info("endpoint target not found: " + endpoint.getTargetName()); + } + + } + } + + protected void resolveEndpoint(Component targetComponent) { + + endpoint.setTargetComponent(targetComponent); + endpoint.setTargetComponentService(targetComponent.getServices().get(0)); // TODO real service + + DefaultEndpointBuilder ebi = new DefaultEndpointBuilder(new Monitor() { + public void problem(Problem problem) { + logger.warning(problem.toString()); + } + + public List<Problem> getProblems() { + return null; + } + }); + + ebi.build(endpoint); + } + + protected Component findTarget() { + for (StandardContext sc : TuscanyHost.scaApps) { + SCADomain scaDomain = (SCADomain)sc.getServletContext().getAttribute(WebAppServletHost.SCA_DOMAIN_ATTRIBUTE); + if (scaDomain != null) { + Component component = ((DefaultSCADomain)scaDomain).getComponent(endpoint.getTargetName()); + if ( component != null) { + return component; + } + } + } + return null; + } + + public void stop() { + if (!endpoint.isUnresolved()){ + // Currently the CompositeActivator stop() should take care of the providers and + // wires that have been added. + } + } + +} diff --git a/branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyContext.java b/branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyContext.java new file mode 100644 index 0000000000..c8d3aa7a46 --- /dev/null +++ b/branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyContext.java @@ -0,0 +1,270 @@ +/* + * 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.runtime.tomcat; + +import java.util.Hashtable; + +import javax.naming.Binding; +import javax.naming.Context; +import javax.naming.Name; +import javax.naming.NameClassPair; +import javax.naming.NameParser; +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.directory.Attributes; +import javax.naming.directory.DirContext; +import javax.naming.directory.ModificationItem; +import javax.naming.directory.SearchControls; +import javax.naming.directory.SearchResult; + +import org.apache.catalina.core.StandardContext; + +/** + * + * @version $Rev$ $Date$ + */ +public class TuscanyContext extends StandardContext { + private static final long serialVersionUID = 1L; + + public TuscanyContext() { + setProcessTlds(false); + } + + @Override + public boolean getConfigured() { + return true; + } + + @Override + public DirContext getResources() { + return DUMMY_CONTEXT; + } + + @Override + public synchronized void setResources(DirContext resources) { + setDocBase("tuscany"); + super.setResources(DUMMY_CONTEXT); + } + + private static final DirContext DUMMY_CONTEXT = new DirContext(){ + + public void bind(Name name, Object obj, Attributes attrs) throws NamingException { + } + + public void bind(String name, Object obj, Attributes attrs) throws NamingException { + } + + public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException { + return null; + } + + public DirContext createSubcontext(String name, Attributes attrs) throws NamingException { + return null; + } + + public Attributes getAttributes(Name name) throws NamingException { + return null; + } + + public Attributes getAttributes(String name) throws NamingException { + return null; + } + + public Attributes getAttributes(Name name, String[] attrIds) throws NamingException { + return null; + } + + public Attributes getAttributes(String name, String[] attrIds) throws NamingException { + return null; + } + + public DirContext getSchema(Name name) throws NamingException { + return null; + } + + public DirContext getSchema(String name) throws NamingException { + return null; + } + + public DirContext getSchemaClassDefinition(Name name) throws NamingException { + return null; + } + + public DirContext getSchemaClassDefinition(String name) throws NamingException { + return null; + } + + public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException { + } + + public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException { + } + + public void modifyAttributes(Name name, int mod_op, Attributes attrs) throws NamingException { + } + + public void modifyAttributes(String name, int mod_op, Attributes attrs) throws NamingException { + } + + public void rebind(Name name, Object obj, Attributes attrs) throws NamingException { + } + + public void rebind(String name, Object obj, Attributes attrs) throws NamingException { + } + + public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes) throws NamingException { + return null; + } + + public NamingEnumeration<SearchResult> search(String name, Attributes matchingAttributes) throws NamingException { + return null; + } + + public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException { + return null; + } + + public NamingEnumeration<SearchResult> search(String name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException { + return null; + } + + public NamingEnumeration<SearchResult> search(Name name, String filter, SearchControls cons) throws NamingException { + return null; + } + + public NamingEnumeration<SearchResult> search(String name, String filter, SearchControls cons) throws NamingException { + return null; + } + + public NamingEnumeration<SearchResult> search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException { + return null; + } + + public NamingEnumeration<SearchResult> search(String name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException { + return null; + } + + public Object addToEnvironment(String propName, Object propVal) throws NamingException { + return null; + } + + public void bind(Name name, Object obj) throws NamingException { + } + + public void bind(String name, Object obj) throws NamingException { + } + + public void close() throws NamingException { + } + + public Name composeName(Name name, Name prefix) throws NamingException { + return null; + } + + public String composeName(String name, String prefix) throws NamingException { + return null; + } + + public Context createSubcontext(Name name) throws NamingException { + return null; + } + + public Context createSubcontext(String name) throws NamingException { + return null; + } + + public void destroySubcontext(Name name) throws NamingException { + } + + public void destroySubcontext(String name) throws NamingException { + } + + public Hashtable<?, ?> getEnvironment() throws NamingException { + return null; + } + + public String getNameInNamespace() throws NamingException { + return null; + } + + public NameParser getNameParser(Name name) throws NamingException { + return null; + } + + public NameParser getNameParser(String name) throws NamingException { + return null; + } + + public NamingEnumeration<NameClassPair> list(Name name) throws NamingException { + return null; + } + + public NamingEnumeration<NameClassPair> list(String name) throws NamingException { + return null; + } + + public NamingEnumeration<Binding> listBindings(Name name) throws NamingException { + return null; + } + + public NamingEnumeration<Binding> listBindings(String name) throws NamingException { + throw new NamingException(); + } + + public Object lookup(Name name) throws NamingException { + return null; + } + + public Object lookup(String name) throws NamingException { + return null; + } + + public Object lookupLink(Name name) throws NamingException { + return null; + } + + public Object lookupLink(String name) throws NamingException { + return null; + } + + public void rebind(Name name, Object obj) throws NamingException { + } + + public void rebind(String name, Object obj) throws NamingException { + } + + public Object removeFromEnvironment(String propName) throws NamingException { + return null; + } + + public void rename(Name oldName, Name newName) throws NamingException { + } + + public void rename(String oldName, String newName) throws NamingException { + } + + public void unbind(Name name) throws NamingException { + } + + public void unbind(String name) throws NamingException { + } + }; + +} diff --git a/branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyContextListener.java b/branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyContextListener.java new file mode 100644 index 0000000000..b19e2326a2 --- /dev/null +++ b/branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyContextListener.java @@ -0,0 +1,69 @@ +/* + * 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.runtime.tomcat; + +import java.io.File; + +import org.apache.catalina.Context; +import org.apache.catalina.Lifecycle; +import org.apache.catalina.LifecycleEvent; +import org.apache.catalina.LifecycleListener; +import org.apache.catalina.core.StandardContext; +//import org.apache.tuscany.sca.runtime.Launcher; + +/** + * + * @version $Rev$ $Date$ + */ +public class TuscanyContextListener implements LifecycleListener { + +// private Launcher launcher; + +// public TuscanyContextListener(Launcher launcher) { +// this.launcher = launcher; +// } + + public void lifecycleEvent(LifecycleEvent event) { + String type = event.getType(); + if (Lifecycle.AFTER_START_EVENT.equals(type)) { + startContext((Context) event.getLifecycle()); + } else if (Lifecycle.STOP_EVENT.equals(type)) { + stopContext((Context) event.getLifecycle()); + } + } + + protected void startContext(Context context) { + StandardContext sc = (StandardContext) context; + String path = sc.getServletContext().getRealPath("/"); + try { + File f = new File(path + "WEB-INF/classes"); + if (f.exists()) { + System.out.println("adding contribution: "+ path); +// launcher.addContribution(f.toURL()); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + protected void stopContext(Context context) { + } + +} diff --git a/branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyHost.java b/branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyHost.java new file mode 100644 index 0000000000..190fe137d9 --- /dev/null +++ b/branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyHost.java @@ -0,0 +1,154 @@ +/* + * 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.runtime.tomcat; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.jar.JarFile; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.catalina.Container; +import org.apache.catalina.LifecycleException; +import org.apache.catalina.core.StandardContext; +import org.apache.catalina.core.StandardEngine; +import org.apache.catalina.core.StandardHost; +import org.apache.catalina.deploy.FilterDef; +import org.apache.catalina.deploy.FilterMap; + +/** + * To use this copy all the Tuscany jars to the Tomcat lib folder and update + * the Tomcat conf/server.xml <Host> to include className="org.apache.tuscany.sca.runtime.tomcat.TomcatHost" + * + * For example: + * + * <Host name="localhost" appBase="webapps" + * className="org.apache.tuscany.sca.runtime.tomcat.TuscanyHost" + * unpackWARs="true" autoDeploy="true" + * xmlValidation="false" xmlNamespaceAware="false"> + * + * + * @version $Rev$ $Date$ + */ +public class TuscanyHost extends StandardHost { + private static final long serialVersionUID = 1L; + private static final Logger logger = Logger.getLogger(TuscanyHost.class.getName()); + + // TODO static for expedience, find a better way to share when/if this is working properly + protected static List<StandardContext> scaApps = new ArrayList<StandardContext>(); + + public synchronized void start() throws LifecycleException { + try { + logger.log(Level.INFO, "Starting Tuscany/SCA runtime"); + + super.start(); + + } catch (Exception e) { + logger.log(Level.SEVERE, "Exception starting Tuscany/SCA runtime", e); + } + } + + public synchronized void stop() throws LifecycleException { + try { + logger.log(Level.INFO, "Stopping Tuscany/SCA runtime"); + + super.stop(); + + } catch (Exception e) { + logger.log(Level.SEVERE, "Exception Stopping Tuscany/SCA runtime", e); + } + } + + public synchronized void addChild(Container child) { + try { + if (isSCAApp(child)) { + initSCAApplication((StandardContext)child); + } + } catch (Exception e) { + logger.log(Level.WARNING, "Exception detecting SCA application " + child.getName(), e); + } + super.addChild(child); + } + + /** + * Tests if the child is an SCA application by checking for the presence + * of either an sca-contribution.xml file or a sca-deployables folder + */ + protected boolean isSCAApp(Container child) throws IOException { + if (child instanceof StandardContext) { + StandardContext sc = (StandardContext) child; + + if (sc.getDocBase().endsWith(".war")) { + JarFile jar = null; + try { + jar = new JarFile(((StandardEngine)this.getParent()).getBaseDir() + "/" + getAppBase() + "/" + sc.getDocBase()); + + if (jar.getEntry("META-INF/sca-deployables/") != null) { + return true; + } + + if (jar.getEntry("META-INF/sca-contribution.xml") != null) { + return true; + } + + } finally { + if (jar != null) { + jar.close(); + } + } + } else { + File webappRoot = new File(sc.getConfigFile()).getParentFile().getParentFile(); + + File scaDeployables = new File(webappRoot, "META-INF/sca-deployables"); + if (scaDeployables.exists()) { + return true; + } + + File scaContribution = new File(webappRoot, "META-INF/sca-contribution.xml"); + if (scaContribution.exists()) { + return true; + } + } + } + return false; + } + + protected void initSCAApplication(StandardContext scaApp) { + logger.log(Level.INFO, "Initilizing SCA application: " + scaApp.getName()); + + // Add the Tuscany ContextListener + scaApp.addApplicationListener(org.apache.tuscany.sca.host.webapp.TuscanyContextListener.class.getName()); + + // Add the Tuscany Servlet Filter + FilterDef filterDef = new FilterDef(); + filterDef.setFilterClass(org.apache.tuscany.sca.host.webapp.TuscanyServletFilter.class.getName()); + filterDef.setFilterName(org.apache.tuscany.sca.host.webapp.TuscanyServletFilter.class.getName()); + scaApp.addFilterDef(filterDef); + FilterMap filterMap = new FilterMap(); + filterMap.setFilterName(filterDef.getFilterName()); + filterMap.addURLPattern("/*"); + scaApp.addFilterMap(filterMap); + + scaApps.add(scaApp); + } + +} diff --git a/branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyServlet.java b/branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyServlet.java new file mode 100644 index 0000000000..112b404515 --- /dev/null +++ b/branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyServlet.java @@ -0,0 +1,65 @@ +/* + * 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.runtime.tomcat; + +import java.io.IOException; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; + +import org.apache.tuscany.sca.host.webapp.WebAppServletHost; + +/** + * A Servlet that forwards requests to the Servlets registered with the Tuscany + * ServletHost. + * + * TODO: Copy of host-webapp TuscanyServlet. Can be removed once host-webapp TuscanyServlet + * moved over to latest SCADomain API. + * + * @version $Rev$ $Date$ + */ +public class TuscanyServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + private transient WebAppServletHost servletHost; + + @Override + public void init(ServletConfig config) throws ServletException { + servletHost = WebAppServletHost.getInstance(); + servletHost.init(config); + } + + @Override + public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { + String path = ((HttpServletRequest)req).getPathInfo(); + RequestDispatcher dispatcher = servletHost.getRequestDispatcher(path); + if (dispatcher == null) { + throw new IllegalStateException("No servlet registered for path: " + path); + } + + dispatcher.forward(req, res); + } + +} diff --git a/branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyWrapper.java b/branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyWrapper.java new file mode 100644 index 0000000000..17c3cb1707 --- /dev/null +++ b/branches/sca-java-1.3.1/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyWrapper.java @@ -0,0 +1,49 @@ +/* + * 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.runtime.tomcat; + +import javax.servlet.Servlet; + +import org.apache.catalina.core.StandardWrapper; + +/** + * Override the StandardWrapper so that Servlets are not instantiated from the + * class name but just the instance Tuscany passes in the constructor is always used. + * + * @version $Rev$ $Date$ + */ +public class TuscanyWrapper extends StandardWrapper { + private static final long serialVersionUID = 1L; + + private final Servlet servlet; + + public TuscanyWrapper(Servlet servlet) { + super(); + this.servlet = servlet; + } + + public synchronized Servlet loadServlet() { + return servlet; + } + + public Servlet getServlet() { + return servlet; + } +}
\ No newline at end of file |