use of org.talend.esb.sam.common.event.Event in project tesb-rt-se by Talend.
the class StringContentFilterTest method testFilter.
@Test
public void testFilter() {
StringContentFilter filter = new StringContentFilter();
List<String> wordsList = new ArrayList<String>();
wordsList.add("confidential");
filter.setWordsToFilter(wordsList);
Event event = new Event();
event.setContent("This event is confidential");
Assert.assertTrue(filter.filter(event));
}
use of org.talend.esb.sam.common.event.Event in project tesb-rt-se by Talend.
the class EventRepositoryImplTest method test.
@Test
public void test() {
Event e = new Event();
Date ts = new Date();
e.setTimestamp(ts);
e.setEventType(EventTypeEnum.REQ_IN);
Originator orig = new Originator("pid1", "127.0.0.1", "localhost", "custom_id1", "principal1");
e.setOriginator(orig);
MessageInfo mi = new MessageInfo("mid1", "flo123", "portType_1", "seekBook", "HTTP");
e.setMessageInfo(mi);
e.setContentCut(false);
e.setContent("<seekBook>Survival in the Arctic</seekBook>");
e.getCustomInfo().put("key1", "value1");
e.getCustomInfo().put("key2", "value2");
eri.writeEvent(e);
Event e2 = eri.readEvent(e.getPersistedId());
Assert.assertNotNull(e2);
Assert.assertEquals(e2.getEventType(), e.getEventType());
Assert.assertEquals(e2.getOriginator(), e.getOriginator());
Assert.assertEquals(e2.getMessageInfo(), e.getMessageInfo());
Assert.assertEquals(e2.isContentCut(), e.isContentCut());
Assert.assertEquals(e2.getContent(), e.getContent());
Map<String, String> cim = e2.getCustomInfo();
Assert.assertNotNull(cim.get("key1"));
Assert.assertEquals("value1", cim.get("key1"));
Assert.assertEquals("value2", cim.get("key2"));
}
use of org.talend.esb.sam.common.event.Event in project tesb-rt-se by Talend.
the class SAMProviderImplTest method writeEventtoDb.
private Event writeEventtoDb(String flowId) {
Event e = new Event();
Date ts = new Date();
e.setTimestamp(ts);
e.setEventType(EventTypeEnum.REQ_IN);
Originator orig = new Originator("pid1", "127.0.0.1", "localhost", "custom_id1", "principal1");
e.setOriginator(orig);
MessageInfo mi = new MessageInfo("mid1", flowId, "portType_1", "seekBook", "HTTP");
e.setMessageInfo(mi);
e.setContentCut(false);
e.setContent("<seekBook>Survival in the Arctic</seekBook>");
e.getCustomInfo().put("key1", "value1");
e.getCustomInfo().put("key2", "value2");
eri.writeEvent(e);
return e;
}
use of org.talend.esb.sam.common.event.Event in project tesb-rt-se by Talend.
the class EventRowMapper method mapRow.
/* (non-Javadoc)
* @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int)
*/
@Override
public Event mapRow(ResultSet rs, int rowNum) throws SQLException {
Event event = new Event();
event.setPersistedId(rs.getLong("ID"));
event.setTimestamp(rs.getTimestamp("EI_TIMESTAMP"));
event.setEventType(EventTypeEnum.valueOf(rs.getString("EI_EVENT_TYPE")));
Originator originator = new Originator();
originator.setProcessId(rs.getString("ORIG_PROCESS_ID"));
originator.setIp(rs.getString("ORIG_IP"));
originator.setHostname(rs.getString("ORIG_HOSTNAME"));
originator.setCustomId(rs.getString("ORIG_CUSTOM_ID"));
originator.setPrincipal(rs.getString("ORIG_PRINCIPAL"));
event.setOriginator(originator);
MessageInfo messageInfo = new MessageInfo();
messageInfo.setMessageId(rs.getString("MI_MESSAGE_ID"));
messageInfo.setFlowId(rs.getString("MI_FLOW_ID"));
messageInfo.setPortType(rs.getString("MI_PORT_TYPE"));
messageInfo.setOperationName(rs.getString("MI_OPERATION_NAME"));
messageInfo.setTransportType(rs.getString("MI_TRANSPORT_TYPE"));
event.setMessageInfo(messageInfo);
event.setContentCut(rs.getBoolean("CONTENT_CUT"));
try {
event.setContent(IOUtils.toString(rs.getClob("MESSAGE_CONTENT").getAsciiStream()));
} catch (IOException e) {
throw new RuntimeException("Error reading content", e);
}
return event;
}
use of org.talend.esb.sam.common.event.Event in project tesb-rt-se by Talend.
the class EventCollector method sendEventsFromQueue.
/**
* Method will be executed asynchronously.
*/
public void sendEventsFromQueue() {
if (null == queue || stopSending) {
return;
}
LOG.fine("Scheduler called for sending events");
int packageSize = getEventsPerMessageCall();
while (!queue.isEmpty()) {
final List<Event> list = new ArrayList<Event>();
int i = 0;
while (i < packageSize && !queue.isEmpty()) {
Event event = queue.remove();
if (event != null && !filter(event)) {
list.add(event);
i++;
}
}
if (list.size() > 0) {
executor.execute(new Runnable() {
public void run() {
try {
sendEvents(list);
} catch (MonitoringException e) {
e.logException(Level.SEVERE);
}
}
});
}
}
}
Aggregations