Exemplo n.º 1
0
  /**
   * Sets up the logging system with the given configuration in {@link java.util.Properties} format.
   *
   * @param properties with the logging configuration
   */
  public static synchronized void configureLogging(Properties properties) {
    LogManager.resetConfiguration();
    BasicConfigurator.configure();
    // AK: we re-configure the logging a few lines later from the
    // properties, but in case
    // no config is set, we set the root level to info, install the brigde
    // which sets it's own logging level to DEBUG
    // and the output should be pretty much the same as with plain WO
    Logger.getRootLogger().setLevel(Level.INFO);
    boolean is522OrHigher = ERXProperties.webObjectsVersionIs522OrHigher();
    if (is522OrHigher) {
      int allowedLevel = NSLog.debug.allowedDebugLevel();
      if (!(NSLog.debug instanceof ERXNSLogLog4jBridge)) {
        NSLog.setOut(new ERXNSLogLog4jBridge(ERXNSLogLog4jBridge.OUT));
        NSLog.setErr(new ERXNSLogLog4jBridge(ERXNSLogLog4jBridge.ERR));
        NSLog.setDebug(new ERXNSLogLog4jBridge(ERXNSLogLog4jBridge.DEBUG));
      }
      NSLog.debug.setAllowedDebugLevel(allowedLevel);
    }
    PropertyConfigurator.configure(properties);
    // AK: if the root logger has no appenders, something is really broken
    // most likely the properties didn't read correctly.
    if (!Logger.getRootLogger().getAllAppenders().hasMoreElements()) {
      Appender appender =
          new ConsoleAppender(
              new ERXPatternLayout("%-5p %d{HH:mm:ss} (%-20c:%L):  %m%n"), "System.out");
      Logger.getRootLogger().addAppender(appender);
      Logger.getRootLogger().setLevel(Level.DEBUG);
      Logger.getRootLogger()
          .error("Logging prefs couldn't get read from properties, using defaults");
    }
    if (ERXLogger.log == null) {
      ERXLogger.log = Logger.getLogger(Logger.class.getName());
    }
    ERXLogger.log.info("Updated the logging configuration with the current system properties.");
    if (ERXLogger.log.isDebugEnabled()) {
      ERXLogger.log.debug("log4j.loggerFactory: " + System.getProperty("log4j.loggerFactory"));
      ERXLogger.log.debug("Factory: " + ERXLogger.factory);
      // MS: This just trips everyone up, and it really seems to only be
      // used by PW developers, so I say we just turn it on when we need it.
      // log.debug("", new RuntimeException(
      // "This is not a real exception. It is just to show you where logging was initialized."
      // ));
    }
    // PropertyPrinter printer = new PropertyPrinter(new
    // PrintWriter(System.out));
    // printer.print(new PrintWriter(System.out));
    if (ERXLogger.factory != null) {
      ERXLogger.factory.loggingConfigurationDidChange();
    }

    NSNotificationCenter.defaultCenter()
        .postNotification(ERXConfigurationManager.ConfigurationDidChangeNotification, null);
  }
Exemplo n.º 2
0
  protected NSMutableArray getQueryErrors(NSDictionary[] responseDicts) {
    NSMutableArray errorArray = new NSMutableArray();

    for (int i = 0; i < responseDicts.length; i++) {
      if (responseDicts[i] != null) {
        NSDictionary responseDict = responseDicts[i];
        getGlobalErrorFromResponse(responseDict, errorArray);

        NSArray commandWotaskdResponse =
            (NSArray) responseDict.valueForKey("commandWotaskdResponse");
        if ((commandWotaskdResponse != null) && (commandWotaskdResponse.count() > 0)) {
          int count = commandWotaskdResponse.count();
          for (int j = 1; j < count; j++) {
            NSDictionary aDict = (NSDictionary) commandWotaskdResponse.objectAtIndex(j);
            String errorMessage = (String) aDict.valueForKey("errorMessage");
            if (errorMessage != null) {
              errorArray.addObject(errorMessage);
              if (j == 0) break; // the command produced an error,
              // parsing didn't finish
            }
          }
        }
      }
    }
    if (NSLog.debugLoggingAllowedForLevelAndGroups(
        NSLog.DebugLevelDetailed, NSLog.DebugGroupDeployment))
      NSLog.debug.appendln("##### getQueryErrors: " + errorArray);
    mySession().addObjectsFromArrayIfAbsentToErrorMessageArray(errorArray);
    return errorArray;
  }
