Package org.jabsorb

Examples of org.jabsorb.JSONRPCBridge$ObjectInstance


         * Create a new bridge for every request to avoid all the problems with
         * JSON-RPC-Java storing the bridge in the session
         */
        HttpSession session = request.getSession();

        JSONRPCBridge jsonrpcBridge = new JSONRPCBridge();
        jsonrpcBridge.registerObject("Service", serviceInstance, serviceInterface);
        session.setAttribute("JSONRPCBridge", jsonrpcBridge);
       
        org.json.JSONObject jsonReq = null;
        JSONRPCResult jsonResp = null;
        jsonReq = new org.json.JSONObject(requestData);

        String method = jsonReq.getString("method");
        if ((method != null) && (method.indexOf('.') < 0)) {
            jsonReq.putOpt("method", "Service" + "." + method);
        }

        // invoke the request
        jsonResp = jsonrpcBridge.call(new Object[] {request}, jsonReq);

        return jsonResp.toString().getBytes("UTF-8");
    }
View Full Code Here


      else {
        proxy = parent();
      }
      String proxyName = (String) valueForBinding("proxyName");

      JSONRPCBridge bridge = null;
      if (canGetValueForBinding("AjaxBridge")) {
        bridge = (JSONRPCBridge) valueForBinding("AjaxBridge");
      }
      else {
        bridge = JSONBridge.createBridge();
        if (canSetValueForBinding("AjaxBridge")) {
          setValueForBinding(bridge, "AjaxBridge");
        }
      }
      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;
    }
View Full Code Here

        try {
          JSONComponentCallback componentCallback = null;
         
          WODynamicURL url = request._uriDecomposed();
          String requestHandlerPath = url.requestHandlerPath();
          JSONRPCBridge jsonBridge;
          if (requestHandlerPath != null && requestHandlerPath.length() > 0) {
            String componentNameAndInstance = requestHandlerPath;
            String componentInstance;
            String componentName;
            int slashIndex = componentNameAndInstance.indexOf('/');
            if (slashIndex == -1) {
              componentName = componentNameAndInstance;
              componentInstance = null;
            }
            else {
              componentName = componentNameAndInstance.substring(0, slashIndex);
              componentInstance = componentNameAndInstance.substring(slashIndex + 1);
            }

            if (session == null) {
              session = context.session();
            }

            String bridgesKey = (componentInstance == null) ? "_JSONGlobalBridges" : "_JSONInstanceBridges";
            Map<String, JSONRPCBridge> componentBridges = (Map<String, JSONRPCBridge>) session.objectForKey(bridgesKey);
            if (componentBridges == null) {
              int limit = ERXProperties.intForKeyWithDefault((componentInstance == null) ? "er.ajax.json.globalBacktrackCacheSize" : "er.ajax.json.backtrackCacheSize", WOApplication.application().pageCacheSize());
              componentBridges = new LRUMap<String, JSONRPCBridge>(limit);
              session.setObjectForKey(componentBridges, bridgesKey);
            }
            jsonBridge = componentBridges.get(componentNameAndInstance);
            if (jsonBridge == null) {
              Class componentClass = _NSUtilities.classWithName(componentName);
              JSONComponent component;
              if (JSONComponent.class.isAssignableFrom(componentClass)) {
                component = (JSONComponent) _NSUtilities.instantiateObject(componentClass, new Class[] { WOContext.class }, new Object[] { context }, true, false);
              }
              else {
                throw new SecurityException("There is no JSON component named '" + componentName + "'.");
              }
              jsonBridge = createBridgeForComponent(component, componentName, componentInstance, componentBridges);
            }
           
            componentCallback = new JSONComponentCallback(context);
            jsonBridge.registerCallback(componentCallback, WOContext.class);
          }
          else {
            jsonBridge = _sharedBridge;
          }

          try {
            output = jsonBridge.call(new Object[] { request, response, context }, input);
          }
          finally {
            if (componentCallback != null) {
              jsonBridge.unregisterCallback(componentCallback, WOContext.class);
            }
          }

          if (context._session() != null) {
            WOSession contextSession = context._session();
View Full Code Here

    }
    return componentNameAndInstance;
  }

  protected JSONRPCBridge createBridgeForComponent(JSONComponent component, String componentName, String componentInstance, Map<String, JSONRPCBridge> componentBridges) throws Exception {
    JSONRPCBridge jsonBridge = JSONBridge.createBridge();
    jsonBridge.registerCallableReference(JSONComponent.class);
    jsonBridge.registerObject("component", component);
    String componentNameAndInstance = JSONRequestHandler.componentNameAndInstance(componentName, componentInstance);
    componentBridges.put(componentNameAndInstance, jsonBridge);
    return jsonBridge;
  }
View Full Code Here

TOP

Related Classes of org.jabsorb.JSONRPCBridge$ObjectInstance

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.