[jboss-cvs] JBossAS SVN: r79275 - in trunk/tomcat/src: resources/test and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Oct 8 11:42:19 EDT 2008


Author: emuckenhuber
Date: 2008-10-08 11:42:19 -0400 (Wed, 08 Oct 2008)
New Revision: 79275

Added:
   trunk/tomcat/src/main/org/jboss/web/tomcat/metadata/ServerXMLObjectModelFactory.java
   trunk/tomcat/src/resources/test/metadata/
   trunk/tomcat/src/resources/test/metadata/server.xml
   trunk/tomcat/src/tests/org/jboss/test/web/metadata/
   trunk/tomcat/src/tests/org/jboss/test/web/metadata/ServerMetaDataUniTestCase.java
Log:
[JBAS-6058] simple ObjectModelFactory prototype

Added: trunk/tomcat/src/main/org/jboss/web/tomcat/metadata/ServerXMLObjectModelFactory.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/metadata/ServerXMLObjectModelFactory.java	                        (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/metadata/ServerXMLObjectModelFactory.java	2008-10-08 15:42:19 UTC (rev 79275)
@@ -0,0 +1,201 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.web.tomcat.metadata;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.xb.binding.GenericObjectModelFactory;
+import org.jboss.xb.binding.UnmarshallingContext;
+import org.xml.sax.Attributes;
+
+/**
+ * A Server.xml ObjectModelFactory.
+ * 
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class ServerXMLObjectModelFactory implements GenericObjectModelFactory
+{
+
+   public Object newRoot(Object root, UnmarshallingContext ctx, String namespaceURI, String localName, Attributes attrs)
+   {
+      ServerMetaData metaData = new ServerMetaData();
+      metaData.setName(attrs.getValue("name"));
+      return metaData;
+   }
+   
+   public Object completeRoot(Object root, UnmarshallingContext ctx, String namespaceURI, String localName)
+   {
+      return root;
+   }
+
+   public void addChild(Object parent, Object child, UnmarshallingContext ctx, String namespaceURI, String localName)
+   {
+      if(parent instanceof ServerMetaData)
+      {
+         ServerMetaData metaData = (ServerMetaData) parent;
+         if(child instanceof ListenerMetaData)
+         {
+            if(metaData.getListeners() == null)
+               metaData.setListeners(new ArrayList<ListenerMetaData>());
+            metaData.getListeners().add((ListenerMetaData) child);
+         }
+         else if(child instanceof ServiceMetaData)
+         {
+            if(metaData.getServices() == null)
+               metaData.setServices(new ArrayList<ServiceMetaData>());
+            metaData.getServices().add((ServiceMetaData) child);
+         }
+      }
+      
+      if(parent instanceof ServiceMetaData)
+      {
+         ServiceMetaData metaData = (ServiceMetaData) parent;
+         if(child instanceof ConnectorMetaData)
+         {
+            if(metaData.getConnectors() == null)
+               metaData.setConnectors(new ArrayList<ConnectorMetaData>());
+            metaData.getConnectors().add((ConnectorMetaData) child);
+         }
+         else if(child instanceof ListenerMetaData)
+         {
+            if(metaData.getListeners() == null)
+               metaData.setListeners(new ArrayList<ListenerMetaData>());
+            metaData.getListeners().add((ListenerMetaData) child);
+         }
+         else if(child instanceof EngineMetaData)
+         {
+            metaData.setEngine((EngineMetaData) child);
+         }
+         else if(child instanceof ExecutorMetaData)
+         {
+            metaData.setExecutor((ExecutorMetaData) child);
+         }
+      }
+      
+      // ... 
+   }
+
+   public Object newChild(Object parent, UnmarshallingContext ctx, String namespaceURI, String localName,
+         Attributes attrs)
+   {
+      Set<String> excludeAttributes = new HashSet<String>();
+      Object child = null;
+
+      // TODO child.setName(attrs.getValue("name"));
+      
+      // <Server/>
+      if(parent instanceof ServerMetaData)
+      {
+         // <Service/>
+         if("Service".equals(localName))
+            child = new ServiceMetaData();
+         // <Listener/>
+         else if("Listener".equals(localName))
+            child = new ListenerMetaData(); 
+      }
+      
+      // <Service/>
+      if(parent instanceof ServiceMetaData)
+      {
+         // <Connector/>         
+         if("Connector".equals(localName))
+            child = new ConnectorMetaData();
+         // <Engine/>
+         else if("Engine".equals(localName))
+         {
+            EngineMetaData engine = new EngineMetaData();
+            
+            engine.setDefaultHost(getAttribute("defaultHost", excludeAttributes, attrs));
+            engine.setJvmRoute(getAttribute("jvmRoute", excludeAttributes, attrs));
+            engine.setName(getAttribute("name", excludeAttributes, attrs));
+            
+            child = engine;
+            
+         }
+         // <Executor/>
+         else if("Executor".equals(localName))
+            child = new ExecutorMetaData();
+         // <Listener/>
+         else if("Listener".equals(localName))
+            child = new ListenerMetaData();
+      }
+      
+      if(parent instanceof EngineMetaData)
+      {
+         // TODO
+      }
+      
+      if(parent instanceof HostMetaData)
+      {
+         // TODO
+      }
+      
+      // Handle attributes for AnyXmlMetaData
+      if(child instanceof AnyXmlMetaData)
+      {
+         AnyXmlMetaData metaData = (AnyXmlMetaData) child;
+         if( metaData.getAttributes() == null)
+            metaData.setAttributes(new HashMap<String, Object>());
+         
+         // ClassName
+         String className = getAttribute("className", excludeAttributes, attrs);
+         metaData.setClassName(className);
+
+         if(attrs != null)
+         {
+            for(int i = 0; i <attrs.getLength(); i++)
+            {
+               String key = attrs.getLocalName(i);
+               if(excludeAttributes.contains(key))
+                  continue;
+               //                
+               String value = attrs.getValue(i);
+               metaData.getAttributes().put(key, value);
+            }
+         }
+         return metaData;
+      }
+      
+      return child;
+   }
+
+   public void setValue(Object o, UnmarshallingContext ctx, String namespaceURI, String localName, String value)
+   {
+
+   }
+   
+   protected String getAttribute(String name, Set<String> excludeList, Attributes attrs)
+   {
+      if(attrs == null) return null;
+      
+      if(excludeList != null)
+         excludeList.add(name);
+      
+      return attrs.getValue(name);
+   }
+
+}
+

Added: trunk/tomcat/src/resources/test/metadata/server.xml
===================================================================
--- trunk/tomcat/src/resources/test/metadata/server.xml	                        (rev 0)
+++ trunk/tomcat/src/resources/test/metadata/server.xml	2008-10-08 15:42:19 UTC (rev 79275)
@@ -0,0 +1,161 @@
+<Server>
+
+   <!-- Optional listener which ensures correct init and shutdown of APR,
+        and provides information if it is not installed -->
+   <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
+   <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
+   <Listener className="org.apache.catalina.core.JasperListener" />
+
+   <Service name="jboss.web">
+
+      <!-- A HTTP/1.1 Connector on port 8080 -->
+      <Connector protocol="HTTP/1.1" port="8080" address="${jboss.bind.address}" 
+               connectionTimeout="20000" redirectPort="8443" />
+
+      <!-- Add this option to the connector to avoid problems with 
+          .NET clients that don't implement HTTP/1.1 correctly 
+         restrictedUserAgents="^.*MS Web Services Client Protocol 1.1.4322.*$"
+      -->
+
+      <!-- A AJP 1.3 Connector on port 8009 -->
+      <Connector protocol="AJP/1.3" port="8009" address="${jboss.bind.address}"
+         redirectPort="8443" />
+
+      <!-- SSL/TLS Connector configuration using the admin devl guide keystore
+      <Connector protocol="HTTP/1.1" SSLEnabled="true" 
+           port="8443" address="${jboss.bind.address}"
+           scheme="https" secure="true" clientAuth="false" 
+           keystoreFile="${jboss.server.home.dir}/conf/chap8.keystore"
+           keystorePass="rmi+ssl" sslProtocol = "TLS" />
+      -->
+
+      <Engine name="jboss.web" defaultHost="localhost">
+
+         <!-- The JAAS based authentication and authorization realm implementation
+         that is compatible with the jboss 3.2.x realm implementation.
+         - certificatePrincipal : the class name of the
+         org.jboss.security.auth.certs.CertificatePrincipal impl
+         used for mapping X509[] cert chains to a Princpal.
+         - allRolesMode : how to handle an auth-constraint with a role-name=*,
+         one of strict, authOnly, strictAuthOnly
+           + strict = Use the strict servlet spec interpretation which requires
+           that the user have one of the web-app/security-role/role-name
+           + authOnly = Allow any authenticated user
+           + strictAuthOnly = Allow any authenticated user only if there are no
+           web-app/security-roles
+         -->
+         <Realm className="org.jboss.web.tomcat.security.JBossWebRealm"
+            certificatePrincipal="org.jboss.security.auth.certs.SubjectDNMapping"
+            allRolesMode="authOnly"
+            />
+         <!-- A subclass of JBossSecurityMgrRealm that uses the authentication
+         behavior of JBossSecurityMgrRealm, but overrides the authorization
+         checks to use JACC permissions with the current java.security.Policy
+         to determine authorized access.
+         - allRolesMode : how to handle an auth-constraint with a role-name=*,
+         one of strict, authOnly, strictAuthOnly
+           + strict = Use the strict servlet spec interpretation which requires
+           that the user have one of the web-app/security-role/role-name
+           + authOnly = Allow any authenticated user
+           + strictAuthOnly = Allow any authenticated user only if there are no
+           web-app/security-roles
+         <Realm className="org.jboss.web.tomcat.security.JaccAuthorizationRealm"
+            certificatePrincipal="org.jboss.security.auth.certs.SubjectDNMapping"
+            allRolesMode="authOnly"
+            />
+         -->
+
+         <Host name="localhost"> 
+
+            <!-- Uncomment to enable request dumper. This Valve "logs interesting 
+                 contents from the specified Request (before processing) and the 
+                 corresponding Response (after processing). It is especially useful 
+                 in debugging problems related to headers and cookies."
+            -->
+            <!--
+            <Valve className="org.apache.catalina.valves.RequestDumperValve" />
+            -->
+ 
+            <!-- Access logger -->
+            <!--
+            <Valve className="org.apache.catalina.valves.AccessLogValve"
+                prefix="localhost_access_log." suffix=".log"
+                pattern="common" directory="${jboss.server.log.dir}" 
+                resolveHosts="false" />
+            -->
+
+            <!-- Uncomment to enable single sign-on across web apps
+                deployed to this host. Does not provide SSO across a cluster.     
+            
+                If this valve is used, do not use the JBoss ClusteredSingleSignOn 
+                valve shown below.
+                
+                A new configuration attribute is available beginning with
+                release 4.0.4:
+                
+                cookieDomain  configures the domain to which the SSO cookie
+                              will be scoped (i.e. the set of hosts to
+                              which the cookie will be presented).  By default
+                              the cookie is scoped to "/", meaning the host
+                              that presented it.  Set cookieDomain to a
+                              wider domain (e.g. "xyz.com") to allow an SSO
+                              to span more than one hostname.
+             -->
+            <!--
+            <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
+            -->
+
+            <!-- Uncomment to enable single sign-on across web apps
+               deployed to this host AND to all other hosts in the cluster.
+            
+               If this valve is used, do not use the standard Tomcat SingleSignOn
+               valve shown above.
+            
+               Valve uses a JBossCache instance to support SSO credential 
+               caching and replication across the cluster.  The JBossCache 
+               instance must be configured separately.  See the 
+               "jboss-web-clusteredsso-beans.xml" file in the 
+               server/all/deploy directory for cache configuration details.
+            
+               Besides the attributes supported by the standard Tomcat
+               SingleSignOn valve (see the Tomcat docs), this version also 
+               supports the following attributes:
+            
+               cookieDomain   see above
+               
+               treeCacheName  JMX ObjectName of the JBossCache MBean used to 
+                              support credential caching and replication across
+                              the cluster. If not set, the default value is 
+                              "jboss.cache:service=ClusteredSSOCache"
+                              
+               maxEmptyLife   The maximum number of seconds an SSO with no 
+                              active sessions will be usable by a request
+                              
+               processExpiresInterval The minimum number of seconds between 
+                              efforts by the valve to find and invalidate 
+                              SSO's that have exceeded their 'maxEmptyLife'. 
+                              Does not imply effort will be spent on such
+                      			cleanup every 'processExpiresInterval'.
+            -->
+            <!--
+            <Valve className="org.jboss.web.tomcat.service.sso.ClusteredSingleSignOn" />
+            -->
+         
+            <!-- Check for unclosed connections and transaction terminated checks
+                 in servlets/jsps.
+                 
+                 Important: The dependency on the CachedConnectionManager
+                 in META-INF/jboss-service.xml must be uncommented, too
+           -->
+
+            <Valve className="org.jboss.web.tomcat.service.jca.CachedConnectionValve"
+                cachedConnectionManagerObjectName="jboss.jca:service=CachedConnectionManager"
+                transactionManagerObjectName="jboss:service=TransactionManager" />
+                
+         </Host>
+
+      </Engine>
+
+   </Service>
+
+</Server>


Property changes on: trunk/tomcat/src/resources/test/metadata/server.xml
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/tomcat/src/tests/org/jboss/test/web/metadata/ServerMetaDataUniTestCase.java
===================================================================
--- trunk/tomcat/src/tests/org/jboss/test/web/metadata/ServerMetaDataUniTestCase.java	                        (rev 0)
+++ trunk/tomcat/src/tests/org/jboss/test/web/metadata/ServerMetaDataUniTestCase.java	2008-10-08 15:42:19 UTC (rev 79275)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.web.metadata;
+
+import java.io.InputStream;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.jboss.web.tomcat.metadata.ListenerMetaData;
+import org.jboss.web.tomcat.metadata.ServerMetaData;
+import org.jboss.web.tomcat.metadata.ServerXMLObjectModelFactory;
+import org.jboss.xb.binding.ObjectModelFactory;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class ServerMetaDataUniTestCase extends TestCase
+{
+
+   public void test() throws Exception
+   {
+
+      ObjectModelFactory factory = new ServerXMLObjectModelFactory();
+      Unmarshaller u = UnmarshallerFactory.newInstance().newUnmarshaller();
+      u.setSchemaValidation(false);
+      u.setValidation(false);
+      
+      InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("test/metadata/server.xml");
+
+      ServerMetaData m = ServerMetaData.class.cast(u.unmarshal(is, factory, null));
+      assertNotNull(m);
+      assertNotNull(m.getListeners());
+      assertNotNull(m.getServices());
+      
+      assertEquals(2, m.getListeners().size());
+      ListenerMetaData l = m.getListeners().get(0);
+      assertNotNull(l);
+      assertEquals(l.getClassName(), "org.apache.catalina.core.AprLifecycleListener");
+      assertEquals("on", l.getAttributes().get("SSLEngine"));
+   }
+   
+}
+




More information about the jboss-cvs-commits mailing list