Java rest client download file






















ClientProtocolException; import org. HttpClient; import org. HttpPost; import org. FileEntity; import org. Bharti Gulati Bharti Gulati 31 3 3 bronze badges. I do not how to do it but these links below will definitely lead you to your answer. Sohail Shaikh Sohail Shaikh 6 6 silver badges 16 16 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. So basically what I want to achieve is to allow the client to download a file from 1st server using the REST service on 2nd server since there is no direct access from client to 1st server using only data streams so no data touching the file system of 2nd server.

Which one is the more efficient? I'm not sure, but the returned InputStream s are different classes, so you may want to look into that if you care to. So most of the answers you'll see in the link provided by GradyGCooper seem to favor the use of StreamingOutput. An example implementation might be something like. But if we look at the source code for StreamingOutputProvider , you'll see in the writeTo , that it simply writes the data from one stream to another.

So with our implementation above, we have to write twice. How can we get only one write? Simple return the InputStream as the Response. Client objects are expensive resources. You may want to reuse the same Client for request. You can extract a WebTarget from the client for each request. I think the WebTarget can even be shared. I can't find anything in the Jersey 2. So I'm guessing Jersey 2. You don't have to make use of the Client API.

A download can be easily achieved with the java. But since you're already using Jersey, it doesn't hurt to use its APIs. The above is assuming Jersey 2. For Jersey 1. I'm such a dufus. Sign Out View Profile. Over 2 million developers have joined DZone. This article demonstrates how to use a Spring Boot application and MySQL to maintain a database of uploaded files and their metadata.

Like Join the DZone community and get the full member experience. Join For Free. Spring Boot dependencies Set up application. You need to do two stpes to download a file from java restful web services. Here is the service class to download file: package com. File; import javax. GET; import javax. Path; import javax.

Produces; import javax.



0コメント

  • 1000 / 1000