IBM / ibm-cos-sdk-java

ibm-cos-sdk-java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

null Token causes NPE

roryodonnell opened this issue · comments

		tokenExpiresInSecs = Integer.parseInt(token.getExpires_in());
ERROR [2018-05-11 08:21:17,497] io.dropwizard.jersey.errors.LoggingExceptionMapper: Error handling a request: 29b2039092d5264c
! java.lang.NullPointerException: null
! at com.ibm.cloud.objectstorage.oauth.DefaultTokenManager.cacheToken(DefaultTokenManager.java:246)
! at com.ibm.cloud.objectstorage.oauth.DefaultTokenManager.retrieveToken(DefaultTokenManager.java:375)
! at com.ibm.cloud.objectstorage.oauth.DefaultTokenManager.getToken(DefaultTokenManager.java:190)
! at com.ibm.cloud.objectstorage.oauth.IBMOAuthSigner.sign(IBMOAuthSigner.java:40)
! at com.ibm.cloud.objectstorage.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1164)
! at com.ibm.cloud.objectstorage.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1030)
! at com.ibm.cloud.objectstorage.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:742)
! at com.ibm.cloud.objectstorage.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:716)
! at com.ibm.cloud.objectstorage.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:699)
! at com.ibm.cloud.objectstorage.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:667)
! at com.ibm.cloud.objectstorage.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:649)

Hi @roryodonnell we'll look into this. It should be handled better. Were you running normal IAM authentication flow or have you written any custom token provider implementation? Also, what version of the SDK are you using?

Using this code from the Wiki

    public static AmazonS3 getS3Client(ObjectStorageConfig config, boolean keepConnectionAlive) {
        AWSCredentials credentials = null;
        if (config.getEndpoint().contains("objectstorage.softlayer.net")) {
            credentials = new BasicIBMOAuthCredentials(config.getAccessKey(), config.getSecretKey());
        }
        else {
            credentials = new BasicAWSCredentials(config.getAccessKey(), config.getSecretKey());
        }

        ClientConfiguration clientConfig = new ClientConfiguration().withRequestTimeout(config.getRequestTimeout());
        clientConfig.setUseTcpKeepAlive(keepConnectionAlive);

        AmazonS3 cos = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials))
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(config.getEndpoint(), config.getRegion()))
                .withPathStyleAccessEnabled(true).withClientConfiguration(clientConfig).build();
        return cos;
    }

Using this endpoint -> s3.us-south.objectstorage.softlayer.net along with the apiKey and resource_instance_id. Funny thing is, it works locally from Eclipse, but fails under a local minikube deployment

    <dependency>
        <groupId>com.ibm.cos</groupId>
        <artifactId>ibm-cos-java-sdk</artifactId>
        <version>2.1.0</version>
    </dependency>

Looks like it is failing to retrieve a token, although it should handle the null object better. Can you reach https://iam.ng.bluemix.net/oidc/token from within minikube?

haven't tried that - just a fyi

@roryodonnell did you get connectivity within minikube to the token endpoint? If so, did it resolve your issue?

I'm not sure - didn't dig into it too much. It could have been a temporary connection issue with cos - but as you say - the main point is to direct you to the unhandled NPE exception

ok, we have an internal Jira raised - CSAFE-38356. I'll keep this github issue open too. thanks

....happy Friday!!

Hi @roryodonnell this issue has been resolved in the latest public release of the Java SDK. Version 2.1.3.

Please let us know if you have any further issues with this.