Package com.webobjects.appserver

Examples of com.webobjects.appserver.WOResponse


  }

  WOResponse _handleRequest(WORequest aRequest)
  {
    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


  @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

      return request.requestHandlerPath() != null && request.requestHandlerPath().toLowerCase().indexOf("stats") >= 0;
    }
   
    @Override
    public WOResponse handleRequest(WORequest request) {
        WOResponse response = null;
       
        String actionName = null;
        Class actionClass = null;
        boolean shouldCacheResult = false;
       
        if (ERXWOResponseCache.sharedInstance().isEnabled()) {
            try {
                // Caching scheme for 5.2 applications. Will uncomment once we are building 5.2 only ERExtensions
              // CHECKME
                Object[] actionClassAndName = getRequestActionClassAndNameForPath(getRequestHandlerPathForRequest(request));
                //Object[] actionClassAndName = null;
                if (actionClassAndName != null && actionClassAndName.length == 3) {
                    actionName = (String)actionClassAndName[1];
                    actionClass = (Class)actionClassAndName[2];
                    if (ERXWOResponseCache.Cacheable.class.isAssignableFrom(actionClass)) {
                        response = ERXWOResponseCache.sharedInstance().cachedResponseForRequest(actionClass,
                                actionName,
                                request);
                        // we need to cache only when there was no previous response in the cache
                        shouldCacheResult = (response == null);
                    }
                }
            } catch (Exception e) {
                log.error("Caught exception checking for cache. Leaving it up to the regular exception handler to cache. Request: " + request, e);
            }
        }
    if (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)) {
          // 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);
                }
              }
            } else {
              // if no session was supplied, what are we doing here in the
          // first place? The adaptor shouldn't have linked to us as
View Full Code Here

      synchronized (this) {
        _currentThread = Thread.currentThread();
      }
      try {
        final ERXApplication app = ERXApplication.erxApplication();
        WOResponse response = app.dispatchRequestImmediately(request());
        // testing
        // Thread.sleep(16000);
        // log.info("Done: " + this);
        return response;
      }
View Full Code Here

  }
 
    @Override
  public void appendToResponse(WOResponse response, WOContext context) {
    if(entry == null) {
      WOResponse newResponse = application().createResponseInContext(context);
      newResponse.setHeaders(response.headers());
      newResponse.setUserInfo(response.userInfo());
      super.appendToResponse(newResponse, context);
      String content = newResponse.contentString();
      entry = new Entry(content, cacheDuration(), (context.hasSession() ? context.session().sessionID() : null));
      cache.put(values(), entry);
    }
    String content = entry.content(context);
    response.appendContentString(content);
View Full Code Here

    _documentRoot = bundleFile.getAbsolutePath();
    _useRequestHandlerPath = true;
  }

  protected WOResponse _generateResponseForInputStream(InputStream is, long length, String type) {
    WOResponse response = application.createResponseInContext(null);
    if (is != null) {
      if (length != 0) {
        response.setContentStream(is, 50*1024, length);
      }
    } else {
      response.setStatus(404);
    }
    if (type != null) {
      response.setHeader(type, "content-type");
    }
    if(length != 0) {
      response.setHeader("" + length, "content-length");
    }
    return response;
  }
