private Set<String> populateRealm(
      ClassRealm classRealm, List<ClassRealmConstituent> constituents) {
    Set<String> includedIds = new LinkedHashSet<String>();

    if (logger.isDebugEnabled()) {
      logger.debug("Populating class realm " + classRealm.getId());
    }

    for (ClassRealmConstituent constituent : constituents) {
      File file = constituent.getFile();

      String id = getId(constituent);
      includedIds.add(id);

      if (logger.isDebugEnabled()) {
        logger.debug("  Included: " + id);
      }

      try {
        classRealm.addURL(file.toURI().toURL());
      } catch (MalformedURLException e) {
        // Not going to happen
        logger.error(e.getMessage(), e);
      }
    }

    return includedIds;
  }
  /**
   * Retrieves dependency information from Spring XML configuration files in a Maven project.
   *
   * @param project the project to analyze
   * @param dependentClasses A set of classes that already had their dependencies analyzed. This
   *     method will <b>ADD</b> all Spring-induced dependencies to this set and also use it to
   *     determine whether a given class needs to have it's dependencies analyzed.
   * @throws Exception
   */
  public void addSpringDependencyClasses(MavenProject project, final Set<String> dependentClasses)
      throws Exception {
    final SpringFileBeanVisitor beanVisitor =
        new DefaultSpringXmlBeanVisitor(this.resolver, dependentClasses);

    for (File springXml : fileLocator.locateSpringXmls(project)) {
      final BufferedInputStream in = new BufferedInputStream(new FileInputStream(springXml));
      try {
        fileParser.parse(in, beanVisitor);
        if (log != null && log.isInfoEnabled()) {
          log.info("Scanned Spring XML " + springXml.getPath());
        }
      } catch (NoSpringXmlException ex) {
        if (log != null && log.isDebugEnabled()) {
          log.debug("Not a Spring XML file : " + springXml.getPath());
        }
        // ok
      } catch (Exception e) {
        if (log != null) {
          log.error("Failed to parse Spring XML " + springXml.getPath() + " ...", e);
        }
        throw e;
      } finally {
        in.close();
      }
    }
  }
예제 #3
0
  @Override
  public void run() {
    try {
      m_channelManager = new ClientChannelManager();

      long expireTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(1);

      while (m_channelManager.getActiveChannel() == null
          && System.currentTimeMillis() < expireTime) {
        TimeUnit.MILLISECONDS.sleep(1);
      }

      m_warmup.countDown();
      run0();
    } catch (Throwable e) {
      m_logger.error(e.getMessage(), e);
      m_warmup.countDown();
    } finally {
      if (m_channelManager != null) {
        m_channelManager.close();
      }

      m_latch.countDown();
    }
  }
예제 #4
0
  @Override
  public void run() {
    m_active = true;

    while (m_active) {
      ChannelFuture channel = m_manager.channel();

      if (channel != null && checkWritable(channel)) {
        try {
          MessageTree tree = m_queue.poll();

          if (tree != null) {
            sendInternal(tree);
            tree.setMessage(null);
          }

        } catch (Throwable t) {
          m_logger.error("Error when sending message over TCP socket!", t);
        }
      } else {
        try {
          Thread.sleep(5);
        } catch (Exception e) {
          // ignore it
          m_active = false;
        }
      }
    }
  }
  private List<ClassRealmManagerDelegate> getDelegates() {
    try {
      return container.lookupList(ClassRealmManagerDelegate.class);
    } catch (ComponentLookupException e) {
      logger.error("Failed to lookup class realm delegates: " + e.getMessage(), e);

      return Collections.emptyList();
    }
  }
