use of com.webobjects.appserver.WOContext in project wonder-slim by undur.
the class ERXAjaxSession method _saveCurrentPage.
/**
* Semi-private method that saves the current page. Overridden to put the page in the
* permanent page cache if it's already in there.
*/
@Override
public void _saveCurrentPage() {
if (overridePrivateCache) {
WOContext _currentContext = context();
if (_currentContext != null) {
String contextID = context().contextID();
log.debug("Saving page for contextID: {}", contextID);
WOComponent currentPage = _currentContext._pageComponent();
if (currentPage != null && currentPage._isPage()) {
WOComponent permanentSenderPage = _permanentPageWithContextID(_currentContext._requestContextID());
WOComponent permanentCurrentPage = _permanentPageWithContextID(contextID);
if (permanentCurrentPage == null && _permanentPageCache().containsValue(currentPage)) {
// AK: note that we put it directly in the cache, not bothering with
// savePageInPermanentCache() as this one would clear out the old IDs
_permanentPageCache.setObjectForKey(currentPage, contextID);
} else if (permanentCurrentPage != currentPage) {
WOApplication woapplication = WOApplication.application();
if (permanentSenderPage == currentPage && woapplication.permanentPageCacheSize() != 0) {
if (_shouldPutInPermanentCache(currentPage))
savePageInPermanentCache(currentPage);
} else if (woapplication.pageCacheSize() != 0)
savePage(currentPage);
}
}
}
} else {
super._saveCurrentPage();
}
}
use of com.webobjects.appserver.WOContext in project wonder-slim by undur.
the class ERXApplication method handleActionRequestError.
/**
* 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.
*/
// NOTE: if you use WO 5.1, comment out this method, otherwise it won't compile.
// CHECKME this was created for WO 5.2, do we still need this for 5.4.3?
@Override
public WOResponse handleActionRequestError(WORequest aRequest, Exception exception, String reason, WORequestHandler aHandler, String actionClassName, String actionName, Class actionClass, WOAction actionInstance) {
WOContext context = actionInstance != null ? actionInstance.context() : null;
boolean didCreateContext = false;
if (context == null) {
// AK: we provide the "handleException" with not much enough info to output a reasonable error message
context = createContextForRequest(aRequest);
didCreateContext = true;
}
final WOResponse response = handleException(exception, context);
// a prime suspect. I am leaving the code below in so that if it does something for prior versions, that will still work.
if (didCreateContext) {
context._putAwakeComponentsToSleep();
saveSessionForContext(context);
} else // does not check sessions back in which leads to a deadlock in the session store when the session is accessed again.
if (context.hasSession() && ("InstantiationError".equals(reason) || "InvocationError".equals(reason))) {
context._putAwakeComponentsToSleep();
saveSessionForContext(context);
}
return response;
}
use of com.webobjects.appserver.WOContext in project wonder-slim by undur.
the class ERXComponentRequestHandler method _handleRequest.
WOResponse _handleRequest(WORequest aRequest) {
WOContext aContext = null;
WOResponse aResponse;
NSDictionary requestHandlerValues = requestHandlerValuesForRequest(aRequest);
WOApplication anApplication = WOApplication.application();
String aSessionID = (String) requestHandlerValues.objectForKey(WOApplication.application().sessionIdKey());
if ((!anApplication.isRefusingNewSessions()) || (aSessionID != null)) {
String aSenderID = (String) requestHandlerValues.objectForKey("woeid");
String oldContextID = (String) requestHandlerValues.objectForKey("wocid");
WOStatisticsStore aStatisticsStore = anApplication.statisticsStore();
if (aStatisticsStore != null)
aStatisticsStore.applicationWillHandleComponentActionRequest();
try {
aContext = anApplication.createContextForRequest(aRequest);
aContext._setRequestContextID(oldContextID);
aContext._setSenderID(aSenderID);
anApplication.awake();
aResponse = _dispatchWithPreparedApplication(anApplication, aContext, requestHandlerValues);
NSNotificationCenter.defaultCenter().postNotification(WORequestHandler.DidHandleRequestNotification, aContext);
anApplication.sleep();
} catch (Exception exception) {
try {
NSLog.err.appendln("<" + getClass().getName() + ">: Exception occurred while handling request:\n" + exception.toString());
if (NSLog.debugLoggingAllowedForLevelAndGroups(1, 4L)) {
NSLog.debug.appendln(exception);
}
if (aContext == null)
aContext = anApplication.createContextForRequest(aRequest);
else {
aContext._putAwakeComponentsToSleep();
}
WOSession aSession = aContext._session();
aResponse = anApplication.handleException(exception, aContext);
if (aSession != null) {
try {
anApplication.saveSessionForContext(aContext);
anApplication.sleep();
} catch (Exception eAgain) {
NSLog.err.appendln("<WOApplication '" + anApplication.name() + "'>: Another Exception occurred while trying to clean the application:\n" + eAgain.toString());
if (NSLog.debugLoggingAllowedForLevelAndGroups(1, 4L))
NSLog.debug.appendln(eAgain);
}
}
} finally {
if ((aContext != null) && (aContext._session() != null))
anApplication.saveSessionForContext(aContext);
}
}
if (aResponse != null) {
aResponse._finalizeInContext(aContext);
}
if (aStatisticsStore != null) {
WOComponent aPage = aContext.page();
String aName = null;
if (aPage != null) {
aName = aPage.name();
}
aStatisticsStore.applicationDidHandleComponentActionRequestWithPageNamed(aName);
}
} else {
String newLocationURL = anApplication._newLocationForRequest(aRequest);
String contentString = "Sorry, your request could not immediately be processed. Please try this URL: <a href=\"" + newLocationURL + "\">" + newLocationURL + "</a>";
aResponse = anApplication.createResponseInContext(null);
WOResponse._redirectResponse(aResponse, newLocationURL, contentString);
aResponse._finalizeInContext(null);
}
return aResponse;
}
use of com.webobjects.appserver.WOContext in project wonder-slim by undur.
the class ERXWORepetition method invokeAction.
@Override
public WOActionResults invokeAction(WORequest worequest, WOContext wocontext) {
WOComponent wocomponent = wocontext.component();
Context repetitionContext = createContext(wocomponent);
int count = _count(repetitionContext, wocomponent);
WOActionResults woactionresults = null;
String indexString = _indexOfChosenItem(worequest, wocontext);
int index = 0;
boolean checkHashCodes = checkHashCodes(wocomponent);
if (indexString != null && !checkHashCodes) {
index = Integer.parseInt(indexString);
}
if (indexString != null) {
if (_item != null) {
Object object = null;
if (checkHashCodes) {
boolean found = false;
if (_uniqueKey == null) {
int hashCode = Integer.parseInt(indexString);
int otherHashCode = 0;
for (int i = 0; i < repetitionContext.count() && !found; i++) {
Object o = repetitionContext.objectAtIndex(i);
otherHashCode = hashCodeForObject(wocomponent, o);
if (otherHashCode == hashCode) {
object = o;
index = i;
found = true;
}
}
if (found) {
log.debug("Found object: {} vs {}", otherHashCode, hashCode);
} else {
log.warn("Wrong object: {} vs {} (array = {})", otherHashCode, hashCode, repetitionContext.nsarray);
}
} else {
String key = indexString;
String otherKey = null;
for (int i = 0; i < repetitionContext.count() && !found; i++) {
Object o = repetitionContext.objectAtIndex(i);
otherKey = keyForObject(wocomponent, o);
if (otherKey.equals(key)) {
object = o;
index = i;
found = true;
}
}
if (found) {
log.debug("Found object: {} vs {}", otherKey, key);
} else {
log.warn("Wrong object: {} vs {} (array = {})", otherKey, key, repetitionContext.nsarray);
}
}
if (!found) {
if (raiseOnUnmatchedObject(wocomponent)) {
throw new UnmatchedObjectException();
}
if (_notFoundMarker == null) {
return wocontext.page();
}
object = _notFoundMarker.valueInComponent(wocomponent);
}
} else {
if (index >= repetitionContext.count()) {
if (raiseOnUnmatchedObject(wocomponent)) {
throw new UnmatchedObjectException();
}
return wocontext.page();
}
object = repetitionContext.objectAtIndex(index);
}
_item._setValueNoValidation(object, wocomponent);
}
if (_index != null) {
_index._setValueNoValidation(index, wocomponent);
}
wocontext.appendElementIDComponent(indexString);
log.debug("invokeAction: {}", wocontext.elementID());
woactionresults = super.invokeAction(worequest, wocontext);
wocontext.deleteLastElementIDComponent();
} else {
for (int i = 0; i < count && woactionresults == null; i++) {
_prepareForIterationWithIndex(repetitionContext, i, wocontext, wocomponent, checkHashCodes);
woactionresults = super.invokeAction(worequest, wocontext);
}
if (count > 0) {
_cleanupAfterIteration(count, wocontext, wocomponent);
}
}
return woactionresults;
}
use of com.webobjects.appserver.WOContext in project wonder-slim by undur.
the class ERXLocalizer method currentLocalizer.
/**
* Returns the current localizer for the current thread. Note that the localizer for a given session is pushed onto
* the thread when a session awakes and is nulled out when a session sleeps. In case there is no localizer set, it tries to
* pull it from the current WOContext or the default language.
*
* @return the current localizer that has been pushed into thread storage.
*/
public static ERXLocalizer currentLocalizer() {
ERXLocalizer current = (ERXLocalizer) ERXThreadStorage.valueForKey("localizer");
if (current == null) {
if (!isInitialized) {
initialize();
}
WOContext context = ERXWOContext.currentContext();
// set the current localizer
if (context != null && context.request() != null && context.request().browserLanguages() != null) {
current = ERXLocalizer.localizerForLanguages(context.request().browserLanguages());
ERXLocalizer.setCurrentLocalizer(current);
} else {
current = defaultLocalizer();
}
}
return current;
}
Aggregations