Search in sources :

Example 6 with OutputStreamContentProvider

use of org.eclipse.jetty.client.util.OutputStreamContentProvider in project jetty.project by eclipse.

the class Usage method testRequestOutputStream.

@Test
public void testRequestOutputStream() throws Exception {
    HttpClient client = new HttpClient();
    client.start();
    OutputStreamContentProvider content = new OutputStreamContentProvider();
    try (OutputStream output = content.getOutputStream()) {
        client.newRequest("localhost", 8080).content(content).send(new Response.CompleteListener() {

            @Override
            public void onComplete(Result result) {
                Assert.assertEquals(200, result.getResponse().getStatus());
            }
        });
        output.write(new byte[1024]);
        output.write(new byte[512]);
        output.write(new byte[256]);
        output.write(new byte[128]);
    }
}
Also used : OutputStreamContentProvider(org.eclipse.jetty.client.util.OutputStreamContentProvider) HttpClient(org.eclipse.jetty.client.HttpClient) OutputStream(java.io.OutputStream) Test(org.junit.Test)

Example 7 with OutputStreamContentProvider

use of org.eclipse.jetty.client.util.OutputStreamContentProvider in project jersey by jersey.

the class JettyConnector method getStreamProvider.

private ContentProvider getStreamProvider(final ClientRequest clientRequest) {
    final Object entity = clientRequest.getEntity();
    if (entity == null) {
        return null;
    }
    final OutputStreamContentProvider streamContentProvider = new OutputStreamContentProvider();
    clientRequest.setStreamProvider(new OutboundMessageContext.StreamProvider() {

        @Override
        public OutputStream getOutputStream(final int contentLength) throws IOException {
            return streamContentProvider.getOutputStream();
        }
    });
    return streamContentProvider;
}
Also used : OutputStreamContentProvider(org.eclipse.jetty.client.util.OutputStreamContentProvider) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) OutboundMessageContext(org.glassfish.jersey.message.internal.OutboundMessageContext)

Aggregations

OutputStreamContentProvider (org.eclipse.jetty.client.util.OutputStreamContentProvider)7 OutputStream (java.io.OutputStream)6 Test (org.junit.Test)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 IOException (java.io.IOException)4 InterruptedIOException (java.io.InterruptedIOException)3 ServletOutputStream (javax.servlet.ServletOutputStream)3 ServletException (javax.servlet.ServletException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Result (org.eclipse.jetty.client.api.Result)2 BufferingResponseListener (org.eclipse.jetty.client.util.BufferingResponseListener)2 Request (org.eclipse.jetty.server.Request)2 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Random (java.util.Random)1 HttpClient (org.eclipse.jetty.client.HttpClient)1 OutboundMessageContext (org.glassfish.jersey.message.internal.OutboundMessageContext)1