001: /*******************************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *******************************************************************************/package org.ofbiz.base.util;
019:
020: import javax.servlet.ServletContext;
021:
022: /**
023: * Misc J2EE Compatibility Utility Functions
024: *
025: */
026: public class UtilJ2eeCompat {
027:
028: public static final String module = UtilJ2eeCompat.class.getName();
029:
030: public static final String TOMCAT = "Apache Tomcat";
031: public static final String ORION = "Orion";
032: public static final String RESIN = "Resin";
033: public static final String REX_IP = "TradeCity";
034: public static final String OC4J = "Oracle";
035: public static final String JRUN = "JRun";
036: public static final String JETTY = "Jetty";
037: public static final String WEBSPHERE = "Websphere";
038:
039: protected static Boolean doFlushOnRenderValue = null;
040: protected static Boolean useOutputStreamNotWriterValue = null;
041: protected static Boolean useNestedJspException = null;
042:
043: public static boolean doFlushOnRender(ServletContext context) {
044: initCompatibilityOptions(context);
045: return doFlushOnRenderValue.booleanValue();
046: }
047:
048: public static boolean useOutputStreamNotWriter(
049: ServletContext context) {
050: initCompatibilityOptions(context);
051: return useOutputStreamNotWriterValue.booleanValue();
052: }
053:
054: public static boolean useNestedJspException(ServletContext context) {
055: initCompatibilityOptions(context);
056: return useNestedJspException.booleanValue();
057: }
058:
059: protected static void initCompatibilityOptions(
060: ServletContext context) {
061: // this check to see if we should flush is done because on most servers this
062: // will just slow things down and not solve any problems, but on Tomcat, Orion, etc it is necessary
063: if (useOutputStreamNotWriterValue == null
064: || doFlushOnRenderValue == null) {
065: boolean doflush = true;
066: boolean usestream = true;
067: boolean nestjspexception = true;
068: // if context is null use an empty string here which will cause the defaults to be used
069: String serverInfo = context == null ? "" : context
070: .getServerInfo();
071:
072: Debug.logInfo("serverInfo: " + serverInfo, module);
073:
074: if (serverInfo.indexOf(RESIN) >= 0) {
075: Debug
076: .logImportant(
077: "Resin detected, disabling the flush on the region render from PageContext for better performance",
078: module);
079: doflush = false;
080: } else if (serverInfo.indexOf(REX_IP) >= 0) {
081: Debug
082: .logImportant(
083: "Trade City RexIP detected, using response.getWriter to write text out instead of response.getOutputStream",
084: module);
085: usestream = false;
086: } else if (serverInfo.indexOf(TOMCAT) >= 0) {
087: Debug
088: .logImportant(
089: "Apache Tomcat detected, using response.getWriter to write text out instead of response.getOutputStream",
090: module);
091: usestream = false;
092: } else if (serverInfo.indexOf(JRUN) >= 0) {
093: Debug
094: .logImportant(
095: "JRun detected, using response.getWriter to write text out instead of response.getOutputStream",
096: module);
097: usestream = false;
098: } else if (serverInfo.indexOf(JETTY) >= 0) {
099: Debug
100: .logImportant(
101: "Jetty detected, using response.getWriter to write text out instead of response.getOutputStream",
102: module);
103: usestream = false;
104: } else if (serverInfo.indexOf(ORION) >= 0) {
105: Debug
106: .logImportant(
107: "Orion detected, using response.getWriter to write text out instead of response.getOutputStream",
108: module);
109: usestream = false;
110: Debug
111: .logImportant(
112: "Orion detected, using non-nested JspException",
113: module);
114: nestjspexception = false;
115: } else if (serverInfo.indexOf(WEBSPHERE) >= 0) {
116: Debug
117: .logImportant(
118: "IBM Websphere Application Server detected, using response.getWriter to write text out instead of response.getOutputStream",
119: module);
120: usestream = false;
121: }
122:
123: doFlushOnRenderValue = new Boolean(doflush);
124: useOutputStreamNotWriterValue = new Boolean(usestream);
125: useNestedJspException = new Boolean(nestjspexception);
126: }
127: }
128: }
|