Search in sources :

Example 11 with HttpFlowFileServerProtocol

use of org.apache.nifi.remote.protocol.http.HttpFlowFileServerProtocol in project nifi by apache.

the class TestDataTransferResource method testReceiveZeroFlowFiles.

@Test
public void testReceiveZeroFlowFiles() throws Exception {
    final HttpServletRequest req = createCommonHttpServletRequest();
    final DataTransferResource resource = getDataTransferResource();
    final HttpFlowFileServerProtocol serverProtocol = resource.getHttpFlowFileServerProtocol(null);
    final RootGroupPort port = mock(RootGroupPort.class);
    doReturn(port).when(serverProtocol).getPort();
    doAnswer(invocation -> 0).when(port).receiveFlowFiles(any(Peer.class), any());
    final ServletContext context = null;
    final InputStream inputStream = null;
    final HttpRemoteSiteListener transactionManager = HttpRemoteSiteListener.getInstance(NiFiProperties.createBasicNiFiProperties(null, null));
    final String transactionId = transactionManager.createTransaction();
    final Response response = resource.receiveFlowFiles("port-id", transactionId, req, context, inputStream);
    transactionManager.cancelTransaction(transactionId);
    assertEquals(400, response.getStatus());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) RootGroupPort(org.apache.nifi.remote.RootGroupPort) InputStream(java.io.InputStream) Peer(org.apache.nifi.remote.Peer) HttpRemoteSiteListener(org.apache.nifi.remote.HttpRemoteSiteListener) HttpFlowFileServerProtocol(org.apache.nifi.remote.protocol.http.HttpFlowFileServerProtocol) ServletContext(javax.servlet.ServletContext) Test(org.junit.Test)

Example 12 with HttpFlowFileServerProtocol

use of org.apache.nifi.remote.protocol.http.HttpFlowFileServerProtocol in project nifi by apache.

the class TestDataTransferResource method testReceiveFlowFiles.

@Test
public void testReceiveFlowFiles() throws Exception {
    final HttpServletRequest req = createCommonHttpServletRequest();
    final DataTransferResource resource = getDataTransferResource();
    final HttpFlowFileServerProtocol serverProtocol = resource.getHttpFlowFileServerProtocol(null);
    final RootGroupPort port = mock(RootGroupPort.class);
    doReturn(port).when(serverProtocol).getPort();
    doAnswer(invocation -> {
        Peer peer = (Peer) invocation.getArguments()[0];
        ((HttpServerCommunicationsSession) peer.getCommunicationsSession()).setChecksum("server-checksum");
        return 7;
    }).when(port).receiveFlowFiles(any(Peer.class), any());
    final ServletContext context = null;
    final InputStream inputStream = null;
    final HttpRemoteSiteListener transactionManager = HttpRemoteSiteListener.getInstance(NiFiProperties.createBasicNiFiProperties(null, null));
    final String transactionId = transactionManager.createTransaction();
    final Response response = resource.receiveFlowFiles("port-id", transactionId, req, context, inputStream);
    transactionManager.cancelTransaction(transactionId);
    final Object entity = response.getEntity();
    assertEquals(202, response.getStatus());
    assertEquals("server-checksum", entity);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) HttpServerCommunicationsSession(org.apache.nifi.remote.io.http.HttpServerCommunicationsSession) RootGroupPort(org.apache.nifi.remote.RootGroupPort) InputStream(java.io.InputStream) Peer(org.apache.nifi.remote.Peer) HttpRemoteSiteListener(org.apache.nifi.remote.HttpRemoteSiteListener) HttpFlowFileServerProtocol(org.apache.nifi.remote.protocol.http.HttpFlowFileServerProtocol) ServletContext(javax.servlet.ServletContext) Test(org.junit.Test)

Aggregations

HttpFlowFileServerProtocol (org.apache.nifi.remote.protocol.http.HttpFlowFileServerProtocol)12 HandshakeException (org.apache.nifi.remote.exception.HandshakeException)8 InputStream (java.io.InputStream)6 ServletContext (javax.servlet.ServletContext)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 Response (javax.ws.rs.core.Response)6 Peer (org.apache.nifi.remote.Peer)6 TransactionResultEntity (org.apache.nifi.web.api.entity.TransactionResultEntity)6 Test (org.junit.Test)6 StandardHttpFlowFileServerProtocol (org.apache.nifi.remote.protocol.http.StandardHttpFlowFileServerProtocol)5 ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponses (io.swagger.annotations.ApiResponses)4 IOException (java.io.IOException)4 UnknownHostException (java.net.UnknownHostException)4 Consumes (javax.ws.rs.Consumes)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 AccessDeniedException (org.apache.nifi.authorization.AccessDeniedException)4