Changed MiscService to return dedicated type for getHostinfo operation

git-svn-id: https://brutex.net/svn/xservices/trunk@78 e7e49efb-446e-492e-b9ec-fcafc1997a86
tag-20130205r
Brian Rosenberger 2011-12-31 13:42:51 +00:00
parent 72ae2fae1b
commit 43dc5c30e4
2 changed files with 39 additions and 24 deletions

View File

@ -20,9 +20,12 @@ import javax.jws.WebParam;
import javax.jws.WebService; import javax.jws.WebService;
import net.brutex.xservices.types.FileSetResource; import net.brutex.xservices.types.FileSetResource;
import net.brutex.xservices.types.HostConnection; import net.brutex.xservices.types.HostConnection;
import net.brutex.xservices.types.HostinfoType;
import net.brutex.xservices.types.MailMimeType; import net.brutex.xservices.types.MailMimeType;
import net.brutex.xservices.types.ReturnCode; import net.brutex.xservices.types.ReturnCode;
import net.brutex.xservices.util.BrutexNamespaces; import net.brutex.xservices.util.BrutexNamespaces;
import org.apache.cxf.aegis.type.java5.XmlElement;
import org.apache.cxf.annotations.WSDLDocumentation; import org.apache.cxf.annotations.WSDLDocumentation;
import org.apache.cxf.annotations.WSDLDocumentationCollection; import org.apache.cxf.annotations.WSDLDocumentationCollection;
@ -43,8 +46,8 @@ public interface MiscService {
*/ */
@WebMethod(operationName = "getHostinfo") @WebMethod(operationName = "getHostinfo")
@WSDLDocumentation(value = "Get information about a host.") @WSDLDocumentation(value = "Get information about a host.")
public ReturnCode getHostinfo( public HostinfoType getHostinfo(
@WebParam(name = "hostname") String hostname); @WebParam(name = "hostname") @XmlElement(minOccurs="1", nillable=false ) String hostname);
/** /**
* *
@ -132,4 +135,12 @@ public interface MiscService {
@WSDLDocumentation(value = "Get XService information.") @WSDLDocumentation(value = "Get XService information.")
public ReturnCode getInfo(); public ReturnCode getInfo();
/**
* Generate a UUID
* @return new UUID
*/
@WebMethod(operationName = "generateUUID")
@WSDLDocumentation(value = "Generate a UUID.")
public String generateUUID();
} }

View File

@ -18,10 +18,12 @@ package net.brutex.xservices.ws.impl;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Properties; import java.util.Properties;
import java.util.UUID;
import javax.jws.WebService; import javax.jws.WebService;
import net.brutex.xservices.types.FileSetResource; import net.brutex.xservices.types.FileSetResource;
import net.brutex.xservices.types.HostConnection; import net.brutex.xservices.types.HostConnection;
import net.brutex.xservices.types.HostinfoType;
import net.brutex.xservices.types.MailMimeType; import net.brutex.xservices.types.MailMimeType;
import net.brutex.xservices.types.ReturnCode; import net.brutex.xservices.types.ReturnCode;
import net.brutex.xservices.util.BrutexNamespaces; import net.brutex.xservices.util.BrutexNamespaces;
@ -38,15 +40,22 @@ import org.apache.tools.ant.taskdefs.email.EmailTask;
* *
* @author Brian Rosenberger, bru@brutex.de * @author Brian Rosenberger, bru@brutex.de
*/ */
@WebService( @WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.MiscService", serviceName = "MiscService")
targetNamespace = BrutexNamespaces.WS_XSERVICES,
endpointInterface = "net.brutex.xservices.ws.MiscService",
serviceName = "MiscService"
)
public class MiscServiceImpl implements MiscService { public class MiscServiceImpl implements MiscService {
public ReturnCode getHostinfo(String hostname) { public HostinfoType getHostinfo(String hostname) {
return antGetHostinfo(hostname, null); HostInfo info = new HostInfo();
info.setTaskName("HostInfo");
RunTask runner = new RunTask(info);
info.setHost(hostname);
// info.setPrefix(prefix);
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() { public ReturnCode getInfo() {
@ -56,20 +65,20 @@ public class MiscServiceImpl implements MiscService {
Properties props = System.getProperties(); Properties props = System.getProperties();
// Enumerate all system properties // Enumerate all system properties
@SuppressWarnings("unchecked")
Enumeration<String> e = (Enumeration<String>) props.propertyNames(); Enumeration<String> e = (Enumeration<String>) props.propertyNames();
for (; e.hasMoreElements(); ) { for (; e.hasMoreElements();) {
// Get property name // Get property name
String propName = (String)e.nextElement(); String propName = (String) e.nextElement();
// Get property value // Get property value
String propValue = (String)props.get(propName); String propValue = (String) props.get(propName);
r.stdOut = r.stdOut + propName + ": " + propValue + "\n"; r.stdOut = r.stdOut + propName + ": " + propValue + "\n";
} }
return r; return r;
} }
public ReturnCode sendMailSimple(HostConnection mailhost, String from, public ReturnCode sendMailSimple(HostConnection mailhost, String from,
String tolist, String subject, String message) { String tolist, String subject, String message) {
return sendMail(from, from, tolist, "", "", subject, message, return sendMail(from, from, tolist, "", "", subject, message,
@ -98,13 +107,8 @@ public class MiscServiceImpl implements MiscService {
return sleep(0, minutes, seconds, 0); return sleep(0, minutes, seconds, 0);
} }
private ReturnCode antGetHostinfo(String hostname, String prefix) { public String generateUUID() {
HostInfo info = new HostInfo(); return UUID.randomUUID().toString();
info.setTaskName("HostInfo");
RunTask runner = new RunTask(info);
info.setHost(hostname);
// info.setPrefix(prefix);
return runner.postTask();
} }
private ReturnCode sendMail(String from, String replyto, String tolist, private ReturnCode sendMail(String from, String replyto, String tolist,