protected void deploy(HttpServletResponse response,String contextPath,String warURL) throws IOException {
  String context=contextPath;
  boolean error=false;
  if (context == null) {
    File file=new File(warURL);
    String fileName=file.getName();
    if (fileName.endsWith(".war")) {
      fileName=fileName.substring(0,fileName.lastIndexOf(".war"));
    }
    context="/" + fileName;
  }
  if (getContextHandler(context) != null) {
    sendError(response,"An application is already deployed at this context : " + context);
    error=true;
  }
 else   if (!context.startsWith("/")) {
    sendError(response,"The path does not start with a forward slash");
    error=true;
  }
  if (error) {
    return;
  }
 else {
    File webappDest=new File(webAppDirectory,context + ".war");
    URI uri=null;
    try {
      uri=new URI(warURL);
    }
 catch (    URISyntaxException e) {
      sendError(response,"Cannot parse URL " + warURL);
      Log.warn(e);
      return;
    }
    File webappSource=new File(uri);
    FileInputStream fileInputStream=new FileInputStream(webappSource);
    FileOutputStream fileOutputStream=new FileOutputStream(webappDest);
    int i=fileInputStream.read();
    while (i != -1) {
      fileOutputStream.write(i);
      i=fileInputStream.read();
    }
    fileInputStream.close();
    fileOutputStream.flush();
    fileOutputStream.close();
    WebAppContext webappcontext=new WebAppContext();
    webappcontext.setContextPath(context);
    webappcontext.setWar(webappDest.getPath());
    chc.addHandler(webappcontext);
    try {
      webappcontext.start();
    }
 catch (    Exception e) {
      sendError(response,"Unexpected error when trying to start the webapp");
      Log.warn(e);
      return;
    }
  }
  sendMessage(response,"Webapp deployed at context " + contextPath);
}

protected void deploy ( HttpServletResponse response , String contextPath , String warURL ) throws IOException { String context = contextPath ; boolean error = false ; if ( context == null ) { File file = new File ( warURL ) ; String fileName = file . getName ( ) ; if ( fileName . endsWith ( ".war" ) ) { fileName = fileName . substring ( 0 , fileName . lastIndexOf ( ".war" ) ) ; } context = "/" + fileName ; } if ( getContextHandler ( context ) != null ) { sendError ( response , "An application is already deployed at this context : " + context ) ; error = true ; } else if ( ! context . startsWith ( "/" ) ) { sendError ( response , "The path does not start with a forward slash" ) ; error = true ; } if ( error ) { return ; } else { File webappDest = new File ( webAppDirectory , context + ".war" ) ; URI uri = null ; try { uri = new URI ( warURL ) ; } catch ( URISyntaxException e ) { sendError ( response , "Cannot parse URL " + warURL ) ; Log . warn ( e ) ; return ; } File webappSource = new File ( uri ) ; FileInputStream fileInputStream = new FileInputStream ( webappSource ) ; FileOutputStream fileOutputStream = new FileOutputStream ( webappDest ) ; int i = fileInputStream . read ( ) ; while ( i != - 1 ) { fileOutputStream . write ( i ) ; i = fileInputStream . read ( ) ; } fileInputStream . close ( ) ; fileOutputStream . flush ( ) ; fileOutputStream . close ( ) ; WebAppContext webappcontext = new WebAppContext ( ) ; webappcontext . setContextPath ( context ) ; webappcontext . setWar ( webappDest . getPath ( ) ) ; chc . addHandler ( webappcontext ) ; try { webappcontext . start ( ) ; } catch ( Exception e ) { sendError ( response , "Unexpected error when trying to start the webapp" ) ; Log . warn ( e ) ; return ; } } sendMessage ( response , "Webapp deployed at context " + contextPath ) ; }
deploy the war to the given context path .
