Package com.webobjects.appserver

Examples of com.webobjects.appserver.WOApplication


        cookie.isHttpOnly());
    return wocookie;
  }
 
  public static WOSession existingSession(WORequest request) {
    WOApplication app = WOApplication.application();
    String sessionID = request.stringFormValueForKey(app.sessionIdKey());
    WOSession session = null;
    if(sessionID != null) {
      WOContext context = app.createContextForRequest(request);
      session = app.restoreSessionWithID(sessionID, context);
    }
    return session;
  }
View Full Code Here


  public WOActionResults invokeAction(WORequest worequest, WOContext wocontext) {
    if (wocontext.senderID() != null && wocontext.senderID().startsWith(wocontext.elementID())) {
      try {
        String componentName = worequest.stringFormValueForKey("component");
        WOApplication application = WOApplication.application();
       
        Method debugEnabledMethod = application.getClass().getMethod("debugEnabledForComponent", String.class);
        Boolean debugEnabled = (Boolean) debugEnabledMethod.invoke(application, componentName);

        Method setDebugEnabledMethod = application.getClass().getMethod("setDebugEnabledForComponent", boolean.class, String.class);
        setDebugEnabledMethod.invoke(application, Boolean.valueOf(!debugEnabled.booleanValue()), componentName);
      }
      catch (Throwable e) {
        e.printStackTrace();
      }
View Full Code Here

    return context().page().getClass().getSimpleName();
  }
 
  public WOActionResults toggleDebugEnabled() {
    try {
      WOApplication application = WOApplication.application();
      Method setDebugMethod = application.getClass().getMethod("setDebugEnabledForComponent", boolean.class, WOComponent.class);
      _debugEnabled = !_debugEnabled;
      setDebugMethod.invoke(application, Boolean.valueOf(_debugEnabled), context().page());
    }
    catch (Throwable t) {
      NSLog.debug.appendln("Your application does not have a setDebugEnabledForComopnent(boolean, WOComponent) method.");
View Full Code Here

    requestHandler.addDefaultRoutes("EOModelGroup", false, SEModelGroupController.class);
    requestHandler.addDefaultRoutes("EOModel", false, SEModelController.class);
    requestHandler.addDefaultRoutes("EOEntity", false, SEEntityController.class);
   
    // Display "How to Boot" Message in Log
    WOApplication app = ERXApplication.application()
    String entity = requestHandler.controllerPathForEntityNamed("ModelGroup");
    NSLog.out.appendln("SESnapshotExplorer ModelGroup launch line: " + app.directConnectURL() + "/" + ERXRouteRequestHandler.Key + "/" + entity + ".html");

  }
View Full Code Here

   *
   * @return whether or not the current application is in development mode
   */
  public static boolean isDevelopmentModeSafe() {
    boolean developmentMode;
    WOApplication application = WOApplication.application();
    if (application instanceof ERXApplication) {
      ERXApplication erxApplication = (ERXApplication) application;
      developmentMode = erxApplication.isDevelopmentMode();
    }
    else {
View Full Code Here

    /**
     * This is called directly only for when ERXApplication is sub-classed.
     */
  @Override
  public void finishInitialization() {
    WOApplication application = WOApplication.application();
    if (!AjaxRequestHandler.useAjaxRequestHandler()) {
      application.registerRequestHandler(new AjaxRequestHandler(), AjaxRequestHandler.AjaxRequestHandlerKey);
      log.debug("AjaxRequestHandler installed");
    }
    application.registerRequestHandler(new AjaxPushRequestHandler(), AjaxPushRequestHandler.AjaxCometRequestHandlerKey);

    // Register the AjaxResponseDelegate if you're using an ERXAjaxApplication ... This allows us
    // to fix some weird border cases caused by structural page changes.
    if (application instanceof ERXAjaxApplication) {
      ((ERXAjaxApplication)application).setResponseDelegate(new AjaxResponse.AjaxResponseDelegate());
View Full Code Here

        String path = null;
        NSBundle bundle = "app".equals(frameworkName) ? NSBundle.mainBundle() : NSBundle.bundleForName(frameworkName);
        if(bundle != null && bundle.isJar()) {
            log.warn("Can't get path when run as jar: " + frameworkName + " - " + fileName);
        } else {
          WOApplication application = WOApplication.application();
          if (application != null) {
              URL url = application.resourceManager().pathURLForResourceNamed(fileName, frameworkName, languages);
              if(url != null) {
                  path = url.getFile();
              }
          } else if( bundle != null ) {
            URL url = bundle.pathURLForResourcePath(fileName);
View Full Code Here

     * @param languages array of languages to get localized resource or <code>null</code>
     * @return the absolutePath method off of the file object
     */
    public static URL pathURLForResourceNamed(String fileName, String frameworkName, NSArray<String> languages) {
      URL url = null;
      WOApplication application = WOApplication.application();
      if (application != null) {
        WOResourceManager resourceManager = application.resourceManager();
        if (resourceManager != null) {
          url = resourceManager.pathURLForResourceNamed(fileName, frameworkName, languages);
        }
      }
        return url;
View Full Code Here

  }

  @SuppressWarnings("unchecked")
  @Override
  public WOResponse handleRequest(WORequest request) {
    WOApplication application = WOApplication.application();
    application.awake();
    try {
      WOContext context = application.createContextForRequest(request);
      WOResponse response = application.createResponseInContext(context);

      Object output;
      try {
        String inputString = request.contentString();
        JSONObject input = new JSONObject(inputString);
        String sessionIdKey = WOApplication.application().sessionIdKey();
        String sessionId = request.cookieValueForKey(sessionIdKey);
        if (sessionId == null) {
          ERXMutableURL url = new ERXMutableURL();
          url.setQueryParameters(request.queryString());
          sessionId = url.queryParameter(sessionIdKey);
          if (sessionId == null && input.has(sessionIdKey)) {
            sessionId = input.getString(sessionIdKey);
          }
        }
        context._setRequestSessionID(sessionId);
        WOSession session = null;
        if (context._requestSessionID() != null) {
          session = WOApplication.application().restoreSessionWithID(sessionId, context);
        }
        if (session != null) {
          session.awake();
        }
        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();
            // If this is a new session, then we have to force it to be a cookie session
            if (sessionId == null) {
              boolean storesIDsInCookies = contextSession.storesIDsInCookies();
              try {
                contextSession.setStoresIDsInCookies(true);
                contextSession._appendCookieToResponse(response);
              }
              finally {
                contextSession.setStoresIDsInCookies(storesIDsInCookies);
              }
            }
            else {
              contextSession._appendCookieToResponse(response);
            }
          }
          response.appendContentString(output.toString());
          response._finalizeInContext(context);
          response.disableClientCaching();
        }
        finally {
          try {
            if (session != null) {
              session.sleep();
            }
          }
          finally {
            if (context._session() != null) {
              WOApplication.application().saveSessionForContext(context);
            }
          }
        }
      }
      catch (NoSuchElementException e) {
        e.printStackTrace();
        output = new JSONRPCResult(JSONRPCResult.CODE_ERR_NOMETHOD, null, JSONRPCResult.MSG_ERR_NOMETHOD);
      }
      catch (JSONException e) {
        e.printStackTrace();
        output = new JSONRPCResult(JSONRPCResult.CODE_ERR_PARSE, null, JSONRPCResult.MSG_ERR_PARSE);
      }
      catch (Throwable t) {
        t.printStackTrace();
        output = new JSONRPCResult(JSONRPCResult.CODE_ERR_PARSE, null, t.getMessage());
      }

      return response;
    }
    finally {
      application.sleep();
    }
  }
View Full Code Here

TOP

Related Classes of com.webobjects.appserver.WOApplication

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.