use of org.talend.esb.sam.common.event.MessageInfo 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.MessageInfo 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.MessageInfo 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.MessageInfo 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.MessageInfo in project tesb-rt-se by Talend.
the class EventTypeMapper method map.
/**
* Map the EventType.
*
* @param eventType the event type
* @return the event
*/
public static Event map(EventType eventType) {
Event event = new Event();
event.setEventType(mapEventTypeEnum(eventType.getEventType()));
Date date = (eventType.getTimestamp() == null) ? new Date() : eventType.getTimestamp().toGregorianCalendar().getTime();
event.setTimestamp(date);
event.setOriginator(mapOriginatorType(eventType.getOriginator()));
MessageInfo messageInfo = mapMessageInfo(eventType.getMessageInfo());
event.setMessageInfo(messageInfo);
String content = mapContent(eventType.getContent());
event.setContent(content);
event.getCustomInfo().clear();
event.getCustomInfo().putAll(mapCustomInfo(eventType.getCustomInfo()));
return event;
}
Aggregations