Package org.talend.esb.sam.common.event

Examples of org.talend.esb.sam.common.event.Event


     * @see org.talend.esb.sam.common.event.persistence.EventRepository#readEvent(long)
     */
    @Override
    public Event readEvent(long id) {
        RowMapper<Event> rowMapper = new EventRowMapper();
        Event event = getSimpleJdbcTemplate()
            .queryForObject("select * from EVENTS where ID=" + id, rowMapper);
        event.getCustomInfo().clear();
        event.getCustomInfo().putAll(readCustomInfo(id));
        return event;
    }
View Full Code Here


    /* (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;
    }
View Full Code Here

    protected void processStart(Endpoint endpoint, EventTypeEnum eventType) {
        if (!sendLifecycleEvent) {
            return;
        }

        Event event = createEvent(endpoint, eventType);
        queue.add(event);
    }
View Full Code Here

    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!");
        }
    }
View Full Code Here

     * @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;
    }
View Full Code Here

        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++;
                }
            }
View Full Code Here

        }

        //check MessageID
        checkMessageID(message);

        Event event = mapper.mapToEvent(message);

        if (null != handler) {
            handler.handleEvent(event);
        }
        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);
        }
View Full Code Here

     * @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");
        }

        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;
    }
View Full Code Here

    private static final String Address = "http://localhost:8080/test";
   
    @Test
    public void testMapEvent() throws IOException, EndpointException {
        Message message = getTestMessage();
        Event event = new MessageToEventMapper().mapToEvent(message);
        Assert.assertEquals(EventTypeEnum.REQ_IN, event.getEventType());
        Assert.assertEquals("{interfaceNs}interfaceName", event.getMessageInfo().getPortType());
        Assert.assertEquals("{namespace}opName", event.getMessageInfo().getOperationName());
        Assert.assertEquals(TransportType, event.getMessageInfo().getTransportType());
        Assert.assertEquals(FlowID, event.getMessageInfo().getFlowId());
        Assert.assertNull(event.getMessageInfo().getMessageId());

        // By default the content should not be cut
        Assert.assertEquals(TESTCONTENT, event.getContent());
        Assert.assertFalse(event.isContentCut());

        // Principal
        Assert.assertEquals(PrincipalString, event.getOriginator().getPrincipal());

        Map<String, String> customInfo = event.getCustomInfo();
        //Assert.assertEquals(2, customInfo.keySet().size());
        //Assert.assertEquals(Address, customInfo.get("address"));
        Assert.assertEquals("value1", customInfo.get("key1"));

    }
View Full Code Here

    @Test
    public void testMaxContentLength() throws IOException, EndpointException {
        Message message = getTestMessage();
        MessageToEventMapper mapper = new MessageToEventMapper();
        mapper.setMaxContentLength(MAXCONTENTLENGTH);
        Event event = mapper.mapToEvent(message);
        //System.out.println(event.getContent());
        Assert.assertEquals(MAXCONTENTLENGTH, event.getContent().length());
        Assert.assertEquals("<cut><![CDATA[" + TESTCONTENT.substring(0, MAXCONTENTLENGTH - 23) + "]]></cut>", event.getContent());
        Assert.assertTrue(event.isContentCut());
    }
View Full Code Here

TOP

Related Classes of org.talend.esb.sam.common.event.Event

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.