Subversion Repositories XServices

Rev

Go to most recent revision | Details | 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;
83 brianR 28
import net.brutex.xservices.types.ant.FileSetResource;
46 brianR 29
import net.brutex.xservices.util.BrutexNamespaces;
17 brianR 30
import net.brutex.xservices.util.RunTask;
46 brianR 31
import net.brutex.xservices.ws.MiscService;
32
 
23 brianR 33
import org.apache.cxf.annotations.WSDLDocumentation;
34
import org.apache.cxf.annotations.WSDLDocumentationCollection;
17 brianR 35
import org.apache.tools.ant.taskdefs.HostInfo;
20 brianR 36
import org.apache.tools.ant.taskdefs.Sleep;
18 brianR 37
import org.apache.tools.ant.taskdefs.email.EmailTask;
16 brianR 38
 
39
/**
85 brianR 40
 * Implements the web service
46 brianR 41
 *
16 brianR 42
 * @author Brian Rosenberger, bru@brutex.de
43
 */
85 brianR 44
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES,
45
		endpointInterface = "net.brutex.xservices.ws.MiscService",
46
		serviceName = "MiscService")
16 brianR 47
public class MiscServiceImpl implements MiscService {
48
 
78 brianR 49
	public HostinfoType getHostinfo(String hostname) {
50
		HostInfo info = new HostInfo();
51
		info.setTaskName("HostInfo");
52
		RunTask runner = new RunTask(info);
53
		info.setHost(hostname);
54
		// info.setPrefix(prefix);
85 brianR 55
		// TODO: Does not work for IP Addresses?
78 brianR 56
		ReturnCode ret = runner.postTask();
57
		HostinfoType infotype = new HostinfoType(
58
				ret.getProperty("NAME"),
59
				ret.getProperty("DOMAIN"),
60
				ret.getProperty("ADDR4"),
61
				ret.getProperty("ADDR6"));
62
		return infotype;
46 brianR 63
	}
78 brianR 64
 
54 brianR 65
	public ReturnCode getInfo() {
66
		ReturnCode r = new ReturnCode();
67
		r.returnCode = 0;
68
		// Get all system properties
69
		Properties props = System.getProperties();
16 brianR 70
 
54 brianR 71
		// Enumerate all system properties
78 brianR 72
		@SuppressWarnings("unchecked")
54 brianR 73
		Enumeration<String> e = (Enumeration<String>) props.propertyNames();
78 brianR 74
		for (; e.hasMoreElements();) {
75
			// Get property name
76
			String propName = (String) e.nextElement();
54 brianR 77
 
78 brianR 78
			// Get property value
79
			String propValue = (String) props.get(propName);
80
			r.stdOut = r.stdOut + propName + ": " + propValue + "\n";
54 brianR 81
		}
82
 
83
		return r;
84
	}
85
 
46 brianR 86
	public ReturnCode sendMailSimple(HostConnection mailhost, String from,
87
			String tolist, String subject, String message) {
88
		return sendMail(from, from, tolist, "", "", subject, message,
89
				"text/plain", null, mailhost.hostname, mailhost.port,
90
				mailhost.user, mailhost.password, "utf-8", false, false);
91
	}
18 brianR 92
 
46 brianR 93
	public ReturnCode sendMailSimpleWithAttachment(HostConnection mailhost,
94
			String from, String tolist, String subject, String message,
95
			FileSetResource res) {
96
		return sendMail(from, from, tolist, "", "", subject, message,
97
				"text/plain", res, mailhost.hostname, mailhost.port,
98
				mailhost.user, mailhost.password, "utf-8", false, false);
99
	}
21 brianR 100
 
46 brianR 101
	public ReturnCode sendMail(HostConnection mailhost, String from,
102
			String tolist, String cclist, String bcclist, String subject,
103
			MailMimeType mimetype, String charset, String message,
104
			FileSetResource res, boolean ssl, boolean tls) {
105
		return sendMail(from, from, tolist, cclist, bcclist, subject, message,
106
				mimetype.value(), res, mailhost.hostname, mailhost.port,
107
				mailhost.user, mailhost.password, charset, tls, ssl);
108
	}
21 brianR 109
 
46 brianR 110
	public ReturnCode sleep(int minutes, int seconds) {
111
		return sleep(0, minutes, seconds, 0);
112
	}
21 brianR 113
 
78 brianR 114
	public String generateUUID() {
115
		return UUID.randomUUID().toString();
46 brianR 116
	}
22 brianR 117
 
46 brianR 118
	private ReturnCode sendMail(String from, String replyto, String tolist,
119
			String cclist, String bcclist, String subject, String message,
120
			String messagemimetype, FileSetResource attachments,
121
			String mailhost, int mailport, String user, String password,
122
			String charset, boolean tls, boolean ssl) {
123
		EmailTask mail = new EmailTask();
124
		mail.setTaskName("Mail");
125
		RunTask runner = new RunTask(mail);
126
		mail.setFrom(from);
127
		mail.setReplyTo(replyto);
128
		mail.setToList(tolist);
129
		mail.setCcList(cclist);
130
		mail.setBccList(bcclist);
131
		mail.setSubject(subject);
132
		mail.setMessage(message);
133
		mail.setMessageMimeType(messagemimetype);
134
		if (attachments != null) {
54 brianR 135
			mail.addFileset(attachments.getAntResource(mail.getProject()));
46 brianR 136
		}
137
		mail.setMailhost(mailhost);
138
		mail.setMailport(mailport);
139
		mail.setUser(user);
140
		mail.setPassword(password);
141
		mail.setCharset(charset);
142
		mail.setSSL(ssl);
143
		mail.setEnableStartTLS(tls);
144
		return runner.postTask();
145
	}
22 brianR 146
 
46 brianR 147
	private ReturnCode sleep(int hours, int minutes, int seconds,
148
			int milliseconds) {
149
		Sleep sleep = new Sleep();
150
		sleep.setTaskName("Sleep");
151
		RunTask runner = new RunTask(sleep);
152
		sleep.setHours(hours);
153
		sleep.setMinutes(minutes);
154
		sleep.setSeconds(seconds);
155
		sleep.setMilliseconds(milliseconds);
156
		return runner.postTask();
157
	}
16 brianR 158
}