Subversion Repositories XServices

Compare Revisions

Ignore whitespace Rev 97 → Rev 114

/xservices/trunk/src/java/net/brutex/xservices/ws/impl/MiscServiceImpl.java
1,5 → 1,5
/*
* Copyright 2010 Brian Rosenberger (Brutex Network)
* Copyright 2013 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.
18,12 → 18,15
 
import java.util.Enumeration;
import java.util.Properties;
import java.util.UUID;
 
import javax.jws.WebService;
import net.brutex.xservices.types.FileSetResource;
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;
35,122 → 38,116
import org.apache.tools.ant.taskdefs.email.EmailTask;
 
/**
* Implements the web service
*
* @author Brian Rosenberger, bru@brutex.de
*/
@WSDLDocumentationCollection({
@WSDLDocumentation("My portType documentation"),
@WSDLDocumentation(value = "My top level documentation", placement = WSDLDocumentation.Placement.TOP),
@WSDLDocumentation(value = "My binding doc", placement = WSDLDocumentation.Placement.BINDING) })
@WebService(
targetNamespace = BrutexNamespaces.WS_XSERVICES,
endpointInterface = "net.brutex.xservices.ws.MiscService",
serviceName = "MiscService"
)
public class MiscServiceImpl implements MiscService {
@WebService(targetNamespace="http://ws.xservices.brutex.net", 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);
 
@WSDLDocumentation(value = "Get information about a host.")
public ReturnCode getHostinfo(String hostname) {
return antGetHostinfo(hostname, null);
}
@WSDLDocumentation(value = "Get XService information.")
public ReturnCode getInfo() {
ReturnCode r = new ReturnCode();
r.returnCode = 0;
// Get all system properties
Properties props = System.getProperties();
ReturnCode ret = runner.postTask();
HostinfoType infotype = new HostinfoType(
ret.getProperty("NAME"),
ret.getProperty("DOMAIN"),
ret.getProperty("ADDR4"),
ret.getProperty("ADDR6"));
return infotype;
}
 
// Enumerate all system properties
Enumeration<String> e = (Enumeration<String>) props.propertyNames();
for (; e.hasMoreElements(); ) {
// Get property name
String propName = (String)e.nextElement();
public ReturnCode getInfo() {
ReturnCode r = new ReturnCode();
r.returnCode = 0;
 
// Get property value
String propValue = (String)props.get(propName);
r.stdOut = r.stdOut + propName + ": " + propValue + "\n";
}
Properties props = System.getProperties();
 
return r;
}
Enumeration e = props.propertyNames();
while (e.hasMoreElements())
{
String propName = (String)e.nextElement();
 
String propValue = (String)props.get(propName);
r.stdOut = (r.stdOut + propName + ": " + propValue + "\n");
}
 
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);
}
return r;
}
 
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 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 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 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 sleep(int minutes, int seconds) {
return sleep(0, minutes, seconds, 0);
}
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 antGetHostinfo(String hostname, String prefix) {
HostInfo info = new HostInfo();
info.setTaskName("HostInfo");
RunTask runner = new RunTask(info);
info.setHost(hostname);
// info.setPrefix(prefix);
return runner.postTask();
}
public ReturnCode sleep(int minutes, int seconds) {
return sleep(0, minutes, seconds, 0);
}
 
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();
}
public String generateUUID() {
return UUID.randomUUID().toString();
}
 
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();
}
}
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();
}
}