use of org.apache.nifi.remote.codec.StandardFlowFileCodec in project nifi by apache.
the class TestHttpFlowFileServerProtocol method testShutdown.
@Test
public void testShutdown() throws Exception {
final HttpFlowFileServerProtocol serverProtocol = getDefaultHttpFlowFileServerProtocol();
final Peer peer = getDefaultPeer();
serverProtocol.handshake(peer);
assertTrue(serverProtocol.isHandshakeSuccessful());
final FlowFileCodec negotiatedCoded = serverProtocol.negotiateCodec(peer);
assertTrue(negotiatedCoded instanceof StandardFlowFileCodec);
assertEquals(negotiatedCoded, serverProtocol.getPreNegotiatedCodec());
assertEquals(1234, serverProtocol.getRequestExpiration());
serverProtocol.shutdown(peer);
final ProcessContext context = null;
final ProcessSession processSession = null;
try {
serverProtocol.transferFlowFiles(peer, context, processSession, negotiatedCoded);
fail("transferFlowFiles should fail since it's already shutdown.");
} catch (final IllegalStateException e) {
}
try {
serverProtocol.receiveFlowFiles(peer, context, processSession, negotiatedCoded);
fail("receiveFlowFiles should fail since it's already shutdown.");
} catch (final IllegalStateException e) {
}
}
use of org.apache.nifi.remote.codec.StandardFlowFileCodec in project nifi by apache.
the class TestHttpClient method readIncomingPacket.
private static DataPacket readIncomingPacket(HttpServletRequest req) throws IOException {
final StandardFlowFileCodec codec = new StandardFlowFileCodec();
InputStream inputStream = req.getInputStream();
if (Boolean.valueOf(req.getHeader(HttpHeaders.HANDSHAKE_PROPERTY_USE_COMPRESSION))) {
inputStream = new CompressionInputStream(inputStream);
}
return codec.decode(inputStream);
}
use of org.apache.nifi.remote.codec.StandardFlowFileCodec in project nifi by apache.
the class SocketClientProtocol method negotiateCodec.
@Override
public FlowFileCodec negotiateCodec(final Peer peer) throws IOException, ProtocolException {
if (!handshakeComplete) {
throw new IllegalStateException("Handshake has not been performed");
}
logger.debug("{} Negotiating Codec with {}", this, peer);
final CommunicationsSession commsSession = peer.getCommunicationsSession();
final DataInputStream dis = new DataInputStream(commsSession.getInput().getInputStream());
final DataOutputStream dos = new DataOutputStream(commsSession.getOutput().getOutputStream());
RequestType.NEGOTIATE_FLOWFILE_CODEC.writeRequestType(dos);
FlowFileCodec codec = new StandardFlowFileCodec();
try {
codec = (FlowFileCodec) RemoteResourceInitiator.initiateResourceNegotiation(codec, dis, dos);
} catch (HandshakeException e) {
throw new ProtocolException(e.toString());
}
logger.debug("{} negotiated FlowFileCodec {} with {}", new Object[] { this, codec, commsSession });
return codec;
}
use of org.apache.nifi.remote.codec.StandardFlowFileCodec in project nifi by apache.
the class TestHttpClient method writeOutgoingPacket.
private static void writeOutgoingPacket(OutputStream outputStream) throws IOException {
final DataPacket packet = new DataPacketBuilder().contents("Example contents from server.").attr("Server attr 1", "Server attr 1 value").attr("Server attr 2", "Server attr 2 value").build();
new StandardFlowFileCodec().encode(packet, outputStream);
outputStream.flush();
}
Aggregations