Subversion Repositories XServices

Rev

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

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