diff --git a/pom.xml b/pom.xml
index 98446b0..7e4aae9 100755
--- a/pom.xml
+++ b/pom.xml
@@ -20,7 +20,7 @@
* Invokes the feed API with the max range value of 100 MB. If the file is lesser than 100 MB, * then it returns the downloaded file path along with the status. - * + * * If the file is greater than 100 MB - Iteratively calls feed API, with incrementing range * headers - Appends content to file - Downloads entire content and returns with downloaded file * path. - * + * *
- * + * * @param request The API request * @param path Path of the downloaded or partially downloading file, where contents need to be * appended @@ -296,6 +300,27 @@ private GetFeedResponse invoker(Request.Builder requestBuilder, Path path, boole requestBuilder.removeHeader(Constants.RANGE_HEADER); requestBuilder.addHeader(Constants.RANGE_HEADER, val); + //token refresh on the fly from config file. + try { + AuthRequest authRequest = new AuthRequest(credentialFilePath, null); + CredentialLoader credentialLoader = new CredentialLoader(authRequest); + credentialLoader.loadCredentials(); + Date tokenExpireTime = credentialLoader.getOauthResponse().getAccessToken().get().getExpiresOn(); + String oldToken = credentialLoader.getOauthResponse().getAccessToken().get().getToken(); + LOGGER.info("Token :"+ oldToken + "Expiry time :"+tokenExpireTime); + Date currentTime = new Date(); + if(tokenExpireTime.before(currentTime)){ + String token = credentialLoader.getOauthResponse().getAccessToken().get().getToken(); + token = Constants.TOKEN_BEARER_PREFIX + token; + requestBuilder.removeHeader(Constants.AUTHORIZATION_HEADER); + requestBuilder.addHeader(Constants.AUTHORIZATION_HEADER, token); + } + } catch(Exception e){ + LOGGER.info("Exception in fetching the new access token"+ e.getMessage()); + return new GetFeedResponse(Constants.FAILURE_CODE, Constants.FAILURE, null, null); + } + + requestBuilder.addHeader(Constants.RANGE_HEADER, val); responseFlag = invokeIteratively(requestBuilder.build(), path); if (responseFlag == null) { @@ -324,24 +349,24 @@ private GetFeedResponse invoker(Request.Builder requestBuilder, Path path, boole * @return */ private String fixFilePath(Path originalFilePath, InvokeResponse invokeResponse) { - Path newFilePath = originalFilePath; - if(originalFilePath.toString().contains("null") && !StringUtils.isEmpty(invokeResponse.getLastModified())){ - String newPath = originalFilePath.toString().replace("null", invokeResponse.getLastModified()); - newFilePath = Paths.get(newPath); - try { - Files.move(originalFilePath, newFilePath, StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e) { - LOGGER.error("Unable to rename the bootstrap item feed file with date field", e); - } - } - return newFilePath.toString(); + Path newFilePath = originalFilePath; + if(originalFilePath.toString().contains("null") && !StringUtils.isEmpty(invokeResponse.getLastModified())){ + String newPath = originalFilePath.toString().replace("null", invokeResponse.getLastModified()); + newFilePath = Paths.get(newPath); + try { + Files.move(originalFilePath, newFilePath, StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + LOGGER.error("Unable to rename the bootstrap item feed file with date field", e); + } + } + return newFilePath.toString(); } - + /** ** Invoked, only if the file size is greater than max chunk size *
- * + * * @param request The API request * @param path Path of the downloaded or partially downloading file, where contents need to be * appended @@ -374,23 +399,23 @@ private InvokeResponse invokeIteratively(Request request, Path path) { String lastModifiedHeader = response.header(Constants.LAST_MODIFIED_DATE_HEADER); String lastModifiedDate = null; if(!StringUtils.isEmpty(lastModifiedHeader)){ - LocalDate localDate = LocalDate.parse(lastModifiedHeader, DateTimeFormatter.RFC_1123_DATE_TIME); - lastModifiedDate = localDate.format(DateTimeFormatter.BASIC_ISO_DATE); + LocalDate localDate = LocalDate.parse(lastModifiedHeader, DateTimeFormatter.RFC_1123_DATE_TIME); + lastModifiedDate = localDate.format(DateTimeFormatter.BASIC_ISO_DATE); } responseFlag = new InvokeResponse(response.header(Constants.CONTENT_RANGE_HEADER), response.code(), lastModifiedDate); } catch (Throwable t) { - LOGGER.error("Exception in feed.invokeIteratively()", t); - responseFlag = new InvokeResponse(null, 400); + LOGGER.error("Exception in feed.invokeIteratively()", t); + responseFlag = new InvokeResponse(null, 400); } return responseFlag; } /* * (non-Javadoc) - * + * * @see com.ebay.feed.api.Feed#processConfigFile(java.lang.String, java.lang.String) */ @Override @@ -496,7 +521,7 @@ public List* Returns a new instance of response, based on the provided inputs *
- * + * * @param statusCode * @param message * @param filePath @@ -513,4 +538,4 @@ private com.ebay.feed.model.feed.operation.filter.Response createResponse(Intege return new com.ebay.feed.model.feed.operation.filter.Response(statusCode, message, filePath, appliedFilters); } -} +} \ No newline at end of file