Subversion Repositories XServices

Compare Revisions

Ignore whitespace Rev 198 → Rev 199

/xservices/trunk/src/main/java/net/brutex/xservices/ws/impl/JobServiceImpl.java
26,15 → 26,7
 
import javax.jws.WebService;
 
import org.quartz.JobBuilder;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleTrigger;
import org.quartz.Trigger;
import org.quartz.TriggerKey;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.impl.matchers.GroupMatcher;
 
148,4 → 140,5
}
}
 
 
}
/xservices/trunk/src/main/java/net/brutex/xservices/ws/impl/MiscServiceImpl.java
16,27 → 16,45
 
package net.brutex.xservices.ws.impl;
 
import java.util.Enumeration;
import java.util.Properties;
import java.util.UUID;
 
import javax.jws.WebService;
import net.brutex.xservices.types.HostConnection;
import net.brutex.xservices.types.HostinfoType;
import net.brutex.xservices.types.MailMimeType;
import net.brutex.xservices.types.ReturnCode;
import net.brutex.xservices.types.RuntimeInfoType;
import net.brutex.xservices.types.*;
import net.brutex.xservices.types.alfevent.ALFEventResponseType;
import net.brutex.xservices.types.alfevent.ALFEventType;
import net.brutex.xservices.types.alfevent.ObjectFactory;
import net.brutex.xservices.types.ant.FileSetResource;
import net.brutex.xservices.util.BrutexNamespaces;
import net.brutex.xservices.util.EventEmitter;
import net.brutex.xservices.util.RunTask;
import net.brutex.xservices.ws.MiscService;
 
import org.apache.cxf.annotations.WSDLDocumentation;
import org.apache.cxf.annotations.WSDLDocumentationCollection;
import net.brutex.xservices.ws.XServicesFault;
import org.apache.tools.ant.taskdefs.HostInfo;
import org.apache.tools.ant.taskdefs.Sleep;
import org.apache.tools.ant.taskdefs.email.EmailTask;
import org.h2.jdbcx.JdbcConnectionPool;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
 
import javax.annotation.Resource;
import javax.jws.WebService;
import javax.servlet.ServletContext;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;
import java.io.StringReader;
import java.io.StringWriter;
import java.math.BigInteger;
import java.sql.*;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.Enumeration;
import java.util.Properties;
import java.util.UUID;
 
