DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://issues.apache.org/bugzilla/show_bug.cgi?id=31851>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=31851 UserTransaction not working if declared inside a DefaultContext Summary: UserTransaction not working if declared inside a DefaultContext Product: Tomcat 5 Version: 5.0.29 Platform: All OS/Version: Other Status: NEW Severity: Normal Priority: Other Component: Catalina AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] Hi, As of tomcat-5.0.29, it is not possible to have a java:/comp/UserTransaction resource working if declared from a <DefaultContext> ResourceLink. (ie) : ....... <GlobalNamingResources> <Resource name="UTransaction" auth="Container" type="javax.transaction.UserTransaction"/> <ResourceParams name="UTransaction"> <parameter> <name>factory</name> <value>org.objectweb.jotm.UserTransactionFactory</value> </parameter> <parameter> <name>jotm.timeout</name> <value>60</value> </parameter> </ResourceParams> </GlobalNamingResources> ....... <Host> <DefaultContext> <ResourceLink name="UserTransaction" global="UTransaction" type="javax.transaction.UserTransaction"/> </DefaultContext> </Host> ..... As far as i have investigated the problem, <DefaultContext> resources are not avaliable as NamingResources when NamingContextListener creates the NamingContext for the Context (NamingContextListener.createNamingContext()). So at the moment NamingContext (webapp is being loaded) is created, the java:/comp/UserTransation resource is added with an empty TransactionRef object. Later, in the life cicle, when DefaultContext resources are added to the context, in this case a ResourceLink pointing to the UserTransaction global resource, we get a NameAlreadyBoundException, so the previously registered TransactionRef object remains without config parameters. The UserTransaction works fine if included in each application's own context.xml file. There are, at least, two possible solutions for this issue, without messing around with WebAppLoader (<DefaultConxtext> has been rewriten for 5.5.x). Which one should be taken (if) ? A) one solution that does not interfere if an UserTransaction has been successfully registered by a <Context> element (more power to the web-application) even if there is a UserTransaction Resource element in a <DefaultContext>. This is the solution I've made a patch for, and IMHO makes more sense regarding a <DefaultContext> concept. It is attached in the end of this report. B) if a UserTransaction is present in a <DefaultContext>, it will be the available one. This behavior is the current behavior for the StandardDefaultContext implementation regarding all resources inside a <DefaultContext> (yes, the implementation unregisters previous resources from <Context> initializations per web-application, and override them with equally named resources (if) available inside a <DefaultContext> for a <Host>). I have a possible patch proposal for this, but did not investigated (tested) it yet. I haven't found any notes regarding this anywhere (manual, list and Bugzilla). Thanks. -----------------BEGIN --- jakarta-tomcat-5.0.29-src/jakarta-tomcat-catalina/catalina/src/share/org/apa che/catalina/core/NamingContextListener.java 2004-10-22 11:38:27.000000000 -0 200 +++ NamingContextListener.java 2004-10-22 11:35:23.000000000 -0200 @@ -33,6 +33,7 @@ import org.apache.catalina.ContainerEvent; import org.apache.catalina.ContainerListener; import org.apache.catalina.Context; +import org.apache.catalina.DefaultContext; import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleEvent; import org.apache.catalina.LifecycleListener; @@ -898,14 +899,56 @@ javax.naming.Context ctx = "UserTransaction".equals(resourceLink.getName()) ? compCtx : envCtx; + int try_again = 0; try { if (debug >= 2) log(" Adding resource link " + resourceLink.getName()); createSubcontexts(envCtx, resourceLink.getName()); ctx.bind(resourceLink.getName(), ref); } catch (NamingException e) { - log(sm.getString("naming.bindFailed", e)); - } + if (container instanceof Context + && "UserTransaction".equals(resourceLink.getName()) ) { + try_again = 1; + } else log(sm.getString("naming.bindFailed", e)); + } + if (try_again == 1) { + // As DefaultContext resources are not avaliable + // at NamingContext initialization, lets give + // it a chance to register a UserTransaction + // if the initialized one stills empty + try { + if ( debug >=2 ) + log(" Trying again adding " + resourceLink.getN ame() + " now from DefaultContext"); + Object orig_ref = compCtx.lookup("UserTransaction"); + if ( debug >=2 ) + log(" Got initial UserTransaction Reference"); + try_again = 0; + } catch (NamingException e) { + // Initial UserTransaction empty + try_again = 1; + } + + if (try_again == 1) { + try { + if (debug >=2 ) + log(" Trying to unbind initial UserTran saction Reference"); + ctx.unbind("UserTransaction"); + if (debug >=2 ) + log(" Unbinding empty UserTransaction " ); + } catch (NamingException e) { + // Nothing to be done + } + } + // Either way, at this point, or we are + // registering the DefaultContext + // UserTransaction Ref, or it will throw the right + // NameAlreadyBoudException + try { + ctx.bind(resourceLink.getName(), ref); + } catch (NamingException e) { + log(sm.getString("naming.bindFailed", e)); + } + } } -------------------END --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]