View Full Code Here

    return _documentRoot;
  }

  @Override
  public WOResponse handleRequest(WORequest request) {
    WOResponse response = null;
    FileInputStream is = null;
    long length = 0;
    String contentType = null;
    String uri = request.uri();
    if (uri.charAt(0) == '/') {
      WOResourceManager rm = application.resourceManager();
      String documentRoot = documentRoot();
      File file = null;
      StringBuilder sb = new StringBuilder(documentRoot.length() + uri.length());
      String wodataKey = request.stringFormValueForKey("wodata");
      if(uri.startsWith("/cgi-bin") && wodataKey != null) {
        uri = wodataKey;
        if(uri.startsWith("file:")) {
          // remove file:/
          uri = uri.substring(5);
        } else {
         
        }
      } else {
        int index = uri.indexOf("/wodata=");

        if(index >= 0) {
          uri = uri.substring(index+"/wodata=".length());
        } else {
          sb.append(documentRoot);
        }
      }
     
      if (_useRequestHandlerPath) {
          try {
            WODynamicURL dynamicURL = new WODynamicURL(uri);
            String requestHandlerPath = dynamicURL.requestHandlerPath();
            if (requestHandlerPath == null || requestHandlerPath.length() == 0) {
              sb.append(uri);
            } else {
              sb.append('/');
              sb.append(requestHandlerPath);
            }
          }
          catch (Exception e) {
            throw new RuntimeException("Failed to parse URL '" + uri + "'.", e);
          }
      }
      else {
        sb.append(uri);
      }
     
      String path = sb.toString();
      try {
        path = path.replaceAll("\\?.*", "");
        if (request.userInfo() != null && !request.userInfo().containsKey("HttpServletRequest")) {
          /* PATH_INFO is already decoded by the servlet container */
          path = path.replace('+', ' ');
          path = URLDecoder.decode(path, CharEncoding.UTF_8);
        }
        file = new File(path);
        length = file.length();
        is = new FileInputStream(file);
       
        contentType = rm.contentTypeForResourceNamed(path);
        log.debug("Reading file '" + file + "' for uri: " + uri);
      } catch (IOException ex) {
        if (!uri.toLowerCase().endsWith("/favicon.ico")) {
          log.info("Unable to get contents of file '" + file + "' for uri: " + uri);
        }
      }
    } else {
      log.error("Can't fetch relative path: " + uri);
    }
    response = _generateResponseForInputStream(is, length, contentType);
    NSNotificationCenter.defaultCenter().postNotification(WORequestHandler.DidHandleRequestNotification, response);
    response._finalizeInContext(null);
    return response;
  }
View Full Code Here

   * Handles the request and returns the applicable response.
   */
  @Override
  public WOResponse handleRequest(final WORequest request) {
    ERXApplication app = ERXApplication.erxApplication();
    WOResponse response = null;
    if (canHandleRequest(request)) {
      String uri = request.uri();
      DelayedRequest delayedRequest;
      String id;
      log.debug("Handling: " + uri);

      String key = request.requestHandlerKey();
      if (KEY.equals(key)) {
        id = request.stringFormValueForKey("id");
        delayedRequest = _futures.objectForKey(id);
        if (delayedRequest == null) {
          String url = _urls.objectForKey(id);
          if (url == null) {
            return createErrorResponse(request);
          }
          response = new ERXResponse(ERXHttpStatusCodes.FOUND);
          response.setHeader(url, "location");
          // refresh entry, so it doesn't time out
          _urls.setObjectForKey(url, id);
          return response;
        }
        // refresh entry, so it doesn't time out
View Full Code Here

   * @param delayedRequest
   * @param id
   */
  protected WOResponse handle(WORequest request, DelayedRequest delayedRequest, String id) {
    final ERXApplication app = ERXApplication.erxApplication();
    WOResponse response = null;
    try {
      String action = request.stringFormValueForKey("action");
      if (!delayedRequest.isDone()) {
        if ("stop".equals(action)) {
          if (delayedRequest.cancel()) {
View Full Code Here

    String args = (request.sessionID() != null ? "/" + request.sessionID() : "");
    // dirty trick: use a non-existing context id to get the page-expired
    // reply.
    String url = request.applicationURLPrefix() + "/wo" + args + "/9999999999.0";
    WORequest expired = app.createRequest("GET", url, "HTTP/1.0", request.headers(), null, null);
    WOResponse result = app.dispatchRequestImmediately(expired);
    return result;
  }
View Full Code Here

TOP

Related Classes of com.webobjects.appserver.WOResponse

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.