dan-s1 commented on code in PR #8484:
URL: https://github.com/apache/nifi/pull/8484#discussion_r1546454088
##########
nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/test/java/org/apache/nifi/lookup/TestRestLookupService.java:
##########
@@ -170,6 +171,30 @@ void testLookupRecordFoundPostMethod() throws Exception {
assertPostRecordedRequestFound();
}
+ @Test
+ void testLookupErrorPassThrough() throws Exception {
+ runner.setProperty(restLookupService,
RestLookupService.PROP_RESPONSE_CODE_HANDLING,
ResponseHandlingStrategy.RETURNED);
+ runner.enableControllerService(restLookupService);
+
+ when(recordReaderFactory.createRecordReader(any(), any(), anyLong(),
any())).thenReturn(recordReader);
+ when(recordReader.nextRecord()).thenReturn(record);
+
+ mockWebServer.enqueue(new
MockResponse().setResponseCode(HTTP_NOT_FOUND)
+ .setHeader("Content-type", "application/json")
+ .setBody("{\"error\": { \"code\": 404 } }"));
+
+ final Optional<Record> recordFound =
restLookupService.lookup(Collections.emptyMap());
+ assertTrue(recordFound.isPresent());
+ }
Review Comment:
```suggestion
}
```
##########
nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/test/java/org/apache/nifi/lookup/TestRestLookupService.java:
##########
@@ -170,6 +171,30 @@ void testLookupRecordFoundPostMethod() throws Exception {
assertPostRecordedRequestFound();
}
+ @Test
+ void testLookupErrorPassThrough() throws Exception {
+ runner.setProperty(restLookupService,
RestLookupService.PROP_RESPONSE_CODE_HANDLING,
ResponseHandlingStrategy.RETURNED);
+ runner.enableControllerService(restLookupService);
+
+ when(recordReaderFactory.createRecordReader(any(), any(), anyLong(),
any())).thenReturn(recordReader);
+ when(recordReader.nextRecord()).thenReturn(record);
+
+ mockWebServer.enqueue(new
MockResponse().setResponseCode(HTTP_NOT_FOUND)
+ .setHeader("Content-type", "application/json")
+ .setBody("{\"error\": { \"code\": 404 } }"));
+
+ final Optional<Record> recordFound =
restLookupService.lookup(Collections.emptyMap());
+ assertTrue(recordFound.isPresent());
+ }
+ @Test
+ void testLookupErrorHandle() {
+ runner.setProperty(restLookupService,
RestLookupService.PROP_RESPONSE_CODE_HANDLING,
ResponseHandlingStrategy.EVALUATED);
+ runner.enableControllerService(restLookupService);
+ mockWebServer.enqueue(new
MockResponse().setResponseCode(HTTP_NOT_FOUND));
+
+ final LookupFailureException exception =
assertThrows(LookupFailureException.class, () ->
restLookupService.lookup(Collections.emptyMap()));
+ assertInstanceOf(IOException.class, exception.getCause());
+ }
Review Comment:
```suggestion
}
```
##########
nifi-nar-bundles/nifi-standard-services/nifi-lookup-services-bundle/nifi-lookup-services/src/main/java/org/apache/nifi/lookup/RestLookupService.java:
##########
@@ -172,6 +172,17 @@ public class RestLookupService extends
AbstractControllerService implements Reco
.addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
.build();
+
+ public static final PropertyDescriptor RESPONSE_HANDLING_STRATEGY = new
PropertyDescriptor.Builder()
+ .name("rest-lookup-response-code-handling")
+ .displayName("Response Code Handling Strategy")
+ .description("How to handle response codes from remote service.
'Pass-through' sends successful and unsuccessful HTTP responses to the caller.
" +
+ "'Handle Service Errors' generates an exception when an
unsuccessful HTTP response code is received.")
+ .required(true)
+ .defaultValue(ResponseHandlingStrategy.RETURNED)
+ .allowableValues(ResponseHandlingStrategy.RETURNED,
ResponseHandlingStrategy.EVALUATED)
Review Comment:
```suggestion
.allowableValues(ResponseHandlingStrategy.class)
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]