Excel Sheet Generator and Converter REST API Solution Aspose.Cells REST API authorization issue in Java SDK

We are using Cells Java SDK 20.1(https://repository.aspose.cloud/repo/com/aspose/aspose-cells-cloud/20.1/) to invoke Cells API.

We are encountering Unauthorized exception while using above SDK. Following is the stack trace.

com.aspose.cloud.cells.client.ApiException: Unauthorized
at com.aspose.cloud.cells.client.ApiClient.handleResponse(ApiClient.java:1133)
at com.aspose.cloud.cells.client.ApiClient.execute(ApiClient.java:1049)
at com.aspose.cloud.cells.api.CellsApi.uploadFileWithHttpInfo(CellsApi.java:40002)
at com.aspose.cloud.cells.api.CellsApi.uploadFile(CellsApi.java:39986)

Please suggest on how to resolve this.

@flockfilesharing

Thanks for your inquiry. We have noticed the issue and logged a ticket CELLSCLOUD-10279 for further investigation. We will notify you as soon as it is resolved.

@flockfilesharing

Thanks for your patience. Please double check you are passing correct credentials. Please note first parameter for CellsApi method is App SID and App Key is second parameter. Please check following sample code for reference.

File file = new File("C:/Temp/test.xlsx");
    try {
    	 CellsApi api = new CellsApi(aapSID,aapKey);
        //api = new CellsApi(Utils.GetClientId(),Utils.GetClientSecret());
        api.uploadFile( "test.xlsx", file, null);
        System.out.print("done");
    } catch (ApiException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
1 Like

Yes, I am passing correct credentials as per the mentioned order.

It work’s fine for sometime and later on we get the error as “Unauthorized”. We don’t re-initialise the “CellsApi” for every request. I think probably the issue is with the access token on the Java SDK.

Please let me know on how to address this.

@flockfilesharing

Thanks for your feedback. I’m afraid it is difficult to suggest you anything without replicating the issue at our end. We will appreciate it if you please share your sample code and file along with your observation to replicate the issue.

Furthermore, please also check and share the error details from the My Usage tab of your aspose.cloud dashboard .

Here is the code that I use to upload a cells file using Cells API

try {
        filesUploadResult = this.cellsApi.uploadFile(fileName, file, STORAGE_NAME);
    } catch (com.aspose.cloud.cells.client.ApiException e) {
        if (e.getLocalizedMessage().contains("Unauthorized")) {
            logger.warn("Re initializing cells API for file:{} due to error", fileName, e);
            this.initializeCellApi();
            filesUploadResult = this.cellsApi.uploadFile(fileName, file, STORAGE_NAME);
        }
    }

Following is the error logged in my system while there is an “Unauthorized” exception from cellsAPI.

    p.s.f.s.a.AsposeCloudService - Re initializing cells API for file:d63ff0f1580902460a633240.xls due to error
com.aspose.cloud.cells.client.ApiException: Unauthorized
	at com.aspose.cloud.cells.client.ApiClient.handleResponse(ApiClient.java:1133)
	at com.aspose.cloud.cells.client.ApiClient.execute(ApiClient.java:1049)
	at com.aspose.cloud.cells.api.CellsApi.uploadFileWithHttpInfo(CellsApi.java:40002)
	at com.aspose.cloud.cells.api.CellsApi.uploadFile(CellsApi.java:39986)
	at pw.server.filesharing.service.aspose.AsposeCloudService.uploadCellsFile(AsposeCloudService.java:137)
	at pw.server.filesharing.service.aspose.AsposeCloudService.processXlsAndCsv(AsposeCloudService.java:115)

I have verified the usage log and found something strange for the same file id “d63ff0f1580902460a633240”, that I have tried to upload using cellsAPI.

Screen Shot 2020-02-07 at 10.55.28 AM.png (305.6 KB)

The UnAuthorized exception that I have got earlier is from the “cellsApi.uploadFile” method, where as in your usage log it shows as error while GetPageConvertToJpeg from PDF API due to invalid token.

Please help to check this and revert back.

@flockfilesharing

Thanks for sharing the sample code but I’m afraid I’m unable to reproduce the issue. We will appreceiate it if you please share a sample Java project to replicate issue at our end. Furthermore, please note JSON Web Token expires after 24 hours(86400 secs).

Please double check, you or your colleague must be using Aspose.PDF Cloud API as well with same file name. So you are getting the logs of Aspose.PDF Cloud API calls.

Thanks for sharing the sample code but I’m afraid I’m unable to reproduce the issue. We will 
appreceiate it if you please share a sample Java project to replicate issue at our end. Furthermore, 
please note JSON Web Token expires after 24 hours(86400 secs).`

Doesn’t the “CellsApi” refresh the JWT once it expires?

@flockfilesharing
Yes, Aspose.Cells Cloud SDKs don’t refresh token. You need to take care if it.

@flockfilesharing

We have logged a new feature request(CELLSCLOUD-10283) to refresh expired token automatically in Aspose.Cells Cloud SDK for Java. We will update you as soon as it is resolved.

@flockfilesharing

Thanks for your patience. Please note above reported issue(CELLSCLOUD-10283) is resolved. Please download latest Aspose.Cells Cloud SDK for Java, it includes feature to automatically refresh authorization Token.