Subversion Repositories XServices

Rev

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