Project Wonder 2.0

er.extensions
Class ERXApplication

java.lang.Object
  extended bycom.webobjects.appserver.WOApplication
      extended byer.extensions.ERXApplication
All Implemented Interfaces:
ERXGracefulShutdown.GracefulApplication, NSKeyValueCoding, NSKeyValueCoding.ErrorHandling, NSKeyValueCodingAdditions

public abstract class ERXApplication
extends WOApplication
implements ERXGracefulShutdown.GracefulApplication

ERXApplication is the abstract superclass of WebObjects applications built with the ER frameworks.

Useful enhancements include the ability to change the deployed name of the application, support for automatic application restarting at given intervals and more context information when handling exceptions.


Nested Class Summary
 
Nested classes inherited from class com.webobjects.appserver.WOApplication
WOApplication._EventLoggingEnabler, WOApplication.Event
 
Nested classes inherited from class com.webobjects.foundation.NSKeyValueCoding
NSKeyValueCoding._BooleanFieldBinding, NSKeyValueCoding._BooleanMethodBinding, NSKeyValueCoding._FieldBinding, NSKeyValueCoding._ForwardingBinding, NSKeyValueCoding._KeyBinding, NSKeyValueCoding._KeyBindingCreation, NSKeyValueCoding._MethodBinding, NSKeyValueCoding._NumberFieldBinding, NSKeyValueCoding._NumberMethodBinding, NSKeyValueCoding._ReflectionKeyBindingCreation, NSKeyValueCoding.DefaultImplementation, NSKeyValueCoding.ErrorHandling, NSKeyValueCoding.Null, NSKeyValueCoding.UnknownKeyException, NSKeyValueCoding.Utility, NSKeyValueCoding.ValueAccessor
 
Nested classes inherited from class com.webobjects.foundation.NSKeyValueCodingAdditions
NSKeyValueCodingAdditions.DefaultImplementation, NSKeyValueCodingAdditions.Utility
 
Field Summary
protected  WOTimer _killTimer
           
 short _responseCompressionEnabled
           
 NSMutableArray _streamingRequestHandlerKeys
          improved streaming support
protected  Boolean _useSessionStoreDeadlockDetection
          use the redirect feature
protected  EOModelGroup defaultModelGroup
          holds the default model group
static ERXLogger log
          logging support
static ERXLogger requestHandlingLog
          request logging support
protected  Boolean useComponentActionRedirection
          use the redirect feature
 
Fields inherited from class com.webobjects.appserver.WOApplication
_adminRequestHandlerKey, _TheLastApplicationAccessTime, _unsetHost, _wasMainInvoked, ApplicationDidDispatchRequestNotification, ApplicationDidFinishLaunchingNotification, ApplicationWillDispatchRequestNotification, ApplicationWillFinishLaunchingNotification
 
Fields inherited from interface com.webobjects.foundation.NSKeyValueCoding
_CLASS, NullValue
 
Fields inherited from interface com.webobjects.foundation.NSKeyValueCoding.ErrorHandling
_CLASS
 
Fields inherited from interface com.webobjects.foundation.NSKeyValueCodingAdditions
_CLASS, _KeyPathSeparatorChar, KeyPathSeparator
 
Constructor Summary
ERXApplication()
          The ERXApplication contructor.
 
Method Summary
 void appendToResponse(WOResponse response, WOContext context)
          Overridden to allow for redirected responses.
 void configureStatisticsLogging()
          Configures the statistics logging for a given application.
 WOContext createContextForRequest(WORequest request)
          When a context is created we push it into thread local storage.
 WORequest createRequest(String aMethod, String aURL, String anHTTPVersion, NSDictionary someHeaders, NSData aContent, NSDictionary someInfo)
          Creates the request object for this loop.
 WOSession createSessionForRequest(WORequest worequest)
          Overridden to check the sessions
 EOModelGroup defaultModelGroup()
          Delegate method for the EOModelGroup class delegate.
 void didFinishLaunching()
          Called when the application posts WOApplication.ApplicationDidFinishLaunchingNotification.
 void didFinishLaunching(NSNotification n)
          Notification method called when the application posts the notification WOApplication.ApplicationDidFinishLaunchingNotification.
 WOResponse dispatchRequest(WORequest request)
          Overridden to allow for redirected responses and null the thread local storage.
