Subversion Repositories XServices

Rev

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

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