Search in sources :

Example 11 with MessageInfo

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

Example 12 with MessageInfo

use of org.talend.esb.sam.common.event.MessageInfo in project tesb-rt-se by Talend.

the class SAMProviderImplTest method test.

@Test
public void test() {
    SAMProviderImpl provider = new SAMProviderImpl();
    provider.setDialect("derbyDialect");
    provider.setDataSource(ds);
    provider.init();
    Event e = writeEventtoDb("SAMProviderImplTest-1");
    Event e2 = writeEventtoDb("SAMProviderImplTest-2");
    Assert.assertEquals("derbyDialect", provider.getDialect());
    List<FlowEvent> flowEvents = provider.getFlowDetails("SAMProviderImplTest-1");
    Assert.assertNotNull(flowEvents);
    for (FlowEvent fe : flowEvents) {
        if (fe.getFlowID().equals(e.getMessageInfo().getFlowId())) {
            Assert.assertEquals(e.getTimestamp().getTime(), fe.getTimestamp());
            Assert.assertEquals(e.getEventType(), fe.getType());
            Originator o = e.getOriginator();
            Assert.assertEquals(o.getProcessId(), fe.getProcess());
            Assert.assertEquals(o.getIp(), fe.getIp());
            Assert.assertEquals(o.getHostname(), fe.getHost());
            Assert.assertEquals(o.getCustomId(), fe.getCustomId());
            Assert.assertEquals(o.getPrincipal(), fe.getPrincipal());
            MessageInfo mi = e.getMessageInfo();
            Assert.assertEquals(mi.getMessageId(), fe.getMessageID());
            Assert.assertEquals(mi.getFlowId(), fe.getFlowID());
            Assert.assertEquals(mi.getPortType(), fe.getPort());
            Assert.assertEquals(mi.getOperationName(), fe.getOperation());
            Assert.assertEquals(mi.getTransportType(), fe.getTransport());
            Assert.assertEquals(e.isContentCut(), fe.isContentCut());
        // Assert.assertEquals(e.getContent(), fe.getContent());
        } else {
            Assert.fail("record with invalid flowId " + fe.getFlowID() + " was written into database");
        }
    }
    FlowEvent fe = provider.getEventDetails(-33);
    Assert.assertNull(fe);
    int id = Integer.parseInt(e.getPersistedId().toString());
    fe = provider.getEventDetails(id);
    Assert.assertNotNull(fe);
    Assert.assertEquals(e.getTimestamp().getTime(), fe.getTimestamp());
    Assert.assertEquals(e.getEventType(), fe.getType());
    Originator o = e.getOriginator();
    Assert.assertEquals(o.getProcessId(), fe.getProcess());
    Assert.assertEquals(o.getIp(), fe.getIp());
    Assert.assertEquals(o.getHostname(), fe.getHost());
    Assert.assertEquals(o.getCustomId(), fe.getCustomId());
    Assert.assertEquals(o.getPrincipal(), fe.getPrincipal());
    MessageInfo mi = e.getMessageInfo();
    Assert.assertEquals(mi.getMessageId(), fe.getMessageID());
    Assert.assertEquals(mi.getFlowId(), fe.getFlowID());
    Assert.assertEquals(mi.getPortType(), fe.getPort());
    Assert.assertEquals(mi.getOperationName(), fe.getOperation());
    Assert.assertEquals(mi.getTransportType(), fe.getTransport());
    Assert.assertEquals(e.isContentCut(), fe.isContentCut());
    Assert.assertEquals(e.getContent(), fe.getContent());
    Map<String, String[]> criterias = new HashMap<String, String[]>();
    String[] arr = { "SAMProviderImplTest-1" };
    criterias.put("flowID", arr);
    CriteriaAdapter ca = new CriteriaAdapter(0, 100, criterias);
    FlowCollection fc = provider.getFlows(ca);
    Assert.assertNotNull(fc);
    Assert.assertNotNull(fc.getFlows());
    List<Flow> flows = fc.getFlows();
    Assert.assertFalse(flows.isEmpty());
    Assert.assertEquals(1, flows.size());
    Flow flow = flows.get(0);
    Assert.assertEquals(flow.getEventType(), e.getEventType());
    Assert.assertEquals(flow.getflowID(), e.getMessageInfo().getFlowId());
    Assert.assertEquals(flow.getHost(), e.getOriginator().getHostname());
    Assert.assertEquals(flow.getIp(), e.getOriginator().getIp());
    Assert.assertEquals(flow.getOperation(), e.getMessageInfo().getOperationName());
    Assert.assertEquals(flow.getPort(), e.getMessageInfo().getPortType());
    Assert.assertEquals(flow.getTransport(), e.getMessageInfo().getTransportType());
}
Also used : HashMap(java.util.HashMap) MessageInfo(org.talend.esb.sam.common.event.MessageInfo) CriteriaAdapter(org.talend.esb.sam.server.persistence.criterias.CriteriaAdapter) Originator(org.talend.esb.sam.common.event.Originator) Event(org.talend.esb.sam.common.event.Event) Test(org.junit.Test)

Example 13 with MessageInfo

use of org.talend.esb.sam.common.event.MessageInfo in project tesb-rt-se by Talend.

the class JxPathFilterTest method testExpression.

@Test
public void testExpression() {
    Event event = new Event();
    event.setContent("test");
    event.setEventType(EventTypeEnum.FAULT_IN);
    event.getCustomInfo().put("key1", "value1");
    MessageInfo messageInfo = new MessageInfo();
    messageInfo.setFlowId("urn:flowid");
    messageInfo.setMessageId("urn:messageId");
    messageInfo.setOperationName("{namespace}opname");
    messageInfo.setPortType("{namespace}portname");
    messageInfo.setTransportType("http");
    event.setMessageInfo(messageInfo);
    JxPathFilter jxPathFilter = new JxPathFilter();
    jxPathFilter.setExpression("content='test'");
    Assert.assertTrue("Event should be filtered ", jxPathFilter.filter(event));
    checkFiltered("content='test'", event);
    checkNotFiltered("content='test2'", event);
    checkFiltered("eventType='FAULT_IN'", event);
    checkFiltered("content='test' and eventType='FAULT_IN'", event);
    checkFiltered("content='test' and eventType='FAULT_IN'", event);
    checkFiltered("content='test' and eventType='FAULT_IN' and customInfo/key1='value1'", event);
    checkFiltered("messageInfo/flowId='urn:flowid' and messageInfo/operationName='{namespace}opname'", event);
}
Also used : Event(org.talend.esb.sam.common.event.Event) MessageInfo(org.talend.esb.sam.common.event.MessageInfo) Test(org.junit.Test)

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