Exemplo n.º 3
0
  public static void sendCommandInstancesToWotaskds(
      String command, NSArray instanceArray, NSArray wotaskdArray, WOTaskdHandler collector) {
    if (instanceArray.count() > 0 && wotaskdArray.count() > 0) {
      int instanceCount = instanceArray.count();

      NSMutableDictionary monitorRequest = new NSMutableDictionary(1);
      NSMutableArray commandWotaskd = new NSMutableArray(instanceArray.count() + 1);

      commandWotaskd.addObject(command);

      for (int i = 0; i < instanceCount; i++) {
        MInstance anInst = (MInstance) instanceArray.objectAtIndex(i);
        commandWotaskd.addObject(
            new NSDictionary(
                new Object[] {
                  anInst.applicationName(), anInst.id(), anInst.hostName(), anInst.port()
                },
                commandInstanceKeys));
      }
      monitorRequest.takeValueForKey(commandWotaskd, "commandWotaskd");

      WOResponse[] responses = collector.sendRequest(monitorRequest, wotaskdArray, false);
      NSDictionary[] responseDicts = collector.generateResponseDictionaries(responses);
      if (NSLog.debugLoggingAllowedForLevelAndGroups(
          NSLog.DebugLevelDetailed, NSLog.DebugGroupDeployment)) {
        NSLog.debug.appendln(
            "OUT: "
                + NSPropertyListSerialization.stringFromPropertyList(monitorRequest)
                + "\n\nIN: "
                + NSPropertyListSerialization.stringFromPropertyList(new NSArray(responseDicts)));
      }
      collector.getCommandErrors(responseDicts);
    }
  }
Exemplo n.º 4
0
 public NSDictionary jdbcInfo() {
   NSDictionary jdbcInfo = super.jdbcInfo();
   JDBCContext jdbccontext = this.adaptor()._cachedAdaptorContext();
   try {
     jdbccontext.connection().commit();
   } catch (SQLException exception) {
     if (NSLog.debugLoggingAllowedForLevelAndGroups(3, 0x0L)) NSLog.debug.appendln(exception);
   }
   return jdbcInfo;
 }
Exemplo n.º 5
0
  /* ******** Error Handling ********* */
  public NSMutableArray getUpdateErrors(
      NSDictionary[] responseDicts,
      String updateType,
      boolean hasHosts,
      boolean hasApplications,
      boolean hasInstances,
      boolean hasSite) {
    NSMutableArray errorArray = new NSMutableArray();

    boolean clearOverwrite = false;
    if ((updateType.equals("overwrite")) || (updateType.equals("clear"))) clearOverwrite = true;

    for (int i = 0; i < responseDicts.length; i++) {
      if (responseDicts[i] != null) {
        NSDictionary responseDict = responseDicts[i];
        getGlobalErrorFromResponse(responseDict, errorArray);

        NSDictionary updateWotaskdResponseDict =
            (NSDictionary) responseDict.valueForKey("updateWotaskdResponse");

        if (updateWotaskdResponseDict != null) {
          NSDictionary updateTypeResponse =
              (NSDictionary) updateWotaskdResponseDict.valueForKey(updateType);
          if (updateTypeResponse != null) {
            if (clearOverwrite) {
              String errorMessage = (String) updateTypeResponse.valueForKey("errorMessage");
              if (errorMessage != null) {
                errorArray.addObject(errorMessage);
              }
            } else {
              if (hasSite) {
                NSDictionary aDict = (NSDictionary) updateTypeResponse.valueForKey("site");
                String errorMessage = (String) aDict.valueForKey("errorMessage");
                if (errorMessage != null) {
                  errorArray.addObject(errorMessage);
                }
              }
              if (hasHosts)
                _addUpdateResponseToErrorArray(updateTypeResponse, "hostArray", errorArray);
              if (hasApplications)
                _addUpdateResponseToErrorArray(updateTypeResponse, "applicationArray", errorArray);
              if (hasInstances)
                _addUpdateResponseToErrorArray(updateTypeResponse, "instanceArray", errorArray);
            }
          }
        }
      }
    }
    if (NSLog.debugLoggingAllowedForLevelAndGroups(
        NSLog.DebugLevelDetailed, NSLog.DebugGroupDeployment))
      NSLog.debug.appendln("##### getUpdateErrors: " + errorArray);
    mySession().addObjectsFromArrayIfAbsentToErrorMessageArray(errorArray);
    return errorArray;
  }
