示例#1
0
 @Override
 public void run() {
   try {
     IOTools.flow(is, baos);
   } catch (IOException e) {
     // Ignore
   }
 }
示例#2
0
  /** @see SSICommand */
  public void process(
      SSIMediator ssiMediator, String[] paramNames, String[] paramValues, PrintWriter writer) {

    String configErrMsg = ssiMediator.getConfigErrMsg();
    String paramName = paramNames[0];
    String paramValue = paramValues[0];

    if (paramName.equalsIgnoreCase("cgi")) {
      ssiInclude.process(ssiMediator, new String[] {"virtual"}, new String[] {paramValue}, writer);
    } else if (paramName.equalsIgnoreCase("cmd")) {
      boolean foundProgram = false;
      try {
        Runtime rt = Runtime.getRuntime();
        Process proc = rt.exec(paramValue);
        foundProgram = true;

        BufferedReader stdOutReader =
            new BufferedReader(new InputStreamReader(proc.getInputStream()));
        BufferedReader stdErrReader =
            new BufferedReader(new InputStreamReader(proc.getErrorStream()));

        char[] buf = new char[BUFFER_SIZE];
        IOTools.flow(stdErrReader, writer, buf);
        IOTools.flow(stdOutReader, writer, buf);
        proc.waitFor();
      } catch (InterruptedException e) {
        ssiMediator.log("Couldn't exec file: " + paramValue, e);
        writer.write(configErrMsg);
      } catch (IOException e) {
        if (!foundProgram) {
          // apache doesn't output an error message if it can't find a program
        }
        ssiMediator.log("Couldn't exec file: " + paramValue, e);
      }
    }
  }
示例#3
0
  /**
   * @param contextPath
   * @param dir
   * @param file
   */
  protected void deployDirectory(String contextPath, File dir, String file) {
    DeployedApplication deployedApp = new DeployedApplication(contextPath);

    if (deploymentExists(contextPath)) return;

    // Deploy the application in this directory
    if (log.isInfoEnabled()) log.info(sm.getString("hostConfig.deployDir", file));
    try {
      Context context = null;
      File xml = new File(dir, Constants.ApplicationContextXml);
      File xmlCopy = null;
      if (deployXML && xml.exists()) {
        // Will only do this on initial deployment. On subsequent
        // deployments the copied xml file means we'll use
        // deployDescriptor() instead
        synchronized (digester) {
          try {
            context = (Context) digester.parse(xml);
            if (context == null) {
              log.error(sm.getString("hostConfig.deployDescriptor.error", xml));
              return;
            }
          } finally {
            digester.reset();
          }
        }
        configBase.mkdirs();
        xmlCopy = new File(configBase, file + ".xml");
        InputStream is = null;
        OutputStream os = null;
        try {
          is = new FileInputStream(xml);
          os = new FileOutputStream(xmlCopy);
          IOTools.flow(is, os);
          // Don't catch IOE - let the outer try/catch handle it
        } finally {
          try {
            if (is != null) is.close();
          } catch (IOException e) {
            // Ignore
          }
          try {
            if (os != null) os.close();
          } catch (IOException e) {
            // Ignore
          }
        }
        context.setConfigFile(xmlCopy.getAbsolutePath());
      } else {
        context = (Context) Class.forName(contextClass).newInstance();
      }

      if (context instanceof Lifecycle) {
        Class clazz = Class.forName(host.getConfigClass());
        LifecycleListener listener = (LifecycleListener) clazz.newInstance();
        ((Lifecycle) context).addLifecycleListener(listener);
      }
      context.setPath(contextPath);
      context.setDocBase(file);
      host.addChild(context);
      deployedApp.redeployResources.put(dir.getAbsolutePath(), new Long(dir.lastModified()));
      if (xmlCopy != null) {
        deployedApp.redeployResources.put(
            xmlCopy.getAbsolutePath(), new Long(xmlCopy.lastModified()));
      }
      addWatchedResources(deployedApp, dir.getAbsolutePath(), context);
    } catch (Throwable t) {
      log.error(sm.getString("hostConfig.deployDir.error", file), t);
    }

    deployed.put(contextPath, deployedApp);
  }