Subversion Repositories XServices

Rev

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

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