Subversion Repositories XServices

Compare Revisions

Problem with comparison.

Regard whitespace Rev HEAD → Rev 9

/xservices/trunk/src/java/net/brutex/xservices/util/BrutexNamespaces.java
0,0 → 1,35
/*
* 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.util;
 
/**
* Holds static namespace information.
*
*
* @author Brian Rosenberger, bru@brutex.de
*/
public class BrutexNamespaces {
 
/**
* Brutex Network XServices web service namespace declaration
*/
public static final String WS_XSERVICES = "http://ws.xservices.brutex.net";
 
 
private BrutexNamespaces() {};
}
/xservices/trunk/src/java/net/brutex/xservices/util/RunTask.java
0,0 → 1,91
/*
* 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.util;
 
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildListener;
import org.apache.tools.ant.BuildLogger;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Target;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.Echo;
 
/**
*
* @author Brian Rosenberger, bru@brutex.de
*/
public class RunTask {
 
Project antproject;
Target anttarget;
Task anttask;
 
public RunTask(Task anttask) {
 
antproject = new Project();
antproject.init();
antproject.setBasedir(System.getProperty("java.io.tmpdir"));
DefaultLogger log = new DefaultLogger();
log.setErrorPrintStream(System.err);
log.setOutputPrintStream(System.out);
antproject.addBuildListener(log);
Vector listeners = antproject.getBuildListeners();
for (Iterator i = listeners.iterator(); i.hasNext(); ) {
BuildListener listener = (BuildListener) i.next();
 
if (listener instanceof BuildLogger) {
BuildLogger logger = (BuildLogger) listener;
logger.setMessageOutputLevel(Echo.EchoLevel.VERBOSE.getLevel());
logger.setOutputPrintStream(System.out);
logger.setErrorPrintStream(System.err);
}
}
 
anttarget = new Target();
anttarget.setName("XBridgeNGDynamicTarget");
anttarget.setProject(antproject);
antproject.addTarget(anttarget);
 
this.anttask = anttask;
prepareTask();
}
 
private void prepareTask()
throws BuildException {
anttask.init();
anttask.setProject(antproject);
anttask.setOwningTarget(anttarget);
anttarget.addTask(anttask);
antproject.addOrReplaceTarget(anttarget);
}
 
public Map<String, String> postTask()
throws BuildException
{
try {
antproject.executeTarget(anttarget.getName());
//anttask.execute();
return antproject.getProperties();
} catch (Exception ex) {
throw new BuildException(ex);
}
}
}
/xservices/trunk/src/java/net/brutex/xservices/util/UnRarTask.java
0,0 → 1,74
/*
* 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.util;
 
import de.innosystec.unrar.Archive;
import de.innosystec.unrar.exception.RarException;
import de.innosystec.unrar.rarfile.FileHeader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
 
/**
*
* @author Brian Rosenberger, bru@brutex.de
*/
public class UnRarTask extends Task {
 
private File dst = null;
private File src = null;
 
public File getDst() {
return dst;
}
 
public void setDst(File dst) {
this.dst = dst;
}
 
public File getSrc() {
return src;
}
 
public void setSrc(File src) {
this.src = src;
}
 
 
@Override
public void execute() {
if(src==null ) throw new BuildException("Please supply a source archive file.");
if(!src.exists()) throw new BuildException("Archive '"+src.getName()+"' does not exist.");
 
try {
if(dst==null) dst = new File(src.getParent());
Archive ar = new Archive(src);
List<FileHeader> list = ar.getFileHeaders();
for(FileHeader h : list) {
ar.extractFile(h, new FileOutputStream(new File(dst.getAbsolutePath()+"/"+h.getFileNameString())));
}
} catch (RarException ex) {
throw new BuildException(ex.getMessage(), ex);
} catch (IOException ex) {
throw new BuildException(ex.getMessage(), ex);
}
}
 
}
/xservices/trunk/src/java/net/brutex/xservices/types/CompressionType.java
0,0 → 1,28
/*
* 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.types;
 
import javax.xml.bind.annotation.XmlEnum;
 
/**
*
* @author Brian Rosenberger, bru@brutex.de
*/
@XmlEnum()
public enum CompressionType {
NONE, GZIP, BZIP2
}
/xservices/trunk/src/java/net/brutex/xservices/types/FileSetResource.java
0,0 → 1,89
/*
* 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.types;
 
import java.io.File;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlType;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.TarFileSet;
import org.apache.tools.ant.types.ZipFileSet;
 
/**
*
* @author Brian Rosenberger, bru@brutex.de
*/
@XmlType(name="FileSetType", namespace="http://ws.xservices.brutex.net",
propOrder={"type", "source", "includes", "excludes", "casesensitive"})
public class FileSetResource {
 
@XmlElement(name="FileSetType", required=true, nillable=false, defaultValue="FILES")
public FileSetType type = FileSetType.FILES;
 
@XmlElement(name="source", required=true, nillable=false)
public String source = "";
 
@XmlElement(name="includes", required=true, nillable=false, defaultValue="**/*")
public String includes = "";
 
@XmlElement(name="excludes", required=false, nillable=true, defaultValue="")
public String excludes ="";
 
@XmlElement(name="casesensitive", required=true, nillable=false, defaultValue="true")
public boolean casesensitive = true;
 
public FileSet getAntFileSet(Project p) {
FileSet set = null;
switch(type) {
case ZIP:
ZipFileSet zset = new ZipFileSet();
zset.setSrc(new File(source));
zset.setEncoding(System.getProperty("file.encoding"));
set = zset;
break;
case TAR:
TarFileSet tset = new TarFileSet();
tset.setSrc(new File(source));
set = tset;
break;
case GZTAR:
Resource res = new FileResource(FileResource.Type.GZIP, source).getAntResource(p);
TarFileSet gzset = new TarFileSet();
gzset.setSrcResource(res);
set = gzset;
break;
default: //FILES
set = new FileSet();
set.setDir(new File(source));
}
set.setProject(p);
set.setIncludes(includes);
set.setExcludes(excludes);
set.setCaseSensitive(casesensitive);
 
return set;
}
 
@XmlEnum
public enum FileSetType{
FILES, ZIP, TAR, GZTAR
}
 
}
/xservices/trunk/src/java/net/brutex/xservices/types/FileResource.java
0,0 → 1,83
/*
* 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.types;
 
import java.io.File;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.resources.BZip2Resource;
import org.apache.tools.ant.types.resources.GZipResource;
import org.apache.tools.ant.types.resources.URLResource;
 
/**
*
* @author Brian Rosenberger, bru@brutex.de
*/
@XmlRootElement(namespace="http://ws.xservices.brutex.net")
public class FileResource
implements ResourceInterface {
 
@XmlElement(defaultValue = "FILE", nillable = false, required = true)
public Type type = Type.FILE;
@XmlElement(nillable = false, required = true)
public String uri;
 
@XmlEnum(String.class)
public enum Type {
 
FILE, URL, GZIP, BZIP2
}
 
public FileResource(Type type, String uri) {
this.type = type;
this.uri = uri;
}
 
public FileResource() {
}
 
public Resource getAntResource(Project p) {
Resource res = null;
switch (type) {
case URL:
URLResource ures = new URLResource(uri);
res = ures;
break;
 
case GZIP:
GZipResource gres = new GZipResource(
new org.apache.tools.ant.types.resources.FileResource(new File(uri)));
res = gres;
break;
 
case BZIP2:
BZip2Resource bres = new BZip2Resource(
new org.apache.tools.ant.types.resources.FileResource(new File(uri)));
res = bres;
break;
 
default:
//Default is Type FILE
res = new org.apache.tools.ant.types.resources.FileResource(new File(uri));
}
res.setProject(p);
return res;
}
}
/xservices/trunk/src/java/net/brutex/xservices/types/ResourceInterface.java
0,0 → 1,30
/*
* 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.types;
 
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Resource;
 
/**
*
* @author Brian Rosenberger, bru@brutex.de
*/
public interface ResourceInterface {
 
Resource getAntResource(Project p);
 
}
/xservices/trunk/src/java/net/brutex/xservices/types/ArchiveResource.java
0,0 → 1,79
/*
* 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.types;
 
import java.io.File;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlType;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.resources.TarResource;
import org.apache.tools.ant.types.resources.ZipResource;
import org.apache.tools.tar.TarEntry;
import org.apache.tools.zip.ZipEntry;
 
/**
*
* @author Brian Rosenberger, bru@brutex.de
*/
@XmlType(namespace = "http://ws.xservices.brutex.net")
public class ArchiveResource
implements ResourceInterface {
 
@XmlElement(defaultValue = "ZIP", nillable = false, required = true)
public ArchiveType type = ArchiveType.ZIP;
@XmlElement(nillable = false, required = true)
public String archive;
@XmlElement(nillable = false, required = true)
public String uri;
 
@XmlEnum(String.class)
public enum ArchiveType {
 
ZIP, TAR, GZTAR
}
 
public Resource getAntResource(Project p) {
Resource res = null;
switch (type) {
case TAR:
TarEntry tarentry = new TarEntry(uri);
TarResource tres = new TarResource(new File(archive), tarentry);
res = tres;
break;
 
case GZTAR:
TarResource gres = new TarResource(new org.apache.tools.ant.types.resources.GZipResource(
new org.apache.tools.ant.types.resources.FileResource(
new File(archive))), new TarEntry(uri));
res = gres;
break;
 
default: //This is type ZIP also
ZipEntry zipentry = new ZipEntry(uri);
if (zipentry.getTime() == -1) {
zipentry.setTime(System.currentTimeMillis());
}
res = new ZipResource(new File(archive), null, zipentry);
break;
}
 
res.setProject(p);
return res;
}
}
/xservices/trunk/src/java/net/brutex/xservices/types/ReturnCode.java
0,0 → 1,43
/*
* 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.types;
 
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
 
/**
*
* @author Brian Rosenberger, bru@brutex.de
*/
@XmlType(namespace="http://ws.xservices.brutex.net")
public class ReturnCode {
 
@XmlElement(required=true)
public int returnCode;
 
public String stdOut;
public String stdErr;
 
public ReturnCode() {
}
 
public ReturnCode(int returnCode, String stdOut, String stdErr) {
this.returnCode = returnCode;
this.stdOut = stdOut;
this.stdErr = stdErr;
}
}
/xservices/trunk/src/java/net/brutex/xservices/ws/FileService.java
0,0 → 1,147
/*
* 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.io.File;
import java.util.Map;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import net.brutex.xservices.types.ArchiveResource;
import net.brutex.xservices.types.FileResource;
import net.brutex.xservices.types.FileSetResource;
import net.brutex.xservices.types.ResourceInterface;
import net.brutex.xservices.util.RunTask;
import org.apache.tools.ant.taskdefs.Basename;
import org.apache.tools.ant.taskdefs.Copy;
import org.apache.tools.ant.taskdefs.Echo;
import org.apache.tools.ant.taskdefs.LoadResource;
import org.apache.tools.ant.types.FileSet;
 
/**
*
* @author Brian Rosenberger, bru@brutex.de
*/
@WebService(targetNamespace="http://ws.xservices.brutex.net", name="FileService")
public class FileService {
 
@WebMethod(operationName = "basename")
public String basename(@WebParam(name = "file") String filename,
@WebParam(name = "suffix") String suffix) {
return basename(new File(filename), suffix);
}
 
@WebMethod(operationName = "copy")
public void copy(@WebParam(name="fileset") FileSetResource src,
@WebParam(name="todir") String todir,
@WebParam(name="preservelastmodified") boolean plm,
@WebParam(name="overwrite") boolean overwrite,
@WebParam(name="encoding") String encoding)
throws XServicesFault {
try {
copy(src, new File(todir), plm, overwrite, encoding);
} catch (Exception ex) {
throw new XServicesFault(ex.getMessage(), ex);
}
}
 
@WebMethod(operationName = "loadResource")
public String loadRes(@WebParam(name = "resource") FileResource res,
@WebParam(name = "encoding") String encoding) {
if (encoding == null || encoding.equals("")) {
encoding = System.getProperty("file.encoding");
}
return loadResource(res, encoding);
}
 
@WebMethod(operationName = "loadResourceFromArchive")
public String loadResFromArchive(@WebParam(name = "archiveresource") ArchiveResource res,
@WebParam(name = "encoding") String encoding) {
if (encoding == null || encoding.equals("")) {
encoding = System.getProperty("file.encoding");
}
return loadResource(res, encoding);
}
 
@WebMethod(operationName = "echoToFile")
public String echo2file(@WebParam(name="message") String message,
@WebParam(name="file")String file, @WebParam(name="encoding") String encoding,
@WebParam(name="append")boolean append) {
return echo(message, new File(file), encoding, append);
}
 
@WebMethod(exclude = true)
private String basename(File file,
String suffix) {
Basename basename = new Basename();
RunTask runner = new RunTask(basename);
basename.setFile(file);
if (suffix != null && !suffix.equals("")) {
basename.setSuffix(suffix);
}
basename.setProperty("basename.value");
Map<String, String> result = runner.postTask();
return result.get("basename.value");
}
@WebMethod(exclude = true)
private String loadResource(ResourceInterface src, String encoding) {
LoadResource lr = new LoadResource();
lr.setTaskName("LoadResource");
RunTask runner = new RunTask(lr);
lr.addConfigured(src.getAntResource(lr.getProject()));
lr.setEncoding(encoding);
System.out.println("Using encoding: " + encoding);
lr.setProperty("LoadResource.out");
Map<String, String> result = runner.postTask();
return result.get("LoadResource.out");
}
 
@WebMethod(exclude = true)
private String echo(String msg, File file, String encoding, boolean append) {
Echo echo = new Echo();
echo.setTaskName("toFile");
RunTask runTask = new RunTask(echo);
echo.addText(msg);
echo.setEncoding(encoding);
echo.setFile(file);
echo.setAppend(append);
Map<String, String> result = runTask.postTask();
return "complete";
}
 
@WebMethod(exclude=true)
private void copy(FileSetResource src, File dst, boolean preservelastmodified,
boolean overwrite, String encoding) {
Copy copy = new Copy();
copy.setTaskName("Copy");
RunTask runner = new RunTask(copy);
FileSet set = src.getAntFileSet(copy.getProject());
copy.add(set);
 
if(dst.isDirectory()) copy.setTodir(dst);
if(dst.isFile()) copy.setTofile(dst);
copy.setOverwrite(overwrite);
copy.setPreserveLastModified(preservelastmodified);
if(encoding!=null && !encoding.equals("") ) {
copy.setOutputEncoding(encoding);
} else {
copy.setOutputEncoding(System.getProperty("file.encoding"));
}
 
Map<String, String> result = runner.postTask();
}
}
/xservices/trunk/src/java/net/brutex/xservices/ws/ArchiveService.java
0,0 → 1,300
/*
* 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.io.File;
import java.util.Map;
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.util.RunTask;
import net.brutex.xservices.util.UnRarTask;
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="http://ws.xservices.brutex.net", name="ArchiveService")
public class ArchiveService {
 
public static final String WS_OPERATION_BZIP2 = "bzip2";
public static final String WS_OPERATION_BZIP2_ARCHIVE = "bzip2FromArchive";
public static final String WS_OPERATION_GZIP = "gzip";
public static final String WS_OPERATION_GZIP_ARCHIVE = "gzipFromArchive";
public static final String WS_OPERATION_UNZIP = "unzip";
public static final String WS_OPERATION_GUNZIP = "gunzip";
public static final String WS_OPERATION_BUNZIP2 = "bunzip2";
 
public static final String WS_PARAM_SOURCEFILE = "source";
public static final String WS_PARAM_SOURCEFILE_STRING = "srcfile";
public static final String WS_PARAM_SOURCEURL = "srcurl";
public static final String WS_PARAM_SOURCEARCHIVE = "archivesource";
public static final String WS_PARAM_DESTFILE = "destfile";
public static final String WS_PARAM_DESTDIR = "destdir";
 
public static final String WS_PARAM_ENCODING = "encoding";
public static final String WS_PARAM_OVERWRITE= "overwrite";
 
@WebMethod(operationName = WS_OPERATION_BZIP2, action=WS_OPERATION_BZIP2)
public String bzip2(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
@WebParam(name = WS_PARAM_DESTFILE) String file) {
return bzip(src, new File(file));
}
 
@WebMethod(operationName = WS_OPERATION_BZIP2_ARCHIVE, action=WS_OPERATION_BZIP2_ARCHIVE)
public String bzip2FromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
@WebParam(name = WS_PARAM_DESTFILE) String file) {
return bzip(src, new File(file));
}
 
@WebMethod(operationName = WS_OPERATION_GZIP, action=WS_OPERATION_GZIP)
public String gzip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
@WebParam(name = WS_PARAM_DESTFILE) String file) {
return gzip(src, new File(file));
}
 
@WebMethod(operationName = WS_OPERATION_GZIP_ARCHIVE, action=WS_OPERATION_GZIP_ARCHIVE)
public String gzipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
@WebParam(name = WS_PARAM_DESTFILE) String file) {
return gzip(src, new File(file));
}
 
@WebMethod(operationName = WS_OPERATION_GUNZIP, action=WS_OPERATION_GUNZIP)
public String gunzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
@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);
}
 
@WebMethod(operationName = WS_OPERATION_BUNZIP2)
public String 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);
}
 
@WebMethod(operationName = "gunzipFromURL")
public String 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);
}
 
@WebMethod(operationName = "bunzip2FromURL")
public String 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);
}
 
@WebMethod(operationName = "zip")
public String 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);
}
 
@WebMethod(operationName = "zipFromArchive")
public String 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);
}
 
 
@WebMethod(operationName = "unzip")
public String 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);
}
 
@WebMethod(operationName = "unrar")
public String unrar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
return unrar(new File(src), new File(dest));
}
 
@WebMethod(operationName = "untar")
public String untar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
@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 String 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);
 
Map<String, String> result = runner.postTask();
return "complete";
}
 
@WebMethod(exclude = true)
private String 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);
Map<String, String> result = runner.postTask();
return "complete";
}
 
 
 
@WebMethod(exclude = true)
private String 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);
Map<String, String> result = runner.postTask();
return "complete";
}
 
@WebMethod(exclude = true)
private String 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);
}
Map<String, String> result = runner.postTask();
return "complete";
}
 
@WebMethod(exclude = true)
private String 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);
}
Map<String, String> result = runner.postTask();
return "complete";
}
 
@WebMethod(exclude = true)
private String 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);
}
 
Map<String, String> result = runner.postTask();
return "complete";
}
 
@WebMethod(exclude = true)
private String 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);
Map<String, String> result = runner.postTask();
return "complete";
}
 
@WebMethod(exclude = true)
private String unrar(File src, File dst) {
UnRarTask unrar = new UnRarTask();
unrar.setTaskName("UnRar");
RunTask runner = new RunTask(unrar);
unrar.setSrc(src);
unrar.setDst(dst);
Map<String, String> result = runner.postTask();
return "complete";
}
 
}
/xservices/trunk/src/java/net/brutex/xservices/ws/ExecuteService.java
0,0 → 1,290
/*
* 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.io.File;
import java.util.Map;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import net.brutex.xservices.types.ReturnCode;
import net.brutex.xservices.util.RunTask;
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;
 
/**
*
* @author Brian Rosenberger, bru@brutex.de
*/
@WebService(targetNamespace="http://ws.xservices.brutex.net", name="ExecuteService")
public class ExecuteService {
 
@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);
}
 
