Search in sources :

Example 1 with Event

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

the class EventProducerInterceptor method handleMessage.

/* (non-Javadoc)
     * @see org.apache.cxf.interceptor.Interceptor#handleMessage(org.apache.cxf.message.Message)
     */
@Override
public void handleMessage(Message message) throws Fault {
    // ignore the messages from SAM Server service itself
    BindingOperationInfo boi = message.getExchange().getBindingOperationInfo();
    if (null != boi) {
        String operationName = boi.getName().toString();
        if (SAM_OPERATION.equals(operationName)) {
            return;
        }
    }
    if (isRestWadlRequest(message)) {
        // skip handling REST service WADL requests - temporary fix since will be fixed in CXF soon
        return;
    }
    if (isOnewayResponse(message)) {
        // skip oneway response events
        return;
    }
    // Skip Swagger UI web static, swagger.json and swagger.yaml requests
    if (isSwaggerResourceRequest(message)) {
        return;
    }
    // check MessageID
    checkMessageID(message);
    Event event = mapper.mapToEvent(message);
    if (LOG.isLoggable(Level.FINE)) {
        String id = (event.getMessageInfo() != null) ? event.getMessageInfo().getMessageId() : null;
        LOG.fine("Store event [message_id=" + id + "] in cache.");
    }
    if (null != event) {
        queue.add(event);
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Event(org.talend.esb.sam.common.event.Event)

Example 2 with Event

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

the class MessageToEventMapper method mapToEvent.

/**
 * Map to event.
 *
 * @param message
 *            the message
 * @return the event
 */
public Event mapToEvent(Message message) {
    Event event = new Event();
    MessageInfo messageInfo = new MessageInfo();
    Originator originator = new Originator();
    boolean isRestMessage = isRestMessage(message);
    event.setMessageInfo(messageInfo);
    event.setOriginator(originator);
    String content = getPayload(message);
    event.setContent(content);
    handleContentLength(event);
    event.setEventType(null);
    Date date = new Date();
    event.setTimestamp(date);
    // if (isRestMessage) {
    // String queryString = (String) message.get(Message.QUERY_STRING);
    // if (queryString == null && message.getExchange().getInMessage() != null) {
    // queryString = (String) message.getExchange().getInMessage().get(Message.QUERY_STRING);
    // }
    // if (queryString != null && queryString.contains("_wadl")) {
    // return null;
    // }
    // }
    messageInfo.setFlowId(FlowIdHelper.getFlowId(message));
    if (!isRestMessage) {
        messageInfo.setMessageId(getMessageId(message));
        ServiceInfo serviceInfo = message.getExchange().getBinding().getBindingInfo().getService();
        if (null != serviceInfo) {
            String portTypeName = serviceInfo.getInterface().getName().toString();
            messageInfo.setPortType(portTypeName);
            messageInfo.setOperationName(getOperationName(message));
        }
        SoapBinding soapBinding = (SoapBinding) message.getExchange().getBinding();
        if (soapBinding.getBindingInfo() instanceof SoapBindingInfo) {
            SoapBindingInfo soapBindingInfo = (SoapBindingInfo) soapBinding.getBindingInfo();
            messageInfo.setTransportType(soapBindingInfo.getTransportURI());
        }
    } else {
        messageInfo.setTransportType("http://cxf.apache.org/transports/http");
        messageInfo.setPortType(message.getExchange().getEndpoint().getEndpointInfo().getName().toString());
        String opName = getRestOperationName(message);
        messageInfo.setOperationName(opName);
    }
    if (messageInfo.getTransportType() == null) {
        messageInfo.setTransportType("Unknown transport type");
    }
    // add custom properties from CXF properties
    if (null != message.getExchange().getEndpoint().get(EventFeature.SAM_PROPERTIES)) {
        Map<String, String> customProp = (Map<String, String>) message.getExchange().getEndpoint().get(EventFeature.SAM_PROPERTIES);
        event.getCustomInfo().putAll(customProp);
    }
    String addr = message.getExchange().getEndpoint().getEndpointInfo().getAddress();
    if (null != addr) {
        event.getCustomInfo().put("address", addr);
    }
    String correlationId = CorrelationIdHelper.getCorrelationId(message);
    if (null != correlationId) {
        event.getCustomInfo().put("CorrelationID", correlationId);
    }
    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");
    }
    originator.setProcessId(Converter.getPID());
    if (isRestMessage) {
        // String queryString = (String) message.get(Message.QUERY_STRING);
        // if (null == queryString && null != message.getExchange().getInMessage()) {
        // queryString = (String) message.getExchange().getInMessage().get(Message.QUERY_STRING);
        // }
        // if (null != queryString) {
        // event.getCustomInfo().put("Query String", queryString);
        // }
        String accept = (String) message.get(Message.ACCEPT_CONTENT_TYPE);
        if (null != accept) {
            event.getCustomInfo().put("Accept Type", accept);
        }
        // String httpMethod = (String) message.get(Message.HTTP_REQUEST_METHOD);
        // if (null != httpMethod) {
        // event.getCustomInfo().put("HTTP Method", httpMethod);
        // }
        String contentType = (String) message.get(Message.CONTENT_TYPE);
        if (null != contentType) {
            event.getCustomInfo().put("Content Type", contentType);
        }
        Integer responseCode = (Integer) message.get(Message.RESPONSE_CODE);
        if (null != responseCode) {
            event.getCustomInfo().put("Response Code", responseCode.toString());
        }
    }
    SecurityContext sc = message.get(SecurityContext.class);
    if (sc != null && sc.getUserPrincipal() != null) {
        originator.setPrincipal(sc.getUserPrincipal().getName());
    }
    if (originator.getPrincipal() == null) {
        AuthorizationPolicy authPolicy = message.get(AuthorizationPolicy.class);
        if (authPolicy != null) {
            originator.setPrincipal(authPolicy.getUserName());
        }
    }
    EventTypeEnum eventType = getEventType(message);
    event.setEventType(eventType);
    CustomInfo customInfo = CustomInfo.getOrCreateCustomInfo(message);
    // System.out.println("custom props: " + customInfo);
    event.getCustomInfo().putAll(customInfo);
    return event;
}
Also used : UnknownHostException(java.net.UnknownHostException) Date(java.util.Date) SoapBinding(org.apache.cxf.binding.soap.SoapBinding) MessageInfo(org.talend.esb.sam.common.event.MessageInfo) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) Originator(org.talend.esb.sam.common.event.Originator) EventTypeEnum(org.talend.esb.sam.common.event.EventTypeEnum) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SecurityContext(org.apache.cxf.security.SecurityContext) Event(org.talend.esb.sam.common.event.Event) CustomInfo(org.talend.esb.sam.agent.message.CustomInfo) Map(java.util.Map) InetAddress(java.net.InetAddress)