예제 #6
0
  protected void sendStatus(String label, GitHubStatus status) {
    logger.info("  ** " + label + " : " + status + "  ** ");

    HttpPost httpPostRequest = new HttpPost(githubEndpoint);

    try {
      String payload =
          String.format(
              "{\"state\": \"%s\", \"target_url\": \"%s\", \"description\": \"%s\", \"context\": \"%s\"}",
              status, "http://github.com", "This is a meaningful description", label);

      StringEntity params = new StringEntity(payload);

      httpPostRequest.addHeader("content-type", "application/json");
      httpPostRequest.addHeader("Authorization", "token " + githubToken);

      RequestConfig requestConfig =
          RequestConfig.custom()
              .setSocketTimeout(5000)
              .setConnectTimeout(5000)
              .setConnectionRequestTimeout(5000)
              .build();
      httpPostRequest.setConfig(requestConfig);

      httpPostRequest.setEntity(params);

      HttpResponse response = httpClient.execute(httpPostRequest);
      if (response.getStatusLine().getStatusCode() >= 300) {
        logger.error(response.getStatusLine().toString());
      }
      logger.info(response.getStatusLine().toString());
    } catch (Exception e) {
      logger.error(e.getMessage());
      e.printStackTrace();
    } finally {
      httpPostRequest.releaseConnection();
    }

    // post.s

  }
예제 #7
0
파일: Handler.java 프로젝트: ryanjin/cat
  private void offerQueue(AppData appData) {
    boolean success = m_appDataConsumer.enqueue(appData);

    if (!success) {
      m_error++;

      if (m_error % 1000 == 0) {
        Cat.logEvent("Discard", "AppDataConsumer", Event.SUCCESS, null);
        m_logger.error("Error when offer appData to queue , discard number " + m_error);
      }
    }
  }
예제 #8
0
파일: Handler.java 프로젝트: ryanjin/cat
  private void processOneRecord(int cityId, int operatorId, String record) {
    String items[] = record.split("\t");

    if (items.length == 10) {
      AppData appData = new AppData();

      try {
        String url = URLDecoder.decode(items[4], "utf-8");
        Integer command = m_appConfigManager.getCommands().get(url);

        if (command != null) {
          // appData.setTimestamp(Long.parseLong(items[0]));
          appData.setTimestamp(System.currentTimeMillis());
          appData.setCommand(command);
          appData.setNetwork(Integer.parseInt(items[1]));
          appData.setVersion(Integer.parseInt(items[2]));
          appData.setConnectType(Integer.parseInt(items[3]));
          appData.setCode(Integer.parseInt(items[5]));
          appData.setPlatform(Integer.parseInt(items[6]));
          appData.setRequestByte(Integer.parseInt(items[7]));
          appData.setResponseByte(Integer.parseInt(items[8]));
          appData.setResponseTime(Integer.parseInt(items[9]));
          appData.setCity(cityId);
          appData.setOperator(operatorId);
          appData.setCount(1);

          int responseTime = appData.getResponseTime();

          if (responseTime < 60 * 1000 && responseTime >= 0) {
            offerQueue(appData);

            Cat.logEvent("Command", url, Event.SUCCESS, null);
          } else if (responseTime > 0) {
            Integer tooLong = m_appConfigManager.getCommands().get(TOO_LONG);

            if (tooLong != null) {
              appData.setCommand(tooLong);
              offerQueue(appData);
            }
            Cat.logEvent("ResponseTooLong", url, Event.SUCCESS, String.valueOf(responseTime));
          } else {
            Cat.logEvent("ResponseTimeError", url, Event.SUCCESS, String.valueOf(responseTime));
          }
        } else {
          Cat.logEvent("CommandNotFound", url, Event.SUCCESS, items[4]);
        }
      } catch (Exception e) {
        m_logger.error(e.getMessage(), e);
      }
    } else {
      Cat.logEvent("InvalidPar", items[4], Event.SUCCESS, items[4]);
    }
  }
예제 #9
0
  private void logQueueFullInfo(MessageTree tree) {
    if (m_statistics != null) {
      m_statistics.onOverflowed(tree);
    }

    int count = m_errors.incrementAndGet();

    if (count % 1000 == 0 || count == 1) {
      m_logger.error("Message queue is full in tcp socket sender! Count: " + count);
    }

    tree = null;
  }
예제 #10
0
  public Toolchain getToolchainFromBuildContext(String type, MavenSession session) {
    Map<String, Object> context = retrieveContext(session);

    ToolchainModel model = (ToolchainModel) context.get(getStorageKey(type));

    if (model != null) {
      try {
        ToolchainFactory fact = factories.get(type);
        if (fact != null) {
          return fact.createToolchain(model);
        } else {
          logger.error(
              "Missing toolchain factory for type: "
                  + type
                  + ". Possibly caused by misconfigured project.");
        }
      } catch (MisconfiguredToolchainException ex) {
        logger.error("Misconfigured toolchain.", ex);
      }
    }

    return null;
  }
예제 #11
0
  protected void processExecutionResult(DefaultMavenExecutionResult executionResult) {
    BuildSummary bs = executionResult.getBuildSummary(executionResult.getProject());

    if (bs instanceof BuildSuccess) {
      sendStatus(bs.getProject().getName(), GitHubStatus.Success);
    } else if (bs instanceof BuildFailure) {
      sendStatus(bs.getProject().getName(), GitHubStatus.Failure);
    } else {
      logger.error(
          "m2github - unknown status for "
              + bs.getProject().getName()
              + " - "
              + bs.getClass().getName());
    }
  }
예제 #12
0
  private boolean checkWritable(ChannelFuture future) {
    boolean isWriteable = false;
    Channel channel = future.channel();

    if (future != null && channel.isOpen()) {
      if (channel.isActive() && channel.isWritable()) {
        isWriteable = true;
      } else {
        int count = m_attempts.incrementAndGet();

        if (count % 1000 == 0 || count == 1) {
          m_logger.error("Netty write buffer is full! Attempts: " + count);
        }
      }
    }

    return isWriteable;
  }
예제 #13
0
 /**
  * Grab lists of all root-level files and all directories contained in the given archive.
  *
  * @param file .
  * @param files .
  * @param dirs .
  * @throws java.io.IOException .
  */
 protected static void grabFilesAndDirs(String file, List<String> dirs, List<String> files)
     throws IOException {
   File zipFile = new File(file);
   if (!zipFile.exists()) {
     Logger logger = new ConsoleLogger(Logger.LEVEL_INFO, "console");
     logger.error("JarArchive skipping non-existing file: " + zipFile.getAbsolutePath());
   } else if (zipFile.isDirectory()) {
     Logger logger = new ConsoleLogger(Logger.LEVEL_INFO, "console");
     logger.info("JarArchiver skipping indexJar " + zipFile + " because it is not a jar");
   } else {
     org.apache.commons.compress.archivers.zip.ZipFile zf = null;
     try {
       zf = new org.apache.commons.compress.archivers.zip.ZipFile(file, "utf-8");
       Enumeration<ZipArchiveEntry> entries = zf.getEntries();
       HashSet<String> dirSet = new HashSet<String>();
       while (entries.hasMoreElements()) {
         ZipArchiveEntry ze = entries.nextElement();
         String name = ze.getName();
         // avoid index for manifest-only jars.
         if (!name.equals(META_INF_NAME)
             && !name.equals(META_INF_NAME + '/')
             && !name.equals(INDEX_NAME)
             && !name.equals(MANIFEST_NAME)) {
           if (ze.isDirectory()) {
             dirSet.add(name);
           } else if (!name.contains("/")) {
             files.add(name);
           } else {
             // a file, not in the root
             // since the jar may be one without directory
             // entries, add the parent dir of this file as
             // well.
             dirSet.add(name.substring(0, name.lastIndexOf("/") + 1));
           }
         }
       }
       dirs.addAll(dirSet);
     } finally {
       if (zf != null) {
         zf.close();
       }
     }
   }
 }
  /**
   * Reads the version from a properties file (the one embedded by Maven into Jar).
   *
   * @param path
   * @return
   */
  protected String readVersion(String path) {
    String version = "Unknown";

    try {
      Properties props = new Properties();

      InputStream is = getClass().getResourceAsStream(path);

      if (is != null) {
        props.load(is);

        version = props.getProperty("version");
      }

    } catch (IOException e) {
      logger.error("Could not load/read version from " + path, e);
    }

    return version;
  }
 public void delegate() {
   switch (level) {
     case LEVEL_DEBUG:
       logger.debug(message, cause);
       break;
     case LEVEL_INFO:
       logger.info(message, cause);
       break;
     case LEVEL_WARN:
       logger.warn(message, cause);
       break;
     case LEVEL_ERROR:
       logger.error(message, cause);
       break;
     case LEVEL_FATAL:
       logger.fatalError(message, cause);
       break;
     default:
       throw new Error();
   }
 }
