Subversion Repositories XServices

Rev

Rev 201 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 201 Rev 203
Line 39... Line 39...
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;
Line 67... Line 68...
67
public class MiscServiceImpl
68
public class MiscServiceImpl
68
  implements MiscService {
69
        implements MiscService {
Line 69... Line 70...
69
 
70
 
70
  @Resource
71
    @Resource
-
 
72
    private WebServiceContext context;
71
  private WebServiceContext context;
73
 
72
    public MiscServiceImpl() throws SchedulerException {
74
    public MiscServiceImpl() throws SchedulerException {
Line 73... Line 75...
73
    }
75
    }
74
 
76
 
Line 172... Line 174...
172
 
174
 
173
  @Override
175
    @Override
Line 174... Line -...
174
  public BigInteger lock(String id, String objectId) throws XServicesFault {
-
 
175
 
176
    public BigInteger lock(String id, String objectId) throws XServicesFault {
176
 
177
 
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\\;" +
Line 225... Line 226...
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();
Line -... Line 230...
-
 
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
Line 249... Line 252...
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);
Line 253... Line 256...
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) " +
Line -... Line 259...
-
 
259
                "VALUES (?,?,?,?,?,?));";
Line -... Line 260...
-
 
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()) {
-
 
265
            Marshaller m = JAXBContext.newInstance(ALFEventType.class).createMarshaller();
260
      Marshaller m = JAXBContext.newInstance(ALFEventType.class).createMarshaller();
266
            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
261
      m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
267
            m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
262
      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);
-
 
270
            StringWriter sw = new StringWriter();
264
      StringWriter sw = new StringWriter();
271
            m.marshal(e, sw);
265
      m.marshal(e, sw);
272
            StringBuilder sb = new StringBuilder();
266
      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);
Line 272... Line -...
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);
-
 
287
            prep.setString(3, objectType);
-
 
288
            prep.setString(4, objectId);
-
 
289
            prep.setLong(5, ts);
-
 
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);
280
      prep.setString(3, objectType);
308
            prep.setString(4, objectId);
-
 
309
            prep.setLong(5, ts);
281
      prep.setString(4, objectId);
310
            prep.setString(6, supersed_id);
282
      prep.setLong(5, ts);
311
            prep.setClob(7, new StringReader(sb.toString()));
Line 283... Line 312...
283
      prep.setClob(6, new StringReader(sb.toString()));
312
            prep.execute();
Line -... Line 313...
-
 
313
 
284
      prep.execute();
314
            con.commit();
285
      con.commit();
315
            con.close();
286
      con.close();
316
 
287
 
317
            ingres_counter.incrementAndGet();
288
      ingres_counter.incrementAndGet();
318
 
Line 305... Line 335...
305
                    .build();
335
                                .build();
Line 306... Line 336...
306
 
336
 
307
            scheduler.scheduleJob(job2, t);
337
                        scheduler.scheduleJob(job2, t);
308
          }
338
                    }
-
 
339
                }
309
      }
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
        }