0

im running a nexus (OSS 3.36.0-01) instance which hosts some maven artefacts for my application (Apache Flink Jobs).

These Jar-files needs to be downloaded by a java a application (it's a flink k8s operator).

Using the nexus-internal swagger UI on /v1/search/assets i've build a query which contains the desired jar only.

https://<my-nexus-url>/service/rest/v1/search/assets?repository=maven-releases&maven.groupId=de.ilem0n.ngbm&maven.artifactId=kafka-health-check&maven.baseVersion=1.0.0&maven.extension=jar

Result:

{
"items": [
{
  "downloadUrl": "https://<my-nexus-url>/repository/maven-releases/de/ilem0n/ngbm/kafka-health-check/1.0.0/kafka-health-check-1.0.0.jar",
  "path": "de/ilem0n/ngbm/kafka-health-check/1.0.0/kafka-health-check-1.0.0.jar",
  "id": "<artefact-id>",
  "repository": "maven-releases",
  "format": "maven2",
  "checksum": {
    "sha1": "<checksum>",
    "sha256": "<checksum>",
    "sha512": "<checksum>",
    "md5": "<checksum>"
  },
  "contentType": "application/java-archive",
  "lastModified": "2021-12-28T12:11:28.622+00:00",
  "maven2": {
    "extension": "jar",
    "groupId": "de.ilem0n.ngbm",
    "artifactId": "kafka-health-check",
    "version": "1.0.0"
  }
}],
"continuationToken": null
}

The same query on /v1/search/assets/download from postman or even in the browser runs fine and gives me the correct jar-file back.

In my java application i use the following code to do the same:

String url = "https://<my-nexus-url>/service/rest/v1/search/assets?repository=maven-releases&maven.groupId=de.ilem0n.ngbm&maven.artifactId=kafka-health-check&maven.baseVersion=1.0.0&maven.extension=jar";

Authenticator auth = new Authenticator() {
        public Request authenticate(Route route, Response response) throws IOException {
            String credential = Credentials.basic(username, password);
            return response.request().newBuilder().header("Authorization", credential).build();
        }
    };

OkHttpClient httpClient = new OkHttpClient.Builder().authenticator(auth).build();
    
Request.Builder requestBuilder = new Request.Builder();
requestBuilder.url(url);

Response response = client.newCall(requestBuilder.build()).execute();

But here I get back an empty list in the response body:

{
  "items" : [ ],
  "continuationToken" : null
}

Does anyone has a hint what's wrong here or a better solution to download a single jar-file from a nexus maven repository programmatically? (Background here is that this jar-file will be uploaded to the Flink REST API and therefore it needs to be present on the machine)

POM-File:

    <?xml version="1.0"?>
    <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <modelVersion>4.0.0</modelVersion>
      <groupId>de.ilem0n.ngbm</groupId>
      <artifactId>flink-operator-next</artifactId>
      <version>0.1.2</version>

      <properties>
        <compiler-plugin.version>3.8.1</compiler-plugin.version>
        <maven.compiler.parameters>true</maven.compiler.parameters>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <quarkus.platform.version>2.6.0.CR1</quarkus.platform.version>
        <surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
        <flink-client.version>1.0.4</flink-client.version>
        <quarkus-sdk.version>2.0.2</quarkus-sdk.version>
      </properties>
      <dependencyManagement>
        <dependencies>
          <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-bom</artifactId>
            <version>${quarkus.platform.version}</version>
            <type>pom</type>
            <scope>import</scope>
          </dependency>
        </dependencies>
      </dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-core</artifactId>
          <version>2.6.0.CR1</version>
        </dependency>
        <!-- Operator SDK -->
        <dependency>
          <groupId>io.quarkiverse.operatorsdk</groupId>
          <artifactId>quarkus-operator-sdk</artifactId>
          <version>${quarkus-sdk.version}</version>
        </dependency>

        <dependency>
          <groupId>com.nextbreakpoint</groupId>
          <artifactId>com.nextbreakpoint.flinkclient</artifactId>
          <version>${flink-client.version}</version>
        </dependency>

        <dependency>
          <groupId>com.squareup.okio</groupId>
          <artifactId>okio</artifactId>
          <version>2.7.0</version>
        </dependency>

        <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-kafka-client</artifactId>
        </dependency>

        <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-smallrye-health</artifactId>
        </dependency>
        <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-kubernetes-config</artifactId>
        </dependency>
        <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-kubernetes</artifactId>
        </dependency>
        <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-smallrye-context-propagation</artifactId>
        </dependency>
        <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-smallrye-metrics</artifactId>
        </dependency>
        <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-arc</artifactId>
        </dependency>
        <dependency>
          <groupId>io.quarkus</groupId>
          <artifactId>quarkus-junit5</artifactId>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok</artifactId>
          <version>1.18.22</version>
          <scope>compile</scope>
        </dependency>
    
      </dependencies>
      <build>
        <plugins>
          <plugin>
            <groupId>io.quarkus.platform</groupId>
            <artifactId>quarkus-maven-plugin</artifactId>
            <version>${quarkus.platform.version}</version>
            <extensions>true</extensions>
            <executions>
              <execution>
                <goals>
                  <goal>build</goal>
                  <goal>generate-code</goal>
                  <goal>generate-code-tests</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${compiler-plugin.version}</version>
            <configuration>
              <parameters>${maven.compiler.parameters}</parameters>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${surefire-plugin.version}</version>
            <configuration>
              <systemPropertyVariables>
                    <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
            <maven.home>${maven.home}</maven.home>
          </systemPropertyVariables>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>native</id>
      <activation>
        <property>
          <name>native</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>${surefire-plugin.version}</version>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
                <configuration>
                  <systemPropertyVariables>
                            <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>                            <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                        <maven.home>${maven.home}</maven.home>
                      </systemPropertyVariables>
                    </configuration>
                  </execution>
                </executions>
              </plugin>
            </plugins>
          </build>
          <properties>
            <quarkus.package.type>native</quarkus.package.type>
          </properties>
        </profile>
      </profiles>
    </project>
Peter C. Glade
  • 543
  • 2
  • 8
  • 16

1 Answers1

0

It seems that adding an Authenticator to the client doesn't mean that the requests will are authenticated as well.

I had to additionally add the authorisation headers manually the request to get it work. The confusing thing here ist that you will not get an unauthorised message, just an empty response ;)

Peter C. Glade
  • 543
  • 2
  • 8
  • 16