Subversion Repositories XServices

Rev

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