Search in sources :

Example 6 with MessageInfo

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"));
}
Also used : Originator(org.talend.esb.sam.common.event.Originator) Event(org.talend.esb.sam.common.event.Event) Date(java.util.Date) MessageInfo(org.talend.esb.sam.common.event.MessageInfo) Test(org.junit.Test)

Example 7 with MessageInfo

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;
}
Also used : Originator(org.talend.esb.sam.common.event.Originator) Event(org.talend.esb.sam.common.event.Event) Date(java.util.Date) MessageInfo(org.talend.esb.sam.common.event.MessageInfo)

Example 8 with MessageInfo

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);
    }
}
Also used : Originator(org.talend.esb.sam.common.event.Originator) MessageInfo(org.talend.esb.sam.common.event.MessageInfo)

Example 9 with MessageInfo

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;
}
Also used : Originator(org.talend.esb.sam.common.event.Originator) Event(org.talend.esb.sam.common.event.Event) IOException(java.io.IOException) MessageInfo(org.talend.esb.sam.common.event.MessageInfo)

Example 10 with MessageInfo

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;
}
Also used : Event(org.talend.esb.sam.common.event.Event) Date(java.util.Date) MessageInfo(org.talend.esb.sam.common.event.MessageInfo)

Aggregations

MessageInfo (org.talend.esb.sam.common.event.MessageInfo)13 Event (org.talend.esb.sam.common.event.Event)11 Originator (org.talend.esb.sam.common.event.Originator)10 Date (java.util.Date)6 Test (org.junit.Test)4 InetAddress (java.net.InetAddress)2 UnknownHostException (java.net.UnknownHostException)2 SoapBinding (org.apache.cxf.binding.soap.SoapBinding)2 SoapBindingInfo (org.apache.cxf.binding.soap.model.SoapBindingInfo)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DataHandler (javax.activation.DataHandler)1 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)1 SecurityContext (org.apache.cxf.security.SecurityContext)1 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)1 EventType (org.talend.esb.sam._2011._03.common.EventType)1 CustomInfo (org.talend.esb.sam.agent.message.CustomInfo)1 EventTypeEnum (org.talend.esb.sam.common.event.EventTypeEnum)1 FlowEvent (org.talend.esb.sam.server.persistence.FlowEvent)1