geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r946928 - in /geronimo/server/trunk/plugins/j2ee/geronimo-web-2.5-builder/src/main/java/org/apache/geronimo/web25/deployment: merge/webfragment/SessionConfigMergeHandler.java utils/WebDeploymentMessageUtils.java
Date Fri, 21 May 2010 08:02:09 GMT
Author: xuhaihong
Date: Fri May 21 08:02:09 2010
New Revision: 946928

URL: http://svn.apache.org/viewvc?rev=946928&view=rev
Log:
Add merge process for session-config configurations

Modified:
    geronimo/server/trunk/plugins/j2ee/geronimo-web-2.5-builder/src/main/java/org/apache/geronimo/web25/deployment/merge/webfragment/SessionConfigMergeHandler.java
    geronimo/server/trunk/plugins/j2ee/geronimo-web-2.5-builder/src/main/java/org/apache/geronimo/web25/deployment/utils/WebDeploymentMessageUtils.java

Modified: geronimo/server/trunk/plugins/j2ee/geronimo-web-2.5-builder/src/main/java/org/apache/geronimo/web25/deployment/merge/webfragment/SessionConfigMergeHandler.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/j2ee/geronimo-web-2.5-builder/src/main/java/org/apache/geronimo/web25/deployment/merge/webfragment/SessionConfigMergeHandler.java?rev=946928&r1=946927&r2=946928&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/j2ee/geronimo-web-2.5-builder/src/main/java/org/apache/geronimo/web25/deployment/merge/webfragment/SessionConfigMergeHandler.java
(original)
+++ geronimo/server/trunk/plugins/j2ee/geronimo-web-2.5-builder/src/main/java/org/apache/geronimo/web25/deployment/merge/webfragment/SessionConfigMergeHandler.java
Fri May 21 08:02:09 2010
@@ -18,19 +18,28 @@
 package org.apache.geronimo.web25.deployment.merge.webfragment;
 
 import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.web25.deployment.merge.ElementSource;
 import org.apache.geronimo.web25.deployment.merge.MergeContext;
+import org.apache.geronimo.web25.deployment.merge.MergeItem;
 import org.apache.geronimo.web25.deployment.utils.WebDeploymentMessageUtils;
+import org.apache.geronimo.xbeans.javaee6.CookieConfigType;
+import org.apache.geronimo.xbeans.javaee6.SessionConfigType;
+import org.apache.geronimo.xbeans.javaee6.TrackingModeType;
 import org.apache.geronimo.xbeans.javaee6.WebAppType;
 import org.apache.geronimo.xbeans.javaee6.WebFragmentType;
 
 /**
- * @FIXME For session-config, no rules are mentioned in spec, from my understanding, we should
only use the one from web.xml
  * @version $Rev$ $Date$
  */
 public class SessionConfigMergeHandler implements WebFragmentMergeHandler<WebFragmentType,
