Subversion Repositories XServices

Rev

Rev 83 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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