Package org.eclipse.jetty.client.util

Examples of org.eclipse.jetty.client.util.StringContentProvider


            String sent = IO.toString(new FileInputStream("src/test/resources/message.txt"));
           
            Request request = client.newRequest(srvUrl);
            request.method(HttpMethod.POST);
            request.content(new StringContentProvider(sent));
            _received=null;
            request = request.timeout(5, TimeUnit.SECONDS);
            ContentResponse response = request.send();
          
            Assert.assertEquals(200,response.getStatus());
View Full Code Here


                    }
                };
            }
        }));

        ContentResponse response = httpClient.newRequest("localhost", proxyAddress.getPort()).method(HttpMethod.POST).content(new
                StringContentProvider(data)).followRedirects(false).send();
        assertThat("response code is 303", response.getStatus(), is(303));

        // Perform another request so that we are sure we reset the states of parsers and generators
        ContentResponse response2 = httpClient.newRequest("localhost", proxyAddress.getPort()).method(HttpMethod
                .POST).content(new StringContentProvider(data)).followRedirects(false).send();
        assertThat("response2 code is 303", response2.getStatus(), is(303));
    }
View Full Code Here

                    }
                };
            }
        }));

        ContentResponse response = httpClient.POST("http://localhost:" + proxyAddress.getPort() + "/").content(new
                StringContentProvider(dataString)).send();
        assertThat("response status is 200 OK", response.getStatus(), is(200));
        assertThat("response content matches expected dataString", response.getContentAsString(), is(dataString));

        // Perform another request so that we are sure we reset the states of parsers and generators
        response = httpClient.POST("http://localhost:" + proxyAddress.getPort() + "/").content(new
                StringContentProvider(dataString)).send();
        assertThat("response status is 200 OK", response.getStatus(), is(200));
        assertThat("response content matches expected dataString", response.getContentAsString(), is(dataString));
    }
View Full Code Here

                    .scheme(HttpScheme.HTTPS.asString())
                    .method(HttpMethod.POST)
                    .path("/echo")
                    .header(HttpHeader.CONTENT_TYPE, MimeTypes.Type.FORM_ENCODED.asString())
                    .header(HttpHeader.CONTENT_LENGTH, String.valueOf(content.length()))
                    .content(new StringContentProvider(content))
                    .send();

            assertEquals(HttpStatus.OK_200, response2.getStatus());
            content = response2.getContentAsString();
            assertEquals(body, content);
View Full Code Here

                    .scheme(HttpScheme.HTTPS.asString())
                    .method(HttpMethod.POST)
                    .path("/echo")
                    .header(HttpHeader.CONTENT_TYPE, MimeTypes.Type.FORM_ENCODED.asString())
                    .header(HttpHeader.CONTENT_LENGTH, String.valueOf(body2.length()))
                    .content(new StringContentProvider(body2));

            // Make sure the second connection can send the exchange via the tunnel
            FutureResponseListener listener2 = new FutureResponseListener(request2);
            connection.get().send(request2, listener2);
            ContentResponse response2 = listener2.get(5, TimeUnit.SECONDS);
View Full Code Here

  protected ResponseEntity<String> executeRequest(URI url, HttpMethod method, HttpHeaders headers, String body) {
    Request httpRequest = this.httpClient.newRequest(url).method(method);
    addHttpHeaders(httpRequest, headers);
    if (body != null) {
      httpRequest.content(new StringContentProvider(body));
    }
    ContentResponse response;
    try {
      response = httpRequest.send();
    }
View Full Code Here

    }

    @Override
    protected void addPostEntity(Request request, String postEntity, String contentType) {
        request.header(HttpHeader.CONTENT_TYPE, contentType +  "; charset=utf-8");
        request.content(new StringContentProvider(postEntity, UTF8));
    }