Exemplo n.º 6
0
  public void getApplicationStatusForHosts(NSArray<MHost> hostArray) {

    WOResponse[] responses = sendQueryToWotaskds("APPLICATION", hostArray);

    NSMutableArray errorArray = new NSMutableArray();
    NSDictionary applicationResponseDictionary;
    NSDictionary queryResponseDictionary;
    NSArray responseArray = null;
    NSDictionary responseDictionary = null;
    for (int i = 0; i < responses.length; i++) {
      if ((responses[i] == null) || (responses[i].content() == null)) {
        queryResponseDictionary = emptyResponse;
      } else {
        try {
          queryResponseDictionary =
              (NSDictionary) new _JavaMonitorDecoder().decodeRootObject(responses[i].content());
        } catch (WOXMLException wxe) {
          NSLog.err.appendln(
              "MonitorComponent pageWithName(ApplicationsPage) Error decoding response: "
                  + responses[i].contentString());
          queryResponseDictionary = responseParsingFailed;
        }
      }
      getGlobalErrorFromResponse(queryResponseDictionary, errorArray);

      applicationResponseDictionary =
          (NSDictionary) queryResponseDictionary.valueForKey("queryWotaskdResponse");
      if (applicationResponseDictionary != null) {
        responseArray = (NSArray) applicationResponseDictionary.valueForKey("applicationResponse");
        if (responseArray != null) {
          for (int j = 0; j < responseArray.count(); j++) {
            responseDictionary = (NSDictionary) responseArray.objectAtIndex(j);
            String appName = (String) responseDictionary.valueForKey("name");
            Integer runningInstances = (Integer) responseDictionary.valueForKey("runningInstances");
            MApplication anApplication = siteConfig().applicationWithName(appName);
            if (anApplication != null) {
              anApplication.setRunningInstancesCount(
                  anApplication.runningInstancesCount() + runningInstances.intValue());
            }
          }
        }
      }
    } // for
    if (NSLog.debugLoggingAllowedForLevelAndGroups(
        NSLog.DebugLevelDetailed, NSLog.DebugGroupDeployment))
      NSLog.debug.appendln("##### pageWithName(ApplicationsPage) errors: " + errorArray);
    mySession().addObjectsFromArrayIfAbsentToErrorMessageArray(errorArray);
  }
 private String _removeNewStyleCommentsAndQuotedStringsFromString(String declarationsStr) {
   String escapedQuoteStr =
       _NSStringUtilities.replaceAllInstancesOfString(
           declarationsStr, "\\\"", WOHelperFunctionDeclarationParser.ESCAPED_QUOTE_STRING);
   StringBuilder declarationWithoutCommentsBuffer = new StringBuilder(100);
   StringTokenizer tokenizer = new StringTokenizer(escapedQuoteStr, "/\"", true);
   try {
     while (tokenizer.hasMoreTokens()) {
       String token = tokenizer.nextToken("/\"");
       if (token.equals("/")) {
         token = tokenizer.nextToken("\n");
         if (token.startsWith("/")) {
           token =
               _NSStringUtilities.replaceAllInstancesOfString(
                   token, WOHelperFunctionDeclarationParser.ESCAPED_QUOTE_STRING, "\\\"");
           declarationWithoutCommentsBuffer.append('\n');
           tokenizer.nextToken();
         } else {
           declarationWithoutCommentsBuffer.append('/');
           declarationWithoutCommentsBuffer.append(token);
         }
       } else if (token.equals("\"")) {
         token = tokenizer.nextToken("\"");
         if (token.equals("\"")) {
           token = "";
         } else {
           tokenizer.nextToken();
         }
         String quotedStringKey =
             WOHelperFunctionDeclarationParser.QUOTED_STRING_KEY + _quotedStrings.count();
         if (NSLog.debugLoggingAllowedForLevelAndGroups(3, 0x0L)) {
           NSLog.debug.appendln("Found a quoted string: " + quotedStringKey + "='" + token + "';");
         }
         token =
             _NSStringUtilities.replaceAllInstancesOfString(
                 token, WOHelperFunctionDeclarationParser.ESCAPED_QUOTE_STRING, "\"");
         _quotedStrings.setObjectForKey(token, quotedStringKey);
         declarationWithoutCommentsBuffer.append(quotedStringKey);
       } else {
         declarationWithoutCommentsBuffer.append(token);
       }
     }
   } catch (NoSuchElementException e) {
     log.debug("Parsing failed.", e);
   }
   return declarationWithoutCommentsBuffer.toString();
 }
