Subversion Repositories XServices

Rev

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

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