@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);
}
 
@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);
}
 
@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);
}
 
@WebMethod(operationName = "runCommandWithSSH")
public ReturnCode runCommandWithSSH(@WebParam(name = "host") String host,
@WebParam(name = "port") int port,
@WebParam(name = "username") String username,
@WebParam(name = "password") String password,
@WebParam(name = "command") String cmd,
@WebParam(name = "timeout") long timeout) {
 
return sshExec(host, username, password, port, cmd, timeout);
}
 
@WebMethod(operationName = "runCommandWithSSHKeyAuth")
public ReturnCode runCommandWithSSHKeyAuth(@WebParam(name = "host") String host,
@WebParam(name = "port") int port,
@WebParam(name = "username") String username,
@WebParam(name = "passphrase") String passphrase,
@WebParam(name = "keyfile") String keyfile,
@WebParam(name = "command") String cmd,
@WebParam(name = "timeout") long timeout) {
 
return sshExecWithCert(host, username, passphrase, keyfile, port, cmd, timeout);
}
 
@WebMethod(operationName = "rExec")
public ReturnCode rExec(@WebParam(name = "host") String host,
@WebParam(name = "port") int port,
@WebParam(name = "username") String username,
@WebParam(name = "password") String password,
@WebParam(name = "command") String cmd,
@WebParam(name = "timeout") long timeout) {
return rexec(host, port, username, password, cmd, timeout);
}
 
