Subversion Repositories XServices

Rev

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

Rev 17 Rev 18
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;
18
 
18
 
19
import javax.jws.WebService;
19
import javax.jws.WebService;
-
 
20
import net.brutex.xservices.types.FileSetResource;
-
 
21
import net.brutex.xservices.types.HostConnection;
20
import net.brutex.xservices.types.ReturnCode;
22
import net.brutex.xservices.types.ReturnCode;
21
import net.brutex.xservices.util.RunTask;
23
import net.brutex.xservices.util.RunTask;
22
import org.apache.tools.ant.taskdefs.HostInfo;
24
import org.apache.tools.ant.taskdefs.HostInfo;
-
 
25
import org.apache.tools.ant.taskdefs.email.EmailTask;
-
 
26
import org.apache.tools.ant.taskdefs.email.Mailer;
23
 
27
 
24
/**
28
/**
25
 *
29
 *
26
 * @author Brian Rosenberger, bru@brutex.de
30
 * @author Brian Rosenberger, bru@brutex.de
27
 */
31
 */
28
@WebService(endpointInterface="net.brutex.xservices.ws.MiscService",
32
@WebService(endpointInterface="net.brutex.xservices.ws.MiscService",
29
serviceName="MiscService")
33
serviceName="MiscService")
30
public class MiscServiceImpl implements MiscService {
34
public class MiscServiceImpl implements MiscService {
31
 
35
 
32
    public ReturnCode getHostinfo(String hostname) {
36
    public ReturnCode getHostinfo(String hostname) {
33
        return antGetHostinfo(hostname, "");
37
        return antGetHostinfo(hostname, null);
34
    }
38
    }
-
 
39
 
-
 
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
 
35
 
60
 
36
    private ReturnCode antGetHostinfo(String hostname, String prefix) {
61
    private ReturnCode antGetHostinfo(String hostname, String prefix) {
37
        HostInfo info = new HostInfo();
62
        HostInfo info = new HostInfo();
38
        info.setTaskName("HostInfo");
63
        info.setTaskName("HostInfo");
39
        RunTask runner = new RunTask(info);
64
        RunTask runner = new RunTask(info);
40
        info.setHost(hostname);
65
        info.setHost(hostname);
41
        info.setPrefix(prefix);
66
        //info.setPrefix(prefix);
-
 
67
        return runner.postTask();
-
 
68
    }
-
 
69
 
-
 
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);
42
        return runner.postTask();
107
        return runner.postTask();
43
    }
108
    }
44
 
109
 
45
}
110
}