use of org.talend.esb.sam.common.event.Originator 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.Originator 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.Originator in project tesb-rt-se by Talend.
the class EventRepositoryImpl method writeEvent.
/* (non-Javadoc)
* @see org.talend.esb.sam.common.event.persistence.EventRepository#writeEvent(org.talend.esb.sam.common.event.Event)
*/
@Override
public void writeEvent(Event event) {
Originator originator = event.getOriginator();
MessageInfo messageInfo = event.getMessageInfo();
long id = dbDialect.getIncrementer().nextLongValue();
event.setPersistedId(id);
getJdbcTemplate().update("insert into EVENTS (ID, EI_TIMESTAMP, EI_EVENT_TYPE," + " ORIG_PROCESS_ID, ORIG_IP, ORIG_HOSTNAME, " + " ORIG_CUSTOM_ID, ORIG_PRINCIPAL," + " MI_MESSAGE_ID, MI_FLOW_ID, MI_PORT_TYPE," + " MI_OPERATION_NAME, MI_TRANSPORT_TYPE," + " CONTENT_CUT, MESSAGE_CONTENT) " + " values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", event.getPersistedId(), event.getTimestamp(), event.getEventType().toString(), originator.getProcessId(), originator.getIp(), originator.getHostname(), originator.getCustomId(), originator.getPrincipal(), messageInfo.getMessageId(), messageInfo.getFlowId(), messageInfo.getPortType(), messageInfo.getOperationName(), messageInfo.getTransportType(), event.isContentCut(), event.getContent());
writeCustomInfo(event);
if (LOG.isLoggable(Level.INFO)) {
LOG.info("event [message_id=" + messageInfo.getMessageId() + "] persist to Database successful." + " ID=" + id);
}
}
use of org.talend.esb.sam.common.event.Originator 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.Originator in project tesb-rt-se by Talend.
the class EventCreator method createEvent.
public static Event createEvent(String content, Date timestamp, EventTypeEnum eventType, String customOriginatorId, String hostname, String ip, String processId, String flowId, String messageId, String operarionName, String portType, String transportType) {
Event event = new Event();
event.setContent(content);
event.setTimestamp(timestamp);
event.setEventType(eventType);
Originator originator = new Originator();
originator.setCustomId(customOriginatorId);
originator.setHostname(hostname);
originator.setIp(ip);
originator.setProcessId(processId);
event.setOriginator(originator);
event.setMessageInfo(new MessageInfo());
MessageInfo messageInfo = event.getMessageInfo();
messageInfo.setFlowId(flowId);
messageInfo.setMessageId(messageId);
messageInfo.setOperationName(operarionName);
messageInfo.setPortType(portType);
messageInfo.setTransportType(transportType);
if (event.getContent() == null || event.getContent().equals("")) {
logger.info("Set content empty element");
event.setContent("<empty/>");
}
if (event.getTimestamp() == null) {
logger.info("Set timestamp to current Date");
event.setTimestamp(Calendar.getInstance().getTime());
}
if (event.getEventType() == null) {
logger.info("Set eventType to REQ_IN");
event.setEventType(EventTypeEnum.REQ_IN);
}
if (originator.getCustomId() == null || originator.getCustomId().equals("")) {
logger.info("Set custom id to empty");
originator.setCustomId("empty");
}
if (originator.getHostname() == null || originator.getHostname().equals("")) {
logger.info("Set hostname to empty");
originator.setHostname("empty");
}
if (originator.getIp() == null || originator.getIp().equals("")) {
logger.info("Set ip to empty");
originator.setIp("empty");
}
if (originator.getProcessId() == null || originator.getProcessId().equals("")) {
logger.info("Set process id to empty");
originator.setProcessId("empty");
}
if (messageInfo.getFlowId() == null || messageInfo.getFlowId().equals("")) {
logger.info("Set flow id to empty");
messageInfo.setFlowId("empty");
}
if (messageInfo.getMessageId() == null || messageInfo.getMessageId().equals("")) {
logger.info("Set message id to empty");
messageInfo.setMessageId("empty");
}
if (messageInfo.getOperationName() == null || messageInfo.getOperationName().equals("")) {
logger.info("Set operation name to empty");
messageInfo.setOperationName("empty");
}
if (messageInfo.getPortType() == null || messageInfo.getPortType().equals("")) {
logger.info("Set porttype to empty");
messageInfo.setPortType("empty");
}
if (messageInfo.getTransportType() == null || messageInfo.getTransportType().equals("")) {
logger.info("Set pransport type to empty");
messageInfo.setTransportType("empty");
}
if (event.getPersistedId() != null) {
logger.warning("Persisted Id is not null, but event is not persisted jet!");
}
return event;
}
Aggregations