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 */ 019 package org.apache.wiki.util; 020 021 import org.apache.log4j.Logger; 022 023 /** 024 * Misc J2EE Compatibility Utility Functions 025 */ 026 public class UtilJ2eeCompat 027 { 028 private static Logger log = Logger.getLogger( UtilJ2eeCompat.class.getName() ); 029 030 public static final String TOMCAT = "Apache Tomcat"; 031 032 public static final String ORION = "Orion"; 033 034 public static final String RESIN = "Resin"; 035 036 public static final String REX_IP = "TradeCity"; 037 038 public static final String OC4J = "Oracle"; 039 040 public static final String JRUN = "JRun"; 041 042 public static final String JETTY = "Jetty"; 043 044 public static final String WEBSPHERE = "Websphere"; 045 046 public static final String WEBLOGIC = "WebLogic"; 047 048 public static final String GLASSFISH = "Sun Java System Application Server"; 049 050 public static final String JBOSS = "JBoss"; 051 052 /** 053 * 054 */ 055 protected static Boolean useOutputStreamValue = null; 056 057 private static String m_serverInfo; 058 059 /** 060 * Determines the response wrapper for the servlet filters 061 * 062 * @param serverInfo The string returned from context.getServerInfo() 063 * @return <code>true</code> if standard response wrapper does not work 064 * properly; <code>false</code> default, otherwise 065 */ 066 public static boolean useOutputStream( String serverInfo ) 067 { 068 if( useOutputStreamValue == null ) 069 { 070 initCompatibilityOptions( serverInfo ); 071 } 072 return useOutputStreamValue.booleanValue(); 073 } 074 075 /** 076 * For testing only 077 * 078 * @param serverInfo The string returned from context.getServerInfo() 079 * @param boolInitialize True, if you want to force initialization again 080 * @return <code>true</code> if standard response wrapper does not work 081 * properly; <code>false</code> default, otherwise 082 */ 083 public static boolean useOutputStream( String serverInfo, Boolean boolInitialize ) 084 { 085 if( (useOutputStreamValue == null) | (boolInitialize) ) 086 { 087 initCompatibilityOptions( serverInfo ); 088 } 089 return useOutputStreamValue.booleanValue(); 090 } 091 092 /** 093 * Simple check of the servlet container 094 * 095 * @param serverInfo The string returned from context.getServerInfo() 096 */ 097 protected static void initCompatibilityOptions( String serverInfo ) 098 { 099 log.info( "serverInfo: " + serverInfo ); 100 m_serverInfo = serverInfo; 101 // response.getWriter is the default 102 boolean useStream = false; 103 if( serverInfo.indexOf( RESIN ) >= 0 ) 104 { 105 log.info( RESIN + " detected" ); 106 // use response.getOutputStream instead of response.getWriter 107 useStream = true; 108 } 109 else if( serverInfo.indexOf( REX_IP ) >= 0 ) 110 { 111 log.info( REX_IP + " detected" ); 112 } 113 else if( serverInfo.indexOf( TOMCAT ) >= 0 ) 114 { 115 log.info( TOMCAT + " detected" ); 116 // use response.getOutputStream instead of response.getWriter 117 useStream = true; 118 } 119 else if( serverInfo.indexOf( JRUN ) >= 0 ) 120 { 121 log.info( JRUN + " detected" ); 122 } 123 else if( serverInfo.indexOf( JETTY ) >= 0 ) 124 { 125 log.info( JETTY + " detected" ); 126 } 127 else if( serverInfo.indexOf( ORION ) >= 0 ) 128 { 129 log.info( ORION + " detected" ); 130 } 131 else if( serverInfo.indexOf( WEBSPHERE ) >= 0 ) 132 { 133 log.info( WEBSPHERE + " detected" ); 134 } 135 else if( serverInfo.indexOf( WEBLOGIC ) >= 0 ) 136 { 137 log.info( WEBLOGIC + " detected" ); 138 // use response.getOutputStream instead of response.getWriter 139 useStream = true; 140 } 141 else if( serverInfo.indexOf( GLASSFISH ) >= 0 ) 142 { 143 log.info( GLASSFISH + " detected" ); 144 } 145 else if( serverInfo.indexOf( OC4J ) >= 0 ) 146 { 147 log.info( "Oracle Container for JEE detected" ); 148 // use response.getOutputStream instead of response.getWriter 149 useStream = true; 150 } 151 else if( serverInfo.indexOf( JBOSS ) >= 0 ) 152 { 153 log.info( JBOSS + " detected" ); 154 // use response.getOutputStream instead of response.getWriter 155 useStream = true; 156 } 157 useOutputStreamValue = new Boolean( useStream ); 158 } 159 160 /** 161 * @return the Container type that has been detected 162 */ 163 public static String getServerInfo() 164 { 165 return m_serverInfo; 166 } 167 168 }