use of org.eclipse.jetty.client.HttpExchange in project jetty.project by eclipse.
the class HttpReceiverOverHTTP2 method onData.
@Override
public void onData(Stream stream, DataFrame frame, Callback callback) {
HttpExchange exchange = getHttpExchange();
if (exchange == null) {
callback.failed(new IOException("terminated"));
return;
}
// We must copy the data since we do not know when the
// application will consume the bytes and the parsing
// will continue as soon as this method returns, eventually
// leading to reusing the underlying buffer for more reads.
ByteBufferPool byteBufferPool = getHttpDestination().getHttpClient().getByteBufferPool();
ByteBuffer original = frame.getData();
int length = original.remaining();
final ByteBuffer copy = byteBufferPool.acquire(length, original.isDirect());
BufferUtil.clearToFill(copy);
copy.put(original);
BufferUtil.flipToFlush(copy, 0);
contentNotifier.offer(new DataInfo(exchange, copy, callback, frame.isEndStream()));
contentNotifier.iterate();
}
use of org.eclipse.jetty.client.HttpExchange in project jetty.project by eclipse.
the class HttpReceiverOverHTTP2 method onPush.
@Override
public Stream.Listener onPush(Stream stream, PushPromiseFrame frame) {
HttpExchange exchange = getHttpExchange();
if (exchange == null)
return null;
HttpRequest request = exchange.getRequest();
MetaData.Request metaData = (MetaData.Request) frame.getMetaData();
HttpRequest pushRequest = (HttpRequest) getHttpDestination().getHttpClient().newRequest(metaData.getURIString());
BiFunction<Request, Request, Response.CompleteListener> pushListener = request.getPushListener();
if (pushListener != null) {
Response.CompleteListener listener = pushListener.apply(request, pushRequest);
if (listener != null) {
HttpChannelOverHTTP2 pushChannel = getHttpChannel().getHttpConnection().newHttpChannel(true);
List<Response.ResponseListener> listeners = Collections.singletonList(listener);
HttpExchange pushExchange = new HttpExchange(getHttpDestination(), pushRequest, listeners);
pushChannel.associate(pushExchange);
pushChannel.setStream(stream);
// TODO: idle timeout ?
pushExchange.requestComplete(null);
pushExchange.terminateRequest();
return pushChannel.getStreamListener();
}
}
stream.reset(new ResetFrame(stream.getId(), ErrorCode.REFUSED_STREAM_ERROR.code), Callback.NOOP);
return null;
}
use of org.eclipse.jetty.client.HttpExchange in project openhab1-addons by openhab.
the class FritzahaWebInterface method asyncPost.
/**
* Sends an HTTP POST request using the asynchronous client
*
* @param Path
* Path of the requested resource
* @param Args
* Arguments for the request
* @param Callback
* Callback to handle the response with
*/
public HttpExchange asyncPost(String path, String args, FritzahaCallback callback) {
if (!isAuthenticated()) {
authenticate();
}
HttpExchange postExchange = new FritzahaContentExchange(callback);
postExchange.setMethod("POST");
postExchange.setURL(getURL(path));
try {
postExchange.setRequestContent(new ByteArrayBuffer(addSID(args).getBytes("UTF-8")));
} catch (UnsupportedEncodingException e1) {
logger.error("An encoding error occurred in the POST arguments");
return null;
}
postExchange.setRequestContentType("application/x-www-form-urlencoded;charset=utf-8");
try {
asyncclient.send(postExchange);
} catch (IOException e) {
logger.error("An I/O error occurred while sending the POST request to " + getURL(path));
return null;
}
return postExchange;
}
use of org.eclipse.jetty.client.HttpExchange in project jetty.project by eclipse.
the class HttpReceiverOverHTTP method parsedHeader.
@Override
public void parsedHeader(HttpField field) {
HttpExchange exchange = getHttpExchange();
if (exchange == null)
return;
responseHeader(exchange, field);
}
use of org.eclipse.jetty.client.HttpExchange in project jetty.project by eclipse.
the class HttpReceiverOverHTTP method earlyEOF.
@Override
public void earlyEOF() {
HttpExchange exchange = getHttpExchange();
HttpConnectionOverHTTP connection = getHttpConnection();
if (exchange == null)
connection.close();
else
failAndClose(new EOFException(String.valueOf(connection)));
}
Aggregations