FileDocCategorySizeDatePackage
AdminClientTask.javaAPI DocApache Axis 1.413544Sat Apr 22 18:57:28 BST 2006org.apache.axis.tools.ant.axis

AdminClientTask

public class AdminClientTask extends org.apache.tools.ant.taskdefs.MatchingTask
Task to administer a local or remote Axis server. Remember, for remote admin, the server has to be accept remote management calls.
ant.task
category="axis" name="axis-admin"

Fields Summary
private boolean
failOnError
flag to control action on execution trouble
private String
hostname
private int
port
private String
servletPath
private File
srcDir
private File
xmlFile
private String
transportChain
private String
username
private String
password
private String
fileProtocol
private String
action
private String
url
private boolean
debug
private String
newPassword
private LinkedList
argslist
private boolean
fork
private org.apache.tools.ant.types.Path
classpath
Constructors Summary
Methods Summary
protected voidaddArg(java.lang.String argument)
add one arg

param
argument

        argslist.add(argument);
    
protected voidaddArg(java.lang.String argument, boolean test)
add one arg

param
argument

        if (test) {
            argslist.add(argument);
        }
    
protected voidaddArgs(java.lang.String argument, java.lang.String param)
add an arg pair

param
argument
param
param

        addArg(argument);
        addArg(param);
    
protected voidaddArgs(java.lang.String argument, java.lang.String param, boolean test)
add an arg pair if the test is true

param
argument first arg
param
param param to accompany
param
test test to trigger argument add

        if (test) {
            addArg(argument);
            addArg(param);
        }
    
public org.apache.tools.ant.types.PathcreateClasspath()
Set the optional classpath

return
a path instance to be configured by the Ant core.

        if (classpath == null) {
            classpath = new Path(getProject());
        }
        return classpath.createPath();
    
public voidexecute()

Processes a set of administration commands.

The following commands are available:

  • -lurl sets the AxisServlet URL
  • -hhostName sets the AxisServlet host
  • -pportNumber sets the AxisServlet port
  • -sservletPath sets the path to the AxisServlet
  • -ffileName specifies that a simple file protocol should be used
  • -uusername sets the username
  • -wpassword sets the password
  • -d sets the debug flag (for instance, -ddd would set it to 3)
  • -tname sets the transport chain touse
  • list will list the currently deployed services
  • quit will quit (???)
  • passwd value changes the admin password
  • xmlConfigFile deploys or undeploys Axis components and web services

If -l or -h -p -s are not set, the AdminClient will invoke http://localhost:8080/axis/servlet/AxisServlet.

outputs XML result or null in case of failure. In the case of multiple commands, the XML results will be concatenated, separated by \n

throws
BuildException something went wrong

        traceParams(Project.MSG_VERBOSE);
        validate();
        argslist = new LinkedList();

        //build an array of args
        addArgs("-l", url, url != null);
        addArgs("-h", hostname, hostname != null);
        addArgs("-p", Integer.toString(port), port != 0);
        addArgs("-s", servletPath, servletPath != null);
        addArgs("-f", fileProtocol, fileProtocol != null);
        addArgs("-u", username, username != null);
        addArgs("-w", password, password != null);
        addArgs("-t", transportChain, transportChain != null);
        addArg("-d", debug);
        //action
        addArg(action, action != null);
        //action extras
        if ("passwd".equals(action)) {
            if (newPassword == null) {
                throw new BuildException("No newpassword set for passwd");
            }
            addArg(newPassword);
        } else {
            if (newPassword != null) {
                throw new BuildException(
                        "newpassword is only used when action=passwd");
            }
        }

        //final param is the xml file(s)
        if (xmlFile != null) {
            if (!xmlFile.exists()) {
                throw new BuildException("File " + xmlFile + " no found");
            }
            addArg(xmlFile.toString());
        }
        if (srcDir != null) {
            DirectoryScanner ds = super.getDirectoryScanner(srcDir);
            String[] files = ds.getIncludedFiles();
            for (int i = 0; i < files.length; i++) {
                File srcFile = new File(srcDir, files[i]);
                if (!srcFile.exists()) {
                    throw new BuildException("File " + srcFile + " no found");
                }
                addArg(srcFile.getAbsolutePath());
            }
        }
        
        //turn the list into an array
        int counter = 0;
        String[] args = new String[argslist.size()];
        Iterator it = argslist.iterator();
        while (it.hasNext()) {
            String arg = (String) it.next();
            args[counter] = arg;
            counter++;
        }
        if (fork) {
            executeInForkedVM(args);
        } else {
            executeInCurrentVM(args);
        }
    
private voidexecuteInCurrentVM(java.lang.String[] args)

        //now create a client and invoke it
        AdminClient admin = null;
        try {
            admin = new AdminClient(true);
        } catch (ServiceException e) {
            throw new BuildException("failed to start the axis engine", e);
        }
        String result = null;
        try {
            result = admin.process(args);
            if (result != null) {
                log(result);
            } else {
                logOrThrow(getTaskName() + " got a null response");
            }
        } catch (AxisFault fault) {
            log(fault.dumpToString(), Project.MSG_ERR);
            traceParams(Project.MSG_ERR);
            logOrThrow(getTaskName()
                    + " failed with  "
                    + fault.getFaultCode().toString()
                    + " " + fault.getFaultString());
        } catch (BuildException e) {
            //rethrow these
            throw e;
        } catch (Exception e) {
            throw new BuildException("Exception in " + getTaskName(), e);
        }
    
private voidexecuteInForkedVM(java.lang.String[] args)

        try {
            // Create an instance of the compiler, redirecting output to
            // the project log
            Java java = (Java) (getProject().createTask("java"));
            getProject().log("using classpath: " + classpath,
                    Project.MSG_DEBUG);
            java.setClasspath(classpath);
            java.setClassname("org.apache.axis.client.AdminClient");
            for (int i = 0; i < args.length; i++) {
                java.createArg().setValue(args[i]);
            }
            java.setFailonerror(failOnError);
            //we are forking here to be sure that if AdminClient calls
            //System.exit() it doesn't halt the build
            java.setFork(true);
            java.setTaskName("AdminClient");
            java.execute();
        } catch (BuildException e) {
            //rethrow these
            throw e;
        } catch (Exception e) {
            throw new BuildException("Exception in " + getTaskName(), e);
        }
    
private voidlogOrThrow(java.lang.String text)

        if (failOnError) {
            throw new BuildException(text);
        } else {
            log(text, Project.MSG_ERR);
        }
    
public voidsetClasspath(org.apache.tools.ant.types.Path classpath)
Set the optional classpath

param
classpath the classpath to use when loading class

        createClasspath().append(classpath);
    
public voidsetClasspathRef(org.apache.tools.ant.types.Reference r)
Set the reference to an optional classpath

param
r the id of the Ant path instance to act as the classpath

        createClasspath().setRefid(r);
    
public voidsetDebug(boolean debug)
set a debug flag

param
debug


               
        
        this.debug = debug;
    
public voidsetFailOnError(boolean fail)
Whether or not the build should halt if this task fails. Defaults to true.

        failOnError = fail;
    
public voidsetFileProtocol(java.lang.String fileProtocol)
specifies that a simple file protocol be used

param
fileProtocol

        this.fileProtocol = fileProtocol;
    
public voidsetFork(boolean f)
If true, forks the ant invocation.

param
f "true|false|on|off|yes|no"

        fork = f;
    
public voidsetHostname(java.lang.String hostname)
name the host to admin

param
hostname

        this.hostname = hostname;
    
public voidsetNewPassword(java.lang.String newPassword)
set a new password; only valid if action=passwd

param
newPassword

        this.newPassword = newPassword;
    
public voidsetPassword(java.lang.String password)
the admin password

param
password

        this.password = password;
    
public voidsetPort(int port)
the port to connect to

param
port

        this.port = port;
    
public voidsetServletPath(java.lang.String servletPath)
the path to the AxisAdmin servlet

param
servletPath

        this.servletPath = servletPath;
    
public voidsetSrcdir(java.io.File srcDir)
Set the source dir to find the source text files.

        this.srcDir = srcDir;
    
public voidsetTransportChain(java.lang.String transportChain)
set the transport chain to use

param
transportChain

        this.transportChain = transportChain;
    
public voidsetUrl(java.lang.String url)
full url to the admin endpoint

param
url

        this.url = url;
    
public voidsetUsername(java.lang.String username)
username to log in as

param
username

        this.username = username;
    
public voidsetXmlFile(java.io.File xmlFile)
the name of the XML file containing deployment information

param
xmlFile

        this.xmlFile = xmlFile;
    
public voidtraceParams(int logLevel)
trace out parameters

param
logLevel to log at
see
org.apache.tools.ant.Project#log

        log("Running axis-admin with parameters:", logLevel);
        log("  action:" + action, logLevel);
        log("  url:" + url, logLevel);
        log("  hostname:" + hostname, logLevel);
        log("  port:" + port, logLevel);
        log("  servletPath:" + servletPath, logLevel);
        log("  fileProtocol:" + fileProtocol, logLevel);
        log("  username:" + username, logLevel);
        log("  password:" + password, logLevel);
        log("  transportChain:" + transportChain, logLevel);
        log("  debug:" + debug, logLevel);
    
protected voidvalidate()
validation code

throws
org.apache.tools.ant.BuildException if validation failed

        if (srcDir != null) {
            if (!srcDir.exists()) {
                throw new BuildException("srcdir does not exist!");
            }
            if (!srcDir.isDirectory()) {
                throw new BuildException("srcdir is not a directory!");
            }
        }