Package com.webobjects.appserver

Examples of com.webobjects.appserver.WOApplication


    public Action(WORequest arg0) {
      super(arg0);
    }
   
    public WOActionResults keepAliveAction() {
      WOApplication application = WOApplication.application();
      WOContext context = context();
      WOResponse response = application.createResponseInContext(context);
      String sessionID = context.request().stringFormValueForKey("erxsid");
      if (!application.isRefusingNewSessions()) {
        WOSession session = application.restoreSessionWithID(sessionID, context);
        if (session != null) {
          log.debug("Pinging " + sessionID);
          // CHECKME TH do we still need that?
          // we give over the session id as we also need to touch the session anyway
          response.setHeader(ERXSession.DONT_STORE_PAGE, sessionID);
View Full Code Here


            if (AppSpecificPropertyNames.size() > 128) {
                AppSpecificPropertyNames.clear();
            }
            String appSpecificPropertyName = (String)AppSpecificPropertyNames.get(propertyName);
            if (appSpecificPropertyName == null) {
                final WOApplication application = WOApplication.application();
                if (application != null) {
                    final String appName = application.name();
                    appSpecificPropertyName = propertyName + "." + appName;
                }
                else {
                    appSpecificPropertyName = propertyName;
                }
View Full Code Here

     */
  @SuppressWarnings("javadoc")
  public static String applicationMachinePropertiesPath(String fileName) {
      String applicationMachinePropertiesPath = null;
      String machinePropertiesPath = ERXSystem.getProperty("er.extensions.ERXProperties.machinePropertiesPath", "/etc/WebObjects");
      WOApplication application = WOApplication.application();
      String applicationName;
      if (application != null) {
        applicationName = application.name();
      }
      else {
        applicationName = ERXSystem.getProperty("WOApplicationName");
        if (applicationName == null) {
          NSBundle mainBundle = NSBundle.mainBundle();
View Full Code Here

  public static void flattenPropertyNames(Properties properties) {
      if (_useLoadtimeAppSpecifics == false) {
          return;
      }
     
      WOApplication application = WOApplication.application();
      if (application == null) {
          return;
      }
      String applicationName = application.name();
      for (Object keyObj : new TreeSet<Object>(properties.keySet())) {
          String key = (String) keyObj;
          if (key != null && key.length() > 0) {
              String value = properties.getProperty(key);
              int lastDotPosition = key.lastIndexOf(".");
View Full Code Here

    _maxUploadSize = maxUploadSize;
  }

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

      String uploadIdentifier = null;
      String uploadFileName = null;
      InputStream uploadInputStream = null;
      long streamLength = -1L;

      try {
        String sessionIdKey = WOApplication.application().sessionIdKey();
        String sessionId = request.cookieValueForKey(sessionIdKey);
        WOMultipartIterator multipartIterator = request.multipartIterator();
        if (multipartIterator == null) {
          response.appendContentString("Already Consumed!");
        }
        else {
          WOMultipartIterator.WOFormData formData = null;
          while ((formData = multipartIterator.nextFormData()) != null) {
            String name = formData.name();
            if (sessionIdKey.equals(name)) {
              sessionId = formData.formValue();
            }
            else if ("id".equals(name)) {
              uploadIdentifier = formData.formValue();
            }
            else if (formData.isFileUpload()) {
              uploadFileName = request.stringFormValueForKey(name + ".filename");
              streamLength = multipartIterator.contentLengthRemaining();
              uploadInputStream = formData.formDataInputStream();
              break;
            }
          }
          context._setRequestSessionID(sessionId);
          WOSession session = null;
          if (context._requestSessionID() != null) {
            session = WOApplication.application().restoreSessionWithID(sessionId, context);
          }
          if (session == null) {
            throw new Exception("No valid session!");
          }
          File tempFile = File.createTempFile("AjaxFileUpload", ".tmp", _tempFileFolder);
          tempFile.deleteOnExit();
          AjaxUploadProgress progress = new AjaxUploadProgress(uploadIdentifier, tempFile, uploadFileName, streamLength);
          try {
            AjaxProgressBar.registerProgress(session, progress);
          }
          finally {
            if (context._requestSessionID() != null) {
              WOApplication.application().saveSessionForContext(context);
            }
          }

          if (formData != null) {
            NSArray<String> contentType = (NSArray<String>)formData.headers().valueForKey("content-type");
            if (contentType != null) {
              progress.setContentType(contentType.objectAtIndex(0));
            }
          }
         
          try {
            if (_maxUploadSize >= 0L && streamLength > _maxUploadSize) {
              IOException e = new IOException("You attempted to upload a file larger than the maximum allowed size of " + new ERXUnitAwareDecimalFormat(ERXUnitAwareDecimalFormat.BYTE).format(_maxUploadSize) + ".");
              progress.setFailure(e);
              progress.dispose();
              throw e;
            }
            FileOutputStream fos = new FileOutputStream(progress.tempFile());
            try {
              progress.copyAndTrack(uploadInputStream, fos, _maxUploadSize);
            }
            finally {
              fos.flush();
              fos.close();
            }
            if (!progress.isCanceled() && !progress.shouldReset()) {
              downloadFinished(progress);
            }
          }
          finally {
            progress.setDone(true);
          }
        }
      }
      catch (Throwable t) {
        log.error("Upload failed",t);
        response.appendContentString("Failed: " + t.getMessage());
      }
      finally {
        if (uploadInputStream != null) {
          try {
            uploadInputStream.close();
          }
          catch (IOException e) {
            // ignore
          }
        }
      }
      return response;
    }
    finally {
      application.sleep();
    }
  }
View Full Code Here

    public static ERCNNotificationCoordinator coordinator() {
        return _coordinator;
    }

    protected String id() {
        WOApplication app = WOApplication.application();
        String host = app.host();
        Number port = app.port();
        String appName = app.name();
        return host + ":" + port + "/" + appName;
    }
View Full Code Here

     *            a given logging event
     * @return the current application name
     */
    @Override
    public String convert(LoggingEvent event) {
      WOApplication app = WOApplication.application();
      if (app != null) {

        if (!_constantsInitialized) {
          String pid = System.getProperty("com.webobjects.pid");
          if (pid != null) {
            _appInfo.setObjectForKey(pid, "pid");
          }

          String appName = app.name();
          if (appName != null) {
            _appInfo.setObjectForKey(appName, "appName");
          }

          if (app.port() != null && app.port().intValue() > 0) {
            _appInfo.setObjectForKey(app.port().toString(), "portNumber");
          }
          else {
            // WO 5.1.x -- Apple Ref# 2260519
            NSArray adaptors = app.adaptors();
            if (adaptors != null && adaptors.count() > 0) {
              WOAdaptor primaryAdaptor = (WOAdaptor) adaptors.objectAtIndex(0);
              String portNumber = String.valueOf(primaryAdaptor.port());
              if (portNumber != null) {
                _appInfo.setObjectForKey(portNumber, "portNumber");
              }
            }
          }

          _template = _templateParser.parseTemplateWithObject(_template, "@@", _appInfo, _defaultLabels);
          _constantsInitialized = true;
        }

        _appInfo.setObjectForKey(String.valueOf(app.activeSessionsCount()), "sessionCount");
      }
      return _templateParser.parseTemplateWithObject(_template, "@@", _appInfo);
    }
View Full Code Here

   
    private transient String _toString;
    private transient int _entryCount = 0;

    public ERCNSnapshot(NSNotification notification) {
        WOApplication app = WOApplication.application();
        _senderHost = app.host();
        _senderPort = app.port(); // Don't forget to apply Max's change
        _senderAppName = app.name();

        NSDictionary userInfo = notification.userInfo();

        ERCNConfiguration configuration = ERCNNotificationCoordinator.coordinator().configuration();
        if (configuration.changeTypesToPublish().containsObject(INSERTED))
View Full Code Here

   
    /**
     * Implementation of the {@link Runnable} interface.
     */
    public void run() {
        WOApplication app = WOApplication.application();
       
        setResult(null);
       
        _done = false;
       
View Full Code Here

  @Override
  public WOResponse handleRequest(WORequest request) {
    int bufferSize = 16384;

    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 {
        if (context._requestSessionID() != null) {
          WOApplication.application().saveSessionForContext(context);
        }
      }
    }
    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.