public class Util extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
addResponseWriteFailureListener(HttpResponseFuture outboundRespStatusFuture,
io.netty.channel.ChannelFuture channelFuture,
Http2OutboundRespListener http2OutboundRespListener)
Adds a listener to notify the outbound response future if an error occurs while writing the response message.
|
static boolean |
checkContentLengthAndTransferEncodingHeaderAllowance(HttpCarbonMessage httpOutboundRequest) |
static void |
checkForResponseWriteStatus(HttpCarbonMessage inboundRequestMsg,
HttpResponseFuture outboundRespStatusFuture,
io.netty.channel.ChannelFuture channelFuture)
Checks for status of the response write operation.
|
static void |
checkUnWritabilityAndNotify(io.netty.channel.ChannelHandlerContext context,
BackPressureHandler backpressureHandler)
Checks if channel is unWritable and notifies BackPressure observable.
|
static SSLEngine |
configureHttpPipelineForSSL(io.netty.channel.socket.SocketChannel socketChannel,
String host,
int port,
SSLConfig sslConfig)
Configure outbound HTTP pipeline for SSL configuration.
|
static io.netty.handler.codec.http.HttpResponse |
createFullHttpResponse(HttpCarbonMessage outboundResponseMsg,
String inboundReqHttpVersion,
String serverName,
boolean keepAlive,
io.netty.buffer.ByteBuf fullContent) |
static HttpCarbonMessage |
createHTTPCarbonMessage(io.netty.handler.codec.http.HttpMessage httpMessage,
io.netty.channel.ChannelHandlerContext ctx)
Creates HTTP carbon message.
|
static io.netty.handler.codec.http.HttpRequest |
createHttpRequest(HttpCarbonMessage outboundRequestMsg) |
static io.netty.handler.codec.http.HttpRequest |
createHttpRequestFromHttp2Headers(io.netty.handler.codec.http2.Http2Headers http2Headers,
int streamId)
Creates a
HttpRequest using a Http2Headers received over a particular HTTP/2 stream. |
static io.netty.handler.codec.http.HttpResponse |
createHttpResponse(HttpCarbonMessage outboundResponseMsg,
String inboundReqHttpVersion,
String serverName,
boolean keepAlive) |
static HttpCarbonMessage |
createInboundReqCarbonMsg(io.netty.handler.codec.http.HttpRequest httpRequestHeaders,
io.netty.channel.ChannelHandlerContext ctx,
SourceHandler sourceHandler)
Create a HttpCarbonMessage using the netty inbound http request.
|
static HttpCarbonMessage |
createInboundRespCarbonMsg(io.netty.channel.ChannelHandlerContext ctx,
io.netty.handler.codec.http.HttpResponse httpResponseHeaders,
HttpCarbonMessage outboundRequestMsg)
Create a HttpCarbonMessage using the netty inbound response message.
|
static io.netty.handler.ssl.SslContext |
createInsecureSslEngineForHttp2()
Creates an insecure ssl engine for clients connecting over HTTP2
|
static String |
createServerConnectorID(String host,
int port)
Create ID for server connector.
|
static BackPressureHandler |
getBackPressureHandler(io.netty.channel.ChannelHandlerContext channelContext)
Use this method to get the
BackPressureHandler in the pipeline. |
static Boolean |
getBooleanProperty(Map<String,Object> properties,
String key,
boolean defaultVal)
Get boolean type property value from a property map.
|
static io.netty.handler.codec.http.HttpResponseStatus |
getHttpResponseStatus(HttpCarbonMessage msg) |
static int |
getIntProperty(Map<String,Object> properties,
String key,
int defaultVal)
Get integer type property value from a property map.
|
static Long |
getLongProperty(Map<String,Object> properties,
String key,
long defaultVal)
Get long type property value from a property map.
|
static String |
getStringProperty(Map<String,Object> properties,
String key,
String defaultVal)
Get string type property value from a property map.
|
static void |
handleIncompleteMsgOnReset(Http2Reset http2Reset,
int streamId,
HttpCarbonMessage message) |
static void |
handleOutboundConnectionHeader(SenderConfiguration senderConfiguration,
HttpCarbonMessage httpOutboundRequest) |
static boolean |
is100ContinueRequest(HttpCarbonMessage inboundRequestMsg)
Check whether a particular request is expecting continue.
|
static boolean |
isKeepAlive(KeepAliveConfig keepAliveConfig,
HttpCarbonMessage outboundRequestMsg)
Check whether a connection should alive or not.
|
static boolean |
isKeepAliveConnection(KeepAliveConfig keepAliveConfig,
String requestConnectionHeader,
String httpVersion)
Decide whether the connection should be kept open.
|
static boolean |
isLastHttpContent(io.netty.handler.codec.http.HttpContent httpContent)
Check if a given content is last httpContent.
|
static boolean |
isVersionCompatibleForChunking(String httpVersion)
Returns the status of chunking compatibility with http version.
|
static void |
resetChannelAttributes(io.netty.channel.ChannelHandlerContext ctx)
Reset channel attributes.
|
static void |
safelyRemoveHandlers(io.netty.channel.ChannelPipeline pipeline,
String... handlerNames)
Removes handlers from the pipeline if they are present.
|
static ScheduledFuture<?> |
schedule(io.netty.channel.ChannelHandlerContext ctx,
Runnable task,
long delay) |
static void |
sendAndCloseNoEntityBodyResp(io.netty.channel.ChannelHandlerContext ctx,
io.netty.handler.codec.http.HttpResponseStatus status,
io.netty.handler.codec.http.HttpVersion httpVersion,
String serverName)
Send back no entity body response and close the connection.
|
static void |
setBackPressureListener(HttpCarbonMessage outboundMessage,
BackPressureHandler backpressureHandler,
io.netty.channel.ChannelHandlerContext ctx)
Sets the backPressure listener the to the Observable of the handler.
|
static void |
setCorrelationIdForLogging(io.netty.channel.ChannelPipeline pipeline,
io.netty.channel.ChannelInboundHandlerAdapter srcHandler) |
static void |
setForwardedExtension(ForwardedExtensionConfig forwardedConfig,
String localAddress,
HttpCarbonMessage httpOutboundRequest) |
static void |
setHostNameVerfication(SSLEngine sslEngine)
Disable host name verification if it is set to false by the user.
|
static void |
setMutualSslStatus(io.netty.channel.ChannelHandlerContext ctx,
SSLEngine sslEngine) |
static void |
setSslHandshakeTimeOut(SSLConfig sslConfig,
io.netty.handler.ssl.SslHandler sslHandler) |
static void |
setupChunkedRequest(HttpCarbonMessage httpOutboundRequest) |
static void |
setupContentLengthRequest(HttpCarbonMessage httpOutboundRequest,
long contentLength) |
static boolean |
shouldEnforceChunkingforHttpOneZero(ChunkConfig chunkConfig,
String httpVersion)
Returns whether to enforce chunking on HTTP 1.0 requests.
|
static String |
substituteVariables(String value)
Replace system property holders in the property values.
|
static long |
ticksInNanos() |
public static io.netty.handler.codec.http.HttpResponse createHttpResponse(HttpCarbonMessage outboundResponseMsg, String inboundReqHttpVersion, String serverName, boolean keepAlive)
public static io.netty.handler.codec.http.HttpResponse createFullHttpResponse(HttpCarbonMessage outboundResponseMsg, String inboundReqHttpVersion, String serverName, boolean keepAlive, io.netty.buffer.ByteBuf fullContent)
public static io.netty.handler.codec.http.HttpResponseStatus getHttpResponseStatus(HttpCarbonMessage msg)
public static io.netty.handler.codec.http.HttpRequest createHttpRequest(HttpCarbonMessage outboundRequestMsg)
public static void setupChunkedRequest(HttpCarbonMessage httpOutboundRequest)
public static io.netty.handler.codec.http.HttpRequest createHttpRequestFromHttp2Headers(io.netty.handler.codec.http2.Http2Headers http2Headers,
int streamId)
throws io.netty.handler.codec.http2.Http2Exception
HttpRequest using a Http2Headers received over a particular HTTP/2 stream.http2Headers - the Http2Headers received over a HTTP/2 streamstreamId - the stream idio.netty.handler.codec.http2.Http2Exception - if an error occurs while converting headers from HTTP/2 to HTTPpublic static void setupContentLengthRequest(HttpCarbonMessage httpOutboundRequest, long contentLength)
public static boolean checkContentLengthAndTransferEncodingHeaderAllowance(HttpCarbonMessage httpOutboundRequest)
public static boolean isVersionCompatibleForChunking(String httpVersion)
httpVersion - http version string.public static boolean shouldEnforceChunkingforHttpOneZero(ChunkConfig chunkConfig, String httpVersion)
chunkConfig - Chunking configuration.httpVersion - http version string.public static SSLEngine configureHttpPipelineForSSL(io.netty.channel.socket.SocketChannel socketChannel, String host, int port, SSLConfig sslConfig) throws SSLException
socketChannel - Socket channel of outbound connectionsslConfig - SSLConfighost - host of the connectionport - port of the connectionSSLEngine which enables secure communicationSSLException - if any error occurs in the SSL connectionpublic static io.netty.handler.ssl.SslContext createInsecureSslEngineForHttp2()
throws SSLException
SSLException - if any error occurs in the SSL connectionpublic static int getIntProperty(Map<String,Object> properties, String key, int defaultVal)
If properties is null or property value is null, default value is returned
properties - map of propertieskey - property namedefaultVal - default value of the propertypublic static String getStringProperty(Map<String,Object> properties, String key, String defaultVal)
If properties is null or property value is null, default value is returned
properties - map of propertieskey - property namedefaultVal - default value of the propertypublic static Boolean getBooleanProperty(Map<String,Object> properties, String key, boolean defaultVal)
If properties is null or property value is null, default value is returned
properties - map of propertieskey - property namedefaultVal - default value of the propertypublic static Long getLongProperty(Map<String,Object> properties, String key, long defaultVal)
If properties is null or property value is null, default value is returned
properties - map of propertieskey - property namedefaultVal - default value of the propertypublic static String substituteVariables(String value)
value - string value to substitutepublic static String createServerConnectorID(String host, int port)
host - host of the channel.port - port of the channel.public static void resetChannelAttributes(io.netty.channel.ChannelHandlerContext ctx)
ctx - Channel handler contextpublic static boolean isLastHttpContent(io.netty.handler.codec.http.HttpContent httpContent)
httpContent - new content.public static void sendAndCloseNoEntityBodyResp(io.netty.channel.ChannelHandlerContext ctx,
io.netty.handler.codec.http.HttpResponseStatus status,
io.netty.handler.codec.http.HttpVersion httpVersion,
String serverName)
ctx - connectionstatus - response statushttpVersion - of the responseserverName - server namepublic static void checkForResponseWriteStatus(HttpCarbonMessage inboundRequestMsg, HttpResponseFuture outboundRespStatusFuture, io.netty.channel.ChannelFuture channelFuture)
inboundRequestMsg - request message received from the clientoutboundRespStatusFuture - the future of outbound response write operationchannelFuture - the channel future related to response write operationpublic static void addResponseWriteFailureListener(HttpResponseFuture outboundRespStatusFuture, io.netty.channel.ChannelFuture channelFuture, Http2OutboundRespListener http2OutboundRespListener)
outboundRespStatusFuture - the future of outbound response write operationchannelFuture - the channel future related to response write operationhttp2OutboundRespListener - the http/2 outbound response listenerpublic static HttpCarbonMessage createHTTPCarbonMessage(io.netty.handler.codec.http.HttpMessage httpMessage, io.netty.channel.ChannelHandlerContext ctx)
httpMessage - HTTP messagectx - Channel handler contextpublic static void safelyRemoveHandlers(io.netty.channel.ChannelPipeline pipeline,
String... handlerNames)
pipeline - the channel pipelinehandlerNames - names of the handlers to be removedpublic static HttpCarbonMessage createInboundReqCarbonMsg(io.netty.handler.codec.http.HttpRequest httpRequestHeaders, io.netty.channel.ChannelHandlerContext ctx, SourceHandler sourceHandler)
httpRequestHeaders - of inbound requestctx - of the inbound requestsourceHandler - instance which handled the particular requestpublic static HttpCarbonMessage createInboundRespCarbonMsg(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpResponse httpResponseHeaders, HttpCarbonMessage outboundRequestMsg)
ctx - of the inbound response messagehttpResponseHeaders - of the inbound response messageoutboundRequestMsg - is the correlated outbound request messagepublic static boolean isKeepAlive(KeepAliveConfig keepAliveConfig, HttpCarbonMessage outboundRequestMsg) throws ConfigurationException
keepAliveConfig - of the connectionoutboundRequestMsg - of this particular transactionConfigurationException - for invalid configurationspublic static boolean is100ContinueRequest(HttpCarbonMessage inboundRequestMsg)
inboundRequestMsg - in questionpublic static boolean isKeepAliveConnection(KeepAliveConfig keepAliveConfig, String requestConnectionHeader, String httpVersion)
keepAliveConfig - Represents keepalive configurationrequestConnectionHeader - Connection header of the requesthttpVersion - Represents HTTP versionpublic static void setHostNameVerfication(SSLEngine sslEngine)
sslEngine - ssl enginepublic static BackPressureHandler getBackPressureHandler(io.netty.channel.ChannelHandlerContext channelContext)
BackPressureHandler in the pipeline. This requires a ChannelHandlerContext of a handler in the pipeline.channelContext - the channelContext which will be used to obtain the BackPressureHandler in the
pipeline.BackPressureHandler in the pipeline.public static void setBackPressureListener(HttpCarbonMessage outboundMessage, BackPressureHandler backpressureHandler, io.netty.channel.ChannelHandlerContext ctx)
outboundMessage - represents the outbound request or responsebackpressureHandler - the handler that checks the writabilityctx - represents channel handler contextpublic static void checkUnWritabilityAndNotify(io.netty.channel.ChannelHandlerContext context,
BackPressureHandler backpressureHandler)
context - The context on which to check writablity.backpressureHandler - The back pressure handler with the observable.public static void setSslHandshakeTimeOut(SSLConfig sslConfig, io.netty.handler.ssl.SslHandler sslHandler)
public static long ticksInNanos()
public static ScheduledFuture<?> schedule(io.netty.channel.ChannelHandlerContext ctx, Runnable task, long delay)
public static void setCorrelationIdForLogging(io.netty.channel.ChannelPipeline pipeline,
io.netty.channel.ChannelInboundHandlerAdapter srcHandler)
public static void handleOutboundConnectionHeader(SenderConfiguration senderConfiguration, HttpCarbonMessage httpOutboundRequest)
public static void setForwardedExtension(ForwardedExtensionConfig forwardedConfig, String localAddress, HttpCarbonMessage httpOutboundRequest)
public static void setMutualSslStatus(io.netty.channel.ChannelHandlerContext ctx,
SSLEngine sslEngine)
public static void handleIncompleteMsgOnReset(Http2Reset http2Reset, int streamId, HttpCarbonMessage message)
Copyright © 2023 WSO2. All rights reserved.