use of org.apache.nifi.processors.websocket.WebSocketProcessorAttributes.ATTR_WS_CS_ID in project nifi by apache.
the class AbstractWebSocketGatewayProcessor method enqueueMessage.
private void enqueueMessage(final WebSocketMessage incomingMessage) {
final ProcessSession session = processSessionFactory.createSession();
try {
FlowFile messageFlowFile = session.create();
final Map<String, String> attrs = new HashMap<>();
attrs.put(ATTR_WS_CS_ID, webSocketService.getIdentifier());
final WebSocketSessionInfo sessionInfo = incomingMessage.getSessionInfo();
attrs.put(ATTR_WS_SESSION_ID, sessionInfo.getSessionId());
attrs.put(ATTR_WS_ENDPOINT_ID, endpointId);
attrs.put(ATTR_WS_LOCAL_ADDRESS, sessionInfo.getLocalAddress().toString());
attrs.put(ATTR_WS_REMOTE_ADDRESS, sessionInfo.getRemoteAddress().toString());
final WebSocketMessage.Type messageType = incomingMessage.getType();
if (messageType != null) {
attrs.put(ATTR_WS_MESSAGE_TYPE, messageType.name());
}
messageFlowFile = session.putAllAttributes(messageFlowFile, attrs);
final byte[] payload = incomingMessage.getPayload();
if (payload != null) {
messageFlowFile = session.write(messageFlowFile, out -> {
out.write(payload, incomingMessage.getOffset(), incomingMessage.getLength());
});
}
session.getProvenanceReporter().receive(messageFlowFile, getTransitUri(sessionInfo));
if (incomingMessage instanceof WebSocketConnectedMessage) {
session.transfer(messageFlowFile, REL_CONNECTED);
} else {
switch(messageType) {
case TEXT:
session.transfer(messageFlowFile, REL_MESSAGE_TEXT);
break;
case BINARY:
session.transfer(messageFlowFile, REL_MESSAGE_BINARY);
break;
}
}
session.commit();
} catch (Exception e) {
logger.error("Unable to fully process input due to " + e, e);
session.rollback();
}
}
Aggregations