From: Keats K. <ke...@xa...> - 2005-05-25 04:55:01
|
Rab Wallace wrote: >Keats >I tried your example and it works ok! But, my simple >test bean still refused to cooperate when >scope=session. I've got logging in the constructor and >the test bean is getting instantiated *every* time the >page loads (I don't think this is correct behaviour >for session scope). How can it be instantiated, but my >template not 'see' any methods on the bean? > > This is curious. For session scope, the BeanDirective tests if an attribute exists in the session, and if not it instantiates the object and sets the attribute. If your class is getting instantiated on each request then it is either not getting into the session, or it is getting removed, or the session is getting recreated. Here are some suggestions: - Make sure you have your logging level set to Debug. The #bean directive should log each time it runs. - You could make your class implement HttpSessionBindingListener and then log each time it is bound or unbound to the session (in the valueBound/valueUnbound methods). - You might also try referencing the attribute directly through the $Session tool before and after the #bean statement. E.g., Session $Session.Id, created $Session.CreationTime<br> Before bean directive: [test=$Session.test]<br> #bean $test="com.myteststuff.Test" scope=session After bean directive: [test=$Session.test]<br> If you can send me a small example that exhibits the problem, I'll be glad to try and debug it. There can be some confusion here due the fact that the session-scoped #bean objects share the same namespace as any other session object. So if an attribute with the same name is placed in the session before the #bean is evaluated, the statement will have no effect. I've considered using a separate namespace for #bean session objects, but I'm not convinced this is the right way to go. (I hope to address this in the future along with the concept of scoped variables in the context.) >I'm curious about your comment about my BeanDirective >security, are you referring to something in >webmacro.properties? > > Yes. You can restrict what packages classes can be instantiated from by the #bean directive, e.g., BeanDirective.AllowedPackages: com.mystuff, com.mystuff.extra This helps alleviate some of the dangerous things that people might try to do with the #bean directive. Good luck. Keats >Many thanks. > >Rab Wallace > >--- Keats Kirsch <ke...@xa...> wrote: > > > >>I spent a couple of hours setting up Tomcat 5.5.9 >>and cooking up some >>test cases and I can't reproduce your problem. >> >>I put the following into a sandbox template, with no >>problem. I'm using >>Win2K with Sun JRE 1.5.0_02. I also tested with >>Tomcat 4.1 and 5.0 with >>JDK 1.4.2. >> >>Your error indicates that your class wasn't >>instantiated. You might try >>putting some logging into the constructor to see >>what's going on. Also >>check your BeanDirective security settings. Good >>luck. >> >>Keats >> >>Sample WMScript: >> >>#bean $testbean = "com.xaltus.wm.Test" scope=session >>onNew >> #set $testbean.Num = 2 >>#end >>#set $testbean.Num = $testbean.Num * 2 >>testbean.Num = $testbean.Num<br><br> >> >>#bean $counts = "java.util.HashMap" scope=session >>onNew >> #set $counts.Hits = 0 >>#end >>#set $counts.Hits = $counts.Hits + 1 >>Number of visits to this page in this session: >>$counts.Hits<br><br> >> >> >> >>Rab Wallace wrote: >> >> >> >>>I recently upgraded to Tomcat 5.5.9 and noticed all my >>> >>> >>>pages with a #bean...scope=session no longer works >>>(scope=page works fine), anyone else seen this? >>> >>>I tried a simple example: >>>A simple bean 'com.myteststuff.Test' has a single long >>> >>> >>>attribute 'value' and a getter & setter. In my >>>template, I've got: >>> >>>#bean $test="com.myteststuff.Test" scope=session >>>$test.setValue(123) >>> >>>results in the exception below. If I switch to >>>scope=page, everything works fine. Earlier version >>> >>> >>of >> >> >>>Tomcat also ok. Thanks for any advice. >>> >>>Rab Wallace >>> >>>ps. this problem exists on both the latest Webmacro >>>(2.0rc1) and at least the previous version (2.0b1). >>> >>> >>> >>> >>org.webmacro.PropertyException$NoSuchMethodException: >> >> >>>No public method setValue(123) on variable $test of >>>class org.webmacro.engine.UndefinedMacro at >>> >>> >>jndi:/localhost/metridium_jboss/skins/kelpforest/kelpforest_DefaultMainPage.wm:229.1 >> >> >>> at >>> >>> >>org.webmacro.engine.PropertyOperator.getProperty(PropertyOperatorCache.java:716) >> >> >>> at >>> >>> >>org.webmacro.engine.PropertyOperatorCache.getProperty(PropertyOperatorCache.java:163) >> >> >>> at >>> >>> >>org.webmacro.Context.internalGet(Context.java:383) >> >> >>> at >>> >>> >>org.webmacro.Context.getProperty(Context.java:443) >> >> >>> at >>> >>> >>org.webmacro.engine.PropertyVariable.getValue(PropertyVariable.java:52) >> >> >>> at >>> >>> >>org.webmacro.engine.Variable.write(Variable.java:211) >> >> >>> at org.webmacro.engine.Block.write(Block.java:133) >>> at >>> >>> >>org.webmacro.directive.IfDirective.write(IfDirective.java:210) >> >> >>> at org.webmacro.engine.Block.write(Block.java:184) >>> at >>> >>> >>org.webmacro.directive.ForeachDirective.write(ForeachDirective.java:177) >> >> >>> at org.webmacro.engine.Block.write(Block.java:145) >>> at >>> >>> >>org.webmacro.directive.IfDirective.write(IfDirective.java:210) >> >> >>> at org.webmacro.engine.Block.write(Block.java:199) >>> at >>> >>> >>org.webmacro.engine.WMTemplate.write(WMTemplate.java:324) >> >> >>> at >>> >>> >>org.webmacro.engine.WMTemplate.evaluateAsString(WMTemplate.java:253) >> >> >>> at >>> >>> >>com.metridia.metridium.servlets.MetridiumServlet.renderPageAlias(MetridiumServlet.java:743) >> >> >>> at >>> >>> >>com.metridia.metridium.servlets.MetridiumServlet.doGet(MetridiumServlet.java:598) >> >> >>> at >>> >>> >>javax.servlet.http.HttpServlet.service(HttpServlet.java:689) >> >> >>> at >>> >>> >>javax.servlet.http.HttpServlet.service(HttpServlet.java:802) >> >> >>> at >>> >>> >>org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) >> >> >>> at >>> >>> >>org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) >> >> >>> at >>> >>> >>org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) >> >> >>> at >>> >>> >>org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) >> >> >>> at >>> >>> >>org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:407) >> >> >>> at >>> >>> >>org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) >> >> >>> at >>> >>> >>org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) >> >> >>> at >>> >>> >>org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) >> >> >>> at >>> >>> >>org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) >> >> >>> at >>> >>> >>org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:307) >> >> >>> at >>> >>> >>org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:385) >> >> >>> at >>> >>> >>org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:748) >> >> >>> at >>> >>> >>org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:678) >> >> >>> at >>> >>> >>org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:871) >> >> >>> at >>> >>> >>org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) >> >> >>> at java.lang.Thread.run(Unknown Source) >>> >>> >>> >>> |