Subversion Repositories XServices

Compare Revisions

Ignore whitespace Rev 5 → Rev 6

/xservices/trunk/src/java/net/brutex/xservices/ws/FileService.java
0,0 → 1,147
/*
* 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 java.io.File;
import java.util.Map;
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.util.RunTask;
import org.apache.tools.ant.taskdefs.Basename;
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.types.FileSet;
 
/**
*
* @author Brian Rosenberger, bru@brutex.de
*/
@WebService(targetNamespace="http://ws.xservices.brutex.net", name="FileService")
public class FileService {
 
@WebMethod(operationName = "basename")
public String basename(@WebParam(name = "file") String filename,
@WebParam(name = "suffix") String suffix) {
return basename(new File(filename), suffix);
}
 
@WebMethod(operationName = "copy")
public void 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 {
try {
copy(src, new File(todir), plm, overwrite, encoding);
} catch (Exception ex) {
throw new XServicesFault(ex.getMessage(), ex);
}
}
 
@WebMethod(operationName = "loadResource")
public String 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 String 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 String 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(exclude = true)
private String 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");
Map<String, String> result = runner.postTask();
return result.get("basename.value");
}
@WebMethod(exclude = true)
private String 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");
Map<String, String> result = runner.postTask();
return result.get("LoadResource.out");
}
 
@WebMethod(exclude = true)
private String 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);
Map<String, String> result = runTask.postTask();
return "complete";
}
 
@WebMethod(exclude=true)
private void 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"));
}
 
Map<String, String> result = runner.postTask();
}
}
/xservices/trunk/src/java/net/brutex/xservices/ws/ArchiveService.java
0,0 → 1,300
/*
* 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 java.io.File;
import java.util.Map;
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.util.RunTask;
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
*/
@WebService(targetNamespace="http://ws.xservices.brutex.net", name="ArchiveService")
public class ArchiveService {
 
public static final String WS_OPERATION_BZIP2 = "bzip2";
public static final String WS_OPERATION_BZIP2_ARCHIVE = "bzip2FromArchive";
public static final String WS_OPERATION_GZIP = "gzip";
public static final String WS_OPERATION_GZIP_ARCHIVE = "gzipFromArchive";
public static final String WS_OPERATION_UNZIP = "unzip";
public static final String WS_OPERATION_GUNZIP = "gunzip";
public static final String WS_OPERATION_BUNZIP2 = "bunzip2";
 
public static final String WS_PARAM_SOURCEFILE = "source";
public static final String WS_PARAM_SOURCEFILE_STRING = "srcfile";
public static final String WS_PARAM_SOURCEURL = "srcurl";
public static final String WS_PARAM_SOURCEARCHIVE = "archivesource";
public static final String WS_PARAM_DESTFILE = "destfile";
public static final String WS_PARAM_DESTDIR = "destdir";
 
public static final String WS_PARAM_ENCODING = "encoding";
public static final String WS_PARAM_OVERWRITE= "overwrite";
 
@WebMethod(operationName = WS_OPERATION_BZIP2, action=WS_OPERATION_BZIP2)
public String bzip2(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
@WebParam(name = WS_PARAM_DESTFILE) String file) {
return bzip(src, new File(file));
}
 
@WebMethod(operationName = WS_OPERATION_BZIP2_ARCHIVE, action=WS_OPERATION_BZIP2_ARCHIVE)
public String bzip2FromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
@WebParam(name = WS_PARAM_DESTFILE) String file) {
return bzip(src, new File(file));
}
 
@WebMethod(operationName = WS_OPERATION_GZIP, action=WS_OPERATION_GZIP)
public String gzip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
@WebParam(name = WS_PARAM_DESTFILE) String file) {
return gzip(src, new File(file));
}
 
@WebMethod(operationName = WS_OPERATION_GZIP_ARCHIVE, action=WS_OPERATION_GZIP_ARCHIVE)
public String gzipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
@WebParam(name = WS_PARAM_DESTFILE) String file) {
return gzip(src, new File(file));
}
 
@WebMethod(operationName = WS_OPERATION_GUNZIP, action=WS_OPERATION_GUNZIP)
public String 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);
}
 
@WebMethod(operationName = WS_OPERATION_BUNZIP2)
public String 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);
}
 
@WebMethod(operationName = "gunzipFromURL")
public String 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);
}
 
@WebMethod(operationName = "bunzip2FromURL")
public String 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);
}
 
@WebMethod(operationName = "zip")
public String 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);
}
 
