extract WS interfaces
git-svn-id: https://brutex.net/svn/xservices/trunk@46 e7e49efb-446e-492e-b9ec-fcafc1997a86tag-20130205r
parent
64cced1731
commit
5644a7ba99
|
@ -15,32 +15,23 @@
|
||||||
*/
|
*/
|
||||||
package net.brutex.xservices.ws;
|
package net.brutex.xservices.ws;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Map;
|
|
||||||
import javax.jws.WebMethod;
|
import javax.jws.WebMethod;
|
||||||
import javax.jws.WebParam;
|
import javax.jws.WebParam;
|
||||||
import javax.jws.WebService;
|
import javax.jws.WebService;
|
||||||
import net.brutex.xservices.types.ArchiveResource;
|
import net.brutex.xservices.types.ArchiveResource;
|
||||||
import net.brutex.xservices.types.CompressionType;
|
import net.brutex.xservices.types.CompressionType;
|
||||||
import net.brutex.xservices.types.FileResource;
|
import net.brutex.xservices.types.FileResource;
|
||||||
import net.brutex.xservices.types.ResourceInterface;
|
|
||||||
import net.brutex.xservices.types.ReturnCode;
|
import net.brutex.xservices.types.ReturnCode;
|
||||||
import net.brutex.xservices.util.RunTask;
|
import net.brutex.xservices.util.BrutexNamespaces;
|
||||||
import net.brutex.xservices.util.UnRarTask;
|
|
||||||
import org.apache.tools.ant.taskdefs.BUnzip2;
|
|
||||||
import org.apache.tools.ant.taskdefs.BZip2;
|
|
||||||
import org.apache.tools.ant.taskdefs.Expand;
|
|
||||||
import org.apache.tools.ant.taskdefs.GUnzip;
|
|
||||||
import org.apache.tools.ant.taskdefs.GZip;
|
|
||||||
import org.apache.tools.ant.taskdefs.Untar;
|
|
||||||
import org.apache.tools.ant.taskdefs.Zip;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Brian Rosenberger, bru@brutex.de
|
* @author Brian Rosenberger, bru@brutex.de
|
||||||
*/
|
*/
|
||||||
@WebService(targetNamespace = "http://ws.xservices.brutex.net", name = "ArchiveService")
|
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES)
|
||||||
public class ArchiveService {
|
public interface ArchiveService {
|
||||||
|
|
||||||
public static final String WS_OPERATION_BZIP2 = "bzip2";
|
public static final String WS_OPERATION_BZIP2 = "bzip2";
|
||||||
public static final String WS_OPERATION_BZIP2_ARCHIVE = "bzip2FromArchive";
|
public static final String WS_OPERATION_BZIP2_ARCHIVE = "bzip2FromArchive";
|
||||||
|
@ -60,225 +51,63 @@ public class ArchiveService {
|
||||||
|
|
||||||
@WebMethod(operationName = WS_OPERATION_BZIP2, action = WS_OPERATION_BZIP2)
|
@WebMethod(operationName = WS_OPERATION_BZIP2, action = WS_OPERATION_BZIP2)
|
||||||
public ReturnCode bzip2(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
|
public ReturnCode bzip2(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
|
||||||
@WebParam(name = WS_PARAM_DESTFILE) String file) {
|
@WebParam(name = WS_PARAM_DESTFILE) String file);
|
||||||
return bzip(src, new File(file));
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(operationName = WS_OPERATION_BZIP2_ARCHIVE, action = WS_OPERATION_BZIP2_ARCHIVE)
|
@WebMethod(operationName = WS_OPERATION_BZIP2_ARCHIVE, action = WS_OPERATION_BZIP2_ARCHIVE)
|
||||||
public ReturnCode bzip2FromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
|
public ReturnCode bzip2FromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
|
||||||
@WebParam(name = WS_PARAM_DESTFILE) String file) {
|
@WebParam(name = WS_PARAM_DESTFILE) String file);
|
||||||
return bzip(src, new File(file));
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(operationName = WS_OPERATION_GZIP, action = WS_OPERATION_GZIP)
|
@WebMethod(operationName = WS_OPERATION_GZIP, action = WS_OPERATION_GZIP)
|
||||||
public ReturnCode gzip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
|
public ReturnCode gzip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
|
||||||
@WebParam(name = WS_PARAM_DESTFILE) String file) {
|
@WebParam(name = WS_PARAM_DESTFILE) String file);
|
||||||
return gzip(src, new File(file));
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(operationName = WS_OPERATION_GZIP_ARCHIVE, action = WS_OPERATION_GZIP_ARCHIVE)
|
@WebMethod(operationName = WS_OPERATION_GZIP_ARCHIVE, action = WS_OPERATION_GZIP_ARCHIVE)
|
||||||
public ReturnCode gzipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
|
public ReturnCode gzipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
|
||||||
@WebParam(name = WS_PARAM_DESTFILE) String file) {
|
@WebParam(name = WS_PARAM_DESTFILE) String file);
|
||||||
return gzip(src, new File(file));
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(operationName = WS_OPERATION_GUNZIP, action = WS_OPERATION_GUNZIP)
|
@WebMethod(operationName = WS_OPERATION_GUNZIP, action = WS_OPERATION_GUNZIP)
|
||||||
public ReturnCode gunzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
|
public ReturnCode gunzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
|
||||||
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
|
@WebParam(name = WS_PARAM_DESTDIR) String dest);
|
||||||
File target = null;
|
|
||||||
if (!dest.equals("") && dest != null) {
|
|
||||||
target = new File(dest);
|
|
||||||
}
|
|
||||||
return GUnzip(new FileResource(FileResource.Type.FILE, src), target);
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(operationName = WS_OPERATION_BUNZIP2)
|
@WebMethod(operationName = WS_OPERATION_BUNZIP2)
|
||||||
public ReturnCode bunzip2(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
|
public ReturnCode bunzip2(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
|
||||||
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
|
@WebParam(name = WS_PARAM_DESTDIR) String dest);
|
||||||
File target = null;
|
|
||||||
if (!dest.equals("") && dest != null) {
|
|
||||||
target = new File(dest);
|
|
||||||
}
|
|
||||||
return BUnzip2(new FileResource(FileResource.Type.FILE, src), target);
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(operationName = "gunzipFromURL")
|
@WebMethod(operationName = "gunzipFromURL")
|
||||||
public ReturnCode gunzipFromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src,
|
public ReturnCode gunzipFromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src,
|
||||||
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
|
@WebParam(name = WS_PARAM_DESTDIR) String dest);
|
||||||
File target = null;
|
|
||||||
if (!dest.equals("") && dest != null) {
|
|
||||||
target = new File(dest);
|
|
||||||
}
|
|
||||||
return GUnzip(new FileResource(FileResource.Type.URL, src), target);
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(operationName = "bunzip2FromURL")
|
@WebMethod(operationName = "bunzip2FromURL")
|
||||||
public ReturnCode bunzip2FromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src,
|
public ReturnCode bunzip2FromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src,
|
||||||
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
|
@WebParam(name = WS_PARAM_DESTDIR) String dest);
|
||||||
File target = null;
|
|
||||||
if (!dest.equals("") && dest != null) {
|
|
||||||
target = new File(dest);
|
|
||||||
}
|
|
||||||
return BUnzip2(new FileResource(FileResource.Type.URL, src), target);
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(operationName = "zip")
|
@WebMethod(operationName = "zip")
|
||||||
public ReturnCode zip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
|
public ReturnCode zip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
|
||||||
@WebParam(name = WS_PARAM_DESTFILE) String file,
|
@WebParam(name = WS_PARAM_DESTFILE) String file,
|
||||||
@WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite,
|
@WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite,
|
||||||
@WebParam(name = WS_PARAM_ENCODING) String encoding,
|
@WebParam(name = WS_PARAM_ENCODING) String encoding,
|
||||||
@WebParam(name = "compresslevel") int level) {
|
@WebParam(name = "compresslevel") int level);
|
||||||
if (level > 9) {
|
|
||||||
level = 9;
|
|
||||||
}
|
|
||||||
if (level < 0) {
|
|
||||||
level = 0;
|
|
||||||
}
|
|
||||||
return zip(src, new File(file), encoding, !overwrite, level);
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(operationName = "zipFromArchive")
|
@WebMethod(operationName = "zipFromArchive")
|
||||||
public ReturnCode zipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
|
public ReturnCode zipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
|
||||||
@WebParam(name = WS_PARAM_DESTFILE) String file,
|
@WebParam(name = WS_PARAM_DESTFILE) String file,
|
||||||
@WebParam(name = WS_PARAM_OVERWRITE) boolean update,
|
@WebParam(name = WS_PARAM_OVERWRITE) boolean update,
|
||||||
@WebParam(name = WS_PARAM_ENCODING) String encoding,
|
@WebParam(name = WS_PARAM_ENCODING) String encoding,
|
||||||
@WebParam(name = "compresslevel") int level) {
|
@WebParam(name = "compresslevel") int level);
|
||||||
return zip(src, new File(file), encoding, !update, level);
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(operationName = "unzip")
|
@WebMethod(operationName = "unzip")
|
||||||
public ReturnCode unzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
|
public ReturnCode unzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
|
||||||
@WebParam(name = WS_PARAM_DESTDIR) String dest,
|
@WebParam(name = WS_PARAM_DESTDIR) String dest,
|
||||||
@WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite,
|
@WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite,
|
||||||
@WebParam(name = WS_PARAM_ENCODING) String encoding) {
|
@WebParam(name = WS_PARAM_ENCODING) String encoding);
|
||||||
return unzip(new File(src), new File(dest), overwrite, encoding);
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(operationName = "unrar")
|
@WebMethod(operationName = "unrar")
|
||||||
public ReturnCode unrar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
|
public ReturnCode unrar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
|
||||||
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
|
@WebParam(name = WS_PARAM_DESTDIR) String dest);
|
||||||
return unrar(new File(src), new File(dest));
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(operationName = "untar")
|
@WebMethod(operationName = "untar")
|
||||||
public ReturnCode untar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
|
public ReturnCode untar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
|
||||||
@WebParam(name = WS_PARAM_DESTDIR) String dest,
|
@WebParam(name = WS_PARAM_DESTDIR) String dest,
|
||||||
@WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite,
|
@WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite,
|
||||||
@WebParam(name = "compression") CompressionType compression) {
|
@WebParam(name = "compression") CompressionType compression);
|
||||||
Untar.UntarCompressionMethod c = new Untar.UntarCompressionMethod();
|
|
||||||
switch (compression) {
|
|
||||||
case GZIP:
|
|
||||||
c.setValue("gzip");
|
|
||||||
break;
|
|
||||||
case BZIP2:
|
|
||||||
c.setValue("bzip2");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
c.setValue("none");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return untar(new File(src), new File(dest), overwrite, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
|
||||||
private ReturnCode bzip(ResourceInterface src, File dst) {
|
|
||||||
if (dst.exists() && dst.isFile()) {
|
|
||||||
dst.delete();
|
|
||||||
}
|
|
||||||
BZip2 bzip = new BZip2();
|
|
||||||
bzip.setTaskName("BZip2");
|
|
||||||
RunTask runner = new RunTask(bzip);
|
|
||||||
bzip.setSrcResource(src.getAntResource(bzip.getProject()));
|
|
||||||
bzip.setDestfile(dst);
|
|
||||||
|
|
||||||
return runner.postTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
|
||||||
private ReturnCode gzip(ResourceInterface src, File dst) {
|
|
||||||
if (dst.exists() && dst.isFile()) {
|
|
||||||
dst.delete();
|
|
||||||
}
|
|
||||||
GZip gzip = new GZip();
|
|
||||||
gzip.setTaskName("GZip");
|
|
||||||
RunTask runner = new RunTask(gzip);
|
|
||||||
gzip.addConfigured(src.getAntResource(gzip.getProject()));
|
|
||||||
gzip.setDestfile(dst);
|
|
||||||
return runner.postTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
|
||||||
private ReturnCode zip(ResourceInterface src, File dst, String encoding, boolean update, int compresslevel) {
|
|
||||||
Zip zip = new Zip();
|
|
||||||
zip.setTaskName("Zip");
|
|
||||||
RunTask runner = new RunTask(zip);
|
|
||||||
zip.add(src.getAntResource(zip.getProject()));
|
|
||||||
zip.setDestFile(dst);
|
|
||||||
if (encoding != null && !encoding.equals("")) {
|
|
||||||
zip.setEncoding(encoding);
|
|
||||||
}
|
|
||||||
zip.setUpdate(update);
|
|
||||||
zip.setLevel(compresslevel);
|
|
||||||
return runner.postTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
|
||||||
private ReturnCode GUnzip(ResourceInterface src, File dst) {
|
|
||||||
GUnzip uz = new GUnzip();
|
|
||||||
uz.setTaskName("GUnzip");
|
|
||||||
RunTask runner = new RunTask(uz);
|
|
||||||
uz.setSrcResource(src.getAntResource(uz.getProject()));
|
|
||||||
if (dst != null) {
|
|
||||||
uz.setDest(dst);
|
|
||||||
}
|
|
||||||
return runner.postTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
|
||||||
private ReturnCode BUnzip2(ResourceInterface src, File dst) {
|
|
||||||
BUnzip2 uz = new BUnzip2();
|
|
||||||
uz.setTaskName("BUnzip2");
|
|
||||||
RunTask runner = new RunTask(uz);
|
|
||||||
uz.setSrcResource(src.getAntResource(uz.getProject()));
|
|
||||||
if (dst != null) {
|
|
||||||
uz.setDest(dst);
|
|
||||||
}
|
|
||||||
return runner.postTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
|
||||||
private ReturnCode unzip(File src, File dest, boolean overwrite, String encoding) {
|
|
||||||
Expand unzip = new Expand();
|
|
||||||
unzip.setTaskName("UnZip");
|
|
||||||
RunTask runner = new RunTask(unzip);
|
|
||||||
unzip.setSrc(src);
|
|
||||||
unzip.setDest(dest);
|
|
||||||
unzip.setOverwrite(overwrite);
|
|
||||||
if (encoding != null && !encoding.equals("")) {
|
|
||||||
unzip.setEncoding(encoding);
|
|
||||||
}
|
|
||||||
return runner.postTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
|
||||||
private ReturnCode untar(File src, File dest, boolean overwrite, Untar.UntarCompressionMethod compression) {
|
|
||||||
Untar unzip = new Untar();
|
|
||||||
unzip.setTaskName("Untar");
|
|
||||||
RunTask runner = new RunTask(unzip);
|
|
||||||
unzip.setSrc(src);
|
|
||||||
unzip.setDest(dest);
|
|
||||||
unzip.setOverwrite(overwrite);
|
|
||||||
unzip.setCompression(compression);
|
|
||||||
return runner.postTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
|
||||||
private ReturnCode unrar(File src, File dst) {
|
|
||||||
UnRarTask unrar = new UnRarTask();
|
|
||||||
unrar.setTaskName("UnRar");
|
|
||||||
RunTask runner = new RunTask(unrar);
|
|
||||||
unrar.setSrc(src);
|
|
||||||
unrar.setDst(dst);
|
|
||||||
return runner.postTask();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,265 +1,69 @@
|
||||||
/*
|
package net.brutex.xservices.ws;
|
||||||
* Copyright 2010 Brian Rosenberger (Brutex Network)
|
|
||||||
*
|
import javax.jws.WebMethod;
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
import javax.jws.WebParam;
|
||||||
* you may not use this file except in compliance with the License.
|
import javax.jws.WebService;
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
import net.brutex.xservices.types.HostConnection;
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
import net.brutex.xservices.types.ReturnCode;
|
||||||
*
|
import net.brutex.xservices.util.BrutexNamespaces;
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES)
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
public interface ExecuteService {
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
@WebMethod(operationName = "runCommand")
|
||||||
*/
|
public abstract ReturnCode runCommand(
|
||||||
|
@WebParam(name = "executable") String cmd,
|
||||||
package net.brutex.xservices.ws;
|
@WebParam(name = "argline") String args,
|
||||||
|
@WebParam(name = "timeout") long timeout);
|
||||||
import java.io.File;
|
|
||||||
import javax.jws.WebMethod;
|
@WebMethod(operationName = "runCommandWithArgs")
|
||||||
import javax.jws.WebParam;
|
public abstract ReturnCode runCommandWithArgs(
|
||||||
import javax.jws.WebService;
|
@WebParam(name = "executable") String cmd,
|
||||||
import net.brutex.xservices.types.HostConnection;
|
@WebParam(name = "arg") String[] args,
|
||||||
import net.brutex.xservices.types.ReturnCode;
|
@WebParam(name = "timeout") long timeout);
|
||||||
import net.brutex.xservices.util.RunTask;
|
|
||||||
import org.apache.tools.ant.taskdefs.ExecTask;
|
@WebMethod(operationName = "runCommandAsync")
|
||||||
import org.apache.tools.ant.taskdefs.optional.net.RExecTask;
|
public abstract ReturnCode runCommandAsync(
|
||||||
import org.apache.tools.ant.taskdefs.optional.net.TelnetTask;
|
@WebParam(name = "executable") String cmd,
|
||||||
import org.apache.tools.ant.taskdefs.optional.ssh.SSHExec;
|
@WebParam(name = "argline") String args);
|
||||||
import org.apache.tools.ant.types.Commandline;
|
|
||||||
|
@WebMethod(operationName = "runCommandAsyncWithArgs")
|
||||||
/**
|
public abstract ReturnCode runCommandAsyncWithArgs(
|
||||||
*
|
@WebParam(name = "executable") String cmd,
|
||||||
* @author Brian Rosenberger, bru@brutex.de
|
@WebParam(name = "arg") String[] args);
|
||||||
*/
|
|
||||||
@WebService(targetNamespace="http://ws.xservices.brutex.net", name="ExecuteService")
|
@WebMethod(operationName = "runCommandWithSSH")
|
||||||
public class ExecuteService {
|
public abstract ReturnCode runCommandWithSSH(
|
||||||
|
@WebParam(name = "host") String host,
|
||||||
@WebMethod(operationName = "runCommand")
|
@WebParam(name = "port") int port,
|
||||||
public ReturnCode runCommand(@WebParam(name = "executable") String cmd,
|
@WebParam(name = "username") String username,
|
||||||
@WebParam(name = "argline") String args,
|
@WebParam(name = "password") String password,
|
||||||
@WebParam(name = "timeout") long timeout) {
|
@WebParam(name = "command") String cmd,
|
||||||
|
@WebParam(name = "timeout") long timeout);
|
||||||
return executeCommand(cmd,
|
|
||||||
Commandline.translateCommandline(args),
|
@WebMethod(operationName = "runCommandWithSSHKeyAuth")
|
||||||
null,
|
public abstract ReturnCode runCommandWithSSHKeyAuth(
|
||||||
false,
|
@WebParam(name = "host") String host,
|
||||||
null,
|
@WebParam(name = "port") int port,
|
||||||
false,
|
@WebParam(name = "username") String username,
|
||||||
true,
|
@WebParam(name = "passphrase") String passphrase,
|
||||||
false,
|
@WebParam(name = "keyfile") String keyfile,
|
||||||
timeout);
|
@WebParam(name = "command") String cmd,
|
||||||
}
|
@WebParam(name = "timeout") long timeout);
|
||||||
|
|
||||||
@WebMethod(operationName = "runCommandWithArgs")
|
@WebMethod(operationName = "rExec")
|
||||||
public ReturnCode runCommandWithArgs(@WebParam(name = "executable") String cmd,
|
public abstract ReturnCode rExec(
|
||||||
@WebParam(name = "arg") String[] args,
|
@WebParam(name = "host") HostConnection host,
|
||||||
@WebParam(name = "timeout") long timeout) {
|
@WebParam(name = "command") String cmd,
|
||||||
|
@WebParam(name = "timeout") long timeout);
|
||||||
return executeCommand(cmd,
|
|
||||||
args,
|
@WebMethod(operationName = "telnet")
|
||||||
null,
|
public abstract ReturnCode runTelnet(
|
||||||
false,
|
@WebParam(name = "host") HostConnection host,
|
||||||
null,
|
@WebParam(name = "prompt") String prompt,
|
||||||
false,
|
@WebParam(name = "command") String cmd,
|
||||||
true,
|
@WebParam(name = "expect") String expect,
|
||||||
false,
|
@WebParam(name = "timeout") long timeout);
|
||||||
timeout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(operationName = "runCommandAsync")
|
|
||||||
public ReturnCode runCommandAsync(@WebParam(name = "executable") String cmd,
|
|
||||||
@WebParam(name = "argline") String args) {
|
|
||||||
|
|
||||||
return executeCommand(cmd,
|
|
||||||
Commandline.translateCommandline(args),
|
|
||||||
null,
|
|
||||||
true,
|
|
||||||
null,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(operationName = "runCommandAsyncWithArgs")
|
|
||||||
public ReturnCode runCommandAsyncWithArgs(@WebParam(name = "executable") String cmd,
|
|
||||||
@WebParam(name = "arg") String[] args) {
|
|
||||||
|
|
||||||
return executeCommand(cmd,
|
|
||||||
args,
|
|
||||||
null,
|
|
||||||
true,
|
|
||||||
null,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(operationName = "runCommandWithSSH")
|
|
||||||
public ReturnCode runCommandWithSSH(@WebParam(name = "host") String host,
|
|
||||||
@WebParam(name = "port") int port,
|
|
||||||
@WebParam(name = "username") String username,
|
|
||||||
@WebParam(name = "password") String password,
|
|
||||||
@WebParam(name = "command") String cmd,
|
|
||||||
@WebParam(name = "timeout") long timeout) {
|
|
||||||
|
|
||||||
return sshExec(host, username, password, port, cmd, timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(operationName = "runCommandWithSSHKeyAuth")
|
|
||||||
public ReturnCode runCommandWithSSHKeyAuth(@WebParam(name = "host") String host,
|
|
||||||
@WebParam(name = "port") int port,
|
|
||||||
@WebParam(name = "username") String username,
|
|
||||||
@WebParam(name = "passphrase") String passphrase,
|
|
||||||
@WebParam(name = "keyfile") String keyfile,
|
|
||||||
@WebParam(name = "command") String cmd,
|
|
||||||
@WebParam(name = "timeout") long timeout) {
|
|
||||||
|
|
||||||
return sshExecWithCert(host, username, passphrase, keyfile, port, cmd, timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(operationName = "rExec")
|
|
||||||
public ReturnCode rExec(@WebParam(name = "host") HostConnection host,
|
|
||||||
@WebParam(name = "command") String cmd,
|
|
||||||
@WebParam(name = "timeout") long timeout) {
|
|
||||||
return rexec(host.hostname, host.port, host.user, host.password, cmd, timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(operationName = "telnet")
|
|
||||||
public ReturnCode runTelnet(@WebParam(name = "host") HostConnection host,
|
|
||||||
@WebParam(name = "prompt") String prompt,
|
|
||||||
@WebParam(name = "command") String cmd,
|
|
||||||
@WebParam(name = "expect") String expect,
|
|
||||||
@WebParam(name = "timeout") long timeout) {
|
|
||||||
return telnet(host.hostname, host.port, host.user, host.password, cmd, timeout, prompt, expect);
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
|
||||||
private ReturnCode executeCommand(String executable,
|
|
||||||
String[] args,
|
|
||||||
File dir,
|
|
||||||
boolean spawn,
|
|
||||||
String inputstring,
|
|
||||||
boolean newenvironment,
|
|
||||||
boolean vmlauncher,
|
|
||||||
boolean searchpath,
|
|
||||||
long timeout) {
|
|
||||||
ExecTask exe = new ExecTask();
|
|
||||||
RunTask runner = new RunTask(exe);
|
|
||||||
|
|
||||||
/*
|
|
||||||
Commandline cmdl = new Commandline();
|
|
||||||
cmdl.setExecutable(executable);
|
|
||||||
cmdl.addArguments(args);
|
|
||||||
System.out.println(cmdl.describeCommand());
|
|
||||||
*/
|
|
||||||
|
|
||||||
exe.setExecutable(executable);
|
|
||||||
for (String s : args) {
|
|
||||||
exe.createArg().setValue(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
exe.setDir(dir);
|
|
||||||
if (spawn) {
|
|
||||||
exe.setSpawn(spawn);
|
|
||||||
} else {
|
|
||||||
exe.setTimeout(timeout);
|
|
||||||
exe.setInputString(inputstring);
|
|
||||||
exe.setOutputproperty("ExecuteService.stdout");
|
|
||||||
exe.setErrorProperty("ExecuteService.stderr");
|
|
||||||
exe.setResultProperty("ExecuteService.result");
|
|
||||||
}
|
|
||||||
|
|
||||||
exe.setNewenvironment(newenvironment);
|
|
||||||
exe.setVMLauncher(vmlauncher);
|
|
||||||
exe.setSearchPath(searchpath);
|
|
||||||
|
|
||||||
return runner.postTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
|
||||||
private ReturnCode sshExec(String host,
|
|
||||||
String username,
|
|
||||||
String password,
|
|
||||||
int port,
|
|
||||||
String command,
|
|
||||||
long timeout) {
|
|
||||||
SSHExec sshexec = new SSHExec();
|
|
||||||
RunTask runner = new RunTask(sshexec);
|
|
||||||
sshexec.setHost(host);
|
|
||||||
sshexec.setUsername(username);
|
|
||||||
sshexec.setPassword(password);
|
|
||||||
sshexec.setPort(port);
|
|
||||||
sshexec.setCommand(command);
|
|
||||||
sshexec.setTrust(true);
|
|
||||||
sshexec.setTimeout(timeout);
|
|
||||||
sshexec.setOutputproperty("SSHExec.stdout");
|
|
||||||
return runner.postTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
|
||||||
private ReturnCode sshExecWithCert(String host,
|
|
||||||
String username,
|
|
||||||
String passphrase,
|
|
||||||
String keyfile,
|
|
||||||
int port,
|
|
||||||
String command,
|
|
||||||
long timeout) {
|
|
||||||
SSHExec sshexec = new SSHExec();
|
|
||||||
RunTask runner = new RunTask(sshexec);
|
|
||||||
sshexec.setHost(host);
|
|
||||||
sshexec.setUsername(username);
|
|
||||||
sshexec.setKeyfile(keyfile);
|
|
||||||
sshexec.setPassphrase(passphrase);
|
|
||||||
sshexec.setPort(port);
|
|
||||||
sshexec.setCommand(command);
|
|
||||||
sshexec.setTrust(true);
|
|
||||||
sshexec.setTimeout(timeout);
|
|
||||||
sshexec.setOutputproperty("SSHExec.stdout");
|
|
||||||
return runner.postTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
|
||||||
private ReturnCode rexec(String host,
|
|
||||||
int port,
|
|
||||||
String username,
|
|
||||||
String password,
|
|
||||||
String command,
|
|
||||||
long timeout) {
|
|
||||||
RExecTask rexec = new RExecTask();
|
|
||||||
RunTask runner = new RunTask(rexec);
|
|
||||||
rexec.setServer(host);
|
|
||||||
rexec.setPort(port);
|
|
||||||
rexec.setUserid(username);
|
|
||||||
rexec.setPassword(password);
|
|
||||||
rexec.setCommand(command);
|
|
||||||
rexec.setTimeout((int) Math.round(timeout));
|
|
||||||
|
|
||||||
return runner.postTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
|
||||||
private ReturnCode telnet(String host,
|
|
||||||
int port,
|
|
||||||
String username,
|
|
||||||
String password,
|
|
||||||
String command,
|
|
||||||
long timeout, String prompt, String expect) {
|
|
||||||
TelnetTask rexec = new TelnetTask();
|
|
||||||
RunTask runner = new RunTask(rexec);
|
|
||||||
rexec.setServer(host);
|
|
||||||
rexec.setPort(port);
|
|
||||||
rexec.setUserid(username);
|
|
||||||
rexec.setPassword(password);
|
|
||||||
rexec.setTimeout((int) Math.round(timeout));
|
|
||||||
|
|
||||||
rexec.createRead().addText(prompt);
|
|
||||||
rexec.createWrite().addText(command);
|
|
||||||
rexec.createRead().addText(expect);
|
|
||||||
|
|
||||||
return runner.postTask();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,203 +1,60 @@
|
||||||
/*
|
package net.brutex.xservices.ws;
|
||||||
* Copyright 2010 Brian Rosenberger (Brutex Network)
|
|
||||||
*
|
import javax.jws.WebMethod;
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
import javax.jws.WebParam;
|
||||||
* you may not use this file except in compliance with the License.
|
import javax.jws.WebService;
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
import net.brutex.xservices.types.ArchiveResource;
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
import net.brutex.xservices.types.FileResource;
|
||||||
*
|
import net.brutex.xservices.types.FileSetResource;
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
import net.brutex.xservices.types.ReturnCode;
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
import net.brutex.xservices.util.BrutexNamespaces;
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES)
|
||||||
* See the License for the specific language governing permissions and
|
public interface FileService {
|
||||||
* limitations under the License.
|
|
||||||
*/
|
@WebMethod(operationName = "basename")
|
||||||
package net.brutex.xservices.ws;
|
public abstract ReturnCode basename(
|
||||||
|
@WebParam(name = "file") String filename,
|
||||||
import java.io.File;
|
@WebParam(name = "suffix") String suffix);
|
||||||
import javax.jws.WebMethod;
|
|
||||||
import javax.jws.WebParam;
|
@WebMethod(operationName = "copy")
|
||||||
import javax.jws.WebService;
|
public abstract ReturnCode copy(
|
||||||
import net.brutex.xservices.types.ArchiveResource;
|
@WebParam(name = "fileset") FileSetResource src,
|
||||||
import net.brutex.xservices.types.FileResource;
|
@WebParam(name = "todir") String todir,
|
||||||
import net.brutex.xservices.types.FileSetResource;
|
@WebParam(name = "preservelastmodified") boolean plm,
|
||||||
import net.brutex.xservices.types.ResourceInterface;
|
@WebParam(name = "overwrite") boolean overwrite,
|
||||||
import net.brutex.xservices.types.ReturnCode;
|
@WebParam(name = "encoding") String encoding) throws XServicesFault;
|
||||||
import net.brutex.xservices.util.RunTask;
|
|
||||||
import org.apache.tools.ant.taskdefs.Basename;
|
@WebMethod(operationName = "loadResource")
|
||||||
import org.apache.tools.ant.taskdefs.Chmod;
|
public abstract ReturnCode loadRes(
|
||||||
import org.apache.tools.ant.taskdefs.Copy;
|
@WebParam(name = "resource") FileResource res,
|
||||||
import org.apache.tools.ant.taskdefs.Echo;
|
@WebParam(name = "encoding") String encoding);
|
||||||
import org.apache.tools.ant.taskdefs.LoadResource;
|
|
||||||
import org.apache.tools.ant.taskdefs.optional.unix.Chgrp;
|
@WebMethod(operationName = "loadResourceFromArchive")
|
||||||
import org.apache.tools.ant.taskdefs.optional.unix.Chown;
|
public abstract ReturnCode loadResFromArchive(
|
||||||
import org.apache.tools.ant.types.FileSet;
|
@WebParam(name = "archiveresource") ArchiveResource res,
|
||||||
|
@WebParam(name = "encoding") String encoding);
|
||||||
/**
|
|
||||||
*
|
@WebMethod(operationName = "echoToFile")
|
||||||
* @author Brian Rosenberger, bru@brutex.de
|
public abstract ReturnCode echo2file(
|
||||||
*/
|
@WebParam(name = "message") String message,
|
||||||
@WebService(targetNamespace = "http://ws.xservices.brutex.net", name = "FileService")
|
@WebParam(name = "file") String file,
|
||||||
public class FileService {
|
@WebParam(name = "encoding") String encoding,
|
||||||
|
@WebParam(name = "append") boolean append);
|
||||||
@WebMethod(operationName = "basename")
|
|
||||||
public ReturnCode basename(@WebParam(name = "file") String filename,
|
@WebMethod(operationName = "changeOwner")
|
||||||
@WebParam(name = "suffix") String suffix) {
|
public abstract ReturnCode changeOwner(
|
||||||
return basename(new File(filename), suffix);
|
@WebParam(name = "fileset") FileSetResource res,
|
||||||
}
|
@WebParam(name = "owner") String owner);
|
||||||
|
|
||||||
@WebMethod(operationName = "copy")
|
@WebMethod(operationName = "changeGroup")
|
||||||
public ReturnCode copy(@WebParam(name = "fileset") FileSetResource src,
|
public abstract ReturnCode changeGroup(
|
||||||
@WebParam(name = "todir") String todir,
|
@WebParam(name = "fileset") FileSetResource res,
|
||||||
@WebParam(name = "preservelastmodified") boolean plm,
|
@WebParam(name = "group") String group);
|
||||||
@WebParam(name = "overwrite") boolean overwrite,
|
|
||||||
@WebParam(name = "encoding") String encoding)
|
@WebMethod(operationName = "changeMode")
|
||||||
throws XServicesFault {
|
public abstract ReturnCode changeMode(
|
||||||
return copy(src, new File(todir), plm, overwrite, encoding);
|
@WebParam(name = "fileset") FileSetResource res,
|
||||||
}
|
@WebParam(name = "permissions") String perm);
|
||||||
|
|
||||||
@WebMethod(operationName = "loadResource")
|
}
|
||||||
public ReturnCode loadRes(@WebParam(name = "resource") FileResource res,
|
|
||||||
@WebParam(name = "encoding") String encoding) {
|
|
||||||
if (encoding == null || encoding.equals("")) {
|
|
||||||
encoding = System.getProperty("file.encoding");
|
|
||||||
}
|
|
||||||
return loadResource(res, encoding);
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(operationName = "loadResourceFromArchive")
|
|
||||||
public ReturnCode loadResFromArchive(@WebParam(name = "archiveresource") ArchiveResource res,
|
|
||||||
@WebParam(name = "encoding") String encoding) {
|
|
||||||
if (encoding == null || encoding.equals("")) {
|
|
||||||
encoding = System.getProperty("file.encoding");
|
|
||||||
}
|
|
||||||
return loadResource(res, encoding);
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(operationName = "echoToFile")
|
|
||||||
public ReturnCode echo2file(@WebParam(name = "message") String message,
|
|
||||||
@WebParam(name = "file") String file, @WebParam(name = "encoding") String encoding,
|
|
||||||
@WebParam(name = "append") boolean append) {
|
|
||||||
return echo(message, new File(file), encoding, append);
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(operationName = "changeOwner")
|
|
||||||
public ReturnCode changeOwner(@WebParam(name = "fileset") FileSetResource res,
|
|
||||||
@WebParam(name = "owner") String owner) {
|
|
||||||
return chown(res, owner);
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(operationName = "changeGroup")
|
|
||||||
public ReturnCode changeGroup(@WebParam(name = "fileset") FileSetResource res,
|
|
||||||
@WebParam(name = "group") String group) {
|
|
||||||
return chgrp(res, group);
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(operationName = "changeMode")
|
|
||||||
public ReturnCode changeMode(@WebParam(name="fileset") FileSetResource res,
|
|
||||||
@WebParam(name="permissions") String perm) {
|
|
||||||
return chmod(res, perm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
|
||||||
private ReturnCode basename(File file,
|
|
||||||
String suffix) {
|
|
||||||
Basename basename = new Basename();
|
|
||||||
RunTask runner = new RunTask(basename);
|
|
||||||
basename.setFile(file);
|
|
||||||
if (suffix != null && !suffix.equals("")) {
|
|
||||||
basename.setSuffix(suffix);
|
|
||||||
}
|
|
||||||
basename.setProperty("basename.value");
|
|
||||||
return runner.postTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
|
||||||
private ReturnCode loadResource(ResourceInterface src, String encoding) {
|
|
||||||
LoadResource lr = new LoadResource();
|
|
||||||
lr.setTaskName("LoadResource");
|
|
||||||
RunTask runner = new RunTask(lr);
|
|
||||||
lr.addConfigured(src.getAntResource(lr.getProject()));
|
|
||||||
lr.setEncoding(encoding);
|
|
||||||
System.out.println("Using encoding: " + encoding);
|
|
||||||
lr.setProperty("LoadResource.out");
|
|
||||||
return runner.postTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
|
||||||
private ReturnCode echo(String msg, File file, String encoding, boolean append) {
|
|
||||||
Echo echo = new Echo();
|
|
||||||
echo.setTaskName("toFile");
|
|
||||||
RunTask runTask = new RunTask(echo);
|
|
||||||
echo.addText(msg);
|
|
||||||
echo.setEncoding(encoding);
|
|
||||||
echo.setFile(file);
|
|
||||||
echo.setAppend(append);
|
|
||||||
return runTask.postTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
|
||||||
private ReturnCode copy(FileSetResource src, File dst, boolean preservelastmodified,
|
|
||||||
boolean overwrite, String encoding) {
|
|
||||||
Copy copy = new Copy();
|
|
||||||
copy.setTaskName("Copy");
|
|
||||||
RunTask runner = new RunTask(copy);
|
|
||||||
FileSet set = src.getAntFileSet(copy.getProject());
|
|
||||||
copy.add(set);
|
|
||||||
|
|
||||||
if (dst.isDirectory()) {
|
|
||||||
copy.setTodir(dst);
|
|
||||||
}
|
|
||||||
if (dst.isFile()) {
|
|
||||||
copy.setTofile(dst);
|
|
||||||
}
|
|
||||||
copy.setOverwrite(overwrite);
|
|
||||||
copy.setPreserveLastModified(preservelastmodified);
|
|
||||||
if (encoding != null && !encoding.equals("")) {
|
|
||||||
copy.setOutputEncoding(encoding);
|
|
||||||
} else {
|
|
||||||
copy.setOutputEncoding(System.getProperty("file.encoding"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return runner.postTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
|
||||||
private ReturnCode chown(FileSetResource src, String owner) {
|
|
||||||
Chown chown = new Chown();
|
|
||||||
chown.setTaskName("Chown");
|
|
||||||
RunTask runner = new RunTask(chown);
|
|
||||||
chown.setOwner(owner);
|
|
||||||
FileSet set = src.getAntFileSet(chown.getProject());
|
|
||||||
chown.add(set);
|
|
||||||
chown.setMaxParallel(300);
|
|
||||||
return runner.postTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
|
||||||
private ReturnCode chgrp(FileSetResource src, String group) {
|
|
||||||
Chgrp chgrp = new Chgrp();
|
|
||||||
chgrp.setTaskName("Chgrp");
|
|
||||||
RunTask runner = new RunTask(chgrp);
|
|
||||||
chgrp.setGroup(group);
|
|
||||||
FileSet set = src.getAntFileSet(chgrp.getProject());
|
|
||||||
chgrp.add(set);
|
|
||||||
chgrp.setMaxParallel(300);
|
|
||||||
return runner.postTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
|
||||||
private ReturnCode chmod(FileSetResource src, String perm) {
|
|
||||||
Chmod chmod = new Chmod();
|
|
||||||
chmod.setTaskName("Chmod");
|
|
||||||
RunTask runner = new RunTask(chmod);
|
|
||||||
FileSet set = src.getAntFileSet(chmod.getProject());
|
|
||||||
chmod.add(set);
|
|
||||||
chmod.setMaxParallel(300);
|
|
||||||
chmod.setPerm(perm);
|
|
||||||
chmod.setVerbose(true);
|
|
||||||
return runner.postTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,185 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2010 Brian Rosenberger (Brutex Network)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package net.brutex.xservices.ws;
|
|
||||||
|
|
||||||
import javax.jws.WebService;
|
|
||||||
import net.brutex.xservices.types.FileSetResource;
|
|
||||||
import net.brutex.xservices.types.HostConnection;
|
|
||||||
import net.brutex.xservices.types.MailMimeType;
|
|
||||||
import net.brutex.xservices.types.ReturnCode;
|
|
||||||
import net.brutex.xservices.util.RunTask;
|
|
||||||
import org.apache.cxf.annotations.WSDLDocumentation;
|
|
||||||
import org.apache.cxf.annotations.WSDLDocumentationCollection;
|
|
||||||
import org.apache.tools.ant.taskdefs.HostInfo;
|
|
||||||
import org.apache.tools.ant.taskdefs.Sleep;
|
|
||||||
import org.apache.tools.ant.taskdefs.email.EmailTask;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Brian Rosenberger, bru@brutex.de
|
|
||||||
*/
|
|
||||||
@WSDLDocumentationCollection(
|
|
||||||
{
|
|
||||||
@WSDLDocumentation("My portType documentation"),
|
|
||||||
@WSDLDocumentation(value = "My top level documentation",
|
|
||||||
placement = WSDLDocumentation.Placement.TOP),
|
|
||||||
@WSDLDocumentation(value = "My binding doc",
|
|
||||||
placement = WSDLDocumentation.Placement.BINDING)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@WebService(endpointInterface="net.brutex.xservices.ws.MiscService",
|
|
||||||
serviceName="MiscService")
|
|
||||||
public class MiscServiceImpl implements MiscService {
|
|
||||||
|
|
||||||
@WSDLDocumentation(value="Get information about a host.")
|
|
||||||
public ReturnCode getHostinfo(String hostname) {
|
|
||||||
return antGetHostinfo(hostname, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ReturnCode sendMailSimple(HostConnection mailhost, String from, String tolist, String subject, String message) {
|
|
||||||
return sendMail(from,
|
|
||||||
from,
|
|
||||||
tolist,
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
subject,
|
|
||||||
message,
|
|
||||||
"text/plain",
|
|
||||||
null,
|
|
||||||
mailhost.hostname,
|
|
||||||
mailhost.port,
|
|
||||||
mailhost.user,
|
|
||||||
mailhost.password,
|
|
||||||
"utf-8",
|
|
||||||
false,
|
|
||||||
false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ReturnCode sendMailSimpleWithAttachment(HostConnection mailhost, String from,
|
|
||||||
String tolist, String subject, String message,
|
|
||||||
FileSetResource res) {
|
|
||||||
return sendMail(from,
|
|
||||||
from,
|
|
||||||
tolist,
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
subject,
|
|
||||||
message,
|
|
||||||
"text/plain",
|
|
||||||
res,
|
|
||||||
mailhost.hostname,
|
|
||||||
mailhost.port,
|
|
||||||
mailhost.user,
|
|
||||||
mailhost.password,
|
|
||||||
"utf-8",
|
|
||||||
false,
|
|
||||||
false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ReturnCode sendMail(HostConnection mailhost, String from, String tolist,
|
|
||||||
String cclist, String bcclist, String subject,
|
|
||||||
MailMimeType mimetype, String charset, String message,
|
|
||||||
FileSetResource res, boolean ssl, boolean tls) {
|
|
||||||
return sendMail(from,
|
|
||||||
from,
|
|
||||||
tolist,
|
|
||||||
cclist,
|
|
||||||
bcclist,
|
|
||||||
subject,
|
|
||||||
message,
|
|
||||||
mimetype.value(),
|
|
||||||
res,
|
|
||||||
mailhost.hostname,
|
|
||||||
mailhost.port,
|
|
||||||
mailhost.user,
|
|
||||||
mailhost.password,
|
|
||||||
charset,
|
|
||||||
tls,
|
|
||||||
ssl);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public ReturnCode sleep(int minutes, int seconds) {
|
|
||||||
return sleep(0, minutes, seconds, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private ReturnCode antGetHostinfo(String hostname, String prefix) {
|
|
||||||
HostInfo info = new HostInfo();
|
|
||||||
info.setTaskName("HostInfo");
|
|
||||||
RunTask runner = new RunTask(info);
|
|
||||||
info.setHost(hostname);
|
|
||||||
//info.setPrefix(prefix);
|
|
||||||
return runner.postTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
private ReturnCode sendMail(String from,
|
|
||||||
String replyto,
|
|
||||||
String tolist,
|
|
||||||
String cclist,
|
|
||||||
String bcclist,
|
|
||||||
String subject,
|
|
||||||
String message,
|
|
||||||
String messagemimetype,
|
|
||||||
FileSetResource attachments,
|
|
||||||
String mailhost,
|
|
||||||
int mailport,
|
|
||||||
String user,
|
|
||||||
String password,
|
|
||||||
String charset,
|
|
||||||
boolean tls,
|
|
||||||
boolean ssl) {
|
|
||||||
EmailTask mail = new EmailTask();
|
|
||||||
mail.setTaskName("Mail");
|
|
||||||
RunTask runner = new RunTask(mail);
|
|
||||||
mail.setFrom(from);
|
|
||||||
mail.setReplyTo(replyto);
|
|
||||||
mail.setToList(tolist);
|
|
||||||
mail.setCcList(cclist);
|
|
||||||
mail.setBccList(bcclist);
|
|
||||||
mail.setSubject(subject);
|
|
||||||
mail.setMessage(message);
|
|
||||||
mail.setMessageMimeType(messagemimetype);
|
|
||||||
if(attachments != null) {
|
|
||||||
mail.addFileset(attachments.getAntFileSet(mail.getProject()));
|
|
||||||
}
|
|
||||||
mail.setMailhost(mailhost);
|
|
||||||
mail.setMailport(mailport);
|
|
||||||
mail.setUser(user);
|
|
||||||
mail.setPassword(password);
|
|
||||||
mail.setCharset(charset);
|
|
||||||
mail.setSSL(ssl);
|
|
||||||
mail.setEnableStartTLS(tls);
|
|
||||||
return runner.postTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
private ReturnCode sleep(int hours, int minutes, int seconds, int milliseconds) {
|
|
||||||
Sleep sleep = new Sleep();
|
|
||||||
sleep.setTaskName("Sleep");
|
|
||||||
RunTask runner = new RunTask(sleep);
|
|
||||||
sleep.setHours(hours);
|
|
||||||
sleep.setMinutes(minutes);
|
|
||||||
sleep.setSeconds(seconds);
|
|
||||||
sleep.setMilliseconds(milliseconds);
|
|
||||||
return runner.postTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -28,7 +28,12 @@ import javax.xml.datatype.XMLGregorianCalendar;
|
||||||
*/
|
*/
|
||||||
public class XServicesFault extends Exception {
|
public class XServicesFault extends Exception {
|
||||||
|
|
||||||
public XServicesFault(String message, Exception e) {
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = -6779279189376374820L;
|
||||||
|
|
||||||
|
public XServicesFault(String message, Exception e) {
|
||||||
this(message, e.getCause());
|
this(message, e.getCause());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,325 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2010 Brian Rosenberger (Brutex Network)
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package net.brutex.xservices.ws.impl;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import javax.jws.WebMethod;
|
||||||
|
import javax.jws.WebParam;
|
||||||
|
import javax.jws.WebService;
|
||||||
|
import net.brutex.xservices.types.ArchiveResource;
|
||||||
|
import net.brutex.xservices.types.CompressionType;
|
||||||
|
import net.brutex.xservices.types.FileResource;
|
||||||
|
import net.brutex.xservices.types.ResourceInterface;
|
||||||
|
import net.brutex.xservices.types.ReturnCode;
|
||||||
|
import net.brutex.xservices.util.BrutexNamespaces;
|
||||||
|
import net.brutex.xservices.util.RunTask;
|
||||||
|
import net.brutex.xservices.util.UnRarTask;
|
||||||
|
import net.brutex.xservices.ws.ArchiveService;
|
||||||
|
|
||||||
|
import org.apache.tools.ant.taskdefs.BUnzip2;
|
||||||
|
import org.apache.tools.ant.taskdefs.BZip2;
|
||||||
|
import org.apache.tools.ant.taskdefs.Expand;
|
||||||
|
import org.apache.tools.ant.taskdefs.GUnzip;
|
||||||
|
import org.apache.tools.ant.taskdefs.GZip;
|
||||||
|
import org.apache.tools.ant.taskdefs.Untar;
|
||||||
|
import org.apache.tools.ant.taskdefs.Zip;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Brian Rosenberger, bru@brutex.de
|
||||||
|
*/
|
||||||
|
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES,
|
||||||
|
endpointInterface="net.brutex.xservices.ws.ArchiveService",
|
||||||
|
name = "ArchiveService")
|
||||||
|
public class ArchiveServiceImpl implements ArchiveService {
|
||||||
|
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.ArchiveService#bzip2(net.brutex.xservices.types.FileResource, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = WS_OPERATION_BZIP2, action = WS_OPERATION_BZIP2)
|
||||||
|
public ReturnCode bzip2(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
|
||||||
|
@WebParam(name = WS_PARAM_DESTFILE) String file) {
|
||||||
|
return bzip(src, new File(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.ArchiveService#bzip2FromArchive(net.brutex.xservices.types.ArchiveResource, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = WS_OPERATION_BZIP2_ARCHIVE, action = WS_OPERATION_BZIP2_ARCHIVE)
|
||||||
|
public ReturnCode bzip2FromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
|
||||||
|
@WebParam(name = WS_PARAM_DESTFILE) String file) {
|
||||||
|
return bzip(src, new File(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.ArchiveService#gzip(net.brutex.xservices.types.FileResource, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = WS_OPERATION_GZIP, action = WS_OPERATION_GZIP)
|
||||||
|
public ReturnCode gzip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
|
||||||
|
@WebParam(name = WS_PARAM_DESTFILE) String file) {
|
||||||
|
return gzip(src, new File(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.ArchiveService#gzipFromArchive(net.brutex.xservices.types.ArchiveResource, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = WS_OPERATION_GZIP_ARCHIVE, action = WS_OPERATION_GZIP_ARCHIVE)
|
||||||
|
public ReturnCode gzipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
|
||||||
|
@WebParam(name = WS_PARAM_DESTFILE) String file) {
|
||||||
|
return gzip(src, new File(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.ArchiveService#gunzip(java.lang.String, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = WS_OPERATION_GUNZIP, action = WS_OPERATION_GUNZIP)
|
||||||
|
public ReturnCode gunzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
|
||||||
|
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
|
||||||
|
File target = null;
|
||||||
|
if (!dest.equals("") && dest != null) {
|
||||||
|
target = new File(dest);
|
||||||
|
}
|
||||||
|
return GUnzip(new FileResource(FileResource.Type.FILE, src), target);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.ArchiveService#bunzip2(java.lang.String, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = WS_OPERATION_BUNZIP2)
|
||||||
|
public ReturnCode bunzip2(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
|
||||||
|
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
|
||||||
|
File target = null;
|
||||||
|
if (!dest.equals("") && dest != null) {
|
||||||
|
target = new File(dest);
|
||||||
|
}
|
||||||
|
return BUnzip2(new FileResource(FileResource.Type.FILE, src), target);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.ArchiveService#gunzipFromURL(java.lang.String, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "gunzipFromURL")
|
||||||
|
public ReturnCode gunzipFromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src,
|
||||||
|
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
|
||||||
|
File target = null;
|
||||||
|
if (!dest.equals("") && dest != null) {
|
||||||
|
target = new File(dest);
|
||||||
|
}
|
||||||
|
return GUnzip(new FileResource(FileResource.Type.URL, src), target);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.ArchiveService#bunzip2FromURL(java.lang.String, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "bunzip2FromURL")
|
||||||
|
public ReturnCode bunzip2FromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src,
|
||||||
|
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
|
||||||
|
File target = null;
|
||||||
|
if (!dest.equals("") && dest != null) {
|
||||||
|
target = new File(dest);
|
||||||
|
}
|
||||||
|
return BUnzip2(new FileResource(FileResource.Type.URL, src), target);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.ArchiveService#zip(net.brutex.xservices.types.FileResource, java.lang.String, boolean, java.lang.String, int)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "zip")
|
||||||
|
public ReturnCode zip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
|
||||||
|
@WebParam(name = WS_PARAM_DESTFILE) String file,
|
||||||
|
@WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite,
|
||||||
|
@WebParam(name = WS_PARAM_ENCODING) String encoding,
|
||||||
|
@WebParam(name = "compresslevel") int level) {
|
||||||
|
if (level > 9) {
|
||||||
|
level = 9;
|
||||||
|
}
|
||||||
|
if (level < 0) {
|
||||||
|
level = 0;
|
||||||
|
}
|
||||||
|
return zip(src, new File(file), encoding, !overwrite, level);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.ArchiveService#zipFromArchive(net.brutex.xservices.types.ArchiveResource, java.lang.String, boolean, java.lang.String, int)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "zipFromArchive")
|
||||||
|
public ReturnCode zipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
|
||||||
|
@WebParam(name = WS_PARAM_DESTFILE) String file,
|
||||||
|
@WebParam(name = WS_PARAM_OVERWRITE) boolean update,
|
||||||
|
@WebParam(name = WS_PARAM_ENCODING) String encoding,
|
||||||
|
@WebParam(name = "compresslevel") int level) {
|
||||||
|
return zip(src, new File(file), encoding, !update, level);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.ArchiveService#unzip(java.lang.String, java.lang.String, boolean, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "unzip")
|
||||||
|
public ReturnCode unzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
|
||||||
|
@WebParam(name = WS_PARAM_DESTDIR) String dest,
|
||||||
|
@WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite,
|
||||||
|
@WebParam(name = WS_PARAM_ENCODING) String encoding) {
|
||||||
|
return unzip(new File(src), new File(dest), overwrite, encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.ArchiveService#unrar(java.lang.String, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "unrar")
|
||||||
|
public ReturnCode unrar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
|
||||||
|
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
|
||||||
|
return unrar(new File(src), new File(dest));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.ArchiveService#untar(java.lang.String, java.lang.String, boolean, net.brutex.xservices.types.CompressionType)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "untar")
|
||||||
|
public ReturnCode untar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
|
||||||
|
@WebParam(name = WS_PARAM_DESTDIR) String dest,
|
||||||
|
@WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite,
|
||||||
|
@WebParam(name = "compression") CompressionType compression) {
|
||||||
|
Untar.UntarCompressionMethod c = new Untar.UntarCompressionMethod();
|
||||||
|
switch (compression) {
|
||||||
|
case GZIP:
|
||||||
|
c.setValue("gzip");
|
||||||
|
break;
|
||||||
|
case BZIP2:
|
||||||
|
c.setValue("bzip2");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
c.setValue("none");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return untar(new File(src), new File(dest), overwrite, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
@WebMethod(exclude = true)
|
||||||
|
private ReturnCode bzip(ResourceInterface src, File dst) {
|
||||||
|
if (dst.exists() && dst.isFile()) {
|
||||||
|
dst.delete();
|
||||||
|
}
|
||||||
|
BZip2 bzip = new BZip2();
|
||||||
|
bzip.setTaskName("BZip2");
|
||||||
|
RunTask runner = new RunTask(bzip);
|
||||||
|
bzip.setSrcResource(src.getAntResource(bzip.getProject()));
|
||||||
|
bzip.setDestfile(dst);
|
||||||
|
|
||||||
|
return runner.postTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
@WebMethod(exclude = true)
|
||||||
|
private ReturnCode gzip(ResourceInterface src, File dst) {
|
||||||
|
if (dst.exists() && dst.isFile()) {
|
||||||
|
dst.delete();
|
||||||
|
}
|
||||||
|
GZip gzip = new GZip();
|
||||||
|
gzip.setTaskName("GZip");
|
||||||
|
RunTask runner = new RunTask(gzip);
|
||||||
|
gzip.addConfigured(src.getAntResource(gzip.getProject()));
|
||||||
|
gzip.setDestfile(dst);
|
||||||
|
return runner.postTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
@WebMethod(exclude = true)
|
||||||
|
private ReturnCode zip(ResourceInterface src, File dst, String encoding, boolean update, int compresslevel) {
|
||||||
|
Zip zip = new Zip();
|
||||||
|
zip.setTaskName("Zip");
|
||||||
|
RunTask runner = new RunTask(zip);
|
||||||
|
zip.add(src.getAntResource(zip.getProject()));
|
||||||
|
zip.setDestFile(dst);
|
||||||
|
if (encoding != null && !encoding.equals("")) {
|
||||||
|
zip.setEncoding(encoding);
|
||||||
|
}
|
||||||
|
zip.setUpdate(update);
|
||||||
|
zip.setLevel(compresslevel);
|
||||||
|
return runner.postTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
@WebMethod(exclude = true)
|
||||||
|
private ReturnCode GUnzip(ResourceInterface src, File dst) {
|
||||||
|
GUnzip uz = new GUnzip();
|
||||||
|
uz.setTaskName("GUnzip");
|
||||||
|
RunTask runner = new RunTask(uz);
|
||||||
|
uz.setSrcResource(src.getAntResource(uz.getProject()));
|
||||||
|
if (dst != null) {
|
||||||
|
uz.setDest(dst);
|
||||||
|
}
|
||||||
|
return runner.postTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
@WebMethod(exclude = true)
|
||||||
|
private ReturnCode BUnzip2(ResourceInterface src, File dst) {
|
||||||
|
BUnzip2 uz = new BUnzip2();
|
||||||
|
uz.setTaskName("BUnzip2");
|
||||||
|
RunTask runner = new RunTask(uz);
|
||||||
|
uz.setSrcResource(src.getAntResource(uz.getProject()));
|
||||||
|
if (dst != null) {
|
||||||
|
uz.setDest(dst);
|
||||||
|
}
|
||||||
|
return runner.postTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
@WebMethod(exclude = true)
|
||||||
|
private ReturnCode unzip(File src, File dest, boolean overwrite, String encoding) {
|
||||||
|
Expand unzip = new Expand();
|
||||||
|
unzip.setTaskName("UnZip");
|
||||||
|
RunTask runner = new RunTask(unzip);
|
||||||
|
unzip.setSrc(src);
|
||||||
|
unzip.setDest(dest);
|
||||||
|
unzip.setOverwrite(overwrite);
|
||||||
|
if (encoding != null && !encoding.equals("")) {
|
||||||
|
unzip.setEncoding(encoding);
|
||||||
|
}
|
||||||
|
return runner.postTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
@WebMethod(exclude = true)
|
||||||
|
private ReturnCode untar(File src, File dest, boolean overwrite, Untar.UntarCompressionMethod compression) {
|
||||||
|
Untar unzip = new Untar();
|
||||||
|
unzip.setTaskName("Untar");
|
||||||
|
RunTask runner = new RunTask(unzip);
|
||||||
|
unzip.setSrc(src);
|
||||||
|
unzip.setDest(dest);
|
||||||
|
unzip.setOverwrite(overwrite);
|
||||||
|
unzip.setCompression(compression);
|
||||||
|
return runner.postTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
@WebMethod(exclude = true)
|
||||||
|
private ReturnCode unrar(File src, File dst) {
|
||||||
|
UnRarTask unrar = new UnRarTask();
|
||||||
|
unrar.setTaskName("UnRar");
|
||||||
|
RunTask runner = new RunTask(unrar);
|
||||||
|
unrar.setSrc(src);
|
||||||
|
unrar.setDst(dst);
|
||||||
|
return runner.postTask();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,304 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2010 Brian Rosenberger (Brutex Network)
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.brutex.xservices.ws.impl;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import javax.jws.WebMethod;
|
||||||
|
import javax.jws.WebParam;
|
||||||
|
import javax.jws.WebService;
|
||||||
|
import net.brutex.xservices.types.HostConnection;
|
||||||
|
import net.brutex.xservices.types.ReturnCode;
|
||||||
|
import net.brutex.xservices.util.BrutexNamespaces;
|
||||||
|
import net.brutex.xservices.util.RunTask;
|
||||||
|
import net.brutex.xservices.ws.ExecuteService;
|
||||||
|
|
||||||
|
import org.apache.tools.ant.taskdefs.ExecTask;
|
||||||
|
import org.apache.tools.ant.taskdefs.optional.net.RExecTask;
|
||||||
|
import org.apache.tools.ant.taskdefs.optional.net.TelnetTask;
|
||||||
|
import org.apache.tools.ant.taskdefs.optional.ssh.SSHExec;
|
||||||
|
import org.apache.tools.ant.types.Commandline;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Brian Rosenberger, bru@brutex.de
|
||||||
|
*/
|
||||||
|
@WebService(
|
||||||
|
targetNamespace=BrutexNamespaces.WS_XSERVICES,
|
||||||
|
endpointInterface="net.brutex.xservices.ws.ExecuteService",
|
||||||
|
name="ExecuteService"
|
||||||
|
)
|
||||||
|
public class ExecuteServiceImpl implements ExecuteService {
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.impl.ExecuteService#runCommand(java.lang.String, java.lang.String, long)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "runCommand")
|
||||||
|
public ReturnCode runCommand(@WebParam(name = "executable") String cmd,
|
||||||
|
@WebParam(name = "argline") String args,
|
||||||
|
@WebParam(name = "timeout") long timeout) {
|
||||||
|
|
||||||
|
return executeCommand(cmd,
|
||||||
|
Commandline.translateCommandline(args),
|
||||||
|
null,
|
||||||
|
false,
|
||||||
|
null,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.impl.ExecuteService#runCommandWithArgs(java.lang.String, java.lang.String[], long)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "runCommandWithArgs")
|
||||||
|
public ReturnCode runCommandWithArgs(@WebParam(name = "executable") String cmd,
|
||||||
|
@WebParam(name = "arg") String[] args,
|
||||||
|
@WebParam(name = "timeout") long timeout) {
|
||||||
|
|
||||||
|
return executeCommand(cmd,
|
||||||
|
args,
|
||||||
|
null,
|
||||||
|
false,
|
||||||
|
null,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.impl.ExecuteService#runCommandAsync(java.lang.String, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "runCommandAsync")
|
||||||
|
public ReturnCode runCommandAsync(@WebParam(name = "executable") String cmd,
|
||||||
|
@WebParam(name = "argline") String args) {
|
||||||
|
|
||||||
|
return executeCommand(cmd,
|
||||||
|
Commandline.translateCommandline(args),
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
null,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.impl.ExecuteService#runCommandAsyncWithArgs(java.lang.String, java.lang.String[])
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "runCommandAsyncWithArgs")
|
||||||
|
public ReturnCode runCommandAsyncWithArgs(@WebParam(name = "executable") String cmd,
|
||||||
|
@WebParam(name = "arg") String[] args) {
|
||||||
|
|
||||||
|
return executeCommand(cmd,
|
||||||
|
args,
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
null,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.impl.ExecuteService#runCommandWithSSH(java.lang.String, int, java.lang.String, java.lang.String, java.lang.String, long)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "runCommandWithSSH")
|
||||||
|
public ReturnCode runCommandWithSSH(@WebParam(name = "host") String host,
|
||||||
|
@WebParam(name = "port") int port,
|
||||||
|
@WebParam(name = "username") String username,
|
||||||
|
@WebParam(name = "password") String password,
|
||||||
|
@WebParam(name = "command") String cmd,
|
||||||
|
@WebParam(name = "timeout") long timeout) {
|
||||||
|
|
||||||
|
return sshExec(host, username, password, port, cmd, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.impl.ExecuteService#runCommandWithSSHKeyAuth(java.lang.String, int, java.lang.String, java.lang.String, java.lang.String, java.lang.String, long)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "runCommandWithSSHKeyAuth")
|
||||||
|
public ReturnCode runCommandWithSSHKeyAuth(@WebParam(name = "host") String host,
|
||||||
|
@WebParam(name = "port") int port,
|
||||||
|
@WebParam(name = "username") String username,
|
||||||
|
@WebParam(name = "passphrase") String passphrase,
|
||||||
|
@WebParam(name = "keyfile") String keyfile,
|
||||||
|
@WebParam(name = "command") String cmd,
|
||||||
|
@WebParam(name = "timeout") long timeout) {
|
||||||
|
|
||||||
|
return sshExecWithCert(host, username, passphrase, keyfile, port, cmd, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.impl.ExecuteService#rExec(net.brutex.xservices.types.HostConnection, java.lang.String, long)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "rExec")
|
||||||
|
public ReturnCode rExec(@WebParam(name = "host") HostConnection host,
|
||||||
|
@WebParam(name = "command") String cmd,
|
||||||
|
@WebParam(name = "timeout") long timeout) {
|
||||||
|
return rexec(host.hostname, host.port, host.user, host.password, cmd, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.impl.ExecuteService#runTelnet(net.brutex.xservices.types.HostConnection, java.lang.String, java.lang.String, java.lang.String, long)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "telnet")
|
||||||
|
public ReturnCode runTelnet(@WebParam(name = "host") HostConnection host,
|
||||||
|
@WebParam(name = "prompt") String prompt,
|
||||||
|
@WebParam(name = "command") String cmd,
|
||||||
|
@WebParam(name = "expect") String expect,
|
||||||
|
@WebParam(name = "timeout") long timeout) {
|
||||||
|
return telnet(host.hostname, host.port, host.user, host.password, cmd, timeout, prompt, expect);
|
||||||
|
}
|
||||||
|
|
||||||
|
@WebMethod(exclude = true)
|
||||||
|
private ReturnCode executeCommand(String executable,
|
||||||
|
String[] args,
|
||||||
|
File dir,
|
||||||
|
boolean spawn,
|
||||||
|
String inputstring,
|
||||||
|
boolean newenvironment,
|
||||||
|
boolean vmlauncher,
|
||||||
|
boolean searchpath,
|
||||||
|
long timeout) {
|
||||||
|
ExecTask exe = new ExecTask();
|
||||||
|
RunTask runner = new RunTask(exe);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Commandline cmdl = new Commandline();
|
||||||
|
cmdl.setExecutable(executable);
|
||||||
|
cmdl.addArguments(args);
|
||||||
|
System.out.println(cmdl.describeCommand());
|
||||||
|
*/
|
||||||
|
|
||||||
|
exe.setExecutable(executable);
|
||||||
|
for (String s : args) {
|
||||||
|
exe.createArg().setValue(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
exe.setDir(dir);
|
||||||
|
if (spawn) {
|
||||||
|
exe.setSpawn(spawn);
|
||||||
|
} else {
|
||||||
|
exe.setTimeout(timeout);
|
||||||
|
exe.setInputString(inputstring);
|
||||||
|
exe.setOutputproperty("ExecuteService.stdout");
|
||||||
|
exe.setErrorProperty("ExecuteService.stderr");
|
||||||
|
exe.setResultProperty("ExecuteService.result");
|
||||||
|
}
|
||||||
|
|
||||||
|
exe.setNewenvironment(newenvironment);
|
||||||
|
exe.setVMLauncher(vmlauncher);
|
||||||
|
exe.setSearchPath(searchpath);
|
||||||
|
|
||||||
|
return runner.postTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
@WebMethod(exclude = true)
|
||||||
|
private ReturnCode sshExec(String host,
|
||||||
|
String username,
|
||||||
|
String password,
|
||||||
|
int port,
|
||||||
|
String command,
|
||||||
|
long timeout) {
|
||||||
|
SSHExec sshexec = new SSHExec();
|
||||||
|
RunTask runner = new RunTask(sshexec);
|
||||||
|
sshexec.setHost(host);
|
||||||
|
sshexec.setUsername(username);
|
||||||
|
sshexec.setPassword(password);
|
||||||
|
sshexec.setPort(port);
|
||||||
|
sshexec.setCommand(command);
|
||||||
|
sshexec.setTrust(true);
|
||||||
|
sshexec.setTimeout(timeout);
|
||||||
|
sshexec.setOutputproperty("SSHExec.stdout");
|
||||||
|
return runner.postTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
@WebMethod(exclude = true)
|
||||||
|
private ReturnCode sshExecWithCert(String host,
|
||||||
|
String username,
|
||||||
|
String passphrase,
|
||||||
|
String keyfile,
|
||||||
|
int port,
|
||||||
|
String command,
|
||||||
|
long timeout) {
|
||||||
|
SSHExec sshexec = new SSHExec();
|
||||||
|
RunTask runner = new RunTask(sshexec);
|
||||||
|
sshexec.setHost(host);
|
||||||
|
sshexec.setUsername(username);
|
||||||
|
sshexec.setKeyfile(keyfile);
|
||||||
|
sshexec.setPassphrase(passphrase);
|
||||||
|
sshexec.setPort(port);
|
||||||
|
sshexec.setCommand(command);
|
||||||
|
sshexec.setTrust(true);
|
||||||
|
sshexec.setTimeout(timeout);
|
||||||
|
sshexec.setOutputproperty("SSHExec.stdout");
|
||||||
|
return runner.postTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
@WebMethod(exclude = true)
|
||||||
|
private ReturnCode rexec(String host,
|
||||||
|
int port,
|
||||||
|
String username,
|
||||||
|
String password,
|
||||||
|
String command,
|
||||||
|
long timeout) {
|
||||||
|
RExecTask rexec = new RExecTask();
|
||||||
|
RunTask runner = new RunTask(rexec);
|
||||||
|
rexec.setServer(host);
|
||||||
|
rexec.setPort(port);
|
||||||
|
rexec.setUserid(username);
|
||||||
|
rexec.setPassword(password);
|
||||||
|
rexec.setCommand(command);
|
||||||
|
rexec.setTimeout((int) Math.round(timeout));
|
||||||
|
|
||||||
|
return runner.postTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
@WebMethod(exclude = true)
|
||||||
|
private ReturnCode telnet(String host,
|
||||||
|
int port,
|
||||||
|
String username,
|
||||||
|
String password,
|
||||||
|
String command,
|
||||||
|
long timeout, String prompt, String expect) {
|
||||||
|
TelnetTask rexec = new TelnetTask();
|
||||||
|
RunTask runner = new RunTask(rexec);
|
||||||
|
rexec.setServer(host);
|
||||||
|
rexec.setPort(port);
|
||||||
|
rexec.setUserid(username);
|
||||||
|
rexec.setPassword(password);
|
||||||
|
rexec.setTimeout((int) Math.round(timeout));
|
||||||
|
|
||||||
|
rexec.createRead().addText(prompt);
|
||||||
|
rexec.createWrite().addText(command);
|
||||||
|
rexec.createRead().addText(expect);
|
||||||
|
|
||||||
|
return runner.postTask();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,243 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2010 Brian Rosenberger (Brutex Network)
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package net.brutex.xservices.ws.impl;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import javax.jws.WebMethod;
|
||||||
|
import javax.jws.WebParam;
|
||||||
|
import javax.jws.WebService;
|
||||||
|
import net.brutex.xservices.types.ArchiveResource;
|
||||||
|
import net.brutex.xservices.types.FileResource;
|
||||||
|
import net.brutex.xservices.types.FileSetResource;
|
||||||
|
import net.brutex.xservices.types.ResourceInterface;
|
||||||
|
import net.brutex.xservices.types.ReturnCode;
|
||||||
|
import net.brutex.xservices.util.BrutexNamespaces;
|
||||||
|
import net.brutex.xservices.util.RunTask;
|
||||||
|
import net.brutex.xservices.ws.FileService;
|
||||||
|
import net.brutex.xservices.ws.XServicesFault;
|
||||||
|
|
||||||
|
import org.apache.tools.ant.taskdefs.Basename;
|
||||||
|
import org.apache.tools.ant.taskdefs.Chmod;
|
||||||
|
import org.apache.tools.ant.taskdefs.Copy;
|
||||||
|
import org.apache.tools.ant.taskdefs.Echo;
|
||||||
|
import org.apache.tools.ant.taskdefs.LoadResource;
|
||||||
|
import org.apache.tools.ant.taskdefs.optional.unix.Chgrp;
|
||||||
|
import org.apache.tools.ant.taskdefs.optional.unix.Chown;
|
||||||
|
import org.apache.tools.ant.types.FileSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Brian Rosenberger, bru@brutex.de
|
||||||
|
*/
|
||||||
|
@WebService(
|
||||||
|
targetNamespace = BrutexNamespaces.WS_XSERVICES,
|
||||||
|
endpointInterface ="net.brutex.xservices.ws.FileService",
|
||||||
|
name = "FileService"
|
||||||
|
)
|
||||||
|
public class FileServiceImpl implements FileService {
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.impl.FileService#basename(java.lang.String, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "basename")
|
||||||
|
public ReturnCode basename(@WebParam(name = "file") String filename,
|
||||||
|
@WebParam(name = "suffix") String suffix) {
|
||||||
|
return basename(new File(filename), suffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.impl.FileService#copy(net.brutex.xservices.types.FileSetResource, java.lang.String, boolean, boolean, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "copy")
|
||||||
|
public ReturnCode copy(@WebParam(name = "fileset") FileSetResource src,
|
||||||
|
@WebParam(name = "todir") String todir,
|
||||||
|
@WebParam(name = "preservelastmodified") boolean plm,
|
||||||
|
@WebParam(name = "overwrite") boolean overwrite,
|
||||||
|
@WebParam(name = "encoding") String encoding)
|
||||||
|
throws XServicesFault {
|
||||||
|
return copy(src, new File(todir), plm, overwrite, encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.impl.FileService#loadRes(net.brutex.xservices.types.FileResource, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "loadResource")
|
||||||
|
public ReturnCode loadRes(@WebParam(name = "resource") FileResource res,
|
||||||
|
@WebParam(name = "encoding") String encoding) {
|
||||||
|
if (encoding == null || encoding.equals("")) {
|
||||||
|
encoding = System.getProperty("file.encoding");
|
||||||
|
}
|
||||||
|
return loadResource(res, encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.impl.FileService#loadResFromArchive(net.brutex.xservices.types.ArchiveResource, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "loadResourceFromArchive")
|
||||||
|
public ReturnCode loadResFromArchive(@WebParam(name = "archiveresource") ArchiveResource res,
|
||||||
|
@WebParam(name = "encoding") String encoding) {
|
||||||
|
if (encoding == null || encoding.equals("")) {
|
||||||
|
encoding = System.getProperty("file.encoding");
|
||||||
|
}
|
||||||
|
return loadResource(res, encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.impl.FileService#echo2file(java.lang.String, java.lang.String, java.lang.String, boolean)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "echoToFile")
|
||||||
|
public ReturnCode echo2file(@WebParam(name = "message") String message,
|
||||||
|
@WebParam(name = "file") String file, @WebParam(name = "encoding") String encoding,
|
||||||
|
@WebParam(name = "append") boolean append) {
|
||||||
|
return echo(message, new File(file), encoding, append);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.impl.FileService#changeOwner(net.brutex.xservices.types.FileSetResource, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "changeOwner")
|
||||||
|
public ReturnCode changeOwner(@WebParam(name = "fileset") FileSetResource res,
|
||||||
|
@WebParam(name = "owner") String owner) {
|
||||||
|
return chown(res, owner);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.impl.FileService#changeGroup(net.brutex.xservices.types.FileSetResource, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "changeGroup")
|
||||||
|
public ReturnCode changeGroup(@WebParam(name = "fileset") FileSetResource res,
|
||||||
|
@WebParam(name = "group") String group) {
|
||||||
|
return chgrp(res, group);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.brutex.xservices.ws.impl.FileService#changeMode(net.brutex.xservices.types.FileSetResource, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebMethod(operationName = "changeMode")
|
||||||
|
public ReturnCode changeMode(@WebParam(name="fileset") FileSetResource res,
|
||||||
|
@WebParam(name="permissions") String perm) {
|
||||||
|
return chmod(res, perm);
|
||||||
|
}
|
||||||
|
|
||||||
|
@WebMethod(exclude = true)
|
||||||
|
private ReturnCode basename(File file,
|
||||||
|
String suffix) {
|
||||||
|
Basename basename = new Basename();
|
||||||
|
RunTask runner = new RunTask(basename);
|
||||||
|
basename.setFile(file);
|
||||||
|
if (suffix != null && !suffix.equals("")) {
|
||||||
|
basename.setSuffix(suffix);
|
||||||
|
}
|
||||||
|
basename.setProperty("basename.value");
|
||||||
|
return runner.postTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
@WebMethod(exclude = true)
|
||||||
|
private ReturnCode loadResource(ResourceInterface src, String encoding) {
|
||||||
|
LoadResource lr = new LoadResource();
|
||||||
|
lr.setTaskName("LoadResource");
|
||||||
|
RunTask runner = new RunTask(lr);
|
||||||
|
lr.addConfigured(src.getAntResource(lr.getProject()));
|
||||||
|
lr.setEncoding(encoding);
|
||||||
|
System.out.println("Using encoding: " + encoding);
|
||||||
|
lr.setProperty("LoadResource.out");
|
||||||
|
return runner.postTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
@WebMethod(exclude = true)
|
||||||
|
private ReturnCode echo(String msg, File file, String encoding, boolean append) {
|
||||||
|
Echo echo = new Echo();
|
||||||
|
echo.setTaskName("toFile");
|
||||||
|
RunTask runTask = new RunTask(echo);
|
||||||
|
echo.addText(msg);
|
||||||
|
echo.setEncoding(encoding);
|
||||||
|
echo.setFile(file);
|
||||||
|
echo.setAppend(append);
|
||||||
|
return runTask.postTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
@WebMethod(exclude = true)
|
||||||
|
private ReturnCode copy(FileSetResource src, File dst, boolean preservelastmodified,
|
||||||
|
boolean overwrite, String encoding) {
|
||||||
|
Copy copy = new Copy();
|
||||||
|
copy.setTaskName("Copy");
|
||||||
|
RunTask runner = new RunTask(copy);
|
||||||
|
FileSet set = src.getAntFileSet(copy.getProject());
|
||||||
|
copy.add(set);
|
||||||
|
|
||||||
|
if (dst.isDirectory()) {
|
||||||
|
copy.setTodir(dst);
|
||||||
|
}
|
||||||
|
if (dst.isFile()) {
|
||||||
|
copy.setTofile(dst);
|
||||||
|
}
|
||||||
|
copy.setOverwrite(overwrite);
|
||||||
|
copy.setPreserveLastModified(preservelastmodified);
|
||||||
|
if (encoding != null && !encoding.equals("")) {
|
||||||
|
copy.setOutputEncoding(encoding);
|
||||||
|
} else {
|
||||||
|
copy.setOutputEncoding(System.getProperty("file.encoding"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return runner.postTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
@WebMethod(exclude = true)
|
||||||
|
private ReturnCode chown(FileSetResource src, String owner) {
|
||||||
|
Chown chown = new Chown();
|
||||||
|
chown.setTaskName("Chown");
|
||||||
|
RunTask runner = new RunTask(chown);
|
||||||
|
chown.setOwner(owner);
|
||||||
|
FileSet set = src.getAntFileSet(chown.getProject());
|
||||||
|
chown.add(set);
|
||||||
|
chown.setMaxParallel(300);
|
||||||
|
return runner.postTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
@WebMethod(exclude = true)
|
||||||
|
private ReturnCode chgrp(FileSetResource src, String group) {
|
||||||
|
Chgrp chgrp = new Chgrp();
|
||||||
|
chgrp.setTaskName("Chgrp");
|
||||||
|
RunTask runner = new RunTask(chgrp);
|
||||||
|
chgrp.setGroup(group);
|
||||||
|
FileSet set = src.getAntFileSet(chgrp.getProject());
|
||||||
|
chgrp.add(set);
|
||||||
|
chgrp.setMaxParallel(300);
|
||||||
|
return runner.postTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
@WebMethod(exclude = true)
|
||||||
|
private ReturnCode chmod(FileSetResource src, String perm) {
|
||||||
|
Chmod chmod = new Chmod();
|
||||||
|
chmod.setTaskName("Chmod");
|
||||||
|
RunTask runner = new RunTask(chmod);
|
||||||
|
FileSet set = src.getAntFileSet(chmod.getProject());
|
||||||
|
chmod.add(set);
|
||||||
|
chmod.setMaxParallel(300);
|
||||||
|
chmod.setPerm(perm);
|
||||||
|
chmod.setVerbose(true);
|
||||||
|
return runner.postTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,132 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2010 Brian Rosenberger (Brutex Network)
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.brutex.xservices.ws.impl;
|
||||||
|
|
||||||
|
import javax.jws.WebService;
|
||||||
|
import net.brutex.xservices.types.FileSetResource;
|
||||||
|
import net.brutex.xservices.types.HostConnection;
|
||||||
|
import net.brutex.xservices.types.MailMimeType;
|
||||||
|
import net.brutex.xservices.types.ReturnCode;
|
||||||
|
import net.brutex.xservices.util.BrutexNamespaces;
|
||||||
|
import net.brutex.xservices.util.RunTask;
|
||||||
|
import net.brutex.xservices.ws.MiscService;
|
||||||
|
|
||||||
|
import org.apache.cxf.annotations.WSDLDocumentation;
|
||||||
|
import org.apache.cxf.annotations.WSDLDocumentationCollection;
|
||||||
|
import org.apache.tools.ant.taskdefs.HostInfo;
|
||||||
|
import org.apache.tools.ant.taskdefs.Sleep;
|
||||||
|
import org.apache.tools.ant.taskdefs.email.EmailTask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Brian Rosenberger, bru@brutex.de
|
||||||
|
*/
|
||||||
|
@WSDLDocumentationCollection({
|
||||||
|
@WSDLDocumentation("My portType documentation"),
|
||||||
|
@WSDLDocumentation(value = "My top level documentation", placement = WSDLDocumentation.Placement.TOP),
|
||||||
|
@WSDLDocumentation(value = "My binding doc", placement = WSDLDocumentation.Placement.BINDING) })
|
||||||
|
@WebService(
|
||||||
|
targetNamespace = BrutexNamespaces.WS_XSERVICES,
|
||||||
|
endpointInterface = "net.brutex.xservices.ws.MiscService",
|
||||||
|
serviceName = "MiscService"
|
||||||
|
)
|
||||||
|
public class MiscServiceImpl implements MiscService {
|
||||||
|
|
||||||
|
@WSDLDocumentation(value = "Get information about a host.")
|
||||||
|
public ReturnCode getHostinfo(String hostname) {
|
||||||
|
return antGetHostinfo(hostname, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReturnCode sendMailSimple(HostConnection mailhost, String from,
|
||||||
|
String tolist, String subject, String message) {
|
||||||
|
return sendMail(from, from, tolist, "", "", subject, message,
|
||||||
|
"text/plain", null, mailhost.hostname, mailhost.port,
|
||||||
|
mailhost.user, mailhost.password, "utf-8", false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReturnCode sendMailSimpleWithAttachment(HostConnection mailhost,
|
||||||
|
String from, String tolist, String subject, String message,
|
||||||
|
FileSetResource res) {
|
||||||
|
return sendMail(from, from, tolist, "", "", subject, message,
|
||||||
|
"text/plain", res, mailhost.hostname, mailhost.port,
|
||||||
|
mailhost.user, mailhost.password, "utf-8", false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReturnCode sendMail(HostConnection mailhost, String from,
|
||||||
|
String tolist, String cclist, String bcclist, String subject,
|
||||||
|
MailMimeType mimetype, String charset, String message,
|
||||||
|
FileSetResource res, boolean ssl, boolean tls) {
|
||||||
|
return sendMail(from, from, tolist, cclist, bcclist, subject, message,
|
||||||
|
mimetype.value(), res, mailhost.hostname, mailhost.port,
|
||||||
|
mailhost.user, mailhost.password, charset, tls, ssl);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReturnCode sleep(int minutes, int seconds) {
|
||||||
|
return sleep(0, minutes, seconds, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ReturnCode antGetHostinfo(String hostname, String prefix) {
|
||||||
|
HostInfo info = new HostInfo();
|
||||||
|
info.setTaskName("HostInfo");
|
||||||
|
RunTask runner = new RunTask(info);
|
||||||
|
info.setHost(hostname);
|
||||||
|
// info.setPrefix(prefix);
|
||||||
|
return runner.postTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ReturnCode sendMail(String from, String replyto, String tolist,
|
||||||
|
String cclist, String bcclist, String subject, String message,
|
||||||
|
String messagemimetype, FileSetResource attachments,
|
||||||
|
String mailhost, int mailport, String user, String password,
|
||||||
|
String charset, boolean tls, boolean ssl) {
|
||||||
|
EmailTask mail = new EmailTask();
|
||||||
|
mail.setTaskName("Mail");
|
||||||
|
RunTask runner = new RunTask(mail);
|
||||||
|
mail.setFrom(from);
|
||||||
|
mail.setReplyTo(replyto);
|
||||||
|
mail.setToList(tolist);
|
||||||
|
mail.setCcList(cclist);
|
||||||
|
mail.setBccList(bcclist);
|
||||||
|
mail.setSubject(subject);
|
||||||
|
mail.setMessage(message);
|
||||||
|
mail.setMessageMimeType(messagemimetype);
|
||||||
|
if (attachments != null) {
|
||||||
|
mail.addFileset(attachments.getAntFileSet(mail.getProject()));
|
||||||
|
}
|
||||||
|
mail.setMailhost(mailhost);
|
||||||
|
mail.setMailport(mailport);
|
||||||
|
mail.setUser(user);
|
||||||
|
mail.setPassword(password);
|
||||||
|
mail.setCharset(charset);
|
||||||
|
mail.setSSL(ssl);
|
||||||
|
mail.setEnableStartTLS(tls);
|
||||||
|
return runner.postTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ReturnCode sleep(int hours, int minutes, int seconds,
|
||||||
|
int milliseconds) {
|
||||||
|
Sleep sleep = new Sleep();
|
||||||
|
sleep.setTaskName("Sleep");
|
||||||
|
RunTask runner = new RunTask(sleep);
|
||||||
|
sleep.setHours(hours);
|
||||||
|
sleep.setMinutes(minutes);
|
||||||
|
sleep.setSeconds(seconds);
|
||||||
|
sleep.setMilliseconds(milliseconds);
|
||||||
|
return runner.postTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue