use of org.eclipse.jetty.client.util.BytesContentProvider in project druid by druid-io.
the class AsyncQueryForwardingServlet method sendProxyRequest.
@Override
protected void sendProxyRequest(HttpServletRequest clientRequest, HttpServletResponse proxyResponse, Request proxyRequest) {
proxyRequest.timeout(httpClientConfig.getReadTimeout().getMillis(), TimeUnit.MILLISECONDS);
proxyRequest.idleTimeout(httpClientConfig.getReadTimeout().getMillis(), TimeUnit.MILLISECONDS);
final Query query = (Query) clientRequest.getAttribute(QUERY_ATTRIBUTE);
if (query != null) {
final ObjectMapper objectMapper = (ObjectMapper) clientRequest.getAttribute(OBJECTMAPPER_ATTRIBUTE);
try {
proxyRequest.content(new BytesContentProvider(objectMapper.writeValueAsBytes(query)));
} catch (JsonProcessingException e) {
Throwables.propagate(e);
}
}
super.sendProxyRequest(clientRequest, proxyResponse, proxyRequest);
}
use of org.eclipse.jetty.client.util.BytesContentProvider in project jetty.project by eclipse.
the class DigestPostTest method testServerWithHttpClientStringContent.
@Test
public void testServerWithHttpClientStringContent() throws Exception {
String srvUrl = "http://127.0.0.1:" + ((NetworkConnector) _server.getConnectors()[0]).getLocalPort() + "/test/";
HttpClient client = new HttpClient();
try {
AuthenticationStore authStore = client.getAuthenticationStore();
authStore.addAuthentication(new DigestAuthentication(new URI(srvUrl), "test", "testuser", "password"));
client.start();
Request request = client.newRequest(srvUrl);
request.method(HttpMethod.POST);
request.content(new BytesContentProvider(__message.getBytes("UTF8")));
_received = null;
request = request.timeout(5, TimeUnit.SECONDS);
ContentResponse response = request.send();
Assert.assertEquals(__message, _received);
Assert.assertEquals(200, response.getStatus());
} finally {
client.stop();
}
}
use of org.eclipse.jetty.client.util.BytesContentProvider in project jetty.project by eclipse.
the class JdbcLoginServiceTest method testPut.
@Test
public void testPut() throws Exception {
try {
startClient();
Request request = _client.newRequest(_baseUri.resolve("output.txt"));
request.method(HttpMethod.PUT);
request.content(new BytesContentProvider(_content.getBytes()));
ContentResponse response = request.send();
int responseStatus = response.getStatus();
boolean statusOk = (responseStatus == 200 || responseStatus == 201);
assertTrue(statusOk);
String content = IO.toString(new FileInputStream(new File(_docRoot, "output.txt")));
assertEquals(_content, content);
} finally {
stopClient();
}
}
use of org.eclipse.jetty.client.util.BytesContentProvider in project jetty.project by eclipse.
the class JdbcLoginServiceTest method testPost.
@Test
public void testPost() throws Exception {
try {
startClient();
Request request = _client.newRequest(_baseUri.resolve("test"));
request.method(HttpMethod.POST);
request.content(new BytesContentProvider(_content.getBytes()));
ContentResponse response = request.send();
assertEquals(HttpStatus.OK_200, response.getStatus());
assertEquals(_content, _testServer.getTestHandler().getRequestContent());
} finally {
stopClient();
}
}
use of org.eclipse.jetty.client.util.BytesContentProvider in project jetty.project by eclipse.
the class HttpClientTest method test_POST_WithContent_TracksProgress.
@Test
public void test_POST_WithContent_TracksProgress() throws Exception {
start(new AbstractHandler() {
@Override
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
consume(request.getInputStream(), true);
}
});
final AtomicInteger progress = new AtomicInteger();
ContentResponse response = client.POST(scheme + "://localhost:" + connector.getLocalPort()).onRequestContent((request, buffer) -> {
byte[] bytes = new byte[buffer.remaining()];
Assert.assertEquals(1, bytes.length);
buffer.get(bytes);
Assert.assertEquals(bytes[0], progress.getAndIncrement());
}).content(new BytesContentProvider(new byte[] { 0 }, new byte[] { 1 }, new byte[] { 2 }, new byte[] { 3 }, new byte[] { 4 })).timeout(5, TimeUnit.SECONDS).send();
Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(5, progress.get());
}
Aggregations