@WebMethod(operationName = "zipFromArchive")
public String 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);
}
 
 
@WebMethod(operationName = "unzip")
public String 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);
}
 
@WebMethod(operationName = "unrar")
public String unrar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
return unrar(new File(src), new File(dest));
}
 
@WebMethod(operationName = "untar")
public String 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 String 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);
 
Map<String, String> result = runner.postTask();
return "complete";
}
 
@WebMethod(exclude = true)
private String 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);
Map<String, String> result = runner.postTask();
return "complete";
}
 
 
 
@WebMethod(exclude = true)
private String 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);
Map<String, String> result = runner.postTask();
return "complete";
}
 
@WebMethod(exclude = true)
private String 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);
}
Map<String, String> result = runner.postTask();
return "complete";
}
 
@WebMethod(exclude = true)
private String 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);
}
Map<String, String> result = runner.postTask();
return "complete";
}
 
@WebMethod(exclude = true)
private String 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);
}
 
Map<String, String> result = runner.postTask();
return "complete";
}
 
@WebMethod(exclude = true)
private String 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);
Map<String, String> result = runner.postTask();
return "complete";
}
 
@WebMethod(exclude = true)
private String unrar(File src, File dst) {
UnRarTask unrar = new UnRarTask();
unrar.setTaskName("UnRar");
RunTask runner = new RunTask(unrar);
unrar.setSrc(src);
unrar.setDst(dst);
Map<String, String> result = runner.postTask();
return "complete";
}
 
}
/xservices/trunk/src/java/net/brutex/xservices/ws/ExecuteService.java
0,0 → 1,290
/*
* 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 java.io.File;
import java.util.Map;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import net.brutex.xservices.types.ReturnCode;
import net.brutex.xservices.util.RunTask;
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="http://ws.xservices.brutex.net", name="ExecuteService")
public class ExecuteService {
 
@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);
}
 
@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);
}
 
@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") 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 rexec(host, port, username, password, cmd, timeout);
}
 
@WebMethod(operationName = "telnet")
public ReturnCode runTelnet(@WebParam(name = "host") String host,
@WebParam(name = "port") int port,
@WebParam(name = "username") String username,
@WebParam(name = "password") String password,
@WebParam(name = "prompt") String prompt,
@WebParam(name = "command") String cmd,
@WebParam(name = "expect") String expect,
@WebParam(name = "timeout") long timeout) {
return telnet(host, port, username, 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.setCommand(cmdl);
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);
 
Map<String, String> result = runner.postTask();
ReturnCode res = null;
if (spawn) {
res = new ReturnCode(0, null, null);
} else {
res = new ReturnCode(Integer.valueOf(result.get("ExecuteService.result")),
result.get("ExecuteService.stdout"), result.get("ExecuteService.stderr"));
}
return res;
}
 
@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");
Map<String, String> result = runner.postTask();
ReturnCode res = null;
res = new ReturnCode(0,
result.get("SSHExec.stdout"), "");
 
return res;
}
 
@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");
Map<String, String> result = runner.postTask();
ReturnCode res = null;
res = new ReturnCode(0,
result.get("SSHExec.stdout"), "");
 
return res;
}
 
@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));
 
Map<String, String> result = runner.postTask();
ReturnCode res = null;
res = new ReturnCode(0,
"", "");
 
return res;
}
 
@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);
 
Map<String, String> result = runner.postTask();
ReturnCode res = null;
res = new ReturnCode(0,
"", "");
return res;
}
}
/xservices/trunk/src/java/net/brutex/xservices/ws/XServicesFault.java
0,0 → 1,67
/*
* 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 java.util.GregorianCalendar;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
 
/**
*
* @author Brian Rosenberger, bru@brutex.de
*/
public class XServicesFault extends Exception {
 
public XServicesFault(String message, Exception e) {
this(message, e.getCause());
}
 
public XServicesFault(String string) {
this(string, new Exception(string).getCause());
}
 
public XServicesFault(Exception e) {
this(e.getMessage(), e.getCause());
}
 
public XServicesFault(String message, Throwable cause) {
super(message, cause);
this.faultstring=message;
 
try {
timestamp = DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar());
} catch (DatatypeConfigurationException ex) {
System.err.println(ex.getMessage());
}
 
 
}
@XmlElement(name="faultstring")
public String faultstring = "";
 
@XmlElement(name="username")
public String username = System.getProperty("user.name");
 
@XmlElement(name="homedir")
public String homedir = System.getProperty("user.home");
 
@XmlElement(name="timstamp")
public XMLGregorianCalendar timestamp = null;
}