Change return typ for all web service operations to "ReturnCode". FileServices have now two additional operations "changeOwner" and "changeGroup".
git-svn-id: https://brutex.net/svn/xservices/trunk@12 e7e49efb-446e-492e-b9ec-fcafc1997a86tag-20130205r
parent
f38a378f68
commit
1119f49c34
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package net.brutex.xservices.types;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author brian
|
||||
*/
|
||||
@XmlRootElement
|
||||
public class AntProperty {
|
||||
|
||||
@XmlElement(required=true)
|
||||
public String name ="";
|
||||
|
||||
@XmlElement(required=true)
|
||||
public String value="";
|
||||
|
||||
public static List<AntProperty> createAntPropertyList(Map<String, String> map) {
|
||||
List<AntProperty> list = new ArrayList<AntProperty>();
|
||||
for(Map.Entry<String, String> e : map.entrySet()) {
|
||||
list.add(new AntProperty(e.getKey(), e.getValue()));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public AntProperty(String name, String value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public AntProperty() {
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package net.brutex.xservices.types;
|
||||
|
||||
import java.util.List;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import net.brutex.xservices.util.BrutexNamespaces;
|
||||
|
@ -55,6 +56,10 @@ public class ReturnCode {
|
|||
@XmlElement(name="stdErr", nillable=false)
|
||||
public String stdErr="";
|
||||
|
||||
|
||||
@XmlElement(name="propertyList", nillable=true)
|
||||
public List<AntProperty> property = null;
|
||||
|
||||
/**
|
||||
* Create a new ReturnCode default constructor.
|
||||
*/
|
||||
|
@ -68,9 +73,10 @@ public class ReturnCode {
|
|||
* @param stdOut standard out string
|
||||
* @param stdErr standard error string
|
||||
*/
|
||||
public ReturnCode(int returnCode, String stdOut, String stdErr) {
|
||||
public ReturnCode(int returnCode, String stdOut, String stdErr, List<AntProperty> props) {
|
||||
this.returnCode = returnCode;
|
||||
this.stdOut = stdOut;
|
||||
this.stdErr = stdErr;
|
||||
this.property = props;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,17 +13,15 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.brutex.xservices.util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.util.Iterator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
import net.brutex.xservices.types.AntProperty;
|
||||
import net.brutex.xservices.types.ReturnCode;
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.BuildListener;
|
||||
import org.apache.tools.ant.BuildLogger;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.Target;
|
||||
import org.apache.tools.ant.Task;
|
||||
|
@ -39,7 +37,6 @@ public class RunTask {
|
|||
Project antproject;
|
||||
Target anttarget;
|
||||
Task anttask;
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream err = new ByteArrayOutputStream();
|
||||
TimestampedLogger log = null;
|
||||
|
@ -74,19 +71,28 @@ public class RunTask {
|
|||
antproject.addOrReplaceTarget(anttarget);
|
||||
}
|
||||
|
||||
public Map<String, String> postTask()
|
||||
throws BuildException
|
||||
{
|
||||
public ReturnCode postTask() {
|
||||
int returnCode = 0;
|
||||
Map<String, String> origMap = new HashMap<String, String>();
|
||||
Map<String, String> newMap = null;
|
||||
origMap.putAll(antproject.getProperties());
|
||||
try {
|
||||
antproject.executeTarget(anttarget.getName());
|
||||
} catch (Exception ex) {
|
||||
} catch (BuildException ex) {
|
||||
new PrintStream(err).println(ex.getMessage());
|
||||
returnCode = 1;
|
||||
}
|
||||
Map<String, String> map = antproject.getProperties();
|
||||
map.put("System.stdOut", out.toString());
|
||||
map.put("System.stdErr", err.toString());
|
||||
newMap = antproject.getProperties();
|
||||
|
||||
for (Map.Entry<String, String> e : origMap.entrySet()) {
|
||||
newMap.remove(e.getKey());
|
||||
}
|
||||
|
||||
//anttask.execute();
|
||||
return map;
|
||||
return new ReturnCode(returnCode,
|
||||
out.toString(),
|
||||
err.toString(),
|
||||
AntProperty.createAntPropertyList(newMap));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.brutex.xservices.ws;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -50,14 +49,12 @@ public class ArchiveService {
|
|||
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";
|
||||
|
||||
|
@ -74,19 +71,19 @@ public class ArchiveService {
|
|||
}
|
||||
|
||||
@WebMethod(operationName = WS_OPERATION_GZIP, action = WS_OPERATION_GZIP)
|
||||
public String 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) {
|
||||
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,
|
||||
public ReturnCode 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,
|
||||
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) {
|
||||
|
@ -96,7 +93,7 @@ public class ArchiveService {
|
|||
}
|
||||
|
||||
@WebMethod(operationName = WS_OPERATION_BUNZIP2)
|
||||
public String 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) {
|
||||
File target = null;
|
||||
if (!dest.equals("") && dest != null) {
|
||||
|
@ -106,7 +103,7 @@ public class ArchiveService {
|
|||
}
|
||||
|
||||
@WebMethod(operationName = "gunzipFromURL")
|
||||
public String 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) {
|
||||
File target = null;
|
||||
if (!dest.equals("") && dest != null) {
|
||||
|
@ -116,7 +113,7 @@ public class ArchiveService {
|
|||
}
|
||||
|
||||
@WebMethod(operationName = "bunzip2FromURL")
|
||||
public String 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) {
|
||||
File target = null;
|
||||
if (!dest.equals("") && dest != null) {
|
||||
|
@ -126,7 +123,7 @@ public class ArchiveService {
|
|||
}
|
||||
|
||||
@WebMethod(operationName = "zip")
|
||||
public String 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_OVERWRITE) boolean overwrite,
|
||||
@WebParam(name = WS_PARAM_ENCODING) String encoding,
|
||||
|
@ -141,7 +138,7 @@ public class ArchiveService {
|
|||
}
|
||||
|
||||
@WebMethod(operationName = "zipFromArchive")
|
||||
public String 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_OVERWRITE) boolean update,
|
||||
@WebParam(name = WS_PARAM_ENCODING) String encoding,
|
||||
|
@ -149,9 +146,8 @@ public class ArchiveService {
|
|||
return zip(src, new File(file), encoding, !update, level);
|
||||
}
|
||||
|
||||
|
||||
@WebMethod(operationName = "unzip")
|
||||
public String 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_OVERWRITE) boolean overwrite,
|
||||
@WebParam(name = WS_PARAM_ENCODING) String encoding) {
|
||||
|
@ -159,13 +155,13 @@ public class ArchiveService {
|
|||
}
|
||||
|
||||
@WebMethod(operationName = "unrar")
|
||||
public String 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) {
|
||||
return unrar(new File(src), new File(dest));
|
||||
}
|
||||
|
||||
@WebMethod(operationName = "untar")
|
||||
public String 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_OVERWRITE) boolean overwrite,
|
||||
@WebParam(name = "compression") CompressionType compression) {
|
||||
|
@ -195,12 +191,11 @@ public class ArchiveService {
|
|||
bzip.setSrcResource(src.getAntResource(bzip.getProject()));
|
||||
bzip.setDestfile(dst);
|
||||
|
||||
Map<String, String> result = runner.postTask();
|
||||
return new ReturnCode(0,result.get("System.stdOut"),result.get("System.stdErr"));
|
||||
return runner.postTask();
|
||||
}
|
||||
|
||||
@WebMethod(exclude = true)
|
||||
private String gzip(ResourceInterface src, File dst) {
|
||||
private ReturnCode gzip(ResourceInterface src, File dst) {
|
||||
if (dst.exists() && dst.isFile()) {
|
||||
dst.delete();
|
||||
}
|
||||
|
@ -209,14 +204,11 @@ public class ArchiveService {
|
|||
RunTask runner = new RunTask(gzip);
|
||||
gzip.addConfigured(src.getAntResource(gzip.getProject()));
|
||||
gzip.setDestfile(dst);
|
||||
Map<String, String> result = runner.postTask();
|
||||
return "complete";
|
||||
return runner.postTask();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@WebMethod(exclude = true)
|
||||
private String zip(ResourceInterface src, File dst, String encoding, boolean update, int compresslevel) {
|
||||
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);
|
||||
|
@ -227,12 +219,11 @@ public class ArchiveService {
|
|||
}
|
||||
zip.setUpdate(update);
|
||||
zip.setLevel(compresslevel);
|
||||
Map<String, String> result = runner.postTask();
|
||||
return "complete";
|
||||
return runner.postTask();
|
||||
}
|
||||
|
||||
@WebMethod(exclude = true)
|
||||
private String GUnzip(ResourceInterface src, File dst) {
|
||||
private ReturnCode GUnzip(ResourceInterface src, File dst) {
|
||||
GUnzip uz = new GUnzip();
|
||||
uz.setTaskName("GUnzip");
|
||||
RunTask runner = new RunTask(uz);
|
||||
|
@ -240,12 +231,11 @@ public class ArchiveService {
|
|||
if (dst != null) {
|
||||
uz.setDest(dst);
|
||||
}
|
||||
Map<String, String> result = runner.postTask();
|
||||
return "complete";
|
||||
return runner.postTask();
|
||||
}
|
||||
|
||||
@WebMethod(exclude = true)
|
||||
private String BUnzip2(ResourceInterface src, File dst) {
|
||||
private ReturnCode BUnzip2(ResourceInterface src, File dst) {
|
||||
BUnzip2 uz = new BUnzip2();
|
||||
uz.setTaskName("BUnzip2");
|
||||
RunTask runner = new RunTask(uz);
|
||||
|
@ -253,12 +243,11 @@ public class ArchiveService {
|
|||
if (dst != null) {
|
||||
uz.setDest(dst);
|
||||
}
|
||||
Map<String, String> result = runner.postTask();
|
||||
return "complete";
|
||||
return runner.postTask();
|
||||
}
|
||||
|
||||
@WebMethod(exclude = true)
|
||||
private String unzip(File src, File dest, boolean overwrite, String encoding) {
|
||||
private ReturnCode unzip(File src, File dest, boolean overwrite, String encoding) {
|
||||
Expand unzip = new Expand();
|
||||
unzip.setTaskName("UnZip");
|
||||
RunTask runner = new RunTask(unzip);
|
||||
|
@ -268,13 +257,11 @@ public class ArchiveService {
|
|||
if (encoding != null && !encoding.equals("")) {
|
||||
unzip.setEncoding(encoding);
|
||||
}
|
||||
|
||||
Map<String, String> result = runner.postTask();
|
||||
return "complete";
|
||||
return runner.postTask();
|
||||
}
|
||||
|
||||
@WebMethod(exclude = true)
|
||||
private String untar(File src, File dest, boolean overwrite, Untar.UntarCompressionMethod compression) {
|
||||
private ReturnCode untar(File src, File dest, boolean overwrite, Untar.UntarCompressionMethod compression) {
|
||||
Untar unzip = new Untar();
|
||||
unzip.setTaskName("Untar");
|
||||
RunTask runner = new RunTask(unzip);
|
||||
|
@ -282,20 +269,16 @@ public class ArchiveService {
|
|||
unzip.setDest(dest);
|
||||
unzip.setOverwrite(overwrite);
|
||||
unzip.setCompression(compression);
|
||||
Map<String, String> result = runner.postTask();
|
||||
return "complete";
|
||||
return runner.postTask();
|
||||
}
|
||||
|
||||
@WebMethod(exclude = true)
|
||||
private String unrar(File src, File dst) {
|
||||
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);
|
||||
Map<String, String> result = runner.postTask();
|
||||
return "complete";
|
||||
return runner.postTask();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -155,11 +155,19 @@ public class ExecuteService {
|
|||
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.setExecutable(executable);
|
||||
for (String s : args) {
|
||||
exe.createArg().setValue(s);
|
||||
}
|
||||
|
||||
exe.setDir(dir);
|
||||
if (spawn) {
|
||||
exe.setSpawn(spawn);
|
||||
|
@ -175,15 +183,7 @@ public class ExecuteService {
|
|||
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;
|
||||
return runner.postTask();
|
||||
}
|
||||
|
||||
@WebMethod(exclude = true)
|
||||
|
@ -203,12 +203,7 @@ public class ExecuteService {
|
|||
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;
|
||||
return runner.postTask();
|
||||
}
|
||||
|
||||
@WebMethod(exclude = true)
|
||||
|
@ -230,12 +225,7 @@ public class ExecuteService {
|
|||
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;
|
||||
return runner.postTask();
|
||||
}
|
||||
|
||||
@WebMethod(exclude = true)
|
||||
|
@ -254,12 +244,7 @@ public class ExecuteService {
|
|||
rexec.setCommand(command);
|
||||
rexec.setTimeout((int) Math.round(timeout));
|
||||
|
||||
Map<String, String> result = runner.postTask();
|
||||
ReturnCode res = null;
|
||||
res = new ReturnCode(0,
|
||||
"", "");
|
||||
|
||||
return res;
|
||||
return runner.postTask();
|
||||
}
|
||||
|
||||
@WebMethod(exclude = true)
|
||||
|
@ -281,10 +266,6 @@ public class ExecuteService {
|
|||
rexec.createWrite().addText(command);
|
||||
rexec.createRead().addText(expect);
|
||||
|
||||
Map<String, String> result = runner.postTask();
|
||||
ReturnCode res = null;
|
||||
res = new ReturnCode(0,
|
||||
"", "");
|
||||
return res;
|
||||
return runner.postTask();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
* 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;
|
||||
|
@ -25,11 +23,14 @@ 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.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.taskdefs.optional.unix.Chgrp;
|
||||
import org.apache.tools.ant.taskdefs.optional.unix.Chown;
|
||||
import org.apache.tools.ant.types.FileSet;
|
||||
|
||||
/**
|
||||
|
@ -40,27 +41,23 @@ import org.apache.tools.ant.types.FileSet;
|
|||
public class FileService {
|
||||
|
||||
@WebMethod(operationName = "basename")
|
||||
public String basename(@WebParam(name = "file") String filename,
|
||||
public ReturnCode 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,
|
||||
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 {
|
||||
try {
|
||||
copy(src, new File(todir), plm, overwrite, encoding);
|
||||
} catch (Exception ex) {
|
||||
throw new XServicesFault(ex.getMessage(), ex);
|
||||
}
|
||||
return copy(src, new File(todir), plm, overwrite, encoding);
|
||||
}
|
||||
|
||||
@WebMethod(operationName = "loadResource")
|
||||
public String loadRes(@WebParam(name = "resource") FileResource res,
|
||||
public ReturnCode loadRes(@WebParam(name = "resource") FileResource res,
|
||||
@WebParam(name = "encoding") String encoding) {
|
||||
if (encoding == null || encoding.equals("")) {
|
||||
encoding = System.getProperty("file.encoding");
|
||||
|
@ -69,7 +66,7 @@ public class FileService {
|
|||
}
|
||||
|
||||
@WebMethod(operationName = "loadResourceFromArchive")
|
||||
public String loadResFromArchive(@WebParam(name = "archiveresource") ArchiveResource res,
|
||||
public ReturnCode loadResFromArchive(@WebParam(name = "archiveresource") ArchiveResource res,
|
||||
@WebParam(name = "encoding") String encoding) {
|
||||
if (encoding == null || encoding.equals("")) {
|
||||
encoding = System.getProperty("file.encoding");
|
||||
|
@ -78,14 +75,26 @@ public class FileService {
|
|||
}
|
||||
|
||||
@WebMethod(operationName = "echoToFile")
|
||||
public String echo2file(@WebParam(name="message") String message,
|
||||
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(exclude = true)
|
||||
private String basename(File file,
|
||||
private ReturnCode basename(File file,
|
||||
String suffix) {
|
||||
Basename basename = new Basename();
|
||||
RunTask runner = new RunTask(basename);
|
||||
|
@ -94,11 +103,11 @@ public class FileService {
|
|||
basename.setSuffix(suffix);
|
||||
}
|
||||
basename.setProperty("basename.value");
|
||||
Map<String, String> result = runner.postTask();
|
||||
return result.get("basename.value");
|
||||
return runner.postTask();
|
||||
}
|
||||
|
||||
@WebMethod(exclude = true)
|
||||
private String loadResource(ResourceInterface src, String encoding) {
|
||||
private ReturnCode loadResource(ResourceInterface src, String encoding) {
|
||||
LoadResource lr = new LoadResource();
|
||||
lr.setTaskName("LoadResource");
|
||||
RunTask runner = new RunTask(lr);
|
||||
|
@ -106,12 +115,11 @@ public class FileService {
|
|||
lr.setEncoding(encoding);
|
||||
System.out.println("Using encoding: " + encoding);
|
||||
lr.setProperty("LoadResource.out");
|
||||
Map<String, String> result = runner.postTask();
|
||||
return result.get("LoadResource.out");
|
||||
return runner.postTask();
|
||||
}
|
||||
|
||||
@WebMethod(exclude = true)
|
||||
private String echo(String msg, File file, String encoding, boolean append) {
|
||||
private ReturnCode echo(String msg, File file, String encoding, boolean append) {
|
||||
Echo echo = new Echo();
|
||||
echo.setTaskName("toFile");
|
||||
RunTask runTask = new RunTask(echo);
|
||||
|
@ -119,12 +127,11 @@ public class FileService {
|
|||
echo.setEncoding(encoding);
|
||||
echo.setFile(file);
|
||||
echo.setAppend(append);
|
||||
Map<String, String> result = runTask.postTask();
|
||||
return "complete";
|
||||
return runTask.postTask();
|
||||
}
|
||||
|
||||
@WebMethod(exclude = true)
|
||||
private void copy(FileSetResource src, File dst, boolean preservelastmodified,
|
||||
private ReturnCode copy(FileSetResource src, File dst, boolean preservelastmodified,
|
||||
boolean overwrite, String encoding) {
|
||||
Copy copy = new Copy();
|
||||
copy.setTaskName("Copy");
|
||||
|
@ -132,8 +139,12 @@ public class FileService {
|
|||
FileSet set = src.getAntFileSet(copy.getProject());
|
||||
copy.add(set);
|
||||
|
||||
if(dst.isDirectory()) copy.setTodir(dst);
|
||||
if(dst.isFile()) copy.setTofile(dst);
|
||||
if (dst.isDirectory()) {
|
||||
copy.setTodir(dst);
|
||||
}
|
||||
if (dst.isFile()) {
|
||||
copy.setTofile(dst);
|
||||
}
|
||||
copy.setOverwrite(overwrite);
|
||||
copy.setPreserveLastModified(preservelastmodified);
|
||||
if (encoding != null && !encoding.equals("")) {
|
||||
|
@ -142,6 +153,28 @@ public class FileService {
|
|||
copy.setOutputEncoding(System.getProperty("file.encoding"));
|
||||
}
|
||||
|
||||
Map<String, String> result = runner.postTask();
|
||||
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);
|
||||
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);
|
||||
return runner.postTask();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue