Skip to content

Instantly share code, notes, and snippets.

@hprange
Created July 6, 2011 23:06
Show Gist options
  • Save hprange/1068553 to your computer and use it in GitHub Desktop.
Save hprange/1068553 to your computer and use it in GitHub Desktop.
ERXServletAdaptor source code
package er.extensions.jspservlet;
import java.lang.reflect.Method;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.UnavailableException;
import com.webobjects.jspservlet.WOServletAdaptor;
import er.extensions.ERXApplication;
/**
* This class is just a wrapper around <code>WOServletAdaptor</code>.
* <code>ERXServletAdaptor</code> must be used to make Wonder applications
* compliant with WAR deployment.
* <p>
* This class is responsible to invoke the
* {@link ERXApplication#setup(String[])} method before the application
* initialization.
*
* @see WOServletAdaptor
* @author <a href="mailto:hprange@gmail.com">Henrique Prange</a>
*/
public class ERXServletAdaptor extends WOServletAdaptor
{
/**
* Invoke the <code>setup</code> method on the specified WOApplicationClass.
*
* @param servletContext The servlet context to get the application class
* @throws UnavailableException If something wrong happens while trying to
* invoke the application setup method.
*/
static void invokeApplicationSetupMethod( final ServletContext servletContext ) throws UnavailableException
{
ClassLoader classLoader = WOServletAdaptor.class.getClassLoader();
try
{
String applicationClassName = servletContext.getInitParameter( "WOApplicationClass" );
if( applicationClassName == null || "".equals( applicationClassName ) )
{
throw new UnavailableException( "WOApplicationClass must be defined. Verify your web.xml configuration." );
}
Class<?> applicationClass = classLoader.loadClass( applicationClassName );
Method method = applicationClass.getMethod( "setup", new Class[] { String[].class } );
method.invoke( null, new Object[] { new String[0] } );
}
catch( Exception exception )
{
exception.printStackTrace();
throw new UnavailableException( "Error initializing ERXServletAdaptor: " + exception.getMessage() );
}
}
public ERXServletAdaptor() throws ServletException
{
super();
}
/**
* Overrides the <code>_appliationInit</code> and invoke the
* {@link ERXApplication#setup(String[])} method before the application
* initialization.
*
* @see WOServletAdaptor#init()
*/
@Override
public void init() throws ServletException
{
invokeApplicationSetupMethod( getServletContext() );
super.init();
// TODO: Check if this is really necessary
ERXApplication.erxApplication().didFinishLaunching();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment