Is it possible to download an issue attachment to the server where add-on is working?

I need to process the attachment file on the server side. How to access it? I have this java code to download the attachment from the url:

    @PostMapping(value ="/download", consumes = "application/json")
    @CrossOrigin
    public void download(@RequestBody Map<String, String> data) throws IOException {
        String url = data.get("url");
        FileUtils.copyURLToFile(
                new URL(url),
                new File("attachment.txt"),
                1000,
                10000);
    }

This creates a file with a 302 Found code inside it. I think this is because I don’t have an authentication here. If this is because of authentication, can anyone help me to add authentication headers here? How do I get a Jwt token and how to include it? Thank you

@SeyidAghayev,

I don’t think it’s auth. 302 is a kind of HTTP redirect. Your code should catch and handle redirects generally. Specifically for attachments, the client should look at the Location header to find the URL to download from.

Thank you for the reply. I have changed the code to the one with ApacheHttpClient that handles the redirection:

        HttpClient httpclient = new DefaultHttpClient();

        HttpGet httpget = new HttpGet(url);
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            FileOutputStream fos = new java.io.FileOutputStream("attachment.txt");
            entity.writeTo(fos);
            fos.close();
        }

And now it creates the file and the content is this:
attachment.txt (8.3 KB)

I think this one tells about not being signed in

@SeyidAghayev,

How does your client authenticate?