use of org.eclipse.jetty.client.util.BytesContentProvider in project cayenne by apache.
the class JettyHttpROPConnector method sendMessage.
@Override
public InputStream sendMessage(byte[] message) throws IOException {
try {
Request request = httpClient.newRequest(url).method(HttpMethod.POST).header(HttpHeader.CONTENT_TYPE, "application/octet-stream").header(HttpHeader.ACCEPT_ENCODING, "gzip").content(new BytesContentProvider(message));
addSessionCookie(request);
InputStreamResponseListener listener = new InputStreamResponseListener();
request.send(listener);
/**
* Waits for the given timeout for the response to be available, then returns it.
* The wait ends as soon as all the HTTP headers have been received, without waiting for the content.
*/
Response response = listener.get(readTimeout, TimeUnit.SECONDS);
if (response.getStatus() >= 300) {
throw new IOException("Did not receive successful HTTP response: status code = " + response.getStatus() + ", status message = [" + response.getReason() + "]");
}
return listener.getInputStream();
} catch (Exception e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
throw new IOException("Exception while sending message", e);
}
}
Aggregations