WebAppType> {
 
     @Override
-    public void merge(WebFragmentType srcElement, WebAppType webApp, MergeContext mergeContext)
throws DeploymentException {
+    public void merge(WebFragmentType webFragment, WebAppType webApp, MergeContext mergeContext)
throws DeploymentException {
+        if (webFragment.getSessionConfigArray().length == 1) {
+            mergeSessionConfig(webApp, webFragment.getSessionConfigArray(0), mergeContext,
ElementSource.WEB_FRAGMENT);
+        } else if (webFragment.getSessionConfigArray().length > 1) {
+            throw new DeploymentException(WebDeploymentMessageUtils.createMultipleConfigurationWebFragmentErrorMessage("session-config",
mergeContext.getCurrentJarUrl()));
+        }
     }
 
     @Override
@@ -39,8 +48,86 @@ public class SessionConfigMergeHandler i
 
     @Override
     public void preProcessWebXmlElement(WebAppType webApp, MergeContext context) throws DeploymentException
{
-        if (webApp.getSessionConfigArray().length > 1) {
+        if (webApp.getSessionConfigArray().length == 1) {
+            SessionConfigType sessionConfig = webApp.getSessionConfigArray(0);
+            mergeSessionConfig(webApp, sessionConfig, context, ElementSource.WEB_XML);
+            context.setAttribute("session-config", sessionConfig);
+        } else if (webApp.getSessionConfigArray().length > 1) {
             throw new DeploymentException(WebDeploymentMessageUtils.createMultipleConfigurationWebAppErrorMessage("session-config"));
         }
     }
+
+    private CookieConfigType getCookieConfig(WebAppType webApp, MergeContext context) {
+        SessionConfigType sessionConfig = getSessionConfig(webApp, context);
+        if (sessionConfig.isSetCookieConfig()) {
+            return sessionConfig.getCookieConfig();
+        } else {
+            return sessionConfig.addNewCookieConfig();
+        }
+    }
+
+    private SessionConfigType getSessionConfig(WebAppType webApp, MergeContext context) {
+        SessionConfigType sessionConfig = (SessionConfigType) context.getAttribute("session-config");
+        if (sessionConfig == null) {
+            sessionConfig = webApp.addNewSessionConfig();
+            context.setAttribute("session-config", sessionConfig);
+        }
+        return sessionConfig;
+    }
+
+    private void mergeSessionConfig(WebAppType webApp, SessionConfigType sessionConfig, MergeContext
context, ElementSource elementSource) throws DeploymentException {
+        if (sessionConfig.isSetSessionTimeout()) {
+            if (mergeSingleAttribute(context, "timeout", "session-config.session-timeout",
sessionConfig.getSessionTimeout().getStringValue(), null, elementSource)) {
+                getSessionConfig(webApp, context).addNewSessionTimeout().set(sessionConfig.getSessionTimeout());
+            }
+        }
+        if (sessionConfig.isSetCookieConfig()) {
+            CookieConfigType cookieConfig = sessionConfig.getCookieConfig();
+            if (cookieConfig.isSetName() && mergeSingleAttribute(context, "name",
"session-config.cookie-config.name", cookieConfig.getName().getStringValue(), null, elementSource))
{
+                getCookieConfig(webApp, context).addNewName().set(cookieConfig.getName());
+            }
+            if (cookieConfig.isSetDomain() && mergeSingleAttribute(context, "domain",
"session-config.cookie-config.domain", cookieConfig.getDomain().getStringValue(), null, elementSource))
{
+                getCookieConfig(webApp, context).addNewDomain().set(cookieConfig.getDomain());
+            }
+            if (cookieConfig.isSetPath() && mergeSingleAttribute(context, "path",
"session-config.cookie-config.path", cookieConfig.getPath().getStringValue(), null, elementSource))
{
+                getCookieConfig(webApp, context).addNewPath().set(cookieConfig.getPath());
+            }
+            if (cookieConfig.isSetComment() && mergeSingleAttribute(context, "comment",
"session-config.cookie-config.comment", cookieConfig.getComment().getStringValue(), null,
elementSource)) {
+                getCookieConfig(webApp, context).addNewComment().set(cookieConfig.getComment());
+            }
+            if (cookieConfig.isSetHttpOnly() && mergeSingleAttribute(context, "http-only",
"session-config.cookie-config.http-only", cookieConfig.getHttpOnly().getStringValue(), null,
elementSource)) {
+                getCookieConfig(webApp, context).addNewHttpOnly().set(cookieConfig.getHttpOnly());
+            }
+            if (cookieConfig.isSetSecure() && mergeSingleAttribute(context, "secure",
"session-config.cookie-config.secure", cookieConfig.getSecure().getStringValue(), null, elementSource))
{
+                getCookieConfig(webApp, context).addNewSecure().set(cookieConfig.getSecure());
+            }
+            if (cookieConfig.isSetMaxAge() && mergeSingleAttribute(context, "max-age",
"session-config.cookie-config.max-age", cookieConfig.getMaxAge().getStringValue(), null, elementSource))
{
+                getCookieConfig(webApp, context).addNewMaxAge().set(cookieConfig.getMaxAge());
+            }
+        }
+        if (elementSource.equals(ElementSource.WEB_FRAGMENT) && sessionConfig.getTrackingModeArray().length
> 0) {
+            for (TrackingModeType trackingMode : sessionConfig.getTrackingModeArray()) {
+                if (!context.containsAttribute("session-config.tracking-mode." + trackingMode.getStringValue()))
{
+                    getSessionConfig(webApp, context).addNewTrackingMode().set(trackingMode);
+                    context.setAttribute("session-config.tracking-mode." + trackingMode.getStringValue(),
Boolean.TRUE);
+                }
+            }
+        }
+    }
+
+    private boolean mergeSingleAttribute(MergeContext mergeContext, String elementName, String
key, String value, String jarUrl, ElementSource elementSource) throws DeploymentException
{
+        MergeItem mergeItem = (MergeItem) mergeContext.getAttribute(key);
+        if (mergeItem != null) {
+            if (mergeItem.getSourceType().equals(ElementSource.WEB_FRAGMENT)) {
+                if (!mergeItem.getValue().equals(value)) {
+                    throw new DeploymentException(WebDeploymentMessageUtils.createDuplicateValueMessage("session-config",
elementName, (String) mergeItem.getValue(), mergeItem.getBelongedURL(),
+                            value, jarUrl));
+                }
+            }
+            return false;
+        } else {
+            mergeContext.setAttribute(key, new MergeItem(value, jarUrl, elementSource));
+            return elementSource.equals(ElementSource.WEB_FRAGMENT);
+        }
+    }
 }

Modified: geronimo/server/trunk/plugins/j2ee/geronimo-web-2.5-builder/src/main/java/org/apache/geronimo/web25/deployment/utils/WebDeploymentMessageUtils.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/j2ee/geronimo-web-2.5-builder/src/main/java/org/apache/geronimo/web25/deployment/utils/WebDeploymentMessageUtils.java?rev=946928&r1=946927&r2=946928&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/j2ee/geronimo-web-2.5-builder/src/main/java/org/apache/geronimo/web25/deployment/utils/WebDeploymentMessageUtils.java
(original)
+++ geronimo/server/trunk/plugins/j2ee/geronimo-web-2.5-builder/src/main/java/org/apache/geronimo/web25/deployment/utils/WebDeploymentMessageUtils.java
Fri May 21 08:02:09 2010
@@ -38,6 +38,8 @@ public class WebDeploymentMessageUtils {
 
     private static MessageFormat MULTIPLE_CONFIGURATION_WEB_APP_ERROR_MESSAGE_FORMAT = new
MessageFormat("Only one element of {0} could be configured in web.xml");
 
+    private static MessageFormat MULTIPLE_CONFIGURATION_WEB_FRAGMENT_ERROR_MESSAGE_FORMAT
= new MessageFormat("Only one element of {0} could be configured in web-fragment.xml of the
jar file {1}");
+
     private static MessageFormat INVALID_URL_PATTERN_ERROR_MESSAGE = new MessageFormat("Invalid
character CR(#xD) or LF(#xA) is found in <url-pattern> {2} of {0} {1} from {3}");
 
     public static String createDuplicateJNDIRefMessage(String elementName, String refName,
String jarUrlA, String jarUrlB) {
@@ -61,6 +63,10 @@ public class WebDeploymentMessageUtils {
         return MULTIPLE_CONFIGURATION_WEB_APP_ERROR_MESSAGE_FORMAT.format(new Object[] {
elementName });
     }
 
+    public static String createMultipleConfigurationWebFragmentErrorMessage(String elementName,
String jarUrl) {
+        return MULTIPLE_CONFIGURATION_WEB_FRAGMENT_ERROR_MESSAGE_FORMAT.format(new Object[]
{ elementName, jarUrl });
+    }
+
     public static String createInvalidUrlPatternErrorMessage(String parentElementName, String
parentElement, String urlPattern, String location) {
         return INVALID_URL_PATTERN_ERROR_MESSAGE.format(new Object[] { parentElementName,
parentElement, urlPattern, location });
     }



Mime
View raw message