Arbeitsstand Ende Januar 2013

git-svn-id: https://brutex.net/svn/xservices/trunk@97 e7e49efb-446e-492e-b9ec-fcafc1997a86
tag-20130205r
Brian Rosenberger 2013-01-31 16:04:41 +00:00
parent ca7b048885
commit c09098ce11
4 changed files with 108 additions and 160 deletions

View File

@ -18,44 +18,48 @@ package net.brutex.xservices.ws.impl;
import java.math.BigInteger; import java.math.BigInteger;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.List;
import java.util.TimeZone; import java.util.TimeZone;
import javax.jws.WebService; import javax.jws.WebService;
import net.brutex.xservices.types.DateFormatType; import net.brutex.xservices.types.DateFormatType;
import net.brutex.xservices.types.DateInfoExtendedType;
import net.brutex.xservices.types.DateInfoType;
import net.brutex.xservices.types.DateTimeUnits; import net.brutex.xservices.types.DateTimeUnits;
import net.brutex.xservices.types.TimeZoneType;
import net.brutex.xservices.util.BrutexNamespaces; import net.brutex.xservices.util.BrutexNamespaces;
import net.brutex.xservices.ws.DateService; import net.brutex.xservices.ws.DateService;
import net.brutex.xservices.ws.XServicesFault; import net.brutex.xservices.ws.XServicesFault;
/** /**
* @author Brian Rosenberger * @author Brian Rosenberger
* *
*/ */
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.DateService", serviceName = DateService.SERVICE_NAME) @WebService(
targetNamespace = BrutexNamespaces.WS_XSERVICES,
endpointInterface = "net.brutex.xservices.ws.DateService",
serviceName = DateService.SERVICE_NAME
)
public class DateServiceImpl implements DateService { public class DateServiceImpl implements DateService {
private static String ERR_INVALIDFORMAT = "Invalid format pattern."; private static String ERR_INVALIDFORMAT = "Invalid format pattern.";
private static String ERR_INVALIDTIMEZONE = "Invalid timezone."; private static String ERR_INVALIDTIMEZONE = "Invalid timezone.";
public DateInfoType getDate() throws XServicesFault { public GregorianCalendar getDate(String timezone) throws XServicesFault {
GregorianCalendar c = new GregorianCalendar(); if (! isValidTimezone(timezone) ) {
DateInfoType dateinfo = new DateInfoType(c, TimeZone.getDefault()); String valid_ids = "";
return dateinfo; String[] tid = TimeZone.getAvailableIDs();
for (String s : tid) {
valid_ids += s + "\n";
}
throw new XServicesFault("Please supply a valid timezone id or none. Valid timezones are:\n" + valid_ids,
new Exception( ));
}
if (timezone == null || timezone.length()<1 ) timezone = "GMT0";
GregorianCalendar c = new GregorianCalendar(TimeZone.getTimeZone(timezone));
return c;
} }
public DateInfoExtendedType getDateExtended() throws XServicesFault {
GregorianCalendar c = new GregorianCalendar();
DateInfoExtendedType dateinfo = new DateInfoExtendedType(c,
TimeZone.getDefault());
return dateinfo;
}
public BigInteger getTimestamp() { public BigInteger getTimestamp() {
Date d = new Date(); Date d = new Date();
@ -69,49 +73,44 @@ public class DateServiceImpl implements DateService {
return new BigInteger(Long.toString(l)); return new BigInteger(Long.toString(l));
} }
public String getInTimezone(Date date, String timezone)
throws XServicesFault { public GregorianCalendar getInTimezone(GregorianCalendar cal,
if (!isValidTimezone(timezone)) String timezone) throws XServicesFault {
throw new XServicesFault(ERR_INVALIDTIMEZONE); if(! isValidTimezone(timezone)) throw new XServicesFault(ERR_INVALIDTIMEZONE);
TimeZone targetzone = TimeZone.getTimeZone(timezone); GregorianCalendar c = new GregorianCalendar(TimeZone.getTimeZone(timezone));
String targetstring = DateFormatType.ISO8601.format(date, null, targetzone); c.setTimeInMillis(cal.getTimeInMillis());
return targetstring; return c;
} }
public String formatDate(Date cal, DateFormatType format)
throws XServicesFault { public String formatDate(GregorianCalendar cal, DateFormatType format) throws XServicesFault {
return format.format(cal, null, null); return formatDateAdvanced(cal, format.format());
} }
public String formatDateAdvanced(Date cal, String format)
public String formatDateAdvanced(GregorianCalendar cal, String format)
throws XServicesFault { throws XServicesFault {
String result= null; String result= null;
try {
SimpleDateFormat f = new SimpleDateFormat(format); SimpleDateFormat f = new SimpleDateFormat(format);
result = f.format(cal); result = f.format(cal.getTime());
} catch (IllegalArgumentException e) {
throw new XServicesFault(ERR_INVALIDFORMAT + e.getMessage());
}
return result; return result;
} }
public Date parseDate(String s, DateFormatType format, String timezone)
throws XServicesFault { public GregorianCalendar parseDate(String s, DateFormatType format, String timezone) throws XServicesFault {
if (timezone == null | timezone.equals("")) return parseDateAdvanced(s, format.format(), timezone);
timezone = TimeZone.getDefault().getID();
if (!isValidTimezone(timezone))
throw new XServicesFault(ERR_INVALIDTIMEZONE);
try {
return format.parse(s, null, TimeZone.getTimeZone(timezone));
} catch (ParseException e) {
throw new XServicesFault(e);
}
} }
public GregorianCalendar parseDateAdvanced(String s, String format,
String timezone) throws XServicesFault { public GregorianCalendar parseDateAdvanced(String s, String format, String timezone) throws XServicesFault {
SimpleDateFormat f = null; SimpleDateFormat f = null;
Date date = null; Date date = null;
if (timezone == null | timezone.equals("")) if(timezone==null | timezone.equals("")) timezone = TimeZone.getDefault().getID();
timezone = TimeZone.getDefault().getID(); if(! isValidTimezone(timezone)) throw new XServicesFault(ERR_INVALIDTIMEZONE);
if (!isValidTimezone(timezone))
throw new XServicesFault(ERR_INVALIDTIMEZONE);
try { try {
f = new SimpleDateFormat(format); f = new SimpleDateFormat(format);
@ -127,15 +126,17 @@ public class DateServiceImpl implements DateService {
return cal; return cal;
} }
public BigInteger dateTimeDiff(Date fromCal, Date toCal)
throws XServicesFault { public BigInteger dateTimeDiff(GregorianCalendar fromCal,
long diff = toCal.getTime() - fromCal.getTime(); GregorianCalendar toCal) throws XServicesFault {
long diff = toCal.getTimeInMillis() - fromCal.getTimeInMillis();
BigInteger d = new BigInteger(String.valueOf(diff), 10); BigInteger d = new BigInteger(String.valueOf(diff), 10);
return d; return d;
} }
public BigInteger dateTimeDiff2(Date fromCal, Date toCal, DateTimeUnits unit)
throws XServicesFault { public BigInteger dateTimeDiff2(GregorianCalendar fromCal,
GregorianCalendar toCal, DateTimeUnits unit) throws XServicesFault {
BigInteger d = dateTimeDiff(fromCal, toCal); BigInteger d = dateTimeDiff(fromCal, toCal);
switch (unit) { switch (unit) {
case SECONDS: case SECONDS:
@ -149,16 +150,13 @@ public class DateServiceImpl implements DateService {
break; break;
case DAYS: case DAYS:
d = d.divide(new BigInteger("86400000")); d = d.divide(new BigInteger("86400000"));
break;
case YEARS:
d = d.divide(new BigInteger("31536000000"));
break;
} }
return d; return d;
} }
public GregorianCalendar dateAdd(GregorianCalendar cal, BigInteger value,
DateTimeUnits unit) throws XServicesFault { public GregorianCalendar dateAdd(GregorianCalendar cal, BigInteger value, DateTimeUnits unit)
throws XServicesFault {
switch (unit) { switch (unit) {
case SECONDS: case SECONDS:
cal.add(GregorianCalendar.SECOND, value.intValue()); cal.add(GregorianCalendar.SECOND, value.intValue());
@ -172,9 +170,6 @@ public class DateServiceImpl implements DateService {
case DAYS: case DAYS:
cal.add(GregorianCalendar.DAY_OF_MONTH, value.intValue()); cal.add(GregorianCalendar.DAY_OF_MONTH, value.intValue());
break; break;
case YEARS:
cal.add(GregorianCalendar.YEAR, value.intValue());
break;
default: default:
cal.add(GregorianCalendar.MILLISECOND, value.intValue()); cal.add(GregorianCalendar.MILLISECOND, value.intValue());
} }
@ -192,11 +187,4 @@ public class DateServiceImpl implements DateService {
return yes; return yes;
} }
public List<TimeZoneType> getTimezones() {
List<TimeZoneType> output = new ArrayList<TimeZoneType>();
for (String s : TimeZone.getAvailableIDs()) {
output.add(new TimeZoneType(TimeZone.getTimeZone(s)));
}
return output;
}
} }

View File

@ -13,11 +13,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package net.brutex.xservices.ws.impl; package net.brutex.xservices.ws.impl;
import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -30,12 +27,12 @@ import javax.jws.WebMethod;
import javax.jws.WebParam; import javax.jws.WebParam;
import javax.jws.WebService; import javax.jws.WebService;
import net.brutex.xservices.types.ArchiveResource;
import net.brutex.xservices.types.AttachmentType;
import net.brutex.xservices.types.FileResource;
import net.brutex.xservices.types.FileSetResource;
import net.brutex.xservices.types.ReplacePattern; import net.brutex.xservices.types.ReplacePattern;
import net.brutex.xservices.types.ReturnCode; import net.brutex.xservices.types.ReturnCode;
import net.brutex.xservices.types.ant.ArchiveResource;
import net.brutex.xservices.types.ant.AttachmentType;
import net.brutex.xservices.types.ant.FileResource;
import net.brutex.xservices.types.ant.FileSetResource;
import net.brutex.xservices.util.BrutexNamespaces; import net.brutex.xservices.util.BrutexNamespaces;
import net.brutex.xservices.util.RunTask; import net.brutex.xservices.util.RunTask;
import net.brutex.xservices.ws.FileService; import net.brutex.xservices.ws.FileService;
@ -159,26 +156,6 @@ public class FileServiceImpl implements FileService {
} }
} }
public byte[] encodeFile(FileResource res) throws XServicesFault {
InputStream is = null;
try {
is = res.getAntResource(null).getInputStream();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[4096];
while ((nRead = is.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
buffer.flush();
return buffer.toByteArray();
} catch (IOException e) {
throw new XServicesFault(e);
}
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012 Brian Rosenberger (Brutex Network) * Copyright 2011 Brian Rosenberger (Brutex Network)
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -15,6 +15,7 @@
*/ */
package net.brutex.xservices.ws.impl; package net.brutex.xservices.ws.impl;
import static org.quartz.TriggerBuilder.newTrigger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
@ -36,9 +37,8 @@ import org.quartz.Trigger;
import org.quartz.TriggerKey; import org.quartz.TriggerKey;
import org.quartz.impl.StdSchedulerFactory; import org.quartz.impl.StdSchedulerFactory;
import org.quartz.impl.matchers.GroupMatcher; import org.quartz.impl.matchers.GroupMatcher;
import static org.quartz.TriggerBuilder.*;
import net.brutex.xservices.types.ScheduledJob; import net.brutex.xservices.types.ScheduledJob;
import net.brutex.xservices.types.SchedulerStatisticsType;
import net.brutex.xservices.util.BrutexNamespaces; import net.brutex.xservices.util.BrutexNamespaces;
import net.brutex.xservices.util.JobWrapper; import net.brutex.xservices.util.JobWrapper;
import net.brutex.xservices.ws.JobService; import net.brutex.xservices.ws.JobService;
@ -148,14 +148,4 @@ public class JobServiceImpl implements JobService {
} }
} }
public SchedulerStatisticsType getStatistics() throws XServicesFault {
try {
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
return new SchedulerStatisticsType(scheduler);
} catch (SchedulerException e) {
throw new XServicesFault(e);
}
}
} }

View File

@ -18,15 +18,12 @@ package net.brutex.xservices.ws.impl;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Properties; import java.util.Properties;
import java.util.UUID;
import javax.jws.WebService; import javax.jws.WebService;
import net.brutex.xservices.types.FileSetResource;
import net.brutex.xservices.types.HostConnection; import net.brutex.xservices.types.HostConnection;
import net.brutex.xservices.types.HostinfoType;
import net.brutex.xservices.types.MailMimeType; import net.brutex.xservices.types.MailMimeType;
import net.brutex.xservices.types.ReturnCode; import net.brutex.xservices.types.ReturnCode;
import net.brutex.xservices.types.RuntimeInfoType;
import net.brutex.xservices.types.ant.FileSetResource;
import net.brutex.xservices.util.BrutexNamespaces; import net.brutex.xservices.util.BrutexNamespaces;
import net.brutex.xservices.util.RunTask; import net.brutex.xservices.util.RunTask;
import net.brutex.xservices.ws.MiscService; import net.brutex.xservices.ws.MiscService;
@ -38,31 +35,26 @@ import org.apache.tools.ant.taskdefs.Sleep;
import org.apache.tools.ant.taskdefs.email.EmailTask; import org.apache.tools.ant.taskdefs.email.EmailTask;
/** /**
* Implements the web service
* *
* @author Brian Rosenberger, bru@brutex.de * @author Brian Rosenberger, bru@brutex.de
*/ */
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, @WSDLDocumentationCollection({
@WSDLDocumentation("My portType documentation"),
@WSDLDocumentation(value = "My top level documentation", placement = WSDLDocumentation.Placement.TOP),
@WSDLDocumentation(value = "My binding doc", placement = WSDLDocumentation.Placement.BINDING) })
@WebService(
targetNamespace = BrutexNamespaces.WS_XSERVICES,
endpointInterface = "net.brutex.xservices.ws.MiscService", endpointInterface = "net.brutex.xservices.ws.MiscService",
serviceName = "MiscService") serviceName = "MiscService"
)
public class MiscServiceImpl implements MiscService { public class MiscServiceImpl implements MiscService {
public HostinfoType getHostinfo(String hostname) { @WSDLDocumentation(value = "Get information about a host.")
HostInfo info = new HostInfo(); public ReturnCode getHostinfo(String hostname) {
info.setTaskName("HostInfo"); return antGetHostinfo(hostname, null);
RunTask runner = new RunTask(info);
info.setHost(hostname);
// info.setPrefix(prefix);
// TODO: Does not work for IP Addresses?
ReturnCode ret = runner.postTask();
HostinfoType infotype = new HostinfoType(
ret.getProperty("NAME"),
ret.getProperty("DOMAIN"),
ret.getProperty("ADDR4"),
ret.getProperty("ADDR6"));
return infotype;
} }
@WSDLDocumentation(value = "Get XService information.")
public ReturnCode getInfo() { public ReturnCode getInfo() {
ReturnCode r = new ReturnCode(); ReturnCode r = new ReturnCode();
r.returnCode = 0; r.returnCode = 0;
@ -70,7 +62,6 @@ public class MiscServiceImpl implements MiscService {
Properties props = System.getProperties(); Properties props = System.getProperties();
// Enumerate all system properties // Enumerate all system properties
@SuppressWarnings("unchecked")
Enumeration<String> e = (Enumeration<String>) props.propertyNames(); Enumeration<String> e = (Enumeration<String>) props.propertyNames();
for (; e.hasMoreElements(); ) { for (; e.hasMoreElements(); ) {
// Get property name // Get property name
@ -84,6 +75,7 @@ public class MiscServiceImpl implements MiscService {
return r; return r;
} }
public ReturnCode sendMailSimple(HostConnection mailhost, String from, public ReturnCode sendMailSimple(HostConnection mailhost, String from,
String tolist, String subject, String message) { String tolist, String subject, String message) {
return sendMail(from, from, tolist, "", "", subject, message, return sendMail(from, from, tolist, "", "", subject, message,
@ -112,8 +104,13 @@ public class MiscServiceImpl implements MiscService {
return sleep(0, minutes, seconds, 0); return sleep(0, minutes, seconds, 0);
} }
public String generateUUID() { private ReturnCode antGetHostinfo(String hostname, String prefix) {
return UUID.randomUUID().toString(); HostInfo info = new HostInfo();
info.setTaskName("HostInfo");
RunTask runner = new RunTask(info);
info.setHost(hostname);
// info.setPrefix(prefix);
return runner.postTask();
} }
private ReturnCode sendMail(String from, String replyto, String tolist, private ReturnCode sendMail(String from, String replyto, String tolist,
@ -156,8 +153,4 @@ public class MiscServiceImpl implements MiscService {
sleep.setMilliseconds(milliseconds); sleep.setMilliseconds(milliseconds);
return runner.postTask(); return runner.postTask();
} }
public RuntimeInfoType getMemory() {
return new RuntimeInfoType();
}
} }