Package com.webobjects.appserver

Examples of com.webobjects.appserver.WOApplication


     *
     * @return String
     */
    protected String defaultNotificationURL() {
        StringBuilder notURL = new StringBuilder();
        WOApplication app = application();

        //check if we're in directConnect mode
        if (app.isDirectConnectEnabled()) {
            // we're running in development mode; try to get the i.p. address; if it's not 127.0.0.1, we'll include the notify_url parameter; .local. means we're running locally under rendezvous
            if (app.host().equals("localhost") || app.host().indexOf(".local.") != -1) {
                if (app.hostAddress().getHostAddress().equals("127.0.0.1")) {
                    // probably not connected to internet
                    return "testing_mode"; //just so we can see this method working
                } else {
                    //get protocol
                    String protocol = app.cgiAdaptorURL().substring(0, app.cgiAdaptorURL().indexOf(":"));
                    notURL.append(protocol).append("://"); // http:// or https://
                    notURL.append(app.hostAddress().getHostAddress()); // host i.p.
                    if (app.port().intValue() != 80) { // 80 is standard web port
                        notURL.append(':').append(app.port()); // :portNum
                    }
                    notURL.append(context().request().adaptorPrefix()).append('/'); // cgi-bin/WebObjects/
                    notURL.append(context().request().applicationName()).append(".woa/wa/PayPalAction/ipn"); // our processing action
                }

            }
        } else {
            // we're running the app in a deployment or testing mode
            notURL.append(app.cgiAdaptorURL()).append("://"); // http://host/cgi-bin/WebObjects
            notURL.append('/').append(context().request().applicationName()).append(".woa/"); // /applicationName.woa/
            notURL.append(context().request().applicationNumber()); // app instance number (for routing with multiple instances running)
            notURL.append("/wa/PayPalAction/ipn"); // our processing action
        }
        NSLog.debug.appendln("defaultNotificationURL: " + notURL.toString());
View Full Code Here


            // 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);

          }
        }
      }
View Full Code Here

  /**
   * Creates a WOContext using a dummy WORequest.
   * @return the new WOContext
   */
  public static WOContext newContext() {
    WOApplication app = WOApplication.application();
    // 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);
      requestUrl = url.getPath(); // Get just the part of the URL that is relative to the server root.
    } 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 = "";
    }
    return app.createContextForRequest(app.createRequest("GET", requestUrl, "HTTP/1.1", null, null, null));
  }
View Full Code Here

  }

  public static boolean shouldIgnoreResults(WORequest request, WOContext context, WOActionResults results) {
    boolean shouldIgnoreResults = false;
    if (results == context.page() && !ERXAjaxApplication.isAjaxReplacement(request)) {
      WOApplication application = WOApplication.application();
      if (application instanceof ERXAjaxApplication) {
        shouldIgnoreResults = !((ERXAjaxApplication)application).allowContextPageResponse();
      }
      else {
        shouldIgnoreResults = true;
View Full Code Here

  }

  @Override
  public WOResponse handleRequest(WORequest aRequest)
  {
    WOApplication anApplication = WOApplication.application();
    Object globalLock = anApplication.requestHandlingLock();
    WOResponse aResponse;
    if (globalLock != null)
    {
      synchronized (globalLock) {
        aResponse = _handleRequest(aRequest);
View Full Code Here

      Templates t = (Templates) pool.getTemplates().get(key);
      String s = null;

      if (t == null) {
        try {
          WOApplication app = WOApplication.application();
          WOResourceManager rm = app.resourceManager();

          TransformerFactory fac = TransformerFactory.newInstance();

          log.debug("creating template for file " + filename + " in framework " + framework);
          InputStream is = rm.inputStreamForResourceNamed(filename, framework, null);
          if (is == null) {
            log.debug("trying with framework = null");
            is = rm.inputStreamForResourceNamed(filename, null, null);
            if (is == null) {
              throw new IllegalArgumentException("inputStream is null");
            }
          }
          if (is.available() == 0) {
            throw new IllegalArgumentException("InputStream has 0 bytes available, cannot read xsl file!");
          }
          s = ERXFileUtilities.stringFromInputStream(is);
          s = templateParser.parseTemplateWithObject(s, "@@", app);
          t = fac.newTemplates(new StreamSource(new ByteArrayInputStream(s.getBytes())));

          if (app.isCachingEnabled()) {
            templates.put(key, t);
          }
        } catch (IOException e1) {
          throw NSForwardException._runtimeExceptionForThrowable(e1);
        } catch (TransformerConfigurationException tce) {
View Full Code Here

      // 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)) {
          // we know the imp of the server session store simply
          // looks up the ID in the registered sessions,
          // so we don't need to do the check-out/check-in
          // 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);
View Full Code Here

    return aSession.restorePageForContextID(oldContextID);
  }

  private WOResponse _dispatchWithPreparedPage(WOComponent aPage, WOSession aSession, WOContext aContext, NSDictionary someElements) {
    WORequest aRequest = aContext.request();
    WOApplication anApplication = WOApplication.application();
    WOResponse aResponse = anApplication.createResponseInContext(aContext);
    String aSenderID = aContext.senderID();

    String oldContextID = aSession._contextIDMatchingIDs(aContext);
    aResponse.setHTTPVersion(aRequest.httpVersion());

    aResponse.setHeader("text/html", "content-type");

    aContext._setResponse(aResponse);

    if (oldContextID == null)
    {
      if (aSenderID != null)
      {
        if (aRequest._hasFormValues()) {
          anApplication.takeValuesFromRequest(aRequest, aContext);
        }
      }

      aContext._setPageChanged(false);
      if (aSenderID != null)
      {
        WOActionResults anActionResults = anApplication.invokeAction(aRequest, aContext);

        if ((anActionResults == null) || ((anActionResults instanceof WOComponent)))
        {
          WOComponent aResultComponent = (WOComponent)anActionResults;
          if ((aResultComponent != null) && (aResultComponent.context() != aContext)) {
            aResultComponent._awakeInContext(aContext);
          }
          boolean didPageChange = false;
          if ((aResultComponent != null) && (aResultComponent != aContext._pageElement())) {
            didPageChange = true;
          }
          aContext._setPageChanged(didPageChange);
          if (didPageChange) {
            aContext._setPageElement(aResultComponent);
          }

        }
        else
        {
          WOResponse theResponse = anActionResults.generateResponse();

          return theResponse;
        }
      }

    }
    else
    {
      WOComponent responsePage = _restorePageForContextID(oldContextID, aSession);
      aContext._setPageElement(responsePage);
    }

    anApplication.appendToResponse(aResponse, aContext);

    return aResponse;
  }
View Full Code Here

    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())) {
View Full Code Here

    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;
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.