From a7187e2cca96645ebd0bae450df82cb7439af384 Mon Sep 17 00:00:00 2001 From: Brian Rosenberger Date: Fri, 20 May 2011 17:38:12 +0000 Subject: [PATCH] Further tidy up git-svn-id: https://brutex.net/svn/xservices/trunk@65 e7e49efb-446e-492e-b9ec-fcafc1997a86 --- .../brutex/xservices/types/FileResource.java | 2 + .../xservices/types/FileSetResource.java | 1 + .../net/brutex/xservices/util/RunTask.java | 13 +- .../util/XServicesDocumentation.java | 6 + .../brutex/xservices/ws/ArchiveService.java | 115 ++- .../brutex/xservices/ws/ExecuteService.java | 53 ++ .../net/brutex/xservices/ws/FileService.java | 119 ++- .../brutex/xservices/ws/XServicesFault.java | 33 +- .../xservices/ws/impl/FileServiceImpl.java | 288 +++--- test/FileService-soapui-project.xml | 891 +++++++++++++++++- 10 files changed, 1281 insertions(+), 240 deletions(-) diff --git a/src/java/net/brutex/xservices/types/FileResource.java b/src/java/net/brutex/xservices/types/FileResource.java index 85aeb4f..9bd254e 100644 --- a/src/java/net/brutex/xservices/types/FileResource.java +++ b/src/java/net/brutex/xservices/types/FileResource.java @@ -38,6 +38,8 @@ import org.apache.tools.ant.types.resources.URLResource; public class FileResource implements ResourceInterface { + public static final String XML_NAME = "file"; + /** * File resource type. */ diff --git a/src/java/net/brutex/xservices/types/FileSetResource.java b/src/java/net/brutex/xservices/types/FileSetResource.java index 69ab08e..ebfa629 100644 --- a/src/java/net/brutex/xservices/types/FileSetResource.java +++ b/src/java/net/brutex/xservices/types/FileSetResource.java @@ -34,6 +34,7 @@ import org.apache.tools.ant.types.ZipFileSet; propOrder = {"type", "source", "filter", "excludes", "casesensitive"}) public class FileSetResource implements ResourceSetInterface { + public static final String XML_NAME = "fileset"; /** * Type of FileSet */ diff --git a/src/java/net/brutex/xservices/util/RunTask.java b/src/java/net/brutex/xservices/util/RunTask.java index 3fb0591..1891611 100644 --- a/src/java/net/brutex/xservices/util/RunTask.java +++ b/src/java/net/brutex/xservices/util/RunTask.java @@ -73,17 +73,16 @@ public class RunTask { antproject.addOrReplaceTarget(anttarget); } - public ReturnCode postTask() { + /** + * @return ReturnCode type {@link ReturnCode} + * @throws BuildException + */ + public ReturnCode postTask() throws BuildException { int returnCode = 0; Map origMap = new HashMap(); Map newMap = null; origMap.putAll(antproject.getProperties()); - try { - antproject.executeTarget(anttarget.getName()); - } catch (BuildException ex) { - err.print(ex.getMessage()); - returnCode = 1; - } + antproject.executeTarget(anttarget.getName()); newMap = antproject.getProperties(); newMap.putAll(antproject.getUserProperties()); diff --git a/src/java/net/brutex/xservices/util/XServicesDocumentation.java b/src/java/net/brutex/xservices/util/XServicesDocumentation.java index 474f6d5..60d957b 100644 --- a/src/java/net/brutex/xservices/util/XServicesDocumentation.java +++ b/src/java/net/brutex/xservices/util/XServicesDocumentation.java @@ -61,5 +61,11 @@ public class XServicesDocumentation { public static final String SERVICE_OPERATION_ECHOTOFILE = "Write or append a string to a file"; + public static final String SERVICE_OPERATION_REPLACEINFILE = "Replaces every with a string in an ascii file"; + + public static final String SERVICE_OPERATION_REPLACEINFILE2 = "Replaces every with a string in an ascii file"; + + public static final String SERVICE_OPERATION_REPLACEINFILEREGEX = "Replaces every with a string in an ascii file"; + private XServicesDocumentation() {}; } diff --git a/src/java/net/brutex/xservices/ws/ArchiveService.java b/src/java/net/brutex/xservices/ws/ArchiveService.java index 0c7d040..619b263 100644 --- a/src/java/net/brutex/xservices/ws/ArchiveService.java +++ b/src/java/net/brutex/xservices/ws/ArchiveService.java @@ -49,66 +49,155 @@ public interface ArchiveService { public static final String WS_PARAM_DESTDIR = "destdir"; public static final String WS_PARAM_ENCODING = "encoding"; public static final String WS_PARAM_OVERWRITE = "overwrite"; + public static final String WS_PARAM_COMPRESS = "compresslevel"; + /** + * @param src + * @param file + * @return + * @throws XServicesFault + */ @WebMethod(operationName = WS_OPERATION_BZIP2, action = WS_OPERATION_BZIP2) public ReturnCode bzip2(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src, - @WebParam(name = WS_PARAM_DESTFILE) String file); + @WebParam(name = WS_PARAM_DESTFILE) String file) throws XServicesFault; + /** + * @param src + * @param file + * @return + * @throws XServicesFault + */ @WebMethod(operationName = WS_OPERATION_BZIP2_ARCHIVE, action = WS_OPERATION_BZIP2_ARCHIVE) public ReturnCode bzip2FromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src, - @WebParam(name = WS_PARAM_DESTFILE) String file); + @WebParam(name = WS_PARAM_DESTFILE) String file) throws XServicesFault; + /** + * @param src + * @param file + * @return + * @throws XServicesFault + */ @WebMethod(operationName = WS_OPERATION_GZIP, action = WS_OPERATION_GZIP) public ReturnCode gzip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src, - @WebParam(name = WS_PARAM_DESTFILE) String file); + @WebParam(name = WS_PARAM_DESTFILE) String file) throws XServicesFault; + /** + * @param src + * @param file + * @return + * @throws XServicesFault + */ @WebMethod(operationName = WS_OPERATION_GZIP_ARCHIVE, action = WS_OPERATION_GZIP_ARCHIVE) public ReturnCode gzipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src, - @WebParam(name = WS_PARAM_DESTFILE) String file); + @WebParam(name = WS_PARAM_DESTFILE) String file) throws XServicesFault; + /** + * @param src + * @param dest + * @return + * @throws XServicesFault + */ @WebMethod(operationName = WS_OPERATION_GUNZIP, action = WS_OPERATION_GUNZIP) public ReturnCode gunzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src, - @WebParam(name = WS_PARAM_DESTDIR) String dest); + @WebParam(name = WS_PARAM_DESTDIR) String dest) throws XServicesFault; + /** + * @param src + * @param dest + * @return + * @throws XServicesFault + */ @WebMethod(operationName = WS_OPERATION_BUNZIP2) 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) throws XServicesFault; + /** + * @param src + * @param dest + * @return + * @throws XServicesFault + */ @WebMethod(operationName = "gunzipFromURL") public ReturnCode gunzipFromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src, - @WebParam(name = WS_PARAM_DESTDIR) String dest); + @WebParam(name = WS_PARAM_DESTDIR) String dest) throws XServicesFault; + /** + * @param src + * @param dest + * @return + * @throws XServicesFault + */ @WebMethod(operationName = "bunzip2FromURL") public ReturnCode bunzip2FromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src, - @WebParam(name = WS_PARAM_DESTDIR) String dest); + @WebParam(name = WS_PARAM_DESTDIR) String dest) throws XServicesFault; + /** + * @param src + * @param file + * @param overwrite + * @param encoding + * @param level + * @return + * @throws XServicesFault + */ @WebMethod(operationName = "zip") public ReturnCode zip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src, @WebParam(name = WS_PARAM_DESTFILE) String file, @WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite, @WebParam(name = WS_PARAM_ENCODING) String encoding, - @WebParam(name = "compresslevel") int level); + @WebParam(name = WS_PARAM_COMPRESS) int level) throws XServicesFault; + /** + * @param src + * @param file + * @param update + * @param encoding + * @param level + * @return + * @throws XServicesFault + */ @WebMethod(operationName = "zipFromArchive") public ReturnCode zipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src, @WebParam(name = WS_PARAM_DESTFILE) String file, @WebParam(name = WS_PARAM_OVERWRITE) boolean update, @WebParam(name = WS_PARAM_ENCODING) String encoding, - @WebParam(name = "compresslevel") int level); + @WebParam(name = "compresslevel") int level) throws XServicesFault; + /** + * @param src + * @param dest + * @param overwrite + * @param encoding + * @return + * @throws XServicesFault + */ @WebMethod(operationName = "unzip") public ReturnCode unzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src, @WebParam(name = WS_PARAM_DESTDIR) String dest, @WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite, - @WebParam(name = WS_PARAM_ENCODING) String encoding); + @WebParam(name = WS_PARAM_ENCODING) String encoding) throws XServicesFault; + /** + * @param src + * @param dest + * @return + * @throws XServicesFault + */ @WebMethod(operationName = "unrar") 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) throws XServicesFault; + /** + * @param src + * @param dest + * @param overwrite + * @param compression + * @return + * @throws XServicesFault + */ @WebMethod(operationName = "untar") public ReturnCode untar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src, @WebParam(name = WS_PARAM_DESTDIR) String dest, @WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite, - @WebParam(name = "compression") CompressionType compression); + @WebParam(name = "compression") CompressionType compression) throws XServicesFault; } diff --git a/src/java/net/brutex/xservices/ws/ExecuteService.java b/src/java/net/brutex/xservices/ws/ExecuteService.java index c328544..d90a617 100644 --- a/src/java/net/brutex/xservices/ws/ExecuteService.java +++ b/src/java/net/brutex/xservices/ws/ExecuteService.java @@ -8,37 +8,76 @@ import net.brutex.xservices.types.HostConnection; import net.brutex.xservices.types.ReturnCode; import net.brutex.xservices.util.BrutexNamespaces; +/** + * @author brosenberger + * + */ @WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES) public interface ExecuteService { + /** + * @param cmd + * @param args + * @param timeout + * @return + */ @WebMethod(operationName = "runCommand") public abstract ReturnCode runCommand( @WebParam(name = "executable") String cmd, @WebParam(name = "argline") String args, @WebParam(name = "timeout") long timeout); + /** + * @param cmd + * @param args + * @param timeout + * @return + */ @WebMethod(operationName = "runCommandWithArgs") public abstract ReturnCode runCommandWithArgs( @WebParam(name = "executable") String cmd, @WebParam(name = "arg") String[] args, @WebParam(name = "timeout") long timeout); + /** + * @param cmd + * @param args + * @return + */ @WebMethod(operationName = "runCommandAsync") public abstract ReturnCode runCommandAsync( @WebParam(name = "executable") String cmd, @WebParam(name = "argline") String args); + /** + * @param cmd + * @param args + * @return + */ @WebMethod(operationName = "runCommandAsyncWithArgs") public abstract ReturnCode runCommandAsyncWithArgs( @WebParam(name = "executable") String cmd, @WebParam(name = "arg") String[] args); + /** + * @param host + * @param cmd + * @param timeout + * @return + */ @WebMethod(operationName = "runCommandWithSSH") public abstract ReturnCode runCommandWithSSH( @WebParam(name = "host") HostConnection host, @WebParam(name = "command") String cmd, @WebParam(name = "timeout") long timeout); + /** + * @param host + * @param keyfile + * @param cmd + * @param timeout + * @return + */ @WebMethod(operationName = "runCommandWithSSHKeyAuth") public abstract ReturnCode runCommandWithSSHKeyAuth( @WebParam(name = "host") HostConnection host, @@ -46,12 +85,26 @@ public interface ExecuteService { @WebParam(name = "command") String cmd, @WebParam(name = "timeout") long timeout); + /** + * @param host + * @param cmd + * @param timeout + * @return + */ @WebMethod(operationName = "rExec") public abstract ReturnCode rExec( @WebParam(name = "host") HostConnection host, @WebParam(name = "command") String cmd, @WebParam(name = "timeout") long timeout); + /** + * @param host + * @param prompt + * @param cmd + * @param expect + * @param timeout + * @return + */ @WebMethod(operationName = "telnet") public abstract ReturnCode runTelnet( @WebParam(name = "host") HostConnection host, diff --git a/src/java/net/brutex/xservices/ws/FileService.java b/src/java/net/brutex/xservices/ws/FileService.java index 2f8dc16..7dc5548 100644 --- a/src/java/net/brutex/xservices/ws/FileService.java +++ b/src/java/net/brutex/xservices/ws/FileService.java @@ -48,13 +48,28 @@ import net.brutex.xservices.util.XServicesDocumentation; ) public interface FileService { + public static final String OPERATION_BASENAME ="basename"; + public static final String OPERATION_DOWNLOADFILE ="downloadFile"; + public static final String OPERATION_UPLOADFILE ="uploadFile"; + public static final String OPERATION_COPY ="copy"; + public static final String OPERATION_COPYFILE ="copyFile"; + public static final String OPERATION_LOADRESOURCE = "loadResource"; + public static final String OPERATION_LOADRESOURCEFROMARCHIVE = "loadResourceFromArchive"; + public static final String OPERATION_ECHOTOFILE = "echoToFile"; + public static final String OPERATION_CHANGEOWNER = "changeOwner"; + public static final String OPERATION_CHANGEMODE = "changeMode"; + public static final String OPERATION_CHANGEGROUP = "changeGroup"; + public static final String OPERATION_REPLACEINFILE = "replaceInFile"; + public static final String OPERATION_REPLACEINFILE2 = "replaceInFile2"; + public static final String OPERATION_REPLACEINFILEREGEX = "replaceInFileRegEx"; + /** * @param filename * @param suffix * @return The base name of the given file excluding the suffix. */ @WSDLDocumentation(value = "The base name of the given file excluding the suffix.") - @WebMethod(operationName = "basename") + @WebMethod(operationName = OPERATION_BASENAME) public abstract String basename( @WebParam(name = "file") @XmlElement(required=true) String filename, @WebParam(name = "suffix") String suffix); @@ -62,20 +77,22 @@ public interface FileService { /** * @param res * @return The file itself (MTOM attachment or inline base64) including some file metadata. + * @throws XServicesFault */ @WSDLDocumentation(XServicesDocumentation.SERVICE_OPERATION_DOWNLOADFILE) - @WebMethod(operationName = "downloadFile") + @WebMethod(operationName = OPERATION_DOWNLOADFILE) public abstract AttachmentType downloadFile( - @WebParam(name = "file") FileResource res); + @WebParam(name = FileResource.XML_NAME) FileResource res) throws XServicesFault; /** * @param file * @return The file name of the file that has been uploaded. + * @throws XServicesFault */ @WSDLDocumentation(XServicesDocumentation.SERVICE_OPERATION_UPLOADFILE) - @WebMethod(operationName = "uploadFile") + @WebMethod(operationName = OPERATION_UPLOADFILE) public abstract String uploadFile( - @WebParam(name = "file") AttachmentType file); + @WebParam(name = "file") AttachmentType file) throws XServicesFault; /** * @param src @@ -87,9 +104,9 @@ public interface FileService { * @throws XServicesFault */ @WSDLDocumentation(value = XServicesDocumentation.SERVICE_OPERATION_COPY) - @WebMethod(operationName = "copy") + @WebMethod(operationName = OPERATION_COPY) public abstract ReturnCode copy( - @WebParam(name = "fileset") @XmlElement(required=true) FileSetResource src, + @WebParam(name = FileSetResource.XML_NAME) @XmlElement(required=true) FileSetResource src, @WebParam(name = "todir") @XmlElement(required=true) String todir, @WebParam(name = "preservelastmodified") boolean plm, @WebParam(name = "overwrite") boolean overwrite, @@ -103,7 +120,7 @@ public interface FileService { * @throws XServicesFault */ @WSDLDocumentation(value = XServicesDocumentation.SERVICE_OPERATION_COPYFILE) - @WebMethod(operationName = "copyFile") + @WebMethod(operationName = OPERATION_COPYFILE) public abstract ReturnCode copyFile( @WebParam(name = "fromFile") @XmlElement(required=true) String fromFile, @WebParam(name = "toFile") @XmlElement(required=true) String tofile, @@ -113,23 +130,25 @@ public interface FileService { * @param res * @param encoding * @return content of the resource + * @throws XServicesFault */ @WSDLDocumentation(value = XServicesDocumentation.SERVICE_OPERATION_LOADRESOURCE) - @WebMethod(operationName = "loadResource") + @WebMethod(operationName = OPERATION_LOADRESOURCE) public abstract String loadRes( - @WebParam(name = "resource") FileResource res, - @WebParam(name = "encoding") String encoding); + @WebParam(name = FileResource.XML_NAME) FileResource res, + @WebParam(name = "encoding") String encoding) throws XServicesFault; /** * @param res * @param encoding * @return content of the resource + * @throws XServicesFault */ @WSDLDocumentation(value = XServicesDocumentation.SERVICE_OPERATION_LOADRESOURCEFROMARCHIVE) - @WebMethod(operationName = "loadResourceFromArchive") + @WebMethod(operationName = OPERATION_LOADRESOURCEFROMARCHIVE) public abstract String loadResFromArchive( @WebParam(name = "archiveresource") ArchiveResource res, - @WebParam(name = "encoding") String encoding); + @WebParam(name = "encoding") String encoding) throws XServicesFault; /** * @param message @@ -137,45 +156,85 @@ public interface FileService { * @param encoding * @param append * @return + * @throws XServicesFault */ @WSDLDocumentation(value = XServicesDocumentation.SERVICE_OPERATION_ECHOTOFILE) - @WebMethod(operationName = "echoToFile") + @WebMethod(operationName = OPERATION_ECHOTOFILE) public abstract ReturnCode echo2file( @WebParam(name = "message") @XmlElement(required=true) String message, @WebParam(name = "file") @XmlElement(required=true) String file, @WebParam(name = "encoding") String encoding, - @WebParam(name = "append") boolean append); + @WebParam(name = "append") boolean append) throws XServicesFault; - @WebMethod(operationName = "changeOwner") + /** + * @param res + * @param owner + * @return + */ + @WebMethod(operationName = OPERATION_CHANGEOWNER) public abstract ReturnCode changeOwner( - @WebParam(name = "fileset") FileSetResource res, + @WebParam(name = FileSetResource.XML_NAME) FileSetResource res, @WebParam(name = "owner") @XmlElement(required=true) String owner); - @WebMethod(operationName = "changeGroup") + /** + * @param res + * @param group + * @return + */ + @WebMethod(operationName = OPERATION_CHANGEGROUP) public abstract ReturnCode changeGroup( - @WebParam(name = "fileset") FileSetResource res, + @WebParam(name = FileSetResource.XML_NAME) FileSetResource res, @WebParam(name = "group") @XmlElement(required=true) String group); - @WebMethod(operationName = "changeMode") + /** + * @param res + * @param perm + * @return + */ + @WebMethod(operationName = OPERATION_CHANGEMODE) public abstract ReturnCode changeMode( - @WebParam(name = "fileset") FileSetResource res, + @WebParam(name = FileSetResource.XML_NAME) FileSetResource res, @WebParam(name = "permissions") @XmlElement(required=true) String perm); - @WebMethod(operationName = "replaceInFile") + /** + * @param res + * @param search + * @param replace + * @return + * @throws XServicesFault + */ + @WSDLDocumentation(value = XServicesDocumentation.SERVICE_OPERATION_REPLACEINFILE) + @WebMethod(operationName = OPERATION_REPLACEINFILE) public abstract ReturnCode replaceInFile( - @WebParam(name = "file") @XmlElement(required=true) FileResource res, + @WebParam(name = FileResource.XML_NAME) @XmlElement(required=true) FileResource res, @WebParam(name = "search") @XmlElement(required=true) String search, - @WebParam(name = "replace") @XmlElement(required=true) String replace); + @WebParam(name = "replace") @XmlElement(required=true) String replace) throws XServicesFault; - @WebMethod(operationName = "replaceInFile2") + /** + * @param res + * @param patternList + * @return + * @throws XServicesFault + */ + @WSDLDocumentation(value = XServicesDocumentation.SERVICE_OPERATION_REPLACEINFILE2) + @WebMethod(operationName = OPERATION_REPLACEINFILE2) public abstract ReturnCode replaceInFile2( - @WebParam(name = "file") FileResource res, - @WebParam(name = "patternList") List patternList); + @WebParam(name = FileResource.XML_NAME) FileResource res, + @WebParam(name = "patternList") List patternList) throws XServicesFault; - @WebMethod(operationName = "replaceInFileRegEx") + /** + * @param res + * @param search + * @param replace + * @param flags + * @return + * @throws XServicesFault + */ + @WSDLDocumentation(value = XServicesDocumentation.SERVICE_OPERATION_REPLACEINFILEREGEX) + @WebMethod(operationName = OPERATION_REPLACEINFILEREGEX) public abstract ReturnCode replaceInFileRegEx( - @WebParam(name = "file") FileResource res, + @WebParam(name = FileResource.XML_NAME) FileResource res, @WebParam(name = "search") String search, @WebParam(name = "replace") String replace, - @WebParam(name = "flags") String flags); + @WebParam(name = "flags") String flags) throws XServicesFault; } \ No newline at end of file diff --git a/src/java/net/brutex/xservices/ws/XServicesFault.java b/src/java/net/brutex/xservices/ws/XServicesFault.java index eacd8d3..514c59a 100644 --- a/src/java/net/brutex/xservices/ws/XServicesFault.java +++ b/src/java/net/brutex/xservices/ws/XServicesFault.java @@ -18,14 +18,20 @@ package net.brutex.xservices.ws; import java.util.GregorianCalendar; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; +import javax.xml.ws.WebFault; + +import net.brutex.xservices.util.BrutexNamespaces; /** * * @author Brian Rosenberger, bru@brutex.de */ +@WebFault(targetNamespace=BrutexNamespaces.WS_XSERVICES) public class XServicesFault extends Exception { /** @@ -58,15 +64,34 @@ public class XServicesFault extends Exception { } - @XmlElement(name="faultstring") + /** + * The error message. + */ + @XmlElement(name="faultstring", namespace=BrutexNamespaces.WS_XSERVICES) public String faultstring = ""; - @XmlElement(name="username") + /** + * Username under which the web service has been executed. + */ + @XmlElement(name="username", namespace=BrutexNamespaces.WS_XSERVICES) public String username = System.getProperty("user.name"); - @XmlElement(name="homedir") + /** + * Home directory of the user profile running the web service. + */ + @XmlElement(name="homedir", namespace=BrutexNamespaces.WS_XSERVICES) public String homedir = System.getProperty("user.home"); - @XmlElement(name="timstamp") + + /** + * Timestamp when the fault was thrown. + */ + @XmlElement(name="timstamp", namespace=BrutexNamespaces.WS_XSERVICES) public XMLGregorianCalendar timestamp = null; + + /** + * Java runtime version. + */ + @XmlElement(name="jvmversion") + public String jvmruntime = System.getProperty("java.version"); } diff --git a/src/java/net/brutex/xservices/ws/impl/FileServiceImpl.java b/src/java/net/brutex/xservices/ws/impl/FileServiceImpl.java index b3cbf39..7fb6f18 100644 --- a/src/java/net/brutex/xservices/ws/impl/FileServiceImpl.java +++ b/src/java/net/brutex/xservices/ws/impl/FileServiceImpl.java @@ -15,15 +15,11 @@ */ package net.brutex.xservices.ws.impl; -import java.io.BufferedInputStream; 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.Iterator; import java.util.List; import javax.activation.DataHandler; @@ -31,21 +27,17 @@ 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.ReplacePattern; -import net.brutex.xservices.types.ResourceInterface; import net.brutex.xservices.types.ReturnCode; import net.brutex.xservices.util.BrutexNamespaces; import net.brutex.xservices.util.RunTask; import net.brutex.xservices.ws.FileService; import net.brutex.xservices.ws.XServicesFault; -import org.apache.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; @@ -58,8 +50,6 @@ import org.apache.tools.ant.taskdefs.optional.ReplaceRegExp; 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.Resource; -import org.apache.tools.ant.types.ResourceCollection; /** * @@ -75,9 +65,7 @@ public class FileServiceImpl implements FileService { * java.lang.String) */ @Override - @WebMethod(operationName = "basename") - public String basename(@WebParam(name = "file") String filename, - @WebParam(name = "suffix") String suffix) { + public String basename(String filename, String suffix) { final String BASENAME_VALUE = "basename.value"; Basename basename = new Basename(); RunTask runner = new RunTask(basename); @@ -85,16 +73,13 @@ public class FileServiceImpl implements FileService { if (suffix != null && !suffix.equals("")) { basename.setSuffix(suffix); } - basename.setProperty("BASENAME_VALUE"); + basename.setProperty(BASENAME_VALUE); ReturnCode r = runner.postTask(); - return r.getProperty("BASENAME_VALUE"); + return r.getProperty(BASENAME_VALUE); } - @WebMethod(operationName = "replaceInFile") - public ReturnCode replaceInFile( - @WebParam(name = "file") FileResource res, - @WebParam(name = "search") String search, - @WebParam(name = "replace") String replace) { + public ReturnCode replaceInFile(FileResource res, String search, + String replace) throws XServicesFault { ReturnCode r = null; Replace rep = new Replace(); rep.setTaskName("Replace"); @@ -102,14 +87,16 @@ public class FileServiceImpl implements FileService { rep.addConfigured(res.getAntResource(rep.getProject())); rep.setToken(search); rep.setValue(replace); - r = runner.postTask(); + try { + r = runner.postTask(); + } catch (BuildException e) { + throw new XServicesFault(e); + } return r; } - - @WebMethod(operationName = "replaceInFile2") - public ReturnCode replaceInFile2( - @WebParam(name = "file") FileResource res, - @WebParam(name = "patternList") List patternList) { + + public ReturnCode replaceInFile2(FileResource res, + List patternList) throws XServicesFault { ReturnCode r = null; for (ReplacePattern pat : patternList) { Replace rep = new Replace(); @@ -118,17 +105,17 @@ public class FileServiceImpl implements FileService { rep.addConfigured(res.getAntResource(rep.getProject())); rep.setToken(pat.search); rep.setValue(pat.replace); - r = runner.postTask(); + try { + r = runner.postTask(); + } catch (BuildException e) { + throw new XServicesFault(e); + } } return r; } - - @WebMethod(operationName = "replaceInFileRegEx") - public ReturnCode replaceInFileRegEx( - @WebParam(name = "file") FileResource res, - @WebParam(name = "search") String search, - @WebParam(name = "replace") String replace, - @WebParam(name = "flags") String flags) { + + public ReturnCode replaceInFileRegEx(FileResource res, String search, + String replace, String flags) throws XServicesFault { ReplaceRegExp rep = new ReplaceRegExp(); rep.setTaskName("ReplaceRegExp"); RunTask runner = new RunTask(rep); @@ -137,11 +124,14 @@ public class FileServiceImpl implements FileService { rep.setMatch(search); rep.setReplace(replace); rep.setFlags(flags); - ReturnCode r = runner.postTask(); - return r; + try { + ReturnCode r = runner.postTask(); + return r; + } catch (BuildException e) { + throw new XServicesFault(e); + } } - - + /* * (non-Javadoc) * @@ -150,21 +140,20 @@ public class FileServiceImpl implements FileService { * .types.FileSetResource) */ @Override - @WebMethod(operationName = "downloadFile") - public AttachmentType downloadFile(@WebParam(name = "file") FileResource res) { + public AttachmentType downloadFile(FileResource res) throws XServicesFault { InputStream is = null; try { is = res.getAntResource(null).getInputStream(); + StreamDataSource ssource = new StreamDataSource( + "application/binary", is); + DataHandler h = new DataHandler(ssource); + AttachmentType t = new AttachmentType(); + t.setContent(h); + t.setFilename(res.getAntResource(null).getName()); + return t; } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + throw new XServicesFault(e); } - DataHandler h = new DataHandler(new StreamDataSource( - "application/binary", is)); - AttachmentType t = new AttachmentType(); - t.setContent(h); - t.setFilename(res.getAntResource(null).getName()); - return t; } /* @@ -175,28 +164,19 @@ public class FileServiceImpl implements FileService { * .types.AttachmentType) */ @Override - @WebMethod(operationName = "uploadFile") - public String uploadFile(@WebParam(name = "file") AttachmentType file) { - DataHandler h = file.getContent(); + public String uploadFile(AttachmentType file) throws XServicesFault { + 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); + throw new XServicesFault(e); } catch (IOException e) { - throw new BuildException(e); + throw new XServicesFault(e); } return file.getFilename(); } @@ -209,25 +189,40 @@ public class FileServiceImpl implements FileService { * .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(FileSetResource src, String todir, boolean plm, + boolean overwrite, String encoding) throws XServicesFault { + Copy copy = new Copy(); + copy.setTaskName("Copy"); + RunTask runner = new RunTask(copy); + FileSet set = src.getAntResource(copy.getProject()); + copy.add(set); + File dst = new File(todir); + if (dst.isDirectory()) { + copy.setTodir(dst); + } + if (dst.isFile()) { + copy.setTofile(dst); + } + copy.setOverwrite(overwrite); + copy.setPreserveLastModified(plm); + if (encoding != null && !encoding.equals("")) { + copy.setOutputEncoding(encoding); + } else { + copy.setOutputEncoding(System.getProperty("file.encoding")); + } + return runner.postTask(); } - + @Override - public ReturnCode copyFile(String fromFile, - String tofile, - boolean overwrite) throws XServicesFault { + public ReturnCode copyFile(String fromFile, String tofile, boolean overwrite) + throws XServicesFault { Copy copy = new Copy(); copy.setTaskName("Copy"); RunTask runner = new RunTask(copy); File f = new File(fromFile); - if( ! f.isFile() ) throw new XServicesFault("File '"+fromFile+"' not found."); - copy.setFile( new File( fromFile )); + if (!f.isFile()) + throw new XServicesFault("File '" + fromFile + "' not found."); + copy.setFile(new File(fromFile)); copy.setTofile(new File(tofile)); copy.setOverwrite(overwrite); return runner.postTask(); @@ -241,9 +236,8 @@ public class FileServiceImpl implements FileService { * .types.FileResource, java.lang.String) */ @Override - @WebMethod(operationName = "loadResource") - public String loadRes(@WebParam(name = "resource") FileResource res, - @WebParam(name = "encoding") String encoding) { + public String loadRes(FileResource res, String encoding) + throws XServicesFault { if (encoding == null || encoding.equals("")) { encoding = System.getProperty("file.encoding"); } @@ -266,10 +260,7 @@ public class FileServiceImpl implements FileService { * .xservices.types.ArchiveResource, java.lang.String) */ @Override - @WebMethod(operationName = "loadResourceFromArchive") - public String loadResFromArchive( - @WebParam(name = "archiveresource") ArchiveResource res, - @WebParam(name = "encoding") String encoding) { + public String loadResFromArchive(ArchiveResource res, String encoding) { if (encoding == null || encoding.equals("")) { encoding = System.getProperty("file.encoding"); } @@ -282,7 +273,7 @@ public class FileServiceImpl implements FileService { lr.setProperty("LoadResource.out"); ReturnCode r = runner.postTask(); return r.getProperty("LoadResource.out"); - + } /* @@ -292,12 +283,30 @@ public class FileServiceImpl implements FileService { * java.lang.String, java.lang.String, boolean) */ @Override - @WebMethod(operationName = "echoToFile") - public ReturnCode echo2file(@WebParam(name = "message") String message, - @WebParam(name = "file") String file, - @WebParam(name = "encoding") String encoding, - @WebParam(name = "append") boolean append) { - return echo(message, new File(file), encoding, append); + public ReturnCode echo2file(String message, String file, String encoding, + boolean append) throws XServicesFault { + + Echo echo = new Echo(); + echo.setTaskName("toFile"); + RunTask runTask = new RunTask(echo); + echo.addText(message); + echo.setEncoding(encoding); + File f = new File(file); + try { + if (!f.canWrite()) + + throw new XServicesFault("Cannot write to file: " + + f.getCanonicalPath()); + + echo.setFile(f); + echo.setAppend(append); + ReturnCode c = runTask.postTask(); + return c; + } catch (BuildException e) { + throw new XServicesFault("Error in echo2file.", e); + } catch (IOException e) { + throw new XServicesFault("Cannot write to file.", e); + } } /* @@ -308,11 +317,15 @@ public class FileServiceImpl implements FileService { * .types.FileSetResource, java.lang.String) */ @Override - @WebMethod(operationName = "changeOwner") - public ReturnCode changeOwner( - @WebParam(name = "fileset") FileSetResource res, - @WebParam(name = "owner") String owner) { - return chown(res, owner); + public ReturnCode changeOwner(FileSetResource res, String owner) { + Chown chown = new Chown(); + chown.setTaskName("Chown"); + RunTask runner = new RunTask(chown); + chown.setOwner(owner); + FileSet set = res.getAntResource(chown.getProject()); + chown.add(set); + chown.setMaxParallel(300); + return runner.postTask(); } /* @@ -323,11 +336,15 @@ public class FileServiceImpl implements FileService { * .types.FileSetResource, java.lang.String) */ @Override - @WebMethod(operationName = "changeGroup") - public ReturnCode changeGroup( - @WebParam(name = "fileset") FileSetResource res, - @WebParam(name = "group") String group) { - return chgrp(res, group); + public ReturnCode changeGroup(FileSetResource res, String group) { + Chgrp chgrp = new Chgrp(); + chgrp.setTaskName("Chgrp"); + RunTask runner = new RunTask(chgrp); + chgrp.setGroup(group); + FileSet set = res.getAntResource(chgrp.getProject()); + chgrp.add(set); + chgrp.setMaxParallel(300); + return runner.postTask(); } /* @@ -338,82 +355,11 @@ public class FileServiceImpl implements FileService { * .types.FileSetResource, java.lang.String) */ @Override - @WebMethod(operationName = "changeMode") - public ReturnCode changeMode( - @WebParam(name = "fileset") FileSetResource res, - @WebParam(name = "permissions") String perm) { - return chmod(res, perm); - } - - @WebMethod(exclude = true) - private ReturnCode 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.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")); - } - - 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.getAntResource(chgrp.getProject()); - chgrp.add(set); - chgrp.setMaxParallel(300); - return runner.postTask(); - } - - @WebMethod(exclude = true) - private ReturnCode chmod(FileSetResource src, String perm) { + public ReturnCode changeMode(FileSetResource res, String perm) { Chmod chmod = new Chmod(); chmod.setTaskName("Chmod"); RunTask runner = new RunTask(chmod); - FileSet set = src.getAntResource(chmod.getProject()); + FileSet set = res.getAntResource(chmod.getProject()); chmod.add(set); chmod.setMaxParallel(300); chmod.setPerm(perm); diff --git a/test/FileService-soapui-project.xml b/test/FileService-soapui-project.xml index ade1737..64827c5 100644 --- a/test/FileService-soapui-project.xml +++ b/test/FileService-soapui-project.xml @@ -1,16 +1,877 @@ - - - - - 0 - - - - basename.value - xservices - - - - - \ No newline at end of file +http://localhost:8080/XServices/FileService?wsdl + /* +* Copyright 2010 Brian Rosenberger (Brutex Network) +* +* Licensed under the Apache License, Version 2.0 (the "License") +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Download a file from the maschine where the service is running in order to process it with the client. The file is either downloaded as a MTOM attachment or as inline base64 encoded block. Keep in mind that unless you are using MTOM, a lot of java heap memory is used. + + + + + + + + + + + + + + + + + + + + + + Write or append a string to a file + + + + + + Send a file from client to web service server using either MTOM attachment or base64 inline attachment. + + + + + + + + + + Copies a fileset locally on the server. + + + + + + + + + + Load the content of a resource + + + + + + The base name of the given file excluding the suffix. + + + + + Load the content of a resource + + + + + + Copies a single file locally on the server + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +]]>http://schemas.xmlsoap.org/wsdl/http://localhost:8080/XServices/FileServiceUTF-8http://localhost:8080/XServices/FileService + + + + ? + + ? + + +]]>UTF-8http://localhost:8080/XServices/FileService + + + + + + FILES + ? + + + **/* + + ? + + + + + ? + true + false + + + + + + true + + ? + + +]]>UTF-8http://localhost:8080/XServices/FileService + + + + + + FILES + ? + + + **/* + + ? + + + + + ? + true + false + + + + + + true + + ? + + +]]>UTF-8http://localhost:8080/XServices/FileService + + + + + + FILES + ? + + + **/* + + ? + + + + + ? + true + false + + + + + + true + + ? + + +]]>UTF-8http://localhost:8080/XServices/FileService + + + + + FILES + ? + + + **/* + + ? + + + + + ? + true + false + + + + + + true + + ? + ? + ? + + ? + + +]]>UTF-8http://localhost:8080/XServices/FileService + + + + ? + ? + ? + + +]]>UTF-8http://localhost:8080/XServices/FileService + + + + + + FILE + ? + + + +]]>UTF-8http://localhost:8080/XServices/FileService + + + + ? + ? + + ? + ? + + +]]>UTF-8http://localhost:8080/XServices/FileService + + + + + + FILE + ? + + + ? + + +]]>UTF-8http://localhost:8080/XServices/FileService + + + + + + ZIP + ? + ? + + + ? + + +]]>UTF-8http://localhost:8080/XServices/FileService + + + + + FILE + ? + + ? + ? + + +]]>UTF-8http://localhost:8080/XServices/FileService + + + + + + FILE + ? + + + + ? + ? + + + +]]>UTF-8http://localhost:8080/XServices/FileService + + + + + + FILE + ? + + + ? + + ? + + ? + + +]]>UTF-8http://localhost:8080/XServices/FileService + + + + + + cid:1190185022376 + + ? + + + +]]> \ No newline at end of file