Search in sources :

Example 6 with WOContext

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();
    }
}
Also used : WOComponent(com.webobjects.appserver.WOComponent) WOContext(com.webobjects.appserver.WOContext) WOApplication(com.webobjects.appserver.WOApplication)

Example 7 with WOContext

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;
}
Also used : WOContext(com.webobjects.appserver.WOContext) WOResponse(com.webobjects.appserver.WOResponse)

Example 8 with WOContext

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;
}
Also used : NSDictionary(com.webobjects.foundation.NSDictionary) WOComponent(com.webobjects.appserver.WOComponent) WOContext(com.webobjects.appserver.WOContext) WOSession(com.webobjects.appserver.WOSession) WOStatisticsStore(com.webobjects.appserver.WOStatisticsStore) WOResponse(com.webobjects.appserver.WOResponse) WOApplication(com.webobjects.appserver.WOApplication)

Example 9 with WOContext

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;
}
Also used : WOContext(com.webobjects.appserver.WOContext) ERXWOContext(er.extensions.appserver.ERXWOContext) WOActionResults(com.webobjects.appserver.WOActionResults) WOComponent(com.webobjects.appserver.WOComponent)

Example 10 with WOContext

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;
}
Also used : WOContext(com.webobjects.appserver.WOContext) ERXWOContext(er.extensions.appserver.ERXWOContext)

Aggregations

WOContext (com.webobjects.appserver.WOContext)15 WOComponent (com.webobjects.appserver.WOComponent)8 WOResponse (com.webobjects.appserver.WOResponse)5 ERXWOContext (er.extensions.appserver.ERXWOContext)5 WOApplication (com.webobjects.appserver.WOApplication)4 WOSession (com.webobjects.appserver.WOSession)3 LinkedHashMap (java.util.LinkedHashMap)3 WORequest (com.webobjects.appserver.WORequest)2 ERXMutableURL (er.extensions.foundation.ERXMutableURL)2 Map (java.util.Map)2 WOActionResults (com.webobjects.appserver.WOActionResults)1 WODynamicURL (com.webobjects.appserver.WODynamicURL)1 WOMultipartIterator (com.webobjects.appserver.WOMultipartIterator)1 WOStatisticsStore (com.webobjects.appserver.WOStatisticsStore)1 NSArray (com.webobjects.foundation.NSArray)1 NSDictionary (com.webobjects.foundation.NSDictionary)1 NSMutableArray (com.webobjects.foundation.NSMutableArray)1 NSMutableDictionary (com.webobjects.foundation.NSMutableDictionary)1 ERXRedirect (er.extensions.appserver.ERXRedirect)1 ERXUnitAwareDecimalFormat (er.extensions.formatters.ERXUnitAwareDecimalFormat)1