Subversion Repositories XServices

Rev

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