import static org.quartz.TriggerBuilder.newTrigger;
 
 
/**
* Implements the web service
*
44,10 → 62,32
*/
@WebService(targetNamespace="http://ws.xservices.brutex.net", endpointInterface="net.brutex.xservices.ws.MiscService", serviceName="MiscService")
public class MiscServiceImpl
implements MiscService
{
public HostinfoType getHostinfo(String hostname)
{
implements MiscService {
 
@Resource
private WebServiceContext context;
 
// Grab the Scheduler instance from the Factory
private final Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
private final static String conStr = "jdbc:h2:mem:lockdb;DB_CLOSE_DELAY=-1;";
 
private final static String dbinit = "" +
"CREATE SCHEMA IF NOT EXISTS brutex;" +
"CREATE TABLE IF NOT EXISTS brutex.tbl_events (" +
"btx_event_type VARCHAR(128) NOT NULL," +
"btx_id VARCHAR(32) NOT NULL, " +
"btx_obj_type VARCHAR(32) NOT NULL, " +
"btx_obj_id VARCHAR(32) NOT NULL, " +
"btx_timestamp BIGINT NOT NULL," +
"btx_event CLOB" +
");" +
"CREATE INDEX IF NOT EXISTS brutex.btx_idx ON brutex.tbl_events (btx_obj_id, btx_obj_type, btx_event_type);" +
"CREATE INDEX IF NOT EXISTS brutex.IDX_TO_DESC ON brutex.tbl_events (btx_timestamp ASC);";
 
public MiscServiceImpl() throws SchedulerException {
}
 
public HostinfoType getHostinfo(String hostname) {
HostInfo info = new HostInfo();
info.setTaskName("HostInfo");
RunTask runner = new RunTask(info);
55,10 → 95,10
 
ReturnCode ret = runner.postTask();
HostinfoType infotype = new HostinfoType(
ret.getProperty("NAME"),
ret.getProperty("DOMAIN"),
ret.getProperty("ADDR4"),
ret.getProperty("ADDR6"));
ret.getProperty("NAME"),
ret.getProperty("DOMAIN"),
ret.getProperty("ADDR4"),
ret.getProperty("ADDR6"));
return infotype;
}
 
69,11 → 109,10
Properties props = System.getProperties();
 
Enumeration e = props.propertyNames();
while (e.hasMoreElements())
{
String propName = (String)e.nextElement();
while (e.hasMoreElements()) {
String propName = (String) e.nextElement();
 
String propValue = (String)props.get(propName);
String propValue = (String) props.get(propName);
r.stdOut = (r.stdOut + propName + ": " + propValue + "\n");
}
 
80,25 → 119,22
return r;
}
 
public ReturnCode sendMailSimple(HostConnection mailhost, String from, String tolist, String subject, String message)
{
return sendMail(from, from, tolist, "", "", subject, message,
"text/plain", null, mailhost.hostname, mailhost.port,
mailhost.user, mailhost.password, "utf-8", false, false);
public ReturnCode sendMailSimple(HostConnection mailhost, String from, String tolist, String subject, String message) {
return sendMail(from, from, tolist, "", "", subject, message,
"text/plain", null, mailhost.hostname, mailhost.port,
mailhost.user, mailhost.password, "utf-8", false, false);
}
 
public ReturnCode sendMailSimpleWithAttachment(HostConnection mailhost, String from, String tolist, String subject, String message, FileSetResource res)
{
return sendMail(from, from, tolist, "", "", subject, message,
"text/plain", res, mailhost.hostname, mailhost.port,
mailhost.user, mailhost.password, "utf-8", false, false);
public ReturnCode sendMailSimpleWithAttachment(HostConnection mailhost, String from, String tolist, String subject, String message, FileSetResource res) {
return sendMail(from, from, tolist, "", "", subject, message,
"text/plain", res, mailhost.hostname, mailhost.port,
mailhost.user, mailhost.password, "utf-8", false, false);
}
 
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)
{
return sendMail(from, from, tolist, cclist, bcclist, subject, message,
mimetype.value(), res, mailhost.hostname, mailhost.port,
mailhost.user, mailhost.password, charset, tls, ssl);
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) {
return sendMail(from, from, tolist, cclist, bcclist, subject, message,
mimetype.value(), res, mailhost.hostname, mailhost.port,
mailhost.user, mailhost.password, charset, tls, ssl);
}
 
public ReturnCode sleep(int minutes, int seconds) {
109,8 → 145,7
return UUID.randomUUID().toString();
}
 
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)
{
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) {
EmailTask mail = new EmailTask();
mail.setTaskName("Mail");
RunTask runner = new RunTask(mail);
135,8 → 170,7
return runner.postTask();
}
 
private ReturnCode sleep(int hours, int minutes, int seconds, int milliseconds)
{
private ReturnCode sleep(int hours, int minutes, int seconds, int milliseconds) {
Sleep sleep = new Sleep();
sleep.setTaskName("Sleep");
RunTask runner = new RunTask(sleep);
150,4 → 184,145
public RuntimeInfoType getMemory() {
return new RuntimeInfoType();
}
 
@Override
public BigInteger lock(String id, String objectId) throws XServicesFault {
 
 
 
final String conString = "jdbc:h2:mem:lockdb;DB_CLOSE_DELAY=10;" +
"INIT=CREATE SCHEMA IF NOT EXISTS brutex\\;" +
// "SET SCHEMA brutex\\;" +
"CREATE SEQUENCE IF NOT EXISTS brutex.btx_sequence1\\;" +
"CREATE TABLE IF NOT EXISTS brutex.tbl_lock (btx_seq BIGINT NOT NULL, btx_id VARCHAR(100) NOT NULL, btx_obj_id VARCHAR(100) NOT NULL, btx_timestamp BIGINT NOT NULL);";
 
//JdbcConnectionPool cp = JdbcConnectionPool.create(conString, "sa", "");
//cp.setMaxConnections(1);
 
Connection con = null;
long rows = 0L;
final long ts = new Date().getTime();
try {
Class.forName("org.h2.Driver"); //Java 1.8
con = DriverManager.getConnection(conString);
PreparedStatement prep = con.prepareStatement(
"SELECT btx_id from brutex.tbl_lock where btx_obj_id=? ORDER BY btx_seq DESC");
prep.setString(1, objectId);
 
ResultSet rs = prep.executeQuery();
StringBuffer bf = new StringBuffer();
while (rs.next()) {
//bf.append(rs.getString(1));
rows++;
}
rs.close();
 
prep = con.prepareStatement("INSERT INTO brutex.tbl_lock values (NEXT VALUE FOR brutex.btx_sequence1, ?, ?, ?)");
prep.setString(1, id);
prep.setString(2, objectId);
prep.setLong(3, ts);
prep.execute();
 
prep = con.prepareStatement("DELETE from brutex.tbl_lock WHERE btx_timestamp < ?");
prep.setLong(1, ts - 10000);
prep.execute();
prep.close();
 
con.close();
//System.out.println(bf);
} catch (SQLException | ClassNotFoundException e) {
throw new XServicesFault(e);
}
 
return BigInteger.valueOf(rows);
}
 
@Override
public ALFEventResponseType mergeALFEvent(ALFEventType event) throws XServicesFault {
final Instant d = Instant.now();
final long ts = d.toEpochMilli();
//System.out.println("Step 1: " + ChronoUnit.MILLIS.between(Instant.now(), d));
 
final ServletContext servletContext =
(ServletContext) context.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
final JdbcConnectionPool pool = (JdbcConnectionPool) servletContext.getAttribute("dbConnection");
//System.out.println("Step 2: " + ChronoUnit.MILLIS.between(Instant.now(), d));
final ObjectFactory of = new ObjectFactory();
 
final String objectId = event.getBase().getObjectId();
final String eventId = event.getBase().getEventId();
final String objectType = event.getBase().getObjectType();
final String eventType = event.getBase().getEventType();
 
final String mergeStatememt = "MERGE INTO brutex.tbl_events " +
"KEY (btx_event_type, btx_obj_type, btx_obj_id) " +
"VALUES (?,?,?,?,?,?) " +
"";
 
long rows = 0L;
//System.out.println("Step 3: " + ChronoUnit.MILLIS.between(Instant.now(), d));
try {
//System.out.println("Step 4: " + ChronoUnit.MILLIS.between(Instant.now(), d));
Marshaller m = JAXBContext.newInstance(ALFEventType.class).createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
JAXBElement<ALFEventType> e = of.createEventNotice(event);
StringWriter sw = new StringWriter();
m.marshal(e, sw);
StringBuilder sb = new StringBuilder();
sb.append(" <soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://www.eclipse.org/alf/schema/EventBase/1\">\n");
sb.append("<soapenv:Body>\n");
sb.append("<ns:EventNotice>\n");
sb.append(sw);
sb.append("</ns:EventNotice>\n");
sb.append("</soapenv:Body>");
sb.append("</soapenv:Envelope>");
//System.out.println("Step 5: " + ChronoUnit.MILLIS.between(Instant.now(), d));
Connection con = pool.getConnection();
//System.out.println("Step 6: " + ChronoUnit.MILLIS.between(Instant.now(), d));
PreparedStatement prep = con.prepareStatement(mergeStatememt);
prep.setString(1, eventType);
prep.setString(2, eventId);
prep.setString(3, objectType);
prep.setString(4, objectId);
prep.setLong(5, ts);
prep.setClob(6, new StringReader(sb.toString()));
//prep.setLong(7, ts-20000);
//System.out.println("Step 7 SQL START: " + ChronoUnit.MILLIS.between(Instant.now(), d));
prep.execute();
con.commit();
con.close();
//System.out.println("Step 8 SQL END: " + ChronoUnit.MILLIS.between(Instant.now(), d));
//SimpleSoap ss = new SimpleSoap("http://localhost:8099/ALFEventManager/services/ALFEventManagerSOAP", sb.toString());
//ss.sendSoap(false);
 
 
// and start it off
 
if (!scheduler.isStarted())
scheduler.start();
if (scheduler.isInStandbyMode())
scheduler.resumeAll();
//System.out.println("Step 9: " + ChronoUnit.MILLIS.between(Instant.now(), d));
synchronized (scheduler) {
if (!scheduler.checkExists(JobKey.jobKey("ALFEmitter"))) {
JobDetail job2 = JobBuilder.newJob(EventEmitter.class)
.withIdentity("ALFEmitter").build();
//job2.getJobDataMap().put("script", job.getScript());
//job2.getJobDataMap().put("description", job.getDescription());
//job2.getJobDataMap().put("date", job.getDate());
 
SimpleTrigger t = (SimpleTrigger) newTrigger()
.withIdentity("ALFEmitter").startAt(Date.from(d.plusSeconds(20)))
.build();
 
scheduler.scheduleJob(job2, t);
}
}
//System.out.println("Step 10: " + ChronoUnit.MILLIS.between(Instant.now(), d));
} catch (JAXBException | SQLException | SchedulerException e) {
throw new XServicesFault(e);
}
return of.createALFEventResponseType();
}
}
/xservices/trunk/src/main/java/net/brutex/xservices/ws/impl/OpenAirProxyServiceImpl.java
30,13 → 30,13
import javax.jws.WebParam;
import javax.jws.WebService;
 
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.jcs.JCS;
import org.apache.commons.jcs.access.exception.CacheException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
 
 
import net.brutex.DocBuilder.DocBuilder;
import net.brutex.mgmt.api.generator.JITCompiler;
import net.brutex.mgmt.api.xml.AnyEntity;
60,13 → 60,10
* @author Brian Rosenberger
*
*/
@Slf4j
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.OpenAirProxyService", serviceName = OpenAirProxyService.SERVICE_NAME)
public class OpenAirProxyServiceImpl implements OpenAirProxyService {
 
/*
* Log4j2 Set Up
*/
private final Logger logger = LogManager.getLogger(OpenAirProxyServiceImpl.class);
 
/*
* (non-Javadoc)
462,7 → 459,7
final PropertiesConfiguration props;
try {
final String config = "../openair.properties";
logger.debug("Loading Open Air connection details from " + this.getClass().getClassLoader().getResource("/")
log.debug("Loading Open Air connection details from " + this.getClass().getClassLoader().getResource("/")
+ config);
 
final URL configloc = this.getClass().getClassLoader().getResource(config);
479,15 → 476,9
 
con = new OpenAirRestConnection(JCS.getInstance("OACache"), company, user, password);
return con;
} catch (CacheException e) {
logger.error(e);
} catch (CacheException | ConfigurationException | IOException e) {
log.error(e.getMessage());
e.printStackTrace();
} catch (ConfigurationException e) {
logger.error(e);
e.printStackTrace();
} catch (IOException e) {
logger.error(e);
e.printStackTrace();
} finally {
 
}
/xservices/trunk/src/main/java/net/brutex/xservices/ws/impl/XmlServiceImpl.java
32,6 → 32,7
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
 
import lombok.extern.slf4j.Slf4j;
import net.brutex.xservices.types.AttributeType;
import net.brutex.xservices.types.NamespaceListType;
import net.brutex.xservices.types.NamespaceType;
54,8 → 55,7
import org.apache.axiom.om.OMXMLBuilderFactory;
import org.apache.axiom.om.xpath.AXIOMXPath;
 
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
 
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jaxen.JaxenException;
import org.jaxen.SimpleNamespaceContext;
64,10 → 64,11
* @author Brian Rosenberger, bru(at)brutex.de
*
*/
@Slf4j
@WebService(targetNamespace = "http://ws.xservices.brutex.net", endpointInterface = "net.brutex.xservices.ws.XmlService", serviceName = "XmlService")
public class XmlServiceImpl implements XmlService {
private static final Logger logger = LogManager.getLogger();
 
 
public String insertNodesFromFile(FileResource res, NamespaceListType nsList, String xpath, String xmlFragment)
throws XServicesFault {
try {
94,7 → 95,7
XMLStreamWriter writer = xof.createXMLStreamWriter(sw);
document.serialize(writer);
 
this.logger.trace(sw.getBuffer().toString());
log.debug(sw.getBuffer().toString());
return sw.getBuffer().toString();
} catch (JaxenException e) {
e.printStackTrace();
134,7 → 135,7
XMLStreamWriter writer = xof.createXMLStreamWriter(sw);
document.serialize(writer);
 
this.logger.trace(sw.getBuffer().toString());
log.debug(sw.getBuffer().toString());
return sw.getBuffer().toString();
} catch (JaxenException e) {
e.printStackTrace();
175,7 → 176,7
XMLStreamWriter writer = xof.createXMLStreamWriter(sw);
document.serialize(writer);
 
this.logger.trace(sw.getBuffer().toString());
log.debug(sw.getBuffer().toString());
return sw.getBuffer().toString();
} catch (JaxenException e) {
e.printStackTrace();
216,7 → 217,7
XMLStreamWriter writer = xof.createXMLStreamWriter(sw);
document.serialize(writer);
 
this.logger.trace(sw.getBuffer().toString());
log.debug(sw.getBuffer().toString());
return sw.getBuffer().toString();
} catch (JaxenException e) {
e.printStackTrace();
357,8 → 358,8
List<?> olist = null;
try {
olist = axp.selectNodes(xmldocument.getOMDocumentElement());
this.logger.debug("XPath '" + axp.toString() + "' has " + olist.size() + " matches.");
this.logger.trace("XPath root expression is: '" + axp.debug() + "'.");
log.debug("XPath '" + axp.toString() + "' has " + olist.size() + " matches.");
log.debug("XPath root expression is: '" + axp.debug() + "'.");
} catch (JaxenException e) {
throw new XServicesFault(e.getMessage(), e);
}
380,26 → 381,25
match = (OMElement) o;
if ((o instanceof OMDocument))
match = ((OMDocument) o).getOMDocumentElement();
this.logger.debug(Messages.getString("XmlService.8"));
log.debug(Messages.getString("XmlService.8"));
break;
case OMNode.TEXT_NODE:
match = ((OMText) o).getParent();
this.logger.debug(Messages.getString("XmlService.9"));
log.debug(Messages.getString("XmlService.9"));
break;
case OMNode.COMMENT_NODE:
// match = node.getParent();
match = (OMContainer) node;
this.logger.debug(Messages.getString("XmlService.10"));
log.debug(Messages.getString("XmlService.10"));
break;
default:
this.logger
.error("XPath matched " + o.getClass().getCanonicalName() + " Node Type:" + node.getType());
this.logger.error(Messages.getString("XmlService.11"));
log.error("XPath matched " + o.getClass().getCanonicalName() + " Node Type:" + node.getType());
log.error(Messages.getString("XmlService.11"));
throw new XServicesFault(Messages.getString("XmlService.12"));
}
} else {
this.logger.error("XPath matched " + o.getClass().getCanonicalName());
this.logger.error(Messages.getString("XmlService.11"));
log.error("XPath matched " + o.getClass().getCanonicalName());
log.error(Messages.getString("XmlService.11"));
throw new XServicesFault(Messages.getString("XmlService.12"));
}
 
419,8 → 419,8
List<?> olist = null;
try {
olist = axp.selectNodes(xmldocument.getOMDocumentElement());
this.logger.debug("XPath '" + axp.toString() + "' has " + olist.size() + " matches.");
this.logger.trace("XPath root expression is: '" + axp.debug() + "'.");
log.debug("XPath '" + axp.toString() + "' has " + olist.size() + " matches.");
log.debug("XPath root expression is: '" + axp.debug() + "'.");
} catch (JaxenException e) {
throw new XServicesFault(e.getMessage(), e);
}
442,17 → 442,16
match = (OMElement) o;
if ((o instanceof OMDocument))
match = ((OMDocument) o).getOMDocumentElement();
this.logger.debug(Messages.getString("XmlService.8"));
log.debug(Messages.getString("XmlService.8"));
break;
default:
this.logger
.error("XPath matched " + o.getClass().getCanonicalName() + " Node Type:" + node.getType());
this.logger.error(Messages.getString("XmlService.11"));
log.error("XPath matched " + o.getClass().getCanonicalName() + " Node Type:" + node.getType());
log.error(Messages.getString("XmlService.11"));
throw new XServicesFault(Messages.getString("XmlService.12"));
}
} else {
this.logger.error("XPath matched " + o.getClass().getCanonicalName());
this.logger.error(Messages.getString("XmlService.11"));
log.error("XPath matched " + o.getClass().getCanonicalName());
log.error(Messages.getString("XmlService.11"));
throw new XServicesFault(Messages.getString("XmlService.12"));
}
 
472,11 → 471,11
if (nsList != null) {
for (NamespaceType ns : nsList.getNamespaces()) {
context.addNamespace(ns.getPrefix(), ns.getUri().toString());
this.logger.debug(
log.debug(
Messages.getString("XmlService.0") + ns.getPrefix() + "=\"" + ns.getUri().toString() + "\"'");
}
} else {
logger.debug("No namespaces defined.");
log.debug("No namespaces defined.");
}
return context;
}
490,7 → 489,7
} catch (IllegalCharsetNameException e) {
throw new XServicesFault("Endcoding '" + encoding + "' is not supported by this JRE.");
}
logger.debug("Setting source xml string encoding to '" + encoding + "'");
log.debug("Setting source xml string encoding to '" + encoding + "'");
return encoding;
}