From fb4542b456a52943f635ce1a213790b402b07c87 Mon Sep 17 00:00:00 2001 From: Brian Rosenberger Date: Wed, 20 Apr 2011 16:59:34 +0000 Subject: [PATCH] Added downloadFile and uploadFile operations (with MTOM support) git-svn-id: https://brutex.net/svn/xservices/trunk@54 e7e49efb-446e-492e-b9ec-fcafc1997a86 --- .../xservices/types/AttachmentType.java | 57 +++ .../brutex/xservices/types/FileResource.java | 6 +- .../xservices/types/FileSetResource.java | 7 +- .../xservices/types/HostConnection.java | 2 +- .../xservices/types/ResourceInterface.java | 2 +- .../xservices/types/ResourceSetInterface.java | 35 ++ .../brutex/xservices/types/ReturnCode.java | 7 + .../types/SelectorTypeInterface.java | 21 +- .../net/brutex/xservices/util/RunTask.java | 3 +- .../brutex/xservices/ws/ArchiveService.java | 1 + .../net/brutex/xservices/ws/FileService.java | 10 + .../net/brutex/xservices/ws/MiscService.java | 5 + .../xservices/ws/impl/ArchiveServiceImpl.java | 6 +- .../xservices/ws/impl/FileServiceImpl.java | 432 +++++++++++------- .../xservices/ws/impl/MiscServiceImpl.java | 28 +- 15 files changed, 441 insertions(+), 181 deletions(-) create mode 100644 src/java/net/brutex/xservices/types/AttachmentType.java create mode 100644 src/java/net/brutex/xservices/types/ResourceSetInterface.java diff --git a/src/java/net/brutex/xservices/types/AttachmentType.java b/src/java/net/brutex/xservices/types/AttachmentType.java new file mode 100644 index 0000000..50a9905 --- /dev/null +++ b/src/java/net/brutex/xservices/types/AttachmentType.java @@ -0,0 +1,57 @@ +/* + * Copyright 2011 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.types; + +import java.io.File; +import java.io.IOException; + +import javax.activation.DataHandler; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlMimeType; + +public class AttachmentType { + + private DataHandler content; + private String filename = null; + + public void setContent(DataHandler content) { + this.content = content; + } + + @XmlMimeType("application/octet-stream") + @XmlElement(required=true) + public DataHandler getContent() { + return content; + } + + public String getFilename() { + if(filename==null || filename.equals("")) { + try { + filename = File.createTempFile("XServices_", ".tmp").getPath(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + return filename; + } + + public void setFilename(String filename) { + this.filename = filename; + } + +} diff --git a/src/java/net/brutex/xservices/types/FileResource.java b/src/java/net/brutex/xservices/types/FileResource.java index 21d888a..85aeb4f 100644 --- a/src/java/net/brutex/xservices/types/FileResource.java +++ b/src/java/net/brutex/xservices/types/FileResource.java @@ -19,7 +19,8 @@ package net.brutex.xservices.types; import java.io.File; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlEnum; -import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + import net.brutex.xservices.util.BrutexNamespaces; import org.apache.tools.ant.Project; import org.apache.tools.ant.types.Resource; @@ -30,9 +31,10 @@ import org.apache.tools.ant.types.resources.URLResource; /** * File based resource declaration. * + * * @author Brian Rosenberger, bru@brutex.de */ -@XmlRootElement(namespace=BrutexNamespaces.WS_XSERVICES, name="FileResourceType") +@XmlType(name="FileResourceType", namespace=BrutexNamespaces.WS_XSERVICES) public class FileResource implements ResourceInterface { diff --git a/src/java/net/brutex/xservices/types/FileSetResource.java b/src/java/net/brutex/xservices/types/FileSetResource.java index 84f601f..69ab08e 100644 --- a/src/java/net/brutex/xservices/types/FileSetResource.java +++ b/src/java/net/brutex/xservices/types/FileSetResource.java @@ -32,7 +32,7 @@ import org.apache.tools.ant.types.ZipFileSet; */ @XmlType(name = "FileSetType", namespace = "http://ws.xservices.brutex.net", propOrder = {"type", "source", "filter", "excludes", "casesensitive"}) -public class FileSetResource { +public class FileSetResource implements ResourceSetInterface { /** * Type of FileSet @@ -71,7 +71,7 @@ public class FileSetResource { * @param p Ant project * @return Ant FileSet for this file set. */ - public FileSet getAntFileSet(Project p) { + public FileSet getAntResource(Project p) { FileSet set = null; switch (type) { case ZIP: @@ -106,7 +106,8 @@ public class FileSetResource { /** * File set types. */ - @XmlEnum + @XmlEnum() + @XmlType(name="resourcetype") public enum FileSetType { /** diff --git a/src/java/net/brutex/xservices/types/HostConnection.java b/src/java/net/brutex/xservices/types/HostConnection.java index 9200891..bdf01f5 100644 --- a/src/java/net/brutex/xservices/types/HostConnection.java +++ b/src/java/net/brutex/xservices/types/HostConnection.java @@ -29,7 +29,7 @@ public class HostConnection { public HostConnection() { } - @XmlElement(name="hostname", required=false, nillable=false) + @XmlElement(name="hostname", required=true, nillable=false) public String hostname; @XmlElement(name="port", required=false, nillable=false) diff --git a/src/java/net/brutex/xservices/types/ResourceInterface.java b/src/java/net/brutex/xservices/types/ResourceInterface.java index 11f72a1..b49536d 100644 --- a/src/java/net/brutex/xservices/types/ResourceInterface.java +++ b/src/java/net/brutex/xservices/types/ResourceInterface.java @@ -20,7 +20,7 @@ import org.apache.tools.ant.Project; import org.apache.tools.ant.types.Resource; /** - * Wrapper for Ant Resources. + * Wrapper for a single file like Ant Resources. * * @author Brian Rosenberger, bru@brutex.de */ diff --git a/src/java/net/brutex/xservices/types/ResourceSetInterface.java b/src/java/net/brutex/xservices/types/ResourceSetInterface.java new file mode 100644 index 0000000..b91d1a4 --- /dev/null +++ b/src/java/net/brutex/xservices/types/ResourceSetInterface.java @@ -0,0 +1,35 @@ +/* + * Copyright 2011 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. + */ + +/** + * Wrapper for Ant Resource Sets. A resource set + * is simply a collection of resources. + * + * @author Brian Rosenberger, bru@brutex.de + */ +package net.brutex.xservices.types; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.ResourceCollection; +/** + * Wrapper for Ant Resource Collection. + * + * @author Brian Rosenberger, bru@brutex.de + */ +public interface ResourceSetInterface { + + public ResourceCollection getAntResource(Project p); +} diff --git a/src/java/net/brutex/xservices/types/ReturnCode.java b/src/java/net/brutex/xservices/types/ReturnCode.java index 08de227..e742890 100644 --- a/src/java/net/brutex/xservices/types/ReturnCode.java +++ b/src/java/net/brutex/xservices/types/ReturnCode.java @@ -79,4 +79,11 @@ public class ReturnCode { this.stdErr = stdErr; this.property = props; } + + public String getProperty(String key) { + for(AntProperty prop : this.property) { + if(prop.equals(key)) return prop.value; + } + return null; + } } diff --git a/src/java/net/brutex/xservices/types/SelectorTypeInterface.java b/src/java/net/brutex/xservices/types/SelectorTypeInterface.java index f558c23..2a27d75 100644 --- a/src/java/net/brutex/xservices/types/SelectorTypeInterface.java +++ b/src/java/net/brutex/xservices/types/SelectorTypeInterface.java @@ -1,7 +1,18 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ +/* + * Copyright 2011 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.types; @@ -9,7 +20,7 @@ import org.apache.tools.ant.types.selectors.FileSelector; /** * - * @author brian + * @author Brian Rosenberger */ public interface SelectorTypeInterface { public FileSelector getSelector(); diff --git a/src/java/net/brutex/xservices/util/RunTask.java b/src/java/net/brutex/xservices/util/RunTask.java index c01ae12..3fb0591 100644 --- a/src/java/net/brutex/xservices/util/RunTask.java +++ b/src/java/net/brutex/xservices/util/RunTask.java @@ -85,7 +85,8 @@ public class RunTask { returnCode = 1; } newMap = antproject.getProperties(); - + newMap.putAll(antproject.getUserProperties()); + for (Map.Entry e : origMap.entrySet()) { newMap.remove(e.getKey()); } diff --git a/src/java/net/brutex/xservices/ws/ArchiveService.java b/src/java/net/brutex/xservices/ws/ArchiveService.java index 9c99234..0c7d040 100644 --- a/src/java/net/brutex/xservices/ws/ArchiveService.java +++ b/src/java/net/brutex/xservices/ws/ArchiveService.java @@ -21,6 +21,7 @@ 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.FileSetResource; import net.brutex.xservices.types.ReturnCode; import net.brutex.xservices.util.BrutexNamespaces; diff --git a/src/java/net/brutex/xservices/ws/FileService.java b/src/java/net/brutex/xservices/ws/FileService.java index 0ddbcbb..2c141c4 100644 --- a/src/java/net/brutex/xservices/ws/FileService.java +++ b/src/java/net/brutex/xservices/ws/FileService.java @@ -1,10 +1,12 @@ package net.brutex.xservices.ws; +import javax.activation.DataHandler; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; import net.brutex.xservices.types.ArchiveResource; +import net.brutex.xservices.types.AttachmentType; import net.brutex.xservices.types.FileResource; import net.brutex.xservices.types.FileSetResource; import net.brutex.xservices.types.ReturnCode; @@ -17,6 +19,14 @@ public interface FileService { @WebParam(name = "file") String filename, @WebParam(name = "suffix") String suffix); + @WebMethod(operationName = "downloadFile") + public abstract AttachmentType downloadFile( + @WebParam(name = "file") FileResource res); + + @WebMethod(operationName = "uploadFile") + public abstract String uploadFile( + @WebParam(name = "file") AttachmentType file); + @WebMethod(operationName = "copy") public abstract ReturnCode copy( @WebParam(name = "fileset") FileSetResource src, diff --git a/src/java/net/brutex/xservices/ws/MiscService.java b/src/java/net/brutex/xservices/ws/MiscService.java index aa4f6fd..1a814ea 100644 --- a/src/java/net/brutex/xservices/ws/MiscService.java +++ b/src/java/net/brutex/xservices/ws/MiscService.java @@ -114,4 +114,9 @@ public interface MiscService { @WebMethod(operationName = "sleep") public ReturnCode sleep(@WebParam(name = "minutes") int minutes, @WebParam(name = "seconds") int seconds); + + + @WebMethod(operationName = "getInfo") + public ReturnCode getInfo(); + } diff --git a/src/java/net/brutex/xservices/ws/impl/ArchiveServiceImpl.java b/src/java/net/brutex/xservices/ws/impl/ArchiveServiceImpl.java index b435748..6a1a7b0 100644 --- a/src/java/net/brutex/xservices/ws/impl/ArchiveServiceImpl.java +++ b/src/java/net/brutex/xservices/ws/impl/ArchiveServiceImpl.java @@ -22,7 +22,9 @@ 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.FileSetResource; import net.brutex.xservices.types.ResourceInterface; +import net.brutex.xservices.types.ResourceSetInterface; import net.brutex.xservices.types.ReturnCode; import net.brutex.xservices.util.BrutexNamespaces; import net.brutex.xservices.util.RunTask; @@ -62,9 +64,9 @@ public class ArchiveServiceImpl implements ArchiveService { */ @Override @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) { - return bzip(src, new File(file)); +return null;// return bzip(src, new File(file)); } /* (non-Javadoc) diff --git a/src/java/net/brutex/xservices/ws/impl/FileServiceImpl.java b/src/java/net/brutex/xservices/ws/impl/FileServiceImpl.java index d5ca09b..6c1d62a 100644 --- a/src/java/net/brutex/xservices/ws/impl/FileServiceImpl.java +++ b/src/java/net/brutex/xservices/ws/impl/FileServiceImpl.java @@ -16,10 +16,22 @@ package net.brutex.xservices.ws.impl; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.util.List; + +import javax.activation.DataHandler; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; + +import net.brutex.xservices.types.AntProperty; import net.brutex.xservices.types.ArchiveResource; +import net.brutex.xservices.types.AttachmentType; import net.brutex.xservices.types.FileResource; import net.brutex.xservices.types.FileSetResource; import net.brutex.xservices.types.ResourceInterface; @@ -29,6 +41,10 @@ import net.brutex.xservices.util.RunTask; import net.brutex.xservices.ws.FileService; import net.brutex.xservices.ws.XServicesFault; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.codec.binary.Base64InputStream; +import org.apache.cxf.aegis.type.mtom.StreamDataSource; +import org.apache.tools.ant.BuildException; import org.apache.tools.ant.taskdefs.Basename; import org.apache.tools.ant.taskdefs.Chmod; import org.apache.tools.ant.taskdefs.Copy; @@ -39,205 +55,293 @@ 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", - serviceName = "FileService" - ) +@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.FileService", serviceName = "FileService") public class FileServiceImpl implements FileService { - /* (non-Javadoc) - * @see net.brutex.xservices.ws.impl.FileService#basename(java.lang.String, java.lang.String) + /* + * (non-Javadoc) + * + * @see net.brutex.xservices.ws.impl.FileService#basename(java.lang.String, + * java.lang.String) */ - @Override + @Override @WebMethod(operationName = "basename") - public ReturnCode basename(@WebParam(name = "file") String filename, - @WebParam(name = "suffix") String suffix) { - return basename(new File(filename), suffix); - } + 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) + /* + * (non-Javadoc) + * + * @see + * net.brutex.xservices.ws.impl.FileService#base64Encode(net.brutex.xservices + * .types.FileSetResource) */ - @Override + @Override + @WebMethod(operationName = "downloadFile") + public AttachmentType downloadFile(@WebParam(name = "file") FileResource res) { + InputStream is = null; + try { + is = res.getAntResource(null).getInputStream(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + DataHandler h = new DataHandler(new StreamDataSource( + "application/binary", is)); + AttachmentType t = new AttachmentType(); + t.setContent(h); + return t; + } + + /* + * (non-Javadoc) + * + * @see + * net.brutex.xservices.ws.impl.FileService#base64Decode(net.brutex.xservices + * .types.AttachmentType) + */ + @Override + @WebMethod(operationName = "uploadFile") + public String uploadFile(@WebParam(name = "file") AttachmentType file) { + DataHandler h = file.getContent(); + File f = new File(file.getFilename()); + FileOutputStream fout; + try { + fout = new FileOutputStream(f); + /* + * InputStream in = h.getInputStream(); + int b; + while( (b=in.read())!= -1 ) { + fout.write(b); + } + */ + h.writeTo(fout); + fout.flush(); + fout.close(); + //in.close(); + } catch (FileNotFoundException e) { + throw new BuildException(e); + } catch (IOException e) { + throw new BuildException(e); + } + return file.getFilename(); + } + + /* + * (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); - } + 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) + /* + * (non-Javadoc) + * + * @see + * net.brutex.xservices.ws.impl.FileService#loadRes(net.brutex.xservices + * .types.FileResource, java.lang.String) */ - @Override + @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); - } + 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) + /* + * (non-Javadoc) + * + * @see + * net.brutex.xservices.ws.impl.FileService#loadResFromArchive(net.brutex + * .xservices.types.ArchiveResource, java.lang.String) */ - @Override + @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); - } + 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) + /* + * (non-Javadoc) + * + * @see net.brutex.xservices.ws.impl.FileService#echo2file(java.lang.String, + * java.lang.String, java.lang.String, boolean) */ - @Override + @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); - } + 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) + /* + * (non-Javadoc) + * + * @see + * net.brutex.xservices.ws.impl.FileService#changeOwner(net.brutex.xservices + * .types.FileSetResource, java.lang.String) */ - @Override + @Override @WebMethod(operationName = "changeOwner") - public ReturnCode changeOwner(@WebParam(name = "fileset") FileSetResource res, - @WebParam(name = "owner") String owner) { - return chown(res, owner); - } + 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) + /* + * (non-Javadoc) + * + * @see + * net.brutex.xservices.ws.impl.FileService#changeGroup(net.brutex.xservices + * .types.FileSetResource, java.lang.String) */ - @Override + @Override @WebMethod(operationName = "changeGroup") - public ReturnCode changeGroup(@WebParam(name = "fileset") FileSetResource res, - @WebParam(name = "group") String group) { - return chgrp(res, group); - } + 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) + /* + * (non-Javadoc) + * + * @see + * net.brutex.xservices.ws.impl.FileService#changeMode(net.brutex.xservices + * .types.FileSetResource, java.lang.String) */ - @Override + @Override @WebMethod(operationName = "changeMode") - public ReturnCode changeMode(@WebParam(name="fileset") FileSetResource res, - @WebParam(name="permissions") String perm) { - return chmod(res, perm); - } + 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 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 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 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); + @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.getAntResource(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")); - } + 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(); - } + 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 chown(FileSetResource src, String owner) { + Chown chown = new Chown(); + chown.setTaskName("Chown"); + RunTask runner = new RunTask(chown); + chown.setOwner(owner); + FileSet set = src.getAntResource(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 chgrp(FileSetResource src, String group) { + Chgrp chgrp = new Chgrp(); + chgrp.setTaskName("Chgrp"); + RunTask runner = new RunTask(chgrp); + chgrp.setGroup(group); + FileSet set = src.getAntResource(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(); - } + @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.getAntResource(chmod.getProject()); + chmod.add(set); + chmod.setMaxParallel(300); + chmod.setPerm(perm); + chmod.setVerbose(true); + return runner.postTask(); + } } diff --git a/src/java/net/brutex/xservices/ws/impl/MiscServiceImpl.java b/src/java/net/brutex/xservices/ws/impl/MiscServiceImpl.java index 8f546af..1ffe8cb 100644 --- a/src/java/net/brutex/xservices/ws/impl/MiscServiceImpl.java +++ b/src/java/net/brutex/xservices/ws/impl/MiscServiceImpl.java @@ -16,6 +16,9 @@ package net.brutex.xservices.ws.impl; +import java.util.Enumeration; +import java.util.Properties; + import javax.jws.WebService; import net.brutex.xservices.types.FileSetResource; import net.brutex.xservices.types.HostConnection; @@ -50,6 +53,28 @@ public class MiscServiceImpl implements MiscService { public ReturnCode getHostinfo(String hostname) { return antGetHostinfo(hostname, null); } + + @WSDLDocumentation(value = "Get XService information.") + public ReturnCode getInfo() { + ReturnCode r = new ReturnCode(); + r.returnCode = 0; + // Get all system properties + Properties props = System.getProperties(); + + // Enumerate all system properties + Enumeration e = (Enumeration) props.propertyNames(); + for (; e.hasMoreElements(); ) { + // Get property name + String propName = (String)e.nextElement(); + + // Get property value + String propValue = (String)props.get(propName); + r.stdOut = r.stdOut + propName + ": " + propValue + "\n"; + } + + return r; + } + public ReturnCode sendMailSimple(HostConnection mailhost, String from, String tolist, String subject, String message) { @@ -105,7 +130,7 @@ public class MiscServiceImpl implements MiscService { mail.setMessage(message); mail.setMessageMimeType(messagemimetype); if (attachments != null) { - mail.addFileset(attachments.getAntFileSet(mail.getProject())); + mail.addFileset(attachments.getAntResource(mail.getProject())); } mail.setMailhost(mailhost); mail.setMailport(mailport); @@ -128,5 +153,4 @@ public class MiscServiceImpl implements MiscService { sleep.setMilliseconds(milliseconds); return runner.postTask(); } - }