Subversion Repositories XServices

Rev

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

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