Subversion Repositories XServices

Rev

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

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