1 24 package org.ofbiz.base.util; 25 26 import javax.servlet.ServletContext ; 27 28 35 public class UtilJ2eeCompat { 36 37 public static final String module = UtilJ2eeCompat.class.getName(); 38 39 public static final String TOMCAT = "Apache Tomcat"; 40 public static final String ORION = "Orion"; 41 public static final String RESIN = "Resin"; 42 public static final String REX_IP = "TradeCity"; 43 public static final String OC4J = "Oracle"; 44 public static final String JRUN = "JRun"; 45 public static final String JETTY = "Jetty"; 46 public static final String WEBSPHERE = "Websphere"; 47 48 protected static Boolean doFlushOnRenderValue = null; 49 protected static Boolean useOutputStreamNotWriterValue = null; 50 protected static Boolean useNestedJspException = null; 51 52 public static boolean doFlushOnRender(ServletContext context) { 53 initCompatibilityOptions(context); 54 return doFlushOnRenderValue.booleanValue(); 55 } 56 57 public static boolean useOutputStreamNotWriter(ServletContext context) { 58 initCompatibilityOptions(context); 59 return useOutputStreamNotWriterValue.booleanValue(); 60 } 61 62 public static boolean useNestedJspException(ServletContext context) { 63 initCompatibilityOptions(context); 64 return useNestedJspException.booleanValue(); 65 } 66 67 protected static void initCompatibilityOptions(ServletContext context) { 68 if (useOutputStreamNotWriterValue == null || doFlushOnRenderValue == null) { 71 boolean doflush = true; 72 boolean usestream = true; 73 boolean nestjspexception = true; 74 String serverInfo = context == null ? "" : context.getServerInfo(); 76 77 Debug.logInfo("serverInfo: " + serverInfo, module); 78 79 if (serverInfo.indexOf(RESIN) >= 0) { 80 Debug.logImportant("Resin detected, disabling the flush on the region render from PageContext for better performance", module); 81 doflush = false; 82 } else if (serverInfo.indexOf(REX_IP) >= 0) { 83 Debug.logImportant("Trade City RexIP detected, using response.getWriter to write text out instead of response.getOutputStream", module); 84 usestream = false; 85 } else if (serverInfo.indexOf(TOMCAT) >= 0) { 86 Debug.logImportant("Apache Tomcat detected, using response.getWriter to write text out instead of response.getOutputStream", module); 87 usestream = false; 88 } else if (serverInfo.indexOf(JRUN) >= 0) { 89 Debug.logImportant("JRun detected, using response.getWriter to write text out instead of response.getOutputStream", module); 90 usestream = false; 91 } else if (serverInfo.indexOf(JETTY) >= 0) { 92 Debug.logImportant("Jetty detected, using response.getWriter to write text out instead of response.getOutputStream", module); 93 usestream = false; 94 } else if (serverInfo.indexOf(ORION) >= 0) { 95 Debug.logImportant("Orion detected, using response.getWriter to write text out instead of response.getOutputStream", module); 96 usestream = false; 97 Debug.logImportant("Orion detected, using non-nested JspException", module); 98 nestjspexception = false; 99 } else if (serverInfo.indexOf(WEBSPHERE) >= 0) { 100 Debug.logImportant("IBM Websphere Application Server detected, using response.getWriter to write text out instead of response.getOutputStream", module); 101 usestream = false; 102 } 103 104 doFlushOnRenderValue = new Boolean (doflush); 105 useOutputStreamNotWriterValue = new Boolean (usestream); 106 useNestedJspException = new Boolean (nestjspexception); 107 } 108 } 109 } 110 | Popular Tags |