Search in sources :

Example 6 with HttpRemoteSiteListener

use of org.apache.nifi.remote.HttpRemoteSiteListener in project nifi by apache.

the class TestDataTransferResource method testCommitInputPortTransaction.

@Test
public void testCommitInputPortTransaction() throws Exception {
    final HttpServletRequest req = createCommonHttpServletRequest();
    final DataTransferResource resource = getDataTransferResource();
    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.commitInputPortTransaction(ResponseCode.CONFIRM_TRANSACTION.getCode(), "port-id", transactionId, req, context, inputStream);
    transactionManager.cancelTransaction(transactionId);
    TransactionResultEntity resultEntity = (TransactionResultEntity) response.getEntity();
    assertEquals(200, response.getStatus());
    assertEquals(ResponseCode.CONFIRM_TRANSACTION.getCode(), resultEntity.getResponseCode());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) TransactionResultEntity(org.apache.nifi.web.api.entity.TransactionResultEntity) InputStream(java.io.InputStream) HttpRemoteSiteListener(org.apache.nifi.remote.HttpRemoteSiteListener) ServletContext(javax.servlet.ServletContext) Test(org.junit.Test)

Example 7 with HttpRemoteSiteListener

use of org.apache.nifi.remote.HttpRemoteSiteListener in project nifi by apache.

the class TestDataTransferResource method testExtendTransaction.

@Test
public void testExtendTransaction() throws Exception {
    final HttpServletRequest req = createCommonHttpServletRequest();
    final DataTransferResource resource = getDataTransferResource();
    final String locationUriStr = "http://localhost:8080/nifi-api/data-transfer/input-ports/port-id/transactions/transaction-id";
    final ServletContext context = null;
    final HttpServletResponse res = null;
    final UriInfo uriInfo = mockUriInfo(locationUriStr);
    final InputStream inputStream = null;
    final HttpRemoteSiteListener transactionManager = HttpRemoteSiteListener.getInstance(NiFiProperties.createBasicNiFiProperties(null, null));
    final String transactionId = transactionManager.createTransaction();
    final Response response = resource.extendPortTransactionTTL("input-ports", "port-id", transactionId, req, res, context, uriInfo, inputStream);
    transactionManager.cancelTransaction(transactionId);
    TransactionResultEntity resultEntity = (TransactionResultEntity) response.getEntity();
    assertEquals(200, response.getStatus());
    assertEquals(ResponseCode.CONTINUE_TRANSACTION.getCode(), resultEntity.getResponseCode());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) TransactionResultEntity(org.apache.nifi.web.api.entity.TransactionResultEntity) InputStream(java.io.InputStream) HttpRemoteSiteListener(org.apache.nifi.remote.HttpRemoteSiteListener) ServletContext(javax.servlet.ServletContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 8 with HttpRemoteSiteListener

use of org.apache.nifi.remote.HttpRemoteSiteListener 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 9 with HttpRemoteSiteListener

use of org.apache.nifi.remote.HttpRemoteSiteListener 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

HttpRemoteSiteListener (org.apache.nifi.remote.HttpRemoteSiteListener)9 InputStream (java.io.InputStream)8 ServletContext (javax.servlet.ServletContext)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 Response (javax.ws.rs.core.Response)7 Test (org.junit.Test)7 TransactionResultEntity (org.apache.nifi.web.api.entity.TransactionResultEntity)4 HttpFlowFileServerProtocol (org.apache.nifi.remote.protocol.http.HttpFlowFileServerProtocol)3 Peer (org.apache.nifi.remote.Peer)2 RootGroupPort (org.apache.nifi.remote.RootGroupPort)2 FlowFileCodec (org.apache.nifi.remote.codec.FlowFileCodec)2 StandardFlowFileCodec (org.apache.nifi.remote.codec.StandardFlowFileCodec)2 HttpServerCommunicationsSession (org.apache.nifi.remote.io.http.HttpServerCommunicationsSession)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 UriInfo (javax.ws.rs.core.UriInfo)1 HandshakeException (org.apache.nifi.remote.exception.HandshakeException)1 HttpInput (org.apache.nifi.remote.io.http.HttpInput)1