Subversion Repositories XServices

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
16 brianR 1
/*
2
 *   Copyright 2010 Brian Rosenberger (Brutex Network)
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (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
7
 *
8
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
15
 */
16
 
46 brianR 17
package net.brutex.xservices.ws.impl;
16 brianR 18
 
54 brianR 19
import java.util.Enumeration;
20
import java.util.Properties;
21
 
16 brianR 22
import javax.jws.WebService;
18 brianR 23
import net.brutex.xservices.types.FileSetResource;
24
import net.brutex.xservices.types.HostConnection;
22 brianR 25
import net.brutex.xservices.types.MailMimeType;
16 brianR 26
import net.brutex.xservices.types.ReturnCode;
46 brianR 27
import net.brutex.xservices.util.BrutexNamespaces;
17 brianR 28
import net.brutex.xservices.util.RunTask;
46 brianR 29
import net.brutex.xservices.ws.MiscService;
30
 
23 brianR 31
import org.apache.cxf.annotations.WSDLDocumentation;
32
import org.apache.cxf.annotations.WSDLDocumentationCollection;
17 brianR 33
import org.apache.tools.ant.taskdefs.HostInfo;
20 brianR 34
import org.apache.tools.ant.taskdefs.Sleep;
18 brianR 35
import org.apache.tools.ant.taskdefs.email.EmailTask;
16 brianR 36
 
37
/**
46 brianR 38
 *
16 brianR 39
 * @author Brian Rosenberger, bru@brutex.de
40
 */
46 brianR 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(
46
		targetNamespace = BrutexNamespaces.WS_XSERVICES,
47
		endpointInterface = "net.brutex.xservices.ws.MiscService",
48
		serviceName = "MiscService"
49
			)
16 brianR 50
public class MiscServiceImpl implements MiscService {
51
 
46 brianR 52
	@WSDLDocumentation(value = "Get information about a host.")
53
	public ReturnCode getHostinfo(String hostname) {
54
		return antGetHostinfo(hostname, null);
55
	}
54 brianR 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();
16 brianR 63
 
54 brianR 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
 
78
 
46 brianR 79
	public ReturnCode sendMailSimple(HostConnection mailhost, String from,
80
			String tolist, String subject, String message) {
81
		return sendMail(from, from, tolist, "", "", subject, message,
82
				"text/plain", null, mailhost.hostname, mailhost.port,
83
				mailhost.user, mailhost.password, "utf-8", false, false);
84
	}
18 brianR 85
 
46 brianR 86
	public ReturnCode sendMailSimpleWithAttachment(HostConnection mailhost,
87
			String from, String tolist, String subject, String message,
88
			FileSetResource res) {
89
		return sendMail(from, from, tolist, "", "", subject, message,
90
				"text/plain", res, mailhost.hostname, mailhost.port,
91
				mailhost.user, mailhost.password, "utf-8", false, false);
92
	}
21 brianR 93
 
46 brianR 94
	public ReturnCode sendMail(HostConnection mailhost, String from,
95
			String tolist, String cclist, String bcclist, String subject,
96
			MailMimeType mimetype, String charset, String message,
97
			FileSetResource res, boolean ssl, boolean tls) {
98
		return sendMail(from, from, tolist, cclist, bcclist, subject, message,
99
				mimetype.value(), res, mailhost.hostname, mailhost.port,
100
				mailhost.user, mailhost.password, charset, tls, ssl);
101
	}
21 brianR 102
 
46 brianR 103
	public ReturnCode sleep(int minutes, int seconds) {
104
		return sleep(0, minutes, seconds, 0);
105
	}
21 brianR 106
 
46 brianR 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);
112
		// info.setPrefix(prefix);
113
		return runner.postTask();
114
	}
22 brianR 115
 
46 brianR 116
	private ReturnCode sendMail(String from, String replyto, String tolist,
117
			String cclist, String bcclist, String subject, String message,
118
			String messagemimetype, FileSetResource attachments,
119
			String mailhost, int mailport, String user, String password,
120
			String charset, boolean tls, boolean ssl) {
121
		EmailTask mail = new EmailTask();
122
		mail.setTaskName("Mail");
123
		RunTask runner = new RunTask(mail);
124
		mail.setFrom(from);
125
		mail.setReplyTo(replyto);
126
		mail.setToList(tolist);
127
		mail.setCcList(cclist);
128
		mail.setBccList(bcclist);
129
		mail.setSubject(subject);
130
		mail.setMessage(message);
131
		mail.setMessageMimeType(messagemimetype);
132
		if (attachments != null) {
54 brianR 133
			mail.addFileset(attachments.getAntResource(mail.getProject()));
46 brianR 134
		}
135
		mail.setMailhost(mailhost);
136
		mail.setMailport(mailport);
137
		mail.setUser(user);
138
		mail.setPassword(password);
139
		mail.setCharset(charset);
140
		mail.setSSL(ssl);
141
		mail.setEnableStartTLS(tls);
142
		return runner.postTask();
143
	}
22 brianR 144
 
46 brianR 145
	private ReturnCode sleep(int hours, int minutes, int seconds,
146
			int milliseconds) {
147
		Sleep sleep = new Sleep();
148
		sleep.setTaskName("Sleep");
149
		RunTask runner = new RunTask(sleep);
150
		sleep.setHours(hours);
151
		sleep.setMinutes(minutes);
152
		sleep.setSeconds(seconds);
153
		sleep.setMilliseconds(milliseconds);
154
		return runner.postTask();
155
	}
16 brianR 156
}