static ERXApplication erxApplication()
          The ERXApplication singleton.
 NSMutableDictionary extraInformationForExceptionInContext(Exception e, WOContext context)
          Puts together a dictionary with a bunch of useful information relative to the current state when the exception occurred.
 void finishInitialization()
          Called when the application posts WOApplication.ApplicationWillFinishLaunchingNotification.
 void finishInitialization(NSNotification n)
          Notification method called when the application posts the notification WOApplication.ApplicationWillFinishLaunchingNotification.
 ERXFormatterFactory formatterFactory()
           
 WOResponse genericHandleException(Exception exception, WOContext context)
          Standard exception page.
 void gracefulTerminate()
          Override to perform any last minute cleanup before the application terminates.
 WOResponse handleActionRequestError(WORequest aRequest, Exception exception, String reason, WORequestHandler aHandler, String actionClassName, String actionName, Class actionClass, WOAction actionInstance)
          Workaround for WO 5.2 DirectAction lock-ups.
 WOResponse handleException(Exception exception, WOContext context)
          Logs extra information about the current state.
 void handlePotentiallyFatalException(Exception exception)
          Handles the potentially fatal OutOfMemoryError by quiting the application ASAP.
 void installPatches()
          Installs several bufixes and enhancements to WODynamicElements.
static WOComponent instantiatePage(String pageName)
          Used to instanciate a WOComponent when no context is available, typically ouside of a session
 WOActionResults invokeAction(WORequest request, WOContext context)
          Overridden to allow for redirected responses.
 boolean isStreamingRequestHandlerKey(String s)
           
 void killInstance()
          Killing the instance will log a 'Forcing exit' message and then call System.exit(1)
static void main(String[] argv, Class applicationClass)
          Called when the application starts up and saves the command line arguments for ERXConfigurationManager.
 String name()
          Adds the ability to completely change the applications name by setting the System property ERApplicationName.
 String nameSuffix()
          The name suffix is appended to the current name of the application.
 String rawName()
          This method returns WOApplication's name method.
 void refuseNewSessions(boolean value)
          Overridden to install/uninstall a timer that will terminate the application in ERTimeToKill seconds from the time this method is called.
 void registerStreamingRequestHandlerKey(String s)
           
 WOResponse reportException(Throwable exception, NSDictionary extraInfo)
          Reports an exception.
 boolean responseCompressionEnabled()
           
 WOSession restoreSessionWithID(String sessionID, WOContext wocontext)
          Overridden to check the sessions
 void run()
          Adds support for automatic application cycling.
 void saveSessionForContext(WOContext wocontext)
          Overridden to check the sessions
 Number sessionTimeOutInMinutes()
           
 void startRefusingSessions()
          Stops the application from handling any new requests.
 boolean useComponentActionRedirection()
          Set the er.extensions.ERXComponentActionRedirector.enabled=true property to actually the redirect feature.
 boolean useEditingContextUnlocker()
          Decides whether to use editing context unlocking.
 boolean useSessionStoreDeadlockDetection()
          Deadlock in session-store detection.
 
