Search in sources :

Example 21 with Event

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

Example 22 with 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"));
}
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 23 with Event

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;
}
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 24 with Event

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

Aggregations

Event (org.talend.esb.sam.common.event.Event)37 Test (org.junit.Test)16 MessageInfo (org.talend.esb.sam.common.event.MessageInfo)11 ArrayList (java.util.ArrayList)10 Originator (org.talend.esb.sam.common.event.Originator)9 Date (java.util.Date)6 EventType (org.talend.esb.sam._2011._03.common.EventType)4 Customer (com.example.customerservice.Customer)3 DataHandler (javax.activation.DataHandler)3 Message (org.apache.cxf.message.Message)3 MessageToEventMapper (org.talend.esb.sam.agent.eventproducer.MessageToEventMapper)3 InetAddress (java.net.InetAddress)2 UnknownHostException (java.net.UnknownHostException)2 HashMap (java.util.HashMap)2 SoapBinding (org.apache.cxf.binding.soap.SoapBinding)2 SoapBindingInfo (org.apache.cxf.binding.soap.model.SoapBindingInfo)2 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)2 SecurityContext (org.apache.cxf.security.SecurityContext)2 CustomInfo (org.talend.esb.sam.agent.message.CustomInfo)2 EventTypeEnum (org.talend.esb.sam.common.event.EventTypeEnum)2