Subversion Repositories XServices

Rev

Rev 20 | 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
 
21 brianR 59
    public ReturnCode sendMailSimpleWithAttachment(HostConnection mailhost, String from,
60
            String tolist, String subject, String message,
61
            FileSetResource res) {
62
        return  sendMail(from,
63
                from,
64
                tolist,
65
                "",
66
                "",
67
                subject,
68
                message,
69
                "text/plain",
70
                res,
71
                mailhost.hostname,
72
                mailhost.port,
73
                mailhost.user,
74
                mailhost.password,
75
                "utf-8",
76
                false,
77
                false);
78
    }
79
 
80
 
81
 
20 brianR 82
    public ReturnCode sleep(int minutes, int seconds) {
83
        return sleep(0, minutes, seconds, 0);
84
    }
18 brianR 85
 
86
 
20 brianR 87
 
17 brianR 88
    private ReturnCode antGetHostinfo(String hostname, String prefix) {
89
        HostInfo info = new HostInfo();
90
        info.setTaskName("HostInfo");
91
        RunTask runner = new RunTask(info);
92
        info.setHost(hostname);
18 brianR 93
        //info.setPrefix(prefix);
17 brianR 94
        return runner.postTask();
16 brianR 95
    }
96
 
18 brianR 97
    private ReturnCode sendMail(String from,
98
            String replyto,
99
            String tolist,
100
            String cclist,
101
            String bcclist,
102
            String subject,
103
            String message,
104
            String messagemimetype,
105
            FileSetResource attachments,
106
            String mailhost,
107
            int mailport,
108
            String user,
109
            String password,
110
            String charset,
111
            boolean tls,
112
            boolean ssl) {
113
        EmailTask mail = new EmailTask();
114
        mail.setTaskName("Mail");
115
        RunTask runner = new RunTask(mail);
116
        mail.setFrom(from);
117
        mail.setReplyTo(replyto);
118
        mail.setToList(tolist);
119
        mail.setCcList(cclist);
120
        mail.setBccList(bcclist);
121
        mail.setSubject(subject);
122
        mail.setMessage(message);
123
        mail.setMessageMimeType(messagemimetype);
124
        if(attachments != null) {
125
            mail.addFileset(attachments.getAntFileSet(mail.getProject()));
126
        }
127
        mail.setMailhost(mailhost);
128
        mail.setMailport(mailport);
129
        mail.setUser(user);
130
        mail.setPassword(password);
131
        mail.setCharset(charset);
132
        mail.setSSL(ssl);
133
        mail.setEnableStartTLS(tls);
134
        return runner.postTask();
135
    }
136
 
20 brianR 137
    private ReturnCode sleep(int hours, int minutes, int seconds, int milliseconds) {
138
        Sleep sleep = new Sleep();
139
        sleep.setTaskName("Sleep");
140
        RunTask runner = new RunTask(sleep);
141
        sleep.setHours(hours);
142
        sleep.setMinutes(minutes);
143
        sleep.setSeconds(seconds);
144
        sleep.setMilliseconds(milliseconds);
145
        return runner.postTask();
146
    }
147
 
16 brianR 148
}