Search in sources :

Example 1 with StandardFlowFileCodec

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) {
    }
}
Also used : MockProcessSession(org.apache.nifi.util.MockProcessSession) ProcessSession(org.apache.nifi.processor.ProcessSession) Peer(org.apache.nifi.remote.Peer) StandardFlowFileCodec(org.apache.nifi.remote.codec.StandardFlowFileCodec) FlowFileCodec(org.apache.nifi.remote.codec.FlowFileCodec) StandardFlowFileCodec(org.apache.nifi.remote.codec.StandardFlowFileCodec) MockProcessContext(org.apache.nifi.util.MockProcessContext) ProcessContext(org.apache.nifi.processor.ProcessContext) Test(org.junit.Test)

Example 2 with StandardFlowFileCodec

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);
}
Also used : CompressionInputStream(org.apache.nifi.remote.io.CompressionInputStream) ByteArrayInputStream(org.apache.nifi.stream.io.ByteArrayInputStream) CompressionInputStream(org.apache.nifi.remote.io.CompressionInputStream) InputStream(java.io.InputStream) StandardFlowFileCodec(org.apache.nifi.remote.codec.StandardFlowFileCodec)

Example 3 with StandardFlowFileCodec

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;
}
Also used : ProtocolException(org.apache.nifi.remote.exception.ProtocolException) DataOutputStream(java.io.DataOutputStream) StandardFlowFileCodec(org.apache.nifi.remote.codec.StandardFlowFileCodec) CommunicationsSession(org.apache.nifi.remote.protocol.CommunicationsSession) DataInputStream(java.io.DataInputStream) HandshakeException(org.apache.nifi.remote.exception.HandshakeException) FlowFileCodec(org.apache.nifi.remote.codec.FlowFileCodec) StandardFlowFileCodec(org.apache.nifi.remote.codec.StandardFlowFileCodec)

Example 4 with StandardFlowFileCodec

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();
}
Also used : StandardFlowFileCodec(org.apache.nifi.remote.codec.StandardFlowFileCodec) DataPacket(org.apache.nifi.remote.protocol.DataPacket) StandardDataPacket(org.apache.nifi.remote.util.StandardDataPacket)

Aggregations

StandardFlowFileCodec (org.apache.nifi.remote.codec.StandardFlowFileCodec)4 FlowFileCodec (org.apache.nifi.remote.codec.FlowFileCodec)2 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 InputStream (java.io.InputStream)1 ProcessContext (org.apache.nifi.processor.ProcessContext)1 ProcessSession (org.apache.nifi.processor.ProcessSession)1 Peer (org.apache.nifi.remote.Peer)1 HandshakeException (org.apache.nifi.remote.exception.HandshakeException)1 ProtocolException (org.apache.nifi.remote.exception.ProtocolException)1 CompressionInputStream (org.apache.nifi.remote.io.CompressionInputStream)1 CommunicationsSession (org.apache.nifi.remote.protocol.CommunicationsSession)1 DataPacket (org.apache.nifi.remote.protocol.DataPacket)1 StandardDataPacket (org.apache.nifi.remote.util.StandardDataPacket)1 ByteArrayInputStream (org.apache.nifi.stream.io.ByteArrayInputStream)1 MockProcessContext (org.apache.nifi.util.MockProcessContext)1 MockProcessSession (org.apache.nifi.util.MockProcessSession)1 Test (org.junit.Test)1