ws-wsrf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject svn commit: r289637 - in /webservices/wsrf/trunk/src: java/org/apache/ws/resource/WsrfRuntime.java java/org/apache/ws/resource/container/ java/org/apache/ws/resource/webapp/WsrfServletContextListener.java test/spring-jndi-config.xml
Date Fri, 16 Sep 2005 19:44:50 GMT
Author: ips
Date: Fri Sep 16 12:44:46 2005
New Revision: 289637

URL: http://svn.apache.org/viewcvs?rev=289637&view=rev
Log:
config/init code moved to a new Runtime class that is called from the servlet context init
method

Added:
    webservices/wsrf/trunk/src/java/org/apache/ws/resource/WsrfRuntime.java
    webservices/wsrf/trunk/src/test/spring-jndi-config.xml
Removed:
    webservices/wsrf/trunk/src/java/org/apache/ws/resource/container/
Modified:
    webservices/wsrf/trunk/src/java/org/apache/ws/resource/webapp/WsrfServletContextListener.java

Added: webservices/wsrf/trunk/src/java/org/apache/ws/resource/WsrfRuntime.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/resource/WsrfRuntime.java?rev=289637&view=auto
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/resource/WsrfRuntime.java (added)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/resource/WsrfRuntime.java Fri Sep 16 12:44:46
2005
@@ -0,0 +1,95 @@
+/*=============================================================================*
+ *  Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *=============================================================================*/
+package org.apache.ws.resource;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ws.resource.i18n.Keys;
+import org.apache.ws.resource.i18n.MessagesImpl;
+import org.apache.ws.util.i18n.Messages;
+import org.apache.ws.util.jndi.SpringJndiPopulator;
+import org.apache.ws.util.jndi.XmlBeanJndiUtils;
+import org.springframework.beans.factory.ListableBeanFactory;
+import org.springframework.beans.factory.xml.XmlBeanFactory;
+import org.springframework.core.io.ClassPathResource;
+
+import java.io.InputStream;
+import java.util.Properties;
+
+/**
+ * A singleton respresenting the WSRF runtime.
+ */
+public class WsrfRuntime
+{
+
+    private static final Log LOG = LogFactory.getLog( WsrfRuntime.class );
+    private static final Messages MSG = MessagesImpl.getInstance();
+
+    private static final String CONFIG_DIALECT_SPRING_BEANS = "http://www.springframework.org/dtd/spring-beans.dtd";
+    private static final String CONFIG_DIALECT_WSRF_JNDI_CONFIG = "http://www.apache.org/wsfx/wsrf/jndi/config";
+
+    private static final String DEFAULT_JNDI_CONFIG_LOCATION = "jndi-config.xml";
+    private static final String DEFAULT_JNDI_CONFIG_DIALECT = CONFIG_DIALECT_WSRF_JNDI_CONFIG;
+
+    private static final String VERSION = "1.1";
+
+    private static final WsrfRuntime INSTANCE = new WsrfRuntime();
+
+    private WsrfRuntime()
+    {
+    }
+
+    public static WsrfRuntime getRuntime()
+    {
+        return INSTANCE;
+    }
+
+    public void init( Properties props )
+    {
+        String jndiConfigDialect = props.getProperty( "jndi.config.dialect", DEFAULT_JNDI_CONFIG_DIALECT
);
+        String jndiConfigLocation = props.getProperty( "jndi.config.location", DEFAULT_JNDI_CONFIG_LOCATION
);
+        LOG.info( MSG.getMessage( Keys.POPULATING_JNDI, jndiConfigLocation ) );
+        try
+        {
+            if ( jndiConfigDialect.equals( CONFIG_DIALECT_WSRF_JNDI_CONFIG ) )
+            {
+                InputStream jndiConfigStream =
+                        Thread.currentThread().getContextClassLoader().getResourceAsStream(
jndiConfigLocation );
+                XmlBeanJndiUtils.initFromInputStream( jndiConfigStream );
+            }
+            else if ( jndiConfigDialect.equals( CONFIG_DIALECT_SPRING_BEANS ) )
+            {
+                ListableBeanFactory beanFactory = new XmlBeanFactory( new ClassPathResource(
jndiConfigLocation ) );
+                SpringJndiPopulator.populateContext( XmlBeanJndiUtils.initWsrfContext(),
beanFactory );
+            }
+            else
+            {
+                throw new RuntimeException(
+                        "Fatal error! An unsupported JNDI configuration dialect was specified
via the 'jndi.config.dialect' initialization property." );
+            }
+        }
+        catch ( Exception e )
+        {
+            throw new RuntimeException( "Fatal error! Failed to initialize WSRF runtime.",
e );
+        }
+    }
+
+    public String getVersion()
+    {
+        return VERSION;
+    }
+
+}

Modified: webservices/wsrf/trunk/src/java/org/apache/ws/resource/webapp/WsrfServletContextListener.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/resource/webapp/WsrfServletContextListener.java?rev=289637&r1=289636&r2=289637&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/resource/webapp/WsrfServletContextListener.java
(original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/resource/webapp/WsrfServletContextListener.java
Fri Sep 16 12:44:46 2005
@@ -17,18 +17,12 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.ws.resource.i18n.Keys;
-import org.apache.ws.resource.i18n.MessagesImpl;
-import org.apache.ws.util.i18n.Messages;
-import org.apache.ws.util.jndi.SpringJndiPopulator;
-import org.apache.ws.util.jndi.XmlBeanJndiUtils;
-import org.springframework.beans.factory.ListableBeanFactory;
-import org.springframework.beans.factory.xml.XmlBeanFactory;
-import org.springframework.core.io.ClassPathResource;
+import org.apache.ws.resource.WsrfRuntime;
 
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
-import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.Properties;
 
 /**
  * A servlet context listener for the WSRF webapp that provides the hook for initializing
the WSRF JNDI context. Note,
@@ -44,13 +38,6 @@
 {
 
     private static final Log LOG = LogFactory.getLog( WsrfServletContextListener.class );
-    private static final Messages MSG = MessagesImpl.getInstance();
-
-    private static final String CONFIG_DIALECT_SPRING_BEANS = "http://www.springframework.org/dtd/spring-beans.dtd";
-    private static final String CONFIG_DIALECT_WSRF_JNDI_CONFIG = "http://www.apache.org/wsfx/wsrf/jndi/config";
-
-    private static final String DEFAULT_JNDI_CONFIG_LOCATION = "jndi-config.xml";
-    private static final String DEFAULT_JNDI_CONFIG_DIALECT = CONFIG_DIALECT_WSRF_JNDI_CONFIG;
 
     /**
      * DOCUMENT_ME
@@ -70,41 +57,21 @@
     public void contextInitialized( ServletContextEvent contextEvent )
     {
         String contextName = contextEvent.getServletContext().getServletContextName();
-        LOG.info( "Initializing the " + contextName + " webapp..." );
+        LOG.info( "Initializing WSRF runtime from within webapp at context " + contextName
+ "..." );
+        Properties initProps = convertInitParametersToProperties( contextEvent );
+        WsrfRuntime runtime = WsrfRuntime.getRuntime();
+        runtime.init( initProps );
+    }
 
-        String jndiConfigDialect = contextEvent.getServletContext().getInitParameter( "jndi.config.dialect"
);
-        if ( jndiConfigDialect == null )
-        {
-            jndiConfigDialect = DEFAULT_JNDI_CONFIG_DIALECT;
-        }
-        String jndiConfigLocation = contextEvent.getServletContext().getInitParameter( "jndi.config.location"
);
-        if ( jndiConfigLocation == null )
-        {
-            jndiConfigLocation = DEFAULT_JNDI_CONFIG_LOCATION;
-        }
-        LOG.info( MSG.getMessage( Keys.POPULATING_JNDI, jndiConfigLocation ) );
-        try
-        {
-            if ( jndiConfigDialect.equals( CONFIG_DIALECT_WSRF_JNDI_CONFIG ) )
-            {
-                InputStream jndiConfigStream =
-                        Thread.currentThread().getContextClassLoader().getResourceAsStream(
jndiConfigLocation );
-                XmlBeanJndiUtils.initFromInputStream( jndiConfigStream );
-            }
-            else if ( jndiConfigDialect.equals( CONFIG_DIALECT_SPRING_BEANS ) )
-            {
-                ListableBeanFactory beanFactory = new XmlBeanFactory( new ClassPathResource(
jndiConfigLocation ) );
-                SpringJndiPopulator.populateContext( XmlBeanJndiUtils.initWsrfContext(),
beanFactory );
-            }
-            else
-            {
-                throw new RuntimeException(
-                        "Fatal error! An unsupported JNDI configuration dialect was specified
via the 'jndi.config.dialect' init-parameter in web.xml." );
-            }
-        }
-        catch ( Exception e )
+    private Properties convertInitParametersToProperties( ServletContextEvent contextEvent
)
+    {
+        Properties props = new Properties();
+        Enumeration initParamNames = contextEvent.getServletContext().getInitParameterNames();
+        while ( initParamNames.hasMoreElements() )
         {
-            throw new RuntimeException( "Fatal error! Failed to initialize WSRF JNDI context.",
e );
+            String initParamName = (String) initParamNames.nextElement();
+            props.setProperty( initParamName, contextEvent.getServletContext().getInitParameter(
initParamName ) );
         }
+        return props;
     }
 }

Added: webservices/wsrf/trunk/src/test/spring-jndi-config.xml
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/test/spring-jndi-config.xml?rev=289637&view=auto
==============================================================================
--- webservices/wsrf/trunk/src/test/spring-jndi-config.xml (added)
+++ webservices/wsrf/trunk/src/test/spring-jndi-config.xml Fri Sep 16 12:44:46 2005
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+
+<beans>
+
+  <bean name="global/DefaultParameters" class="org.apache.ws.util.jndi.DefaultParameters">
+    <property name="factory"><value>org.apache.ws.util.jndi.BeanFactory</value></property>
+  </bean>
+
+  <bean name="global/timer/ContainerTimer" class="org.apache.ws.util.timer.TimerManagerImpl"
/>
+
+</beans>



Mime
View raw message