View Full Code Here

            builder.setLength(0);
            builder.append(cookie.getName()).append("=").append(cookie.getValue());
            request.header(HttpHeader.COOKIE.asString(), builder.toString());
        }

        request.content(new StringContentProvider(generateJSON(messages)));

        customize(request);

        synchronized (this)
        {
View Full Code Here

                "\"supportedConnectionTypes\":[\"long-polling\"]" +
                "}]";
        ContentResponse handshake = httpClient.newRequest("localhost", connector.getLocalPort())
                .method(HttpMethod.POST)
                .path(cometdServletPath)
                .content(new StringContentProvider(handshakeContent), "application/json;charset=UTF-8")
                .timeout(5, TimeUnit.SECONDS)
                .send();
        assertEquals(200, handshake.getStatus());
        HttpCookie browserCookie = httpClient.getCookieStore().get(URI.create(cometdURL)).get(0);
        assertEquals("BAYEUX_BROWSER", browserCookie.getName());
        Message.Mutable[] messages = parser.parse(handshake.getContentAsString());
        assertEquals(1, messages.length);
        String clientId = messages[0].getClientId();

        String connectContent1 = "[{" +
                "\"id\":\"2\"," +
                "\"channel\":\"/meta/connect\"," +
                "\"connectionType\":\"long-polling\"," +
                "\"clientId\":\"" + clientId + "\"," +
                "\"advice\": {\"timeout\":0}" +
                "}]";
        ContentResponse connect1 = httpClient.newRequest("localhost", connector.getLocalPort())
                .method(HttpMethod.POST)
                .path(cometdServletPath)
                .content(new StringContentProvider(connectContent1), "application/json;charset=UTF-8")
                .timeout(5, TimeUnit.SECONDS)
                .send();
        assertEquals(200, connect1.getStatus());

        // This /meta/connect is suspended.
        final CountDownLatch abortedConnectLatch = new CountDownLatch(1);
        String connectContent2 = "[{" +
                "\"id\":\"3\"," +
                "\"channel\":\"/meta/connect\"," +
                "\"connectionType\":\"long-polling\"," +
                "\"clientId\":\"" + clientId + "\"" +
                "}]";
        httpClient.newRequest("localhost", connector.getLocalPort())
                .method(HttpMethod.POST)
                .path(cometdServletPath)
                .content(new StringContentProvider(connectContent2), "application/json;charset=UTF-8")
                .timeout(5, TimeUnit.SECONDS)
                .send(new Response.CompleteListener()
                {
                    @Override
                    public void onComplete(Result result)
                    {
                        assertTrue(result.isSucceeded());
                        assertEquals(408, result.getResponse().getStatus());
                        abortedConnectLatch.countDown();
                    }
                });

        // Give some time to the long poll to happen.
        Thread.sleep(1000);

        // Send the second /meta/connect before the previous returns.
        String connectContent3 = "[{" +
                "\"id\":\"4\"," +
                "\"channel\":\"/meta/connect\"," +
                "\"connectionType\":\"long-polling\"," +
                "\"clientId\":\"" + clientId + "\"," +
                "\"advice\": {\"timeout\":0}" +
                "}]";
        ContentResponse connect3 = httpClient.newRequest("localhost", connector.getLocalPort())
                .method(HttpMethod.POST)
                .path(cometdServletPath)
                .content(new StringContentProvider(connectContent3), "application/json;charset=UTF-8")
                .timeout(5, TimeUnit.SECONDS)
                .send();
        assertEquals(200, connect3.getStatus());

        assertTrue(abortedConnectLatch.await(5, TimeUnit.SECONDS));

        // Make sure a subsequent connect does not have the multiple-clients advice.
        String connectContent4 = "[{" +
                "\"id\":\"5\"," +
                "\"channel\":\"/meta/connect\"," +
                "\"connectionType\":\"long-polling\"," +
                "\"clientId\":\"" + clientId + "\"" +
                "}]";
        ContentResponse connect4 = httpClient.newRequest("localhost", connector.getLocalPort())
                .method(HttpMethod.POST)
                .path(cometdServletPath)
                .content(new StringContentProvider(connectContent4), "application/json;charset=UTF-8")
                .timeout(2 * timeout, TimeUnit.MILLISECONDS)
                .send();
        assertEquals(200, connect4.getStatus());
        messages = parser.parse(connect4.getContentAsString());
        assertEquals(1, messages.length);
View Full Code Here

    protected void configureBayeuxRequest(Request request, String requestBody, String encoding) throws UnsupportedEncodingException
    {
        request.timeout(5, TimeUnit.SECONDS);
        request.method(HttpMethod.POST);
        request.content(new StringContentProvider("application/json;charset=" + encoding, requestBody, Charset.forName(encoding)));
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jetty.client.util.StringContentProvider

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.