Subversion Repositories XServices

Compare Revisions

Problem with comparison.

Ignore whitespace Rev HEAD → Rev 96

/xservices/trunk/src/java/net/brutex/xservices/ws/impl/ArchiveServiceImpl.java
0,0 → 1,324
/*
* Copyright 2010 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.brutex.xservices.ws.impl;
 
import java.io.File;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import net.brutex.xservices.types.ArchiveResource;
import net.brutex.xservices.types.CompressionType;
import net.brutex.xservices.types.FileResource;
import net.brutex.xservices.types.ResourceInterface;
import net.brutex.xservices.types.ReturnCode;
import net.brutex.xservices.util.BrutexNamespaces;
import net.brutex.xservices.util.RunTask;
import net.brutex.xservices.util.UnRarTask;
import net.brutex.xservices.ws.ArchiveService;
 
import org.apache.tools.ant.taskdefs.BUnzip2;
import org.apache.tools.ant.taskdefs.BZip2;
import org.apache.tools.ant.taskdefs.Expand;
import org.apache.tools.ant.taskdefs.GUnzip;
import org.apache.tools.ant.taskdefs.GZip;
import org.apache.tools.ant.taskdefs.Untar;
import org.apache.tools.ant.taskdefs.Zip;
 
/**
*
* @author Brian Rosenberger, bru@brutex.de
*/
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES,
endpointInterface="net.brutex.xservices.ws.ArchiveService",
serviceName = "ArchiveService")
public class ArchiveServiceImpl implements ArchiveService {
 
 
/* (non-Javadoc)
* @see net.brutex.xservices.ws.ArchiveService#bzip2(net.brutex.xservices.types.FileResource, java.lang.String)
*/
@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) {
return bzip(src, new File(file));
}
 
/* (non-Javadoc)
* @see net.brutex.xservices.ws.ArchiveService#bzip2FromArchive(net.brutex.xservices.types.ArchiveResource, java.lang.String)
*/
@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) {
return null;// return bzip(src, new File(file));
}
 
/* (non-Javadoc)
* @see net.brutex.xservices.ws.ArchiveService#gzip(net.brutex.xservices.types.FileResource, java.lang.String)
*/
@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) {
return gzip(src, new File(file));
}
 
/* (non-Javadoc)
* @see net.brutex.xservices.ws.ArchiveService#gzipFromArchive(net.brutex.xservices.types.ArchiveResource, java.lang.String)
*/
@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) {
return gzip(src, new File(file));
}
 
/* (non-Javadoc)
* @see net.brutex.xservices.ws.ArchiveService#gunzip(java.lang.String, java.lang.String)
*/
@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) {
File target = null;
if (!dest.equals("") && dest != null) {
target = new File(dest);
}
return GUnzip(new FileResource(FileResource.Type.FILE, src), target);
}
 
/* (non-Javadoc)
* @see net.brutex.xservices.ws.ArchiveService#bunzip2(java.lang.String, java.lang.String)
*/
@WebMethod(operationName = WS_OPERATION_BUNZIP2)
public ReturnCode bunzip2(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
File target = null;
if (!dest.equals("") && dest != null) {
target = new File(dest);
}
return BUnzip2(new FileResource(FileResource.Type.FILE, src), target);
}
 
/* (non-Javadoc)
* @see net.brutex.xservices.ws.ArchiveService#gunzipFromURL(java.lang.String, java.lang.String)
*/
@WebMethod(operationName = "gunzipFromURL")
public ReturnCode gunzipFromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src,
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
File target = null;
if (!dest.equals("") && dest != null) {
target = new File(dest);
}
return GUnzip(new FileResource(FileResource.Type.URL, src), target);
}
 
/* (non-Javadoc)
* @see net.brutex.xservices.ws.ArchiveService#bunzip2FromURL(java.lang.String, java.lang.String)
*/
@WebMethod(operationName = "bunzip2FromURL")
public ReturnCode bunzip2FromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src,
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
File target = null;
if (!dest.equals("") && dest != null) {
target = new File(dest);
}
return BUnzip2(new FileResource(FileResource.Type.URL, src), target);
}
 
/* (non-Javadoc)
* @see net.brutex.xservices.ws.ArchiveService#zip(net.brutex.xservices.types.FileResource, java.lang.String, boolean, java.lang.String, int)
*/
@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) {
if (level > 9) {
level = 9;
}
if (level < 0) {
level = 0;
}
return zip(src, new File(file), encoding, !overwrite, level);
}
 
/* (non-Javadoc)
* @see net.brutex.xservices.ws.ArchiveService#zipFromArchive(net.brutex.xservices.types.ArchiveResource, java.lang.String, boolean, java.lang.String, int)
*/
@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) {
return zip(src, new File(file), encoding, !update, level);
}
 
/* (non-Javadoc)
* @see net.brutex.xservices.ws.ArchiveService#unzip(java.lang.String, java.lang.String, boolean, java.lang.String)
*/
@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) {
return unzip(new File(src), new File(dest), overwrite, encoding);
}
 
/* (non-Javadoc)
* @see net.brutex.xservices.ws.ArchiveService#unrar(java.lang.String, java.lang.String)
*/
@WebMethod(operationName = "unrar")
public ReturnCode unrar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
return unrar(new File(src), new File(dest));
}
 
/* (non-Javadoc)
* @see net.brutex.xservices.ws.ArchiveService#untar(java.lang.String, java.lang.String, boolean, net.brutex.xservices.types.CompressionType)
*/
@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) {
Untar.UntarCompressionMethod c = new Untar.UntarCompressionMethod();
switch (compression) {
case GZIP:
c.setValue("gzip");
break;
case BZIP2:
c.setValue("bzip2");
break;
default:
c.setValue("none");
break;
}
return untar(new File(src), new File(dest), overwrite, c);
}
 
@WebMethod(exclude = true)
private ReturnCode bzip(ResourceInterface src, File dst) {
if (dst.exists() && dst.isFile()) {
dst.delete();
}
BZip2 bzip = new BZip2();
bzip.setTaskName("BZip2");
RunTask runner = new RunTask(bzip);
bzip.setSrcResource(src.getAntResource(bzip.getProject()));
bzip.setDestfile(dst);
 
return runner.postTask();
}
 
@WebMethod(exclude = true)
private ReturnCode gzip(ResourceInterface src, File dst) {
if (dst.exists() && dst.isFile()) {
dst.delete();
}
GZip gzip = new GZip();
gzip.setTaskName("GZip");
RunTask runner = new RunTask(gzip);
gzip.addConfigured(src.getAntResource(gzip.getProject()));
gzip.setDestfile(dst);
return runner.postTask();
}
 
@WebMethod(exclude = true)
private ReturnCode zip(ResourceInterface src, File dst, String encoding, boolean update, int compresslevel) {
Zip zip = new Zip();
zip.setTaskName("Zip");
RunTask runner = new RunTask(zip);
zip.add(src.getAntResource(zip.getProject()));
zip.setDestFile(dst);
if (encoding != null && !encoding.equals("")) {
zip.setEncoding(encoding);
}
zip.setUpdate(update);
zip.setLevel(compresslevel);
return runner.postTask();
}
 
@WebMethod(exclude = true)
private ReturnCode GUnzip(ResourceInterface src, File dst) {
GUnzip uz = new GUnzip();
uz.setTaskName("GUnzip");
RunTask runner = new RunTask(uz);
uz.setSrcResource(src.getAntResource(uz.getProject()));
if (dst != null) {
uz.setDest(dst);
}
return runner.postTask();
}
 
@WebMethod(exclude = true)
private ReturnCode BUnzip2(ResourceInterface src, File dst) {
BUnzip2 uz = new BUnzip2();
uz.setTaskName("BUnzip2");
RunTask runner = new RunTask(uz);
uz.setSrcResource(src.getAntResource(uz.getProject()));
if (dst != null) {
uz.setDest(dst);
}
return runner.postTask();
}
 
@WebMethod(exclude = true)
private ReturnCode unzip(File src, File dest, boolean overwrite, String encoding) {
Expand unzip = new Expand();
unzip.setTaskName("UnZip");
RunTask runner = new RunTask(unzip);
unzip.setSrc(src);
unzip.setDest(dest);
unzip.setOverwrite(overwrite);
if (encoding != null && !encoding.equals("")) {
unzip.setEncoding(encoding);
}
return runner.postTask();
}
 
@WebMethod(exclude = true)
private ReturnCode untar(File src, File dest, boolean overwrite, Untar.UntarCompressionMethod compression) {
Untar unzip = new Untar();
unzip.setTaskName("Untar");
RunTask runner = new RunTask(unzip);
unzip.setSrc(src);
unzip.setDest(dest);
unzip.setOverwrite(overwrite);
unzip.setCompression(compression);
return runner.postTask();
}
 
@WebMethod(exclude = true)
private ReturnCode unrar(File src, File dst) {
UnRarTask unrar = new UnRarTask();
unrar.setTaskName("UnRar");
RunTask runner = new RunTask(unrar);
unrar.setSrc(src);
unrar.setDst(dst);
return runner.postTask();
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/ws/impl/FileServiceImpl.java
0,0 → 1,393
/*
* Copyright 2010 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
 
package net.brutex.xservices.ws.impl;
 
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
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.ReplacePattern;
import net.brutex.xservices.types.ReturnCode;
import net.brutex.xservices.types.ant.ArchiveResource;
import net.brutex.xservices.types.ant.AttachmentType;
import net.brutex.xservices.types.ant.FileResource;
import net.brutex.xservices.types.ant.FileSetResource;
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.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;
import org.apache.tools.ant.taskdefs.Echo;
import org.apache.tools.ant.taskdefs.LoadResource;
import org.apache.tools.ant.taskdefs.Replace;
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;
 
/**
*
* @author Brian Rosenberger, bru@brutex.de
*/
@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)
*/
public String basename(String filename, String suffix) {
final String BASENAME_VALUE = "basename.value";
Basename basename = new Basename();
RunTask runner = new RunTask(basename);
basename.setFile(new File(filename));
if (suffix != null && !suffix.equals("")) {
basename.setSuffix(suffix);
}
basename.setProperty(BASENAME_VALUE);
ReturnCode r = runner.postTask();
return r.getProperty(BASENAME_VALUE);
}
 
public ReturnCode replaceInFile(FileResource res, String search,
String replace) throws XServicesFault {
ReturnCode r = null;
Replace rep = new Replace();
rep.setTaskName("Replace");
RunTask runner = new RunTask(rep);
rep.addConfigured(res.getAntResource(rep.getProject()));
rep.setToken(search);
rep.setValue(replace);
try {
r = runner.postTask();
} catch (BuildException e) {
throw new XServicesFault(e);
}
return r;
}
 
public ReturnCode replaceInFile2(FileResource res,
List<ReplacePattern> patternList) throws XServicesFault {
ReturnCode r = null;
for (ReplacePattern pat : patternList) {
Replace rep = new Replace();
rep.setTaskName("Replace");
RunTask runner = new RunTask(rep);
rep.addConfigured(res.getAntResource(rep.getProject()));
rep.setToken(pat.search);
rep.setValue(pat.replace);
try {
r = runner.postTask();
} catch (BuildException e) {
throw new XServicesFault(e);
}
}
return r;
}
 
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);
File infile = new File(res.uri);
rep.setFile(infile);
rep.setMatch(search);
rep.setReplace(replace);
rep.setFlags(flags);
try {
ReturnCode r = runner.postTask();
return r;
} catch (BuildException e) {
throw new XServicesFault(e);
}
}
 
