use of org.apache.nifi.websocket.WebSocketMessage in project nifi by apache.
the class AbstractWebSocketGatewayProcessor method consume.
@Override
public void consume(WebSocketSessionInfo sessionInfo, String messageStr) {
final WebSocketMessage message = new WebSocketMessage(sessionInfo);
sessionInfo.setTransitUri(getTransitUri(sessionInfo));
message.setPayload(messageStr);
enqueueMessage(message);
}
use of org.apache.nifi.websocket.WebSocketMessage in project nifi by apache.
the class AbstractWebSocketGatewayProcessor method consume.
@Override
public void consume(WebSocketSessionInfo sessionInfo, byte[] payload, int offset, int length) {
final WebSocketMessage message = new WebSocketMessage(sessionInfo);
sessionInfo.setTransitUri(getTransitUri(sessionInfo));
message.setPayload(payload, offset, length);
enqueueMessage(message);
}
use of org.apache.nifi.websocket.WebSocketMessage in project nifi by apache.
the class AbstractWebSocketGatewayProcessor method connected.
@Override
public void connected(WebSocketSessionInfo sessionInfo) {
final WebSocketMessage message = new WebSocketConnectedMessage(sessionInfo);
sessionInfo.setTransitUri(getTransitUri(sessionInfo));
enqueueMessage(message);
}
use of org.apache.nifi.websocket.WebSocketMessage 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