Subversion Repositories XServices

Rev

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

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