Subversion Repositories XServices

Rev

Rev 22 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
16 brianR 1
/*
2
 *   Copyright 2010 Brian Rosenberger (Brutex Network)
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (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
7
 *
8
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
15
 */
16
 
17
package net.brutex.xservices.ws;
18
 
19
import javax.jws.WebService;
18 brianR 20
import net.brutex.xservices.types.FileSetResource;
21
import net.brutex.xservices.types.HostConnection;
22 brianR 22
import net.brutex.xservices.types.MailMimeType;
16 brianR 23
import net.brutex.xservices.types.ReturnCode;
17 brianR 24
import net.brutex.xservices.util.RunTask;
23 brianR 25
import org.apache.cxf.annotations.WSDLDocumentation;
26
import org.apache.cxf.annotations.WSDLDocumentationCollection;
17 brianR 27
import org.apache.tools.ant.taskdefs.HostInfo;
20 brianR 28
import org.apache.tools.ant.taskdefs.Sleep;
18 brianR 29
import org.apache.tools.ant.taskdefs.email.EmailTask;
16 brianR 30
 
31
/**
32
 *
33
 * @author Brian Rosenberger, bru@brutex.de
34
 */
23 brianR 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
)
16 brianR 44
@WebService(endpointInterface="net.brutex.xservices.ws.MiscService",
45
serviceName="MiscService")
46
public class MiscServiceImpl implements MiscService {
47
 
23 brianR 48
    @WSDLDocumentation(value="Get information about a host.")
16 brianR 49
    public ReturnCode getHostinfo(String hostname) {
18 brianR 50
        return antGetHostinfo(hostname, null);
16 brianR 51
    }
52
 
18 brianR 53
    public ReturnCode sendMailSimple(HostConnection mailhost, String from, String tolist, String subject, String message) {
54
        return sendMail(from,
55
                from,
56
                tolist,
57
                "",
58
                "",
59
                subject,
60
                message,
61
                "text/plain",
62
                null,
63
                mailhost.hostname,
64
                mailhost.port,
65
                mailhost.user,
66
                mailhost.password,
67
                "utf-8",
68
                false,
69
                false);
70
    }
71
 
21 brianR 72
    public ReturnCode sendMailSimpleWithAttachment(HostConnection mailhost, String from,
73
            String tolist, String subject, String message,
74
            FileSetResource res) {
75
        return  sendMail(from,
76
                from,
77
                tolist,
78
                "",
79
                "",
80
                subject,
81
                message,
82
                "text/plain",
83
                res,
84
                mailhost.hostname,
85
                mailhost.port,
86
                mailhost.user,
87
                mailhost.password,
88
                "utf-8",
89
                false,
90
                false);
91
    }
92
 
22 brianR 93
    public ReturnCode sendMail(HostConnection mailhost, String from, String tolist,
94
            String cclist, String bcclist, String subject,
95
            MailMimeType mimetype, String charset, String message,
96
            FileSetResource res, boolean ssl, boolean tls) {
97
         return  sendMail(from,
98
                from,
99
                tolist,
100
                cclist,
101
                bcclist,
102
                subject,
103
                message,
104
                mimetype.value(),
105
                res,
106
                mailhost.hostname,
107
                mailhost.port,
108
                mailhost.user,
109
                mailhost.password,
110
                charset,
111
                tls,
112
                ssl);
113
    }
21 brianR 114
 
115
 
22 brianR 116
 
117
 
118
 
20 brianR 119
    public ReturnCode sleep(int minutes, int seconds) {
120
        return sleep(0, minutes, seconds, 0);
121
    }
18 brianR 122
 
123
 
20 brianR 124
 
17 brianR 125
    private ReturnCode antGetHostinfo(String hostname, String prefix) {
126
        HostInfo info = new HostInfo();
127
        info.setTaskName("HostInfo");
128
        RunTask runner = new RunTask(info);
129
        info.setHost(hostname);
18 brianR 130
        //info.setPrefix(prefix);
17 brianR 131
        return runner.postTask();
16 brianR 132
    }
133
 
18 brianR 134
    private ReturnCode sendMail(String from,
135
            String replyto,
136
            String tolist,
137
            String cclist,
138
            String bcclist,
139
            String subject,
140
            String message,
141
            String messagemimetype,
142
            FileSetResource attachments,
143
            String mailhost,
144
            int mailport,
145
            String user,
146
            String password,
147
            String charset,
148
            boolean tls,
149
            boolean ssl) {
150
        EmailTask mail = new EmailTask();
151
        mail.setTaskName("Mail");
152
        RunTask runner = new RunTask(mail);
153
        mail.setFrom(from);
154
        mail.setReplyTo(replyto);
155
        mail.setToList(tolist);
156
        mail.setCcList(cclist);
157
        mail.setBccList(bcclist);
158
        mail.setSubject(subject);
159
        mail.setMessage(message);
160
        mail.setMessageMimeType(messagemimetype);
161
        if(attachments != null) {
162
            mail.addFileset(attachments.getAntFileSet(mail.getProject()));
163
        }
164
        mail.setMailhost(mailhost);
165
        mail.setMailport(mailport);
166
        mail.setUser(user);
167
        mail.setPassword(password);
168
        mail.setCharset(charset);
169
        mail.setSSL(ssl);
170
        mail.setEnableStartTLS(tls);
171
        return runner.postTask();
172
    }
173
 
20 brianR 174
    private ReturnCode sleep(int hours, int minutes, int seconds, int milliseconds) {
175
        Sleep sleep = new Sleep();
176
        sleep.setTaskName("Sleep");
177
        RunTask runner = new RunTask(sleep);
178
        sleep.setHours(hours);
179
        sleep.setMinutes(minutes);
180
        sleep.setSeconds(seconds);
181
        sleep.setMilliseconds(milliseconds);
182
        return runner.postTask();
183
    }
184
 
16 brianR 185
}