@Test public void failOnNull() { TransmissionPolicyManager tpm = new TransmissionPolicyManager(true); TransmissionHandlerArgs args = new TransmissionHandlerArgs(); ErrorHandler eh = new ErrorHandler(tpm); boolean result = eh.validateTransmissionAndSend(args); Assert.assertFalse(result); }
boolean validateTransmissionAndSend(TransmissionHandlerArgs args) { if (args.getTransmission() != null && args.getTransmissionDispatcher() != null) { switch (args.getResponseCode()) { case HttpStatus.SC_PARTIAL_CONTENT: BackendResponse backendResponse = getBackendResponse(args.getResponseBody()); List<String> originalItems = generateOriginalItems(args); if (backendResponse != null && (originalItems.size() != backendResponse.itemsReceived)) { logger.trace( "Skipping partial content handler due to itemsReceived being larger than the items sent."); return false; } if (backendResponse != null && (backendResponse.itemsAccepted < backendResponse.itemsReceived)) { List<String> newTransmission = new ArrayList<String>(); for (BackendResponse.Error e : backendResponse.errors) { switch (e.statusCode) { case TransmissionSendResult.REQUEST_TIMEOUT: case TransmissionSendResult.INTERNAL_SERVER_ERROR: case TransmissionSendResult.SERVICE_UNAVAILABLE: case TransmissionSendResult.THROTTLED: case TransmissionSendResult.THROTTLED_OVER_EXTENDED_TIME: if (e.index < originalItems.size()) { newTransmission.add(originalItems.get(e.index)); } break; } } return sendNewTransmissionFromStrings(args, newTransmission); } logger .trace("Skipping partial content handler due to itemsAccepted and itemsReceived being equal."); return false; default: logger.trace("Http response code {} not handled by {}", args.getResponseCode(), this.getClass().getName()); return false; } } return false; }
PartialSuccessHandler implements TransmissionHandler { boolean validateTransmissionAndSend(TransmissionHandlerArgs args) { if (args.getTransmission() != null && args.getTransmissionDispatcher() != null) { switch (args.getResponseCode()) { case HttpStatus.SC_PARTIAL_CONTENT: BackendResponse backendResponse = getBackendResponse(args.getResponseBody()); List<String> originalItems = generateOriginalItems(args); if (backendResponse != null && (originalItems.size() != backendResponse.itemsReceived)) { logger.trace( "Skipping partial content handler due to itemsReceived being larger than the items sent."); return false; } if (backendResponse != null && (backendResponse.itemsAccepted < backendResponse.itemsReceived)) { List<String> newTransmission = new ArrayList<String>(); for (BackendResponse.Error e : backendResponse.errors) { switch (e.statusCode) { case TransmissionSendResult.REQUEST_TIMEOUT: case TransmissionSendResult.INTERNAL_SERVER_ERROR: case TransmissionSendResult.SERVICE_UNAVAILABLE: case TransmissionSendResult.THROTTLED: case TransmissionSendResult.THROTTLED_OVER_EXTENDED_TIME: if (e.index < originalItems.size()) { newTransmission.add(originalItems.get(e.index)); } break; } } return sendNewTransmissionFromStrings(args, newTransmission); } logger .trace("Skipping partial content handler due to itemsAccepted and itemsReceived being equal."); return false; default: logger.trace("Http response code {} not handled by {}", args.getResponseCode(), this.getClass().getName()); return false; } } return false; } }
PartialSuccessHandler implements TransmissionHandler { boolean validateTransmissionAndSend(TransmissionHandlerArgs args) { if (args.getTransmission() != null && args.getTransmissionDispatcher() != null) { switch (args.getResponseCode()) { case HttpStatus.SC_PARTIAL_CONTENT: BackendResponse backendResponse = getBackendResponse(args.getResponseBody()); List<String> originalItems = generateOriginalItems(args); if (backendResponse != null && (originalItems.size() != backendResponse.itemsReceived)) { logger.trace( "Skipping partial content handler due to itemsReceived being larger than the items sent."); return false; } if (backendResponse != null && (backendResponse.itemsAccepted < backendResponse.itemsReceived)) { List<String> newTransmission = new ArrayList<String>(); for (BackendResponse.Error e : backendResponse.errors) { switch (e.statusCode) { case TransmissionSendResult.REQUEST_TIMEOUT: case TransmissionSendResult.INTERNAL_SERVER_ERROR: case TransmissionSendResult.SERVICE_UNAVAILABLE: case TransmissionSendResult.THROTTLED: case TransmissionSendResult.THROTTLED_OVER_EXTENDED_TIME: if (e.index < originalItems.size()) { newTransmission.add(originalItems.get(e.index)); } break; } } return sendNewTransmissionFromStrings(args, newTransmission); } logger .trace("Skipping partial content handler due to itemsAccepted and itemsReceived being equal."); return false; default: logger.trace("Http response code {} not handled by {}", args.getResponseCode(), this.getClass().getName()); return false; } } return false; } PartialSuccessHandler(TransmissionPolicyManager policy); }
PartialSuccessHandler implements TransmissionHandler { boolean validateTransmissionAndSend(TransmissionHandlerArgs args) { if (args.getTransmission() != null && args.getTransmissionDispatcher() != null) { switch (args.getResponseCode()) { case HttpStatus.SC_PARTIAL_CONTENT: BackendResponse backendResponse = getBackendResponse(args.getResponseBody()); List<String> originalItems = generateOriginalItems(args); if (backendResponse != null && (originalItems.size() != backendResponse.itemsReceived)) { logger.trace( "Skipping partial content handler due to itemsReceived being larger than the items sent."); return false; } if (backendResponse != null && (backendResponse.itemsAccepted < backendResponse.itemsReceived)) { List<String> newTransmission = new ArrayList<String>(); for (BackendResponse.Error e : backendResponse.errors) { switch (e.statusCode) { case TransmissionSendResult.REQUEST_TIMEOUT: case TransmissionSendResult.INTERNAL_SERVER_ERROR: case TransmissionSendResult.SERVICE_UNAVAILABLE: case TransmissionSendResult.THROTTLED: case TransmissionSendResult.THROTTLED_OVER_EXTENDED_TIME: if (e.index < originalItems.size()) { newTransmission.add(originalItems.get(e.index)); } break; } } return sendNewTransmissionFromStrings(args, newTransmission); } logger .trace("Skipping partial content handler due to itemsAccepted and itemsReceived being equal."); return false; default: logger.trace("Http response code {} not handled by {}", args.getResponseCode(), this.getClass().getName()); return false; } } return false; } PartialSuccessHandler(TransmissionPolicyManager policy); @Override void onTransmissionSent(TransmissionHandlerArgs args); }
PartialSuccessHandler implements TransmissionHandler { boolean validateTransmissionAndSend(TransmissionHandlerArgs args) { if (args.getTransmission() != null && args.getTransmissionDispatcher() != null) { switch (args.getResponseCode()) { case HttpStatus.SC_PARTIAL_CONTENT: BackendResponse backendResponse = getBackendResponse(args.getResponseBody()); List<String> originalItems = generateOriginalItems(args); if (backendResponse != null && (originalItems.size() != backendResponse.itemsReceived)) { logger.trace( "Skipping partial content handler due to itemsReceived being larger than the items sent."); return false; } if (backendResponse != null && (backendResponse.itemsAccepted < backendResponse.itemsReceived)) { List<String> newTransmission = new ArrayList<String>(); for (BackendResponse.Error e : backendResponse.errors) { switch (e.statusCode) { case TransmissionSendResult.REQUEST_TIMEOUT: case TransmissionSendResult.INTERNAL_SERVER_ERROR: case TransmissionSendResult.SERVICE_UNAVAILABLE: case TransmissionSendResult.THROTTLED: case TransmissionSendResult.THROTTLED_OVER_EXTENDED_TIME: if (e.index < originalItems.size()) { newTransmission.add(originalItems.get(e.index)); } break; } } return sendNewTransmissionFromStrings(args, newTransmission); } logger .trace("Skipping partial content handler due to itemsAccepted and itemsReceived being equal."); return false; default: logger.trace("Http response code {} not handled by {}", args.getResponseCode(), this.getClass().getName()); return false; } } return false; } PartialSuccessHandler(TransmissionPolicyManager policy); @Override void onTransmissionSent(TransmissionHandlerArgs args);  }