use of org.eclipse.jetty.client.util.InputStreamContentProvider in project camel by apache.
the class DefaultRestClient method apexCall.
@Override
public void apexCall(String httpMethod, String apexUrl, Map<String, Object> queryParams, InputStream requestDto, ResponseCallback callback) {
// create APEX call request
final Request request;
try {
request = getRequest(httpMethod, apexCallUrl(apexUrl, queryParams));
// set request SObject and content type
if (requestDto != null) {
request.content(new InputStreamContentProvider(requestDto));
request.header(HttpHeader.CONTENT_TYPE, PayloadFormat.JSON.equals(format) ? APPLICATION_JSON_UTF8 : APPLICATION_XML_UTF8);
}
// requires authorization token
setAccessToken(request);
doHttpRequest(request, new DelegatingClientCallback(callback));
} catch (UnsupportedEncodingException e) {
String msg = "Unexpected error: " + e.getMessage();
callback.onResponse(null, new SalesforceException(msg, e));
} catch (URISyntaxException e) {
String msg = "Unexpected error: " + e.getMessage();
callback.onResponse(null, new SalesforceException(msg, e));
}
}
use of org.eclipse.jetty.client.util.InputStreamContentProvider in project camel by apache.
the class DefaultRestClient method createSObject.
@Override
public void createSObject(String sObjectName, InputStream sObject, ResponseCallback callback) {
// post the sObject
final Request post = getRequest(HttpMethod.POST, sobjectsUrl(sObjectName));
// authorization
setAccessToken(post);
// input stream as entity content
post.content(new InputStreamContentProvider(sObject));
post.header(HttpHeader.CONTENT_TYPE, PayloadFormat.JSON.equals(format) ? APPLICATION_JSON_UTF8 : APPLICATION_XML_UTF8);
doHttpRequest(post, new DelegatingClientCallback(callback));
}
use of org.eclipse.jetty.client.util.InputStreamContentProvider in project jetty.project by eclipse.
the class AsyncIOServletTest method testWriteListenerFromOtherThread.
@Test
public void testWriteListenerFromOtherThread() throws Exception {
start(new HttpServlet() {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
AsyncContext asyncContext = request.startAsync();
asyncContext.setTimeout(0);
request.getInputStream().setReadListener(new Listener(asyncContext));
}
});
int cores = 4;
int iterations = 10;
CountDownLatch latch = new CountDownLatch(cores * iterations);
Deque<Throwable> failures = new LinkedBlockingDeque<>();
for (int i = 0; i < cores; ++i) {
client.getExecutor().execute(() -> {
for (int j = 0; j < iterations; ++j) {
try {
ContentResponse response = client.newRequest(newURI()).method(HttpMethod.POST).path(servletPath).content(new InputStreamContentProvider(new ByteArrayInputStream(new byte[16 * 1024]) {
@Override
public int read(byte[] b, int off, int len) {
sleep(5);
return super.read(b, off, Math.min(len, 4242));
}
})).send();
Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
latch.countDown();
} catch (Throwable x) {
failures.offer(x);
}
}
});
}
Assert.assertTrue(latch.await(30, TimeUnit.SECONDS));
Assert.assertTrue(failures.isEmpty());
}
use of org.eclipse.jetty.client.util.InputStreamContentProvider in project jetty.project by eclipse.
the class AsyncRequestContentTest method testInputStream.
@Test
public void testInputStream() throws Exception {
start(new ConsumeInputHandler());
InputStreamContentProvider contentProvider = new InputStreamContentProvider(new ByteArrayInputStream(new byte[1]));
CountDownLatch latch = new CountDownLatch(1);
client.POST(newURI()).content(contentProvider).send(result -> {
if (result.isSucceeded() && result.getResponse().getStatus() == HttpStatus.OK_200)
latch.countDown();
});
contentProvider.close();
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
use of org.eclipse.jetty.client.util.InputStreamContentProvider in project jetty.project by eclipse.
the class AsyncRequestContentTest method testEmptyInputStream.
@Test
public void testEmptyInputStream() throws Exception {
start(new ConsumeInputHandler());
InputStreamContentProvider contentProvider = new InputStreamContentProvider(new ByteArrayInputStream(new byte[0]));
CountDownLatch latch = new CountDownLatch(1);
client.POST(newURI()).content(contentProvider).send(result -> {
if (result.isSucceeded() && result.getResponse().getStatus() == HttpStatus.OK_200)
latch.countDown();
});
contentProvider.close();
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
Aggregations