You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2011/07/26 12:11:48 UTC

DO NOT REPLY [Bug 51558] New: Tomcat Embedded: using tomcat.addWebapp always overrides programmatic context-settings with default values for the context at start of tomcat server

https://issues.apache.org/bugzilla/show_bug.cgi?id=51558

             Bug #: 51558
           Summary: Tomcat Embedded: using tomcat.addWebapp always
                    overrides programmatic context-settings with default
                    values for the context at start of tomcat server
           Product: Tomcat 7
           Version: 7.0.16
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
        AssignedTo: dev@tomcat.apache.org
        ReportedBy: berndhuber98@googlemail.com
    Classification: Unclassified


when i deploy an webapp with a tomcat server, i use the Function
"tomcat.addWebapp". I looked into the code of this function and it makes the
following call:

     ctx.addLifecycleListener(new DefaultWebXmlListener());

When i start tomcat, this DefaultWebXmlListener is activated automatically, and
always does the following code, so the manager i set for my context gets
overriden with this code:

     public static void initWebappDefaults(Context ctx) {
        ...
        // Sessions
        ctx.setManager( new StandardManager());
        ctx.setSessionTimeout(30);
        ...
     }

so when i set a StandardManager programatically, it gets overriden by this
code. The workaround i used, is to unregister the DefaultWebXmlListener, and
than add my own context.xml specific settings, like a custom manager for
deactivating session persistance:

     Context warContext = tomcat.addWebapp(warContextPath, warLocation);

     LifecycleListener[] lclisteners = warContext.findLifecycleListeners();
     LifecycleListener defaultWebXMLListener = null;
     for (int i=0; i < lclisteners.length; i++){
       if (lclisteners[i] instanceof DefaultWebXmlListener){
         defaultWebXMLListener = lclisteners[i];
       }
     }
     warContext.removeLifecycleListener(defaultWebXMLListener);
     ...
     StandardManager manager = new StandardManager();
     manager.setPathname(null); // disable session persistance:
     //manager.setPathname("SESSIONS.ser");     
     warContext.setCookies(true);
     warContext.setCrossContext(true);
     warContext.setManager(manager);

i think its a bug that using the "tomcat.addWebapp" method makes it impossible
to set context.xml specific settings programmatically, because they always get
overriden by default values at the tomcat start.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 51558] Tomcat Embedded: using tomcat.addWebapp always overrides programmatic context-settings with default values for the context at start of tomcat server

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=51558

--- Comment #5 from Martin Grotzke <ma...@googlemail.com> 2011-08-24 22:56:36 UTC ---
Created attachment 27432
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=27432
Attached patch that only sets StandardManager if the manager is not already set

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 51558] Tomcat Embedded: using tomcat.addWebapp always overrides programmatic context-settings with default values for the context at start of tomcat server

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=51558

--- Comment #3 from bhuber <be...@googlemail.com> 2011-07-26 11:20:10 UTC ---
ah sorry, its ok nevermind .. i know now how to do it: ;-)
like you said, i will now just create a standardcontext instead, 
and just dont add a defaultwebxmllistener ...

  Context ctx = new StandardContext();
  ctx.setName(name);
  ctx.setPath(url);
  ctx.setDocBase(path);
  if (defaultRealm == null) {
      initSimpleAuth();
  }
  ctx.setRealm(defaultRealm);

  ContextConfig ctxCfg = new ContextConfig();
  ctx.addLifecycleListener(ctxCfg);

  // prevent it from looking ( if it finds one - it'll have dup error )
  ctxCfg.setDefaultWebXml("org/apache/catalin/startup/NO_DEFAULT_XML");

  if (host == null) {
     getHost().addChild(ctx);
  } else {
      host.addChild(ctx);
  }

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 51558] Tomcat Embedded: using tomcat.addWebapp always overrides programmatic context-settings with default values for the context at start of tomcat server

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=51558

Martin Grotzke <ma...@googlemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |

--- Comment #4 from Martin Grotzke <ma...@googlemail.com> 2011-08-24 22:47:40 UTC ---
A user of memcached-session-manager also ran into this issue and it took me
some time that when using addWebapp the manager is just overwritten.

I'd suggest to set the StandardManager only if there's no manager set on the
context.

Are there any problems why this should not be done?

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 51558] Tomcat Embedded: using tomcat.addWebapp always overrides programmatic context-settings with default values for the context at start of tomcat server

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=51558

--- Comment #2 from bhuber <be...@googlemail.com> 2011-07-26 11:13:18 UTC ---
(In reply to comment #1)
> Use addContext()

because i need to deploy a WAR-File, that includes a web.xml file, it would be 
more complicated to use addContext(), because i cant find any examples in the
web that use addContext() in combination with web.xml...

but your right, this should be a missing feature, not a bug. I hope some
official documentation for tomcat-embedded will be available soon.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 51558] Tomcat Embedded: using tomcat.addWebapp always overrides programmatic context-settings with default values for the context at start of tomcat server

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=51558

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #6 from Mark Thomas <ma...@apache.org> 2011-08-26 16:09:52 UTC ---
StandardContext already conditionally adds a StandardManager if one is not set.

Since the offending code is meant to be replicating conf/web.xml (which can't
set internal Tomcat components) I have simply removed this code from the
listener.

The fix has been applied to trunk and 7.0.x and will be included in 7.0.21
onwards.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 51558] Tomcat Embedded: using tomcat.addWebapp always overrides programmatic context-settings with default values for the context at start of tomcat server

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=51558

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID

--- Comment #1 from Mark Thomas <ma...@apache.org> 2011-07-26 10:24:27 UTC ---
Use addContext()

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org