Subversion Repositories XServices

Rev

Rev 97 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 97 Rev 114
Line 1... Line 1...
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
 *
Line 16... Line 16...
16
 
16
 
Line 17... Line 17...
17
package net.brutex.xservices.ws.impl;
17
package net.brutex.xservices.ws.impl;
18
 
18
 
-
 
19
import java.util.Enumeration;
Line 19... Line 20...
19
import java.util.Enumeration;
20
import java.util.Properties;
20
import java.util.Properties;
-
 
21
 
21
import java.util.UUID;
-
 
22
 
22
import javax.jws.WebService;
23
import javax.jws.WebService;
23
import net.brutex.xservices.types.FileSetResource;
24
import net.brutex.xservices.types.HostConnection;
-
 
25
import net.brutex.xservices.types.HostinfoType;
-
 
26
import net.brutex.xservices.types.MailMimeType;
24
import net.brutex.xservices.types.HostConnection;
27
import net.brutex.xservices.types.ReturnCode;
25
import net.brutex.xservices.types.MailMimeType;
28
import net.brutex.xservices.types.RuntimeInfoType;
26
import net.brutex.xservices.types.ReturnCode;
29
import net.brutex.xservices.types.ant.FileSetResource;
Line 27... Line 30...
27
import net.brutex.xservices.util.BrutexNamespaces;
30
import net.brutex.xservices.util.BrutexNamespaces;
Line 33... Line 36...
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;
Line 36... Line 39...
36
 
39
 
-
 
40
/**
37
/**
41
 * Implements the web service
38
 * 
42
 * 
39
 * @author Brian Rosenberger, bru@brutex.de
43
 * @author Brian Rosenberger, bru@brutex.de
-
 
44
 */
40
 */
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"
-
 
49
			)
53
    RunTask runner = new RunTask(info);
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();
-
 
57
    HostinfoType infotype = new HostinfoType(
-
 
58
      ret.getProperty("NAME"), 
-
 
59
      ret.getProperty("DOMAIN"), 
53
	public ReturnCode getHostinfo(String hostname) {
60
      ret.getProperty("ADDR4"), 
-
 
61
      ret.getProperty("ADDR6"));
54
		return antGetHostinfo(hostname, null);
62
    return infotype;
Line 55... Line -...
55
	}
-
 
56
	
63
  }
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;
Line 61... Line -...
61
		// Get all system properties
-
 
62
		Properties props = System.getProperties();
68
 
63
 
69
    Properties props = System.getProperties();
64
		// Enumerate all system properties
70
 
65
		Enumeration<String> e = (Enumeration<String>) props.propertyNames();
71
    Enumeration e = props.propertyNames();
Line 66... Line -...
66
		for (; e.hasMoreElements(); ) {
-
 
67
		    // Get property name
72
    while (e.hasMoreElements())
68
		    String propName = (String)e.nextElement();
73
    {
69
 
74
      String propName = (String)e.nextElement();
Line 70... Line 75...
70
		    // Get property value
75
 
71
		    String propValue = (String)props.get(propName);
76
      String propValue = (String)props.get(propName);
Line 72... Line -...
72
		    r.stdOut = r.stdOut + propName + ": " + propValue + "\n";
-
 
73
		}
77
      r.stdOut = (r.stdOut + propName + ": " + propValue + "\n");
74
 
-
 
-
 
78
    }
75
		return r;
79
 
76
	}
80
    return r;
77
 
81
  }
78
 
82
 
Line 79... Line 83...
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) {
-
 
81
		return sendMail(from, from, tolist, "", "", subject, message,
84
  {
82
				"text/plain", null, mailhost.hostname, mailhost.port,
85
    return sendMail(from, from, tolist, "", "", subject, message, 
83
				mailhost.user, mailhost.password, "utf-8", false, false);
86
      "text/plain", null, mailhost.hostname, mailhost.port, 
84
	}
87
      mailhost.user, mailhost.password, "utf-8", false, false);
85
 
88
  }
Line 86... Line 89...
86
	public ReturnCode sendMailSimpleWithAttachment(HostConnection mailhost,
89
 
87
			String from, String tolist, String subject, String message,
-
 
88
			FileSetResource res) {
-
 
89
		return sendMail(from, from, tolist, "", "", subject, message,
-
 
-
 
90
  public ReturnCode sendMailSimpleWithAttachment(HostConnection mailhost, String from, String tolist, String subject, String message, FileSetResource res)
90
				"text/plain", res, mailhost.hostname, mailhost.port,
91
  {
91
				mailhost.user, mailhost.password, "utf-8", false, false);
92
    return sendMail(from, from, tolist, "", "", subject, message, 
92
	}
93
      "text/plain", res, mailhost.hostname, mailhost.port, 
93
 
94
      mailhost.user, mailhost.password, "utf-8", false, false);
Line 94... Line 95...
94
	public ReturnCode sendMail(HostConnection mailhost, String from,
95
  }
95
			String tolist, String cclist, String bcclist, String subject,
96
 
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)
Line 97... Line -...
97
			FileSetResource res, boolean ssl, boolean tls) {
-
 
98
		return sendMail(from, from, tolist, cclist, bcclist, subject, message,
98
  {
99
				mimetype.value(), res, mailhost.hostname, mailhost.port,
-
 
100
				mailhost.user, mailhost.password, charset, tls, ssl);
-
 
101
	}
-
 
102
 
-
 
103
	public ReturnCode sleep(int minutes, int seconds) {
99
    return sendMail(from, from, tolist, cclist, bcclist, subject, message, 
104
		return sleep(0, minutes, seconds, 0);
100
      mimetype.value(), res, mailhost.hostname, mailhost.port, 
Line 105... Line 101...
105
	}
101
      mailhost.user, mailhost.password, charset, tls, ssl);
106
 
-
 
107
	private ReturnCode antGetHostinfo(String hostname, String prefix) {
-
 
108
		HostInfo info = new HostInfo();
-
 
109
		info.setTaskName("HostInfo");
-
 
-
 
102
  }
110
		RunTask runner = new RunTask(info);
103
 
111
		info.setHost(hostname);
104
  public ReturnCode sleep(int minutes, int seconds) {
112
		// info.setPrefix(prefix);
105
    return sleep(0, minutes, seconds, 0);
113
		return runner.postTask();
106
  }
114
	}
107
 
Line 140... Line 133...
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
  }
Line 144... Line 137...
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();
-
 
148
  }
-
 
149
 
-
 
150
  public RuntimeInfoType getMemory() {
-
 
151
    return new RuntimeInfoType();
155
	}
152
  }