Subversion Repositories XServices

Rev

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

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