You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2009/11/26 07:47:04 UTC
svn commit: r884416 [1/2] - in
/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat: addons/
servlets/config/ servlets/config/deploy/ servlets/file/ servlets/jmx/
servlets/jsp/ servlets/jspc/ servlets/sec/ servlets/session/ servlets/util/
Author: costin
Date: Thu Nov 26 06:47:03 2009
New Revision: 884416
URL: http://svn.apache.org/viewvc?rev=884416&view=rev
Log:
Removed the 'addons' package, moved the interfaces close to the packages that define them, also
some code move around.
The web.xml parsing ( and some incipient 3.0 annotation processing ) is independent of tomcat, indended as
a user-library.
Added:
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/ConfigLoader.java (with props)
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/ServletContextConfig.java (with props)
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/AnnotationsProcessor.java (with props)
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/DomUtil.java (with props)
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/WarDeploy.java (with props)
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/WebXml.java (with props)
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/Filesystem.java (with props)
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/LocalFilesystem.java (with props)
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/jmx/
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/jmx/JMXProxyServlet.java (with props)
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/jmx/JmxObjectManagerSpi.java (with props)
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/jsp/BaseJspLoader.java (with props)
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/jspc/
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/jspc/JasperRuntime.java (with props)
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/jspc/JspcServlet.java (with props)
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/sec/UserAuthentication.java (with props)
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/session/UserSessionManager.java (with props)
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/Base64.java (with props)
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/FastHttpDateFormat.java (with props)
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/MimeMap.java (with props)
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/URLEncoder.java (with props)
Removed:
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/addons/Filesystem.java
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/addons/UserAuthentication.java
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/addons/UserSessionManager.java
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/addons/UserTemplateClassMapper.java
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/jsp/JasperCompilerTemplateClassMapper.java
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/jsp/JspFileTemplateServlet.java
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/jsp/SimpleTemplateClassMapper.java
Modified:
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/DefaultServlet.java
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/Dir2Html.java
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/WebdavServlet.java
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/jsp/WildcardTemplateServlet.java
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/sec/AccessFilter.java
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/sec/BasicAuthentication.java
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/sec/FormAuthentication.java
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/session/RandomGenerator.java
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/session/SimpleSessionManager.java
tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/RequestUtil.java
Added: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/ConfigLoader.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/ConfigLoader.java?rev=884416&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/ConfigLoader.java (added)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/ConfigLoader.java Thu Nov 26 06:47:03 2009
@@ -0,0 +1,32 @@
+/*
+ */
+package org.apache.tomcat.servlets.config;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+
+public class ConfigLoader {
+
+ public ServletContextConfig loadConfig(String basePath) {
+
+
+ String fileName = basePath + ServletContextConfig.SERIALIZED_PATH;
+ File f = new File(fileName);
+ if (f.exists()) {
+ ServletContextConfig contextConfig = new ServletContextConfig();
+ try {
+ ObjectInputStream ois = new ObjectInputStream(new FileInputStream(f));
+ contextConfig = (ServletContextConfig) ois.readObject();
+ return contextConfig;
+ } catch (Throwable e) {
+ System.err.println("Ignoring invalid .ser config " + e);
+ // ignore
+ }
+ }
+
+ return null;
+ }
+
+}
Propchange: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/ConfigLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/ServletContextConfig.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/ServletContextConfig.java?rev=884416&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/ServletContextConfig.java (added)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/ServletContextConfig.java Thu Nov 26 06:47:03 2009
@@ -0,0 +1,164 @@
+/**
+ *
+ */
+package org.apache.tomcat.servlets.config;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Struct representation of webapp configuration.
+ *
+ * All the data in web.xml, annotations, etc should be represented
+ * here. This class is serializable - but can be saved/loaded as
+ * json or any 'pojo' persistence.
+ *
+ *
+ * Public fields to make it easy to access it, we can add accessors.
+ * Naming should match the web.xml element name.
+ *
+ * @author Costin Manolache
+ */
+public class ServletContextConfig implements Serializable {
+
+ public static final String SERIALIZED_PATH = "/WEB-INF/deploy_web.ser";
+ private static final long serialVersionUID = 1728492145981883124L;
+
+ public static final int CURRENT_VERSION = 1;
+
+ public int version = CURRENT_VERSION;
+
+ /**
+ * Main config ( web.xml ) path and timestamp - touch it to reload.
+ */
+ public List<String> fileName = new ArrayList<String>();
+ public long timestamp;
+
+ public boolean full;
+
+ public String displayName;
+
+ public HashMap<String, String> contextParam = new HashMap<String, String>();
+
+ public HashMap<String, String> mimeMapping = new HashMap<String, String>(); // extension -> mime-type
+
+ public ArrayList<String> listenerClass = new ArrayList<String>();
+
+ public ArrayList<String> welcomeFileList = new ArrayList<String>();
+
+ // code -> location
+ public HashMap<String, String> errorPageCode= new HashMap<String, String>();
+
+ // exception -> location
+ public HashMap<String, String> errorPageException= new HashMap<String, String>();
+
+ public HashMap<String, String> localeEncodingMapping= new HashMap<String, String>(); // locale -> encoding
+
+ // public HashMap tagLibs; // uri->location
+ // jsp-property-group
+
+ // securityConstraint
+ public ArrayList<SecurityConstraintData> securityConstraint = new ArrayList<SecurityConstraintData>();
+
+ // loginConfig
+ public String authMethod;
+ public String realmName;
+ public String formLoginPage;
+ public String formErrorPage;
+
+ public ArrayList<String> securityRole = new ArrayList<String>();
+
+ // envEntry
+ public ArrayList<EnvEntryData> envEntry = new ArrayList<EnvEntryData>();
+
+ // ejbRef
+ // ejbLocalRef
+ // serviceRef
+ // resourceRef
+ // resourceEnvRef
+ // message-destination
+ // message-destinationRef
+ public HashMap<String, FilterData> filters = new HashMap<String, FilterData>();
+ public HashMap<String, ServletData> servlets = new HashMap<String, ServletData>();
+
+ public int sessionTimeout;
+ public boolean distributable;
+
+ public HashMap<String, String> servletMapping = new HashMap<String, String>(); // url -> servlet
+ public ArrayList<FilterMappingData> filterMappings = new ArrayList<FilterMappingData>();
+ public boolean metadataComplete = false;
+
+
+ // Normalized
+ public static class FilterMappingData implements Serializable {
+ private static final long serialVersionUID = -4533568066713041994L;
+ public String filterName;
+
+ // Only one of the 2
+ public String urlPattern;
+ public String servletName;
+
+ // REQUEST, FORWARD, INCLUDE, ERROR, ASYNC
+ public List<String> dispatcher = new ArrayList<String>();
+ }
+
+ public static class EnvEntryData implements Serializable {
+ private static final long serialVersionUID = 7023847615343715257L;
+ public String envEntryName;
+ public String envEntryType;
+ public String envEntryValue;
+ }
+
+ public static class ServiceData implements Serializable {
+ public String name;
+ public String className;
+
+ public Map<String, String> initParams = new HashMap<String, String>();
+
+ public boolean asyncSupported = false;
+ }
+
+ public static class FilterData extends ServiceData implements Serializable {
+ private static final long serialVersionUID = -535820271746973166L;
+ }
+
+ public static class ServletData extends ServiceData implements Serializable {
+ private static final long serialVersionUID = -3216904178501185930L;
+
+ public ServletData() {
+ }
+ public ServletData(String servletName, String servletClass) {
+ this.className = servletClass;
+ this.name = servletName;
+ }
+
+ public String jspFile;
+ public int loadOnStartup = -1;
+ public String runAs;
+ public Map<String, String> securityRoleRef = new HashMap<String, String>(); // roleName -> [roleLink]
+ public boolean multipartConfig = false;
+
+ public List<String> declaresRoles = new ArrayList<String>();
+
+ }
+
+ public static class WebResourceCollectionData implements Serializable {
+ public String webResourceName;
+ public ArrayList<String> urlPattern = new ArrayList<String>();
+ public ArrayList<String> httpMethod = new ArrayList<String>();
+ }
+
+ public static class SecurityConstraintData implements Serializable {
+ private static final long serialVersionUID = -4780214921810871769L;
+
+ public ArrayList<String> roleName = new ArrayList<String>(); // auth-constraint/role
+
+ public ArrayList<WebResourceCollectionData> webResourceCollection =
+ new ArrayList<WebResourceCollectionData>();
+ public String transportGuarantee;
+
+ }
+}
\ No newline at end of file
Propchange: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/ServletContextConfig.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/AnnotationsProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/AnnotationsProcessor.java?rev=884416&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/AnnotationsProcessor.java (added)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/AnnotationsProcessor.java Thu Nov 26 06:47:03 2009
@@ -0,0 +1,339 @@
+/*
+ */
+package org.apache.tomcat.servlets.config.deploy;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import org.apache.tomcat.servlets.config.ServletContextConfig;
+import org.apache.tomcat.servlets.config.ServletContextConfig.FilterData;
+import org.apache.tomcat.servlets.config.ServletContextConfig.FilterMappingData;
+import org.apache.tomcat.servlets.config.ServletContextConfig.ServiceData;
+import org.apache.tomcat.servlets.config.ServletContextConfig.ServletData;
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.Type;
+import org.objectweb.asm.tree.AnnotationNode;
+import org.objectweb.asm.tree.ClassNode;
+import org.objectweb.asm.tree.MethodNode;
+
+
+// TODO: move to 'tools' dir, don't include in runtime
+// ( same for xml processor ) - use binary
+//
+
+// TODO: stupid ordering rules - probably will require merging configs
+// and other ugliness.
+
+// TODO: the even more brain-damaged ServletContextInitializer and
+// HandlesTypes - which requires recording all annotations for all classes,
+// and worse - all the hierarchy to detect annotations on super.
+
+/**
+ * Post-compile or deploy tool: will scan classes and jars and
+ * generate an annotation file.
+ *
+ * Will process:
+ * - annotations - for each class
+ * - find tld descriptors
+ * - web.xml and fragments
+ *
+ * Output: a .ser file, for faster tomcat startup and a 'compete'
+ * web.xml file.
+ *
+ * Tomcat should not read all classes each time it starts, or
+ * depend on bcel at runtime.
+ *
+ * Servlet spec makes the worst use of annotations by requiring
+ * scanning all classes. This should be a compile-time tool only !
+ *
+ * @author Costin Manolache
+ */
+public class AnnotationsProcessor {
+
+ String baseDir;
+ ServletContextConfig cfg;
+
+
+
+ public AnnotationsProcessor(ServletContextConfig cfg2) {
+ this.cfg = cfg2;
+ }
+
+ public void processWebapp(String baseN) throws IOException {
+ if (!baseN.endsWith("/")) {
+ baseN = baseN + "/";
+ }
+ processDir(baseN + "classes");
+
+ File lib = new File(baseN + "lib");
+ if (!lib.isDirectory()) {
+ return;
+ }
+ File[] files = lib.listFiles();
+ if (files == null) {
+ return;
+ }
+
+ for (File f: files) {
+ if (!f.isDirectory() && f.getName().endsWith(".jar")) {
+ processJar(f.getCanonicalPath());
+ }
+ }
+ }
+
+ public void processJar(String path) throws IOException {
+ JarFile jar = new JarFile(path);
+ Enumeration<JarEntry> entries = jar.entries();
+ while (entries.hasMoreElements()) {
+ JarEntry entry = entries.nextElement();
+ String name = entry.getName();
+ if (name.endsWith(".class")) {
+ processClass(jar.getInputStream(entry),
+ "", name);
+ } else if (name.equals("META-INF/services/javax.servlet.ServletContainerInitializer")) {
+
+ }
+
+ }
+ }
+
+ public void processDir(String base) throws IOException {
+ // TODO: keep track of files to avoid loops
+ processDir(new File(base));
+ }
+
+ public void processDir(File base) throws IOException {
+ if (!base.isDirectory()) {
+ return;
+ }
+ String baseN = base.getCanonicalPath();
+ if (!baseN.endsWith("/")) {
+ baseN = baseN + "/";
+ }
+
+ File[] files = base.listFiles();
+ if (files != null) {
+ for (File f: files) {
+ if (f.isDirectory()) {
+ System.err.println(f);
+ processDir(f);
+ } else if (f.getName().endsWith(".class")) {
+ try {
+ processClass(new FileInputStream(f), base.getCanonicalPath(),
+ f.getCanonicalPath());
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ }
+
+ private static Map<String, Object> asmList2Map(List list) {
+ Map<String, Object> values = new HashMap();
+ for (int i = 0; i < list.size(); i+= 2) {
+ String name = (String) list.get(i);
+ Object val = list.get(i + 1);
+ values.put(name, val);
+ }
+ return values;
+ }
+
+ private static Map<String, AnnotationNode> annotationMap(List annL) {
+ Map<String, AnnotationNode> values = new HashMap();
+ if (annL != null) {
+ for (Object annO: annL) {
+ AnnotationNode ann = (AnnotationNode) annO;
+ String name = Type.getType(ann.desc).toString();
+ values.put(name, ann);
+ }
+ }
+ return values;
+ }
+
+
+
+ public void processClass(InputStream classStream,
+ String base,
+ String classFile) throws IOException {
+ String classPath = classFile.substring(base.length() + 1);
+ classPath = classPath.substring(0, classPath.length() - ".class".length());
+ classPath = classPath.replace("/", ".");
+
+ ClassReader classReader = new ClassReader(classStream);
+ ClassNode cN = new ClassNode();
+ classReader.accept(cN,
+ ClassReader.SKIP_CODE + ClassReader.SKIP_DEBUG + ClassReader.SKIP_FRAMES);
+
+ String className = cN.name;
+
+ Map<String, AnnotationNode> annotations = annotationMap(cN.visibleAnnotations);
+
+ processServlets(className, annotations, cN);
+ processWebFilter(className, annotations);
+
+ AnnotationNode listenerA = annotations.get("javax.servlet.annotation.WebListener");
+ if (listenerA != null) {
+ // TODO: checks
+ cfg.listenerClass.add(className);
+ }
+
+
+// for (AnnotationNode mN : annotations.values()) {
+// String ann = Type.getType(mN.desc).toString();
+// Map<String, Object> values = asmList2Map(mN.values);
+//
+// if ("javax.servlet.annotation.HandlesTypes".equals(ann)) {
+// } else if ("javax.servlet.annotation.MultipartConfig".equals(ann)) {
+// } else if ("javax.annotation.security.RunAs".equals(ann)) {
+// } else if ("javax.annotation.security.DeclareRoles".equals(ann)) {
+// } else if ("javax.annotation.security.RolesAllowed".equals(ann)) {
+// } else if ("javax.annotation.security.DenyAll".equals(ann)) {
+// } else if ("javax.annotation.security.PermitAll".equals(ann)) {
+// } else if ("javax.servlet.annotation.WebFilter".equals(ann)) {
+// } else if ("javax.servlet.annotation.WebServlet".equals(ann)) {
+// // in WebServlet
+// } else if ("javax.servlet.annotation.WebListener".equals(ann)) {
+// } else if ("javax.servlet.annotation.WebInitParam".equals(ann)) {
+// // In WebServlet, (WebFilter)
+// } else {
+// System.err.println("\n" + className + " " + Type.getType(mN.desc));
+// }
+// }
+
+ }
+
+ private void processServlets(String className,
+ Map<String, AnnotationNode> annotations, ClassNode cn) {
+
+ AnnotationNode webServletA =
+ annotations.get("javax.servlet.annotation.WebServlet");
+ if (webServletA != null) {
+ ServletData sd = new ServletData();
+ // TODO: validity checks (implements servlet, etc)
+ Map<String, Object> params = asmList2Map(webServletA.values);
+
+ processService(className, webServletA,
+ sd, params);
+
+ if (params.containsKey("loadOnStartup")) {
+ sd.loadOnStartup = (Integer)params.get("loadOnStartup");
+ }
+ if (annotations.get("javax.servlet.annotation.MultipartConfig") != null) {
+ sd.multipartConfig = true;
+ }
+
+ AnnotationNode declareA = annotations.get("javax.annotation.security.DeclareRoles");
+ if (declareA != null) {
+ Map<String, Object> runAsParams = asmList2Map(declareA.values);
+ ArrayList roles = (ArrayList) runAsParams.get("value");
+ for (Object r: roles) {
+ sd.declaresRoles.add((String) r);
+ }
+ }
+
+ AnnotationNode runAsA = annotations.get("javax.annotation.security.RunAs");
+ if (runAsA != null) {
+ Map<String, Object> runAsParams = asmList2Map(runAsA.values);
+
+ sd.runAs = (String) runAsParams.get("value");
+ }
+
+ cfg.servlets.put(sd.name, sd);
+
+ ArrayList urls = (ArrayList) params.get("urlPatterns");
+ if (urls == null) {
+ urls = (ArrayList) params.get("value");
+ }
+
+ for (Object urlO: urls) {
+ cfg.servletMapping.put((String) urlO,
+ sd.name);
+ }
+
+ // TODO: collect them, add on each of the URLs
+ // TODO: also on methods
+ AnnotationNode rolesA = annotations.get("javax.annotation.security.RolesAllowed");
+ if (rolesA != null) {
+
+ }
+ for (Object o: cn.methods) {
+ MethodNode methodNode = (MethodNode) o;
+ System.err.println(methodNode.desc);
+ }
+
+
+
+ }
+ }
+
+ private void processWebFilter(String className,
+ Map<String, AnnotationNode> annotations) {
+ AnnotationNode webFilterA = annotations.get("javax.servlet.annotation.WebServlet");
+ if (webFilterA != null) {
+ // TODO: validity checks (implements servlet, etc)
+
+ FilterData sd = new FilterData();
+ Map<String, Object> params = asmList2Map(webFilterA.values);
+
+ processService(className, webFilterA, sd, params);
+
+ if (params.containsKey("asyncSupported")) {
+ sd.asyncSupported = (Boolean) params.get("asyncSupported");
+ }
+
+ cfg.filters.put(sd.name, sd);
+
+ ArrayList urls = (ArrayList) params.get("urlPatterns");
+ if (urls == null) {
+ urls = (ArrayList) params.get("value");
+ }
+ for (Object urlO: urls) {
+ FilterMappingData fmap = new FilterMappingData();
+ fmap.filterName = sd.name;
+ fmap.urlPattern = (String) urlO;
+
+ cfg.filterMappings.add(fmap);
+ }
+ }
+ }
+
+ private ServiceData processService(String className,
+ AnnotationNode webServletA, ServiceData sd, Map<String, Object> params) {
+
+ sd.name = (String) params.get("name");
+ if (sd.name == null) {
+ sd.name = className;
+ }
+ sd.className = className;
+
+ if (params.containsKey("initParams")) {
+ ArrayList initParamL = (ArrayList) params.get("initParams");
+ for (Object initParamO: initParamL) {
+ AnnotationNode initParamA = (AnnotationNode) initParamO;
+
+ Map<String, Object> initParams = asmList2Map(initParamA.values);
+ sd.initParams.put((String) initParams.get("name"),
+ (String) initParams.get("value"));
+ }
+ }
+
+ if (params.containsKey("asyncSupported")) {
+ sd.asyncSupported = (Boolean) params.get("asyncSupported");
+ }
+ return sd;
+ }
+
+
+}
Propchange: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/AnnotationsProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/DomUtil.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/DomUtil.java?rev=884416&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/DomUtil.java (added)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/DomUtil.java Thu Nov 26 06:47:03 2009
@@ -0,0 +1,240 @@
+package org.apache.tomcat.servlets.config.deploy;
+
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.util.logging.Logger;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+
+/**
+ * Few simple utils to read DOM
+ *
+ * @author Costin Manolache
+ */
+public class DomUtil {
+ private static Logger log=
+ Logger.getLogger( DomUtil.class.getName() );
+
+ // -------------------- DOM utils --------------------
+
+ /** Get the trimed text content of a node or null if there is no text
+ */
+ public static String getContent(Node n ) {
+ if( n==null ) return null;
+ Node n1=DomUtil.getChild(n, Node.TEXT_NODE);
+
+ if( n1==null ) return null;
+
+ String s1=n1.getNodeValue();
+ return s1.trim();
+ }
+
+ /** Get the first element child.
+ * @param parent lookup direct childs
+ * @param name name of the element. If null return the first element.
+ */
+ public static Node getChild( Node parent, String name ) {
+ if( parent==null ) return null;
+ Node first=parent.getFirstChild();
+ if( first==null ) return null;
+
+ for (Node node = first; node != null;
+ node = node.getNextSibling()) {
+ //System.out.println("getNode: " + name + " " + node.getNodeName());
+ if( node.getNodeType()!=Node.ELEMENT_NODE)
+ continue;
+ if( name != null &&
+ name.equals( node.getNodeName() ) ) {
+ return node;
+ }
+ if( name == null ) {
+ return node;
+ }
+ }
+ return null;
+ }
+
+ public static String getAttribute(Node element, String attName ) {
+ NamedNodeMap attrs=element.getAttributes();
+ if( attrs==null ) return null;
+ Node attN=attrs.getNamedItem(attName);
+ if( attN==null ) return null;
+ return attN.getNodeValue();
+ }
+
+ public static void setAttribute(Node node, String attName, String val) {
+ NamedNodeMap attributes=node.getAttributes();
+ Node attNode=node.getOwnerDocument().createAttribute(attName);
+ attNode.setNodeValue( val );
+ attributes.setNamedItem(attNode);
+ }
+
+ public static void removeAttribute( Node node, String attName ) {
+ NamedNodeMap attributes=node.getAttributes();
+ attributes.removeNamedItem(attName);
+ }
+
+
+ /** Set or replace the text value
+ */
+ public static void setText(Node node, String val) {
+ Node chld=DomUtil.getChild(node, Node.TEXT_NODE);
+ if( chld == null ) {
+ Node textN=node.getOwnerDocument().createTextNode(val);
+ node.appendChild(textN);
+ return;
+ }
+ // change the value
+ chld.setNodeValue(val);
+ }
+
+ /** Find the first direct child with a given attribute.
+ * @param parent
+ * @param elemName name of the element, or null for any
+ * @param attName attribute we're looking for
+ * @param attVal attribute value or null if we just want any
+ */
+ public static Node findChildWithAtt(Node parent, String elemName,
+ String attName, String attVal) {
+
+ Node child=DomUtil.getChild(parent, Node.ELEMENT_NODE);
+ if( attVal== null ) {
+ while( child!= null &&
+ ( elemName==null || elemName.equals( child.getNodeName())) &&
+ DomUtil.getAttribute(child, attName) != null ) {
+ child=getNext(child, elemName, Node.ELEMENT_NODE );
+ }
+ } else {
+ while( child!= null &&
+ ( elemName==null || elemName.equals( child.getNodeName())) &&
+ ! attVal.equals( DomUtil.getAttribute(child, attName)) ) {
+ child=getNext(child, elemName, Node.ELEMENT_NODE );
+ }
+ }
+ return child;
+ }
+
+
+ /** Get the first child's content ( ie it's included TEXT node ).
+ */
+ public static String getChildContent( Node parent, String name ) {
+ Node first=parent.getFirstChild();
+ if( first==null ) return null;
+ for (Node node = first; node != null;
+ node = node.getNextSibling()) {
+ //System.out.println("getNode: " + name + " " + node.getNodeName());
+ if( name.equals( node.getNodeName() ) ) {
+ return getContent( node );
+ }
+ }
+ return null;
+ }
+
+ /** Get the first direct child with a given type
+ */
+ public static Node getChild( Node parent, int type ) {
+ Node n=parent.getFirstChild();
+ while( n!=null && type != n.getNodeType() ) {
+ n=n.getNextSibling();
+ }
+ if( n==null ) return null;
+ return n;
+ }
+
+ /** Get the next sibling with the same name and type
+ */
+ public static Node getNext( Node current ) {
+ String name=current.getNodeName();
+ int type=current.getNodeType();
+ return getNext( current, name, type);
+ }
+
+ /** Return the next sibling with a given name and type
+ */
+ public static Node getNext( Node current, String name, int type) {
+ Node first=current.getNextSibling();
+ if( first==null ) return null;
+
+ for (Node node = first; node != null;
+ node = node.getNextSibling()) {
+
+ if( type >= 0 && node.getNodeType() != type ) continue;
+ //System.out.println("getNode: " + name + " " + node.getNodeName());
+ if( name==null )
+ return node;
+ if( name.equals( node.getNodeName() ) ) {
+ return node;
+ }
+ }
+ return null;
+ }
+
+ public static class NullResolver implements EntityResolver {
+ public InputSource resolveEntity (String publicId,
+ String systemId)
+ throws SAXException, IOException
+ {
+// if( log.isTraceEnabled())
+// log.trace("ResolveEntity: " + publicId + " " + systemId);
+ return new InputSource(new StringReader(""));
+ }
+ }
+
+// public static void setAttributes( Object o, Node parent)
+// {
+// NamedNodeMap attrs=parent.getAttributes();
+// if( attrs==null ) return;
+//
+// for (int i=0; i<attrs.getLength(); i++ ) {
+// Node n=attrs.item(i);
+// String name=n.getNodeName();
+// String value=n.getNodeValue();
+//
+//// if( log.isTraceEnabled() )
+//// log.trace("Attribute " + parent.getNodeName() + " " +
+//// name + "=" + value);
+// try {
+// IntrospectionUtils.setProperty(o, name, value);
+// } catch( Exception ex ) {
+// ex.printStackTrace();
+// }
+// }
+// }
+
+ /** Read XML as DOM.
+ */
+ public static Document readXml(InputStream is)
+ throws SAXException, IOException, ParserConfigurationException
+ {
+ DocumentBuilderFactory dbf =
+ DocumentBuilderFactory.newInstance();
+
+ dbf.setValidating(false);
+ dbf.setIgnoringComments(false);
+ dbf.setIgnoringElementContentWhitespace(true);
+ //dbf.setCoalescing(true);
+ //dbf.setExpandEntityReferences(true);
+
+ DocumentBuilder db = null;
+ db = dbf.newDocumentBuilder();
+ db.setEntityResolver( new NullResolver() );
+
+ // db.setErrorHandler( new MyErrorHandler());
+
+ Document doc = db.parse(is);
+ return doc;
+ }
+
+}
Propchange: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/DomUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/WarDeploy.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/WarDeploy.java?rev=884416&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/WarDeploy.java (added)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/WarDeploy.java Thu Nov 26 06:47:03 2009
@@ -0,0 +1,116 @@
+/*
+ */
+package org.apache.tomcat.servlets.config.deploy;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+
+import org.apache.tomcat.servlets.config.ConfigLoader;
+import org.apache.tomcat.servlets.config.ServletContextConfig;
+
+/**
+ * Independent of tomcat-lite - will read the current context config,
+ * parse classes/jars for annotations - and generate a .ser file
+ * containing all info.
+ *
+ * This can be used to display informations about the config ( in a
+ * container-independent servlet ), or by the container for faster
+ * load times.
+ *
+ * @author Costin Manolache
+ */
+public class WarDeploy extends ConfigLoader implements Runnable {
+
+ public ServletContextConfig loadConfig(String basePath) {
+ ServletContextConfig contextConfig = super.loadConfig(basePath);
+
+ boolean needsDeploy = contextConfig == null;
+
+ if (contextConfig != null) {
+ if (contextConfig.version != ServletContextConfig.CURRENT_VERSION) {
+ needsDeploy = true;
+ } else {
+ // Check web.xml and other dep file timestamp(s)
+ for (String fn : contextConfig.fileName) {
+ File f = new File(fn);
+ if (f.lastModified() > contextConfig.timestamp) {
+ needsDeploy = true;
+ break;
+ }
+ }
+ }
+ }
+
+ if (needsDeploy) {
+ setBase(basePath);
+ run();
+ contextConfig = super.loadConfig(basePath);
+ }
+
+ return contextConfig;
+ }
+
+ @Override
+ public void run() {
+ if (base == null) {
+ return; // nothing we can do
+ }
+
+ ServletContextConfig contextConfig = new ServletContextConfig();
+ contextConfig.timestamp = System.currentTimeMillis();
+
+ File webXmlF = new File(base + "/WEB-INF/web.xml");
+ boolean needsAnnotations = true;
+
+ if (webXmlF.exists()) {
+ WebXml webXml = new WebXml(contextConfig);
+ try {
+ webXml.readWebXml(base + "/WEB-INF/web.xml");
+ if (contextConfig.metadataComplete) {
+ needsAnnotations = false;
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ try {
+ if (needsAnnotations) {
+ AnnotationsProcessor ap = new AnnotationsProcessor(contextConfig);
+ ap.processWebapp(base);
+ }
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+
+
+ // Save
+ try {
+ ObjectOutputStream ois =
+ new ObjectOutputStream(new FileOutputStream(base +
+ ServletContextConfig.SERIALIZED_PATH));
+ ois.writeObject(contextConfig);
+ ois.close();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ String base;
+
+
+ public static void main(String[] args) {
+ String base = args[0];
+ WarDeploy wd = new WarDeploy();
+ wd.setBase(base);
+ wd.run();
+ }
+
+ private void setBase(String base) {
+ this.base = base;
+ }
+
+}
Propchange: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/WarDeploy.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/WebXml.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/WebXml.java?rev=884416&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/WebXml.java (added)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/WebXml.java Thu Nov 26 06:47:03 2009
@@ -0,0 +1,397 @@
+/*
+ */
+package org.apache.tomcat.servlets.config.deploy;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import javax.servlet.ServletException;
+
+import org.apache.tomcat.servlets.config.ServletContextConfig;
+import org.apache.tomcat.servlets.config.ServletContextConfig.EnvEntryData;
+import org.apache.tomcat.servlets.config.ServletContextConfig.FilterData;
+import org.apache.tomcat.servlets.config.ServletContextConfig.FilterMappingData;
+import org.apache.tomcat.servlets.config.ServletContextConfig.SecurityConstraintData;
+import org.apache.tomcat.servlets.config.ServletContextConfig.ServletData;
+import org.apache.tomcat.servlets.config.ServletContextConfig.WebResourceCollectionData;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * General-purpose utility to process an web.xml file. Result
+ * is a tree of objects starting with WebAppData.
+ *
+ * TODO: allow writting of web.xml, allow modification ( preserving
+ * comments )
+ *
+ * @author costin
+ */
+public class WebXml {
+ ServletContextConfig d;
+
+ public WebXml(ServletContextConfig cfg) {
+ d = cfg;
+ }
+
+ public void processJar(String path) throws IOException {
+ JarFile jar = new JarFile(path);
+ Enumeration<JarEntry> entries = jar.entries();
+ while (entries.hasMoreElements()) {
+ JarEntry entry = entries.nextElement();
+ String name = entry.getName();
+ if (name.equals("META-INF/web-fragment.xml")) {
+ processFragment(jar.getInputStream(entry));
+ }
+ }
+ }
+
+ private void processFragment(InputStream inputStream) throws IOException {
+ readWebXml(inputStream, "web-fragment");
+
+ }
+
+ public void readWebXml(String baseDir) throws IOException {
+ readWebXml(baseDir, "web-app");
+ }
+
+ public void readWebXml(String baseDir, String topName) throws IOException {
+ try {
+ File webXmlFile = new File(baseDir);
+ if (!webXmlFile.exists()) {
+ return;
+ }
+ d.fileName.add(webXmlFile.getCanonicalPath());
+
+ FileInputStream fileInputStream = new FileInputStream(webXmlFile);
+ readWebXml(fileInputStream, topName);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new IOException(e.getMessage());
+ }
+ }
+
+ public void readWebXml(InputStream fileInputStream, String topName)
+ throws IOException {
+ try {
+
+ Document document = DomUtil.readXml(fileInputStream);
+ Node webappNode = DomUtil.getChild(document, topName);
+
+ String fullS = DomUtil.getAttribute(webappNode, "full");
+ if (fullS != null && fullS.equalsIgnoreCase("true")) {
+ d.full = true;
+ }
+ String metaCompleteS = DomUtil.getAttribute(webappNode, "full");
+ if ("true".equalsIgnoreCase(metaCompleteS)) {
+ d.metadataComplete = true;
+ }
+
+ d.displayName = DomUtil.getAttribute(webappNode, "display-name");
+
+ // Process each child of web-app
+ Node confNode = DomUtil.getChild(webappNode, "filter");
+ while (confNode != null ) {
+ processFilter(confNode);
+ confNode = DomUtil.getNext(confNode);
+ }
+
+ confNode = DomUtil.getChild(webappNode, "filter-mapping");
+ while (confNode != null ) {
+ processFilterMapping(confNode);
+ confNode = DomUtil.getNext(confNode);
+ }
+
+ confNode = DomUtil.getChild(webappNode, "context-param");
+ while (confNode != null ) {
+ String n = DomUtil.getChildContent(confNode, "param-name").trim();
+ String v = DomUtil.getChildContent(confNode, "param-value").trim();
+ d.contextParam.put(n, v);
+ confNode = DomUtil.getNext(confNode);
+ }
+
+ confNode = DomUtil.getChild(webappNode, "mime-mapping");
+ while (confNode != null ) {
+ String n = DomUtil.getChildContent(confNode, "extension");
+ String t = DomUtil.getChildContent(confNode, "mime-type");
+ d.mimeMapping.put(n, t);
+ confNode = DomUtil.getNext(confNode);
+ }
+
+ confNode = DomUtil.getChild(webappNode, "error-page");
+ while (confNode != null ) {
+ processErrorPage(confNode);
+ confNode = DomUtil.getNext(confNode);
+ }
+
+ confNode = DomUtil.getChild(webappNode, "jsp-config");
+ while (confNode != null ) {
+ processJspConfig(confNode);
+ confNode = DomUtil.getNext(confNode);
+ }
+
+ confNode = DomUtil.getChild(webappNode, "servlet");
+ while (confNode != null ) {
+ processServlet(confNode);
+ confNode = DomUtil.getNext(confNode);
+ }
+
+ confNode = DomUtil.getChild(webappNode, "servlet-mapping");
+ while (confNode != null ) {
+ processServletMapping(confNode);
+ confNode = DomUtil.getNext(confNode);
+ }
+
+ confNode = DomUtil.getChild(webappNode, "listener");
+ while (confNode != null ) {
+ String lClass = DomUtil.getChildContent(confNode, "listener-class");
+ d.listenerClass.add(lClass);
+ confNode = DomUtil.getNext(confNode);
+ }
+
+ confNode = DomUtil.getChild(webappNode, "security-constraint");
+ while (confNode != null ) {
+ processSecurityConstraint(confNode);
+ confNode = DomUtil.getNext(confNode);
+ }
+
+ confNode = DomUtil.getChild(webappNode, "login-config");
+ while (confNode != null ) {
+ processLoginConfig(confNode);
+ confNode = DomUtil.getNext(confNode);
+ if (confNode != null)
+ throw new ServletException("Multiple login-config");
+ }
+
+ confNode = DomUtil.getChild(webappNode, "session-config");
+ while (confNode != null ) {
+ String n = DomUtil.getChildContent(confNode, "session-timeout");
+ int stout = Integer.parseInt(n);
+ d.sessionTimeout = stout;
+ confNode = DomUtil.getNext(confNode);
+ if (confNode != null)
+ throw new ServletException("Multiple session-config");
+ }
+
+ confNode = DomUtil.getChild(webappNode, "welcome-file-list");
+ while (confNode != null ) {
+ Node wf = DomUtil.getChild(confNode, "welcome-file");
+ while (wf != null) {
+ String file = DomUtil.getContent(wf);
+ d.welcomeFileList.add(file);
+ wf = DomUtil.getNext(wf);
+ }
+ // more sections ?
+ confNode = DomUtil.getNext(confNode);
+ }
+
+ // Not supported right now - TODO: collect, have jndi plugin
+ confNode = DomUtil.getChild(webappNode, "env-entry");
+ while (confNode != null ) {
+ processEnvEntry(confNode);
+ confNode = DomUtil.getNext(confNode);
+ }
+
+ confNode = DomUtil.getChild(webappNode, "locale-encoding-mapping-list");
+ while (confNode != null ) {
+ confNode = DomUtil.getNext(confNode);
+ String n = DomUtil.getChildContent(confNode, "locale");
+ String t = DomUtil.getChildContent(confNode, "encoding");
+ d.localeEncodingMapping.put(n, t);
+ }
+
+ confNode = DomUtil.getChild(webappNode, "distributable");
+ while (confNode != null ) {
+ d.distributable = true;
+ confNode = DomUtil.getNext(confNode);
+ }
+
+ confNode = DomUtil.getChild(confNode, "security-role");
+ while (confNode != null ) {
+ String n = DomUtil.getChildContent(confNode, "role-name");
+ d.securityRole.add(n);
+ confNode = DomUtil.getNext(confNode);
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new IOException(e.getMessage());
+ }
+ }
+
+ private void processJspConfig(Node confNode) {
+ Node tagLib = DomUtil.getChild(confNode, "taglib");
+ while (tagLib != null) {
+ String uri = DomUtil.getChildContent(tagLib, "taglib-uri");
+ String l = DomUtil.getChildContent(tagLib, "taglib-location");
+ //d.tagLibs.put(uri, l);
+ tagLib = DomUtil.getNext(tagLib);
+ }
+
+ tagLib = DomUtil.getChild(confNode, "jsp-property-group");
+ while (tagLib != null) {
+ // That would be the job of the JSP servlet to process.
+ tagLib = DomUtil.getNext(tagLib);
+ }
+ }
+
+ private void processEnvEntry(Node confNode) {
+ EnvEntryData ed = new EnvEntryData();
+ ed.envEntryName = DomUtil.getChildContent(confNode,"env-entry-name");
+ ed.envEntryType = DomUtil.getChildContent(confNode,"env-entry-type");
+ ed.envEntryValue = DomUtil.getChildContent(confNode,"env-entry-value");
+ d.envEntry.add(ed);
+ }
+
+ private void processLoginConfig(Node confNode) {
+ d.authMethod = DomUtil.getChildContent(confNode,"auth-method");
+ d.realmName = DomUtil.getChildContent(confNode,"auth-method");
+ Node formNode = DomUtil.getChild(confNode, "form-login-config");
+ if (formNode != null) {
+ d.formLoginPage = DomUtil.getChildContent(formNode,"form-login-page");
+ d.formErrorPage = DomUtil.getChildContent(formNode,"form-error-page");
+ }
+ }
+
+ private void processSecurityConstraint(Node confNode) {
+ SecurityConstraintData sd = new SecurityConstraintData();
+ Node cn = DomUtil.getChild(confNode, "web-resource-collection");
+ while (cn != null) {
+ WebResourceCollectionData wrd = new WebResourceCollectionData();
+ wrd.webResourceName = DomUtil.getChildContent(cn, "web-resource-name");
+ Node scn = DomUtil.getChild(cn,"url-pattern");
+ while (scn != null) {
+ wrd.urlPattern.add(DomUtil.getContent(scn));
+ scn = DomUtil.getNext(scn);
+ }
+ scn = DomUtil.getChild(cn,"http-method");
+ while (scn != null) {
+ wrd.httpMethod.add(DomUtil.getContent(scn));
+ scn = DomUtil.getNext(scn);
+ }
+ cn = DomUtil.getNext(cn);
+ sd.webResourceCollection.add(wrd);
+ }
+
+ d.securityConstraint.add(sd);
+ }
+
+ private void processErrorPage(Node confNode) {
+ String name = DomUtil.getChildContent(confNode,"location");
+ String c = DomUtil.getChildContent(confNode,"error-code");
+ String t = DomUtil.getChildContent(confNode,"exception-type");
+ if (c != null) {
+ d.errorPageCode.put(c, name);
+ }
+ if (t != null) {
+ d.errorPageException.put(t, name);
+ }
+ }
+
+ private void processServlet(Node confNode) throws ServletException {
+ ServletData sd = new ServletData();
+
+ sd.name = DomUtil.getChildContent(confNode,"servlet-name");
+ sd.className = DomUtil.getChildContent(confNode,"servlet-class");
+ sd.jspFile = DomUtil.getChildContent(confNode,"jsp-file");
+
+ processInitParams(confNode, sd.initParams);
+
+ d.servlets.put( sd.name, sd );
+
+ String los = DomUtil.getChildContent(confNode, "load-on-startup");
+ if (los != null ) {
+ sd.loadOnStartup = Integer.parseInt(los);
+ }
+
+ Node sn = DomUtil.getChild(confNode, "security-role-ref");
+ while (sn != null ) {
+ String roleName = DomUtil.getChildContent(sn, "role-name");
+ String roleLink = DomUtil.getChildContent(sn, "role-link");
+ if (roleLink == null) {
+ sd.securityRoleRef.put(roleName, "");
+ } else {
+ sd.securityRoleRef.put(roleName, roleLink);
+ }
+ sn = DomUtil.getNext(sn);
+ }
+ }
+
+ private void processInitParams(Node confNode, Map initParams) {
+ Node initN = DomUtil.getChild(confNode, "init-param");
+ while (initN != null ) {
+ String n = DomUtil.getChildContent(initN, "param-name");
+ String v = DomUtil.getChildContent(initN, "param-value");
+ initParams.put(n, v);
+ initN = DomUtil.getNext(initN);
+ }
+ }
+
+ private void processServletMapping(Node confNode) {
+ String name = DomUtil.getChildContent(confNode,"servlet-name");
+ Node dataN = DomUtil.getChild(confNode, "url-pattern");
+ while (dataN != null) {
+ String path = DomUtil.getContent(dataN).trim();
+ dataN = DomUtil.getNext(dataN);
+
+ if (! (path.startsWith("/") || path.startsWith("*"))) {
+ // backward compat
+ path = "/" + path;
+ }
+ d.servletMapping.put(path, name);
+ }
+ }
+
+ private void processFilterMapping(Node confNode) {
+ String filterName = DomUtil.getChildContent(confNode,"filter-name");
+ // multiple
+ ArrayList dispatchers = new ArrayList();
+ Node dataN = DomUtil.getChild(confNode, "dispatcher");
+ while (dataN != null ) {
+ String d = DomUtil.getContent(dataN);
+ dispatchers.add(d);
+ dataN = DomUtil.getNext(dataN);
+ }
+
+ // Multiple url-pattern and servlet-name in one
+ // mapping rule. Need to be applied in order.
+ dataN = DomUtil.getChild(confNode, "url-pattern");
+ while (dataN != null ) {
+ FilterMappingData fm = new FilterMappingData();
+ fm.filterName = filterName;
+ fm.dispatcher = dispatchers;
+ String path = DomUtil.getContent(dataN);
+ dataN = DomUtil.getNext(dataN);
+ fm.urlPattern = path;
+ d.filterMappings.add(fm);
+ }
+ dataN = DomUtil.getChild(confNode, "servlet-name");
+ while (dataN != null ) {
+ FilterMappingData fm = new FilterMappingData();
+ fm.filterName = filterName;
+ fm.dispatcher = dispatchers;
+ String sn = DomUtil.getContent(dataN);
+ dataN = DomUtil.getNext(dataN);
+ fm.servletName = sn;
+ d.filterMappings.add(fm);
+ }
+ }
+
+ private void processFilter(Node confNode) {
+ String name = DomUtil.getChildContent(confNode,"filter-name");
+ String sclass = DomUtil.getChildContent(confNode,"filter-class");
+
+ FilterData fd = new FilterData();
+ processInitParams(confNode, fd.initParams);
+ fd.name = name;
+ fd.className = sclass;
+ d.filters.put(name, fd);
+ }
+
+}
Propchange: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/config/deploy/WebXml.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/DefaultServlet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/DefaultServlet.java?rev=884416&r1=884415&r2=884416&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/DefaultServlet.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/DefaultServlet.java Thu Nov 26 06:47:03 2009
@@ -40,11 +40,8 @@
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
-import org.apache.tomcat.addons.Filesystem;
-import org.apache.tomcat.integration.ObjectManager;
-import org.apache.tomcat.integration.simple.ServletHelper;
import org.apache.tomcat.servlets.util.Range;
+import org.apache.tomcat.servlets.util.URLEncoder;
/**
* The default resource-serving servlet for most web applications,
@@ -126,8 +123,6 @@
// --------------------------------------------------------- Public Methods
-
- protected ObjectManager om;
protected Filesystem fs;
/**
@@ -135,14 +130,15 @@
*/
public void destroy() {
}
-
-
+
/**
* Initialize this servlet.
*/
public void init() throws ServletException {
- om = ServletHelper.getObjectManager(getServletContext());
- fs = (Filesystem) om.get(Filesystem.class.getName());
+ if (fs == null) {
+ // R/O - no write
+ fs = new Filesystem();
+ }
String realPath = getServletContext().getRealPath("/");
basePath = new File(realPath);
@@ -517,9 +513,8 @@
&& (request.getHeader("Range") == null) )
|| (ranges == FULL) ) {
- processFullFile(response, content, resFile, contentType,
- contentLength, ostream, writer);
-
+ processSingleRange(response, content, resFile, contentType,
+ ostream, writer, ranges, contentLength);
} else {
if ((ranges == null) || (ranges.isEmpty()))
@@ -531,7 +526,7 @@
if (ranges.size() == 1) {
processSingleRange(response, content, resFile, contentType,
- ostream, writer, ranges);
+ ostream, writer, ranges, contentLength);
} else {
@@ -572,13 +567,19 @@
}
- private void processSingleRange(HttpServletResponse response, boolean content, File resFile, String contentType, ServletOutputStream ostream, PrintWriter writer, ArrayList ranges) throws IOException {
- Range range = (Range) ranges.get(0);
- response.addHeader("Content-Range", "bytes "
- + range.start
- + "-" + range.end + "/"
- + range.length);
- long length = range.end - range.start + 1;
+ private void processSingleRange(HttpServletResponse response, boolean content, File resFile, String contentType, ServletOutputStream ostream, PrintWriter writer, ArrayList ranges,
+ long contentLength) throws IOException {
+ Range range = null;
+ long length = contentLength;
+
+ if (ranges != null && ranges.size() > 0) {
+ range = (Range) ranges.get(0);
+ response.addHeader("Content-Range", "bytes "
+ + range.start
+ + "-" + range.end + "/"
+ + range.length);
+ length = range.end - range.start + 1;
+ }
if (length < Integer.MAX_VALUE) {
response.setContentLength((int) length);
} else {
@@ -596,44 +597,35 @@
} catch (IllegalStateException e) {
// Silent catch
}
- if (ostream != null) {
- FileCopyUtils.copy(resFile, ostream, range);
- } else {
- FileCopyUtils.copy(resFile, writer, range, fileEncoding);
- }
- }
- }
-
-
- private void processFullFile(HttpServletResponse response, boolean content, File resFile, String contentType, long contentLength, ServletOutputStream ostream, PrintWriter writer) throws IOException {
- // Set the appropriate output headers
- if (contentType != null) {
- response.setContentType(contentType);
- }
- if ((contentLength >= 0)) {
- if (contentLength < Integer.MAX_VALUE) {
- response.setContentLength((int) contentLength);
- } else {
- // Set the content-length as String to be able to use a long
- response.setHeader("content-length", "" + contentLength);
- }
- }
-
- // Copy the input stream to our output stream (if requested)
- if (content) {
+ InputStream is = null;
try {
- response.setBufferSize(output);
- } catch (IllegalStateException e) {
- // Silent catch
- }
- if (ostream != null) {
- FileCopyUtils.copy(resFile, ostream);
- } else {
- FileCopyUtils.copy(resFile, writer, fileEncoding);
+ is = new FileInputStream(resFile);
+ if (ostream != null) {
+ if (range == null) {
+ CopyUtils.copy(is, ostream);
+ } else {
+ CopyUtils.copyRange(is, ostream, range.start, range.end);
+ }
+ } else {Reader reader;
+ if (fileEncoding == null) {
+ reader = new InputStreamReader(is);
+ } else {
+ reader = new InputStreamReader(is,
+ fileEncoding);
+ }
+ if (range == null) {
+ CopyUtils.copyRange(reader, writer);
+ } else {
+ CopyUtils.copyRange(reader, writer, range.start, range.end);
+ }
+ }
+ } finally {
+ is.close();
}
}
}
+
public static String lastModifiedHttp(File resFile) {
String lastModifiedHttp = null;
SimpleDateFormat format = (SimpleDateFormat)formatTL.get();
Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/Dir2Html.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/Dir2Html.java?rev=884416&r1=884415&r2=884416&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/Dir2Html.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/Dir2Html.java Thu Nov 26 06:47:03 2009
@@ -31,14 +31,15 @@
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.tomcat.servlets.util.URLEncoder;
+
/**
* Handles directory listing
*/
-public class Dir2Html extends HttpServlet {
+public class Dir2Html {
/**
* Array containing the safe characters set.
@@ -113,50 +114,6 @@
// --------------------------------------------------------- Public Methods
-
- /**
- * Finalize this servlet.
- */
- public void destroy() {
- }
-
-
- /**
- * Initialize this servlet.
- */
- public void init() throws ServletException {
- }
-
- protected void doGet(HttpServletRequest request,
- HttpServletResponse response)
- throws IOException, ServletException {
-
- // Serve the requested resource, including the data content
- //serveResource(request, response, true);
-
- }
-
-
- protected void doHead(HttpServletRequest request,
- HttpServletResponse response)
- throws IOException, ServletException {
-
- // Serve the requested resource, without the data content
- //serveResource(request, response, false);
-
- }
-
-
- protected void doPost(HttpServletRequest request,
- HttpServletResponse response)
- throws IOException, ServletException {
- doGet(request, response);
- }
-
-
-
-
-
/**
* Serve the specified resource, optionally including the data content.
*
Added: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/Filesystem.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/Filesystem.java?rev=884416&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/Filesystem.java (added)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/Filesystem.java Thu Nov 26 06:47:03 2009
@@ -0,0 +1,29 @@
+/*
+ */
+package org.apache.tomcat.servlets.file;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * Abstract the filesystem - lighter than the JNDI used in catalina.
+ *
+ * This can be used to port the File/Dav servlets to environments that
+ * don't have a file system access, or in servlet engines with class-based
+ * sandboxing.
+ */
+public class Filesystem {
+
+
+ public OutputStream getOutputStream(String name) throws IOException {
+ return null;
+ }
+
+ public InputStream getInputStream(String name) throws IOException {
+ return new FileInputStream(name);
+ }
+
+
+}
Propchange: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/Filesystem.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/LocalFilesystem.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/LocalFilesystem.java?rev=884416&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/LocalFilesystem.java (added)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/LocalFilesystem.java Thu Nov 26 06:47:03 2009
@@ -0,0 +1,15 @@
+/*
+ */
+package org.apache.tomcat.servlets.file;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+
+public class LocalFilesystem extends Filesystem {
+
+ public OutputStream getOutputStream(String name) throws IOException {
+ return new FileOutputStream(name);
+ }
+}
Propchange: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/LocalFilesystem.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/WebdavServlet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/WebdavServlet.java?rev=884416&r1=884415&r2=884416&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/WebdavServlet.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/WebdavServlet.java Thu Nov 26 06:47:03 2009
@@ -37,10 +37,11 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
+import org.apache.tomcat.servlets.util.FastHttpDateFormat;
import org.apache.tomcat.servlets.util.Range;
import org.apache.tomcat.servlets.util.RequestUtil;
import org.apache.tomcat.servlets.util.UrlUtils;
-import org.apache.tomcat.util.http.FastHttpDateFormat;
+
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
Added: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/jmx/JMXProxyServlet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/jmx/JMXProxyServlet.java?rev=884416&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/jmx/JMXProxyServlet.java (added)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/jmx/JMXProxyServlet.java Thu Nov 26 06:47:03 2009
@@ -0,0 +1,281 @@
+/*
+ * 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.tomcat.servlets.jmx;
+
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.lang.management.ManagementFactory;
+import java.util.Iterator;
+import java.util.Set;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.management.MBeanInfo;
+import javax.management.MBeanAttributeInfo;
+import javax.management.Attribute;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * This servlet will dump JMX attributes in a simple format
+ * and implement proxy services for modeler.
+ *
+ * @author Costin Manolache
+ */
+public class JMXProxyServlet extends HttpServlet {
+ protected MBeanServer server = null;
+
+ /**
+ * Initialize this servlet.
+ */
+ public void init() throws ServletException {
+ // Retrieve the MBean serverif (server == null) {
+ if( MBeanServerFactory.findMBeanServer(null).size() > 0 ) {
+ server = MBeanServerFactory.findMBeanServer(null).get(0);
+ } else {
+ server = ManagementFactory.getPlatformMBeanServer();
+ }
+ }
+
+
+ /**
+ * Process a GET request for the specified resource.
+ *
+ * @param request The servlet request we are processing
+ * @param response The servlet response we are creating
+ *
+ * @exception IOException if an input/output error occurs
+ * @exception ServletException if a servlet-specified error occurs
+ */
+ public void doGet(HttpServletRequest request,
+ HttpServletResponse response)
+ throws IOException, ServletException
+ {
+
+ response.setContentType("text/plain");
+
+ PrintWriter writer = response.getWriter();
+
+ if( server==null ) {
+ writer.println("Error - No mbean server");
+ return;
+ }
+
+ String qry=request.getParameter("set");
+ if( qry!= null ) {
+ String name=request.getParameter("att");
+ String val=request.getParameter("val");
+
+ setAttribute( writer, qry, name, val );
+ return;
+ }
+ qry=request.getParameter("get");
+ if( qry!= null ) {
+ String name=request.getParameter("att");
+ getAttribute( writer, qry, name );
+ return;
+ }
+ qry=request.getParameter("qry");
+ if( qry == null ) {
+ qry = "*:*";
+ }
+
+ listBeans( writer, qry );
+
+ }
+
+ public void getAttribute(PrintWriter writer, String onameStr, String att) {
+ try {
+ ObjectName oname = new ObjectName(onameStr);
+ Object value = server.getAttribute(oname, att);
+ writer.println("OK - Attribute get '" + onameStr + "' - " + att
+ + "= " + escape(value.toString()));
+ } catch (Exception ex) {
+ writer.println("Error - " + ex.toString());
+ }
+ }
+
+ public void setAttribute( PrintWriter writer,
+ String onameStr, String att, String val )
+ {
+ try {
+ ObjectName oname=new ObjectName( onameStr );
+ String type = getType(oname, att);
+ if (type == null) {
+ writer.println("Not found");
+ return;
+ }
+ Object valueObj = convertValue(type, val );
+ server.setAttribute( oname, new Attribute(att, valueObj));
+ writer.println("OK - Attribute set");
+ } catch( Exception ex ) {
+ writer.println("Error - " + ex.toString());
+ }
+ }
+
+ public String getType( ObjectName oname, String attName )
+ {
+ String type=null;
+ MBeanInfo info=null;
+ try {
+ info=server.getMBeanInfo(oname);
+ } catch (Exception e) {
+ return null;
+ }
+
+ MBeanAttributeInfo attInfo[]=info.getAttributes();
+ for( int i=0; i<attInfo.length; i++ ) {
+ if( attName.equals(attInfo[i].getName())) {
+ type=attInfo[i].getType();
+ return type;
+ }
+ }
+ return null;
+ }
+
+ public Object convertValue(String type, String value)
+ {
+ Object objValue=value;
+
+ if( type==null || "java.lang.String".equals( type )) {
+ // string is default
+ objValue=value;
+ } else if( "javax.management.ObjectName".equals( type ) ||
+ "ObjectName".equals( type )) {
+ try {
+ objValue=new ObjectName( value );
+ } catch (MalformedObjectNameException e) {
+ return null;
+ }
+ } else if( "java.lang.Integer".equals( type ) ||
+ "int".equals( type )) {
+ objValue=new Integer( value );
+ } else if( "java.lang.Long".equals( type ) ||
+ "long".equals( type )) {
+ objValue=new Long( value );
+ } else if( "java.lang.Boolean".equals( type ) ||
+ "boolean".equals( type )) {
+ objValue=new Boolean( value );
+ }
+ return objValue;
+ }
+
+
+ public void listBeans( PrintWriter writer, String qry )
+ {
+
+ Set<ObjectName> names = null;
+ try {
+ names=server.queryNames(new ObjectName(qry), null);
+ writer.println("OK - Number of results: " + names.size());
+ writer.println();
+ } catch (Exception e) {
+ writer.println("Error - " + e.toString());
+ return;
+ }
+
+ Iterator<ObjectName> it=names.iterator();
+ while( it.hasNext()) {
+ ObjectName oname=it.next();
+ writer.println( "Name: " + oname.toString());
+
+ try {
+ MBeanInfo minfo=server.getMBeanInfo(oname);
+ // can't be null - I thinl
+ String code=minfo.getClassName();
+ if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) {
+ code=(String)server.getAttribute(oname, "modelerType");
+ }
+ writer.println("modelerType: " + code);
+
+ MBeanAttributeInfo attrs[]=minfo.getAttributes();
+ Object value=null;
+
+ for( int i=0; i< attrs.length; i++ ) {
+ if( ! attrs[i].isReadable() ) continue;
+ if( ! isSupported( attrs[i].getType() )) continue;
+ String attName=attrs[i].getName();
+ if( attName.indexOf( "=") >=0 ||
+ attName.indexOf( ":") >=0 ||
+ attName.indexOf( " ") >=0 ) {
+ continue;
+ }
+
+ try {
+ value=server.getAttribute(oname, attName);
+ } catch( Throwable t) {
+ log("Error getting attribute " + oname +
+ " " + attName + " " + t.toString());
+ continue;
+ }
+ if( value==null ) continue;
+ if( "modelerType".equals( attName)) continue;
+ String valueString=value.toString();
+ writer.println( attName + ": " + escape(valueString));
+ }
+ } catch (Exception e) {
+ // Ignore
+ }
+ writer.println();
+ }
+
+ }
+
+ public String escape(String value) {
+ // The only invalid char is \n
+ // We also need to keep the string short and split it with \nSPACE
+ // XXX TODO
+ int idx=value.indexOf( "\n" );
+ if( idx < 0 ) return value;
+
+ int prev=0;
+ StringBuffer sb=new StringBuffer();
+ while( idx >= 0 ) {
+ appendHead(sb, value, prev, idx);
+
+ sb.append( "\\n\n ");
+ prev=idx+1;
+ if( idx==value.length() -1 ) break;
+ idx=value.indexOf('\n', idx+1);
+ }
+ if( prev < value.length() )
+ appendHead( sb, value, prev, value.length());
+ return sb.toString();
+ }
+
+ private void appendHead( StringBuffer sb, String value, int start, int end) {
+ if (end < 1) return;
+
+ int pos=start;
+ while( end-pos > 78 ) {
+ sb.append( value.substring(pos, pos+78));
+ sb.append( "\n ");
+ pos=pos+78;
+ }
+ sb.append( value.substring(pos,end));
+ }
+
+ public boolean isSupported( String type ) {
+ return true;
+ }
+}
Propchange: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/jmx/JMXProxyServlet.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/jmx/JmxObjectManagerSpi.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/jmx/JmxObjectManagerSpi.java?rev=884416&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/jmx/JmxObjectManagerSpi.java (added)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/jmx/JmxObjectManagerSpi.java Thu Nov 26 06:47:03 2009
@@ -0,0 +1,41 @@
+/*
+ */
+package org.apache.tomcat.servlets.jmx;
+
+import java.util.logging.Logger;
+
+import org.apache.tomcat.integration.ObjectManager;
+import org.apache.tomcat.util.modeler.Registry;
+
+/**
+ * Plugin for integration with JMX.
+ *
+ * All objects of interest are registered automatically.
+ */
+public class JmxObjectManagerSpi extends ObjectManager {
+ Registry registry;
+ Logger log = Logger.getLogger("JmxObjectManager");
+
+ public JmxObjectManagerSpi() {
+ registry = Registry.getRegistry(null, null);
+ }
+
+ public void bind(String name, Object o) {
+ try {
+ registry.registerComponent(o,
+ ":name=\"" + name + "\"", null);
+ } catch (Exception e) {
+ log.severe("Error registering" + e);
+ }
+ }
+
+ public void unbind(String name) {
+ registry.unregisterComponent(":name=\"" + name + "\"");
+ }
+
+ @Override
+ public Object get(String key) {
+ return null;
+ }
+
+}
Propchange: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/jmx/JmxObjectManagerSpi.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org