/*
* (non-Javadoc)
*
* @see
* net.brutex.xservices.ws.impl.FileService#base64Encode(net.brutex.xservices
* .types.FileSetResource)
*/
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) {
throw new XServicesFault(e);
}
}
public byte[] encodeFile(FileResource res) throws XServicesFault {
InputStream is = null;
try {
is = res.getAntResource(null).getInputStream();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
 
int nRead;
byte[] data = new byte[4096];
while ((nRead = is.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
buffer.flush();
return buffer.toByteArray();
} catch (IOException e) {
throw new XServicesFault(e);
}
}
 
/*
* (non-Javadoc)
*
* @see
* net.brutex.xservices.ws.impl.FileService#base64Decode(net.brutex.xservices
* .types.AttachmentType)
*/
public String uploadFile(AttachmentType file) throws XServicesFault {
DataHandler h = file.getContent();
File f = new File(file.getFilename());
FileOutputStream fout;
try {
fout = new FileOutputStream(f);
h.writeTo(fout);
fout.flush();
fout.close();
} catch (FileNotFoundException e) {
throw new XServicesFault(e);
} catch (IOException e) {
throw new XServicesFault(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)
*/
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();
}
 
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));
copy.setTofile(new File(tofile));
copy.setOverwrite(overwrite);
return runner.postTask();
}
 
/*
* (non-Javadoc)
*
* @see
* net.brutex.xservices.ws.impl.FileService#loadRes(net.brutex.xservices
* .types.FileResource, java.lang.String)
*/
public String loadRes(FileResource res, String encoding)
throws XServicesFault {
if (encoding == null || encoding.equals("")) {
encoding = System.getProperty("file.encoding");
}
LoadResource lr = new LoadResource();
lr.setTaskName("LoadResource");
RunTask runner = new RunTask(lr);
lr.addConfigured(res.getAntResource(lr.getProject()));
lr.setEncoding(encoding);
System.out.println("Using encoding: " + encoding);
lr.setProperty("LoadResource.out");
ReturnCode r = runner.postTask();
return r.getProperty("LoadResource.out");
}
 
/*
* (non-Javadoc)
*
* @see
* net.brutex.xservices.ws.impl.FileService#loadResFromArchive(net.brutex
* .xservices.types.ArchiveResource, java.lang.String)
*/
public String loadResFromArchive(ArchiveResource res, String encoding) {
if (encoding == null || encoding.equals("")) {
encoding = System.getProperty("file.encoding");
}
LoadResource lr = new LoadResource();
lr.setTaskName("LoadResource");
RunTask runner = new RunTask(lr);
lr.addConfigured(res.getAntResource(lr.getProject()));
lr.setEncoding(encoding);
System.out.println("Using encoding: " + encoding);
lr.setProperty("LoadResource.out");
ReturnCode r = runner.postTask();
return r.getProperty("LoadResource.out");
 
}
 
/*
* (non-Javadoc)
*
* @see net.brutex.xservices.ws.impl.FileService#echo2file(java.lang.String,
* java.lang.String, java.lang.String, boolean)
*/
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);
}
}
 
/*
* (non-Javadoc)
*
* @see
* net.brutex.xservices.ws.impl.FileService#changeOwner(net.brutex.xservices
* .types.FileSetResource, java.lang.String)
*/
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();
}
 
/*
* (non-Javadoc)
*
* @see
* net.brutex.xservices.ws.impl.FileService#changeGroup(net.brutex.xservices
* .types.FileSetResource, java.lang.String)
*/
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();
}
 
