Package com.simoncat.actions

Source Code of com.simoncat.actions.InstallAction

package com.simoncat.actions;

import org.apache.struts.action.*;
import javax.servlet.http.*;
import com.simoncat.beans.FinalScreenOutput;
import com.simoncat.Constants;

import  org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import java.util.List;


import org.apache.commons.fileupload.FileItem;
import java.io.File;
import java.util.Iterator;





import com.simoncat.net.HttpClient;



public final class InstallAction extends Action {

    @Override
    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response) throws Exception {

        //HttpSession session = request.getSession();

        FinalScreenOutput fso;

        if ( form != null ) {
 
            //DynaActionForm df =  (DynaActionForm) form;
            //String warName  =  (String) df.get("c1");
            //String serverId =  (String) df.get("c2");
      //System.out.println("WAR:"+ warName + " Server:" + serverId );


            //recovery war

    /*FileUploadUtils fu = new FileUploadUtils(request);
    Map<String,FileField> fileMap = fu. getFileFieldMap();
    Map<String,String> nfileMap = fu.getNonFileFieldMap();
    FileField ff = fileMap.get("fileControl");
    String fileName = nfileMap.get("fileName");
    fileName = "/home/repository/"+fileName;
  
    ff.write(fileName);*/
     
      System.out.println("AAA");
      if (ServletFileUpload.isMultipartContent(request)){
    System.out.println("BBB");
          // Parse the HTTP request...
        //ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
        //List fileItemsList = servletFileUpload.parseRequest(request);
       
        DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
        diskFileItemFactory.setSizeThreshold(140960); /* the unit is bytes */

    System.out.println("CCC");
        File repositoryPath = new File("/tmp");
        diskFileItemFactory.setRepository(repositoryPath);
    System.out.println("DDD");
        ServletFileUpload servletFileUpload = new ServletFileUpload(diskFileItemFactory);
        servletFileUpload.setSizeMax(-1);//81920); /* the unit is bytes */
        System.out.println("EEE");
        try {
       
            List fileItemsList = servletFileUpload.parseRequest(request);
        System.out.println("FFF items#"+fileItemsList.size())
            /* Process file items... */
            Iterator it = fileItemsList.iterator();
            while (it.hasNext()){
                System.out.println("GGG");     
              FileItem fileItem = (FileItem)it.next();
              if (fileItem.isFormField()){
                /* The file item contains a simple name-value pair of a form field */
                System.out.println("CAMPO NORMAL:"+fileItem.getFieldName());
              }
              else{
                /* The file item contains an uploaded file */
                System.out.println("CAMPO FILE:"+fileItem.getFieldName());
              }
            }
        System.out.println("HHH");
        }
        catch (SizeLimitExceededException ex) {
            /* The size of the HTTP request body exceeds the limit */
      System.out.println("SE DESPARRAMO POR EL TAMAÑO DEL FILE");
        }
    System.out.println("III");
       
      }
           System.out.println("JJJ");    

            //undeploy WAR in SERVER
    //recuperar los datos del server
     //Server server = new Server();

    //verificar si la aplicasion esta corriendo?
    ////http://localhost:8080/manager/list
    HttpClient hc1 = new HttpClient("localhost",8080,"tomcat","admin","");
    boolean lb = hc1.appIsRunning("Binary");
    boolean ub=false;
    boolean db=false;
    if(lb){
      // autenticar y undeploy la aplicacion en el tomcat.
      ////http://localhost:8080/manager/undeploy?path=/Binary
      String undeploy = "http://localhost:8080/manager/undeploy?path=/Binary";
           HttpClient hc2 = new HttpClient("localhost",8080,"tomcat","admin",undeploy);
       ub=hc2.execute();
    }
        //Copy WAR
    //confirmar upload 
   
    if((lb && ub) || (!lb) ){
          //Deploy WAR       
        //enviar comando al tomcat 
      ////http://localhost:8080/manager/deploy?path=/Binary&war=file:/tmp/Binary.war 
       String deploy = "http://localhost:8080/manager/deploy?path=/Binary&war=file:/tmp/Binary.war";
           HttpClient hc3 = new HttpClient("localhost",8080,"tomcat","admin",deploy);
       db=hc3.execute();
    }

    fso = new FinalScreenOutput();
          fso.setPageTitle    ("Upload-Deploy War[Finished]");

            fso.setMessage       ("WAR deployed sucessfully!"+ "It was Running:"+lb+" Undeploy:"+ub+" deploy:"+db);

        } else {
    fso = new FinalScreenOutput();
          fso.setPageTitle    ("Upload-Deploy War[NOT   Finished]");
            fso.setMessage       ("Sorry, problem with submitted form!");
        }

        if (Constants.xmlOutputOnly) {
            request.setAttribute ("content", Constants.xmlContentType);
        } else {
            request.setAttribute ("content", Constants.htmlContentType);
            request.setAttribute ("style", "confirmWar.xsl");
        }
        request.setAttribute ("form", fso);

        return (mapping.findForward(Constants.XMLHandler));
     }

}
TOP

Related Classes of com.simoncat.actions.InstallAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.