Methods inherited from class com.webobjects.appserver.WOApplication
_addToExpectedLanguages, _allowsCacheControlHeader, _checksForSpecialHeaders, _componentDefinition, _componentDefinitionFromClassNamed, _debugString, _discountTerminatedSession, _expectedLanguages, _finishInitializingSession, _initializeSessionInContext, _isDebuggingEnabled, _isDomesticSupportedDevelopmentPlatform, _isForeignSupportedDevelopmentPlatform, _isPageRecreationEnabled, _isSupportedDevelopmentPlatform, _lockDefaultEditingContext, _newLocationForRequest, _openInitialURL, _quitTimer, _rapidTurnaroundActiveForAnyProject, _removeComponentDefinitionCacheContents, _runLoop, _sessionClass, _setAllowsCacheControlHeader, _setChecksForSpecialHeaders, _setHost, _setHostAddress, _setLifebeatDestinationPort, _setLockDefaultEditingContext, _terminateFromMonitor, _terminateOrResetTimer, activeSessionsCount, adaptor, adaptors, adaptorsDispatchRequestsConcurrently, adaptorWithName, additionalAdaptors, allowsConcurrentRequestHandling, application, applicationBaseURL, autoOpenClientApplication, autoOpenInBrowser, awake, baseURL, canAccessFieldsDirectly, cgiAdaptorURL, componentRequestHandlerKey, contextClassName, createResourceManager, createResponseInContext, debugString, defaultRequestHandler, defaultRequestHandlerClassName, defaultUndoStackLimit, directActionRequestHandlerKey, directConnectURL, dynamicElementWithName, frameworksBaseURL, handleMalformedCookieString, handlePageRestorationErrorInContext, handleQueryWithUnboundKey, handlerForRequest, handleSessionCreationErrorInContext, handleSessionRestorationErrorInContext, handleTakeValueForUnboundKey, host, hostAddress, includeCommentsInResponses, isCachingEnabled, isConcurrentRequestHandlingEnabled, isDebuggingEnabled, isDirectConnectEnabled, isMonitorEnabled, isPageRefreshOnBacktrackEnabled, isRefusingNewSessions, isTerminating, licensedRequestLimit, licensedRequestWindow, licensingAllowsMultipleInstances, licensingAllowsMultipleThreads, lifebeatDestinationPort, lifebeatEnabled, lifebeatInterval, listenQueueSize, loadFrameworks, lock, logSetValueForDeclarationNamed, logString, logTakeValueForDeclarationNamed, main, maxSocketIdleTime, minimumActiveSessionsCount, monitorEnabled, monitorHost, monitoringEnabled, number, outputPath, pageCacheSize, pageWithName, path, permanentPageCacheSize, port, primeApplication, primeApplication, printsHTMLParserDiagnostics, projectSearchPath, recordingPath, registeredRequestHandlerKeys, registerRequestHandler, removeRequestHandlerForKey, requestHandlerForKey, requestHandlingLock, resourceManager, resourceRequestHandlerKey, responseForComponentWithName, responseForDirectActionWithNameAndClass, servletConnectURL, sessionStore, sessionStoreClassName, sessionTimeOut, setAdaptor, setAdditionalAdaptors, setAllowsConcurrentRequestHandling, setApplicationBaseURL, setAutoOpenClientApplication, setAutoOpenInBrowser, setCachingEnabled, setCGIAdaptorURL, setComponentRequestHandlerKey, setContextClassName, setDefaultRequestHandler, setDefaultUndoStackLimit, setDirectActionRequestHandlerKey, setDirectConnectEnabled, setFrameworksBaseURL, setIncludeCommentsInResponses, setListenQueueSize, setLoadFrameworks, setMaxSocketIdleTime, setMinimumActiveSessionsCount, setMonitorEnabled, setMonitorHost, setPageCacheSize, setPageRefreshOnBacktrackEnabled, setPermanentPageCacheSize, setPort, setPrintsHTMLParserDiagnostics, setProjectSearchPath, setRecordingPath, setResourceManager, setResourceRequestHandlerKey, setSessionStore, setSessionStoreClassName, setSessionTimeOut, setSMTPHost, setSocketCacheSize, setSocketMonitorSleepTime, setStatisticsStore, setTimeOut, setWebServiceRequestHandlerKey, setWorkerThreadCount, setWorkerThreadCountMax, setWorkerThreadCountMin, sharedEditingContext, shouldRestoreSessionOnCleanEntry, sleep, SMTPHost, socketCacheSize, socketMonitorSleepTime, statistics, statisticsStore, streamActionRequestHandlerKey, takeValueForKey, takeValueForKeyPath, takeValuesFromRequest, terminate, terminateAfterTimeInterval, timeOut, toString, unableToSetNullForKey, unlock, validationFailedWithException, valueForKey, valueForKeyPath, wasMainInvoked, webserverConnectURL, webServiceRequestHandlerKey, workerThreadCount, workerThreadCountMax, workerThreadCountMin
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

public static final ERXLogger log
logging support


requestHandlingLog

public static final ERXLogger requestHandlingLog
request logging support


_streamingRequestHandlerKeys

public NSMutableArray _streamingRequestHandlerKeys
improved streaming support


defaultModelGroup

protected EOModelGroup defaultModelGroup
holds the default model group


_killTimer

protected WOTimer _killTimer

useComponentActionRedirection

protected Boolean useComponentActionRedirection
use the redirect feature


_useSessionStoreDeadlockDetection

protected Boolean _useSessionStoreDeadlockDetection
use the redirect feature


_responseCompressionEnabled

public short _responseCompressionEnabled
Constructor Detail

ERXApplication

public ERXApplication()
The ERXApplication contructor.

Method Detail

main

public static void main(String[] argv,
                        Class applicationClass)
Called when the application starts up and saves the command line arguments for ERXConfigurationManager.

See Also:
WOApplication.main(String[], Class)

installPatches

public void installPatches()
Installs several bufixes and enhancements to WODynamicElements. Sets the Context class name to "er.extensions.ERXWOContext" if it is "WOContext". Patches ERXWOForm, ERXWOFileUpload, ERXWOText to be used instead of WOForm, WOFileUpload, WOText.


defaultModelGroup

public EOModelGroup defaultModelGroup()
Delegate method for the EOModelGroup class delegate.

