ijokarumawak commented on a change in pull request #3647: NIFI-6530 - HTTP
SiteToSite server returns 201 in case no data is ava…
URL: https://github.com/apache/nifi/pull/3647#discussion_r313302446
##########
File path:
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/DataTransferResource.java
##########
@@ -205,9 +207,17 @@ public Response createPortTransaction(
final int transportProtocolVersion =
validationResult.transportProtocolVersion;
try {
- // Execute handshake.
- initiateServerProtocol(req, peer, transportProtocolVersion);
+ HttpFlowFileServerProtocol serverProtocol =
initiateServerProtocol(req, peer, transportProtocolVersion);
+ if (PORT_TYPE_OUTPUT.equals(portType)) {
+ List<Connection> connectionList =
serverProtocol.getPort().getIncomingConnections();
+ if (connectionList.stream().allMatch(c ->
c.getFlowFileQueue().isEmpty())) {
+ // Transaction could be created, but there is nothing to
transfer. Just return 200.
+ logger.debug("Output port has no flowfiles to transfer,
returning 200");
Review comment:
I agree with the idea of using 204 in this case. Regardless of using 200 or
204, current Java HTTP S2S client will treat such response codes as unexpected
and throws an exception. Then users will see following error message:

In order to make this improvement happen while supporting old S2S clients, I
think we need to:
- Update Java HTTP S2S client, too, to properly handle 204. Let's use 204
since we increase protocol version.
- Increase HTTP S2S protocol version from 1 to 2. Please refer:
- 'Protocol version management' at this [wiki
page](https://cwiki.apache.org/confluence/display/NIFI/Support+HTTP%28S%29+as+a+transport+mechanism+for+Site-to-Site)
- You can find related code by searching usage of [this
constant](https://github.com/apache/nifi/blob/master/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/http/HttpHeaders.java#L27)
- Return 204 only for clients using protocol version 2 or higher. Keep
acting the same for older clients.
This requires more changes than I thought, but will provide ideal response
code (204) and backward compatibility. How do you think?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services