/*
* (non-Javadoc)
*
* @see
* net.brutex.xservices.ws.impl.FileService#changeMode(net.brutex.xservices
* .types.FileSetResource, java.lang.String)
*/
public ReturnCode changeMode(FileSetResource res, String perm) {
Chmod chmod = new Chmod();
chmod.setTaskName("Chmod");
RunTask runner = new RunTask(chmod);
FileSet set = res.getAntResource(chmod.getProject());
chmod.add(set);
chmod.setMaxParallel(300);
chmod.setPerm(perm);
chmod.setVerbose(true);
return runner.postTask();
}
 
}
/xservices/trunk/src/java/net/brutex/xservices/ws/impl/StringServiceImpl.java
0,0 → 1,99
/*
* Copyright 2012 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.brutex.xservices.ws.impl;
 
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
import javax.jws.WebService;
 
import net.brutex.xservices.types.StringMatchType;
import net.brutex.xservices.types.StringReplaceType;
import net.brutex.xservices.util.BrutexNamespaces;
import net.brutex.xservices.ws.StringService;
import net.brutex.xservices.ws.XServicesFault;
 
/**
* @author Brian Rosenberger
* @since 0.5.0
*
*/
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.StringService", serviceName = StringService.SERVICE_NAME)
public class StringServiceImpl implements StringService {
 
public StringReplaceType replaceRegEx(String res, String search,
String replace, String flags) throws XServicesFault {
try {
int allflags = getFlags(flags);
Pattern pattern = Pattern.compile(search, allflags);
Matcher matcher = pattern.matcher(res);
int count = 0;
while (matcher.find()) {
count++;
}
if (flags.contains("g")) {
return new StringReplaceType(matcher.replaceAll(replace), count);
} else {
if (count > 1)
count = 1;
return new StringReplaceType(matcher.replaceFirst(replace),
count);
}
} catch (Exception e) {
throw new XServicesFault(e);
}
 
}
 
@Override
public StringMatchType matchRegEx(String res, String search, String flags)
throws XServicesFault {
int allflags = getFlags(flags);
Pattern pattern = Pattern.compile(search, allflags);
Matcher matcher = pattern.matcher(res);
StringMatchType rm = new StringMatchType();
while (matcher.find()) {
for(int i=0; i<=matcher.groupCount();i++){
rm.addStringMatch(matcher.start(), matcher.end(), matcher.group(i));
}
}
return rm;
}
private int getFlags(String flags) {
int allflags = 0;
if(flags.contains("i")) {
allflags = allflags + Pattern.CASE_INSENSITIVE;
}
if(flags.contains("m")) {
allflags = allflags + Pattern.MULTILINE;
}
if(flags.contains("u")) {
allflags = allflags + Pattern.UNICODE_CASE;
}
if(flags.contains("s")) {
allflags = allflags + Pattern.DOTALL;
}
if(flags.contains("d")) {
allflags = allflags + Pattern.UNIX_LINES;
}
if(flags.contains("x")) {
allflags = allflags + Pattern.COMMENTS;
}
return allflags;
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/ws/impl/StorageServiceImpl.java
0,0 → 1,58
/*
* 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.ws.impl;
 
import javax.jws.WebService;
 
import net.brutex.xservices.types.TargetNodeType;
import net.brutex.xservices.types.ant.AttachmentType;
import net.brutex.xservices.types.ant.CollectionType;
import net.brutex.xservices.util.BrutexNamespaces;
import net.brutex.xservices.ws.StorageService;
import net.brutex.xservices.ws.XServicesFault;
 
/**
* @author Brian Rosenberger
* @since 0.5.0
*
*/
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.StorageService", serviceName = StorageService.SERVICE_NAME)
public class StorageServiceImpl implements StorageService {
 
public String storeText(String text) throws XServicesFault {
// TODO Auto-generated method stub
System.err.println("storeText is not yet implemented");
return null;
}
 
public String storeBinary(AttachmentType binary) throws XServicesFault {
// TODO Auto-generated method stub
System.err.println("storeBinary is not yet implemented");
return null;
}
 
public String createCollection(CollectionType collection)
throws XServicesFault {
return collection.getUuid();
}
public void deliverCollection(CollectionType collection,
TargetNodeType targetnode, boolean isFiring) throws XServicesFault {
// TODO Auto-generated method stub
System.err.println("deliverCollection is not yet implemented");
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/ws/impl/JobServiceImpl.java
0,0 → 1,161
/*
* Copyright 2012 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.brutex.xservices.ws.impl;
 
 
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Set;
import java.util.TimeZone;
import java.util.UUID;
 
import javax.jws.WebService;
 
import org.quartz.JobBuilder;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleTrigger;
import org.quartz.Trigger;
import org.quartz.TriggerKey;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.impl.matchers.GroupMatcher;
import static org.quartz.TriggerBuilder.*;
import net.brutex.xservices.types.ScheduledJob;
import net.brutex.xservices.types.SchedulerStatisticsType;
import net.brutex.xservices.util.BrutexNamespaces;
import net.brutex.xservices.util.JobWrapper;
import net.brutex.xservices.ws.JobService;
import net.brutex.xservices.ws.XServicesFault;
 
/**
* @author Brian Rosenberger
* @since 0.5.0
*
*/
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.JobService", serviceName = JobService.SERVICE_NAME)
public class JobServiceImpl implements JobService {
 
public List<ScheduledJob> getJobList() throws XServicesFault {
List<ScheduledJob> joblist = new ArrayList<ScheduledJob>();
try {
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
List<String> jobgroups = scheduler.getJobGroupNames();
for (String g : jobgroups) {
GroupMatcher m = GroupMatcher.groupContains(g);
Set<JobKey> keyset = scheduler.getJobKeys(m);
for (JobKey key : keyset) {
JobDataMap detail = scheduler.getJobDetail(key)
.getJobDataMap();
ScheduledJob job = new ScheduledJob(key.getName(),
(GregorianCalendar) detail.get("date"),
detail.getString("script"));
joblist.add(job);
}
 
}
 
} catch (SchedulerException e) {
throw new XServicesFault(e);
}
return joblist;
}
 
public ScheduledJob getJob(String uuid) throws XServicesFault {
try {
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
JobDetail job = scheduler.getJobDetail(new JobKey(uuid, "DEFAULT"));
if (job == null)
throw new XServicesFault("Job not found.");
Trigger t = scheduler.getTrigger(new TriggerKey(uuid));
GregorianCalendar cal = new GregorianCalendar(TimeZone.getDefault());
cal.setTime(t.getStartTime());
return new ScheduledJob(uuid, cal, job.getJobDataMap().getString(
"script"), job.getDescription());
} catch (SchedulerException e) {
e.printStackTrace();
throw new XServicesFault(e);
}
}
 
public void deleteJob(String uuid) throws XServicesFault {
try {
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
JobKey key = new JobKey(uuid, "DEFAULT");
JobDetail job = scheduler.getJobDetail(key);
if (job == null)
throw new XServicesFault("Job not found.");
Trigger t = scheduler.getTrigger(new TriggerKey(uuid));
scheduler.deleteJob(key);
} catch (SchedulerException e) {
throw new XServicesFault(e);
}
 
}
 
public String scheduleJob(ScheduledJob job) throws XServicesFault {
try {
// Grab the Scheduler instance from the Factory
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
 
// and start it off
 
if (!scheduler.isStarted())
scheduler.start();
if (scheduler.isInStandbyMode())
scheduler.resumeAll();
 
String identity = UUID.randomUUID().toString();
//String identity = "test";
JobDetail job2 = JobBuilder.newJob(JobWrapper.class)
.withIdentity(identity).build();
 
job2.getJobDataMap().put("script", job.getScript());
job2.getJobDataMap().put("description", job.getDescription());
job2.getJobDataMap().put("date", job.getDate());
 
SimpleTrigger t = (SimpleTrigger) newTrigger()
.withIdentity(identity).startAt(job.getDate().getTime())
.build();
;
 
scheduler.scheduleJob(job2, t);
return identity;
} catch (SchedulerException e) {
e.printStackTrace();
throw new XServicesFault(e);
}
}
 
 
public SchedulerStatisticsType getStatistics() throws XServicesFault {
try {
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
return new SchedulerStatisticsType(scheduler);
} catch (SchedulerException e) {
throw new XServicesFault(e);
}
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/ws/impl/MiscServiceImpl.java
0,0 → 1,163
/*
* Copyright 2010 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.ws.impl;
 
import java.util.Enumeration;
import java.util.Properties;
import java.util.UUID;
 
import javax.jws.WebService;
import net.brutex.xservices.types.HostConnection;
import net.brutex.xservices.types.HostinfoType;
import net.brutex.xservices.types.MailMimeType;
import net.brutex.xservices.types.ReturnCode;
import net.brutex.xservices.types.RuntimeInfoType;
import net.brutex.xservices.types.ant.FileSetResource;
import net.brutex.xservices.util.BrutexNamespaces;
import net.brutex.xservices.util.RunTask;
import net.brutex.xservices.ws.MiscService;
 
import org.apache.cxf.annotations.WSDLDocumentation;
import org.apache.cxf.annotations.WSDLDocumentationCollection;
import org.apache.tools.ant.taskdefs.HostInfo;
import org.apache.tools.ant.taskdefs.Sleep;
import org.apache.tools.ant.taskdefs.email.EmailTask;
 
/**
* Implements the web service
*
* @author Brian Rosenberger, bru@brutex.de
*/
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES,
endpointInterface = "net.brutex.xservices.ws.MiscService",
serviceName = "MiscService")
public class MiscServiceImpl implements MiscService {
 
public HostinfoType getHostinfo(String hostname) {
HostInfo info = new HostInfo();
info.setTaskName("HostInfo");
RunTask runner = new RunTask(info);
info.setHost(hostname);
// info.setPrefix(prefix);
// TODO: Does not work for IP Addresses?
ReturnCode ret = runner.postTask();
HostinfoType infotype = new HostinfoType(
ret.getProperty("NAME"),
ret.getProperty("DOMAIN"),
ret.getProperty("ADDR4"),
ret.getProperty("ADDR6"));
return infotype;
}
 
public ReturnCode getInfo() {
ReturnCode r = new ReturnCode();
r.returnCode = 0;
// Get all system properties
Properties props = System.getProperties();
 
// Enumerate all system properties
@SuppressWarnings("unchecked")
Enumeration<String> e = (Enumeration<String>) 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) {
return sendMail(from, from, tolist, "", "", subject, message,
"text/plain", null, mailhost.hostname, mailhost.port,
mailhost.user, mailhost.password, "utf-8", false, false);
}
 
public ReturnCode sendMailSimpleWithAttachment(HostConnection mailhost,
String from, String tolist, String subject, String message,
FileSetResource res) {
return sendMail(from, from, tolist, "", "", subject, message,
"text/plain", res, mailhost.hostname, mailhost.port,
mailhost.user, mailhost.password, "utf-8", false, false);
}
 
public ReturnCode sendMail(HostConnection mailhost, String from,
String tolist, String cclist, String bcclist, String subject,
MailMimeType mimetype, String charset, String message,
FileSetResource res, boolean ssl, boolean tls) {
return sendMail(from, from, tolist, cclist, bcclist, subject, message,
mimetype.value(), res, mailhost.hostname, mailhost.port,
mailhost.user, mailhost.password, charset, tls, ssl);
}
 
public ReturnCode sleep(int minutes, int seconds) {
return sleep(0, minutes, seconds, 0);
}
 
public String generateUUID() {
return UUID.randomUUID().toString();
}
 
private ReturnCode sendMail(String from, String replyto, String tolist,
String cclist, String bcclist, String subject, String message,
String messagemimetype, FileSetResource attachments,
String mailhost, int mailport, String user, String password,
String charset, boolean tls, boolean ssl) {
EmailTask mail = new EmailTask();
mail.setTaskName("Mail");
RunTask runner = new RunTask(mail);
mail.setFrom(from);
mail.setReplyTo(replyto);
mail.setToList(tolist);
mail.setCcList(cclist);
mail.setBccList(bcclist);
mail.setSubject(subject);
mail.setMessage(message);
mail.setMessageMimeType(messagemimetype);
if (attachments != null) {
mail.addFileset(attachments.getAntResource(mail.getProject()));
}
mail.setMailhost(mailhost);
mail.setMailport(mailport);
mail.setUser(user);
mail.setPassword(password);
mail.setCharset(charset);
mail.setSSL(ssl);
mail.setEnableStartTLS(tls);
return runner.postTask();
}
 
private ReturnCode sleep(int hours, int minutes, int seconds,
int milliseconds) {
Sleep sleep = new Sleep();
sleep.setTaskName("Sleep");
RunTask runner = new RunTask(sleep);
sleep.setHours(hours);
sleep.setMinutes(minutes);
sleep.setSeconds(seconds);
sleep.setMilliseconds(milliseconds);
return runner.postTask();
}
 
public RuntimeInfoType getMemory() {
return new RuntimeInfoType();
}
}
/xservices/trunk/src/java/net/brutex/xservices/ws/impl/MailServiceImpl.java
0,0 → 1,94
/*
* Copyright 2012 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.ws.impl;
 
import javax.jws.WebService;
 
import net.brutex.xservices.types.HostConnection;
import net.brutex.xservices.types.MailMimeType;
import net.brutex.xservices.types.ReturnCode;
import net.brutex.xservices.types.ant.FileSetResource;
import net.brutex.xservices.util.BrutexNamespaces;
import net.brutex.xservices.util.RunTask;
import net.brutex.xservices.ws.MailService;
 
import org.apache.tools.ant.taskdefs.email.EmailTask;
 
/**
* Implements MailService
*
* @author Brian Rosenberger, bru@brutex.de
*/
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES,
endpointInterface = "net.brutex.xservices.ws.MailService",
serviceName = "MailService")
public class MailServiceImpl implements MailService {
 
 
public ReturnCode sendMailSimple(HostConnection mailhost, String from,
String tolist, String subject, String message) {
return sendMail(from, from, tolist, "", "", subject, message,
"text/plain", null, mailhost.hostname, mailhost.port,
mailhost.user, mailhost.password, "utf-8", false, false);
}
 
public ReturnCode sendMailSimpleWithAttachment(HostConnection mailhost,
String from, String tolist, String subject, String message,
FileSetResource res) {
return sendMail(from, from, tolist, "", "", subject, message,
"text/plain", res, mailhost.hostname, mailhost.port,
mailhost.user, mailhost.password, "utf-8", false, false);
}
 
public ReturnCode sendMail(HostConnection mailhost, String from,
String tolist, String cclist, String bcclist, String subject,
MailMimeType mimetype, String charset, String message,
FileSetResource res, boolean ssl, boolean tls) {
return sendMail(from, from, tolist, cclist, bcclist, subject, message,
mimetype.value(), res, mailhost.hostname, mailhost.port,
mailhost.user, mailhost.password, charset, tls, ssl);
}
 
private ReturnCode sendMail(String from, String replyto, String tolist,
String cclist, String bcclist, String subject, String message,
String messagemimetype, FileSetResource attachments,
String mailhost, int mailport, String user, String password,
String charset, boolean tls, boolean ssl) {
EmailTask mail = new EmailTask();
mail.setTaskName("Mail");
RunTask runner = new RunTask(mail);
mail.setFrom(from);
mail.setReplyTo(replyto);
mail.setToList(tolist);
mail.setCcList(cclist);
mail.setBccList(bcclist);
mail.setSubject(subject);
mail.setMessage(message);
mail.setMessageMimeType(messagemimetype);
if (attachments != null) {
mail.addFileset(attachments.getAntResource(mail.getProject()));
}
mail.setMailhost(mailhost);
mail.setMailport(mailport);
mail.setUser(user);
mail.setPassword(password);
mail.setCharset(charset);
mail.setSSL(ssl);
mail.setEnableStartTLS(tls);
return runner.postTask();
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/ws/impl/DateServiceImpl.java
0,0 → 1,202
/*
* 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.ws.impl;
 
import java.math.BigInteger;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.TimeZone;
 
import javax.jws.WebService;
import net.brutex.xservices.types.DateFormatType;
import net.brutex.xservices.types.DateInfoExtendedType;
import net.brutex.xservices.types.DateInfoType;
import net.brutex.xservices.types.DateTimeUnits;
import net.brutex.xservices.types.TimeZoneType;
import net.brutex.xservices.util.BrutexNamespaces;
import net.brutex.xservices.ws.DateService;
import net.brutex.xservices.ws.XServicesFault;
 
/**
* @author Brian Rosenberger
*
*/
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.DateService", serviceName = DateService.SERVICE_NAME)
public class DateServiceImpl implements DateService {
 
private static String ERR_INVALIDFORMAT = "Invalid format pattern.";
private static String ERR_INVALIDTIMEZONE = "Invalid timezone.";
 
public DateInfoType getDate() throws XServicesFault {
GregorianCalendar c = new GregorianCalendar();
DateInfoType dateinfo = new DateInfoType(c, TimeZone.getDefault());
return dateinfo;
}
 
public DateInfoExtendedType getDateExtended() throws XServicesFault {
GregorianCalendar c = new GregorianCalendar();
DateInfoExtendedType dateinfo = new DateInfoExtendedType(c,
TimeZone.getDefault());
return dateinfo;
}
 
public BigInteger getTimestamp() {
Date d = new Date();
long l = d.getTime();
return new BigInteger(Long.toString(l));
}
 
public BigInteger getTimestamp2() {
Date d = new Date();
long l = d.getTime() / 1000;
return new BigInteger(Long.toString(l));
}
 
public String getInTimezone(Date date, String timezone)
throws XServicesFault {
if (!isValidTimezone(timezone))
throw new XServicesFault(ERR_INVALIDTIMEZONE);
TimeZone targetzone = TimeZone.getTimeZone(timezone);
String targetstring = DateFormatType.ISO8601.format(date, null, targetzone);
return targetstring;
}
 
public String formatDate(Date cal, DateFormatType format)
throws XServicesFault {
return format.format(cal, null, null);
}
 
public String formatDateAdvanced(Date cal, String format)
throws XServicesFault {
String result = null;
SimpleDateFormat f = new SimpleDateFormat(format);
result = f.format(cal);
return result;
}
 
public Date parseDate(String s, DateFormatType format, String timezone)
throws XServicesFault {
if (timezone == null | timezone.equals(""))
timezone = TimeZone.getDefault().getID();
if (!isValidTimezone(timezone))
throw new XServicesFault(ERR_INVALIDTIMEZONE);
try {
return format.parse(s, null, TimeZone.getTimeZone(timezone));
} catch (ParseException e) {
throw new XServicesFault(e);
}
}
 
public GregorianCalendar parseDateAdvanced(String s, String format,
String timezone) throws XServicesFault {
SimpleDateFormat f = null;
Date date = null;
if (timezone == null | timezone.equals(""))
timezone = TimeZone.getDefault().getID();
if (!isValidTimezone(timezone))
throw new XServicesFault(ERR_INVALIDTIMEZONE);
 
try {
f = new SimpleDateFormat(format);
date = f.parse(s);
} catch (IllegalArgumentException e) {
throw new XServicesFault(ERR_INVALIDFORMAT + e.getMessage());
} catch (ParseException e) {
throw new XServicesFault("Cannot parse date: " + e.getMessage());
}
GregorianCalendar cal = new GregorianCalendar();
cal.setTimeZone(TimeZone.getTimeZone(timezone));
cal.setTime(date);
return cal;
}
 
public BigInteger dateTimeDiff(Date fromCal, Date toCal)
throws XServicesFault {
long diff = toCal.getTime() - fromCal.getTime();
BigInteger d = new BigInteger(String.valueOf(diff), 10);
return d;
}
 
public BigInteger dateTimeDiff2(Date fromCal, Date toCal, DateTimeUnits unit)
throws XServicesFault {
BigInteger d = dateTimeDiff(fromCal, toCal);
switch (unit) {
case SECONDS:
d = d.divide(new BigInteger("1000"));
break;
case MINUTES:
d = d.divide(new BigInteger("60000"));
break;
case HOURS:
d = d.divide(new BigInteger("3600000"));
break;
case DAYS:
d = d.divide(new BigInteger("86400000"));
break;
case YEARS:
d = d.divide(new BigInteger("31536000000"));
break;
}
return d;
}
 
public GregorianCalendar dateAdd(GregorianCalendar cal, BigInteger value,
DateTimeUnits unit) throws XServicesFault {
switch (unit) {
case SECONDS:
cal.add(GregorianCalendar.SECOND, value.intValue());
break;
case MINUTES:
cal.add(GregorianCalendar.MINUTE, value.intValue());
break;
case HOURS:
cal.add(GregorianCalendar.HOUR_OF_DAY, value.intValue());
break;
case DAYS:
cal.add(GregorianCalendar.DAY_OF_MONTH, value.intValue());
break;
case YEARS:
cal.add(GregorianCalendar.YEAR, value.intValue());
break;
default:
cal.add(GregorianCalendar.MILLISECOND, value.intValue());
}
return cal;
}
 
private boolean isValidTimezone(String id) {
boolean yes = false;
for (String s : TimeZone.getAvailableIDs()) {
if (s.equals(id)) {
yes = true;
break;
}
}
return yes;
}
 
public List<TimeZoneType> getTimezones() {
List<TimeZoneType> output = new ArrayList<TimeZoneType>();
for (String s : TimeZone.getAvailableIDs()) {
output.add(new TimeZoneType(TimeZone.getTimeZone(s)));
}
return output;
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/ws/impl/ExecuteServiceImpl.java
0,0 → 1,354
/*
* Copyright 2010 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.ws.impl;
 
import java.io.File;
import java.util.UUID;
 
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import net.brutex.xservices.types.HostConnection;
import net.brutex.xservices.types.ReturnCode;
import net.brutex.xservices.util.BrutexNamespaces;
import net.brutex.xservices.util.JobWrapper;
import net.brutex.xservices.util.RunTask;
import net.brutex.xservices.ws.ExecuteService;
import net.brutex.xservices.ws.XServicesFault;
 
import org.apache.tools.ant.taskdefs.ExecTask;
import org.apache.tools.ant.taskdefs.optional.net.RExecTask;
import org.apache.tools.ant.taskdefs.optional.net.TelnetTask;
import org.apache.tools.ant.taskdefs.optional.ssh.SSHExec;
import org.apache.tools.ant.types.Commandline;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import static org.quartz.TriggerBuilder.*;
import static org.quartz.SimpleScheduleBuilder.*;
import org.quartz.TriggerUtils;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.impl.triggers.SimpleTriggerImpl;
 
/**
*
* @author Brian Rosenberger, bru@brutex.de
*/
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.ExecuteService", serviceName = "ExecuteService")
public class ExecuteServiceImpl implements ExecuteService {
 
/*
* (non-Javadoc)
*
* @see
* net.brutex.xservices.ws.impl.ExecuteService#runCommand(java.lang.String,
* java.lang.String, long)
*/
@WebMethod(operationName = "runCommand")
public ReturnCode runCommand(@WebParam(name = "executable") String cmd,
@WebParam(name = "argline") String args,
@WebParam(name = "timeout") long timeout) {
 
return executeCommand(cmd, Commandline.translateCommandline(args),
null, false, null, false, true, false, timeout);
}
 
/*
* (non-Javadoc)
*
* @see
* net.brutex.xservices.ws.impl.ExecuteService#runCommandWithArgs(java.lang
* .String, java.lang.String[], long)
*/
@WebMethod(operationName = "runCommandWithArgs")
public ReturnCode runCommandWithArgs(
@WebParam(name = "executable") String cmd,
@WebParam(name = "arg") String[] args,
@WebParam(name = "timeout") long timeout) {
 
return executeCommand(cmd, args, null, false, null, false, true, false,
timeout);
}
 
/*
* (non-Javadoc)
*
* @see
* net.brutex.xservices.ws.impl.ExecuteService#runCommandAsync(java.lang
* .String, java.lang.String)
*/
@WebMethod(operationName = "runCommandAsync")
public ReturnCode runCommandAsync(
@WebParam(name = "executable") String cmd,
@WebParam(name = "argline") String args) {
 
return executeCommand(cmd, Commandline.translateCommandline(args),
null, true, null, false, true, false, 0);
}
 
/*
* (non-Javadoc)
*
* @see
* net.brutex.xservices.ws.impl.ExecuteService#runCommandAsyncWithArgs(java
* .lang.String, java.lang.String[])
*/
@WebMethod(operationName = "runCommandAsyncWithArgs")
public ReturnCode runCommandAsyncWithArgs(
@WebParam(name = "executable") String cmd,
@WebParam(name = "arg") String[] args) {
 
return executeCommand(cmd, args, null, true, null, false, true, false,
0);
}
 
/*
* (non-Javadoc)
*
* @see
* net.brutex.xservices.ws.impl.ExecuteService#runCommandWithSSH(java.lang
* .String, int, java.lang.String, java.lang.String, java.lang.String, long)
*/
@WebMethod(operationName = "runCommandWithSSH")
public ReturnCode runCommandWithSSH(
@WebParam(name = "host") HostConnection host,
@WebParam(name = "command") String cmd,
@WebParam(name = "timeout") long timeout) {
 
return sshExec(host.hostname, host.user, host.password, host.port, cmd,
timeout);
}
 
/*
* (non-Javadoc)
*
* @see
* net.brutex.xservices.ws.impl.ExecuteService#runCommandWithSSHKeyAuth(
* java.lang.String, int, java.lang.String, java.lang.String,
* java.lang.String, java.lang.String, long)
*/
@WebMethod(operationName = "runCommandWithSSHKeyAuth")
public ReturnCode runCommandWithSSHKeyAuth(
@WebParam(name = "host") HostConnection host,
@WebParam(name = "keyfile") String keyfile,
@WebParam(name = "command") String cmd,
@WebParam(name = "timeout") long timeout) {
 
return sshExecWithCert(host.hostname, host.user, host.password,
keyfile, host.port, cmd, timeout);
}
 
/*
* (non-Javadoc)
*
* @see
* net.brutex.xservices.ws.impl.ExecuteService#rExec(net.brutex.xservices
* .types.HostConnection, java.lang.String, long)
*/
@WebMethod(operationName = "rExec")
public ReturnCode rExec(@WebParam(name = "host") HostConnection host,
@WebParam(name = "command") String cmd,
@WebParam(name = "timeout") long timeout) {
return rexec(host.hostname, host.port, host.user, host.password, cmd,
timeout);
}
 
/*
* (non-Javadoc)
*
* @see
* net.brutex.xservices.ws.impl.ExecuteService#runTelnet(net.brutex.xservices
* .types.HostConnection, java.lang.String, java.lang.String,
* java.lang.String, long)
*/
@WebMethod(operationName = "telnet")
public ReturnCode runTelnet(@WebParam(name = "host") HostConnection host,
@WebParam(name = "prompt") String prompt,
@WebParam(name = "command") String cmd,
@WebParam(name = "expect") String expect,
@WebParam(name = "timeout") long timeout) {
return telnet(host.hostname, host.port, host.user, host.password, cmd,
timeout, prompt, expect);
}
 
public void runJScript(String script) throws XServicesFault {
 
try {
// Create and enter a Context. A Context stores information about
// the execution environment of a script.
Context cx = Context.enter();
cx.setOptimizationLevel(0);
cx.setLanguageVersion(Context.VERSION_1_7);
// cx is the Context instance you're using to run scripts
/*
* cx.setClassShutter(new ClassShutter() { public boolean
* visibleToScripts(String className) {
* if(className.startsWith("adapter")) return true;
* if(className.startsWith("java.lang.System") ||
* className.startsWith
* ("org.apache.tomcat.util.log.SystemLogHandler")) return true;
* System.out.println(className + " is blocked."); return false; }
* });
*/
 
// Initialise the standard objects (Object, Function, etc.). This
// must be done before scripts can be
// executed. The null parameter tells initStandardObjects
// to create and return a scope object that we use
// in later calls.
Scriptable scope = cx.initStandardObjects();
// Object wrappedOut = Context.javaToJS(System.out, scope);
// Object wrappedOut2 = Context.javaToJS(this, scope);
// scope.put("out", scope, wrappedOut);
// scope.put("exe", scope, wrappedOut2);
 
// Execute the script
// cx.evaluateString(scope, "importClass('java.lang.System');\n",
// "head", 1, null);
// cx.evaluateString(scope, "importPackage('java.util');\n", "head",
// 2, null);
Object obj = cx
.evaluateString(scope, script, "TestScript", 1, null);
 
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
// Exit the Context. This removes the association between the
// Context and the current thread and is an
// essential cleanup action. There should be a call to exit for
// every call to enter.
Context.exit();
}
 
}
 
@WebMethod(exclude = true)
private ReturnCode executeCommand(String executable, String[] args,
File dir, boolean spawn, String inputstring,
boolean newenvironment, boolean vmlauncher, boolean searchpath,
long timeout) {
ExecTask exe = new ExecTask();
RunTask runner = new RunTask(exe);
 
/*
* Commandline cmdl = new Commandline(); cmdl.setExecutable(executable);
* cmdl.addArguments(args); System.out.println(cmdl.describeCommand());
*/
 
exe.setExecutable(executable);
for (String s : args) {
exe.createArg().setValue(s);
}
 
exe.setDir(dir);
if (spawn) {
exe.setSpawn(spawn);
} else {
exe.setTimeout(timeout);
exe.setInputString(inputstring);
exe.setOutputproperty("ExecuteService.stdout");
exe.setErrorProperty("ExecuteService.stderr");
exe.setResultProperty("ExecuteService.result");
}
 
exe.setNewenvironment(newenvironment);
exe.setVMLauncher(vmlauncher);
exe.setSearchPath(searchpath);
 
return runner.postTask();
}
 
@WebMethod(exclude = true)
private ReturnCode sshExec(String host, String username, String password,
int port, String command, long timeout) {
SSHExec sshexec = new SSHExec();
RunTask runner = new RunTask(sshexec);
sshexec.setHost(host);
sshexec.setUsername(username);
sshexec.setPassword(password);
sshexec.setPort(port);
sshexec.setCommand(command);
sshexec.setTrust(true);
sshexec.setTimeout(timeout);
sshexec.setOutputproperty("SSHExec.stdout");
return runner.postTask();
}
 
@WebMethod(exclude = true)
private ReturnCode sshExecWithCert(String host, String username,
String passphrase, String keyfile, int port, String command,
long timeout) {
SSHExec sshexec = new SSHExec();
RunTask runner = new RunTask(sshexec);
sshexec.setHost(host);
sshexec.setUsername(username);
sshexec.setKeyfile(keyfile);
sshexec.setPassphrase(passphrase);
sshexec.setPort(port);
sshexec.setCommand(command);
sshexec.setTrust(true);
sshexec.setTimeout(timeout);
sshexec.setOutputproperty("SSHExec.stdout");
return runner.postTask();
}
 
@WebMethod(exclude = true)
private ReturnCode rexec(String host, int port, String username,
String password, String command, long timeout) {
RExecTask rexec = new RExecTask();
RunTask runner = new RunTask(rexec);
rexec.setServer(host);
rexec.setPort(port);
rexec.setUserid(username);
rexec.setPassword(password);
rexec.setCommand(command);
rexec.setTimeout((int) Math.round(timeout));
 
return runner.postTask();
}
 
@WebMethod(exclude = true)
private ReturnCode telnet(String host, int port, String username,
String password, String command, long timeout, String prompt,
String expect) {
TelnetTask rexec = new TelnetTask();
RunTask runner = new RunTask(rexec);
rexec.setServer(host);
rexec.setPort(port);
rexec.setUserid(username);
rexec.setPassword(password);
rexec.setTimeout((int) Math.round(timeout));
 
rexec.createRead().addText(prompt);
rexec.createWrite().addText(command);
rexec.createRead().addText(expect);
 
return runner.postTask();
}
}
/xservices/trunk/src/java/net/brutex/xservices/ws/rs/CVSInfo.java
0,0 → 1,69
/*
* Copyright 2012 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.ws.rs;
 
import java.io.File;
import java.util.List;
 
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
 
import net.brutex.xservices.types.FileInfoType;
 
 
 
@Path("/CVSService/")
@Produces ({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public interface CVSInfo {
 
/**
* @param module
* @param withDir
* @param withFiles
* @param depth
* @param search
* @param count
* @param page
* @return List of File
*/
@GET
@Path("getRepositoryFiles/")
public Response getRepositoryFiles(@Context HttpHeaders h,
@QueryParam("config") File f,
@QueryParam("modules") @DefaultValue("") String modules,
@QueryParam("showRevisions") @DefaultValue("false") boolean showRevisions,
@QueryParam("forceNoCache") @DefaultValue("false") boolean forceNoCache
);
 
@GET
@Path("getModules")
public Response getModules(@Context HttpHeaders h,
@QueryParam("config") File f,
@QueryParam("forceNoCache") @DefaultValue("false") boolean forceNoCache);
 
}
 
 
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/ws/rs/CVSInfoImpl.java
0,0 → 1,225
package net.brutex.xservices.ws.rs;
 
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
 
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
 
import org.apache.commons.configuration.ConfigurationException;
import org.apache.jcs.JCS;
import org.apache.jcs.access.exception.CacheException;
import org.apache.log4j.Logger;
import org.netbeans.lib.cvsclient.Client;
import org.netbeans.lib.cvsclient.command.CommandAbortedException;
import org.netbeans.lib.cvsclient.command.CommandException;
import org.netbeans.lib.cvsclient.command.checkout.CheckoutCommand;
import org.netbeans.lib.cvsclient.command.checkout.ModuleListInformation;
import org.netbeans.lib.cvsclient.command.log.LogInformation;
import org.netbeans.lib.cvsclient.command.log.RlogCommand;
import org.netbeans.lib.cvsclient.connection.AuthenticationException;
import org.netbeans.lib.cvsclient.event.FileInfoEvent;
 
import net.brutex.xservices.types.scm.ModuleType;
import net.brutex.xservices.types.scm.FileType;
import net.brutex.xservices.types.scm.Revision;
import net.brutex.xservices.util.BasicCVSListener;
import net.brutex.xservices.util.CVSClient;
 
/**
* @author Brian Rosenberger
* @since 0.5.0-20120824
*
*/
public class CVSInfoImpl implements CVSInfo {
final Logger logger = Logger.getLogger(CVSInfoImpl.class);
 
public Response getRepositoryFiles(HttpHeaders h, File f, String modules,
boolean showRevisions,
boolean forceNoCache) {
 
final List<FileType> list = new ArrayList<FileType>();
 
String cachekey = "getFiles" + f.toURI().toString();
logger.debug("forceNoCache="+forceNoCache);
List<FileType> cacheresult = (List<FileType>) getCacheInstance().get(
cachekey);
 
if (!forceNoCache && cacheresult != null) {
// Cache hit
list.addAll(cacheresult);
} else {
// Cache miss
try {
CVSClient cvsclient = new CVSClient(f);
Client client = cvsclient.client;
 
client.getEventManager().addCVSListener(new BasicCVSListener() {
@Override
public void fileInfoGenerated(FileInfoEvent arg0) {
LogInformation info = (LogInformation) arg0
.getInfoContainer();
FileType cvsfile = new FileType(info.getFile(), info
.getRepositoryFilename(), info.getDescription());
cvsfile.setHeadRevision(info.getHeadRevision());
cvsfile.setBranch(info.getBranch());
cvsfile.setTotalRevisions(info.getTotalRevisions());
for (LogInformation.Revision r : info.getRevisionList()) {
cvsfile.addRevision(new Revision(r.getNumber(), r
.getMessage()));
}
list.add(cvsfile);
}
});
 
RlogCommand rlog = new RlogCommand();
StringTokenizer tk = new StringTokenizer(modules, ",");
while (tk.hasMoreTokens()) {
rlog.setModule(tk.nextToken());
}
if (rlog.getModules().length == 0)
rlog.setModule("");
 
rlog.setDefaultBranch(true); // -b Print information about the
// revisions on the default
// branch,
// normally the highest branch
// on
// the trunk.
rlog.setNoTags(true); // -N Do not print the list of tags for
// this
// file. This option can be very useful
// when
// your site uses a lot of tags, so
// rather
// than "more"'ing over 3 pages of tag
// information, the log information is
// presented without tags at all.
rlog.setHeaderAndDescOnly(false); // -t Print only the name of
// the
// rcs file, name of the
// file in
// the working directory,
// head,
// default branch, access
// list,
// locks, symbolic names,
// and
// suffix. + description
// rlog.setRevisionFilter("1.1.");
// rlog.setSuppressHeader(true); // -S Supress log output when
// no
// revisions are selected within a file.
client.executeCommand(rlog, cvsclient.getGlobalOptions());
logger.info("Execute CVS command '" + rlog.getCVSCommand() + "' against '"+cvsclient.getRoot().host+"@" + cvsclient.getRoot().repository+"'");
//need to put a new list into cache as we will filter the result
//afterwards
getCacheInstance().put(cachekey, new ArrayList<FileType>(list));
} catch (ConfigurationException e) {
logger.error("CVS Configuration File '"
+ f.getAbsolutePath() + f.getName() + "'not found.", e);
} catch (CommandAbortedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AuthenticationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CommandException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CacheException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 
}
// prepare output after everything is cached
if (!showRevisions) {
for (FileType t : list) {
t.clearRevisionList();
}
}
GenericEntity entity = new GenericEntity<List<FileType>>(list) {};
return Response.ok(entity).build();
}
 
@Override
public Response getModules(HttpHeaders h, File f, boolean forceNoCache) {
 
// Try to deliver from Cache
String cachekey = "Modules" + f.toURI().toString();
logger.debug("forceNoCache="+forceNoCache);
List<ModuleType> response = (List<ModuleType>) getCacheInstance().get(
cachekey);
if (!forceNoCache && response != null) {
GenericEntity entity = new GenericEntity<List<ModuleType>>(response) {
};
return Response.ok(entity).build();
}
// -------------------------
 
try {
CVSClient cvsclient = new CVSClient(f);
Client client = cvsclient.client;
 
final List<ModuleType> list = new ArrayList<ModuleType>();
 
client.getEventManager().addCVSListener(new BasicCVSListener() {
public void fileInfoGenerated(FileInfoEvent e) {
ModuleListInformation info = (ModuleListInformation) e
.getInfoContainer();
 
list.add(new ModuleType(info.getModuleName(), info
.getModuleStatus(), info.getPaths(), info.getType()));
}
});
 
CheckoutCommand co = new CheckoutCommand();
co.setShowModulesWithStatus(true);
 
client.executeCommand(co, cvsclient.getGlobalOptions());
logger.info("Execute CVS command '" + co.getCVSCommand() + "' against '"+cvsclient.getRoot().host+"@" + cvsclient.getRoot().repository+"'");
if(list.size()==0) {
logger.warn("Repository '" + cvsclient.getRoot().repository + "' does not have modules");
list.add(new ModuleType("","","",""));
}
GenericEntity entity = new GenericEntity<List<ModuleType>>(list) {
};
getCacheInstance().put(cachekey, list);
return Response.ok(entity).build();
} catch (Exception e) {
e.printStackTrace();
}
return Response.serverError().build();
}
 
/**
* Get the caching manager for CVS objects
*
* @return The CVSCaching JCS region
*/
public JCS getCacheInstance() {
JCS jcs = null;
final String cacheinstance = "CVSCache";
try {
logger.debug("Getting cache instance named '"+cacheinstance+"'" );
jcs = JCS.getInstance(cacheinstance);
} catch (CacheException e) {
logger.error("Failed to get cache instance", e);
e.printStackTrace();
}
return jcs;
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/ws/rs/FileInfoImpl.java
0,0 → 1,104
package net.brutex.xservices.ws.rs;
 
import java.io.File;
import java.io.FileFilter;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
 
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
 
import org.apache.jcs.JCS;
import org.apache.jcs.access.exception.CacheException;
 
import net.brutex.xservices.security.StandardSecurityManager;
import net.brutex.xservices.security.UserIdentity;
import net.brutex.xservices.types.FileInfoType;
 
/**
* @author Brian Rosenberger
*
*/
public class FileInfoImpl implements FileInfo {
 
public Response getFiles(HttpHeaders h, String dir, boolean withDir,
boolean withFiles, int level, String search, int count, int page) {
StandardSecurityManager sec = new StandardSecurityManager();
UserIdentity id = new UserIdentity();
 
if( ! sec.canExecute(Thread.currentThread().getStackTrace()[1].getMethodName(), id)) {
return null;
}
 
System.out.println("Listing directory: " + dir);
if(level <= 0) level = 1;
if(level > 3) level = 3;
if(!withDir && !withFiles) withFiles = true;
String cachekey = level +"||"+ withFiles +"||"+ withDir +"||" + search + "||" + dir;
try {
JCS jcs = JCS.getInstance("FileCache");
List<FileInfoType> list = (List<FileInfoType>) jcs.get(cachekey);
if(list == null) {
list = setDirectory(dir, withDir, withFiles, level, search);
jcs.put(cachekey, list);
System.out.println("Stored in Cache: " + list.toString());
} else {
System.out.println("Got from Cache: " + list.toString());
}
 
int fromIndex = 0;
int toIndex = 0;
fromIndex = (page-1) * count;
toIndex = (page*count);
if(toIndex>list.size()) toIndex = list.size();
if(fromIndex>toIndex) fromIndex=toIndex;
GenericEntity<List<FileInfoType>> sublist = new GenericEntity<List<FileInfoType>>(list.subList(fromIndex, toIndex) ){};
return Response.ok( sublist ).build();
} catch (CacheException e) {
Response.serverError().build();
}
return null;
}
 
 
private void setDirectory(List<FileInfoType> list, File dir, final boolean withDirectories, final boolean withFiles, final int depth, final String search) {
if(depth <=0) return;
File[] files = dir.listFiles(new FileFilter() {
public boolean accept(File pathname) {
if(pathname.isDirectory() && depth > 1) return true;
if(search == null || search.equals("")) return true;
if(!pathname.getAbsolutePath().contains(search)) return false;
return true;
}
});
if(dir.getParentFile() != null && withDirectories==true) list.add(new FileInfoType(dir.getParentFile()));
if(files==null) return;
for( File e : files) {
if(e.isDirectory()) setDirectory(list, e, withDirectories, withFiles, depth-1, search);
if( (withDirectories && e.isDirectory())
|| (withFiles && e.isFile()) ) {
list.add(new FileInfoType(e));
}
}
}
private List<FileInfoType> setDirectory(String dir, final boolean withDirectories, final boolean withFiles, int depth, String search) {
List<FileInfoType> list = new ArrayList<FileInfoType>();
setDirectory( list, (new File(dir)), withDirectories, withFiles, depth, search);
return list;
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/ws/rs/FileInfo.java
0,0 → 1,63
/*
* Copyright 2012 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.ws.rs;
 
import java.util.List;
 
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
 
import net.brutex.xservices.types.FileInfoType;
 
 
 
@Path("/FileService/")
@Produces ("application/xml")
public interface FileInfo {
 
/**
* @param dir
* @param withDir
* @param withFiles
* @param depth
* @param search
* @param count
* @param page
* @return List of File
*/
@GET
@Path("getFiles/")
public Response getFiles(@Context HttpHeaders h,
@QueryParam("directory") String dir,
@QueryParam("includeDirectories") @DefaultValue("0") boolean withDir,
@QueryParam("includeFiles") @DefaultValue("1") boolean withFiles,
@QueryParam("depth") @DefaultValue("1") int depth,
@QueryParam("search") String search,
@QueryParam("itemsPerPage") @DefaultValue("50") int count,
@QueryParam("page") @DefaultValue("1") int page);
 
}
 
 
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/ws/rs/FileListType.java
0,0 → 1,18
package net.brutex.xservices.ws.rs;
 
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
 
@XmlRootElement(name="FileList")
public class FileListType {
 
@XmlElement
public String name;
public FileListType(){};
public FileListType(String name) {
this.name = name;
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/ws/StringService.java
0,0 → 1,80
/*
* Copyright 2012 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.ws;
 
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
 
import net.brutex.xservices.types.ReturnCode;
import net.brutex.xservices.types.StringMatchType;
import net.brutex.xservices.types.StringReplaceType;
import net.brutex.xservices.types.TargetNodeType;
import net.brutex.xservices.types.ant.AttachmentType;
import net.brutex.xservices.types.ant.CollectionType;
import net.brutex.xservices.types.ant.FileResource;
import net.brutex.xservices.util.BrutexNamespaces;
 
import org.apache.cxf.annotations.WSDLDocumentation;
 
/**
* String operation services.
* @author Brian Rosenberger
* @since 0.5.0
*
*/
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES)
public interface StringService {
public static final String SERVICE_NAME = "StringService";
final String OPERATION_REPLACEREGEX = "replaceRegEx";
final String OPERATION_MATCHREGEX = "matchRegEx";
 
 
final static String PARAM_STRING = "string";
final static String PARAM_SEARCH = "search";
final static String PARAM_REPLACE = "replace";
final static String PARAM_FLAGS = "regexflags";
;
/**
* String replace using regular expression.
* @param res String
* @param search regex search pattern
* @param replace string replacement
* @param flags regex flags
*
* @return replacement
* @throws XServicesFault
*/
@WebMethod(operationName=OPERATION_REPLACEREGEX)
@WSDLDocumentation(value="Store text based data")
public abstract StringReplaceType replaceRegEx(
@WebParam(name = PARAM_STRING) String res,
@WebParam(name = PARAM_SEARCH) String search,
@WebParam(name = PARAM_REPLACE) String replace,
@WebParam(name = PARAM_FLAGS) String flags) throws XServicesFault;
@WebMethod(operationName=OPERATION_MATCHREGEX)
@WSDLDocumentation(value="Match text based data")
public abstract StringMatchType matchRegEx(
@WebParam(name = PARAM_STRING) String res,
@WebParam(name = PARAM_SEARCH) String search,
@WebParam(name = PARAM_FLAGS) String flags) throws XServicesFault;
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/ws/FileService.java
0,0 → 1,264
/*
* Copyright 2010 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.ws;
 
import java.util.List;
 
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlElement;
 
import org.apache.cxf.annotations.WSDLDocumentation;
import org.apache.cxf.annotations.WSDLDocumentationCollection;
 
import net.brutex.xservices.types.ReplacePattern;
import net.brutex.xservices.types.ReturnCode;
import net.brutex.xservices.types.ant.ArchiveResource;
import net.brutex.xservices.types.ant.AttachmentType;
import net.brutex.xservices.types.ant.FileResource;
import net.brutex.xservices.types.ant.FileSetResource;
import net.brutex.xservices.util.BrutexNamespaces;
import net.brutex.xservices.util.XServicesDocumentation;
/**
* File related web service operations.
*
* @author Brian Rosenberger
* @since 0.3.0
*
*/
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES)
@WSDLDocumentationCollection(
{
@WSDLDocumentation(value = BrutexNamespaces.BRUTEX_COPYRIGHT, placement = WSDLDocumentation.Placement.TOP)
}
)
public interface FileService {
 
final String OPERATION_BASENAME ="basename";
final String OPERATION_DOWNLOADFILE ="downloadFile";
final String OPERATION_ENCODEFILE= "encodeFile";
final String OPERATION_UPLOADFILE ="uploadFile";
final String OPERATION_COPY ="copy";
final String OPERATION_COPYFILE ="copyFile";
final String OPERATION_LOADRESOURCE = "loadResource";
final String OPERATION_LOADRESOURCEFROMARCHIVE = "loadResourceFromArchive";
final String OPERATION_ECHOTOFILE = "echoToFile";
final String OPERATION_CHANGEOWNER = "changeOwner";
final String OPERATION_CHANGEMODE = "changeMode";
final String OPERATION_CHANGEGROUP = "changeGroup";
final String OPERATION_REPLACEINFILE = "replaceInFile";
final String OPERATION_REPLACEINFILE2 = "replaceInFile2";
final String OPERATION_REPLACEINFILEREGEX = "replaceInFileRegEx";
final String PARAM_FILE = "file";
final String PARAM_ENCODING = "encoding";
final String PARAM_OVERRIDE = "override";
/**
* @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 = OPERATION_BASENAME)
public abstract String basename(
@WebParam(name = PARAM_FILE) @XmlElement(required=true) String filename,
@WebParam(name = "suffix") String suffix);
 
/**
* @param res
* @return The file itself (MTOM attachment or inline base64) including some file metadata.
* @throws XServicesFault
*/
@WSDLDocumentation(XServicesDocumentation.SERVICE_OPERATION_DOWNLOADFILE)
@WebMethod(operationName = OPERATION_DOWNLOADFILE)
public abstract AttachmentType downloadFile(
@WebParam(name = FileResource.XML_NAME) FileResource res) throws XServicesFault;
/**
* @param res
* @return Encodes a file
* @throws XServicesFault
*/
@WSDLDocumentation(XServicesDocumentation.SERVICE_OPERATION_ENCODEFILE)
@WebMethod(operationName = OPERATION_ENCODEFILE)
public abstract byte[] encodeFile(
@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 = OPERATION_UPLOADFILE)
public abstract String uploadFile(
@WebParam(name = PARAM_FILE) AttachmentType file) throws XServicesFault;
/**
* @param src
* @param todir
* @param plm
* @param overwrite
* @param encoding
* @return
* @throws XServicesFault
*/
@WSDLDocumentation(value = XServicesDocumentation.SERVICE_OPERATION_COPY)
@WebMethod(operationName = OPERATION_COPY)
public abstract ReturnCode copy(
@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 = PARAM_OVERRIDE) boolean overwrite,
@WebParam(name = PARAM_ENCODING) String encoding) throws XServicesFault;
/**
* @param fromFile
* @param tofile
* @param overwrite
* @return
* @throws XServicesFault
*/
@WSDLDocumentation(value = XServicesDocumentation.SERVICE_OPERATION_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,
@WebParam(name = PARAM_OVERRIDE) boolean overwrite) throws XServicesFault;
 
/**
* @param res
* @param encoding
* @return content of the resource
* @throws XServicesFault
*/
@WSDLDocumentation(value = XServicesDocumentation.SERVICE_OPERATION_LOADRESOURCE)
@WebMethod(operationName = OPERATION_LOADRESOURCE)
public abstract String loadRes(
@WebParam(name = FileResource.XML_NAME) FileResource res,
@WebParam(name = PARAM_ENCODING) String encoding) throws XServicesFault;
 
/**
* @param res
* @param encoding
* @return content of the resource
* @throws XServicesFault
*/
@WSDLDocumentation(value = XServicesDocumentation.SERVICE_OPERATION_LOADRESOURCEFROMARCHIVE)
@WebMethod(operationName = OPERATION_LOADRESOURCEFROMARCHIVE)
public abstract String loadResFromArchive(
@WebParam(name = "archiveresource") ArchiveResource res,
@WebParam(name = PARAM_ENCODING) String encoding) throws XServicesFault;
 
/**
* @param message
* @param file
* @param encoding
* @param append
* @return
* @throws XServicesFault
*/
@WSDLDocumentation(value = XServicesDocumentation.SERVICE_OPERATION_ECHOTOFILE)
@WebMethod(operationName = OPERATION_ECHOTOFILE)
public abstract ReturnCode echo2file(
@WebParam(name = "message") @XmlElement(required=true) String message,
@WebParam(name = PARAM_FILE) @XmlElement(required=true) String file,
@WebParam(name = PARAM_ENCODING) String encoding,
@WebParam(name = "append") boolean append) throws XServicesFault;
 
/**
* Changes the owner of a file or all files inside specified directories.
* Right now it has effect only under Unix/ Linux as it is implemented through
* the 'chown' command.
*
* @param res Collection of files/ directories
* @param owner Identifier of the new owner
* @return
*/
@WebMethod(operationName = OPERATION_CHANGEOWNER)
public abstract ReturnCode changeOwner(
@WebParam(name = FileSetResource.XML_NAME) FileSetResource res,
@WebParam(name = "owner") @XmlElement(required=true) String owner);
 
/**
* Changes the group owner of a file or all files inside specified directories.
* Right now it has effect only under Unix/ Linux as it is implemented through
* the 'chgrp' command.
*
* @param res Collection of files/ directories
* @param group Identifier of the new group owner
* @return
*/
@WebMethod(operationName = OPERATION_CHANGEGROUP)
public abstract ReturnCode changeGroup(
@WebParam(name = FileSetResource.XML_NAME) FileSetResource res,
@WebParam(name = "group") @XmlElement(required=true) String group);
 
/**
* @param res
* @param perm
* @return
*/
@WebMethod(operationName = OPERATION_CHANGEMODE)
public abstract ReturnCode changeMode(
@WebParam(name = FileSetResource.XML_NAME) FileSetResource res,
@WebParam(name = "permissions") @XmlElement(required=true) String perm);
/**
* @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 = FileResource.XML_NAME) @XmlElement(required=true) FileResource res,
@WebParam(name = "search") @XmlElement(required=true) String search,
@WebParam(name = "replace") @XmlElement(required=true) String replace) throws XServicesFault;
/**
* @param res
* @param patternList
* @return
* @throws XServicesFault
*/
@WSDLDocumentation(value = XServicesDocumentation.SERVICE_OPERATION_REPLACEINFILE2)
@WebMethod(operationName = OPERATION_REPLACEINFILE2)
public abstract ReturnCode replaceInFile2(
@WebParam(name = FileResource.XML_NAME) FileResource res,
@WebParam(name = "patternList") List<ReplacePattern> patternList) throws XServicesFault;
/**
* @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 = FileResource.XML_NAME) FileResource res,
@WebParam(name = "search") String search,
@WebParam(name = "replace") String replace,
@WebParam(name = "flags") String flags) throws XServicesFault;
}
/xservices/trunk/src/java/net/brutex/xservices/ws/JobService.java
0,0 → 1,104
/*
* 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.ws;
 
import java.util.List;
 
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlElement;
 
import net.brutex.xservices.types.ScheduledJob;
import net.brutex.xservices.types.SchedulerStatisticsType;
import net.brutex.xservices.util.BrutexNamespaces;
 
import org.apache.cxf.annotations.WSDLDocumentation;
 
/**
* Job management services.
* @author Brian Rosenberger
* @since 0.5.0
*
*/
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES)
public interface JobService {
public static final String SERVICE_NAME = "JobService";
final String OPERATION_GETJOBLIST = "getJobs";
final String OPERATION_SCHEDULEJOB = "scheduleJob";
final String OPERATION_GETJOB = "getJob";
final String OPERATION_DELETEJOB = "deleteJob";
final String OPERATION_GETSTATISTICS = "getStatistics";
final String PARAM_JOB = "job";
/**
* Get a full list of all scheduled jobs.
*
* @return List of scheduled jobs
* @throws XServicesFault
*/
@WebMethod(operationName=OPERATION_GETJOBLIST)
@WSDLDocumentation(value="Get list of scheduled jobs")
public abstract List<ScheduledJob> getJobList() throws XServicesFault;
/**
* Add a job to the scheduler.
*
* @param job
* @return The unique identifier of the job.
* @throws XServicesFault
*/
@WebMethod(operationName=OPERATION_SCHEDULEJOB)
@WSDLDocumentation(value="Schedule a job")
public abstract String scheduleJob(
@WebParam(name=PARAM_JOB) @XmlElement(required=true) ScheduledJob job)
throws XServicesFault;
/**
* Get a job by id.
*
* @param uuid
* @return Job details
* @throws XServicesFault
*/
@WebMethod(operationName=OPERATION_GETJOB)
@WSDLDocumentation(value="Get a job by id")
public abstract ScheduledJob getJob(
@WebParam(name="id") @XmlElement(required=true) String uuid) throws XServicesFault;
/**
* Delete a job from scheduler.
*
* @param uuid Id of the job that should be deleted
* @throws XServicesFault
*/
@WebMethod(operationName=OPERATION_DELETEJOB)
@WSDLDocumentation(value="Delete a scheduled job.")
public abstract void deleteJob(
@WebParam(name="id") @XmlElement(required=true) String uuid) throws XServicesFault;
/**
* Get statisctis about the scheduler
* @throws XServicesFault
*/
@WebMethod(operationName=OPERATION_GETSTATISTICS)
@WSDLDocumentation(value="Get scheduler statistics")
public abstract SchedulerStatisticsType getStatistics() throws XServicesFault;
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/ws/MiscService.java
0,0 → 1,93
/*
* Copyright 2010 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.brutex.xservices.ws;
 
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import net.brutex.xservices.types.HostConnection;
import net.brutex.xservices.types.HostinfoType;
import net.brutex.xservices.types.MailMimeType;
import net.brutex.xservices.types.ReturnCode;
import net.brutex.xservices.types.RuntimeInfoType;
import net.brutex.xservices.types.ant.FileSetResource;
import net.brutex.xservices.util.BrutexNamespaces;
 
import org.apache.cxf.aegis.type.java5.XmlElement;
import org.apache.cxf.aegis.type.java5.XmlReturnType;
import org.apache.cxf.annotations.WSDLDocumentation;
 
/**
* Bundles various methods
*
* @author Brian Rosenberger, bru@brutex.de
* @since 0.4.0
*/
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES)
@WSDLDocumentation("Various service operations.")
public interface MiscService {
public static final String OPERATION_GETMEMORY = "getMemory";
 
/**
* Get IP address from host name.
*
* @param hostname
* @return ReturnCode
*/
@WebMethod(operationName = "getHostinfo")
@WSDLDocumentation(value = "Get information about a host.")
public HostinfoType getHostinfo(
@WebParam(name = "hostname") @XmlElement(minOccurs="1", nillable=false ) String hostname);
 
/**
* Delay execution for a given time.
*
* @param minutes
* @param seconds
* @return ReturnCode
*/
@WebMethod(operationName = "sleep")
@WSDLDocumentation(value = "Delay request response a specified duration.")
public ReturnCode sleep(
@WebParam(name = "minutes") int minutes,
@WebParam(name = "seconds") int seconds);
/**
* @return ReturnCode
*/
@WebMethod(operationName = "getInfo")
@WSDLDocumentation(value = "Get XService information.")
public ReturnCode getInfo();
/**
* Generate a UUID
* @return new UUID
*/
@WebMethod(operationName = "generateUUID")
@WSDLDocumentation(value = "Generate a UUID.")
public String generateUUID();
/**
* Get Memory information
*/
@WebMethod(operationName = MiscService.OPERATION_GETMEMORY)
@WSDLDocumentation(value = "Get memory and processor information")
public RuntimeInfoType getMemory();
}
/xservices/trunk/src/java/net/brutex/xservices/ws/MailService.java
0,0 → 1,123
/*
* Copyright 2012 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.brutex.xservices.ws;
 
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlElement;
 
import net.brutex.xservices.types.HostConnection;
import net.brutex.xservices.types.MailMimeType;
import net.brutex.xservices.types.ReturnCode;
import net.brutex.xservices.types.ant.FileSetResource;
import net.brutex.xservices.util.BrutexNamespaces;
 
import org.apache.cxf.annotations.WSDLDocumentation;
 
/**
* Bundles various method for sending and receiving mails
*
* @author Brian Rosenberger, bru@brutex.de
* @since 2.0.0
*/
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES)
@WSDLDocumentation("Various mail service operations.")
public interface MailService {
 
final String PARAM_SMTPHOST = "mailhost";
final String PARAM_SENDER = "from";
final String PARAM_RECEIVER = "to";
final String PARAM_SUBJECT = "subject";
final String PARAM_MESSAGE = "message";
final String PARAM_ATTACHMENTS = "attachments";
/**
* Simple mail send operation with sender, single receiver, subject and message.
*
* @param mailhost connection details for the SMTP server to use
* @param from mail address to be used as sender
* @param tolist mail address of the receiver
* @param subject subject of the mail
* @param message mail body
* @return ReturnCode
*/
@WebMethod(operationName = "sendMailSimple")
@WSDLDocumentation(value = "Send an email (simple).")
public ReturnCode sendMailSimple(
@WebParam(name = PARAM_SMTPHOST) @XmlElement(required=true, nillable=false) HostConnection mailhost,
@WebParam(name = PARAM_SENDER) @XmlElement(required=true) String from,
@WebParam(name = PARAM_RECEIVER) @XmlElement(required=true, nillable=false) String tolist,
@WebParam(name = PARAM_SUBJECT) String subject,
@WebParam(name = PARAM_MESSAGE) String message);
 
/**
* Simple mail send operation with sender, single receiver, subject and message
* including support for file attachments.
*
* @param mailhost connection details for the SMTP server to use
* @param from mail address to be used as sender
* @param tolist mail address of the receiver
* @param subject subject of the mail
* @param message mail body
* @param res attachments
* @return ReturnCode
*/
@WebMethod(operationName = "sendMailSimpleWithAttachment")
@WSDLDocumentation(value = "Send an email with attachment (simple).")
public ReturnCode sendMailSimpleWithAttachment(
@WebParam(name = PARAM_SMTPHOST) @XmlElement(required=true, nillable=false) HostConnection mailhost,
@WebParam(name = PARAM_SENDER) @XmlElement(required=true, nillable=false) String from,
@WebParam(name = PARAM_RECEIVER) @XmlElement(required=true, nillable=false) String tolist,
@WebParam(name = PARAM_SUBJECT) String subject,
@WebParam(name = PARAM_MESSAGE) String message,
@WebParam(name = PARAM_ATTACHMENTS) FileSetResource res);
 
/**
* Send email with a lot of options
*
* @param mailhost connection details for the SMTP server to use
* @param from mail address to be used as sender
* @param tolist mail address of the receiver
* @param cclist mail carbon copy receiver
* @param bcclist mail blind carbon copy receiver
* @param subject subject of the mail
* @param mimetype message MIME type (i.e. text/plain)
* @param charset character set to use (i.e. utf-8, iso-8859-15)
* @param message mail body
* @param res attachments
* @param ssl use SSL
* @param tls use TLS
* @return ReturnCode
*/
@WebMethod(operationName = "sendMail")
@WSDLDocumentation(value = "Send an email (advanced).")
public ReturnCode sendMail(
@WebParam(name = PARAM_SMTPHOST) @XmlElement(required=true, nillable=false) HostConnection mailhost,
@WebParam(name = PARAM_SENDER) @XmlElement(required=true, nillable=false) String from,
@WebParam(name = PARAM_RECEIVER) @XmlElement(required=true, nillable=false) String tolist,
@WebParam(name = "cc") String cclist,
@WebParam(name = "bcc") String bcclist,
@WebParam(name = PARAM_SUBJECT) String subject,
@WebParam(name = "mimetype") MailMimeType mimetype,
@WebParam(name = "charset") String charset,
@WebParam(name = PARAM_MESSAGE) String message,
@WebParam(name = PARAM_ATTACHMENTS) FileSetResource res,
@WebParam(name = "useSSL") boolean ssl,
@WebParam(name = "useStartTLS") boolean tls);
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/ws/XServicesFault.java
0,0 → 1,99
/*
* Copyright 2010 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.ws;
 
import java.util.GregorianCalendar;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.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;
 
/**
* Generic web service fault.
*
* @author Brian Rosenberger, bru@brutex.de
* since 0.4.0
*/
@WebFault(targetNamespace=BrutexNamespaces.WS_XSERVICES)
public class XServicesFault extends Exception {
 
/**
*
*/
private static final long serialVersionUID = -6779279189376374820L;
 
public XServicesFault(String message, Exception e) {
this(message, e.getCause());
}
 
public XServicesFault(String string) {
this(string, new Exception(string).getCause());
}
 
public XServicesFault(Exception e) {
this(e.getMessage(), e.getCause());
}
 
public XServicesFault(String message, Throwable cause) {
super(message, cause);
this.faultstring=message;
 
try {
timestamp = DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar());
} catch (DatatypeConfigurationException ex) {
System.err.println(ex.getMessage());
}
 
 
}
/**
* The error message.
*/
@XmlElement(name="faultstring", namespace=BrutexNamespaces.WS_XSERVICES)
public String faultstring = "";
 
/**
* Username under which the web service has been executed.
*/
@XmlElement(name="username", namespace=BrutexNamespaces.WS_XSERVICES)
public String username = System.getProperty("user.name");
 
/**
* Home directory of the user profile running the web service.
*/
@XmlElement(name="homedir", namespace=BrutexNamespaces.WS_XSERVICES)
public String homedir = System.getProperty("user.home");
 
/**
* 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");
}
/xservices/trunk/src/java/net/brutex/xservices/ws/ArchiveService.java
0,0 → 1,205
/*
* Copyright 2010 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.brutex.xservices.ws;
 
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import net.brutex.xservices.types.CompressionType;
 
import net.brutex.xservices.types.ReturnCode;
import net.brutex.xservices.types.ant.ArchiveResource;
import net.brutex.xservices.types.ant.FileResource;
import net.brutex.xservices.types.ant.FileSetResource;
import net.brutex.xservices.util.BrutexNamespaces;
 
 
/**
* Archiving related web service.
*
* @author Brian Rosenberger, bru@brutex.de
* @since 0.4.0
*/
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES)
public interface ArchiveService {
 
final String WS_OPERATION_BZIP2 = "bzip2";
final String WS_OPERATION_BZIP2_ARCHIVE = "bzip2FromArchive";
final String WS_OPERATION_GZIP = "gzip";
final String WS_OPERATION_GZIP_ARCHIVE = "gzipFromArchive";
final String WS_OPERATION_UNZIP = "unzip";
final String WS_OPERATION_GUNZIP = "gunzip";
final String WS_OPERATION_BUNZIP2 = "bunzip2";
final String WS_PARAM_SOURCEFILE = "source";
final String WS_PARAM_SOURCEFILE_STRING = "srcfile";
final String WS_PARAM_SOURCEURL = "srcurl";
final String WS_PARAM_SOURCEARCHIVE = "archivesource";
final String WS_PARAM_DESTFILE = "destfile";
final String WS_PARAM_DESTDIR = "destdir";
final String WS_PARAM_ENCODING = "encoding";
final String WS_PARAM_OVERWRITE = "overwrite";
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) 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) 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) 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) 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) 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) 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) 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) 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 = 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) 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) 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) 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) throws XServicesFault;
}
/xservices/trunk/src/java/net/brutex/xservices/ws/StorageService.java
0,0 → 1,84
/*
* 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.ws;
 
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import net.brutex.xservices.types.TargetNodeType;
import net.brutex.xservices.types.ant.AttachmentType;
import net.brutex.xservices.types.ant.CollectionType;
import net.brutex.xservices.util.BrutexNamespaces;
 
import org.apache.cxf.annotations.WSDLDocumentation;
 
/**
* Storage management services.
* @author Brian Rosenberger
* @since 0.5.0
*
*/
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES)
public interface StorageService {
public static final String SERVICE_NAME = "StorageService";
final String OPERATION_STORETEXT = "storeText";
final String OPERATION_STOREBINARY = "storeBinary";
final String OPERATION_CREATECOLLECTION = "createCollection";
final String OPERATION_DELIVERCOLLECTION = "deliverCollection";
final String PARAM_TEXT = "text";
final String PARAM_BINARY = "binary";
final String PARAM_NAME = "name";
final String PARAM_COLLECTION = "collection";
final String PARAM_TARGETNODE = "target";
final String PARAM_RAISEEVENT = "event";
;
/**
* Store text based data.
* @param text text to be stored
*
* @return uuid reference to stored object
* @throws XServicesFault
*/
@WebMethod(operationName=OPERATION_STORETEXT)
@WSDLDocumentation(value="Store text based data")
public abstract String storeText(@WebParam(name = PARAM_TEXT) String text) throws XServicesFault;
@WebMethod(operationName=OPERATION_STOREBINARY)
@WSDLDocumentation(value="Store binary data")
public abstract String storeBinary(
@WebParam(name= PARAM_BINARY) AttachmentType binary)
throws XServicesFault;
@WebMethod(operationName=OPERATION_CREATECOLLECTION)
@WSDLDocumentation(value="Create a new Collection by name.")
public abstract String createCollection(
@WebParam(name= PARAM_COLLECTION) CollectionType collection)
throws XServicesFault;
@WebMethod(operationName=OPERATION_DELIVERCOLLECTION)
@WSDLDocumentation(value="Deliver a collection to a target node (asynchronous).")
public abstract void deliverCollection(
@WebParam(name= PARAM_COLLECTION) CollectionType collection,
@WebParam(name= PARAM_TARGETNODE) TargetNodeType targetnode,
@WebParam(name= PARAM_RAISEEVENT) boolean isFiring)
throws XServicesFault;
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/ws/DateService.java
0,0 → 1,255
/*
* 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.ws;
 
import java.math.BigInteger;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
 
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.datatype.XMLGregorianCalendar;
 
import net.brutex.xservices.types.DateFormatType;
import net.brutex.xservices.types.DateInfoExtendedType;
import net.brutex.xservices.types.DateInfoType;
import net.brutex.xservices.types.DateTimeUnits;
import net.brutex.xservices.types.TimeZoneType;
import net.brutex.xservices.util.BrutexNamespaces;
 
 
import org.apache.cxf.annotations.WSDLDocumentation;
import org.apache.cxf.annotations.WSDLDocumentationCollection;
 
/**
* Date and time related services.
* @author Brian Rosenberger
*
*/
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES)
@WSDLDocumentationCollection(
{
@WSDLDocumentation(value = BrutexNamespaces.BRUTEX_COPYRIGHT, placement = WSDLDocumentation.Placement.TOP)
}
)
public interface DateService {
public static final String SERVICE_NAME = "DateService";
final String OPERATION_GETDATE = "getDate";
final String OPERATION_GETDATEEXTENDED = "getDateExtended";
final String OPERATION_GETTIMESTAMP = "getTimestamp";
final String OPERATION_GETTIMESTAMP2 = "getTimestamp2";
final String OPERATION_GETINTIMEZONE = "getInTimezone";
final String OPERATION_FORMATDATE = "formatDate";
final String OPERATION_FORMATDATEADVANCED = "formatDateAdvanced";
final String OPERATION_PARSEDATE = "parseDate";
final String OPERATION_PARSEDATEADVANCED = "parseDateAdvanced";
final String OPERATION_DATETIMEDIFF = "dateTimeDiff";
final String OPERATION_DATETIMEDIFF2 = "dateTimeDiff2";
final String OPERATION_DATEADD = "dateAdd";
final String OPERATION_GETTIMEZONES = "getTimezones";
final String PARAM_TIMEZONE = "timezone";
final String PARAM_DATETIME = "datetime";
final String PARAM_FORMAT = "format";
final String PARAM_UNIT = "unit";
/**
* Get current date and time.
*
* @return Current date and time.
* @throws XServicesFault
*/
@WebMethod(operationName=OPERATION_GETDATE)
@WSDLDocumentation(value="Get current date and time.")
public abstract DateInfoType getDate()
throws XServicesFault;
/**
* Get current date and time (extended version).
*
* @return Current date and time.
* @throws XServicesFault
*/
@WebMethod(operationName=OPERATION_GETDATEEXTENDED)
@WSDLDocumentation(value="Get current date and time in different formats.")
public abstract DateInfoExtendedType getDateExtended()
throws XServicesFault;
/**
* Get milliseconds since 01.01.1970.
*
* @return timestamp milliseconds
*/
@WebMethod(operationName=OPERATION_GETTIMESTAMP)
@WSDLDocumentation(value="Get milliseconds since 01.01.1970 (Unix timestap).")
public abstract BigInteger getTimestamp();
 
/**
* Get seconds since 01.01.1970.
*
* @return timestamp seconds
*/
@WebMethod(operationName=OPERATION_GETTIMESTAMP2)
@WSDLDocumentation(value="Get seconds since 01.01.1970 (Unix timestap).")
public abstract BigInteger getTimestamp2();
/**
* Display a date time with a different time zone.
* Changes representation only (no conversion).
*
* @param cal date time.
* @param timezone time zone
* @return date time
* @throws XServicesFault
*/
@WebMethod(operationName=OPERATION_GETINTIMEZONE)
public abstract String getInTimezone(
@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) Date cal,
@WebParam(name=PARAM_TIMEZONE) @XmlElement(required=true) String timezone) throws XServicesFault;
/**
* Formats a date with pre-defined patterns.
*
* @param cal date time to be formatted in ISO8601
* @param format Pattern to be used for date formating
* @return formatted date/time string
* @throws XServicesFault
*/
@WebMethod(operationName=OPERATION_FORMATDATE)
public abstract String formatDate(
@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) Date cal,
@WebParam(name=PARAM_FORMAT) @XmlElement(required=true) DateFormatType format) throws XServicesFault;
@WebMethod(operationName=OPERATION_GETTIMEZONES)
public abstract List<TimeZoneType> getTimezones() throws XServicesFault;
/**
* Formats a date with a free form pattern.
* Uses SimpleDateFormat patterns
* The following pattern letters are defined (all other characters from 'A' to 'Z' and from 'a' to 'z' are reserved):
 
Letter Date or Time Component Presentation Examples
G Era designator Text AD
y Year Year 1996; 96
M Month in year Month July; Jul; 07
w Week in year Number 27
W Week in month Number 2
D Day in year Number 189
d Day in month Number 10
F Day of week in month Number 2
E Day in week Text Tuesday; Tue
a Am/pm marker Text PM
H Hour in day (0-23) Number 0
k Hour in day (1-24) Number 24
K Hour in am/pm (0-11) Number 0
h Hour in am/pm (1-12) Number 12
m Minute in hour Number 30
s Second in minute Number 55
S Millisecond Number 978
z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
Z Time zone RFC 822 time zone -0800
* @param cal Date time to be formatted
* @param format Format string
* @return Date time formatted according to format string
* @throws XServicesFault
*/
@WebMethod(operationName=OPERATION_FORMATDATEADVANCED)
public abstract String formatDateAdvanced(
@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) Date cal,
@WebParam(name=PARAM_FORMAT) @XmlElement(required=true) String format) throws XServicesFault;
/**
* Converts a string into date using pre-defined date formats.
*
* @param s Date/ time as string
* @param format date format
* @param timezone timezone
* @return XML Date
* @throws XServicesFault
*/
@WebMethod(operationName=OPERATION_PARSEDATE)
@WSDLDocumentation(value="Converts a string into date using pre-defined date formats.")
public abstract Date parseDate(
@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) String s,
@WebParam(name=PARAM_FORMAT) @XmlElement(required=true) DateFormatType format,
@WebParam(name=PARAM_TIMEZONE) String timezone) throws XServicesFault;
/**
* Converts a string into date using any format.
* @param s date/ time as string
* @param format date format
* @param timezone timezone
* @return XML Date
* @throws XServicesFault
*/
@WebMethod(operationName=OPERATION_PARSEDATEADVANCED)
public abstract GregorianCalendar parseDateAdvanced(
@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) String s,
@WebParam(name=PARAM_FORMAT) @XmlElement(required=true) String format,
@WebParam(name=PARAM_TIMEZONE) String timezone) throws XServicesFault;
/**
* Calculate elapsed time between two dates.
* @param fromCal First date.
* @param toCal Second date.
* @return Elapsed time in milliseconds
* @throws XServicesFault
*/
@WebMethod(operationName=OPERATION_DATETIMEDIFF)
public abstract BigInteger dateTimeDiff(
@WebParam(name="fromDateTime") @XmlElement(required=true) Date fromCal,
@WebParam(name="toDateTime") @XmlElement(required=true) Date toCal) throws XServicesFault;
/**
* Fully elapsed units between two dates.
* 4:15:10-4:15:55 in minutes = 0 and in seconds = 45
*
* @param fromCal
* @param toCal
* @param unit
* @return Date/time difference in unit
* @throws XServicesFault
*/
@WebMethod(operationName=OPERATION_DATETIMEDIFF2)
@WSDLDocumentation(value="Get elapsed time between to dates.")
public abstract BigInteger dateTimeDiff2(
@WebParam(name="fromDateTime") @XmlElement(required=true) Date fromCal,
@WebParam(name="toDateTime") @XmlElement(required=true) Date toCal,
@WebParam(name=PARAM_UNIT) DateTimeUnits unit) throws XServicesFault;
/**
* Add or subtract a time span from a date.
*
* @param cal The initial date.
* @param value The amount to add.
* @param unit The unit the amount is defined in.
* @return New date and time.
* @throws XServicesFault
*
*/
@WebMethod(operationName=OPERATION_DATEADD)
@WSDLDocumentation(value="Add or substract a time span from a date.")
public abstract GregorianCalendar dateAdd(
@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) GregorianCalendar cal,
@WebParam(name="value") @XmlElement(required=true) BigInteger value,
@WebParam(name=PARAM_UNIT) @XmlElement(required=true) DateTimeUnits unit) throws XServicesFault;
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/ws/ExecuteService.java
0,0 → 1,145
/*
* 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.ws;
 
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlElement;
 
import net.brutex.xservices.types.HostConnection;
import net.brutex.xservices.types.ReturnCode;
import net.brutex.xservices.util.BrutexNamespaces;
 
/**
* Task execution web service
*
* @author Brian Rosenberger
* @since 0.1.0
*
*/
@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,
@WebParam(name = "keyfile") String keyfile,
@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,
@WebParam(name = "prompt") String prompt,
@WebParam(name = "command") String cmd,
@WebParam(name = "expect") String expect,
@WebParam(name = "timeout") long timeout);
/**
* @param script
* @throws XServicesFault
*/
@WebMethod(operationName = "runJavaScript")
public abstract void runJScript(
@WebParam(name = "script") @XmlElement(required=true) String script) throws XServicesFault;
 
}