Returns:
a fixed ERXModelGroup

useEditingContextUnlocker

public boolean useEditingContextUnlocker()
Decides whether to use editing context unlocking.

Returns:
true if ECs should be unlocked after each RR-loop

configureStatisticsLogging

public void configureStatisticsLogging()
Configures the statistics logging for a given application. By default will log to a file /--.log if the base log path is defined. The base log path is defined by the property er.extensions.ERXApplication.StatisticsBaseLogPath The default log rotation frequency is 24 hours, but can be changed by setting in milliseconds the property er.extensions.ERXApplication.StatisticsLogRotationFrequency


finishInitialization

public final void finishInitialization(NSNotification n)
Notification method called when the application posts the notification WOApplication.ApplicationWillFinishLaunchingNotification. This method calls subclasse's finishInitialization(com.webobjects.foundation.NSNotification) method.

Parameters:
n - notification that is posted after the WOApplication has been constructed, but before the application is ready for accepting requests.

didFinishLaunching

public final void didFinishLaunching(NSNotification n)
Notification method called when the application posts the notification WOApplication.ApplicationDidFinishLaunchingNotification. This method calls subclasse's didFinishLaunching(com.webobjects.foundation.NSNotification) method.

Parameters:
n - notification that is posted after the WOApplication has finished launching and is ready for accepting requests.

finishInitialization

public void finishInitialization()
Called when the application posts WOApplication.ApplicationWillFinishLaunchingNotification. Override this to perform application initialization. (optional)


didFinishLaunching

public void didFinishLaunching()
Called when the application posts WOApplication.ApplicationDidFinishLaunchingNotification. Override this to perform application specific tasks after the application has been initialized. THis is a good spot to perform batch application tasks.


erxApplication

public static ERXApplication erxApplication()
The ERXApplication singleton.

Returns:
returns the WOApplication.application() cast as an ERXApplication

run

public void run()
Adds support for automatic application cycling. Applications can be configured to cycle in two ways:

The first way is by setting the System property ERTimeToLive to the number of seconds that the application should be up before terminating. Note that when the application's time to live is up it will quit calling the method killInstance.

The second way is by setting the System property ERTimeToDie to the number of seconds that the application should be up before starting to refuse new sessions. In this case when the application starts to refuse new sessions it will also register a kill timer that will terminate the application between 30 minutes and 1:30 minutes.


createRequest

public WORequest createRequest(String aMethod,
                               String aURL,
                               String anHTTPVersion,
                               NSDictionary someHeaders,
                               NSData aContent,
                               NSDictionary someInfo)
Creates the request object for this loop. Overridden to use an ERXRequest object that fixes a bug with localization.

Parameters:
aMethod - the HTTP method object used to send the request, must be one of "GET", "POST" or "HEAD"
aURL - - must be non-null
anHTTPVersion - - the version of HTTP used
someHeaders - - dictionary whose String keys correspond to header names
aContent - - the HTML content of the receiver
someInfo - - an NSDictionary that can contain any kind of information related to the current response.
Returns:
a new WORequest object

instantiatePage

public static WOComponent instantiatePage(String pageName)
Used to instanciate a WOComponent when no context is available, typically ouside of a session

Parameters:
pageName - - The name of the WOComponent that must be instanciated.
Returns:
created WOComponent with the given name

startRefusingSessions

public void startRefusingSessions()
Stops the application from handling any new requests. Will still handle requests from existing sessions.


refuseNewSessions

public void refuseNewSessions(boolean value)
Overridden to install/uninstall a timer that will terminate the application in ERTimeToKill seconds from the time this method is called. The timer will get uninstalled if you allow new sessions again during that time span.


killInstance

public void killInstance()
Killing the instance will log a 'Forcing exit' message and then call System.exit(1)


nameSuffix

public String nameSuffix()
The name suffix is appended to the current name of the application. This adds the ability to add a useful suffix to differentuate between different sets of applications on the same machine.

The name suffix is set via the System property ERApplicationNameSuffix.

For example if the name of an application is Buyer and you want to have a training instance appear with the name BuyerTraining then you would set the ERApplicationNameSuffix to Training.

Returns:
the System property ERApplicationNameSuffix or null

name

public String name()
Adds the ability to completely change the applications name by setting the System property ERApplicationName. Will also append the nameSuffix if one is set.

Returns:
the computed name of the application.

rawName

public String rawName()
This method returns WOApplication's name method.

Returns:
the name of the application executable.

extraInformationForExceptionInContext