Exemplo n.º 8
0
  /**
   * This is usually extracted from the the database using JDBC, but this is really inconvenient for
   * users who are trying to generate SQL at some. A specific version of the data has been written
   * into the property list of the framework and this can be used as a hard-coded equivalent.
   */
  public NSDictionary jdbcInfo() {
    // you can swap this code out to write the property list out in order
    // to get a fresh copy of the JDBCInfo.plist.
    //    try {
    //      String jdbcInfoS = NSPropertyListSerialization.stringFromPropertyList(super.jdbcInfo());
    //      FileOutputStream fos = new FileOutputStream("/tmp/JDBCInfo.plist");
    //      fos.write(jdbcInfoS.getBytes());
    //      fos.close();
    //    }
    //    catch(Exception e) {
    //      throw new IllegalStateException("problem writing JDBCInfo.plist",e);
    //    }

    NSDictionary jdbcInfo;
    // have a look at the JDBC connection URL to see if the flag has been set to
    // specify that the hard-coded jdbcInfo information should be used.
    if (shouldUseBundledJdbcInfo()) {
      if (NSLog.debugLoggingAllowedForLevel(NSLog.DebugLevelDetailed)) {
        NSLog.debug.appendln(
            "Loading jdbcInfo from JDBCInfo.plist as opposed to using the JDBCPlugIn default implementation.");
      }

      InputStream jdbcInfoStream =
          NSBundle.bundleForClass(getClass()).inputStreamForResourcePath("JDBCInfo.plist");
      if (jdbcInfoStream == null) {
        throw new IllegalStateException("Unable to find 'JDBCInfo.plist' in this plugin jar.");
      }

      try {
        jdbcInfo =
            (NSDictionary)
                NSPropertyListSerialization.propertyListFromData(
                    new NSData(jdbcInfoStream, 2048), "US-ASCII");
      } catch (IOException e) {
        throw new RuntimeException("Failed to load 'JDBCInfo.plist' from this plugin jar.", e);
      } finally {
        try {
          jdbcInfoStream.close();
        } catch (IOException e) {
        }
      }
    } else {
      jdbcInfo = super.jdbcInfo();
    }
    return jdbcInfo;
  }
Exemplo n.º 9
0
 protected static NSDictionary _dictionaryFromFile(File file) {
   NSDictionary model = null;
   try {
     model = Services.dictionaryFromFile(file);
     NSArray rules = (NSArray) model.objectForKey("rules");
     Enumeration e = rules.objectEnumerator();
     while (e.hasMoreElements()) {
       NSMutableDictionary dict = (NSMutableDictionary) e.nextElement();
       if ("com.webobjects.directtoweb.Rule".equals(dict.objectForKey("class"))) {
         dict.setObjectForKey("ERD2WExtendedRule", "class");
       }
     }
   } catch (Throwable throwable) {
     NSLog.err.appendln(
         "****** DirectToWeb: Problem reading file " + file + " reason:" + throwable);
     if (NSLog.debugLoggingAllowedForLevelAndGroups(1, 40L)) {
       NSLog.err.appendln("STACKTRACE:");
       NSLog.err.appendln(throwable);
     }
     throw NSForwardException._runtimeExceptionForThrowable(throwable);
   }
   return model;
 }
Exemplo n.º 10
0
  public void getHostStatusForHosts(NSArray<MHost> hostArray) {
    WOResponse[] responses = sendQueryToWotaskds("HOST", hostArray);

    NSMutableArray errorArray = new NSMutableArray();
    NSDictionary responseDict = null;
    for (int i = 0; i < responses.length; i++) {
      MHost aHost = siteConfig().hostArray().objectAtIndex(i);

      if ((responses[i] == null) || (responses[i].content() == null)) {
        responseDict = emptyResponse;
      } else {
        try {
          responseDict =
              (NSDictionary) new _JavaMonitorDecoder().decodeRootObject(responses[i].content());
        } catch (WOXMLException wxe) {
          NSLog.err.appendln(
              "MonitorComponent pageWithName(HostsPage) Error decoding response: "
                  + responses[i].contentString());
          responseDict = responseParsingFailed;
        }
      }
      getGlobalErrorFromResponse(responseDict, errorArray);

      NSDictionary queryResponse = (NSDictionary) responseDict.valueForKey("queryWotaskdResponse");
      if (queryResponse != null) {
        NSDictionary hostResponse = (NSDictionary) queryResponse.valueForKey("hostResponse");
        aHost._setHostInfo(hostResponse);
        aHost.isAvailable = true;
      } else {
        aHost.isAvailable = false;
      }
    } // for
    if (NSLog.debugLoggingAllowedForLevelAndGroups(
        NSLog.DebugLevelDetailed, NSLog.DebugGroupDeployment))
      NSLog.debug.appendln("##### pageWithName(HostsPage) errors: " + errorArray);
    mySession().addObjectsFromArrayIfAbsentToErrorMessageArray(errorArray);
  }
Exemplo n.º 11
0
  @Override
  @SuppressWarnings({"unchecked", "rawtypes"})
  public NSDictionary<String, Object> jdbcInfo() {

    NSDictionary<String, Object> jdbcInfo;
    // have a look at the JDBC connection URL to see if the flag has been set to
    // specify that the hard-coded jdbcInfo information should be used.
    if (shouldUseBundledJdbcInfo()) {
      if (NSLog.debugLoggingAllowedForLevel(NSLog.DebugLevelDetailed)) {
        NSLog.debug.appendln(
            "Loading jdbcInfo from JDBCInfo.plist as opposed to using the JDBCPlugIn default implementation.");
      }

      InputStream jdbcInfoStream =
          NSBundle.bundleForClass(getClass()).inputStreamForResourcePath("JDBCInfo.plist");
      if (jdbcInfoStream == null) {
        throw new IllegalStateException("Unable to find 'JDBCInfo.plist' in this plugin jar.");
      }

      try {
        jdbcInfo =
            (NSDictionary<String, Object>)
                NSPropertyListSerialization.propertyListFromData(
                    new NSData(jdbcInfoStream, 2048), "US-ASCII");
      } catch (IOException e) {
        throw new RuntimeException("Failed to load 'JDBCInfo.plist' from this plugin jar.", e);
      }

    } else {

      NSMutableDictionary<String, Object> mutableInfo = super.jdbcInfo().mutableClone();
      NSMutableDictionary<String, NSDictionary> typeInfo =
          ((NSDictionary<String, NSDictionary>) mutableInfo.objectForKey("typeInfo"))
              .mutableClone();
      NSDictionary textTypeInfo = typeInfo.objectForKey("TEXT");
      if (textTypeInfo != null) {
        Object rawCreateParams = textTypeInfo.objectForKey("createParams");
        if (!rawCreateParams.equals("1")) {
          NSMutableDictionary newRawTypeInfo = textTypeInfo.mutableClone();
          newRawTypeInfo.setObjectForKey("1", "createParams");
          typeInfo.setObjectForKey(newRawTypeInfo, "RAW");
        }
      }
      JDBCPlugIn._takeValueForKeyPath(typeInfo, "0", "BLOB", "createParams");
      JDBCPlugIn._takeValueForKeyPath(typeInfo, "0", "LONGBLOB", "createParams");
      JDBCPlugIn._takeValueForKeyPath(typeInfo, "0", "MEDIUMBLOB", "createParams");
      JDBCPlugIn._takeValueForKeyPath(typeInfo, "0", "TINYBLOB", "createParams");
      mutableInfo.setObjectForKey(typeInfo, "typeInfo");

      NSLog.debug.appendln(
          new StringBuilder("fetched MySQL (")
              .append(databaseProductName())
              .append(") JDBC Info = ")
              .append(mutableInfo)
              .toString());

      // Write a fresh copy of JDBCInfo.plist to /tmp
      // writeJDBCInfo(mutableInfo);

      jdbcInfo = mutableInfo.immutableClone();
    }
    return jdbcInfo;
  }
