Subversion Repositories XServices

Rev

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

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