public NSMutableDictionary extraInformationForExceptionInContext(Exception e,
                                                                 WOContext context)
Puts together a dictionary with a bunch of useful information relative to the current state when the exception occurred. Potentially added information:
  1. the current page name
  2. the current component
  3. the complete hierarchy of nested components
  4. the requested uri
  5. the D2W page configuration
  6. the previous page list (from the WOStatisticsStore)

Returns:
dictionary containing extra information for the current context.

reportException

public WOResponse reportException(Throwable exception,
                                  NSDictionary extraInfo)
Reports an exception. This method only logs the error and could be overriden to return a valid error page.

Parameters:
exception - to be reported
extraInfo - dictionary of extra information about what was happening when the exception was thrown.
Returns:
a valid response to display or null. In that case the superclasses handleException(Exception, WOContext) is called

handleActionRequestError

public WOResponse handleActionRequestError(WORequest aRequest,
                                           Exception exception,
                                           String reason,
                                           WORequestHandler aHandler,
                                           String actionClassName,
                                           String actionName,
                                           Class actionClass,
                                           WOAction actionInstance)
Workaround for WO 5.2 DirectAction lock-ups. As the super-implementation is empty, it is fairly safe to override here to call the normal exception handling earlier than usual.

See Also:
WOApplication.handleActionRequestError(WORequest, Exception, String, WORequestHandler, String, String, Class, WOAction)

handleException

public WOResponse handleException(Exception exception,
                                  WOContext context)
Logs extra information about the current state.

Parameters:
exception - to be handled
context - current context
Returns:
the WOResponse of the generated exception page.

genericHandleException

public WOResponse genericHandleException(Exception exception,
                                         WOContext context)
Standard exception page. Also logs error to standard out.

Parameters:
exception - to be handled
context - current context
Returns:
the WOResponse of the generic exception page.

handlePotentiallyFatalException

public void handlePotentiallyFatalException(Exception exception)
Handles the potentially fatal OutOfMemoryError by quiting the application ASAP. Broken out into a separate method to make custom error handling easier, ie generating your own error pages in production, etc.

Parameters:
exception - to check if it is a fatal exception.

useComponentActionRedirection

public boolean useComponentActionRedirection()
Set the er.extensions.ERXComponentActionRedirector.enabled=true property to actually the redirect feature.

Returns:
flag if to use the redirect feature

invokeAction

public WOActionResults invokeAction(WORequest request,
                                    WOContext context)
Overridden to allow for redirected responses.

Parameters:
request - object
context - object

appendToResponse

public void appendToResponse(WOResponse response,
                             WOContext context)
Overridden to allow for redirected responses.

Parameters:
response - object
context - object

dispatchRequest

public WOResponse dispatchRequest(WORequest request)
Overridden to allow for redirected responses and null the thread local storage.

Parameters:
request - object
Returns:
response

createContextForRequest

public WOContext createContextForRequest(WORequest request)
When a context is created we push it into thread local storage. This handles the case for direct actions.

Parameters:
request - the request
Returns:
the newly created context

gracefulTerminate

public void gracefulTerminate()
Override to perform any last minute cleanup before the application terminates. See for where this is called if signal handling is enabled. Default implementation calls terminate.

Specified by:
gracefulTerminate in interface ERXGracefulShutdown.GracefulApplication

registerStreamingRequestHandlerKey

public void registerStreamingRequestHandlerKey(String s)

isStreamingRequestHandlerKey

public boolean isStreamingRequestHandlerKey(String s)

useSessionStoreDeadlockDetection

public boolean useSessionStoreDeadlockDetection()
Deadlock in session-store detection. Note that the detection only work in singlethreaded mode, and is mostly useful to find cases when a session is checked out twice in a single RR-loop, which will lead to a session store lockup. Set the er.extensions.ERXApplication.useSessionStoreDeadlockDetection=true property to actually the this feature.

Returns:
flag if to use the this feature

createSessionForRequest

public WOSession createSessionForRequest(WORequest worequest)
Overridden to check the sessions


saveSessionForContext

public void saveSessionForContext(WOContext wocontext)
Overridden to check the sessions


restoreSessionWithID

public WOSession restoreSessionWithID(String sessionID,
                                      WOContext wocontext)
Overridden to check the sessions


sessionTimeOutInMinutes

public Number sessionTimeOutInMinutes()

formatterFactory

public ERXFormatterFactory formatterFactory()

responseCompressionEnabled

public boolean responseCompressionEnabled()

Last updated: Do, Dez 9, 2004 • 12:46 PM CET

Copyright © 2002 – 2004 Project Wonder.