use of org.talend.esb.sam.common.event.EventTypeEnum 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;
}
use of org.talend.esb.sam.common.event.EventTypeEnum in project tesb-rt-se by Talend.
the class SAMRestServiceImpl method aggregateRawData.
public AggregatedFlowCollection aggregateRawData(FlowCollection collection) {
// Render RAW data
Map<String, Long> flowLastTimestamp = new HashMap<String, Long>();
Map<String, String> flowProviderIP = new HashMap<String, String>();
Map<String, String> flowProviderHost = new HashMap<String, String>();
Map<String, String> flowConsumerIP = new HashMap<String, String>();
Map<String, String> flowConsumerHost = new HashMap<String, String>();
Map<String, Set<String>> flowTypes = new HashMap<String, Set<String>>();
Map<String, String> flowConsumerPort = new HashMap<String, String>();
Map<String, String> flowConsumerOperation = new HashMap<String, String>();
Map<String, String> flowProviderPort = new HashMap<String, String>();
Map<String, String> flowProviderOperation = new HashMap<String, String>();
for (Flow obj : collection.getFlows()) {
if (null == obj.getflowID() || obj.getflowID().isEmpty()) {
continue;
}
String flowID = obj.getflowID();
flowLastTimestamp.put(flowID, obj.getTimestamp());
if (!flowTypes.containsKey(flowID)) {
flowTypes.put(flowID, new HashSet<String>());
}
EventTypeEnum typeEnum = obj.getEventType();
flowTypes.get(flowID).add(typeEnum.toString());
boolean isConsumer = typeEnum == EventTypeEnum.REQ_OUT || typeEnum == EventTypeEnum.RESP_IN || typeEnum == EventTypeEnum.FAULT_IN;
boolean isProvider = typeEnum == EventTypeEnum.REQ_IN || typeEnum == EventTypeEnum.RESP_OUT || typeEnum == EventTypeEnum.FAULT_OUT;
String host = obj.getHost();
String ip = obj.getIp();
String port = obj.getPort();
String operation = obj.getOperation();
if (isConsumer) {
flowConsumerIP.put(flowID, ip);
flowConsumerHost.put(flowID, host);
flowConsumerPort.put(flowID, port);
flowConsumerOperation.put(flowID, operation);
}
if (isProvider) {
flowProviderIP.put(flowID, ip);
flowProviderHost.put(flowID, host);
flowProviderPort.put(flowID, port);
flowProviderOperation.put(flowID, operation);
}
}
List<AggregatedFlow> result = new ArrayList<AggregatedFlow>();
for (Flow obj : collection.getFlows()) {
String flowID = obj.getflowID();
if (null == flowID || flowID.isEmpty()) {
continue;
}
Long startTime = flowLastTimestamp.remove(flowID);
if (null != startTime) {
AggregatedFlow aggregatedFlow = new AggregatedFlow();
aggregatedFlow.setFlowID(flowID);
if (flowProviderPort.containsKey(flowID)) {
aggregatedFlow.setPort(flowProviderPort.get(flowID));
aggregatedFlow.setOperation(flowProviderOperation.get(flowID));
} else {
aggregatedFlow.setPort(flowConsumerPort.get(flowID));
aggregatedFlow.setOperation(flowConsumerOperation.get(flowID));
}
aggregatedFlow.setTransport(obj.getTransport());
aggregatedFlow.setTypes(flowTypes.get(flowID));
long timestamp = obj.getTimestamp();
aggregatedFlow.setTimestamp(timestamp);
aggregatedFlow.setElapsed(timestamp - startTime);
aggregatedFlow.setDetails(uriInfo.getBaseUriBuilder().path("flow").path(flowID).build());
if (flowConsumerHost.containsKey(flowID)) {
aggregatedFlow.setConsumerHost(flowConsumerHost.get(flowID));
aggregatedFlow.setConsumerIP(flowConsumerIP.get(flowID));
}
if (flowProviderHost.containsKey(flowID)) {
aggregatedFlow.setProviderHost(flowProviderHost.get(flowID));
aggregatedFlow.setProviderIP(flowProviderIP.get(flowID));
}
result.add(aggregatedFlow);
}
}
AggregatedFlowCollection fc = new AggregatedFlowCollection();
fc.setAggregated(result);
fc.setCount(collection.getCount());
return fc;
}
use of org.talend.esb.sam.common.event.EventTypeEnum in project tesb-rt-se by Talend.
the class AbstractEventProducerTest method checkEventsNum.
protected void checkEventsNum(List<Event> eventList, int expectedNum) {
List<EventTypeEnum> eventTypeList = new ArrayList<EventTypeEnum>();
for (Event event : eventList) {
eventTypeList.add(event.getEventType());
}
Assert.assertEquals("The expected events num should be " + expectedNum + ". Actually events num is " + eventList.size() + " which are " + eventTypeList, expectedNum, eventList.size());
}
Aggregations