@WebMethod(operationName = "telnet")
public ReturnCode runTelnet(@WebParam(name = "host") String host,
@WebParam(name = "port") int port,
@WebParam(name = "username") String username,
@WebParam(name = "password") String password,
@WebParam(name = "prompt") String prompt,
@WebParam(name = "command") String cmd,
@WebParam(name = "expect") String expect,
@WebParam(name = "timeout") long timeout) {
return telnet(host, port, username, password, cmd, timeout, prompt, expect);
}
 
@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.setCommand(cmdl);
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);
 
Map<String, String> result = runner.postTask();
ReturnCode res = null;
if (spawn) {
res = new ReturnCode(0, null, null);
} else {
res = new ReturnCode(Integer.valueOf(result.get("ExecuteService.result")),
result.get("ExecuteService.stdout"), result.get("ExecuteService.stderr"));
}
return res;
}
 
@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");
Map<String, String> result = runner.postTask();
ReturnCode res = null;
res = new ReturnCode(0,
result.get("SSHExec.stdout"), "");
 
return res;
}
 
@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");
Map<String, String> result = runner.postTask();
ReturnCode res = null;
res = new ReturnCode(0,
result.get("SSHExec.stdout"), "");
 
return res;
}
 
@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));
 
Map<String, String> result = runner.postTask();
ReturnCode res = null;
res = new ReturnCode(0,
"", "");
 
return res;
}
 
@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);
 
Map<String, String> result = runner.postTask();
ReturnCode res = null;
res = new ReturnCode(0,
"", "");
return res;
}
}
/xservices/trunk/src/java/net/brutex/xservices/ws/XServicesFault.java
0,0 → 1,67
/*
* 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.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
 
/**
*
* @author Brian Rosenberger, bru@brutex.de
*/
public class XServicesFault extends Exception {
 
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());
}
 
 
}
@XmlElement(name="faultstring")
public String faultstring = "";
 
@XmlElement(name="username")
public String username = System.getProperty("user.name");
 
@XmlElement(name="homedir")
public String homedir = System.getProperty("user.home");
 
@XmlElement(name="timstamp")
public XMLGregorianCalendar timestamp = null;
}