diff options
Diffstat (limited to 'sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook')
9 files changed, 0 insertions, 1098 deletions
diff --git a/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/LICENSE b/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/LICENSE deleted file mode 100644 index 6e529a25c4..0000000000 --- a/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/LICENSE +++ /dev/null @@ -1,205 +0,0 @@ -
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed 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.
-
-
-
diff --git a/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/META-INF/MANIFEST.MF b/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/META-INF/MANIFEST.MF deleted file mode 100644 index 70e18a0c9a..0000000000 --- a/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/META-INF/MANIFEST.MF +++ /dev/null @@ -1,24 +0,0 @@ -Manifest-Version: 1.0
-Export-Package: org.apache.tuscany.sca.tomcat;version="2.0.0"
-Tool: Bnd-0.0.255
-Bundle-Name: Apache Tuscany SCA Tomcat Hook
-Created-By: 1.6.0_07 (Sun Microsystems Inc.)
-Bundle-Vendor: The Apache Software Foundation
-Bundle-Version: 2.0.0
-Bnd-LastModified: 1222833658000
-Bundle-ManifestVersion: 2
-Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
-Bundle-Description: Apache Tuscany SCA Webapp Host
-Import-Package: javax.naming,
- javax.servlet,
- javax.servlet.http,
- org.apache.tuscany.sca.core;version="2.0.0",
- org.apache.tuscany.sca.host.http;version="2.0.0",
- org.apache.tuscany.sca.host.webapp;version="2.0.0",
- org.apache.tuscany.sca.node;version="2.0.0",
- org.apache.tuscany.sca.node.configuration;version="2.0.0",
- org.apache.tuscany.sca.node.impl;version="2.0.0",
- org.oasisopen.sca;version="2.0.0"
-Bundle-SymbolicName: org.apache.tuscany.sca.tomcat
-Bundle-DocURL: http://www.apache.org/
-Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6 diff --git a/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/NOTICE b/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/NOTICE deleted file mode 100644 index 0d2bd8fb3e..0000000000 --- a/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/NOTICE +++ /dev/null @@ -1,7 +0,0 @@ -${pom.name}
-Copyright (c) 2005 - 2010 The Apache Software Foundation
-
-This product includes software developed by
-The Apache Software Foundation (http://www.apache.org/).
-
-
diff --git a/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/pom.xml b/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/pom.xml deleted file mode 100644 index 39f2a1331e..0000000000 --- a/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/pom.xml +++ /dev/null @@ -1,70 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - * 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. ---> -<project> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-modules</artifactId> - <version>2.0-Beta1</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <artifactId>tuscany-tomcat-hook</artifactId> - <name>Apache Tuscany SCA Tomcat Hook</name> - - <dependencies> - - <dependency> - <groupId>org.apache.tomcat</groupId> - <artifactId>catalina</artifactId> - <version>6.0.18</version> - <exclusions> - <exclusion> - <groupId>org.apache.tomcat</groupId> - <artifactId>servlet-api</artifactId> - </exclusion> - </exclusions> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>org.apache.tomcat</groupId> - <artifactId>coyote</artifactId> - <version>6.0.18</version> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>2.5</version> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>org.codehaus.swizzle</groupId> - <artifactId>swizzle-stream</artifactId> - <version>1.0.2</version> - <scope>provided</scope> - </dependency> - - </dependencies> - -</project> diff --git a/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/src/main/java/org/apache/tuscany/sca/tomcat/TuscanyAnnotationsProcessor.java b/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/src/main/java/org/apache/tuscany/sca/tomcat/TuscanyAnnotationsProcessor.java deleted file mode 100644 index 54947d6492..0000000000 --- a/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/src/main/java/org/apache/tuscany/sca/tomcat/TuscanyAnnotationsProcessor.java +++ /dev/null @@ -1,85 +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.tomcat; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import javax.naming.NamingException; -import javax.servlet.ServletContext; - -import org.apache.AnnotationProcessor; -import org.apache.catalina.util.DefaultAnnotationProcessor; - -public class TuscanyAnnotationsProcessor implements AnnotationProcessor { - - private TuscanyStandardContext tuscanyStandardContext; - private AnnotationProcessor tomcatAnnotationProcessor; - private Method tuscanyInjectMethod; - - public TuscanyAnnotationsProcessor(TuscanyStandardContext tuscanyStandardContext, javax.naming.Context context) { - this.tuscanyStandardContext = tuscanyStandardContext; - this.tomcatAnnotationProcessor = new DefaultAnnotationProcessor(context); - initInjectMethod(tuscanyStandardContext); - } - - private void initInjectMethod(TuscanyStandardContext tuscanyStandardContext) { - - // this needs to use reflection as the tuscany-hook module can't have any - // dependencies on the tuscany runtime modules as they're not - // in the server classpath - // TODO: is there a nicer way ? - - ClassLoader cl = tuscanyStandardContext.getParentClassLoader(); - try { - Class<?> c = Class.forName("org.apache.tuscany.sca.implementation.web.runtime.utils.ContextHelper", true, cl); - if (c != null) { - this.tuscanyInjectMethod = c.getMethod("inject", new Class[]{Object.class, ServletContext.class}); - } - } catch (Exception e){ - // ignore - } - } - - public void postConstruct(Object instance) throws IllegalAccessException, InvocationTargetException { - tomcatAnnotationProcessor.postConstruct(instance); - } - - public void preDestroy(Object instance) throws IllegalAccessException, InvocationTargetException { - tomcatAnnotationProcessor.preDestroy(instance); - } - - public void processAnnotations(Object instance) throws IllegalAccessException, InvocationTargetException, NamingException { - if (tuscanyInjectMethod != null) { - ServletContext sc = tuscanyStandardContext.getServletContext(); - if (sc != null) { - Object rc = sc.getAttribute("org.apache.tuscany.sca.implementation.web.RuntimeComponent"); - if (rc != null) { - try { - tuscanyInjectMethod.invoke(null, instance, sc); - } catch (Exception e) { - throw new InvocationTargetException(e); - } - } - } - } - tomcatAnnotationProcessor.processAnnotations(instance); - } -} diff --git a/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/src/main/java/org/apache/tuscany/sca/tomcat/TuscanyContextConfig.java b/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/src/main/java/org/apache/tuscany/sca/tomcat/TuscanyContextConfig.java deleted file mode 100644 index 5e7905d246..0000000000 --- a/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/src/main/java/org/apache/tuscany/sca/tomcat/TuscanyContextConfig.java +++ /dev/null @@ -1,183 +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.tomcat;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-
-import org.apache.catalina.Host;
-import org.apache.catalina.core.StandardContext;
-import org.apache.catalina.core.StandardHost;
-import org.apache.catalina.startup.ContextConfig;
-import org.apache.catalina.startup.ExpandWar;
-
-public class TuscanyContextConfig extends ContextConfig{
-
- /**
- * Return the location of the default deployment descriptor
- *
- * Override the super class method to use the Tuscany specific
- * default web.xml which has the Tuscany listener and filer config
- */
- @Override
- public String getDefaultWebXml() {
- if( defaultWebXml == null ) {
- defaultWebXml="conf/tuscany-web.xml";
- }
- return (this.defaultWebXml);
- }
-
- /**
- * Adjust docBase.
- *
- * This is cutNpaste of the Tomcat method but changed on the lines marked with // TUSCANY:
- * to override the default that only works for file names ending with .war
- *
- */
- @Override
- protected void fixDocBase()
- throws IOException {
-
- Host host = (Host) context.getParent();
- String appBase = host.getAppBase();
-
- boolean unpackWARs = true;
- if (host instanceof StandardHost) {
- unpackWARs = ((StandardHost) host).isUnpackWARs()
- && ((StandardContext) context).getUnpackWAR();
- }
-
- File canonicalAppBase = new File(appBase);
- if (canonicalAppBase.isAbsolute()) {
- canonicalAppBase = canonicalAppBase.getCanonicalFile();
- } else {
- canonicalAppBase =
- new File(System.getProperty("catalina.base"), appBase)
- .getCanonicalFile();
- }
-
- String docBase = context.getDocBase();
- if (docBase == null) {
- // Trying to guess the docBase according to the path
- String path = context.getPath();
- if (path == null) {
- return;
- }
- if (path.equals("")) {
- docBase = "ROOT";
- } else {
- if (path.startsWith("/")) {
- docBase = path.substring(1);
- } else {
- docBase = path;
- }
- }
- }
-
- File file = new File(docBase);
- if (!file.isAbsolute()) {
- docBase = (new File(canonicalAppBase, docBase)).getPath();
- } else {
- docBase = file.getCanonicalPath();
- }
- file = new File(docBase);
- String origDocBase = docBase;
-
- String contextPath = context.getPath();
- if (contextPath.equals("")) {
- contextPath = "ROOT";
- } else {
- if (contextPath.lastIndexOf('/') > 0) {
- contextPath = "/" + contextPath.substring(1).replace('/','#');
- }
- }
- // TUSCANY: update from .war to also support .jar and .zip SCA contributions
- if ((docBase.toLowerCase().endsWith(".war") || docBase.toLowerCase().endsWith(".jar")||docBase.toLowerCase().endsWith(".zip")) && !file.isDirectory() && unpackWARs) {
- URL war = new URL("jar:" + (new File(docBase)).toURI().toURL() + "!/");
- docBase = ExpandWar.expand(host, war, contextPath);
- file = new File(docBase);
- docBase = file.getCanonicalPath();
- if (context instanceof StandardContext) {
- ((StandardContext) context).setOriginalDocBase(origDocBase);
- }
- } else {
- File docDir = new File(docBase);
- if (!docDir.exists()) {
- // TUSCANY: update from .war to also support .jar and .zip SCA contributions
- File warFile = new File(docBase + ".war");
- if (warFile.exists()) {
- if (unpackWARs) {
- URL war =
- new URL("jar:" + warFile.toURI().toURL() + "!/");
- docBase = ExpandWar.expand(host, war, contextPath);
- file = new File(docBase);
- docBase = file.getCanonicalPath();
- } else {
- docBase = warFile.getCanonicalPath();
- }
- } else {
- warFile = new File(docBase + ".jar");
- if (warFile.exists()) {
- if (unpackWARs) {
- URL war =
- new URL("jar:" + warFile.toURI().toURL() + "!/");
- docBase = ExpandWar.expand(host, war, contextPath);
- file = new File(docBase);
- docBase = file.getCanonicalPath();
- } else {
- docBase = warFile.getCanonicalPath();
- }
- } else {
- warFile = new File(docBase + ".zip");
- if (warFile.exists()) {
- if (unpackWARs) {
- URL war =
- new URL("jar:" + warFile.toURI().toURL() + "!/");
- docBase = ExpandWar.expand(host, war, contextPath);
- file = new File(docBase);
- docBase = file.getCanonicalPath();
- } else {
- docBase = warFile.getCanonicalPath();
- }
- }
- }
- }
- if (context instanceof StandardContext) {
- ((StandardContext) context).setOriginalDocBase(origDocBase);
- }
- }
- }
-
- if (docBase.startsWith(canonicalAppBase.getPath())) {
- docBase = docBase.substring(canonicalAppBase.getPath().length());
- docBase = docBase.replace(File.separatorChar, '/');
- if (docBase.startsWith("/")) {
- docBase = docBase.substring(1);
- }
- } else {
- docBase = docBase.replace(File.separatorChar, '/');
- }
-
- context.setDocBase(docBase);
-
- }
-
-}
diff --git a/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/src/main/java/org/apache/tuscany/sca/tomcat/TuscanyHostConfig.java b/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/src/main/java/org/apache/tuscany/sca/tomcat/TuscanyHostConfig.java deleted file mode 100644 index e92d7a0bf6..0000000000 --- a/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/src/main/java/org/apache/tuscany/sca/tomcat/TuscanyHostConfig.java +++ /dev/null @@ -1,167 +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.tomcat;
-
-import java.io.File;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-
-import org.apache.catalina.Context;
-import org.apache.catalina.Lifecycle;
-import org.apache.catalina.LifecycleListener;
-import org.apache.catalina.startup.HostConfig;
-
-/**
- * A Tuscany customized HostConfig that adds support for SCA contributions
- * to be deployed along with the usual .war files.
- */
-public class TuscanyHostConfig extends HostConfig {
-
- protected File scaBase = null;
-
- @Override
- protected void deployApps() {
-
- File appBase = appBase();
- File configBase = configBase();
- // Deploy XML descriptors from configBase
- deployDescriptors(configBase, configBase.list());
- // Deploy WARs, and loop if additional descriptors are found
- deployWARs(appBase, appBase.list());
- // TUSCANY: Deploy any SCA contibutions
- deploySCAContributions(appBase, appBase.list());
- // Deploy expanded folders
- deployDirectories(appBase, appBase.list());
- }
-
- protected void deploySCAContributions(File appBase, String[] files) {
- if (files == null)
- return;
-
- for (int i = 0; i < files.length; i++) {
-
- File scafile = new File(appBase, files[i]);
-
- if (scafile.isFile() && isSCAContribution(scafile)) {
-
- // Calculate the context path and make sure it is unique
- String contextPath = "/" + files[i].replace('#','/');
- int period = contextPath.lastIndexOf(".");
- if (period >= 0)
- contextPath = contextPath.substring(0, period);
-
- if (isServiced(contextPath))
- continue;
-
- String file = files[i];
-
- deploySCAContribution(contextPath, scafile, file);
-
- }
-
- }
-
- }
-
- protected String tuscanyContextClass = "org.apache.tuscany.sca.tomcat.TuscanyContextConfig";
-
- protected void deploySCAContribution(String contextPath, File dir, String file) {
- if (deploymentExists(contextPath))
- return;
-
- DeployedApplication deployedApp = new DeployedApplication(contextPath);
-
- // Deploy the application in this WAR file
- if(log.isInfoEnabled())
- log.info("Deploying SCA contibution: " + file);
-
- // Populate redeploy resources with the WAR file
- deployedApp.redeployResources.put(dir.getAbsolutePath(), new Long(dir.lastModified()));
-
- try {
- Context context = (Context) Class.forName(contextClass).newInstance();
- if (context instanceof Lifecycle) {
-
- // Tuscany: change to use the Tuscany ContextConfig class
- Class clazz = Class.forName(tuscanyContextClass);
-
- LifecycleListener listener =
- (LifecycleListener) clazz.newInstance();
- ((Lifecycle) context).addLifecycleListener(listener);
- }
- context.setPath(contextPath);
- context.setDocBase(file);
-
- host.addChild(context);
- // If we're unpacking WARs, the docBase will be mutated after
- // starting the context
- if (unpackWARs && (context.getDocBase() != null)) {
- String name = null;
- String path = context.getPath();
- if (path.equals("")) {
- name = "ROOT";
- } else {
- if (path.startsWith("/")) {
- name = path.substring(1);
- } else {
- name = path;
- }
- }
- name = name.replace('/', '#');
- File docBase = new File(name);
- if (!docBase.isAbsolute()) {
- docBase = new File(appBase(), name);
- }
- deployedApp.redeployResources.put(docBase.getAbsolutePath(),
- new Long(docBase.lastModified()));
- addWatchedResources(deployedApp, docBase.getAbsolutePath(), context);
- } else {
- addWatchedResources(deployedApp, null, context);
- }
- } catch (Throwable t) {
- log.error(sm.getString("hostConfig.deployJar.error", file), t);
- }
-
- deployed.put(contextPath, deployedApp);
- }
-
- protected boolean isSCAContribution(File file) {
- ZipFile zip = null;
- ZipEntry entry = null;
- try {
- try {
- zip = new ZipFile(file);
- entry = zip.getEntry("META-INF/sca-contribution.xml");
- } catch (Exception e) {
- }
-
- return (entry != null);
-
- } finally {
- if (zip != null) {
- try {
- zip.close();
- } catch (Throwable t) {
- }
- }
- }
- }
-
-}
diff --git a/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/src/main/java/org/apache/tuscany/sca/tomcat/TuscanyLifecycleListener.java b/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/src/main/java/org/apache/tuscany/sca/tomcat/TuscanyLifecycleListener.java deleted file mode 100644 index a9eee9687e..0000000000 --- a/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/src/main/java/org/apache/tuscany/sca/tomcat/TuscanyLifecycleListener.java +++ /dev/null @@ -1,161 +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.tomcat; - -import java.io.File; -import java.util.logging.Logger; - -import org.apache.catalina.Container; -import org.apache.catalina.LifecycleEvent; -import org.apache.catalina.LifecycleListener; -import org.apache.catalina.ServerFactory; -import org.apache.catalina.Service; -import org.apache.catalina.connector.Connector; -import org.apache.catalina.core.StandardEngine; -import org.apache.catalina.core.StandardHost; -import org.apache.catalina.core.StandardServer; -import org.apache.catalina.core.StandardService; -import org.apache.catalina.startup.HostConfig; - -/** - * A Tomcat LifecycleListener that initilizes the Tuscany Tomcat integration. - * It sets a System property with the location of the Tuscany runtime .war - * and configures each Tomcat Connector to use the TuscanyStandardContext. - * - * To configure Tomcat to use this add the following to the Tomcat conf/server.xml - * <Listener className="org.apache.tuscany.sca.tomcat.TuscanyLifecycleListener"/> - */ -public class TuscanyLifecycleListener implements LifecycleListener { - private static final Logger log = Logger.getLogger(TuscanyLifecycleListener.class.getName()); - - public static final String TUSCANY_WAR_PROP = "org.apache.tuscany.sca.tomcat.war"; - - private static boolean running; - - public static boolean isRunning() { - return running; - } - - static final String TUSCANY_SHARED_PROP = "org.apache.tuscany.sca.tomcat.shared"; - - private static String domainURI = "tuscany:default"; - - public TuscanyLifecycleListener() { - running = true; - log.info("Apache Tuscany initilizing"); - } - - public void lifecycleEvent(LifecycleEvent event) { - if ("init".equals(event.getType()) && (event.getSource() instanceof StandardServer)) { - File webappDir = findTuscanyWar(); - if (webappDir == null) { - log.severe("Tuscany disabled as Tuscany webapp not found"); - } else { - System.setProperty(TUSCANY_WAR_PROP, webappDir.getAbsolutePath()); - log.info("Using Tuscany webapp: " + webappDir.getAbsolutePath()); - StandardServer server = (StandardServer)event.getSource(); - StandardService catalina = (StandardService)server.findService("Catalina"); - for (Connector connector : catalina.findConnectors()) { - for (Container container : connector.getContainer().findChildren()) { - if (container instanceof StandardHost) { - for (LifecycleListener listener : ((StandardHost)container).findLifecycleListeners()) { - if (listener instanceof HostConfig) { - ((HostConfig)listener).setContextClass("org.apache.tuscany.sca.tomcat.TuscanyStandardContext"); - log.info("Tuscany enabled on connector: " + container.getName() + ":" + connector.getPort()); - } - } - } - } - } - } - } - } - - private static File findTuscanyWar() { - - // in Tomcat 5.5 the Tuscany war is in the server/webapps director - String catalinaBase = System.getProperty("catalina.base"); - File serverWebapps = new File(catalinaBase, "server/webapps"); - File tuscanyWar = findTuscanyWar(serverWebapps); - if (tuscanyWar != null) { - return tuscanyWar; - } - - // in Tomcat 6 the Tuscany war is normally in webapps, but we just scan all hosts directories - for (Service service : ServerFactory.getServer().findServices()) { - Container container = service.getContainer(); - if (container instanceof StandardEngine) { - StandardEngine engine = (StandardEngine)container; - for (Container child : engine.findChildren()) { - if (child instanceof StandardHost) { - StandardHost host = (StandardHost)child; - String appBase = host.getAppBase(); - - // determine the host dir (normally webapps) - File hostDir = new File(appBase); - if (!hostDir.isAbsolute()) { - hostDir = new File(catalinaBase, appBase); - } - - tuscanyWar = findTuscanyWar(hostDir); - if (tuscanyWar != null) { - return tuscanyWar; - } - } - } - } - } - return null; - } - - private static File findTuscanyWar(File hostDir) { - if (!hostDir.isDirectory()) { - return null; - } - - // iterate over the contexts - for (File contextDir : hostDir.listFiles()) { - // does this war have a web-inf lib dir - File hookLib = new File(contextDir, "tomcat-lib"); - if (!hookLib.isDirectory()) { - continue; - } - // iterate over the libs looking for the tuscany-tomcat-*.jar - for (File file : hookLib.listFiles()) { - if (file.getName().startsWith("tuscany-tomcat-hook-") && file.getName().endsWith(".jar")) { - // this should be in the Tuscany war... - // make sure it has a runtime directory - if (new File(contextDir, "tuscany-lib").isDirectory()) { - return contextDir; - } - } - } - } - return null; - } - - public void setDomainURI(String domainURI) { - TuscanyLifecycleListener.domainURI = domainURI; - } - - public static String getDomainURI() { - return domainURI; - } -} diff --git a/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/src/main/java/org/apache/tuscany/sca/tomcat/TuscanyStandardContext.java b/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/src/main/java/org/apache/tuscany/sca/tomcat/TuscanyStandardContext.java deleted file mode 100644 index ca9c81f1c3..0000000000 --- a/sca-java-2.x/tags/2.0-Beta1-RC1/distribution/tomcat/tomcat-hook/src/main/java/org/apache/tuscany/sca/tomcat/TuscanyStandardContext.java +++ /dev/null @@ -1,196 +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.tomcat; - -import java.io.File; -import java.lang.reflect.Method; -import java.net.URI; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.logging.Logger; - -import javax.naming.NameClassPair; -import javax.naming.NamingEnumeration; -import javax.naming.NamingException; - -import org.apache.catalina.LifecycleException; -import org.apache.catalina.Loader; -import org.apache.catalina.core.StandardContext; - -/** - * A Tuscany StandardContext to initilize SCA applications. - * There is a StandardContext instance for each webapp and its - * called to handle all start/stop/etc requests. This intercepts - * the start and inserts any required Tuscany configuration. - */ -public class TuscanyStandardContext extends StandardContext { - private static final long serialVersionUID = 1L; - private static final Logger log = Logger.getLogger(TuscanyStandardContext.class.getName()); - - private boolean isSCAApp; - - // TODO: this gives an instance per webapp, work out how to have only one per server - // ?? is that comment still true? - private static URLClassLoader tuscanyClassLoader; - private static Object node; - private static Class<?> nodeClass; - private static Method nodeStopMethod; - - public TuscanyStandardContext() { - } - - /** - * Overrides the getLoader method in the Tomcat StandardContext as its a convenient - * point to insert the Tuscany initilization. This gets called the first time during - * StandardContext.start after the webapp resources have been created so this can - * use getResources() to look for the SCA web.composite or sca-contribution.xml files, - * but its still early enough in start to insert the required Tuscany config. - */ - @Override - public Loader getLoader() { - if (loader != null) { - return loader; - } - - ClassLoader parent = getParentClassLoader(); - if (isSCAApp = isSCAApplication()) { - if (tuscanyClassLoader == null) { - initTuscany(); - } - setParentClassLoader(getTuscanyClassloader(parent)); - setDefaultWebXml("conf/tuscany-web.xml"); - } - - return super.getLoader(); - } - - @Override - public boolean listenerStart() { - if (isSCAApp) { - enableTuscany(); - } - return super.listenerStart(); - } - - private void enableTuscany() { - - if (isUseNaming() && getNamingContextListener() != null) { - setAnnotationProcessor(new TuscanyAnnotationsProcessor(this, getNamingContextListener().getEnvContext())); - } else { - setAnnotationProcessor(new TuscanyAnnotationsProcessor(this, null)); - } - - log.info("Tuscany SCA is enabled for: " + this.getName()); - } - - private boolean isSCAApplication() { - Object o = null; - try { - o = getResources().lookup("WEB-INF/web.composite"); - } catch (NamingException e) { - } - if (o == null) { - try { - o = getResources().lookup("META-INF/sca-contribution.xml"); - } catch (NamingException e) { - } - } - if (o == null) { - return false; - } - - // Try to see if the Tuscany jars are packaged in the webapp - NamingEnumeration<NameClassPair> enumeration; - try { - enumeration = getResources().list("WEB-INF/lib"); - while (enumeration.hasMoreElements()) { - String jar = enumeration.nextElement().getName(); - if (jar.startsWith("tuscany-")) { - // Do not alter is - log.info("Tuscany SCA ignoring webapp with embedded Tuscany runtime: " + this.getName()); - return false; - } - } - } catch (NamingException e) { - } - return true; - } - - private URLClassLoader getTuscanyClassloader(ClassLoader parent) { - return tuscanyClassLoader; - } - - private void initTuscany() { - initTuscanyClassloader(getParentClassLoader()); - initDomain(); - } - - private void initTuscanyClassloader(ClassLoader parent) { - if (tuscanyClassLoader == null) { - File tuscanyWar = new File(System.getProperty(TuscanyLifecycleListener.TUSCANY_WAR_PROP)); - File[] runtimeJars = new File(tuscanyWar, "tuscany-lib").listFiles(); - try { - URL[] jarURLs = new URL[runtimeJars.length]; - for (int i = 0; i < jarURLs.length; i++) { - jarURLs[i] = runtimeJars[i].toURI().toURL(); - } - tuscanyClassLoader = new URLClassLoader(jarURLs, parent); - - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } - - private void initDomain() { - ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); - try { - Thread.currentThread().setContextClassLoader(tuscanyClassLoader); - Class<?> nodeFactoryClass = Class.forName("org.apache.tuscany.sca.node.NodeFactory", true, tuscanyClassLoader); - Method getInstanceMethod = nodeFactoryClass.getMethod("getInstance", new Class[0]); - Object instance = getInstanceMethod.invoke(null); - Method createNodeMethod = nodeFactoryClass.getMethod("createNode", new Class[]{URI.class, new String[0].getClass()}); - URI domainURI = URI.create(TuscanyLifecycleListener.getDomainURI()); - this.node = createNodeMethod.invoke(instance, new Object[]{domainURI, new String[0]}); - this.nodeClass = Class.forName("org.apache.tuscany.sca.node.Node", true, tuscanyClassLoader); - Method nodeStartMethod = nodeClass.getMethod("start", new Class[0]); - this.nodeStopMethod = nodeClass.getMethod("stop", new Class[0]); - nodeStartMethod.invoke(node); - } catch (Exception e) { - throw new RuntimeException(e); - } finally { - Thread.currentThread().setContextClassLoader(oldCL); - } - } - - @Override - public synchronized void stop() throws LifecycleException { - super.stop(); - - if (node != null && nodeStopMethod != null) { - try { - nodeStopMethod.invoke(node); - node = null; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } -} |