Uploaded image for project: 'Magnolia Groovy Module'
  1. Magnolia Groovy Module
  2. MGNLGROOVY-46

Script output seems to split into different output streams

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Neutral Neutral
    • None
    • None
    • console
    • None

      Greg reported to me a weird behavior while using the groovy module with the following script.

      hm = ctx.getHierarchyManager("website");
      
      println "Before visit"
      
      ContentUtil.visit(hm.root, new ContentUtil.Visitor() {
      void visit(Content node) {
        println "From Visitor as anonymous impl"
      }
      })
        
      println "After first visit"
        
      ContentUtil.visit(hm.root, {
        println "From visitor as closure"
      } as ContentUtil.Visitor)
        
      println "After both visits"
      

      The result of running this within the dialog or console is that "From Visitor as anonymous impl" gets printed in sys console, all the rest in the dialog/console as expected. I had a quick look at the code in debug mode and what I found is that info.magnolia.module.groovy.console.MgnlGroovyConsole.evaluate(InputStream, String, Writer) at line 74 executing script.run() prints the output that goes to the sys console, whereas
      what ends up being displayed in the dialog console is printed later on when the response has been presumably committed. The Writer object passed in the evaluate method above is an instance of PrintWriter which is obtained with response.getPrintWriter(). It looks like the Groovy's Script class internally redirects part of the response to a different output stream than that being set as a value of the 'out' property (see http://groovy.codehaus.org/gapi/groovy/lang/Script.html#println(java.lang.Object))

        Acceptance criteria

              fgrilli Federico Grilli
              fgrilli Federico Grilli
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: