Search in sources :

Example 21 with WOResponse

use of com.webobjects.appserver.WOResponse in project wonder-slim by undur.

the class AjaxUpdateLink method handleRequest.

@Override
public WOActionResults handleRequest(WORequest request, WOContext context) {
    WOComponent component = context.component();
    boolean disabled = booleanValueForBinding("disabled", false, component);
    String updateContainerID = AjaxUpdateContainer.updateContainerID(this, component);
    AjaxUpdateContainer.setUpdateContainerID(request, updateContainerID);
    WOActionResults results = null;
    if (!disabled) {
        results = (WOActionResults) valueForBinding("action", component);
    }
    if (ERXAjaxApplication.isAjaxReplacement(request)) {
        AjaxUtils.setPageReplacementCacheKey(context, (String) valueForBinding("replaceID", component));
    } else if (results == null || booleanValueForBinding("ignoreActionResponse", false, component)) {
        String script = (String) valueForBinding("onClickServer", component);
        if (script != null) {
            WOResponse response = AjaxUtils.createResponse(request, context);
            AjaxUtils.appendScriptHeaderIfNecessary(request, response);
            response.appendContentString(script);
            AjaxUtils.appendScriptFooterIfNecessary(request, response);
            results = response;
        }
    } else if (updateContainerID != null) {
        AjaxUtils.setPageReplacementCacheKey(context, updateContainerID);
    }
    return results;
}
Also used : WOActionResults(com.webobjects.appserver.WOActionResults) WOComponent(com.webobjects.appserver.WOComponent) WOResponse(com.webobjects.appserver.WOResponse)

Example 22 with WOResponse

use of com.webobjects.appserver.WOResponse in project wonder-slim by undur.

the class AjaxProxy method handleRequest.

/**
 * Ask the an JSONRPCBridge object to handle the json request.
 */
@Override
public WOActionResults handleRequest(WORequest request, WOContext context) {
    WOResponse response = AjaxUtils.createResponse(request, context);
    response.setHeader("application/json", "content-type");
    String inputString = request.contentString();
    log.debug("AjaxProxy.handleRequest: input = {}", inputString);
    // Process the request
    JSONObject input = null;
    Object output = null;
    try {
        input = new JSONObject(inputString);
        Object proxy;
        if (canGetValueForBinding("proxy")) {
            proxy = valueForBinding("proxy");
        } else {
            proxy = parent();
            log.warn("No proxy binding given, so using parent component. This is probably a very bad idea.");
        }
        String proxyName = (String) valueForBinding("proxyName");
        JSONRPCBridge bridge = getBridgeBinding();
        if (bridge == null) {
            bridge = JSONBridge.createBridge();
            setBridgeBinding(bridge);
        }
        bridge.registerObject(proxyName, proxy);
        output = bridge.call(new Object[] { request, context, response, proxy }, input);
    } catch (NoSuchElementException e) {
        log.error("No method in request");
        output = JSONRPCResult.MSG_ERR_NOMETHOD;
    } catch (Exception e) {
        log.error("Exception", e);
        output = JSONRPCResult.MSG_ERR_NOMETHOD;
    }
    // Write the response
    log.debug("AjaxProxy.handleRequest: output = {}", output);
    response.appendContentString(output.toString());
    return response;
}
Also used : JSONObject(org.json.JSONObject) JSONRPCBridge(org.jabsorb.JSONRPCBridge) JSONObject(org.json.JSONObject) WOResponse(com.webobjects.appserver.WOResponse) NoSuchElementException(java.util.NoSuchElementException) NoSuchElementException(java.util.NoSuchElementException)

Example 23 with WOResponse

use of com.webobjects.appserver.WOResponse in project wonder-slim by undur.

the class AjaxRequestHandler method handleRequest.

@Override
public WOResponse handleRequest(WORequest request) {
    ERXAjaxApplication.enableShouldNotStorePage();
    WOResponse response = super.handleRequest(request);
    return response;
}
Also used : WOResponse(com.webobjects.appserver.WOResponse)

Example 24 with WOResponse

use of com.webobjects.appserver.WOResponse in project wonder-slim by undur.

the class AjaxAutoComplete method handleRequest.

/**
 * Handles the Ajax request. Checks for the form value in the edit field,
 * pushes it up to the parent and pulls the "list" binding. The parent is
 * responsible for returning a list with some items that match the current value.
 */
@Override
public WOActionResults handleRequest(WORequest request, WOContext context) {
    // String inputString = request.contentString();
    String fieldValue = context.request().stringFormValueForKey(fieldName);
    setValueForBinding(fieldValue, "value");
    WOResponse response = AjaxUtils.createResponse(request, context);
    response.appendContentString("<ul>");
    int maxItems = maxItems();
    int itemsCount = 0;
    Object values = valueForBinding("list");
    WOElement child = _childTemplate();
    boolean hasItem = hasBinding("item");
    if (values instanceof NSArray) {
        for (Enumeration valueEnum = ((NSArray) values).objectEnumerator(); valueEnum.hasMoreElements() && itemsCount++ < maxItems; ) {
            appendItemToResponse(valueEnum.nextElement(), child, hasItem, response, context);
        }
    } else if (values instanceof List) {
        for (Iterator iter = ((List) values).iterator(); iter.hasNext() && itemsCount++ < maxItems; ) {
            appendItemToResponse(iter.next(), child, hasItem, response, context);
        }
    } else if (values instanceof Object[]) {
        Object[] array = (Object[]) values;
        for (int i = 0; i < array.length && i < maxItems; i++) {
            appendItemToResponse(array[i], child, hasItem, response, context);
        }
    } else if (values != null) {
        log.warn("Unsupported class type for list: {}", values.getClass().getCanonicalName());
    }
    response.appendContentString("</ul>");
    return response;
}
Also used : Enumeration(java.util.Enumeration) NSArray(com.webobjects.foundation.NSArray) Iterator(java.util.Iterator) List(java.util.List) WOResponse(com.webobjects.appserver.WOResponse) WOElement(com.webobjects.appserver.WOElement)

Example 25 with WOResponse

use of com.webobjects.appserver.WOResponse in project wonder-slim by undur.

the class ERXDirectActionRequestHandler method handleRequest.

@Override
public WOResponse handleRequest(WORequest request) {
    WOResponse response = null;
    // ak: when addressed with a DA link with this instance's ID (and
    // an expired session) and the app is refusing new sessions, the
    // default implementation will create a session anyway, which will
    // wreak havoc if the app is memory starved.
    // Search engines are a nuisance in that regard
    WOApplication app = WOApplication.application();
    if (app.isRefusingNewSessions() && request.isUsingWebServer() && !isSystemRequest(request)) {
        if (isSessionIDInRequest(request)) {
            // yadda-yadda.
            if (app.sessionStore().getClass() == WOServerSessionStore.class) {
                if (app.sessionStore().restoreSessionWithID(request.sessionID(), request) == null) {
                    response = generateRequestRefusal(request);
                    // AK: should be a permanent redirect, as the session is gone for good.
                    // However, the adaptor checks explicitly on 302 so we return that...
                    // It shouldn't matter which instance we go to now.
                    response.setStatus(302);
                }
            }
        } else {
            // if no session was supplied, what are we doing here in the
            // first place? The adaptor shouldn't have linked to us as
            // we are refusing new sessions.
            response = generateRequestRefusal(request);
        }
    }
    if (response == null) {
        response = super.handleRequest(request);
    }
    return response;
}
Also used : WOResponse(com.webobjects.appserver.WOResponse) WOApplication(com.webobjects.appserver.WOApplication)

Aggregations

WOResponse (com.webobjects.appserver.WOResponse)33 WOComponent (com.webobjects.appserver.WOComponent)10 WOApplication (com.webobjects.appserver.WOApplication)7 WOActionResults (com.webobjects.appserver.WOActionResults)6 WOContext (com.webobjects.appserver.WOContext)5 WORequest (com.webobjects.appserver.WORequest)4 WOSession (com.webobjects.appserver.WOSession)4 NSDictionary (com.webobjects.foundation.NSDictionary)4 WODynamicURL (com.webobjects.appserver.WODynamicURL)2 NSArray (com.webobjects.foundation.NSArray)2 File (java.io.File)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Iterator (java.util.Iterator)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 NoSuchElementException (java.util.NoSuchElementException)2 JSONRPCBridge (org.jabsorb.JSONRPCBridge)2 JSONObject (org.json.JSONObject)2 WOAssociation (com.webobjects.appserver.WOAssociation)1