Search in sources :

Example 11 with Event

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

the class MonitoringServiceWrapper method putEvents.

/**
 * Sends all events to the web service. Events will be transformed with mapper before sending.
 *
 * @param events the events
 */
public void putEvents(List<Event> events) {
    Exception lastException;
    List<EventType> eventTypes = new ArrayList<EventType>();
    for (Event event : events) {
        EventType eventType = EventMapper.map(event);
        eventTypes.add(eventType);
    }
    int i = 0;
    lastException = null;
    while (i < numberOfRetries) {
        try {
            monitoringService.putEvents(eventTypes);
            break;
        } catch (Exception e) {
            lastException = e;
            i++;
        }
        if (i < numberOfRetries) {
            try {
                Thread.sleep(delayBetweenRetry);
            } catch (InterruptedException e) {
                break;
            }
        }
    }
    if (i == numberOfRetries) {
        throw new MonitoringException("1104", "Could not send events to monitoring service after " + numberOfRetries + " retries.", lastException, events);
    }
}
Also used : EventType(org.talend.esb.sam._2011._03.common.EventType) MonitoringException(org.talend.esb.sam.common.event.MonitoringException) ArrayList(java.util.ArrayList) Event(org.talend.esb.sam.common.event.Event) MonitoringException(org.talend.esb.sam.common.event.MonitoringException)

Example 12 with Event

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

the class AbstractListenerImpl method processStop.

/**
 * Process stop.
 *
 * @param endpoint the endpoint
 * @param eventType the event type
 */
protected void processStop(Endpoint endpoint, EventTypeEnum eventType) {
    if (!sendLifecycleEvent) {
        return;
    }
    Event event = createEvent(endpoint, eventType);
    monitoringServiceClient.putEvents(Collections.singletonList(event));
    if (LOG.isLoggable(Level.INFO)) {
        LOG.info("Send " + eventType + " event to SAM Server successful!");
    }
}
Also used : Event(org.talend.esb.sam.common.event.Event)

Example 13 with Event

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

the class AbstractListenerImpl method processStart.

/**
 * Process start.
 *
 * @param endpoint the endpoint
 * @param eventType the event type
 */
protected void processStart(Endpoint endpoint, EventTypeEnum eventType) {
    if (!sendLifecycleEvent) {
        return;
    }
    Event event = createEvent(endpoint, eventType);
    queue.add(event);
}
Also used : Event(org.talend.esb.sam.common.event.Event)

Example 14 with Event

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

the class AbstractListenerImpl method createEvent.

/**
 * Creates the event for endpoint with specific type.
 *
 * @param endpoint the endpoint
 * @param type the type
 * @return the event
 */
private Event createEvent(Endpoint endpoint, EventTypeEnum type) {
    Event event = new Event();
    MessageInfo messageInfo = new MessageInfo();
    Originator originator = new Originator();
    event.setMessageInfo(messageInfo);
    event.setOriginator(originator);
    Date date = new Date();
    event.setTimestamp(date);
    event.setEventType(type);
    messageInfo.setPortType(endpoint.getBinding().getBindingInfo().getService().getInterface().getName().toString());
    String transportType = null;
    if (endpoint.getBinding() instanceof SoapBinding) {
        SoapBinding soapBinding = (SoapBinding) endpoint.getBinding();
        if (soapBinding.getBindingInfo() instanceof SoapBindingInfo) {
            SoapBindingInfo soapBindingInfo = (SoapBindingInfo) soapBinding.getBindingInfo();
            transportType = soapBindingInfo.getTransportURI();
        }
    }
    messageInfo.setTransportType((transportType != null) ? transportType : "Unknown transport type");
    originator.setProcessId(Converter.getPID());
    try {
        InetAddress inetAddress = InetAddress.getLocalHost();
        originator.setIp(inetAddress.getHostAddress());
        originator.setHostname(inetAddress.getHostName());
    } catch (UnknownHostException e) {
        originator.setHostname("Unknown hostname");
        originator.setIp("Unknown ip address");
    }
    String address = endpoint.getEndpointInfo().getAddress();
    event.getCustomInfo().put("address", address);
    return event;
}
Also used : UnknownHostException(java.net.UnknownHostException) Originator(org.talend.esb.sam.common.event.Originator) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) Event(org.talend.esb.sam.common.event.Event) InetAddress(java.net.InetAddress) Date(java.util.Date) SoapBinding(org.apache.cxf.binding.soap.SoapBinding) MessageInfo(org.talend.esb.sam.common.event.MessageInfo)

