You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by me...@apache.org on 2008/09/03 21:45:34 UTC
svn commit: r691749 - in /incubator/jspwiki/trunk: ChangeLog
src/com/ecyrd/jspwiki/Release.java
src/com/ecyrd/jspwiki/ui/WikiJSPFilter.java
src/com/ecyrd/jspwiki/util/UtilJ2eeCompat.java
tests/com/ecyrd/jspwiki/util/UtilJ2eeCompatTest.java
Author: metskem
Date: Wed Sep 3 12:45:34 2008
New Revision: 691749
URL: http://svn.apache.org/viewvc?rev=691749&view=rev
Log:
2.7.0-alpha-38 JSPWIKI-348: Introduced UtilJ2EECompat to check for container type (thanks to Lutz Tietze)
Added:
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/UtilJ2eeCompat.java
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/UtilJ2eeCompatTest.java
Modified:
incubator/jspwiki/trunk/ChangeLog
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/WikiJSPFilter.java
Modified: incubator/jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=691749&r1=691748&r2=691749&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Wed Sep 3 12:45:34 2008
@@ -1,3 +1,9 @@
+2008-09-03 Harry Metske <ha...@gmail.com>
+
+ * 2.7.0-alpha-38
+
+ * JSPWIKI-364: Introduced UtilJ2EECompat to check for container type (thanks to Lutz Tietze)
+
2008-09-03 Dirk Frederickx <di...@gmail.com>
* 2.7.0-alpha-37
Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java?rev=691749&r1=691748&r2=691749&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java Wed Sep 3 12:45:34 2008
@@ -77,7 +77,7 @@
* <p>
* If the build identifier is empty, it is not added.
*/
- public static final String BUILD = "37";
+ public static final String BUILD = "38";
/**
* This is the generic version string you should use
Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/WikiJSPFilter.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/WikiJSPFilter.java?rev=691749&r1=691748&r2=691749&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/WikiJSPFilter.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/WikiJSPFilter.java Wed Sep 3 12:45:34 2008
@@ -20,9 +20,7 @@
*/
package com.ecyrd.jspwiki.ui;
-import java.io.CharArrayWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
+import java.io.*;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
@@ -36,6 +34,7 @@
import com.ecyrd.jspwiki.event.WikiEventManager;
import com.ecyrd.jspwiki.event.WikiPageEvent;
import com.ecyrd.jspwiki.url.DefaultURLConstructor;
+import com.ecyrd.jspwiki.util.UtilJ2eeCompat;
import com.ecyrd.jspwiki.util.WatchDog;
/**
@@ -69,7 +68,24 @@
*/
public class WikiJSPFilter extends WikiServletFilter
{
+ private Boolean m_useOutputStream;
+
/** {@inheritDoc} */
+ public void init( FilterConfig config ) throws ServletException
+ {
+ super.init( config );
+ ServletContext context = config.getServletContext();
+ m_useOutputStream = UtilJ2eeCompat.useOutputStream( context.getServerInfo() );
+ if( m_useOutputStream )
+ {
+ log.debug( "Using ByteArrayResponseWrapper" );
+ }
+ else
+ {
+ log.debug( "Using MyServletResponseWrapper" );
+ }
+ }
+
public void doFilter( ServletRequest request,
ServletResponse response,
FilterChain chain )
@@ -81,8 +97,16 @@
NDC.push( m_engine.getApplicationName()+":"+((HttpServletRequest)request).getRequestURI() );
w.enterState("Filtering for URL "+((HttpServletRequest)request).getRequestURI(), 90 );
-
- HttpServletResponseWrapper responseWrapper = new MyServletResponseWrapper( (HttpServletResponse)response );
+ HttpServletResponseWrapper responseWrapper;
+
+ if( m_useOutputStream )
+ {
+ responseWrapper = new ByteArrayResponseWrapper( (HttpServletResponse)response );
+ }
+ else
+ {
+ responseWrapper = new MyServletResponseWrapper( (HttpServletResponse)response );
+ }
// fire PAGE_REQUESTED event
String pagename = DefaultURLConstructor.parsePageFromURL(
@@ -284,6 +308,75 @@
}
}
+ /**
+ * Response wrapper for application servers which do not work with
+ * CharArrayWriter Currently only OC4J
+ */
+ private static class ByteArrayResponseWrapper extends HttpServletResponseWrapper
+ {
+ private ByteArrayOutputStream m_output;
+
+ private HttpServletResponse m_response;
+
+ /**
+ * How large the initial buffer should be. This should be tuned to
+ * achieve a balance in speed and memory consumption.
+ */
+ private static final int INIT_BUFFER_SIZE = 4096;
+
+ public ByteArrayResponseWrapper( HttpServletResponse r )
+ {
+ super( r );
+ m_output = new ByteArrayOutputStream( INIT_BUFFER_SIZE );
+ m_response = r;
+ }
+
+ /**
+ * Returns a writer for output; this wraps the internal buffer into a
+ * PrintWriter.
+ */
+ public PrintWriter getWriter()
+ {
+ return new PrintWriter( getOutputStream(), true );
+ }
+
+ public ServletOutputStream getOutputStream()
+ {
+ return new MyServletOutputStream( m_output );
+ }
+
+ static class MyServletOutputStream extends ServletOutputStream
+ {
+ private DataOutputStream m_stream;
+
+ public MyServletOutputStream( OutputStream aOutput )
+ {
+ super();
+ m_stream = new DataOutputStream( aOutput );
+ }
+
+ public void write( int aInt ) throws IOException
+ {
+ m_stream.write( aInt );
+ }
+ }
+
+ /**
+ * Returns whatever was written so far into the Writer.
+ */
+ public String toString()
+ {
+ try
+ {
+ return m_output.toString( m_response.getCharacterEncoding() );
+ }
+ catch( UnsupportedEncodingException e )
+ {
+ log.error( ByteArrayResponseWrapper.class + " Unsupported Encoding", e );
+ return null;
+ }
+ }
+ }
// events processing .......................................................
Added: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/UtilJ2eeCompat.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/UtilJ2eeCompat.java?rev=691749&view=auto
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/UtilJ2eeCompat.java (added)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/UtilJ2eeCompat.java Wed Sep 3 12:45:34 2008
@@ -0,0 +1,156 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package com.ecyrd.jspwiki.util;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Misc J2EE Compatibility Utility Functions
+ */
+public class UtilJ2eeCompat
+{
+ private static Logger log = Logger.getLogger( UtilJ2eeCompat.class.getName() );
+
+ public static final String TOMCAT = "Apache Tomcat";
+
+ public static final String ORION = "Orion";
+
+ public static final String RESIN = "Resin";
+
+ public static final String REX_IP = "TradeCity";
+
+ public static final String OC4J = "Oracle";
+
+ public static final String JRUN = "JRun";
+
+ public static final String JETTY = "Jetty";
+
+ public static final String WEBSPHERE = "Websphere";
+
+ public static final String WEBLOGIC = "WebLogic";
+
+ public static final String GLASSFISH = "Sun Java System Application Server";
+
+ /**
+ *
+ */
+ protected static Boolean useOutputStreamValue = null;
+
+ private static String m_serverInfo;
+
+ /**
+ * Determines the response wrapper for the servlet filters
+ *
+ * @param serverInfo The string returned from context.getServerInfo()
+ * @return <code>true</code> if standard response wrapper does not work
+ * properly; <code>false</code> default, otherwise
+ */
+ public static boolean useOutputStream( String serverInfo )
+ {
+ if( useOutputStreamValue == null )
+ {
+ initCompatibilityOptions( serverInfo );
+ }
+ return useOutputStreamValue.booleanValue();
+ }
+
+ /**
+ * For testing only
+ *
+ * @param serverInfo The string returned from context.getServerInfo()
+ * @param boolInitialize True, if you want to force initialization again
+ * @return <code>true</code> if standard response wrapper does not work
+ * properly; <code>false</code> default, otherwise
+ */
+ public static boolean useOutputStream( String serverInfo, Boolean boolInitialize )
+ {
+ if( (useOutputStreamValue == null) | (boolInitialize) )
+ {
+ initCompatibilityOptions( serverInfo );
+ }
+ return useOutputStreamValue.booleanValue();
+ }
+
+ /**
+ * Simple check of the servlet container
+ *
+ * @param serverInfo The string returned from context.getServerInfo()
+ */
+ protected static void initCompatibilityOptions( String serverInfo )
+ {
+ log.info( "serverInfo: " + serverInfo );
+ m_serverInfo = serverInfo;
+ // response.getWriter is the default
+ boolean useStream = false;
+ if( serverInfo.indexOf( RESIN ) >= 0 )
+ {
+ log.info( RESIN + " detected" );
+ }
+ else if( serverInfo.indexOf( REX_IP ) >= 0 )
+ {
+ log.info( REX_IP + " detected" );
+ }
+ else if( serverInfo.indexOf( TOMCAT ) >= 0 )
+ {
+ log.info( TOMCAT + " detected" );
+ }
+ else if( serverInfo.indexOf( JRUN ) >= 0 )
+ {
+ log.info( JRUN + " detected" );
+ }
+ else if( serverInfo.indexOf( JETTY ) >= 0 )
+ {
+ log.info( JETTY + " detected" );
+ }
+ else if( serverInfo.indexOf( ORION ) >= 0 )
+ {
+ log.info( ORION + " detected" );
+ }
+ else if( serverInfo.indexOf( WEBSPHERE ) >= 0 )
+ {
+ log.info( WEBSPHERE + " detected" );
+ }
+ else if( serverInfo.indexOf( WEBLOGIC ) >= 0 )
+ {
+ log.info( WEBLOGIC + " detected" );
+ }
+ else if( serverInfo.indexOf( GLASSFISH ) >= 0 )
+ {
+ log.info( GLASSFISH + " detected" );
+ }
+ else if( serverInfo.indexOf( OC4J ) >= 0 )
+ {
+ log.info( "Oracle Container for JEE detected" );
+ // use response.getOutputStream instead of response.getWriter
+ useStream = true;
+ }
+ useOutputStreamValue = new Boolean( useStream );
+ }
+
+ /**
+ * @return the Container type that has been detected
+ */
+ public static String getServerInfo()
+ {
+ return m_serverInfo;
+ }
+
+}
Added: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/UtilJ2eeCompatTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/UtilJ2eeCompatTest.java?rev=691749&view=auto
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/UtilJ2eeCompatTest.java (added)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/UtilJ2eeCompatTest.java Wed Sep 3 12:45:34 2008
@@ -0,0 +1,53 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package com.ecyrd.jspwiki.util;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import com.ecyrd.jspwiki.util.UtilJ2eeCompat;
+
+public class UtilJ2eeCompatTest extends TestCase
+{
+
+ public void testOracle()
+ {
+ assertTrue( UtilJ2eeCompat.useOutputStream( "Oracle Containers for J2EE 10g(10.1.3.1.0 )", true ) );
+ // Do not reinitialize
+ assertTrue( UtilJ2eeCompat.useOutputStream( "Apache Tomcat/5.5.20" ) );
+ }
+
+ public void testGlassfish()
+ {
+ assertTrue( UtilJ2eeCompat.useOutputStream( "Sun Java System Application Server 9.1_02" ) );
+ }
+
+ public void testTomcat()
+ {
+ // Reinitialize
+ assertFalse( UtilJ2eeCompat.useOutputStream( "Apache Tomcat/5.5.20", true ) );
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite( UtilJ2eeCompatTest.class );
+ }
+}