Subversion Repositories XServices

Rev

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