Subversion Repositories XServices

Rev

Rev 85 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
16 brianR 1
/*
2
 *   Copyright 2010 Brian Rosenberger (Brutex Network)
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   you may not use this file except in compliance with the License.
6
 *   You may obtain a copy of the License at
7
 *
8
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
15
 */
16
 
46 brianR 17
package net.brutex.xservices.ws.impl;
16 brianR 18
 
54 brianR 19
import java.util.Enumeration;
20
import java.util.Properties;
78 brianR 21
import java.util.UUID;
54 brianR 22
 
16 brianR 23
import javax.jws.WebService;
18 brianR 24
import net.brutex.xservices.types.HostConnection;
78 brianR 25
import net.brutex.xservices.types.HostinfoType;
22 brianR 26
import net.brutex.xservices.types.MailMimeType;
16 brianR 27
import net.brutex.xservices.types.ReturnCode;
87 brianR 28
import net.brutex.xservices.types.RuntimeInfoType;
83 brianR 29
import net.brutex.xservices.types.ant.FileSetResource;
46 brianR 30
import net.brutex.xservices.util.BrutexNamespaces;
17 brianR 31
import net.brutex.xservices.util.RunTask;
46 brianR 32
import net.brutex.xservices.ws.MiscService;
33
 
23 brianR 34
import org.apache.cxf.annotations.WSDLDocumentation;
35
import org.apache.cxf.annotations.WSDLDocumentationCollection;
17 brianR 36
import org.apache.tools.ant.taskdefs.HostInfo;
20 brianR 37
import org.apache.tools.ant.taskdefs.Sleep;
18 brianR 38
import org.apache.tools.ant.taskdefs.email.EmailTask;
16 brianR 39
 
40
/**
85 brianR 41
 * Implements the web service
46 brianR 42
 *
16 brianR 43
 * @author Brian Rosenberger, bru@brutex.de
44
 */
85 brianR 45
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES,
46
		endpointInterface = "net.brutex.xservices.ws.MiscService",
47
		serviceName = "MiscService")
16 brianR 48
public class MiscServiceImpl implements MiscService {
49
 
78 brianR 50
	public HostinfoType getHostinfo(String hostname) {
51
		HostInfo info = new HostInfo();
52
		info.setTaskName("HostInfo");
53
		RunTask runner = new RunTask(info);
54
		info.setHost(hostname);
55
		// info.setPrefix(prefix);
85 brianR 56
		// TODO: Does not work for IP Addresses?
78 brianR 57
		ReturnCode ret = runner.postTask();
58
		HostinfoType infotype = new HostinfoType(
59
				ret.getProperty("NAME"),
60
				ret.getProperty("DOMAIN"),
61
				ret.getProperty("ADDR4"),
62
				ret.getProperty("ADDR6"));
63
		return infotype;
46 brianR 64
	}
78 brianR 65
 
54 brianR 66
	public ReturnCode getInfo() {
67
		ReturnCode r = new ReturnCode();
68
		r.returnCode = 0;
69
		// Get all system properties
70
		Properties props = System.getProperties();
16 brianR 71
 
54 brianR 72
		// Enumerate all system properties
78 brianR 73
		@SuppressWarnings("unchecked")
54 brianR 74
		Enumeration<String> e = (Enumeration<String>) props.propertyNames();
78 brianR 75
		for (; e.hasMoreElements();) {
76
			// Get property name
77
			String propName = (String) e.nextElement();
54 brianR 78
 
78 brianR 79
			// Get property value
80
			String propValue = (String) props.get(propName);
81
			r.stdOut = r.stdOut + propName + ": " + propValue + "\n";
54 brianR 82
		}
83
 
84
		return r;
85
	}
86
 
46 brianR 87
	public ReturnCode sendMailSimple(HostConnection mailhost, String from,
88
			String tolist, String subject, String message) {
89
		return sendMail(from, from, tolist, "", "", subject, message,
90
				"text/plain", null, mailhost.hostname, mailhost.port,
91
				mailhost.user, mailhost.password, "utf-8", false, false);
92
	}
18 brianR 93
 
46 brianR 94
	public ReturnCode sendMailSimpleWithAttachment(HostConnection mailhost,
95
			String from, String tolist, String subject, String message,
96
			FileSetResource res) {
97
		return sendMail(from, from, tolist, "", "", subject, message,
98
				"text/plain", res, mailhost.hostname, mailhost.port,
99
				mailhost.user, mailhost.password, "utf-8", false, false);
100
	}
21 brianR 101
 
46 brianR 102
	public ReturnCode sendMail(HostConnection mailhost, String from,
103
			String tolist, String cclist, String bcclist, String subject,
104
			MailMimeType mimetype, String charset, String message,
105
			FileSetResource res, boolean ssl, boolean tls) {
106
		return sendMail(from, from, tolist, cclist, bcclist, subject, message,
107
				mimetype.value(), res, mailhost.hostname, mailhost.port,
108
				mailhost.user, mailhost.password, charset, tls, ssl);
109
	}
21 brianR 110
 
46 brianR 111
	public ReturnCode sleep(int minutes, int seconds) {
112
		return sleep(0, minutes, seconds, 0);
113
	}
21 brianR 114
 
78 brianR 115
	public String generateUUID() {
116
		return UUID.randomUUID().toString();
46 brianR 117
	}
22 brianR 118
 
46 brianR 119
	private ReturnCode sendMail(String from, String replyto, String tolist,
120
			String cclist, String bcclist, String subject, String message,
121
			String messagemimetype, FileSetResource attachments,
122
			String mailhost, int mailport, String user, String password,
123
			String charset, boolean tls, boolean ssl) {
124
		EmailTask mail = new EmailTask();
125
		mail.setTaskName("Mail");
126
		RunTask runner = new RunTask(mail);
127
		mail.setFrom(from);
128
		mail.setReplyTo(replyto);
129
		mail.setToList(tolist);
130
		mail.setCcList(cclist);
131
		mail.setBccList(bcclist);
132
		mail.setSubject(subject);
133
		mail.setMessage(message);
134
		mail.setMessageMimeType(messagemimetype);
135
		if (attachments != null) {
54 brianR 136
			mail.addFileset(attachments.getAntResource(mail.getProject()));
46 brianR 137
		}
138
		mail.setMailhost(mailhost);
139
		mail.setMailport(mailport);
140
		mail.setUser(user);
141
		mail.setPassword(password);
142
		mail.setCharset(charset);
143
		mail.setSSL(ssl);
144
		mail.setEnableStartTLS(tls);
145
		return runner.postTask();
146
	}
22 brianR 147
 
46 brianR 148
	private ReturnCode sleep(int hours, int minutes, int seconds,
149
			int milliseconds) {
150
		Sleep sleep = new Sleep();
151
		sleep.setTaskName("Sleep");
152
		RunTask runner = new RunTask(sleep);
153
		sleep.setHours(hours);
154
		sleep.setMinutes(minutes);
155
		sleep.setSeconds(seconds);
156
		sleep.setMilliseconds(milliseconds);
157
		return runner.postTask();
158
	}
87 brianR 159
 
160
	public RuntimeInfoType getMemory() {
161
		return new RuntimeInfoType();
162
	}
16 brianR 163
}