Skip to content

DiscoClient.getPkgInfoByEphemeralId and downloadPkg not working #20

Description

@okafke

I have tried to use DiscoClient.downloadPkg which calls DiscoClient.getPkgInfoByEphemeralId.
But I get the following error:

java.lang.NullPointerException: Cannot invoke "com.google.gson.JsonArray.size()" because "jsonArray" is null
	at io.foojay.api.discoclient@2.0.39/io.foojay.api.discoclient.DiscoClient.getPkgInfoByEphemeralId(DiscoClient.java:1556)
	at io.foojay.api.discoclient@2.0.39/io.foojay.api.discoclient.DiscoClient.downloadPkg(DiscoClient.java:1691)
	at io.foojay.api.discoclient@2.0.39/io.foojay.api.discoclient.DiscoClient.downloadPkg(DiscoClient.java:1679)

Which is a here:

JsonObject jsonObject = packageInfoElement.getAsJsonObject();
JsonArray jsonArray = jsonObject.getAsJsonArray("result");
if (jsonArray.size() > 0) {
final JsonObject packageInfoJson = jsonArray.get(0).getAsJsonObject();

The JsonObject returned by the API looks as follows:

{
  "_links": {
    "self": [
      {
        "href": "/disco/v3.0/ephemeral_ids/f7bddbcbba0e705cfa297fd965408e32",
        "templated": false
      }
    ]
  },
  "_embedded": {
    "errors": [
      {
        "message": "Page Not Found"
      }
    ]
  },
  "message": "Not Found"
}

The ephemeral_ids endpoint is also not documented in swagger.
I have tried this for basically all packages:

DiscoClient client = new DiscoClient();
        for (Distribution distribution : client.getDistributions()) {
            System.out.println(distribution.getName());
            List<Pkg> packages = client.getPkgs(
                List.of(distribution),
                new VersionNumber(25),
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null
            );

            for (Pkg pkg : packages) {
                Path path = Paths.get("test").resolve(pkg.getFileName());
                Files.createDirectories(path.getParent());
                try {
                    client.downloadPkg(pkg.getId(), path.toAbsolutePath().toString());
                    return;
                } catch (Exception e) {
                    System.out.println(distribution.getName() + " : " + pkg.getId());
                    e.printStackTrace();
                }
            }
        }

Is the ephemeral_ids endpoint really part of the v3 API?
Usage in the client is confusing, here getPkgInfoByPkgId is used if API is v3:

if (PropertyManager.INSTANCE.getApiVersion().equals(API_VERSION_V3)) {
return getPkgInfoByPkgId(pkgId, pkg.getJavaVersion()).getDirectDownloadUri();
} else {
return getPkgInfoByEphemeralId(pkg.getEphemeralId(), pkg.getJavaVersion()).getDirectDownloadUri();
}

This works well. But here if API version is v3, the package is downloaded by ephemeral id:
if (PropertyManager.INSTANCE.getApiVersion().equals(API_VERSION_V3)) {
final Semver javaVersion = pkg.getJavaVersion();
final String ephemeralId = pkg.getEphemeralId();
return downloadPkg(ephemeralId, javaVersion, targetFileName);
} else {
final Semver javaVersion = pkg.getJavaVersion();
return downloadPkgByPkgId(pkgId, javaVersion, targetFileName);
}

If I invert the if-statement it works. Is it possible that some of the if-statements should be different and use the ephemeral_ids only if not on API v3?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions