Commits

Anonymous committed ad3280a

fix for WW-1336 (makes this work better on WebLogic 8.1)

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@2675573baa09-0c28-0410-bef9-dab3c582ae83

Comments (0)

Files changed (1)

src/java/com/opensymphony/webwork/views/freemarker/FreemarkerResult.java

         if (preTemplateProcess(template, model)) {
             try {
                 // Process the template
-                template.process(model, getWriter());
+                // First, get the writer
+                Writer writer = null;
+                boolean useOutputStream = false;
+                try {
+                    writer = getWriter();
+                }
+                catch (IllegalStateException ise) {
+                    // Getting the writer failed, try using getOutputStream()
+                    // This can happen on some application servers such as WebLogic 8.1
+                    useOutputStream = true;
+                }
+                if (useOutputStream) {
+                    // Use a StringWriter as a buffer to write the template output to
+                    writer = new java.io.StringWriter();
+                    template.process(model, writer);
+                    // Then write the contents of the writer to the OutputStream
+                    java.io.OutputStream os = ServletActionContext.getResponse().getOutputStream();
+                    os.write(writer.toString().getBytes());
+                }
+                else {
+                    // Process the template with the normal writer since it was available
+                    template.process(model, writer);
+                }
             } finally {
                 // Give subclasses a chance to hook into postprocessing
                 postTemplateProcess(template, model);