Example 3 with Event

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

the class EventCollectorTest method createEvent.

public Event createEvent(String content) {
    Event event = new Event();
    event.setContent(content);
    return event;
}
Also used : Event(org.talend.esb.sam.common.event.Event)

Example 4 with Event

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

the class AbstractEventProducerTest method checkMessageIdPresentAndSame.

/**
 * check if the MessageId is present and same
 * @param eventList
 */
protected void checkMessageIdPresentAndSame(List<Event> eventList, boolean isOneway) {
    for (Event event : eventList) {
        String messageId = event.getMessageInfo().getMessageId();
        Assert.assertNotNull("MessageId should not be null in " + event.getEventType(), messageId);
    }
    String messageId0 = eventList.get(0).getMessageInfo().getMessageId();
    String messageId1 = eventList.get(1).getMessageInfo().getMessageId();
    Assert.assertEquals("MessageId from REQ_OUT/REQ_IN should be the same", messageId0, messageId1);
    if (!isOneway) {
        String messageId2 = eventList.get(2).getMessageInfo().getMessageId();
        String messageId3 = eventList.get(3).getMessageInfo().getMessageId();
        Assert.assertEquals("MessageId from RESP_OUT/RESP_IN(FAULT_OUT/FAULT_IN)  should be the same", messageId2, messageId3);
    }
}
Also used : Event(org.talend.esb.sam.common.event.Event)

Example 5 with Event

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

the class AbstractEventProducerTest method checkFlowIdPresentAndSame.

protected void checkFlowIdPresentAndSame(List<Event> eventList) {
    String flowId = eventList.get(0).getMessageInfo().getFlowId();
    for (Event event : eventList) {
        String newFlowId = event.getMessageInfo().getFlowId();
        Assert.assertNotNull("FlowId should not be null in " + event.getEventType(), newFlowId);
        Assert.assertEquals("All flowIds should be the same", flowId, newFlowId);
    }
}
Also used : 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