Subversion Repositories XServices

Rev

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

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