openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r1153503 - in /openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans: servlet/WebBeansConfigurationListener.java web/lifecycle/WebContainerLifecycle.java web/util/ web/util/ServletCompatibilityUtil.java
Date Wed, 03 Aug 2011 14:28:21 GMT
Author: gpetracek
Date: Wed Aug  3 14:28:20 2011
New Revision: 1153503

URL: http://svn.apache.org/viewvc?rev=1153503&view=rev
Log:
OWB-583 Support for Servlet API 2.4 - thx to Udo Schnurpfeil

Added:
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/util/
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/util/ServletCompatibilityUtil.java
Modified:
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java

Modified: openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java?rev=1153503&r1=1153502&r2=1153503&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java
(original)
+++ openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java
Wed Aug  3 14:28:20 2011
@@ -28,6 +28,7 @@ import org.apache.webbeans.spi.Container
 import org.apache.webbeans.spi.FailOverService;
 import org.apache.webbeans.util.WebBeansUtil;
 import org.apache.webbeans.web.context.WebContextsService;
+import org.apache.webbeans.web.util.ServletCompatibilityUtil;
 
 import javax.enterprise.context.RequestScoped;
 import javax.enterprise.context.SessionScoped;
@@ -82,7 +83,7 @@ public class WebBeansConfigurationListen
         }
         catch (Exception e)
         {
-             logger.error(OWBLogConst.ERROR_0018, event.getServletContext().getContextPath());
+             logger.error(OWBLogConst.ERROR_0018, ServletCompatibilityUtil.getServletInfo(event.getServletContext()));
              WebBeansUtil.throwRuntimeExceptions(e);
         }
     }

Modified: openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java?rev=1153503&r1=1153502&r2=1153503&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java
(original)
+++ openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java
Wed Aug  3 14:28:20 2011
@@ -27,6 +27,7 @@ import org.apache.webbeans.lifecycle.Abs
 import org.apache.webbeans.logger.WebBeansLogger;
 import org.apache.webbeans.spi.ResourceInjectionService;
 import org.apache.webbeans.spi.adaptor.ELAdaptor;
+import org.apache.webbeans.web.util.ServletCompatibilityUtil;
 
 import javax.el.ELResolver;
 import javax.enterprise.inject.spi.BeanManager;
@@ -110,7 +111,8 @@ public final class WebContainerLifecycle
             @Override
             public Thread newThread(Runnable runable)
             {
-                Thread t = new Thread(runable, "OwbConversationCleaner-" + ((ServletContext)(startupObject)).getContextPath());
+              Thread t = new Thread(runable, "OwbConversationCleaner-"
+                  + ServletCompatibilityUtil.getServletInfo((ServletContext) (startupObject)));
                 t.setDaemon(true);
                 return t;                
             }
@@ -189,11 +191,11 @@ public final class WebContainerLifecycle
         
         if (logger.wblWillLogInfo())
         {
-            logger.info(OWBLogConst.INFO_0002, servletContext != null ? servletContext.getContextPath()
: "null");
+          logger.info(OWBLogConst.INFO_0002, ServletCompatibilityUtil.getServletInfo(servletContext));
         }
     }
 
-    /**
+  /**
      * Ensures that all ThreadLocals, which could have been set in this
      * (shutdown-) Thread, are removed in order to prevent memory leaks.
      */

Added: openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/util/ServletCompatibilityUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/util/ServletCompatibilityUtil.java?rev=1153503&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/util/ServletCompatibilityUtil.java
(added)
+++ openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/util/ServletCompatibilityUtil.java
Wed Aug  3 14:28:20 2011
@@ -0,0 +1,61 @@
+/*
+ * 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.webbeans.web.util;
+
+import javax.servlet.ServletContext;
+
+/**
+ * This utility helps to be compatible with Servlet API 2.4
+ */
+public class ServletCompatibilityUtil
+{
+
+    // avoid instantiation
+
+    private ServletCompatibilityUtil()
+    {
+    }
+
+    /**
+     * Returns an information about the given servlet context.
+     * In case of Servlet API 2.5 or higher the context name will be returned.
+     *
+     * @param servletContext A given servlet context or null.
+     * @return The info, or the string "null"
+     */
+    public static String getServletInfo(ServletContext servletContext)
+    {
+        if (servletContext != null)
+        {
+            if (servletContext.getMajorVersion() >= 3 ||
+                    servletContext.getMajorVersion() == 2 && servletContext.getMinorVersion()
>= 5)
+            {
+                return servletContext.getContextPath();
+            }
+            else
+            {
+                return servletContext.getServletContextName();
+            }
+        }
+        else
+        {
+            return "null";
+        }
+    }
+}



Mime
View raw message