Subversion Repositories XServices

Rev

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

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