use of org.apache.nifi.remote.io.http.HttpServerCommunicationsSession in project nifi by apache.
the class TestHttpFlowFileServerProtocol method testReceiveZeroFile.
@Test
public void testReceiveZeroFile() throws Exception {
final HttpFlowFileServerProtocol serverProtocol = getDefaultHttpFlowFileServerProtocol();
final Peer peer = getDefaultPeer("testReceiveZeroFile");
final HttpServerCommunicationsSession commsSession = (HttpServerCommunicationsSession) peer.getCommunicationsSession();
commsSession.setUserDn("unit-test");
serverProtocol.handshake(peer);
assertTrue(serverProtocol.isHandshakeSuccessful());
final FlowFileCodec negotiatedCoded = serverProtocol.negotiateCodec(peer);
final ProcessContext context = null;
final ProcessSession processSession = mock(ProcessSession.class);
final InputStream httpInputStream = new ByteArrayInputStream(new byte[] {});
((HttpInput) commsSession.getInput()).setInputStream(httpInputStream);
// Execute test using mock
final int flowFileReceived = serverProtocol.receiveFlowFiles(peer, context, processSession, negotiatedCoded);
assertEquals(0, flowFileReceived);
}
use of org.apache.nifi.remote.io.http.HttpServerCommunicationsSession in project nifi by apache.
the class TestHttpFlowFileServerProtocol method testTransferOneFileBadChecksum.
@Test
public void testTransferOneFileBadChecksum() throws Exception {
final HttpFlowFileServerProtocol serverProtocol = getDefaultHttpFlowFileServerProtocol();
final String transactionId = "testTransferOneFileBadChecksum";
final Peer peer = getDefaultPeer(transactionId);
final HttpServerCommunicationsSession commsSession = (HttpServerCommunicationsSession) peer.getCommunicationsSession();
final String endpointUri = "https://remote-host:8443/nifi-api/output-ports/port-id/transactions/" + transactionId + "/flow-files";
commsSession.putHandshakeParam(HandshakeProperty.BATCH_COUNT, "1");
commsSession.setUserDn("unit-test");
commsSession.setDataTransferUrl(endpointUri);
transferFlowFiles(serverProtocol, transactionId, peer, processSession -> {
final MockFlowFile flowFile = processSession.createFlowFile("Server content".getBytes());
final HashMap<String, String> attributes = new HashMap<>();
attributes.put("uuid", "server-uuid");
attributes.put("filename", "server-filename");
attributes.put("server-attr-1", "server-attr-1-value");
attributes.put("server-attr-2", "server-attr-2-value");
flowFile.putAttributes(attributes);
return Arrays.asList(flowFile);
});
// Commit transaction
try {
serverProtocol.commitTransferTransaction(peer, "client-sent-wrong-checksum");
fail();
} catch (final IOException e) {
assertTrue(e.getMessage().contains("CRC32 Checksum"));
}
}
use of org.apache.nifi.remote.io.http.HttpServerCommunicationsSession in project nifi by apache.
the class StandardHttpFlowFileServerProtocol method commitTransferTransaction.
@Override
public int commitTransferTransaction(Peer peer, String clientChecksum) throws IOException, IllegalStateException {
logger.debug("{} Committing the transfer transaction. peer={} clientChecksum={}", this, peer, clientChecksum);
HttpServerCommunicationsSession commSession = (HttpServerCommunicationsSession) peer.getCommunicationsSession();
String transactionId = commSession.getTransactionId();
FlowFileTransaction transaction = transactionManager.finalizeTransaction(transactionId);
commSession.setChecksum(clientChecksum);
commSession.setStatus(Transaction.TransactionState.DATA_EXCHANGED);
return super.commitTransferTransaction(peer, transaction);
}
use of org.apache.nifi.remote.io.http.HttpServerCommunicationsSession in project nifi by apache.
the class StandardHttpFlowFileServerProtocol method holdTransaction.
private int holdTransaction(Peer peer, FlowFileTransaction transaction) {
// We don't commit the session here yet,
// to avoid losing sent flow files in case some issue happens at client side while it is processing,
// hold the transaction until we confirm additional request from client.
HttpServerCommunicationsSession commSession = (HttpServerCommunicationsSession) peer.getCommunicationsSession();
String transactionId = commSession.getTransactionId();
logger.debug("{} Holding transaction. transactionId={}", this, transactionId);
transactionManager.holdTransaction(transactionId, transaction, handshakeProperties);
return transaction.getFlowFilesSent().size();
}
use of org.apache.nifi.remote.io.http.HttpServerCommunicationsSession in project nifi by apache.
the class TestHttpFlowFileServerProtocol method testPortDestinationFull.
@Test
public void testPortDestinationFull() throws Exception {
final HttpFlowFileServerProtocol serverProtocol = getDefaultHttpFlowFileServerProtocol();
final Peer peer = getDefaultPeer();
((HttpServerCommunicationsSession) peer.getCommunicationsSession()).putHandshakeParam(HandshakeProperty.PORT_IDENTIFIER, "port-identifier");
final ProcessGroup processGroup = mock(ProcessGroup.class);
final RootGroupPort port = mock(RootGroupPort.class);
final PortAuthorizationResult authResult = mock(PortAuthorizationResult.class);
doReturn(true).when(processGroup).isRootGroup();
doReturn(port).when(processGroup).getOutputPort("port-identifier");
doReturn(authResult).when(port).checkUserAuthorization(any(String.class));
doReturn(true).when(authResult).isAuthorized();
doReturn(true).when(port).isValid();
doReturn(true).when(port).isRunning();
final Set<Connection> connections = new HashSet<>();
final Connection connection = mock(Connection.class);
connections.add(connection);
doReturn(connections).when(port).getConnections();
final FlowFileQueue flowFileQueue = mock(FlowFileQueue.class);
doReturn(flowFileQueue).when(connection).getFlowFileQueue();
doReturn(true).when(flowFileQueue).isFull();
serverProtocol.setRootProcessGroup(processGroup);
try {
serverProtocol.handshake(peer);
fail();
} catch (final HandshakeException e) {
assertEquals(ResponseCode.PORTS_DESTINATION_FULL, e.getResponseCode());
}
assertFalse(serverProtocol.isHandshakeSuccessful());
}
Aggregations