Subversion Repositories XServices

Rev

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

Rev Author Line No. Line
16 brianR 1
/*
114 brianR 2
 *   Copyright 2013 Brian Rosenberger (Brutex Network)
16 brianR 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
 
46 brianR 17
package net.brutex.xservices.ws.impl;
16 brianR 18
 
54 brianR 19
import java.util.Enumeration;
20
import java.util.Properties;
114 brianR 21
import java.util.UUID;
54 brianR 22
 
16 brianR 23
import javax.jws.WebService;
18 brianR 24
import net.brutex.xservices.types.HostConnection;
114 brianR 25
import net.brutex.xservices.types.HostinfoType;
22 brianR 26
import net.brutex.xservices.types.MailMimeType;
16 brianR 27
import net.brutex.xservices.types.ReturnCode;
114 brianR 28
import net.brutex.xservices.types.RuntimeInfoType;
29
import net.brutex.xservices.types.ant.FileSetResource;
46 brianR 30
import net.brutex.xservices.util.BrutexNamespaces;
17 brianR 31
import net.brutex.xservices.util.RunTask;
46 brianR 32
import net.brutex.xservices.ws.MiscService;
33
 
23 brianR 34
import org.apache.cxf.annotations.WSDLDocumentation;
35
import org.apache.cxf.annotations.WSDLDocumentationCollection;
17 brianR 36
import org.apache.tools.ant.taskdefs.HostInfo;
20 brianR 37
import org.apache.tools.ant.taskdefs.Sleep;
18 brianR 38
import org.apache.tools.ant.taskdefs.email.EmailTask;
16 brianR 39
 
40
/**
114 brianR 41
 * Implements the web service
46 brianR 42
 *
16 brianR 43
 * @author Brian Rosenberger, bru@brutex.de
44
 */
114 brianR 45
@WebService(targetNamespace="http://ws.xservices.brutex.net", endpointInterface="net.brutex.xservices.ws.MiscService", serviceName="MiscService")
46
public class MiscServiceImpl
47
  implements MiscService
48
{
49
  public HostinfoType getHostinfo(String hostname)
50
  {
51
    HostInfo info = new HostInfo();
52
    info.setTaskName("HostInfo");
53
    RunTask runner = new RunTask(info);
54
    info.setHost(hostname);
16 brianR 55
 
114 brianR 56
    ReturnCode ret = runner.postTask();
57
    HostinfoType infotype = new HostinfoType(
58
      ret.getProperty("NAME"),
59
      ret.getProperty("DOMAIN"),
60
      ret.getProperty("ADDR4"),
61
      ret.getProperty("ADDR6"));
62
    return infotype;
63
  }
16 brianR 64
 
114 brianR 65
  public ReturnCode getInfo() {
66
    ReturnCode r = new ReturnCode();
67
    r.returnCode = 0;
54 brianR 68
 
114 brianR 69
    Properties props = System.getProperties();
54 brianR 70
 
114 brianR 71
    Enumeration e = props.propertyNames();
72
    while (e.hasMoreElements())
73
    {
74
      String propName = (String)e.nextElement();
54 brianR 75
 
114 brianR 76
      String propValue = (String)props.get(propName);
77
      r.stdOut = (r.stdOut + propName + ": " + propValue + "\n");
78
    }
97 brianR 79
 
114 brianR 80
    return r;
81
  }
18 brianR 82
 
114 brianR 83
  public ReturnCode sendMailSimple(HostConnection mailhost, String from, String tolist, String subject, String message)
84
  {
85
    return sendMail(from, from, tolist, "", "", subject, message,
86
      "text/plain", null, mailhost.hostname, mailhost.port,
87
      mailhost.user, mailhost.password, "utf-8", false, false);
88
  }
21 brianR 89
 
114 brianR 90
  public ReturnCode sendMailSimpleWithAttachment(HostConnection mailhost, String from, String tolist, String subject, String message, FileSetResource res)
91
  {
92
    return sendMail(from, from, tolist, "", "", subject, message,
93
      "text/plain", res, mailhost.hostname, mailhost.port,
94
      mailhost.user, mailhost.password, "utf-8", false, false);
95
  }
21 brianR 96
 
114 brianR 97
  public ReturnCode sendMail(HostConnection mailhost, String from, String tolist, String cclist, String bcclist, String subject, MailMimeType mimetype, String charset, String message, FileSetResource res, boolean ssl, boolean tls)
98
  {
99
    return sendMail(from, from, tolist, cclist, bcclist, subject, message,
100
      mimetype.value(), res, mailhost.hostname, mailhost.port,
101
      mailhost.user, mailhost.password, charset, tls, ssl);
102
  }
21 brianR 103
 
114 brianR 104
  public ReturnCode sleep(int minutes, int seconds) {
105
    return sleep(0, minutes, seconds, 0);
106
  }
22 brianR 107
 
114 brianR 108
  public String generateUUID() {
109
    return UUID.randomUUID().toString();
110
  }
22 brianR 111
 
114 brianR 112
  private ReturnCode sendMail(String from, String replyto, String tolist, String cclist, String bcclist, String subject, String message, String messagemimetype, FileSetResource attachments, String mailhost, int mailport, String user, String password, String charset, boolean tls, boolean ssl)
113
  {
114
    EmailTask mail = new EmailTask();
115
    mail.setTaskName("Mail");
116
    RunTask runner = new RunTask(mail);
117
    mail.setFrom(from);
118
    mail.setReplyTo(replyto);
119
    mail.setToList(tolist);
120
    mail.setCcList(cclist);
121
    mail.setBccList(bcclist);
122
    mail.setSubject(subject);
123
    mail.setMessage(message);
124
    mail.setMessageMimeType(messagemimetype);
125
    if (attachments != null) {
126
      mail.addFileset(attachments.getAntResource(mail.getProject()));
127
    }
128
    mail.setMailhost(mailhost);
129
    mail.setMailport(mailport);
130
    mail.setUser(user);
131
    mail.setPassword(password);
132
    mail.setCharset(charset);
133
    mail.setSSL(ssl);
134
    mail.setEnableStartTLS(tls);
135
    return runner.postTask();
136
  }
137
 
138
  private ReturnCode sleep(int hours, int minutes, int seconds, int milliseconds)
139
  {
140
    Sleep sleep = new Sleep();
141
    sleep.setTaskName("Sleep");
142
    RunTask runner = new RunTask(sleep);
143
    sleep.setHours(hours);
144
    sleep.setMinutes(minutes);
145
    sleep.setSeconds(seconds);
146
    sleep.setMilliseconds(milliseconds);
147
    return runner.postTask();
148
  }
149
 
150
  public RuntimeInfoType getMemory() {
151
    return new RuntimeInfoType();
152
  }
153
}