Home > front end >  How to connect and download artifacts from JFrog Artifactory in Spring boot application
How to connect and download artifacts from JFrog Artifactory in Spring boot application

Time:07-20

I tried to connect my spring boot application to JFrog Artifactory to retrieve a file. Anyone has any idea how to do that or what are the steps, we need to do.

Thanks.

CodePudding user response:

So, to get a connection with Jfrog Artifactory in a spring boot app and download some files using HttpURLConnection

My response based on official documentation from JFrog Artifactory REST API.

JFrog has an Artifactory REST API endpoints can be invoked in any of the standard ways to invoke a RESTful API.

So first of all, we need to get an API Key:

  1. Click your login name on the top right-hand corner of the page.
  2. In the menu above, select Edit Profile.
  3. Copy your API Key.

API key can be used to authenticate you when using the REST API.

Now we need, to implement our connection to JFrog using the REST API in our code java.

private BufferedReader getFileContentFromArtifactory(String arifactoryUrl) throws Exception {

    URL repositoryUrl = new URL(arifactoryUrl);
    HttpURLConnection connection = (HttpURLConnection) repositoryUrl.openConnection();
    connection.addRequestProperty("X-JFrog-Art-Api", env.getProperty("arifactoryApiKey"));
    connection.setRequestMethod("GET");
    connection.connect();
    return new BufferedReader(new InputStreamReader(connection.getInputStream()));
}

In this code we need to add the following header to all REST API calls:

X-JFrog-Art-Api: <YOUR_API_KEY>

And finally, to verify if we have our conection work finely, we can show or use connection.getResponseCode() or connection.getResponseMessage() and if we have 200 or OK thats mean we have our connection.

The next part of question is download file from JFrog, here, we need to use BufferedReader and convert the content in object or showin screen, thats depend on our needs.

CodePudding user response:

do you build your application with maven? if so, try following the steps in this document and also there is a video here for your reference. https://www.jfrog.com/confluence/display/JFROG/Maven Repository https://jfrog.com/screencast/setting-maven-repository-jfrog-artifactory-less-one-minute/

  • Related