use of com.webobjects.appserver.WORequest in project wonder-slim by undur.
the class AjaxUtils method javascriptResponse.
/**
* Returns an {@link er.ajax.AjaxResponse} with the given javascript as the body of the response.
*
* @param context the context
* @param javascript the javascript to send
* @return a new response
*/
public static WOResponse javascriptResponse(String javascript, WOContext context) {
WORequest request = context.request();
AjaxResponse response = AjaxUtils.createResponse(request, context);
AjaxUtils.appendScriptHeaderIfNecessary(request, response);
response.appendContentString(javascript);
AjaxUtils.appendScriptFooterIfNecessary(request, response);
return response;
}
use of com.webobjects.appserver.WORequest in project wonder-slim by undur.
the class ERXWOContext method newContext.
/**
* @return A new WOContext created using a dummy WORequest.
*/
public static ERXWOContext newContext() {
ERXApplication app = ERXApplication.erxApplication();
// Try to create a URL with a relative path into the application to mimic a real request.
// We must create a request with a relative URL, as using an absolute URL makes the new
// WOContext's URL absolute, and it is then unable to render relative paths. (Long story short.)
//
// Note: If you configured the adaptor's WebObjectsAlias to something other than the default,
// make sure to also set your WOAdaptorURL property to match. Otherwise, asking the new context
// the path to a direct action or component action URL will give an incorrect result.
String requestUrl = app.cgiAdaptorURL() + "/" + app.name() + app.applicationExtension();
try {
URL url = new URL(requestUrl);
// Get just the part of the URL that is relative to the server root.
requestUrl = url.getPath();
} catch (MalformedURLException mue) {
// The above should never fail. As a last resort, using the empty string will
// look funny in the request, but still allow the context to use a relative url.
requestUrl = "";
}
WORequest dummyRequest = app.createRequest("GET", requestUrl, "HTTP/1.1", null, null, null);
if (ERXProperties.booleanForKeyWithDefault("er.extensions.ERXApplication.publicHostIsSecure", false)) {
dummyRequest.setHeader("on", "https");
}
return (ERXWOContext) app.createContextForRequest(dummyRequest);
}
use of com.webobjects.appserver.WORequest in project wonder-slim by undur.
the class ERXAjaxApplication method shouldNotStorePage.
/**
* Checks if the page should not be stored in the cache
*/
public static boolean shouldNotStorePage(WOContext context) {
WORequest request = context.request();
WOResponse response = context.response();
// MS: The "AJAX_SUBMIT_BUTTON_NAME" check is a total hack, but if your
// page structure changes such that the form that
// is being submitted to is hidden, it ends up not notifying the system
// not to cache the page.
boolean shouldNotStorePage = (shouldNotStorePage(response) || shouldNotStorePage(request) || isAjaxSubmit(request)) && !forceStorePage(response);
return shouldNotStorePage;
}
use of com.webobjects.appserver.WORequest in project wonder-slim by undur.
the class ERXAjaxSession method restorePageForContextID.
/**
* Extension of restorePageForContextID that implements the other side of
* Page Replacement Cache.
*/
@Override
public WOComponent restorePageForContextID(String contextID) {
log.debug("Restoring page for contextID: {}", contextID);
LinkedHashMap pageReplacementCache = (LinkedHashMap) objectForKey(ERXAjaxSession.PAGE_REPLACEMENT_CACHE_KEY);
WOComponent page = null;
if (pageReplacementCache != null) {
TransactionRecord pageRecord = (TransactionRecord) pageReplacementCache.get(contextID);
if (pageRecord != null) {
log.debug("Restoring page for contextID: {} pageRecord = {}", contextID, pageRecord);
page = pageRecord.page();
} else {
log.debug("No page in pageReplacementCache for contextID: {}", contextID);
// If we got the page out of the replacement cache above, then we're obviously still
// using Ajax, and it's likely our cache will be cleaned out in an Ajax update. If the
// requested page was not in the cache, though, then we might be done with Ajax,
// so give the cache a quick run-through for expired pages.
cleanPageReplacementCacheIfNecessary();
}
}
// AK: this will get handled last in the super implementation, so we do it here
if (page == null && overridePrivateCache) {
page = _permanentPageWithContextID(contextID);
if (page != null)
page._awakeInContext(context());
}
if (page == null) {
page = super.restorePageForContextID(contextID);
}
if (page != null) {
WOContext context = page.context();
if (context == null) {
page._awakeInContext(context());
context = page.context();
}
WORequest request = context.request();
// enough information at this point to know whether to do it or not, unfortunately.
if (request != null) {
request.setHeader(contextID, ERXAjaxSession.ORIGINAL_CONTEXT_ID_KEY);
}
}
return page;
}
use of com.webobjects.appserver.WORequest in project wonder-slim by undur.
the class ERXComponentRequestHandler method _dispatchWithPreparedSession.
private WOResponse _dispatchWithPreparedSession(WOSession aSession, WOContext aContext, NSDictionary someElements) {
WOComponent aPage = null;
WOResponse aResponse = null;
String aPageName = (String) someElements.objectForKey("wopage");
String oldContextID = aContext._requestContextID();
String oldSessionID = (String) someElements.objectForKey(WOApplication.application().sessionIdKey());
WOApplication anApplication = WOApplication.application();
boolean clearIDsInCookies = false;
if ((oldSessionID == null) || (oldContextID == null)) {
if ((aPageName == null) && (!aSession.storesIDsInCookies())) {
WORequest request = aContext.request();
String cookieHeader = request.headerForKey("cookie");
if ((cookieHeader != null) && (cookieHeader.length() > 0)) {
NSDictionary cookieDict = request.cookieValues();
if ((cookieDict.objectForKey(WOApplication.application().sessionIdKey()) != null) || (cookieDict.objectForKey(WOApplication.application().instanceIdKey()) != null)) {
clearIDsInCookies = true;
}
}
}
aPage = anApplication.pageWithName(aPageName, aContext);
} else {
aPage = _restorePageForContextID(oldContextID, aSession);
if (aPage == null) {
if (anApplication._isPageRecreationEnabled())
aPage = anApplication.pageWithName(aPageName, aContext);
else {
return anApplication.handlePageRestorationErrorInContext(aContext);
}
}
}
aContext._setPageElement(aPage);
aResponse = _dispatchWithPreparedPage(aPage, aSession, aContext, someElements);
if (anApplication.isPageRefreshOnBacktrackEnabled()) {
aResponse.disableClientCaching();
}
aSession._saveCurrentPage();
if ((clearIDsInCookies) && (!aSession.storesIDsInCookies())) {
aSession._clearCookieFromResponse(aResponse);
}
return aResponse;
}
Aggregations