Skip to content

Commit

Permalink
Merge pull request data-integrations#23 from cloudsufi/bugfix/1367
Browse files Browse the repository at this point in the history
Bugfix for the error messages.
  • Loading branch information
Shubhangi-cs authored Jul 10, 2023
2 parents af1cae5 + 458952f commit 6fc4093
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/main/java/io/cdap/plugin/ariba/source/AribaServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,9 @@ protected Request buildFetchRequest(URL endPoint, String accessToken) {
*/
public Response executeRequest(Request req) throws AribaException, InterruptedException, IOException {
OkHttpClient enhancedOkHttpClient = getConfiguredClient().build();
Response response = enhancedOkHttpClient.newCall(req).execute();
Response response = null;
try {
response = enhancedOkHttpClient.newCall(req).execute();
if (response.code() != HttpURLConnection.HTTP_OK && AribaUtil.isNullOrEmpty(response.message())) {
AribaResponseContainer responseContainer = aribaResponse(response);
InputStream responseStream = responseContainer.getResponseBody();
Expand All @@ -643,11 +645,16 @@ public Response executeRequest(Request req) throws AribaException, InterruptedEx
checkAndThrowException(response);
return response;
} else {
return enhancedOkHttpClient.newCall(req).execute();
response = enhancedOkHttpClient.newCall(req).execute();
}
} catch (IOException e) {
throw new IOException("Endpoint is incorrect. Unable to validate the source with the provided.", e);
}

/**
return response;
}

/**
* @param jobId Ariba Job Id
* @return JsonNode
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ public AribaConnector(AribaConnectorConfig config) {
public void test(ConnectorContext connectorContext) throws ValidationException {
FailureCollector collector = connectorContext.getFailureCollector();
config.validateCredentials(collector);
collector.getOrThrowException();
config.validateToken(collector);
collector.getOrThrowException();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.cdap.cdap.etl.api.connector.ConnectorSpecRequest;
import io.cdap.cdap.etl.api.connector.PluginSpec;
import io.cdap.cdap.etl.api.connector.SampleRequest;
import io.cdap.cdap.etl.api.validation.ValidationException;
import io.cdap.cdap.etl.mock.common.MockConnectorConfigurer;
import io.cdap.cdap.etl.mock.common.MockConnectorContext;
import io.cdap.cdap.etl.mock.validation.MockFailureCollector;
Expand Down Expand Up @@ -307,8 +308,12 @@ public void testValidateTokenWithInvalidResponse() throws AribaException, IOExce

private void testTest(AribaConnector connector) {
ConnectorContext context = new MockConnectorContext(new MockConnectorConfigurer());
connector.test(context);
Assert.assertEquals(1, context.getFailureCollector().getValidationFailures().size());
try {
connector.test(context);
Assert.fail("Exception will not thrown if credentials are correct");
} catch (ValidationException e) {
Assert.assertEquals(1, context.getFailureCollector().getValidationFailures().size());
}
}

@Test
Expand Down

0 comments on commit 6fc4093

Please sign in to comment.