Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for Artifactory Query Language example in Java

I'm trying to use the Artifactory REST API (and in particular, the Artifactory Query Language) from a Java client but the examples on the site are written in Groovy (snippets) and it's not immediately clear how a Java client would work.

A Java example that uses the REST API (or the Artifactory Java Client API) to execute an AQL query would be very much appreciated.

For what it's worth, here's a link to the Artifactory Query Language site...

https://www.jfrog.com/confluence/display/RTF/Artifactory+Query+Language

like image 214
Tom Muldoon Avatar asked Aug 30 '26 23:08

Tom Muldoon


1 Answers

The Artifactory Java Client does not support AQL queries natively. You can however use the generic Rest call interface it provides to create an ArtifactoryRequest pointing to the AQL API endpoint.

The examples in the wiki you linked are not in Groovy they are in AQL syntax - you simply construct a String of whatever query you'd like and send it as the body of the request - roughly something like

String aqlQuery = "items.find({\"name\": {\"$match\" : \"*test.*\"}})";
Artifactory artifactory = Artifactory.create(url, userName, password);
ArtifactoryRequest aqlRequest = new ArtifactoryRequestImpl()
            .method(ArtifactoryRequest.Method.POST)
            .apiUrl("/api/search/aql")
            .requestBody(aqlQuery);
 //Parse this string as json
 String aqlResponse = artifactory.restCall(aqlRequest);

The response is a JSON you can parse and work on - check the example from the API link I provided.

like image 141
danf Avatar answered Sep 01 '26 14:09

danf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!