예제 #16
0
파일: Handler.java 프로젝트: ryanjin/cat
  private void processVersion1(Payload payload, HttpServletRequest request, String userIp) {
    try {
      String content = payload.getContent();
      String[] lines = content.split("\n");
      long time = System.currentTimeMillis();

      for (String line : lines) {
        String[] tabs = line.split("\t");
        // timstampTABtargetUrlTABdurationTABhttpCodeTABerrorCodeENTER
        if (tabs.length == 5 && validate(tabs[3], tabs[4])) {
          MonitorEntity entity = new MonitorEntity();
          String httpStatus = tabs[3];
          String errorCode = tabs[4];

          if (StringUtils.isEmpty(errorCode)) {
            errorCode = Constrants.NOT_SET;
          }
          if (StringUtils.isEmpty(httpStatus)) {
            httpStatus = Constrants.NOT_SET;
          }
          // entity.setTimestamp(Long.parseLong(tabs[0]));
          entity.setTimestamp(time);
          entity.setTargetUrl(tabs[1]);
          entity.setDuration(Double.parseDouble(tabs[2]));
          entity.setHttpStatus(httpStatus);
          entity.setErrorCode(errorCode);
          entity.setIp(userIp);

          if ("200".equals(httpStatus)) {
            entity.setCount(10);
          } else {
            entity.setCount(1);
          }
          m_manager.offer(entity);
        }
      }
    } catch (Exception e) {
      m_logger.error(e.getMessage(), e);
    }
  }
예제 #17
0
파일: SrampWagon.java 프로젝트: rnc/s-ramp
 /**
  * @param message
  * @param t
  */
 private void error(String message, Throwable t) {
   if (logger != null) logger.error(message, t);
 }
예제 #18
0
  @Override
  public void init(Context context) throws Exception {
    super.init(context);
    this.context = context;

    String githubEndpointPrefix = "https://api.github.com/";

    String githubRepo;

    String sha;

    Properties userProperties = (Properties) context.getData().get("userProperties");
    githubRepo = userProperties.getProperty("m2github.repo");
    if (githubRepo == null) {
      logger.error("m2github - Missing property m2github.repo");
      initError = true;
    }

    githubToken = userProperties.getProperty("m2github.token");
    if (githubToken == null) {
      logger.error("m2github - Missing property m2github.token");
      initError = true;
    }

    if (userProperties.getProperty("m2github.endpoint") != null) {
      githubEndpointPrefix = userProperties.getProperty("m2github.endpoint");
    }

    // Need the current SHA
    Process gitProcess = Runtime.getRuntime().exec("git rev-parse HEAD");
    gitProcess.waitFor();

    BufferedReader reader = new BufferedReader(new InputStreamReader(gitProcess.getInputStream()));
    StringBuffer shaStringBuffer = new StringBuffer();
    String line = "";
    while ((line = reader.readLine()) != null) {
      shaStringBuffer.append(line);
    }
    sha = shaStringBuffer.toString();

    if (sha == null) {
      logger.error("m2github - Couldn't figure out SHA1");
      initError = true;
    }

    if (!initError) {
      try {
        githubEndpoint = githubEndpointPrefix + "/repos/" + githubRepo + "/statuses/" + sha;

        httpClient = HttpClients.createDefault();

        if (httpClient == null) {
          logger.error(" ** m2github - Failed to initialize HTTP Client");
          System.exit(1);
        }

        logger.info(
            " ** m2github - GitHub Event Spy succesfully initialized - Endpoint is "
                + githubEndpoint
                + " ** ");
      } catch (Exception e) {
        // TODO Auto-generated catch block
        logger.error(e.getMessage());
        e.printStackTrace();
      }
    }
  }