Exemplo n.º 12
0
  public void getInstanceStatusForHosts(NSArray<MHost> hostArray) {
    if (hostArray.count() != 0) {

      WOResponse[] responses = sendQueryToWotaskds("INSTANCE", hostArray);

      NSMutableArray errorArray = new NSMutableArray();
      NSArray responseArray = null;
      NSDictionary responseDictionary = null;
      NSDictionary queryResponseDictionary = null;
      for (int i = 0; i < responses.length; i++) {
        if ((responses[i] == null) || (responses[i].content() == null)) {
          responseDictionary = emptyResponse;
        } else {
          try {
            responseDictionary =
                (NSDictionary) new _JavaMonitorDecoder().decodeRootObject(responses[i].content());
          } catch (WOXMLException wxe) {
            NSLog.err.appendln(
                "MonitorComponent pageWithName(AppDetailPage) Error decoding response: "
                    + responses[i].contentString());
            responseDictionary = responseParsingFailed;
          }
        }
        getGlobalErrorFromResponse(responseDictionary, errorArray);

        queryResponseDictionary =
            (NSDictionary) responseDictionary.valueForKey("queryWotaskdResponse");
        if (queryResponseDictionary != null) {
          responseArray = (NSArray) queryResponseDictionary.valueForKey("instanceResponse");
          if (responseArray != null) {
            for (int j = 0; j < responseArray.count(); j++) {
              responseDictionary = (NSDictionary) responseArray.objectAtIndex(j);

              String host = (String) responseDictionary.valueForKey("host");
              Integer port = (Integer) responseDictionary.valueForKey("port");
              String runningState = (String) responseDictionary.valueForKey("runningState");
              Boolean refusingNewSessions =
                  (Boolean) responseDictionary.valueForKey("refusingNewSessions");
              NSDictionary statistics = (NSDictionary) responseDictionary.valueForKey("statistics");
              NSArray deaths = (NSArray) responseDictionary.valueForKey("deaths");
              String nextShutdown = (String) responseDictionary.valueForKey("nextShutdown");

              MInstance anInstance = siteConfig().instanceWithHostnameAndPort(host, port);
              if (anInstance != null) {
                for (int k = 0; k < MObject.stateArray.length; k++) {
                  if (MObject.stateArray[k].equals(runningState)) {
                    anInstance.state = k;
                    break;
                  }
                }
                anInstance.setRefusingNewSessions(String_Extensions.boolValue(refusingNewSessions));
                anInstance.setStatistics(statistics);
                anInstance.setDeaths(new NSMutableArray(deaths));
                anInstance.setNextScheduledShutdownString_M(nextShutdown);
              }
            }
          }
        }
      } // For Loop
      if (NSLog.debugLoggingAllowedForLevelAndGroups(
          NSLog.DebugLevelDetailed, NSLog.DebugGroupDeployment))
        NSLog.debug.appendln("##### pageWithName(AppDetailPage) errors: " + errorArray);
      mySession().addObjectsFromArrayIfAbsentToErrorMessageArray(errorArray);
    }
  }