Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-dev] Looking for Jetty HttpClient that downloads large zip files ...

You are trying to queue an entire 1GB file in memory with that code.
While you could have a valid Java environment suitable for 1GB files in memory, that's not typical.
The BufferedResponseListener is for small responses/resources.

Use one of the other examples in the documentation that Simone linked to.
You'll have to manage the read from the HTTP response yourself (either as a series of ByteBuffer's or via the java.io Streams) and write of the file to disk.

Look at Response.Listener.Adapter example for a series of ByteBuffers approach.
Look at InputStreamResponseListener example for using a java.io.InputStream approach.


Joakim Erdfelt / joakim@xxxxxxxxxxx

On Wed, Sep 14, 2016 at 10:46 AM, Alan Nexus <alan.nexus.6@xxxxxxxxx> wrote:
Hi Simone, Yes any help would be appreciated ... See my comment in code below:  // ***
Thanks, -Alan


import org.eclipse.jetty.client.api.AuthenticationStore;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.Result;
import org.eclipse.jetty.client.util.BasicAuthentication;
import org.eclipse.jetty.client.util.BufferingResponseListener;
import java.net.URI;

/*
 * Testcode driver
 */
final public class App {
    public static void main(String[] args) throws Exception {
        HttpClient httpClient = new HttpClient();
        httpClient.start();

        String url = "" href="http://localhost:8080/largefile.zip" target="_blank">http://localhost:8080/largefile.zip";
        URI uri = new URI(url);

        String realm = "MyRealm";
        String u = "u1";
        String p = "p1";

        AuthenticationStore auth = httpClient.getAuthenticationStore();
        auth.addAuthentication(new BasicAuthentication(uri, realm, u, p));

        httpClient.newRequest(uri)
                // Buffer response content up to 8 MiB
                .send(new BufferingResponseListener(8 * 1024 * 1024)
                {
                    @Override
                    public void onComplete(Result result)
                    {
                        if (!result.isFailed())
                        {
                            byte[] responseContent = getContent();
                            System.out.println("Success.");
                        } else {
                            System.out.println("Failed:");
                        }
                    }
                });

         // *** Right after httpClient.newRequest it goes here!  
         httpClient.stop();
    }
}

On Wed, Sep 14, 2016 at 11:58 AM, Simone Bordet <sbordet@xxxxxxxxxxx> wrote:
Hi,

On Wed, Sep 14, 2016 at 6:52 PM, Alan Nexus <alan.nexus.6@xxxxxxxxx> wrote:
> Thank you Simone. I did look at this, but I couldn't get it to work with a
> large file (>1GB).  The lack of a complete example is often the critical
> piece especially when dealing with larger files (ideally a testcase).

What problems did you have ?
Can you share your code ?

--
Simone Bordet
----
http://cometd.org
http://webtide.com
Developer advice, training, services and support
from the Jetty & CometD experts.
_______________________________________________
jetty-dev mailing list
jetty-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-dev


_______________________________________________
jetty-dev mailing list
jetty-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-dev


Back to the top