You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2010/01/31 19:07:39 UTC
svn commit: r905088 - in
/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7: ./
src/main/java/org/apache/geronimo/tomcat/
Author: gawor
Date: Sun Jan 31 18:07:38 2010
New Revision: 905088
URL: http://svn.apache.org/viewvc?rev=905088&view=rev
Log:
fix bunch of Tomcat issues: 1) implement ServletContext.getResourcePaths() properly, 2) install jndi protocol handler (it's needed in some cases) and 3) make sure web.xml parsing is namespace aware
Added:
geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/JNDIURLStreamHandlerService.java (with props)
Modified:
geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/pom.xml
geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/BundleDirContext.java
geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
Modified: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/pom.xml?rev=905088&r1=905087&r2=905088&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/pom.xml (original)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/pom.xml Sun Jan 31 18:07:38 2010
@@ -106,6 +106,15 @@
<forkMode>pertest</forkMode>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Bundle-Activator>org.apache.geronimo.tomcat.JNDIURLStreamHandlerService</Bundle-Activator>
+ </instructions>
+ </configuration>
+ </plugin>
</plugins>
</build>
Modified: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/BundleDirContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/BundleDirContext.java?rev=905088&r1=905087&r2=905088&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/BundleDirContext.java (original)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/BundleDirContext.java Sun Jan 31 18:07:38 2010
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package org.apache.geronimo.tomcat;
import java.io.File;
@@ -27,7 +26,6 @@
import java.util.Iterator;
import java.util.Map;
import java.util.Enumeration;
-import java.util.NoSuchElementException;
import java.util.Map.Entry;
import java.net.URL;
@@ -55,13 +53,10 @@
/**
* Directory Context implementation helper class.
*
- * @author Remy Maucherat
* @version $Revision$ $Date$
*/
-
public class BundleDirContext implements DirContext {
-
private final Bundle bundle;
private final String path;
@@ -70,22 +65,6 @@
this.path = path;
}
- /**
- * Builds a base directory context.
- */
-// public BundleDirContext() {
-// this.env = new Hashtable<String,Object>();
-// }
-//
-//
-// /**
-// * Builds a base directory context using the given environment.
-// */
-// public BundleDirContext(Hashtable<String,Object> env) {
-// this.env = env;
-// }
-
-
// ----------------------------------------------------- Instance Variables
@@ -145,8 +124,7 @@
// ------------------------------------------------------------- Properties
-
-
+
/**
* Add an alias.
*/
@@ -567,11 +545,13 @@
*/
public NamingEnumeration<NameClassPair> list(String name)
throws NamingException {
- throw new OperationNotSupportedException();
-// String fullSearchPath = path + name;
-// //TODO figure out entries
-// Enumeration entries = bundle.findEntries(fullSearchPath, "", true);
-// return new NameClassPairEnumeration(entries);
+ name = getName(name);
+ Enumeration entries = bundle.getEntryPaths(name);
+ if (entries == null) {
+ throw new NamingException("Resource not found: " + name);
+ } else {
+ return new NameClassPairEnumeration(name, entries);
+ }
}
@@ -605,11 +585,13 @@
*/
public NamingEnumeration<Binding> listBindings(String name)
throws NamingException {
- throw new OperationNotSupportedException();
-// String fullSearchPath = path + name;
-// //TODO figure out entries
-// Enumeration entries = bundle.findEntries(fullSearchPath, "", true);
-// return new BindingEnumeration(entries);
+ name = getName(name);
+ Enumeration entries = bundle.getEntryPaths(name);
+ if (entries == null) {
+ throw new NamingException("Resource not found: " + name);
+ } else {
+ return new BindingEnumeration(bundle, name, entries);
+ }
}
@@ -1445,15 +1427,24 @@
}
protected Object doLookup(String name) throws NamingException {
- if (path != null) {
- name = path + name;
- }
+ name = getName(name);
+ // XXX: lookup on directory should return BundleDirContext?
URL url = bundle.getEntry(name);
if (url == null) {
throw new NamingException(sm.getString("resources.notFound", name));
}
return new URLResource(url);
}
+
+ private String getName(String name) {
+ if (name.startsWith("/")) {
+ name = name.substring(1);
+ }
+ if (path != null) {
+ name = path + name;
+ }
+ return name;
+ }
// protected abstract String doGetRealPath(String name);
@@ -1483,63 +1474,102 @@
String aliasName;
}
+ private static String getBasePath(String name) {
+ if (name != null && !name.endsWith("/")) {
+ return name + "/";
+ } else {
+ return name;
+ }
+ }
+
private static class NameClassPairEnumeration implements NamingEnumeration<NameClassPair> {
- public NameClassPairEnumeration(Enumeration entries) {
+
+ private String basePath;
+ private Enumeration entries;
+
+ public NameClassPairEnumeration(String basePath, Enumeration entries) {
+ this.basePath = getBasePath(basePath);
+ this.entries = entries;
}
-
- @Override
public NameClassPair next() throws NamingException {
- return null;
+ return nextElement();
}
- @Override
public boolean hasMore() throws NamingException {
- return false;
+ return hasMoreElements();
}
- @Override
public void close() throws NamingException {
}
- @Override
public boolean hasMoreElements() {
- return false;
+ return (entries != null && entries.hasMoreElements());
}
- @Override
public NameClassPair nextElement() {
- return null;
+ String name = (String) entries.nextElement();
+ String relativeName = getRelativeName(name);
+ if (name.endsWith("/")) {
+ return new Binding(relativeName, DirContext.class.getName());
+ } else {
+ return new Binding(relativeName, String.class.getName());
+ }
+ }
+
+ private String getRelativeName(String name) {
+ if (basePath != null && name.startsWith(basePath)) {
+ return name.substring(basePath.length());
+ } else {
+ return name;
+ }
}
}
+
private static class BindingEnumeration implements NamingEnumeration<Binding> {
- public BindingEnumeration(Enumeration entries) {
+
+ private Bundle bundle;
+ private String basePath;
+ private Enumeration entries;
+
+ public BindingEnumeration(Bundle bundle, String basePath, Enumeration entries) {
+ this.bundle = bundle;
+ this.basePath = getBasePath(basePath);
+ this.entries = entries;
}
-
- @Override
public Binding next() throws NamingException {
- return null;
+ return nextElement();
}
- @Override
public boolean hasMore() throws NamingException {
- return false;
+ return hasMoreElements();
}
- @Override
public void close() throws NamingException {
}
- @Override
public boolean hasMoreElements() {
- return false;
+ return (entries != null && entries.hasMoreElements());
}
- @Override
public Binding nextElement() {
- return null;
+ String name = (String) entries.nextElement();
+ String relativeName = getRelativeName(name);
+ if (name.endsWith("/")) {
+ return new Binding(relativeName, new BundleDirContext(bundle, name));
+ } else {
+ return new Binding(relativeName, relativeName);
+ }
}
+
+ private String getRelativeName(String name) {
+ if (basePath != null && name.startsWith(basePath)) {
+ return name.substring(basePath.length());
+ } else {
+ return name;
+ }
+ }
}
private static class URLResource extends Resource {
Modified: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java?rev=905088&r1=905087&r2=905088&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java (original)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java Sun Jan 31 18:07:38 2010
@@ -95,6 +95,7 @@
private ServiceRegistration serviceRegistration;
public GeronimoStandardContext() {
+ setXmlNamespaceAware(true);
}
public void setContextProperties(TomcatContext ctx) throws DeploymentException {
Added: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/JNDIURLStreamHandlerService.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/JNDIURLStreamHandlerService.java?rev=905088&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/JNDIURLStreamHandlerService.java (added)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/JNDIURLStreamHandlerService.java Sun Jan 31 18:07:38 2010
@@ -0,0 +1,55 @@
+/**
+ * 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.geronimo.tomcat;
+
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Hashtable;
+
+import javax.naming.directory.DirContext;
+
+import org.apache.naming.resources.DirContextURLConnection;
+import org.apache.naming.resources.DirContextURLStreamHandler;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.url.AbstractURLStreamHandlerService;
+import org.osgi.service.url.URLConstants;
+import org.osgi.service.url.URLStreamHandlerService;
+
+/**
+ * URL handler for "jndi" protocol.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JNDIURLStreamHandlerService extends AbstractURLStreamHandlerService implements BundleActivator {
+
+ public URLConnection openConnection(URL url) throws IOException {
+ DirContext currentContext = DirContextURLStreamHandler.get();
+ return new DirContextURLConnection(currentContext, url);
+ }
+
+ public void start(BundleContext context) throws Exception {
+ Hashtable properties = new Hashtable();
+ properties.put(URLConstants.URL_HANDLER_PROTOCOL, new String[] {"jndi"});
+ context.registerService(URLStreamHandlerService.class.getName(), this, properties);
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ }
+
+}
Propchange: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/JNDIURLStreamHandlerService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/JNDIURLStreamHandlerService.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/JNDIURLStreamHandlerService.java
------------------------------------------------------------------------------
svn:mime-type = text/plain