Package com.webobjects.appserver

Examples of com.webobjects.appserver.WOResponse


    WOApplication application = WOApplication.application();
    application.awake();
    try {
      WOContext context = application.createContextForRequest(request);
      WOResponse response = application.createResponseInContext(context);

      String sessionIdKey = application.sessionIdKey();
      String sessionId = (String) request.formValueForKey(sessionIdKey);
      if (sessionId == null) {
        sessionId = request.cookieValueForKey(sessionIdKey);
      }
      context._setRequestSessionID(sessionId);
      if (context._requestSessionID() != null) {
        application.restoreSessionWithID(sessionId, context);
      }

      try {
      final WODynamicURL url = request._uriDecomposed();
        final String requestPath = url.requestHandlerPath();
        final Matcher idMatcher = Pattern.compile("^id/(\\d+)/").matcher(requestPath);

        final Integer requestedAttachmentID;
        String requestedWebPath;

        final boolean requestedPathContainsAnAttachmentID = idMatcher.find();
    if (requestedPathContainsAnAttachmentID) {
          requestedAttachmentID = Integer.valueOf(idMatcher.group(1));
          requestedWebPath = idMatcher.replaceFirst("/");
        } else {
          // MS: This is kind of goofy because we lookup by path, your web path needs to
          // have a leading slash on it.
          requestedWebPath = "/" + requestPath;
          requestedAttachmentID = null;
        }


        try {
          InputStream attachmentInputStream;
          String mimeType;
          String fileName;
          long length;
          String queryString = url.queryString();
          boolean proxyAsAttachment = (queryString != null && queryString.contains("attachment=true"));

          EOEditingContext editingContext = ERXEC.newEditingContext();
          editingContext.lock();

          try {
            ERAttachment attachment = fetchAttachmentFor(editingContext, requestedAttachmentID, requestedWebPath);
           
            if (_delegate != null && !_delegate.attachmentVisible(attachment, request, context)) {
              throw new SecurityException("You are not allowed to view the requested attachment.");
            }
            mimeType = attachment.mimeType();
            length = attachment.size().longValue();
            fileName = attachment.originalFileName();
            ERAttachmentProcessor<ERAttachment> attachmentProcessor = ERAttachmentProcessor.processorForType(attachment);
            if (!proxyAsAttachment) {
              proxyAsAttachment = attachmentProcessor.proxyAsAttachment(attachment);
            }
            InputStream rawAttachmentInputStream = attachmentProcessor.attachmentInputStream(attachment);
            attachmentInputStream = new BufferedInputStream(rawAttachmentInputStream, bufferSize);
          } finally {
            editingContext.unlock();
          }
         
          response.setHeader(mimeType, "Content-Type");
          response.setHeader(String.valueOf(length), "Content-Length");

          if (proxyAsAttachment) {
            response.setHeader("attachment; filename=\"" + fileName + "\"", "Content-Disposition");
          }

          response.setStatus(200);
          response.setContentStream(attachmentInputStream, bufferSize, length);
        }
        catch (SecurityException e) {
          NSLog.out.appendln(e);
          response.setContent(e.getMessage());
          response.setStatus(403);
        }
        catch (NoSuchElementException e) {
          NSLog.out.appendln(e);
          response.setContent(e.getMessage());
          response.setStatus(404);
        }
        catch (FileNotFoundException e) {
          NSLog.out.appendln(e);
          response.setContent(e.getMessage());
          response.setStatus(404);
        }
        catch (IOException e) {
          NSLog.out.appendln(e);
          response.setContent(e.getMessage());
          response.setStatus(500);
        }

        return response;
      }
      finally {
View Full Code Here


        if (NSLog.debugLoggingAllowedForLevel(NSLog.DebugLevelInformational)) {
            NSLog.debug.appendln("PayPal's request looks like: " + ppIPNRequest + "\n\n");
            NSLog.debug.appendln("PayPal's request content looks like: " + ppIPNRequest.contentString() + "\n\n");
        }
       
        WOResponse ppValidationResponse = null; // PayPal's validation of our echoed data
        String ppValidationResponseString = null;
        boolean connectionSuccess;
        if (ppIPNRequest.formValues().containsKey("test_ipn")) {
          isSandboxMode = true;
        } else {
          isSandboxMode = false;
        }

        String returnString = ppIPNRequest.contentString() + "&cmd=_notify-validate";
      WOHTTPConnection ppEchoConnection = new WOHTTPConnection(paypalSite, 80); // our echo to PayPal
        if (isSandboxMode) {
          ppEchoConnection = new WOHTTPConnection(sandboxSite, 80); // our echo to PayPal
        }
        // assemble User-Agent header
        StringBuilder ua = new StringBuilder();
        ua.append("WebObjects/ " + ERXProperties.webObjectsVersion() + " (");
        ua.append(System.getProperty("os.arch"));
        ua.append("; ");
        ua.append(System.getProperty("os.name"));
        ua.append(' ');
        ua.append(System.getProperty("os.version"));
        ua.append(')');

        NSMutableDictionary headers = new NSMutableDictionary();
        headers.setObjectForKey("en", "Accept-Language");
        headers.setObjectForKey("iso-8859-1,*,utf-8", "Accept-Charset");
        headers.setObjectForKey("image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*", "Accept");
        headers.setObjectForKey(ua.toString(),"User-Agent");

        // the response back to PayPal
        WORequest paypalEchoRequest;
        paypalEchoRequest = new WORequest("POST", paypalCgi, "HTTP/1.1", headers, null, null);

        paypalEchoRequest.setContent(returnString);
        ppEchoConnection.setReceiveTimeout(90 * 1000); // 90 second timeout -- this might be too long!?!
        connectionSuccess = ppEchoConnection.sendRequest(paypalEchoRequest);
        if (connectionSuccess) {
          ppValidationResponse = ppEchoConnection.readResponse(); // read PayPal's validation
        }

        ppValidationResponseString = ppValidationResponse.contentString();

        if (connectionSuccess) {
            // PayPal's response *content* will either be "VERIFIED" or "INVALID"
            if (NSLog.debugLoggingAllowedForLevel(NSLog.DebugLevelInformational)) {
                NSLog.debug.appendln("the response looks like: " + ppValidationResponse + "\n\n");
View Full Code Here

      // Skip, because this has already been added ...
      return;
    }
    // default to inline for ajax requests
    boolean inline = booleanValueForBinding( "inline", ERXAjaxApplication.isAjaxRequest( wocontext.request() ) );
    WOResponse response = inline ? originalResponse : new ERXResponse();

    String href = styleSheetUrl();
    if( href == null ) {
      String key = styleSheetKey();
      ERXExpiringCache<String, WOResponse> cache = cache( session() );
      String md5;
      WOResponse cachedResponse = cache.objectForKey( key );
      if( cache.isStale( key ) || ERXApplication.isDevelopmentModeSafe() ) {
        cachedResponse = new ERXResponse();
        super.appendToResponse( cachedResponse, wocontext );
        // appendToResponse above will change the response of
        // "wocontext" to "newresponse". When this happens during an
        // Ajax request, it will lead to backtracking errors on
        // subsequent requests, so restore the original response "r"
        wocontext._setResponse( originalResponse );
        cachedResponse.setHeader( "text/css", "content-type" );
        cache.setObjectForKey( cachedResponse, key );
        md5 = ERXStringUtilities.md5Hex( cachedResponse.contentString(), null );
        cachedResponse.setHeader( md5, "checksum" );
      }
      md5 = cachedResponse.headerForKey( "checksum" );
      NSDictionary<String, Object> query = new NSDictionary<String, Object>( md5, "checksum" );
      href = wocontext.directActionURLForActionNamed( Sheet.class.getName() + "/" + key, query, wocontext.request().isSecure(), 0, false );
    }

    response._appendContentAsciiString( "<link" );
View Full Code Here

      super( worequest );
    }

    @Override
    public WOActionResults performActionNamed( String name ) {
      WOResponse response = ERXStyleSheet.cache( session() ).objectForKey( name );
      String md5 = ERXStringUtilities.md5Hex( response.contentString(), null );
      String queryMd5 = response.headerForKey( "checksum" );
      if (ObjectUtils.equals(md5, queryMd5)) {
        //TODO check for last-whatever time and return not modified if not changed
      }
      return response;
    }
View Full Code Here

  public void savePage(WOComponent page) {
    WOContext context = context();
    if (ERXAjaxApplication.shouldNotStorePage(context)) {
      if (logger.isDebugEnabled()) logger.debug("Considering pageReplacementCache for " + context.request().uri() + " with contextID " + context.contextID());
      WORequest request = context.request();
      WOResponse response = context.response();
      String pageCacheKey = null;
      if (response != null) {
        pageCacheKey = response.headerForKey(ERXAjaxSession.PAGE_REPLACEMENT_CACHE_LOOKUP_KEY);
      }
      if (pageCacheKey == null && request != null) {
        pageCacheKey = request.headerForKey(ERXAjaxSession.PAGE_REPLACEMENT_CACHE_LOOKUP_KEY);
      }
View Full Code Here

    if (ERXAjaxApplication.shouldNotStorePage(context)) {
      if (shouldIgnoreResults(request, context, results)) {
        results = null;
      }
      if (results == null && !ERXAjaxApplication.isAjaxReplacement(request)) {
        WOResponse response = context.response();

        if (_responseDelegate != null) {
          results = _responseDelegate.handleNullActionResults(request, response, context);
          response = context.response();
        }
View Full Code Here

   * </span>
   */
  @SuppressWarnings("javadoc")
  public static boolean shouldNotStorePage(WOContext context) {
    WORequest request = context.request();
    WOResponse response = context.response();
    // MS: The "AJAX_SUBMIT_BUTTON_NAME" check is a total hack, but if your
    // page structure changes such that the form that
    // is being submitted to is hidden, it ends up not notifying the system
    // not to cache the page.
    boolean shouldNotStorePage = (shouldNotStorePage(response) || shouldNotStorePage(request) || isAjaxSubmit(request)) && !forceStorePage(response);
View Full Code Here

  }

  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;
        }
      }
View Full Code Here

    return aResponse;
  }

  private WOResponse _dispatchWithPreparedSession(WOSession aSession, WOContext aContext, NSDictionary someElements) {
    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())) {
      aSession._clearCookieFromResponse(aResponse);
View Full Code Here

    return aResponse;
  }

  private WOResponse _dispatchWithPreparedApplication(WOApplication anApplication, WOContext aContext, NSDictionary someElements) {
    WOSession aSession = null;
    WOResponse aResponse = null;
    WOResponse errorResponse = null;
    String aSessionID = (String)someElements.objectForKey(WOApplication.application().sessionIdKey());

    if (aSessionID == null) {
      aSession = anApplication._initializeSessionInContext(aContext);
      if (aSession == null)
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.