Esempio n. 1
0
 public void testConfig() throws Exception {
   MuleVisualizerPlugin plugin = new MuleVisualizerPlugin();
   String config = getXmlConfig();
   String path = FileUtils.getResourcePath(config, getClass());
   assertNotNull("missing config path: " + config, path);
   plugin.setFiles(Arrays.asList(new String[] {path}));
   plugin.setOutputdir(FileUtils.getResourcePath("target", getClass()));
   plugin.execute();
 }
Esempio n. 2
0
  /**
   * This is something of a hack. Velocity loads files relative to the property
   * VelocityEngine.FILE_RESOURCE_LOADER_PATH. So if we can find the template ourselves then we can
   * infer what the property value should be so that velocity works ok.
   */
  private void inferVelocityLoaderPath(VelocityEngine ve) throws IOException {
    String defaultPath = (String) ve.getProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH);
    if (null == defaultPath || StringUtils.isEmpty(defaultPath)) {
      URL url = IOUtils.getResourceAsUrl(MuleDocPostRenderer.DEFAULT_MULE_TEMPLATE, getClass());
      if (FILE.equals(url.getProtocol())) {
        String path =
            FileUtils.getResourcePath(MuleDocPostRenderer.DEFAULT_MULE_TEMPLATE, getClass());
        if (!StringUtils.isEmpty(path)) {
          File fullPath = new File(path);
          File target = new File(MuleDocPostRenderer.DEFAULT_MULE_TEMPLATE);

          // drop trailing files until we are at the relative parent
          while (null != target && !StringUtils.isEmpty(target.getPath())) {
            env.log(fullPath.getPath() + " - " + target.getPath());
            target = target.getParentFile();
            fullPath = fullPath.getParentFile();
          }

          path = fullPath.getPath();
          if (path.endsWith("!")) {
            path = path + File.separator;
          }
          getEnv().log(VelocityEngine.FILE_RESOURCE_LOADER_PATH + " = " + path);
          ve.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, path);
        }
      } else if (JAR.equals(url.getProtocol())) {
        env.log(url.toString());
        ve.setProperty(VelocityEngine.RESOURCE_LOADER, "class");
        ve.setProperty(MAGIC_VELOCITY_RESOURCE_LOADER, ClasspathResourceLoader.class.getName());
      }
    }
  }
Esempio n. 3
0
 public void setTrustStore(String trustStore) throws IOException {
   this.trustStore = trustStore;
   if (this.trustStore != null) {
     this.trustStore = FileUtils.getResourcePath(trustStore, getClass());
     logger.debug("Normalised trustStore path to: " + getTrustStore());
   }
 }
Esempio n. 4
0
 public void setClientKeyStore(String clientKeyStore) throws IOException {
   this.clientKeyStore = clientKeyStore;
   if (this.clientKeyStore != null) {
     this.clientKeyStore = FileUtils.getResourcePath(clientKeyStore, getClass());
     logger.debug("Normalised clientKeyStore path to: " + getClientKeyStore());
   }
 }
Esempio n. 5
0
 public void setTrustStore(String name) throws IOException {
   trustStoreName = name;
   if (null != trustStoreName) {
     trustStoreName = FileUtils.getResourcePath(trustStoreName, getClass());
     if (logger.isDebugEnabled()) {
       logger.debug("Normalised trustStore path to: " + trustStoreName);
     }
   }
 }
Esempio n. 6
0
 public void setClientKeyStore(String name) throws IOException {
   clientKeyStoreName = name;
   if (null != clientKeyStoreName) {
     clientKeyStoreName = FileUtils.getResourcePath(clientKeyStoreName, getClass());
     if (logger.isDebugEnabled()) {
       logger.debug("Normalised clientKeyStore path to: " + clientKeyStoreName);
     }
   }
 }
Esempio n. 7
0
  public void doInitialise() throws InitialisationException {
    if (getProvider() == null) {
      throw new NullPointerException("The security provider cannot be null");
    }
    if (getKeyStore() != null) {
      if (getKeyPassword() == null) {
        throw new NullPointerException("The Key password cannot be null");
      }
      if (getStorePassword() == null) {
        throw new NullPointerException("The KeyStore password cannot be null");
      }
      if (getKeyManagerAlgorithm() == null) {
        throw new NullPointerException("The Key Manager Algorithm cannot be null");
      }
      if (getKeyStoreType() == null) {
        throw new NullPointerException("The KeyStore type cannot be null");
      }
    }

    if (getKeyStore() != null) {
      KeyStore keystore;
      try {
        Security.addProvider(getProvider());
        // Create keyStore
        keystore = KeyStore.getInstance(keyStoreType);
        InputStream is = IOUtils.getResourceAsStream(getKeyStore(), getClass());
        if (is == null) {
          throw new FileNotFoundException(
              "Failed to load keystore from classpath or local file: " + getKeyStore());
        }
        keystore.load(is, getKeyPassword().toCharArray());
      } catch (Exception e) {
        throw new InitialisationException(
            new Message(Messages.FAILED_LOAD_X, "KeyStore: " + getKeyStore()), e, this);
      }
      try {
        // Get key manager
        keyManagerFactory = KeyManagerFactory.getInstance(getKeyManagerAlgorithm());
        // Initialize the KeyManagerFactory to work with our keyStore
        keyManagerFactory.init(keystore, getStorePassword().toCharArray());
      } catch (Exception e) {
        throw new InitialisationException(
            new Message(Messages.FAILED_LOAD_X, "Key Manager (" + getKeyManagerAlgorithm() + ")"),
            e,
            this);
      }
    }

    if (getTrustStore() != null) {
      KeyStore truststore;
      try {
        truststore = KeyStore.getInstance(trustStoreType);
        InputStream is = IOUtils.getResourceAsStream(getTrustStore(), getClass());
        if (is == null) {
          throw new FileNotFoundException(
              "Failed to load truststore from classpath or local file: " + getTrustStore());
        }
        truststore.load(is, getTrustStorePassword().toCharArray());
      } catch (Exception e) {
        throw new InitialisationException(
            new Message(Messages.FAILED_LOAD_X, "TrustStore: " + getTrustStore()), e, this);
      }

      try {
        trustManagerFactory = TrustManagerFactory.getInstance(getTrustManagerAlgorithm());
        trustManagerFactory.init(truststore);
      } catch (Exception e) {
        throw new InitialisationException(
            new Message(
                Messages.FAILED_LOAD_X, "Trust Manager (" + getTrustManagerAlgorithm() + ")"),
            e,
            this);
      }
    }

    super.doInitialise();

    if (protocolHandler != null) {
      System.setProperty("java.protocol.handler.pkgs", protocolHandler);
    }
    if (clientKeyStore != null) {
      try {
        String clientPath = FileUtils.getResourcePath(clientKeyStore, getClass());
        System.setProperty("javax.net.ssl.keyStore", clientPath);
        System.setProperty("javax.net.ssl.keyStorePassword", clientKeyStorePassword);

        logger.info("Set Client Key store: javax.net.ssl.keyStore=" + clientPath);
      } catch (IOException e) {
        throw new InitialisationException(
            new Message(Messages.FAILED_LOAD_X, "Client KeyStore: " + clientKeyStore), e, this);
      }
    }

    if (trustStore != null) {
      System.setProperty("javax.net.ssl.trustStore", getTrustStore());
      System.setProperty("javax.net.ssl.trustStorePassword", getTrustStorePassword());
      logger.debug("Set Trust store: javax.net.ssl.trustStore=" + getTrustStore());
    } else if (!isExplicitTrustStoreOnly()) {
      logger.info("Defaulting trust store to client Key Store");
      trustStore = getClientKeyStore();
      trustStorePassword = getClientKeyStorePassword();
      System.setProperty("javax.net.ssl.trustStore", getTrustStore());
      System.setProperty("javax.net.ssl.trustStorePassword", getTrustStorePassword());
      logger.debug("Set Trust store: javax.net.ssl.trustStore=" + getTrustStore());
    }
  }