Package org.eclipse.jetty.http2.client
Class HTTP2Client
java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.ContainerLifeCycle
org.eclipse.jetty.http2.client.HTTP2Client
- All Implemented Interfaces:
Container
,Destroyable
,Dumpable
,Dumpable.DumpableContainer
,LifeCycle
HTTP2Client provides an asynchronous, non-blocking implementation to send HTTP/2 frames to a server.
Typical usage:
// Create and start HTTP2Client. HTTP2Client client = new HTTP2Client(); client.start(); SslContextFactory sslContextFactory = client.getClientConnector().getSslContextFactory(); // Connect to host. String host = "webtide.com"; int port = 443; FuturePromise<Session> sessionPromise = new FuturePromise<>(); client.connect(sslContextFactory, new InetSocketAddress(host, port), new ServerSessionListener.Adapter(), sessionPromise); // Obtain the client Session object. Session session = sessionPromise.get(5, TimeUnit.SECONDS); // Prepare the HTTP request headers. HttpFields requestFields = new HttpFields(); requestFields.put("User-Agent", client.getClass().getName() + "/" + Jetty.VERSION); // Prepare the HTTP request object. MetaData.Request request = new MetaData.Request("PUT", HttpURI.from("https://" + host + ":" + port + "/"), HttpVersion.HTTP_2, requestFields); // Create the HTTP/2 HEADERS frame representing the HTTP request. HeadersFrame headersFrame = new HeadersFrame(request, null, false); // Prepare the listener to receive the HTTP response frames. Stream.Listener responseListener = new new Stream.Listener.Adapter() { @Override public void onHeaders(Stream stream, HeadersFrame frame) { System.err.println(frame); } @Override public void onData(Stream stream, DataFrame frame, Callback callback) { System.err.println(frame); callback.succeeded(); } }; // Send the HEADERS frame to create a stream. FuturePromise<Stream> streamPromise = new FuturePromise<>(); session.newStream(headersFrame, streamPromise, responseListener); Stream stream = streamPromise.get(5, TimeUnit.SECONDS); // Use the Stream object to send request content, if any, using a DATA frame. ByteBuffer content = ...; DataFrame requestContent = new DataFrame(stream.getId(), content, true); stream.data(requestContent, Callback.NOOP); // When done, stop the client. client.stop();
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopException
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
Container.InheritedListener, Container.Listener
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(SocketChannel channel, ClientConnectionFactory factory, Session.Listener listener, Promise<Session> promise) void
accept
(SslContextFactory sslContextFactory, SocketChannel channel, Session.Listener listener, Promise<Session> promise) connect
(SocketAddress address, Session.Listener listener) void
connect
(SocketAddress address, Session.Listener listener, Promise<Session> promise) void
connect
(SocketAddress address, ClientConnectionFactory factory, Session.Listener listener, Promise<Session> promise, Map<String, Object> context) connect
(SslContextFactory sslContextFactory, SocketAddress address, Session.Listener listener) void
connect
(SslContextFactory sslContextFactory, SocketAddress address, Session.Listener listener, Promise<Session> promise) void
connect
(SslContextFactory sslContextFactory, SocketAddress address, Session.Listener listener, Promise<Session> promise, Map<String, Object> context) long
long
int
int
int
int
int
int
Deprecated.int
int
Deprecated.int
int
int
int
int
long
boolean
boolean
boolean
boolean
void
setBindAddress
(SocketAddress bindAddress) void
setByteBufferPool
(ByteBufferPool bufferPool) void
setConnectBlocking
(boolean connectBlocking) void
setConnectTimeout
(long connectTimeout) void
setExecutor
(Executor executor) void
setFlowControlStrategyFactory
(FlowControlStrategy.Factory flowControlStrategyFactory) void
setIdleTimeout
(long idleTimeout) void
setInitialSessionRecvWindow
(int initialSessionRecvWindow) void
setInitialStreamRecvWindow
(int initialStreamRecvWindow) void
setInputBufferSize
(int inputBufferSize) void
setMaxConcurrentPushedStreams
(int maxConcurrentPushedStreams) void
setMaxDecoderTableCapacity
(int maxDecoderTableCapacity) void
setMaxDynamicTableSize
(int maxTableSize) Deprecated.void
setMaxEncoderTableCapacity
(int maxEncoderTableCapacity) Sets the limit for the encoder HPACK dynamic table capacity.void
setMaxFrameLength
(int maxFrameSize) Deprecated.void
setMaxFrameSize
(int maxFrameSize) void
setMaxHeaderBlockFragment
(int maxHeaderBlockFragment) void
setMaxResponseHeadersSize
(int maxResponseHeadersSize) void
setMaxSettingsKeys
(int maxSettingsKeys) void
setProtocols
(List<String> protocols) void
setScheduler
(Scheduler scheduler) void
setSelectors
(int selectors) void
setStreamIdleTimeout
(long streamIdleTimeout) void
setUseALPN
(boolean useALPN) void
setUseInputDirectByteBuffers
(boolean useInputDirectByteBuffers) void
setUseOutputDirectByteBuffers
(boolean useOutputDirectByteBuffers) Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, doStart, doStop, dump, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeans
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.util.component.Container
getCachedBeans, getEventListeners
Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
-
Constructor Details
-
HTTP2Client
public HTTP2Client() -
HTTP2Client
-
-
Method Details
-
getClientConnector
-
getExecutor
-
setExecutor
-
getScheduler
-
setScheduler
-
getByteBufferPool
-
setByteBufferPool
-
getFlowControlStrategyFactory
-
setFlowControlStrategyFactory
-
getSelectors
-
setSelectors
public void setSelectors(int selectors) -
getIdleTimeout
-
setIdleTimeout
public void setIdleTimeout(long idleTimeout) -
getStreamIdleTimeout
-
setStreamIdleTimeout
public void setStreamIdleTimeout(long streamIdleTimeout) -
getConnectTimeout
-
setConnectTimeout
public void setConnectTimeout(long connectTimeout) -
isConnectBlocking
-
setConnectBlocking
public void setConnectBlocking(boolean connectBlocking) -
getBindAddress
-
setBindAddress
-
getInputBufferSize
@ManagedAttribute("The size of the buffer used to read from the network") public int getInputBufferSize() -
setInputBufferSize
public void setInputBufferSize(int inputBufferSize) -
getProtocols
-
setProtocols
-
getInitialSessionRecvWindow
@ManagedAttribute("The initial size of session\'s flow control receive window") public int getInitialSessionRecvWindow() -
setInitialSessionRecvWindow
public void setInitialSessionRecvWindow(int initialSessionRecvWindow) -
getInitialStreamRecvWindow
@ManagedAttribute("The initial size of stream\'s flow control receive window") public int getInitialStreamRecvWindow() -
setInitialStreamRecvWindow
public void setInitialStreamRecvWindow(int initialStreamRecvWindow) -
getMaxFrameLength
Deprecated. -
setMaxFrameLength
Deprecated. -
getMaxFrameSize
-
setMaxFrameSize
public void setMaxFrameSize(int maxFrameSize) -
getMaxConcurrentPushedStreams
@ManagedAttribute("The max number of concurrent pushed streams") public int getMaxConcurrentPushedStreams() -
setMaxConcurrentPushedStreams
public void setMaxConcurrentPushedStreams(int maxConcurrentPushedStreams) -
getMaxSettingsKeys
-
setMaxSettingsKeys
public void setMaxSettingsKeys(int maxSettingsKeys) -
getMaxEncoderTableCapacity
@ManagedAttribute("The HPACK encoder dynamic table maximum capacity") public int getMaxEncoderTableCapacity() -
setMaxEncoderTableCapacity
public void setMaxEncoderTableCapacity(int maxEncoderTableCapacity) Sets the limit for the encoder HPACK dynamic table capacity.
Setting this value to
0
disables the use of the dynamic table.- Parameters:
maxEncoderTableCapacity
- The HPACK encoder dynamic table maximum capacity
-
getMaxDecoderTableCapacity
@ManagedAttribute("The HPACK decoder dynamic table maximum capacity") public int getMaxDecoderTableCapacity() -
setMaxDecoderTableCapacity
public void setMaxDecoderTableCapacity(int maxDecoderTableCapacity) -
getMaxDynamicTableSize
Deprecated. -
setMaxDynamicTableSize
Deprecated. -
getMaxHeaderBlockFragment
-
setMaxHeaderBlockFragment
public void setMaxHeaderBlockFragment(int maxHeaderBlockFragment) -
getMaxResponseHeadersSize
-
setMaxResponseHeadersSize
public void setMaxResponseHeadersSize(int maxResponseHeadersSize) -
isUseInputDirectByteBuffers
@ManagedAttribute("Whether to use direct ByteBuffers for reading") public boolean isUseInputDirectByteBuffers() -
setUseInputDirectByteBuffers
public void setUseInputDirectByteBuffers(boolean useInputDirectByteBuffers) -
isUseOutputDirectByteBuffers
@ManagedAttribute("Whether to use direct ByteBuffers for writing") public boolean isUseOutputDirectByteBuffers() -
setUseOutputDirectByteBuffers
public void setUseOutputDirectByteBuffers(boolean useOutputDirectByteBuffers) -
isUseALPN
@ManagedAttribute("Whether ALPN should be used when establishing connections") public boolean isUseALPN() -
setUseALPN
public void setUseALPN(boolean useALPN) -
connect
-
connect
-
connect
public CompletableFuture<Session> connect(SslContextFactory sslContextFactory, SocketAddress address, Session.Listener listener) -
connect
public void connect(SslContextFactory sslContextFactory, SocketAddress address, Session.Listener listener, Promise<Session> promise) -
connect
public void connect(SslContextFactory sslContextFactory, SocketAddress address, Session.Listener listener, Promise<Session> promise, Map<String, Object> context) -
connect
public void connect(SocketAddress address, ClientConnectionFactory factory, Session.Listener listener, Promise<Session> promise, Map<String, Object> context) -
accept
public void accept(SslContextFactory sslContextFactory, SocketChannel channel, Session.Listener listener, Promise<Session> promise) -
accept
public void accept(SocketChannel channel, ClientConnectionFactory factory, Session.Listener listener, Promise<Session> promise)
-