Subversion Repositories XServices

Rev

Rev 46 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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