Please submit a patch for the bugfix only. It is difficult to assess a
patch that contains a lot of formatting changes as well.
Thank you.
----- Original Message -----
From: Mike Haberman <[EMAIL PROTECTED]>
To: Turbine <[EMAIL PROTECTED]>
Sent: Wednesday, September 06, 2000 8:00 AM
Subject: reallyScrewedNow patch
> So I was able to get in a state where the code
> in Turbine.java:reallyScrewedNow is run. The problem is
> how it handles the exception. If the exception is thrown
> and data is still null, then you get another exception (NullPointer)
> which masks the exception that you really care about.
>
> I don't have cvs rights (hopefully someday). So I am including
> the patch. Also, I took the liberty of factoring out some repeated
> code and cleaned up the comments to be consistent. One of my
> two coding pet peeves is code that spills over 80 columns. So I also
> fixed that. I hoped this dosen't step on anyone's toes.
> Here's the diff:
>
>
> --- Turbine.java Tue Sep 5 17:06:30 2000
> +++ /tmp/Turbine.java Tue Sep 5 17:33:53 2000
> @@ -143,9 +143,11 @@
> props = realPath;
> }
>
> - // Check for errors in locating the props file. if there is
> - // one this method will throw an exception and you should look
> - // in your log file for more information.
> + /*
> + * Check for errors in locating the props file. if there is
> + * one this method will throw an exception and you should look
> + * in your log file for more information.
> + */
> propertyFileErrorCheck(props);
>
> // Setup some defaults from the properties file.
> @@ -167,10 +169,10 @@
> firstDoGet = true;
>
> // START SCHEDULER HERE
> - if ( TurbineResources
> - .getBoolean("scheduler.enabled", false) )
> + if (TurbineResources.getBoolean("scheduler.enabled", false))
> {
> -
TurbineServices.getInstance().getService(ScheduleService.SERVICE_NAME);
> + TurbineServices.getInstance().getService(
> + ScheduleService.SERVICE_NAME);
> }
>
> log ("Turbine init()!");
> @@ -208,7 +210,7 @@
>
> // Get general RunData here...
> // Perform turbine specific initialization below.
> - data = RunDataFactory.getRunData( req, res,
getServletConfig() );
> + data = RunDataFactory.getRunData(req, res,
getServletConfig());
>
> // If this is the first invocation, perform some
> // intialization.
> @@ -229,30 +231,37 @@
> }
>
> // Get the instance of the Session Validator.
> - SessionValidator sessionValidator =
(SessionValidator)ActionLoader.getInstance().getInstance(
> - TurbineResources.getString("action.sessionvalidator") );
> -
> - // Insist that the client starts a session before access
> - // to data is allowed. this is done by redirecting them to
> - // the "screen.homepage" page but you could have them go
> - // to any page as a starter (ie: the homepage)
> - // "data.getResponse()" represents the HTTP servlet
> - // response.
> + SessionValidator sessionValidator;
> + sessionValidator =
> + (SessionValidator)ActionLoader.getInstance().getInstance(
> +
TurbineResources.getString("action.sessionvalidator"));
> +
> + /*
> + * Insist that the client starts a session before access
> + * to data is allowed. this is done by redirecting them to
> + * the "screen.homepage" page but you could have them go
> + * to any page as a starter (ie: the homepage)
> + * "data.getResponse()" represents the HTTP servlet
> + * response.
> + */
> if ( sessionValidator.requiresNewSession(data) &&
> data.getSession().isNew() )
> {
> DynamicURI duri = new DynamicURI (data, true);
> - String homepage =
TurbineResources.getString("screen.homepage", null);
> + String homepage;
> + homepage = TurbineResources.getString("screen.homepage",
null);
> if (homepage != null)
> {
> duri.setScreen(homepage);
> }
> // Pass on the sent data in pathinfo.
> - for (Enumeration e = data.getParameters().keys() ;
e.hasMoreElements() ;)
> + Enumeration e;
> + for (e = data.getParameters().keys();
e.hasMoreElements(); )
> {
> - String key = (String) e.nextElement();
> - String value = (String)
data.getParameters().getString ( key );
> - duri.addPathInfo((String)key, (String)value );
> + String key, value;
> + key = (String) e.nextElement();
> + value = (String) data.getParameters().getString
( key );
> + duri.addPathInfo(key, value );
> }
>
> /*
> @@ -287,21 +296,23 @@
> // Special case for login, this must happen before the
> // SessionManager is executed in order to allow a user to
> // even login.
> - if ( data.hasAction() &&
> + if (data.hasAction() &&
> data.getAction().equalsIgnoreCase(TurbineResources
> -
.getString("action.login")) )
> +
.getString("action.login")))
> {
> - // If a User is logging in, we should refresh the
> - // session here. Invalidating session and starting a
> - // new session would seem to be a good method, but I
> - // (JDM) could not get this to work well (it always
> - // required the user to login twice). Maybe related
> - // to JServ? If we do not clear out the session, it
> - // is possible a new User may accidently (if they
> - // login incorrectly) continue on with information
> - // associated with the previous User. Currently the
> - // only keys stored in the session are "turbine.user"
> - // and "turbine.acl".
> + /*
> + * If a User is logging in, we should refresh the
> + * session here. Invalidating session and starting a
> + * new session would seem to be a good method, but I
> + * (JDM) could not get this to work well (it always
> + * required the user to login twice). Maybe related
> + * to JServ? If we do not clear out the session, it
> + * is possible a new User may accidently (if they
> + * login incorrectly) continue on with information
> + * associated with the previous User. Currently the
> + * only keys stored in the session are "turbine.user"
> + * and "turbine.acl".
> + */
> String[] names = data.getSession().getValueNames();
> if (names != null)
> {
> @@ -313,39 +324,46 @@
> ActionLoader.getInstance().exec ( data,
data.getAction() );
> }
>
> - // This is where the validation of the Session information
> - // is performed if the user has not logged in yet, then
> - // the screen is set to be Login. This also handles the
> - // case of not having a screen defined by also setting the
> - // screen to Login. If you want people to go to another
> - // screen other than Login, you need to change that within
> - // TurbineResources.properties...screen.homepage; or, you
> - // can specify your own SessionValidator action.
> - ActionLoader.getInstance()
> - .exec( data,
TurbineResources.getString("action.sessionvalidator") );
> -
> - // Put the Access Control List into the RunData object, so
> - // it is easily available to modules. It is also placed
> - // into the session for serialization. Modules can null
> - // out the ACL to force it to be rebuilt based on more
> - // information.
> - ActionLoader.getInstance()
> -
.exec(data,TurbineResources.getString("action.accesscontroller"));
> -
> - // Start the execution phase. DefaultPage will execute the
> - // appropriate action as well as get the Layout from the
> - // Screen and then execute that. The Layout is then
> - // responsible for executing the Navigation and Screen
> - // modules.
> - //
> - // Note that by default, this cannot be overridden from
> - // parameters passed in via post/query data. This is for
> - // security purposes. You should really never need more
> - // than just the default page. If you do, add logic to
> - // DefaultPage to do what you want.
> - PageLoader.getInstance()
> - .exec(data,TurbineResources.getString("page.default"));
> -
> + /*
> + * This is where the validation of the Session information
> + * is performed if the user has not logged in yet, then
> + * the screen is set to be Login. This also handles the
> + * case of not having a screen defined by also setting the
> + * screen to Login. If you want people to go to another
> + * screen other than Login, you need to change that within
> + * TurbineResources.properties...screen.homepage; or, you
> + * can specify your own SessionValidator action.
> + */
> + String action;
> + action =
TurbineResources.getString("action.sessionvalidator");
> + ActionLoader.getInstance().exec(data, action);
> +
> + /*
> + * Put the Access Control List into the RunData object, so
> + * it is easily available to modules. It is also placed
> + * into the session for serialization. Modules can null
> + * out the ACL to force it to be rebuilt based on more
> + * information.
> + */
> + action =
TurbineResources.getString("action.accesscontroller");
> + ActionLoader.getInstance().exec(data,action);
> +
> + /*
> + * Start the execution phase. DefaultPage will execute the
> + * appropriate action as well as get the Layout from the
> + * Screen and then execute that. The Layout is then
> + * responsible for executing the Navigation and Screen
> + * modules.
> + *
> + * Note that by default, this cannot be overridden from
> + * parameters passed in via post/query data. This is for
> + * security purposes. You should really never need more
> + * than just the default page. If you do, add logic to
> + * DefaultPage to do what you want.
> + */
> + Strong page = TurbineResources.getString("page.default");
> + PageLoader.getInstance().exec(data, page);
> +
> // If a module has set data.acl = null, remove acl from
> // the session.
> if ( data.acl == null )
> @@ -355,24 +373,29 @@
>
> try
> {
> - if ( data.isPageSet() == false && data.isOutSet() ==
false )
> + if (data.isPageSet() == false && data.isOutSet() ==
false )
> + {
> throw new Exception ( "Nothing to output" );
> + }
>
> - // We are all done! if isPageSet() output that way
> - // otherwise, data.getOut() has already been written
> - // to the data.getOut().close() happens below in the
> - // finally.
> - if ( data.isPageSet() && data.isOutSet() == false )
> + /*
> + * We are all done! if isPageSet() output that way
> + * otherwise, data.getOut() has already been written
> + * to the data.getOut().close() happens below in the
> + * finally.
> + */
> + if (data.isPageSet() && data.isOutSet() == false)
> {
> // Modules can override this.
> -
ata.getResponse().setContentType( data.getContentType() );
> +
data.getResponse().setContentType(data.getContentType());
>
> // Handle the case where a module may want to send
> // a redirect.
> - if ( ( data.getStatusCode() == 301 ||
data.getStatusCode() == 302 )
> - && data.getRedirectURI() != null )
> + if ( (data.getStatusCode() == 301 ||
> + data.getStatusCode() == 302) &&
> + data.getRedirectURI() != null)
> {
> - data.getResponse().sendRedirect
data.getRedirectURI() );
> +
data.getResponse().sendRedirect(data.getRedirectURI());
> }
>
> // Set the status code.
> @@ -383,10 +406,11 @@
> }
> catch ( Exception e )
> {
> - // The output stream was probably closed by the client
> - // end of things ie: the client clicked the Stop
> - // button on the browser, so ignore any errors that
> - // result.
> + /*
> + * The output stream was probably closed by the client
> + * end of things ie: the client clicked the Stop
> + * button on the browser, so ignore any errors that
result.
> + */
> }
> }
> catch ( Exception e )
> @@ -449,52 +473,47 @@
> public void propertyFileErrorCheck(String props)
> throws ServletException
> {
> - try
> + String error = null;
> + Object params[] = null;
> +
> + if (props == null)
> {
> - ErrorResources.init();
> - if ( props == null)
> - {
> - Object params[] = {(Object) INIT_PROPS_KEY};
> - initFailureMessage = ErrorResources.getMessage(
> -
ErrorResources.PROPERTIES_INIT_PARAMETER_NOT_FOUND, params);
> - log(initFailureMessage);
> - Log.error (initFailureMessage);
> - throw new Exception(initFailureMessage);
> - }
> - else if(props.length() == 0)
> - {
> - Object params[] = {(Object) INIT_PROPS_KEY};
> - initFailureMessage = ErrorResources.getMessage(
> -
ErrorResources.PROPERTIES_INIT_PARAMETER_ZERO_LENGTH_STRING,
> - params);
> - log(initFailureMessage);
> - Log.error (initFailureMessage);
> - throw new Exception(initFailureMessage);
> - }
> - else if(!(new File(props).exists()))
> + params = new Object[]{(Object) INIT_PROPS_KEY};
> + error = ErrorResources.PROPERTIES_INIT_PARAMETER_NOT_FOUND;
> + }
> + else if(props.length() == 0)
> + {
> + params = new Object[]{(Object) INIT_PROPS_KEY};
> + error =
> +
ErrorResources.PROPERTIES_INIT_PARAMETER_ZERO_LENGTH_STRING;
> + }
> + else if(!(new File(props).exists()))
> + {
> + params = new Object[]{(Object) props, (Object)
INIT_PROPS_KEY};
> + error = ErrorResources.TURBINE_RESOURCE_FILE_DOES_NOT_EXIST;
> + }
> + else if(!(new File(props).canRead()))
> + {
> + params = new Object[]{(Object) props,
> + (Object)
System.getProperty("user.name")};
> + error = ErrorResources.TURBINE_RESOURCE_FILE_NOT_READABLE;
> + }
> +
> + if (error != null)
> + {
> + try
> {
> - Object params[] = {(Object) props, (Object)
INIT_PROPS_KEY};
> - initFailureMessage = ErrorResources.getMessage(
> -
ErrorResources.TURBINE_RESOURCE_FILE_DOES_NOT_EXIST, params);
> + ErrorResources.init();
> + initFailureMessage =
ErrorResources.getMessage(error,params);
> log(initFailureMessage);
> Log.error (initFailureMessage);
> throw new Exception(initFailureMessage);
> }
> - else if(!(new File(props).canRead()))
> + catch ( Exception e )
> {
> - Object params[] = {(Object) props, (Object)
> - System.getProperty("user.name")};
> - initFailureMessage = ErrorResources.getMessage(
> - ErrorResources.TURBINE_RESOURCE_FILE_NOT_READABLE,
params);
> - log(initFailureMessage);
> - Log.error (initFailureMessage);
> - throw new Exception(initFailureMessage);
> + throw new ServletException (e.toString());
> }
> }
> - catch ( Exception e )
> - {
> - throw new ServletException ( e.toString() );
> - }
> }
>
> /**
> @@ -522,21 +541,19 @@
> data.stackTrace = StringUtils.stackTrace(e);
> data.stackTraceException = e;
>
> - // setup the screen
> data.setScreen(TurbineResources
> .getString("screen.error"));
>
> // do more screen setup for template execution if needed
> if (data.getTemplateInfo() != null)
> data.getTemplateInfo().setScreenTemplate(TurbineResources
> - .getString("screen.error"));
> + .getString("screen.error"));
>
> // Make sure to not execute an action.
> data.setAction ("");
>
> PageLoader.getInstance()
> - .exec(data, TurbineResources
> - .getString("page.default"));
> + .exec(data, TurbineResources.getString("page.default"));
>
> data.getResponse().setContentType( data.getContentType() );
> data.getResponse().setStatus ( data.getStatusCode() );
> @@ -558,22 +575,38 @@
> }
> try
> {
> - data.getOut().print ("java.lang.NoSuchFieldError: Please
recompile all of your source code.");
> + String msg;
> + msg = "java.lang.NoSuchFieldError: " +
> + "Please recompile all of your source code.";
> +
> + data.getOut().print(msg);
> }
> catch (IOException io)
> {
> + // ignore
> }
> log ( data.stackTrace );
> org.apache.turbine.util.Log.error ( foo );
> }
> +
> // Attempt to do *something* at this point...
> catch ( Exception reallyScrewedNow )
> {
> try
> {
> + String msg;
> + if (data != null)
> + {
> + msg = "Exception: " + data.stackTrace;
> + }
> + else
> + {
> + msg = "Exception: " + e;
> + }
> +
> res.setContentType( mimeType );
> res.setStatus ( 200 );
> - res.getWriter().print ("Exception: " + data.stackTrace);
> + res.getWriter().print (msg);
> }
> catch (Exception foob)
> {
>
>
> ------------------------------------------------------------
> To subscribe: [EMAIL PROTECTED]
> To unsubscribe: [EMAIL PROTECTED]
> Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
> Problems?: [EMAIL PROTECTED]
>
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?: [EMAIL PROTECTED]