Example 15 with Event

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

the class EventMapperTest method testEventMapper2.

@Test
public void testEventMapper2() throws IOException {
    Event event = new Event();
    event.setContent("testContent");
    MessageInfo messageInfo = EasyMock.createMock(MessageInfo.class);
    EasyMock.expect(messageInfo.getMessageId()).andReturn("MessageId").anyTimes();
    EasyMock.expect(messageInfo.getFlowId()).andReturn("FlowId").anyTimes();
    EasyMock.expect(messageInfo.getPortType()).andReturn("PortType").anyTimes();
    EasyMock.expect(messageInfo.getOperationName()).andReturn("OperationName").anyTimes();
    EasyMock.expect(messageInfo.getTransportType()).andReturn("TransportType").anyTimes();
    EasyMock.replay(messageInfo);
    event.setMessageInfo(messageInfo);
    Originator originator = EasyMock.createMock(Originator.class);
    EasyMock.expect(originator.getProcessId()).andReturn("ProcessId").anyTimes();
    EasyMock.expect(originator.getIp()).andReturn("Ip").anyTimes();
    EasyMock.expect(originator.getHostname()).andReturn("Hostname").anyTimes();
    EasyMock.expect(originator.getCustomId()).andReturn("CustomId").anyTimes();
    EasyMock.expect(originator.getPrincipal()).andReturn("Principal").anyTimes();
    EasyMock.replay(originator);
    event.setOriginator(originator);
    event.getCustomInfo().put("testKey", "testValue");
    EventType eventOut = EventMapper.map(event);
    DataHandler dh = eventOut.getContent();
    String outContent = getContent(dh);
    Assert.assertEquals(event.getContent(), outContent);
    Assert.assertEquals(eventOut.getOriginator().getProcessId(), event.getOriginator().getProcessId());
    Assert.assertEquals(eventOut.getOriginator().getIp(), event.getOriginator().getIp());
    Assert.assertEquals(eventOut.getOriginator().getHostname(), event.getOriginator().getHostname());
    Assert.assertEquals(eventOut.getOriginator().getCustomId(), event.getOriginator().getCustomId());
    Assert.assertEquals(eventOut.getOriginator().getPrincipal(), event.getOriginator().getPrincipal());
    Assert.assertEquals(eventOut.getMessageInfo().getMessageId(), event.getMessageInfo().getMessageId());
    Assert.assertEquals(eventOut.getMessageInfo().getFlowId(), event.getMessageInfo().getFlowId());
    Assert.assertSame(eventOut.getMessageInfo().getPorttype().getLocalPart(), event.getMessageInfo().getPortType());
    Assert.assertEquals(eventOut.getMessageInfo().getOperationName(), event.getMessageInfo().getOperationName());
    Assert.assertEquals(eventOut.getMessageInfo().getTransport(), event.getMessageInfo().getTransportType());
    Assert.assertEquals(eventOut.getCustomInfo().getItem().get(0).getValue(), "testValue");
    Assert.assertEquals(eventOut.getCustomInfo().getItem().get(0).getKey(), "testKey");
}
Also used : Originator(org.talend.esb.sam.common.event.Originator) EventType(org.talend.esb.sam._2011._03.common.EventType) Event(org.talend.esb.sam.common.event.Event) DataHandler(javax.activation.DataHandler) MessageInfo(org.talend.esb.sam.common.event.MessageInfo) Test(org.junit.Test)

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