1 |
/*
|
1 |
/*
|
2 |
* Copyright 2013 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 lombok.extern.slf4j.Slf4j;
|
19 |
import lombok.extern.slf4j.Slf4j;
|
20 |
import net.brutex.xservices.types.*;
|
20 |
import net.brutex.xservices.types.*;
|
21 |
import net.brutex.xservices.types.alfevent.ALFEventResponseType;
|
21 |
import net.brutex.xservices.types.alfevent.ALFEventResponseType;
|
22 |
import net.brutex.xservices.types.alfevent.ALFEventType;
|
22 |
import net.brutex.xservices.types.alfevent.ALFEventType;
|
23 |
import net.brutex.xservices.types.alfevent.ObjectFactory;
|
23 |
import net.brutex.xservices.types.alfevent.ObjectFactory;
|
24 |
import net.brutex.xservices.types.ant.FileSetResource;
|
24 |
import net.brutex.xservices.types.ant.FileSetResource;
|
25 |
import net.brutex.xservices.util.EventEmitter;
|
25 |
import net.brutex.xservices.util.EventEmitter;
|
26 |
import net.brutex.xservices.util.EventmanagerConfiguration;
|
26 |
import net.brutex.xservices.util.EventmanagerConfiguration;
|
27 |
import net.brutex.xservices.util.RunTask;
|
27 |
import net.brutex.xservices.util.RunTask;
|
28 |
import net.brutex.xservices.ws.MiscService;
|
28 |
import net.brutex.xservices.ws.MiscService;
|
29 |
import net.brutex.xservices.ws.XServicesFault;
|
29 |
import net.brutex.xservices.ws.XServicesFault;
|
30 |
import org.apache.tools.ant.taskdefs.HostInfo;
|
30 |
import org.apache.tools.ant.taskdefs.HostInfo;
|
31 |
import org.apache.tools.ant.taskdefs.Sleep;
|
31 |
import org.apache.tools.ant.taskdefs.Sleep;
|
32 |
import org.apache.tools.ant.taskdefs.email.EmailTask;
|
32 |
import org.apache.tools.ant.taskdefs.email.EmailTask;
|
33 |
import org.h2.jdbcx.JdbcConnectionPool;
|
33 |
import org.h2.jdbcx.JdbcConnectionPool;
|
34 |
import org.quartz.*;
|
34 |
import org.quartz.*;
|
35 |
import org.quartz.impl.StdSchedulerFactory;
|
35 |
import org.quartz.impl.StdSchedulerFactory;
|
36 |
|
36 |
|
37 |
import javax.annotation.Resource;
|
37 |
import javax.annotation.Resource;
|
38 |
import javax.jws.WebService;
|
38 |
import javax.jws.WebService;
|
39 |
import javax.servlet.ServletContext;
|
39 |
import javax.servlet.ServletContext;
|
40 |
import javax.xml.bind.JAXBContext;
|
40 |
import javax.xml.bind.JAXBContext;
|
41 |
import javax.xml.bind.JAXBElement;
|
41 |
import javax.xml.bind.JAXBElement;
|
42 |
import javax.xml.bind.JAXBException;
|
42 |
import javax.xml.bind.JAXBException;
|
43 |
import javax.xml.bind.Marshaller;
|
43 |
import javax.xml.bind.Marshaller;
|
- |
|
44 |
import javax.xml.namespace.QName;
|
44 |
import javax.xml.ws.WebServiceContext;
|
45 |
import javax.xml.ws.WebServiceContext;
|
45 |
import javax.xml.ws.handler.MessageContext;
|
46 |
import javax.xml.ws.handler.MessageContext;
|
46 |
import java.io.StringReader;
|
47 |
import java.io.StringReader;
|
47 |
import java.io.StringWriter;
|
48 |
import java.io.StringWriter;
|
48 |
import java.math.BigInteger;
|
49 |
import java.math.BigInteger;
|
49 |
import java.sql.*;
|
50 |
import java.sql.*;
|
50 |
import java.time.Instant;
|
51 |
import java.time.Instant;
|
51 |
import java.util.Date;
|
52 |
import java.util.Date;
|
52 |
import java.util.Enumeration;
|
53 |
import java.util.Enumeration;
|
53 |
import java.util.Properties;
|
54 |
import java.util.Properties;
|
54 |
import java.util.UUID;
|
55 |
import java.util.UUID;
|
55 |
import java.util.concurrent.atomic.AtomicLong;
|
56 |
import java.util.concurrent.atomic.AtomicLong;
|
56 |
|
57 |
|
57 |
import static org.quartz.TriggerBuilder.newTrigger;
|
58 |
import static org.quartz.TriggerBuilder.newTrigger;
|
58 |
|
59 |
|
59 |
|
60 |
|
60 |
/**
|
61 |
/**
|
61 |
* Implements the web service
|
62 |
* Implements the web service
|
62 |
*
|
63 |
*
|
63 |
* @author Brian Rosenberger, bru@brutex.de
|
64 |
* @author Brian Rosenberger, bru@brutex.de
|
64 |
*/
|
65 |
*/
|
65 |
@Slf4j
|
66 |
@Slf4j
|
66 |
@WebService(targetNamespace="http://ws.xservices.brutex.net", endpointInterface="net.brutex.xservices.ws.MiscService", serviceName="MiscService")
|
67 |
@WebService(targetNamespace = "http://ws.xservices.brutex.net", endpointInterface = "net.brutex.xservices.ws.MiscService", serviceName = "MiscService")
|
67 |
public class MiscServiceImpl
|
68 |
public class MiscServiceImpl
|
68 |
implements MiscService {
|
69 |
implements MiscService {
|
69 |
|
70 |
|
70 |
@Resource
|
71 |
@Resource
|
71 |
private WebServiceContext context;
|
72 |
private WebServiceContext context;
|
- |
|
73 |
|
72 |
public MiscServiceImpl() throws SchedulerException {
|
74 |
public MiscServiceImpl() throws SchedulerException {
|
73 |
}
|
75 |
}
|
74 |
|
76 |
|
75 |
public HostinfoType getHostinfo(String hostname) {
|
77 |
public HostinfoType getHostinfo(String hostname) {
|
76 |
HostInfo info = new HostInfo();
|
78 |
HostInfo info = new HostInfo();
|
77 |
info.setTaskName("HostInfo");
|
79 |
info.setTaskName("HostInfo");
|
78 |
RunTask runner = new RunTask(info);
|
80 |
RunTask runner = new RunTask(info);
|
79 |
info.setHost(hostname);
|
81 |
info.setHost(hostname);
|
80 |
|
82 |
|
81 |
ReturnCode ret = runner.postTask();
|
83 |
ReturnCode ret = runner.postTask();
|
82 |
HostinfoType infotype = new HostinfoType(
|
84 |
HostinfoType infotype = new HostinfoType(
|
83 |
ret.getProperty("NAME"),
|
85 |
ret.getProperty("NAME"),
|
84 |
ret.getProperty("DOMAIN"),
|
86 |
ret.getProperty("DOMAIN"),
|
85 |
ret.getProperty("ADDR4"),
|
87 |
ret.getProperty("ADDR4"),
|
86 |
ret.getProperty("ADDR6"));
|
88 |
ret.getProperty("ADDR6"));
|
87 |
return infotype;
|
89 |
return infotype;
|
88 |
}
|
90 |
}
|
89 |
|
91 |
|
90 |
public ReturnCode getInfo() {
|
92 |
public ReturnCode getInfo() {
|
91 |
ReturnCode r = new ReturnCode();
|
93 |
ReturnCode r = new ReturnCode();
|
92 |
r.returnCode = 0;
|
94 |
r.returnCode = 0;
|
93 |
|
95 |
|
94 |
Properties props = System.getProperties();
|
96 |
Properties props = System.getProperties();
|
95 |
|
97 |
|
96 |
Enumeration e = props.propertyNames();
|
98 |
Enumeration e = props.propertyNames();
|
97 |
while (e.hasMoreElements()) {
|
99 |
while (e.hasMoreElements()) {
|
98 |
String propName = (String) e.nextElement();
|
100 |
String propName = (String) e.nextElement();
|
99 |
|
101 |
|
100 |
String propValue = (String) props.get(propName);
|
102 |
String propValue = (String) props.get(propName);
|
101 |
r.stdOut = (r.stdOut + propName + ": " + propValue + "\n");
|
103 |
r.stdOut = (r.stdOut + propName + ": " + propValue + "\n");
|
102 |
}
|
104 |
}
|
103 |
|
105 |
|
104 |
return r;
|
106 |
return r;
|
105 |
}
|
107 |
}
|
106 |
|
108 |
|
107 |
public ReturnCode sendMailSimple(HostConnection mailhost, String from, String tolist, String subject, String message) {
|
109 |
public ReturnCode sendMailSimple(HostConnection mailhost, String from, String tolist, String subject, String message) {
|
108 |
return sendMail(from, from, tolist, "", "", subject, message,
|
110 |
return sendMail(from, from, tolist, "", "", subject, message,
|
109 |
"text/plain", null, mailhost.hostname, mailhost.port,
|
111 |
"text/plain", null, mailhost.hostname, mailhost.port,
|
110 |
mailhost.user, mailhost.password, "utf-8", false, false);
|
112 |
mailhost.user, mailhost.password, "utf-8", false, false);
|
111 |
}
|
113 |
}
|
112 |
|
114 |
|
113 |
public ReturnCode sendMailSimpleWithAttachment(HostConnection mailhost, String from, String tolist, String subject, String message, FileSetResource res) {
|
115 |
public ReturnCode sendMailSimpleWithAttachment(HostConnection mailhost, String from, String tolist, String subject, String message, FileSetResource res) {
|
114 |
return sendMail(from, from, tolist, "", "", subject, message,
|
116 |
return sendMail(from, from, tolist, "", "", subject, message,
|
115 |
"text/plain", res, mailhost.hostname, mailhost.port,
|
117 |
"text/plain", res, mailhost.hostname, mailhost.port,
|
116 |
mailhost.user, mailhost.password, "utf-8", false, false);
|
118 |
mailhost.user, mailhost.password, "utf-8", false, false);
|
117 |
}
|
119 |
}
|
118 |
|
120 |
|
119 |
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) {
|
121 |
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) {
|
120 |
return sendMail(from, from, tolist, cclist, bcclist, subject, message,
|
122 |
return sendMail(from, from, tolist, cclist, bcclist, subject, message,
|
121 |
mimetype.value(), res, mailhost.hostname, mailhost.port,
|
123 |
mimetype.value(), res, mailhost.hostname, mailhost.port,
|
122 |
mailhost.user, mailhost.password, charset, tls, ssl);
|
124 |
mailhost.user, mailhost.password, charset, tls, ssl);
|
123 |
}
|
125 |
}
|
124 |
|
126 |
|
125 |
public ReturnCode sleep(int minutes, int seconds) {
|
127 |
public ReturnCode sleep(int minutes, int seconds) {
|
126 |
return sleep(0, minutes, seconds, 0);
|
128 |
return sleep(0, minutes, seconds, 0);
|
127 |
}
|
129 |
}
|
128 |
|
130 |
|
129 |
public String generateUUID() {
|
131 |
public String generateUUID() {
|
130 |
return UUID.randomUUID().toString();
|
132 |
return UUID.randomUUID().toString();
|
131 |
}
|
133 |
}
|
132 |
|
134 |
|
133 |
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) {
|
135 |
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) {
|
134 |
EmailTask mail = new EmailTask();
|
136 |
EmailTask mail = new EmailTask();
|
135 |
mail.setTaskName("Mail");
|
137 |
mail.setTaskName("Mail");
|
136 |
RunTask runner = new RunTask(mail);
|
138 |
RunTask runner = new RunTask(mail);
|
137 |
mail.setFrom(from);
|
139 |
mail.setFrom(from);
|
138 |
mail.setReplyTo(replyto);
|
140 |
mail.setReplyTo(replyto);
|
139 |
mail.setToList(tolist);
|
141 |
mail.setToList(tolist);
|
140 |
mail.setCcList(cclist);
|
142 |
mail.setCcList(cclist);
|
141 |
mail.setBccList(bcclist);
|
143 |
mail.setBccList(bcclist);
|
142 |
mail.setSubject(subject);
|
144 |
mail.setSubject(subject);
|
143 |
mail.setMessage(message);
|
145 |
mail.setMessage(message);
|
144 |
mail.setMessageMimeType(messagemimetype);
|
146 |
mail.setMessageMimeType(messagemimetype);
|
145 |
if (attachments != null) {
|
147 |
if (attachments != null) {
|
146 |
mail.addFileset(attachments.getAntResource(mail.getProject()));
|
148 |
mail.addFileset(attachments.getAntResource(mail.getProject()));
|
147 |
}
|
149 |
}
|
148 |
mail.setMailhost(mailhost);
|
150 |
mail.setMailhost(mailhost);
|
149 |
mail.setMailport(mailport);
|
151 |
mail.setMailport(mailport);
|
150 |
mail.setUser(user);
|
152 |
mail.setUser(user);
|
151 |
mail.setPassword(password);
|
153 |
mail.setPassword(password);
|
152 |
mail.setCharset(charset);
|
154 |
mail.setCharset(charset);
|
153 |
mail.setSSL(ssl);
|
155 |
mail.setSSL(ssl);
|
154 |
mail.setEnableStartTLS(tls);
|
156 |
mail.setEnableStartTLS(tls);
|
155 |
return runner.postTask();
|
157 |
return runner.postTask();
|
156 |
}
|
158 |
}
|
157 |
|
159 |
|
158 |
private ReturnCode sleep(int hours, int minutes, int seconds, int milliseconds) {
|
160 |
private ReturnCode sleep(int hours, int minutes, int seconds, int milliseconds) {
|
159 |
Sleep sleep = new Sleep();
|
161 |
Sleep sleep = new Sleep();
|
160 |
sleep.setTaskName("Sleep");
|
162 |
sleep.setTaskName("Sleep");
|
161 |
RunTask runner = new RunTask(sleep);
|
163 |
RunTask runner = new RunTask(sleep);
|
162 |
sleep.setHours(hours);
|
164 |
sleep.setHours(hours);
|
163 |
sleep.setMinutes(minutes);
|
165 |
sleep.setMinutes(minutes);
|
164 |
sleep.setSeconds(seconds);
|
166 |
sleep.setSeconds(seconds);
|
165 |
sleep.setMilliseconds(milliseconds);
|
167 |
sleep.setMilliseconds(milliseconds);
|
166 |
return runner.postTask();
|
168 |
return runner.postTask();
|
167 |
}
|
169 |
}
|
168 |
|
170 |
|
169 |
public RuntimeInfoType getMemory() {
|
171 |
public RuntimeInfoType getMemory() {
|
170 |
return new RuntimeInfoType();
|
172 |
return new RuntimeInfoType();
|
171 |
}
|
173 |
}
|
172 |
|
174 |
|
173 |
@Override
|
175 |
@Override
|
174 |
public BigInteger lock(String id, String objectId) throws XServicesFault {
|
176 |
public BigInteger lock(String id, String objectId) throws XServicesFault {
|
175 |
|
177 |
|
176 |
|
- |
|
177 |
|
178 |
|
178 |
final String conString = "jdbc:h2:mem:lockdb;DB_CLOSE_DELAY=10;" +
|
179 |
final String conString = "jdbc:h2:mem:lockdb;DB_CLOSE_DELAY=10;" +
|
179 |
"INIT=CREATE SCHEMA IF NOT EXISTS brutex\\;" +
|
180 |
"INIT=CREATE SCHEMA IF NOT EXISTS brutex\\;" +
|
180 |
// "SET SCHEMA brutex\\;" +
|
181 |
// "SET SCHEMA brutex\\;" +
|
181 |
"CREATE SEQUENCE IF NOT EXISTS brutex.btx_sequence1\\;" +
|
182 |
"CREATE SEQUENCE IF NOT EXISTS brutex.btx_sequence1\\;" +
|
182 |
"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);";
|
183 |
"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);";
|
183 |
|
184 |
|
184 |
//JdbcConnectionPool cp = JdbcConnectionPool.create(conString, "sa", "");
|
185 |
//JdbcConnectionPool cp = JdbcConnectionPool.create(conString, "sa", "");
|
185 |
//cp.setMaxConnections(1);
|
186 |
//cp.setMaxConnections(1);
|
186 |
|
187 |
|
187 |
Connection con = null;
|
188 |
Connection con = null;
|
188 |
long rows = 0L;
|
189 |
long rows = 0L;
|
189 |
final long ts = new Date().getTime();
|
190 |
final long ts = new Date().getTime();
|
190 |
try {
|
191 |
try {
|
191 |
Class.forName("org.h2.Driver"); //Java 1.8
|
192 |
Class.forName("org.h2.Driver"); //Java 1.8
|
192 |
con = DriverManager.getConnection(conString);
|
193 |
con = DriverManager.getConnection(conString);
|
193 |
PreparedStatement prep = con.prepareStatement(
|
194 |
PreparedStatement prep = con.prepareStatement(
|
194 |
"SELECT btx_id from brutex.tbl_lock where btx_obj_id=? ORDER BY btx_seq DESC");
|
195 |
"SELECT btx_id from brutex.tbl_lock where btx_obj_id=? ORDER BY btx_seq DESC");
|
195 |
prep.setString(1, objectId);
|
196 |
prep.setString(1, objectId);
|
196 |
|
197 |
|
197 |
ResultSet rs = prep.executeQuery();
|
198 |
ResultSet rs = prep.executeQuery();
|
198 |
StringBuffer bf = new StringBuffer();
|
199 |
StringBuffer bf = new StringBuffer();
|
199 |
while (rs.next()) {
|
200 |
while (rs.next()) {
|
200 |
//bf.append(rs.getString(1));
|
201 |
//bf.append(rs.getString(1));
|
201 |
rows++;
|
202 |
rows++;
|
202 |
}
|
203 |
}
|
203 |
rs.close();
|
204 |
rs.close();
|
204 |
|
205 |
|
205 |
prep = con.prepareStatement("INSERT INTO brutex.tbl_lock values (NEXT VALUE FOR brutex.btx_sequence1, ?, ?, ?)");
|
206 |
prep = con.prepareStatement("INSERT INTO brutex.tbl_lock values (NEXT VALUE FOR brutex.btx_sequence1, ?, ?, ?)");
|
206 |
prep.setString(1, id);
|
207 |
prep.setString(1, id);
|
207 |
prep.setString(2, objectId);
|
208 |
prep.setString(2, objectId);
|
208 |
prep.setLong(3, ts);
|
209 |
prep.setLong(3, ts);
|
209 |
prep.execute();
|
210 |
prep.execute();
|
210 |
|
211 |
|
211 |
prep = con.prepareStatement("DELETE from brutex.tbl_lock WHERE btx_timestamp < ?");
|
212 |
prep = con.prepareStatement("DELETE from brutex.tbl_lock WHERE btx_timestamp < ?");
|
212 |
prep.setLong(1, ts - 10000);
|
213 |
prep.setLong(1, ts - 10000);
|
213 |
prep.execute();
|
214 |
prep.execute();
|
214 |
prep.close();
|
215 |
prep.close();
|
215 |
|
216 |
|
216 |
con.close();
|
217 |
con.close();
|
217 |
//System.out.println(bf);
|
218 |
//System.out.println(bf);
|
218 |
} catch (SQLException | ClassNotFoundException e) {
|
219 |
} catch (SQLException | ClassNotFoundException e) {
|
219 |
throw new XServicesFault(e);
|
220 |
throw new XServicesFault(e);
|
220 |
}
|
221 |
}
|
221 |
|
222 |
|
222 |
return BigInteger.valueOf(rows);
|
223 |
return BigInteger.valueOf(rows);
|
223 |
}
|
224 |
}
|
224 |
|
225 |
|
225 |
@Override
|
226 |
@Override
|
226 |
public ALFEventResponseType mergeALFEvent(ALFEventType event) throws XServicesFault {
|
227 |
public ALFEventResponseType mergeALFEvent(ALFEventType event) throws XServicesFault {
|
227 |
final Instant d = Instant.now();
|
228 |
final Instant d = Instant.now();
|
228 |
final long ts = d.toEpochMilli();
|
229 |
final long ts = d.toEpochMilli();
|
- |
|
230 |
|
- |
|
231 |
MessageContext cont = context.getMessageContext();
|
229 |
|
232 |
|
230 |
//Get Parameters from the Servlet Context
|
233 |
//Get Parameters from the Servlet Context
|
231 |
final ServletContext servletContext =
|
234 |
final ServletContext servletContext =
|
232 |
(ServletContext) context.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
|
235 |
(ServletContext) context.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
|
233 |
final EventmanagerConfiguration conf = (EventmanagerConfiguration) servletContext
|
236 |
final EventmanagerConfiguration conf = (EventmanagerConfiguration) servletContext
|
234 |
.getAttribute(EventmanagerConfiguration.KEY);
|
237 |
.getAttribute(EventmanagerConfiguration.KEY);
|
235 |
|
238 |
|
236 |
final JdbcConnectionPool pool = (JdbcConnectionPool) servletContext.getAttribute("mdbConnection");
|
239 |
final JdbcConnectionPool pool = (JdbcConnectionPool) servletContext.getAttribute("mdbConnection");
|
237 |
final JdbcConnectionPool fpool = (JdbcConnectionPool) servletContext.getAttribute("fdbConnection");
|
240 |
final JdbcConnectionPool fpool = (JdbcConnectionPool) servletContext.getAttribute("fdbConnection");
|
238 |
final AtomicLong egres_counter = (AtomicLong) servletContext.getAttribute("egres_counter");
|
241 |
final AtomicLong egres_counter = (AtomicLong) servletContext.getAttribute("egres_counter");
|
239 |
final AtomicLong ingres_counter = (AtomicLong) servletContext.getAttribute("ingres_counter");
|
242 |
final AtomicLong ingres_counter = (AtomicLong) servletContext.getAttribute("ingres_counter");
|
240 |
final Scheduler scheduler = (Scheduler) servletContext.getAttribute("scheduler");
|
243 |
final Scheduler scheduler = (Scheduler) servletContext.getAttribute("scheduler");
|
241 |
|
244 |
|
242 |
log.trace("Read dbConnection from servlet context: {}", pool);
|
245 |
log.trace("Read dbConnection from servlet context: {}", pool);
|
243 |
|
246 |
|
244 |
//System.out.println("Step 2: " + ChronoUnit.MILLIS.between(Instant.now(), d));
|
247 |
//System.out.println("Step 2: " + ChronoUnit.MILLIS.between(Instant.now(), d));
|
245 |
final ObjectFactory of = new ObjectFactory();
|
248 |
final ObjectFactory of = new ObjectFactory();
|
246 |
|
249 |
|
247 |
final String objectId = event.getBase().getObjectId();
|
250 |
final String objectId = event.getBase().getObjectId();
|
248 |
final String eventId = event.getBase().getEventId();
|
251 |
final String eventId = event.getBase().getEventId();
|
249 |
final String objectType = event.getBase().getObjectType();
|
252 |
final String objectType = event.getBase().getObjectType();
|
250 |
final String eventType = event.getBase().getEventType();
|
253 |
final String eventType = event.getBase().getEventType();
|
251 |
log.debug("Event id '{}', type '{}' received for object '{}' with object_id '{}'.",
|
254 |
log.debug("Event id '{}', type '{}' received for object '{}' with object_id '{}'.",
|
252 |
eventId, eventType, objectType, objectId);
|
255 |
eventId, eventType, objectType, objectId);
|
253 |
|
256 |
|
254 |
final String mergeStatememt = "MERGE INTO brutex.tbl_events " +
|
257 |
final String mergeStatememt = "SELECT btx_id FROM OLD TABLE (MERGE INTO brutex.tbl_events " +
|
255 |
"KEY (btx_event_type, btx_obj_type, btx_obj_id) " +
|
258 |
"KEY (btx_event_type, btx_obj_type, btx_obj_id) " +
|
- |
|
259 |
"VALUES (?,?,?,?,?,?));";
|
- |
|
260 |
|
256 |
"VALUES (?,?,?,?,?,?);";
|
261 |
final String insertAll = "INSERT INTO brutex.tbl_events_all VALUES (?,?,?,?,?,?,?)";
|
257 |
|
262 |
|
258 |
|
263 |
|
259 |
try {
|
264 |
try (Connection con = pool.getConnection()) {
|
260 |
Marshaller m = JAXBContext.newInstance(ALFEventType.class).createMarshaller();
|
265 |
Marshaller m = JAXBContext.newInstance(ALFEventType.class).createMarshaller();
|
261 |
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
266 |
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
262 |
m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
|
267 |
m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
|
- |
|
268 |
m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
|
263 |
JAXBElement<ALFEventType> e = of.createEventNotice(event);
|
269 |
JAXBElement<ALFEventType> e = of.createALFEventNoticeDoc(event);
|
264 |
StringWriter sw = new StringWriter();
|
270 |
StringWriter sw = new StringWriter();
|
265 |
m.marshal(e, sw);
|
271 |
m.marshal(e, sw);
|
266 |
StringBuilder sb = new StringBuilder();
|
272 |
StringBuilder sb = new StringBuilder();
|
- |
|
273 |
|
267 |
sb.append(" <soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
|
274 |
sb.append(" <soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
|
268 |
"xmlns:ns=\"http://www.eclipse.org/alf/schema/EventBase/1\">\n");
|
275 |
"xmlns:ns=\"http://www.eclipse.org/alf/schema/EventBase/1\">\n");
|
269 |
sb.append("<soapenv:Body>\n");
|
276 |
sb.append("<soapenv:Body>\n");
|
270 |
sb.append("<ns:EventNotice>\n");
|
- |
|
- |
|
277 |
|
271 |
sb.append(sw);
|
278 |
sb.append(sw);
|
272 |
sb.append("</ns:EventNotice>\n");
|
- |
|
- |
|
279 |
|
273 |
sb.append("</soapenv:Body>");
|
280 |
sb.append("</soapenv:Body>");
|
274 |
sb.append("</soapenv:Envelope>");
|
281 |
sb.append("</soapenv:Envelope>");
|
275 |
|
- |
|
- |
|
282 |
|
276 |
Connection con = pool.getConnection();
|
283 |
|
277 |
PreparedStatement prep = con.prepareStatement(mergeStatememt);
|
284 |
PreparedStatement prep = con.prepareStatement(mergeStatememt);
|
278 |
prep.setString(1, eventType);
|
285 |
prep.setString(1, eventType);
|
279 |
prep.setString(2, eventId);
|
286 |
prep.setString(2, eventId);
|
280 |
prep.setString(3, objectType);
|
287 |
prep.setString(3, objectType);
|
281 |
prep.setString(4, objectId);
|
288 |
prep.setString(4, objectId);
|
282 |
prep.setLong(5, ts);
|
289 |
prep.setLong(5, ts);
|
283 |
prep.setClob(6, new StringReader(sb.toString()));
|
290 |
prep.setClob(6, new StringReader(sb.toString()));
|
- |
|
291 |
ResultSet r = prep.executeQuery();
|
- |
|
292 |
con.commit();
|
- |
|
293 |
String supersed_id = null;
|
- |
|
294 |
if (r.next()) {
|
- |
|
295 |
supersed_id = r.getString(1);
|
- |
|
296 |
log.trace("Event '{}' superseded event '{}'", eventId, supersed_id);
|
- |
|
297 |
} else {
|
- |
|
298 |
log.trace("Event '{}' inserted into outgoing queue.", eventId);
|
- |
|
299 |
}
|
- |
|
300 |
|
- |
|
301 |
|
- |
|
302 |
/* Write all into permanent storage */
|
- |
|
303 |
//Connection fcon = fpool.getConnection();
|
- |
|
304 |
prep = con.prepareStatement(insertAll);
|
- |
|
305 |
prep.setString(1, eventType);
|
- |
|
306 |
prep.setString(2, eventId);
|
- |
|
307 |
prep.setString(3, objectType);
|
- |
|
308 |
prep.setString(4, objectId);
|
- |
|
309 |
prep.setLong(5, ts);
|
- |
|
310 |
prep.setString(6, supersed_id);
|
- |
|
311 |
prep.setClob(7, new StringReader(sb.toString()));
|
284 |
prep.execute();
|
312 |
prep.execute();
|
- |
|
313 |
|
285 |
con.commit();
|
314 |
con.commit();
|
286 |
con.close();
|
315 |
con.close();
|
287 |
|
316 |
|
288 |
ingres_counter.incrementAndGet();
|
317 |
ingres_counter.incrementAndGet();
|
- |
|
318 |
|
289 |
|
319 |
if (conf.isEmitterActive()) {
|
290 |
synchronized (scheduler) {
|
320 |
synchronized (scheduler) {
|
291 |
if (!scheduler.checkExists(JobKey.jobKey("ALFEmitter"))) {
|
321 |
if (!scheduler.checkExists(JobKey.jobKey("ALFEmitter"))) {
|
292 |
JobDetail job2 = JobBuilder.newJob(EventEmitter.class)
|
322 |
JobDetail job2 = JobBuilder.newJob(EventEmitter.class)
|
293 |
.withIdentity("ALFEmitter")
|
323 |
.withIdentity("ALFEmitter")
|
294 |
.build();
|
324 |
.build();
|
295 |
job2.getJobDataMap().put("mdbConnection", pool);
|
325 |
job2.getJobDataMap().put("mdbConnection", pool);
|
296 |
job2.getJobDataMap().put("fdbConnection", fpool);
|
326 |
job2.getJobDataMap().put("fdbConnection", fpool);
|
297 |
job2.getJobDataMap().put("run_key", ts);
|
327 |
job2.getJobDataMap().put("run_key", ts);
|
298 |
job2.getJobDataMap().put("egres_counter", egres_counter);
|
328 |
job2.getJobDataMap().put("egres_counter", egres_counter);
|
299 |
job2.getJobDataMap().put("ingres_counter", ingres_counter);
|
329 |
job2.getJobDataMap().put("ingres_counter", ingres_counter);
|
300 |
|
330 |
|
301 |
job2.getJobDataMap().put(EventmanagerConfiguration.KEY, conf);
|
331 |
job2.getJobDataMap().put(EventmanagerConfiguration.KEY, conf);
|
302 |
|
332 |
|
303 |
SimpleTrigger t = (SimpleTrigger) newTrigger()
|
333 |
SimpleTrigger t = (SimpleTrigger) newTrigger()
|
304 |
.withIdentity("ALFEmitter").startAt(Date.from(d.plusSeconds(conf.getInterval())))
|
334 |
.withIdentity("ALFEmitter").startAt(Date.from(d.plusSeconds(conf.getInterval())))
|
305 |
.build();
|
335 |
.build();
|
306 |
|
336 |
|
307 |
scheduler.scheduleJob(job2, t);
|
337 |
scheduler.scheduleJob(job2, t);
|
308 |
}
|
338 |
}
|
309 |
}
|
339 |
}
|
- |
|
340 |
}
|
310 |
} catch (JAXBException | SQLException | SchedulerException e) {
|
341 |
} catch (JAXBException | SQLException | SchedulerException e) {
|
311 |
log.error(e.getMessage());
|
342 |
log.error(e.getMessage());
|
312 |
throw new XServicesFault(e);
|
343 |
throw new XServicesFault(e);
|
313 |
}
|
344 |
}
|
314 |
return of.createALFEventResponseType();
|
345 |
return of.createALFEventResponseType();
|
315 |
}
|
346 |
}
|
316 |
}
|
347 |
}
|
317 |
|
348 |
|
318 |
Generated by GNU Enscript 1.6.5.90.
|
349 |
Generated by GNU Enscript 1.6.5.90.
|
319 |
|
350 |
|
320 |
|
351 |
|