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;
|
package net.brutex.xservices.types;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlType;
|
import javax.xml.bind.annotation.XmlType;
|
||||||
import net.brutex.xservices.util.BrutexNamespaces;
|
import net.brutex.xservices.util.BrutexNamespaces;
|
||||||
|
@ -55,6 +56,10 @@ public class ReturnCode {
|
||||||
@XmlElement(name="stdErr", nillable=false)
|
@XmlElement(name="stdErr", nillable=false)
|
||||||
public String stdErr="";
|
public String stdErr="";
|
||||||
|
|
||||||
|
|
||||||
|
@XmlElement(name="propertyList", nillable=true)
|
||||||
|
public List<AntProperty> property = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new ReturnCode default constructor.
|
* Create a new ReturnCode default constructor.
|
||||||
*/
|
*/
|
||||||
|
@ -68,9 +73,10 @@ public class ReturnCode {
|
||||||
* @param stdOut standard out string
|
* @param stdOut standard out string
|
||||||
* @param stdErr standard error 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.returnCode = returnCode;
|
||||||
this.stdOut = stdOut;
|
this.stdOut = stdOut;
|
||||||
this.stdErr = stdErr;
|
this.stdErr = stdErr;
|
||||||
|
this.property = props;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,17 +13,15 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.brutex.xservices.util;
|
package net.brutex.xservices.util;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.util.Iterator;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
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.BuildException;
|
||||||
import org.apache.tools.ant.BuildListener;
|
|
||||||
import org.apache.tools.ant.BuildLogger;
|
|
||||||
import org.apache.tools.ant.Project;
|
import org.apache.tools.ant.Project;
|
||||||
import org.apache.tools.ant.Target;
|
import org.apache.tools.ant.Target;
|
||||||
import org.apache.tools.ant.Task;
|
import org.apache.tools.ant.Task;
|
||||||
|
@ -39,7 +37,6 @@ public class RunTask {
|
||||||
Project antproject;
|
Project antproject;
|
||||||
Target anttarget;
|
Target anttarget;
|
||||||
Task anttask;
|
Task anttask;
|
||||||
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
ByteArrayOutputStream err = new ByteArrayOutputStream();
|
ByteArrayOutputStream err = new ByteArrayOutputStream();
|
||||||
TimestampedLogger log = null;
|
TimestampedLogger log = null;
|
||||||
|
@ -74,19 +71,28 @@ public class RunTask {
|
||||||
antproject.addOrReplaceTarget(anttarget);
|
antproject.addOrReplaceTarget(anttarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> postTask()
|
public ReturnCode postTask() {
|
||||||
throws BuildException
|
int returnCode = 0;
|
||||||
{
|
Map<String, String> origMap = new HashMap<String, String>();
|
||||||
|
Map<String, String> newMap = null;
|
||||||
|
origMap.putAll(antproject.getProperties());
|
||||||
try {
|
try {
|
||||||
antproject.executeTarget(anttarget.getName());
|
antproject.executeTarget(anttarget.getName());
|
||||||
} catch (Exception ex) {
|
} catch (BuildException ex) {
|
||||||
new PrintStream(err).println(ex.getMessage());
|
new PrintStream(err).println(ex.getMessage());
|
||||||
|
returnCode = 1;
|
||||||
}
|
}
|
||||||
Map<String, String> map = antproject.getProperties();
|
newMap = antproject.getProperties();
|
||||||
map.put("System.stdOut", out.toString());
|
|
||||||
map.put("System.stdErr", err.toString());
|
for (Map.Entry<String, String> e : origMap.entrySet()) {
|
||||||
|
newMap.remove(e.getKey());
|
||||||
|
}
|
||||||
|
|
||||||
//anttask.execute();
|
//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
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.brutex.xservices.ws;
|
package net.brutex.xservices.ws;
|
||||||
|
|
||||||
import java.io.File;
|
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_UNZIP = "unzip";
|
||||||
public static final String WS_OPERATION_GUNZIP = "gunzip";
|
public static final String WS_OPERATION_GUNZIP = "gunzip";
|
||||||
public static final String WS_OPERATION_BUNZIP2 = "bunzip2";
|
public static final String WS_OPERATION_BUNZIP2 = "bunzip2";
|
||||||
|
|
||||||
public static final String WS_PARAM_SOURCEFILE = "source";
|
public static final String WS_PARAM_SOURCEFILE = "source";
|
||||||
public static final String WS_PARAM_SOURCEFILE_STRING = "srcfile";
|
public static final String WS_PARAM_SOURCEFILE_STRING = "srcfile";
|
||||||
public static final String WS_PARAM_SOURCEURL = "srcurl";
|
public static final String WS_PARAM_SOURCEURL = "srcurl";
|
||||||
public static final String WS_PARAM_SOURCEARCHIVE = "archivesource";
|
public static final String WS_PARAM_SOURCEARCHIVE = "archivesource";
|
||||||
public static final String WS_PARAM_DESTFILE = "destfile";
|
public static final String WS_PARAM_DESTFILE = "destfile";
|
||||||
public static final String WS_PARAM_DESTDIR = "destdir";
|
public static final String WS_PARAM_DESTDIR = "destdir";
|
||||||
|
|
||||||
public static final String WS_PARAM_ENCODING = "encoding";
|
public static final String WS_PARAM_ENCODING = "encoding";
|
||||||
public static final String WS_PARAM_OVERWRITE = "overwrite";
|
public static final String WS_PARAM_OVERWRITE = "overwrite";
|
||||||
|
|
||||||
|
@ -74,19 +71,19 @@ public class ArchiveService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(operationName = WS_OPERATION_GZIP, action = WS_OPERATION_GZIP)
|
@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) {
|
@WebParam(name = WS_PARAM_DESTFILE) String file) {
|
||||||
return gzip(src, new File(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 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) {
|
@WebParam(name = WS_PARAM_DESTFILE) String file) {
|
||||||
return gzip(src, new File(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 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) {
|
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
|
||||||
File target = null;
|
File target = null;
|
||||||
if (!dest.equals("") && dest != null) {
|
if (!dest.equals("") && dest != null) {
|
||||||
|
@ -96,7 +93,7 @@ public class ArchiveService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(operationName = WS_OPERATION_BUNZIP2)
|
@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) {
|
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
|
||||||
File target = null;
|
File target = null;
|
||||||
if (!dest.equals("") && dest != null) {
|
if (!dest.equals("") && dest != null) {
|
||||||
|
@ -106,7 +103,7 @@ public class ArchiveService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(operationName = "gunzipFromURL")
|
@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) {
|
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
|
||||||
File target = null;
|
File target = null;
|
||||||
if (!dest.equals("") && dest != null) {
|
if (!dest.equals("") && dest != null) {
|
||||||
|
@ -116,7 +113,7 @@ public class ArchiveService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(operationName = "bunzip2FromURL")
|
@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) {
|
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
|
||||||
File target = null;
|
File target = null;
|
||||||
if (!dest.equals("") && dest != null) {
|
if (!dest.equals("") && dest != null) {
|
||||||
|
@ -126,7 +123,7 @@ public class ArchiveService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(operationName = "zip")
|
@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_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,
|
||||||
|
@ -141,7 +138,7 @@ public class ArchiveService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(operationName = "zipFromArchive")
|
@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_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,
|
||||||
|
@ -149,9 +146,8 @@ public class ArchiveService {
|
||||||
return zip(src, new File(file), encoding, !update, level);
|
return zip(src, new File(file), encoding, !update, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@WebMethod(operationName = "unzip")
|
@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_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) {
|
||||||
|
@ -159,13 +155,13 @@ public class ArchiveService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(operationName = "unrar")
|
@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) {
|
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
|
||||||
return unrar(new File(src), new File(dest));
|
return unrar(new File(src), new File(dest));
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(operationName = "untar")
|
@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_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) {
|
||||||
|
@ -195,12 +191,11 @@ public class ArchiveService {
|
||||||
bzip.setSrcResource(src.getAntResource(bzip.getProject()));
|
bzip.setSrcResource(src.getAntResource(bzip.getProject()));
|
||||||
bzip.setDestfile(dst);
|
bzip.setDestfile(dst);
|
||||||
|
|
||||||
Map<String, String> result = runner.postTask();
|
return runner.postTask();
|
||||||
return new ReturnCode(0,result.get("System.stdOut"),result.get("System.stdErr"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
@WebMethod(exclude = true)
|
||||||
private String gzip(ResourceInterface src, File dst) {
|
private ReturnCode gzip(ResourceInterface src, File dst) {
|
||||||
if (dst.exists() && dst.isFile()) {
|
if (dst.exists() && dst.isFile()) {
|
||||||
dst.delete();
|
dst.delete();
|
||||||
}
|
}
|
||||||
|
@ -209,14 +204,11 @@ public class ArchiveService {
|
||||||
RunTask runner = new RunTask(gzip);
|
RunTask runner = new RunTask(gzip);
|
||||||
gzip.addConfigured(src.getAntResource(gzip.getProject()));
|
gzip.addConfigured(src.getAntResource(gzip.getProject()));
|
||||||
gzip.setDestfile(dst);
|
gzip.setDestfile(dst);
|
||||||
Map<String, String> result = runner.postTask();
|
return runner.postTask();
|
||||||
return "complete";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
@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 zip = new Zip();
|
||||||
zip.setTaskName("Zip");
|
zip.setTaskName("Zip");
|
||||||
RunTask runner = new RunTask(zip);
|
RunTask runner = new RunTask(zip);
|
||||||
|
@ -227,12 +219,11 @@ public class ArchiveService {
|
||||||
}
|
}
|
||||||
zip.setUpdate(update);
|
zip.setUpdate(update);
|
||||||
zip.setLevel(compresslevel);
|
zip.setLevel(compresslevel);
|
||||||
Map<String, String> result = runner.postTask();
|
return runner.postTask();
|
||||||
return "complete";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
@WebMethod(exclude = true)
|
||||||
private String GUnzip(ResourceInterface src, File dst) {
|
private ReturnCode GUnzip(ResourceInterface src, File dst) {
|
||||||
GUnzip uz = new GUnzip();
|
GUnzip uz = new GUnzip();
|
||||||
uz.setTaskName("GUnzip");
|
uz.setTaskName("GUnzip");
|
||||||
RunTask runner = new RunTask(uz);
|
RunTask runner = new RunTask(uz);
|
||||||
|
@ -240,12 +231,11 @@ public class ArchiveService {
|
||||||
if (dst != null) {
|
if (dst != null) {
|
||||||
uz.setDest(dst);
|
uz.setDest(dst);
|
||||||
}
|
}
|
||||||
Map<String, String> result = runner.postTask();
|
return runner.postTask();
|
||||||
return "complete";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
@WebMethod(exclude = true)
|
||||||
private String BUnzip2(ResourceInterface src, File dst) {
|
private ReturnCode BUnzip2(ResourceInterface src, File dst) {
|
||||||
BUnzip2 uz = new BUnzip2();
|
BUnzip2 uz = new BUnzip2();
|
||||||
uz.setTaskName("BUnzip2");
|
uz.setTaskName("BUnzip2");
|
||||||
RunTask runner = new RunTask(uz);
|
RunTask runner = new RunTask(uz);
|
||||||
|
@ -253,12 +243,11 @@ public class ArchiveService {
|
||||||
if (dst != null) {
|
if (dst != null) {
|
||||||
uz.setDest(dst);
|
uz.setDest(dst);
|
||||||
}
|
}
|
||||||
Map<String, String> result = runner.postTask();
|
return runner.postTask();
|
||||||
return "complete";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
@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();
|
Expand unzip = new Expand();
|
||||||
unzip.setTaskName("UnZip");
|
unzip.setTaskName("UnZip");
|
||||||
RunTask runner = new RunTask(unzip);
|
RunTask runner = new RunTask(unzip);
|
||||||
|
@ -268,13 +257,11 @@ public class ArchiveService {
|
||||||
if (encoding != null && !encoding.equals("")) {
|
if (encoding != null && !encoding.equals("")) {
|
||||||
unzip.setEncoding(encoding);
|
unzip.setEncoding(encoding);
|
||||||
}
|
}
|
||||||
|
return runner.postTask();
|
||||||
Map<String, String> result = runner.postTask();
|
|
||||||
return "complete";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
@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();
|
Untar unzip = new Untar();
|
||||||
unzip.setTaskName("Untar");
|
unzip.setTaskName("Untar");
|
||||||
RunTask runner = new RunTask(unzip);
|
RunTask runner = new RunTask(unzip);
|
||||||
|
@ -282,20 +269,16 @@ public class ArchiveService {
|
||||||
unzip.setDest(dest);
|
unzip.setDest(dest);
|
||||||
unzip.setOverwrite(overwrite);
|
unzip.setOverwrite(overwrite);
|
||||||
unzip.setCompression(compression);
|
unzip.setCompression(compression);
|
||||||
Map<String, String> result = runner.postTask();
|
return runner.postTask();
|
||||||
return "complete";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
@WebMethod(exclude = true)
|
||||||
private String unrar(File src, File dst) {
|
private ReturnCode unrar(File src, File dst) {
|
||||||
UnRarTask unrar = new UnRarTask();
|
UnRarTask unrar = new UnRarTask();
|
||||||
unrar.setTaskName("UnRar");
|
unrar.setTaskName("UnRar");
|
||||||
RunTask runner = new RunTask(unrar);
|
RunTask runner = new RunTask(unrar);
|
||||||
unrar.setSrc(src);
|
unrar.setSrc(src);
|
||||||
unrar.setDst(dst);
|
unrar.setDst(dst);
|
||||||
Map<String, String> result = runner.postTask();
|
return runner.postTask();
|
||||||
return "complete";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,11 +155,19 @@ public class ExecuteService {
|
||||||
long timeout) {
|
long timeout) {
|
||||||
ExecTask exe = new ExecTask();
|
ExecTask exe = new ExecTask();
|
||||||
RunTask runner = new RunTask(exe);
|
RunTask runner = new RunTask(exe);
|
||||||
|
|
||||||
|
/*
|
||||||
Commandline cmdl = new Commandline();
|
Commandline cmdl = new Commandline();
|
||||||
cmdl.setExecutable(executable);
|
cmdl.setExecutable(executable);
|
||||||
cmdl.addArguments(args);
|
cmdl.addArguments(args);
|
||||||
System.out.println(cmdl.describeCommand());
|
System.out.println(cmdl.describeCommand());
|
||||||
exe.setCommand(cmdl);
|
*/
|
||||||
|
|
||||||
|
exe.setExecutable(executable);
|
||||||
|
for (String s : args) {
|
||||||
|
exe.createArg().setValue(s);
|
||||||
|
}
|
||||||
|
|
||||||
exe.setDir(dir);
|
exe.setDir(dir);
|
||||||
if (spawn) {
|
if (spawn) {
|
||||||
exe.setSpawn(spawn);
|
exe.setSpawn(spawn);
|
||||||
|
@ -175,15 +183,7 @@ public class ExecuteService {
|
||||||
exe.setVMLauncher(vmlauncher);
|
exe.setVMLauncher(vmlauncher);
|
||||||
exe.setSearchPath(searchpath);
|
exe.setSearchPath(searchpath);
|
||||||
|
|
||||||
Map<String, String> result = runner.postTask();
|
return 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)
|
@WebMethod(exclude = true)
|
||||||
|
@ -203,12 +203,7 @@ public class ExecuteService {
|
||||||
sshexec.setTrust(true);
|
sshexec.setTrust(true);
|
||||||
sshexec.setTimeout(timeout);
|
sshexec.setTimeout(timeout);
|
||||||
sshexec.setOutputproperty("SSHExec.stdout");
|
sshexec.setOutputproperty("SSHExec.stdout");
|
||||||
Map<String, String> result = runner.postTask();
|
return runner.postTask();
|
||||||
ReturnCode res = null;
|
|
||||||
res = new ReturnCode(0,
|
|
||||||
result.get("SSHExec.stdout"), "");
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
@WebMethod(exclude = true)
|
||||||
|
@ -230,12 +225,7 @@ public class ExecuteService {
|
||||||
sshexec.setTrust(true);
|
sshexec.setTrust(true);
|
||||||
sshexec.setTimeout(timeout);
|
sshexec.setTimeout(timeout);
|
||||||
sshexec.setOutputproperty("SSHExec.stdout");
|
sshexec.setOutputproperty("SSHExec.stdout");
|
||||||
Map<String, String> result = runner.postTask();
|
return runner.postTask();
|
||||||
ReturnCode res = null;
|
|
||||||
res = new ReturnCode(0,
|
|
||||||
result.get("SSHExec.stdout"), "");
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
@WebMethod(exclude = true)
|
||||||
|
@ -254,12 +244,7 @@ public class ExecuteService {
|
||||||
rexec.setCommand(command);
|
rexec.setCommand(command);
|
||||||
rexec.setTimeout((int) Math.round(timeout));
|
rexec.setTimeout((int) Math.round(timeout));
|
||||||
|
|
||||||
Map<String, String> result = runner.postTask();
|
return runner.postTask();
|
||||||
ReturnCode res = null;
|
|
||||||
res = new ReturnCode(0,
|
|
||||||
"", "");
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
@WebMethod(exclude = true)
|
||||||
|
@ -281,10 +266,6 @@ public class ExecuteService {
|
||||||
rexec.createWrite().addText(command);
|
rexec.createWrite().addText(command);
|
||||||
rexec.createRead().addText(expect);
|
rexec.createRead().addText(expect);
|
||||||
|
|
||||||
Map<String, String> result = runner.postTask();
|
return runner.postTask();
|
||||||
ReturnCode res = null;
|
|
||||||
res = new ReturnCode(0,
|
|
||||||
"", "");
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,11 +13,9 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.brutex.xservices.ws;
|
package net.brutex.xservices.ws;
|
||||||
|
|
||||||
import java.io.File;
|
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;
|
||||||
|
@ -25,11 +23,14 @@ import net.brutex.xservices.types.ArchiveResource;
|
||||||
import net.brutex.xservices.types.FileResource;
|
import net.brutex.xservices.types.FileResource;
|
||||||
import net.brutex.xservices.types.FileSetResource;
|
import net.brutex.xservices.types.FileSetResource;
|
||||||
import net.brutex.xservices.types.ResourceInterface;
|
import net.brutex.xservices.types.ResourceInterface;
|
||||||
|
import net.brutex.xservices.types.ReturnCode;
|
||||||
import net.brutex.xservices.util.RunTask;
|
import net.brutex.xservices.util.RunTask;
|
||||||
import org.apache.tools.ant.taskdefs.Basename;
|
import org.apache.tools.ant.taskdefs.Basename;
|
||||||
import org.apache.tools.ant.taskdefs.Copy;
|
import org.apache.tools.ant.taskdefs.Copy;
|
||||||
import org.apache.tools.ant.taskdefs.Echo;
|
import org.apache.tools.ant.taskdefs.Echo;
|
||||||
import org.apache.tools.ant.taskdefs.LoadResource;
|
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;
|
import org.apache.tools.ant.types.FileSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,27 +41,23 @@ import org.apache.tools.ant.types.FileSet;
|
||||||
public class FileService {
|
public class FileService {
|
||||||
|
|
||||||
@WebMethod(operationName = "basename")
|
@WebMethod(operationName = "basename")
|
||||||
public String basename(@WebParam(name = "file") String filename,
|
public ReturnCode basename(@WebParam(name = "file") String filename,
|
||||||
@WebParam(name = "suffix") String suffix) {
|
@WebParam(name = "suffix") String suffix) {
|
||||||
return basename(new File(filename), suffix);
|
return basename(new File(filename), suffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(operationName = "copy")
|
@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 = "todir") String todir,
|
||||||
@WebParam(name = "preservelastmodified") boolean plm,
|
@WebParam(name = "preservelastmodified") boolean plm,
|
||||||
@WebParam(name = "overwrite") boolean overwrite,
|
@WebParam(name = "overwrite") boolean overwrite,
|
||||||
@WebParam(name = "encoding") String encoding)
|
@WebParam(name = "encoding") String encoding)
|
||||||
throws XServicesFault {
|
throws XServicesFault {
|
||||||
try {
|
return copy(src, new File(todir), plm, overwrite, encoding);
|
||||||
copy(src, new File(todir), plm, overwrite, encoding);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
throw new XServicesFault(ex.getMessage(), ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(operationName = "loadResource")
|
@WebMethod(operationName = "loadResource")
|
||||||
public String loadRes(@WebParam(name = "resource") FileResource res,
|
public ReturnCode loadRes(@WebParam(name = "resource") FileResource res,
|
||||||
@WebParam(name = "encoding") String encoding) {
|
@WebParam(name = "encoding") String encoding) {
|
||||||
if (encoding == null || encoding.equals("")) {
|
if (encoding == null || encoding.equals("")) {
|
||||||
encoding = System.getProperty("file.encoding");
|
encoding = System.getProperty("file.encoding");
|
||||||
|
@ -69,7 +66,7 @@ public class FileService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(operationName = "loadResourceFromArchive")
|
@WebMethod(operationName = "loadResourceFromArchive")
|
||||||
public String loadResFromArchive(@WebParam(name = "archiveresource") ArchiveResource res,
|
public ReturnCode loadResFromArchive(@WebParam(name = "archiveresource") ArchiveResource res,
|
||||||
@WebParam(name = "encoding") String encoding) {
|
@WebParam(name = "encoding") String encoding) {
|
||||||
if (encoding == null || encoding.equals("")) {
|
if (encoding == null || encoding.equals("")) {
|
||||||
encoding = System.getProperty("file.encoding");
|
encoding = System.getProperty("file.encoding");
|
||||||
|
@ -78,14 +75,26 @@ public class FileService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(operationName = "echoToFile")
|
@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 = "file") String file, @WebParam(name = "encoding") String encoding,
|
||||||
@WebParam(name = "append") boolean append) {
|
@WebParam(name = "append") boolean append) {
|
||||||
return echo(message, new File(file), encoding, 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)
|
@WebMethod(exclude = true)
|
||||||
private String basename(File file,
|
private ReturnCode basename(File file,
|
||||||
String suffix) {
|
String suffix) {
|
||||||
Basename basename = new Basename();
|
Basename basename = new Basename();
|
||||||
RunTask runner = new RunTask(basename);
|
RunTask runner = new RunTask(basename);
|
||||||
|
@ -94,11 +103,11 @@ public class FileService {
|
||||||
basename.setSuffix(suffix);
|
basename.setSuffix(suffix);
|
||||||
}
|
}
|
||||||
basename.setProperty("basename.value");
|
basename.setProperty("basename.value");
|
||||||
Map<String, String> result = runner.postTask();
|
return runner.postTask();
|
||||||
return result.get("basename.value");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
@WebMethod(exclude = true)
|
||||||
private String loadResource(ResourceInterface src, String encoding) {
|
private ReturnCode loadResource(ResourceInterface src, String encoding) {
|
||||||
LoadResource lr = new LoadResource();
|
LoadResource lr = new LoadResource();
|
||||||
lr.setTaskName("LoadResource");
|
lr.setTaskName("LoadResource");
|
||||||
RunTask runner = new RunTask(lr);
|
RunTask runner = new RunTask(lr);
|
||||||
|
@ -106,12 +115,11 @@ public class FileService {
|
||||||
lr.setEncoding(encoding);
|
lr.setEncoding(encoding);
|
||||||
System.out.println("Using encoding: " + encoding);
|
System.out.println("Using encoding: " + encoding);
|
||||||
lr.setProperty("LoadResource.out");
|
lr.setProperty("LoadResource.out");
|
||||||
Map<String, String> result = runner.postTask();
|
return runner.postTask();
|
||||||
return result.get("LoadResource.out");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
@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 echo = new Echo();
|
||||||
echo.setTaskName("toFile");
|
echo.setTaskName("toFile");
|
||||||
RunTask runTask = new RunTask(echo);
|
RunTask runTask = new RunTask(echo);
|
||||||
|
@ -119,12 +127,11 @@ public class FileService {
|
||||||
echo.setEncoding(encoding);
|
echo.setEncoding(encoding);
|
||||||
echo.setFile(file);
|
echo.setFile(file);
|
||||||
echo.setAppend(append);
|
echo.setAppend(append);
|
||||||
Map<String, String> result = runTask.postTask();
|
return runTask.postTask();
|
||||||
return "complete";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebMethod(exclude = true)
|
@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) {
|
boolean overwrite, String encoding) {
|
||||||
Copy copy = new Copy();
|
Copy copy = new Copy();
|
||||||
copy.setTaskName("Copy");
|
copy.setTaskName("Copy");
|
||||||
|
@ -132,8 +139,12 @@ public class FileService {
|
||||||
FileSet set = src.getAntFileSet(copy.getProject());
|
FileSet set = src.getAntFileSet(copy.getProject());
|
||||||
copy.add(set);
|
copy.add(set);
|
||||||
|
|
||||||
if(dst.isDirectory()) copy.setTodir(dst);
|
if (dst.isDirectory()) {
|
||||||
if(dst.isFile()) copy.setTofile(dst);
|
copy.setTodir(dst);
|
||||||
|
}
|
||||||
|
if (dst.isFile()) {
|
||||||
|
copy.setTofile(dst);
|
||||||
|
}
|
||||||
copy.setOverwrite(overwrite);
|
copy.setOverwrite(overwrite);
|
||||||
copy.setPreserveLastModified(preservelastmodified);
|
copy.setPreserveLastModified(preservelastmodified);
|
||||||
if (encoding != null && !encoding.equals("")) {
|
if (encoding != null && !encoding.equals("")) {
|
||||||
|
@ -142,6 +153,28 @@ public class FileService {
|
||||||
copy.setOutputEncoding(System.getProperty("file.encoding"));
|
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