Subversion Repositories XServices

Rev

Go to most recent revision | 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
 
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;
18 brianR 25
import org.apache.tools.ant.taskdefs.email.EmailTask;
26
import org.apache.tools.ant.taskdefs.email.Mailer;
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
 
59
 
60
 
17 brianR 61
    private ReturnCode antGetHostinfo(String hostname, String prefix) {
62
        HostInfo info = new HostInfo();
63
        info.setTaskName("HostInfo");
64
        RunTask runner = new RunTask(info);
65
        info.setHost(hostname);
18 brianR 66
        //info.setPrefix(prefix);
17 brianR 67
        return runner.postTask();
16 brianR 68
    }
69
 
18 brianR 70
    private ReturnCode sendMail(String from,
71
            String replyto,
72
            String tolist,
73
            String cclist,
74
            String bcclist,
75
            String subject,
76
            String message,
77
            String messagemimetype,
78
            FileSetResource attachments,
79
            String mailhost,
80
            int mailport,
81
            String user,
82
            String password,
83
            String charset,
84
            boolean tls,
85
            boolean ssl) {
86
        EmailTask mail = new EmailTask();
87
        mail.setTaskName("Mail");
88
        RunTask runner = new RunTask(mail);
89
        mail.setFrom(from);
90
        mail.setReplyTo(replyto);
91
        mail.setToList(tolist);
92
        mail.setCcList(cclist);
93
        mail.setBccList(bcclist);
94
        mail.setSubject(subject);
95
        mail.setMessage(message);
96
        mail.setMessageMimeType(messagemimetype);
97
        if(attachments != null) {
98
            mail.addFileset(attachments.getAntFileSet(mail.getProject()));
99
        }
100
        mail.setMailhost(mailhost);
101
        mail.setMailport(mailport);
102
        mail.setUser(user);
103
        mail.setPassword(password);
104
        mail.setCharset(charset);
105
        mail.setSSL(ssl);
106
        mail.setEnableStartTLS(tls);
107
        return runner.postTask();
108
    }
109
 
16 brianR 110
}