public class HttpUtil extends Object
Modifier and Type | Field and Description |
---|---|
static boolean |
FALSE |
static boolean |
TRUE |
Modifier and Type | Method and Description |
---|---|
static String |
addBoundaryIfNotExist(org.wso2.transport.http.netty.message.HttpCarbonMessage transportMessage,
String contentType)
If the given Content-Type header value doesn't have a boundary parameter value, get a new boundary string and
append it to Content-Type and set it to transport message.
|
static void |
addCarbonMsg(BMap<String,BValue> struct,
org.wso2.transport.http.netty.message.HttpCarbonMessage httpCarbonMessage) |
static void |
addHTTPSessionAndCorsHeaders(Context context,
org.wso2.transport.http.netty.message.HttpCarbonMessage requestMsg,
org.wso2.transport.http.netty.message.HttpCarbonMessage responseMsg) |
static void |
checkAndObserveHttpRequest(Context context,
org.wso2.transport.http.netty.message.HttpCarbonMessage message) |
static boolean |
checkConfigAnnotationAvailability(Annotation configAnnotation)
Check the availability of an annotation.
|
static void |
checkEntityAvailability(Context context,
BMap<String,BValue> struct)
Check the existence of entity.
|
static void |
checkFunctionValidity(BMap<String,BValue> connectionStruct,
org.wso2.transport.http.netty.message.HttpCarbonMessage reqMsg,
org.wso2.transport.http.netty.message.HttpCarbonMessage outboundResponseMsg) |
static Boolean |
checkRequestBodySizeHeadersAvailability(org.wso2.transport.http.netty.message.HttpCarbonMessage message)
Check the existence of content-length and transfer-encoding headers.
|
static void |
closeMessageOutputStream(OutputStream messageOutputStream) |
static org.wso2.transport.http.netty.message.HttpCarbonMessage |
createErrorMessage(String payload,
int statusCode) |
static org.wso2.transport.http.netty.message.HttpCarbonMessage |
createHttpCarbonMessage(boolean isRequest) |
static org.wso2.transport.http.netty.message.Http2PushPromise |
createHttpPushPromise(BMap<String,BValue> struct)
Creates native
Http2PushPromise from PushPromise struct. |
static org.wso2.transport.http.netty.contract.HttpWsConnectorFactory |
createHttpWsConnectionFactory() |
static BMap<String,BValue> |
createNewEntity(Context context,
BMap<String,BValue> httpMessageStruct)
Set new entity to in/out request/response struct.
|
static BMap<String,BValue> |
createResponseStruct(Context context,
org.wso2.transport.http.netty.message.HttpCarbonMessage httpCarbonMessage)
Creates InResponse using the native
HttpCarbonMessage . |
static BMap<String,BValue> |
createSessionStruct(Context context,
Session session) |
static void |
enrichHttpCallerWithConnectionInfo(BMap<String,BValue> httpCaller,
org.wso2.transport.http.netty.message.HttpCarbonMessage inboundMsg,
HttpResource httpResource,
Struct config)
Populates the HTTP caller with connection information.
|
static void |
enrichHttpCallerWithNativeData(BMap<String,BValue> caller,
org.wso2.transport.http.netty.message.HttpCarbonMessage inboundMsg,
Struct config)
Populates the HTTP caller with native data.
|
static void |
enrichOutboundMessage(org.wso2.transport.http.netty.message.HttpCarbonMessage outboundMsg,
BMap<String,BValue> outboundStruct)
Set headers and properties of request/response struct to the outbound transport message.
|
static BMap<String,BValue> |
extractEntity(BMap<String,BValue> httpMessageStruct) |
static org.wso2.transport.http.netty.message.HttpCarbonMessage |
getCarbonMsg(BMap<String,BValue> struct,
org.wso2.transport.http.netty.message.HttpCarbonMessage defaultMsg) |
static org.wso2.transport.http.netty.contract.config.ChunkConfig |
getChunkConfig(String chunkConfig) |
static CompressionConfigState |
getCompressionState(String compressionState) |
static String |
getContentTypeFromTransportMessage(org.wso2.transport.http.netty.message.HttpCarbonMessage transportMessage) |
static BValue[] |
getEntity(Context context,
boolean isRequest,
boolean entityBodyRequired)
Get the entity from request or response.
|
static BError |
getError(Context context,
String errMsg)
Get error struct.
|
static BError |
getError(Context context,
Throwable throwable)
Get error struct from throwable.
|
static org.wso2.transport.http.netty.contract.config.ForwardedExtensionConfig |
getForwardedExtensionConfig(String forwarded) |
static org.wso2.transport.http.netty.contract.config.KeepAliveConfig |
getKeepAliveConfig(String keepAliveConfig) |
static org.wso2.transport.http.netty.contract.config.ListenerConfiguration |
getListenerConfig(long port,
Struct endpointConfig)
Returns Listener configuration instance populated with endpoint config.
|
static String |
getListenerInterface(String host,
int port) |
static BValue[] |
getProperty(Context context,
boolean isRequest) |
static org.wso2.transport.http.netty.message.Http2PushPromise |
getPushPromise(BMap<String,BValue> pushPromiseStruct,
org.wso2.transport.http.netty.message.Http2PushPromise defaultPushPromise)
Gets the
Http2PushPromise represented by the PushPromise struct. |
static Annotation |
getResourceConfigAnnotation(Resource resource,
String pkgPath) |
static Annotation |
getServiceConfigAnnotation(Service service,
String pkgPath) |
static Annotation |
getServiceConfigStruct(Service service,
String pkgPath) |
static String |
getSessionID(String cookieHeader) |
static Annotation |
getTransactionConfigAnnotation(Resource resource,
String transactionPackagePath) |
static void |
handleFailure(org.wso2.transport.http.netty.message.HttpCarbonMessage requestMessage,
BallerinaConnectorException ex) |
static void |
injectHeaders(org.wso2.transport.http.netty.message.HttpCarbonMessage msg,
Map<String,String> headers) |
static boolean |
isEntityDataSourceAvailable(BMap<String,BValue> struct)
Check the existence of the message entity data source.
|
static boolean |
isRequestStruct(BMap<String,BValue> struct) |
static void |
populateEntityBody(Context context,
BMap<String,BValue> httpMessageStruct,
BMap<String,BValue> entity,
boolean isRequest)
Populate entity with the relevant body content.
|
static void |
populateInboundRequest(BMap<String,BValue> inboundRequestStruct,
BMap<String,BValue> entity,
BMap<String,BValue> mediaType,
org.wso2.transport.http.netty.message.HttpCarbonMessage inboundRequestMsg,
ProgramFile programFile) |
static void |
populateInboundResponse(BMap<String,BValue> inboundResponse,
BMap<String,BValue> entity,
BMap<String,BValue> mediaType,
ProgramFile programFile,
org.wso2.transport.http.netty.message.HttpCarbonMessage inboundResponseMsg)
Populate inbound response with headers and entity.
|
static void |
populatePushPromiseStruct(BMap<String,BValue> pushPromiseStruct,
org.wso2.transport.http.netty.message.Http2PushPromise pushPromise)
Populates the push promise struct from native
Http2PushPromise . |
static void |
populateSenderConfigurationOptions(org.wso2.transport.http.netty.contract.config.SenderConfiguration senderConfiguration,
Struct clientEndpointConfig)
Populates Sender configuration instance with client endpoint configuration.
|
static void |
populateSSLConfiguration(org.wso2.transport.http.netty.contract.config.SslConfiguration sslConfiguration,
Struct secureSocket)
Populates SSL configuration instance with secure socket configuration.
|
static void |
prepareOutboundResponse(Context context,
org.wso2.transport.http.netty.message.HttpCarbonMessage inboundRequestMsg,
org.wso2.transport.http.netty.message.HttpCarbonMessage outboundResponseMsg,
BMap<String,BValue> outboundResponseStruct) |
static org.wso2.transport.http.netty.contract.HttpResponseFuture |
pushPromise(org.wso2.transport.http.netty.message.HttpCarbonMessage requestMsg,
org.wso2.transport.http.netty.message.Http2PushPromise pushPromise)
Sends an HTTP/2 Push Promise message back to the client.
|
static org.wso2.transport.http.netty.contract.HttpResponseFuture |
pushResponse(org.wso2.transport.http.netty.message.HttpCarbonMessage requestMsg,
org.wso2.transport.http.netty.message.HttpCarbonMessage pushResponse,
org.wso2.transport.http.netty.message.Http2PushPromise pushPromise)
Sends an HTTP/2 Server Push message back to the client.
|
static String |
sanitizeBasePath(String basePath) |
static org.wso2.transport.http.netty.contract.HttpResponseFuture |
sendOutboundResponse(org.wso2.transport.http.netty.message.HttpCarbonMessage requestMsg,
org.wso2.transport.http.netty.message.HttpCarbonMessage responseMsg)
This method should never be called directly to send out responses for ballerina HTTP 1.1.
|
static void |
serializeDataSource(BValue outboundMessageSource,
BMap<String,BValue> entity,
OutputStream messageOutputStream)
Serialize outbound message.
|
static void |
serverConnectionStructCheck(org.wso2.transport.http.netty.message.HttpCarbonMessage reqMsg) |
static void |
setDefaultTrustStore(org.wso2.transport.http.netty.contract.config.SslConfiguration sslConfiguration) |
static void |
setEntity(Context context,
boolean isRequest)
Set the given entity to request or response message.
|
static void |
setProperty(Context context,
boolean isRequest) |
public static final boolean TRUE
public static final boolean FALSE
public static void setProperty(Context context, boolean isRequest)
public static BMap<String,BValue> createNewEntity(Context context, BMap<String,BValue> httpMessageStruct)
context
- ballerina context.httpMessageStruct
- request/response struct.public static void setEntity(Context context, boolean isRequest)
context
- Ballerina contextisRequest
- boolean representing whether the message is a request or a responsepublic static BValue[] getEntity(Context context, boolean isRequest, boolean entityBodyRequired)
context
- Ballerina contextisRequest
- boolean representing whether the message is a request or a responseentityBodyRequired
- boolean representing whether the entity body is requiredpublic static void populateEntityBody(Context context, BMap<String,BValue> httpMessageStruct, BMap<String,BValue> entity, boolean isRequest)
context
- Represent ballerina contexthttpMessageStruct
- Represent ballerina request/responseentity
- Represent an entityisRequest
- boolean representing whether the message is a request or a responsepublic static BMap<String,BValue> extractEntity(BMap<String,BValue> httpMessageStruct)
public static void closeMessageOutputStream(OutputStream messageOutputStream)
public static void prepareOutboundResponse(Context context, org.wso2.transport.http.netty.message.HttpCarbonMessage inboundRequestMsg, org.wso2.transport.http.netty.message.HttpCarbonMessage outboundResponseMsg, BMap<String,BValue> outboundResponseStruct)
public static BMap<String,BValue> createSessionStruct(Context context, Session session)
public static void addHTTPSessionAndCorsHeaders(Context context, org.wso2.transport.http.netty.message.HttpCarbonMessage requestMsg, org.wso2.transport.http.netty.message.HttpCarbonMessage responseMsg)
public static org.wso2.transport.http.netty.contract.HttpResponseFuture sendOutboundResponse(org.wso2.transport.http.netty.message.HttpCarbonMessage requestMsg, org.wso2.transport.http.netty.message.HttpCarbonMessage responseMsg)
requestMsg
- Represent the request messageresponseMsg
- Represent the corresponding responsepublic static org.wso2.transport.http.netty.contract.HttpResponseFuture pushResponse(org.wso2.transport.http.netty.message.HttpCarbonMessage requestMsg, org.wso2.transport.http.netty.message.HttpCarbonMessage pushResponse, org.wso2.transport.http.netty.message.Http2PushPromise pushPromise)
requestMsg
- the request message associated to the server push responsepushResponse
- the server push messagepushPromise
- the push promise associated with the server pushpublic static org.wso2.transport.http.netty.contract.HttpResponseFuture pushPromise(org.wso2.transport.http.netty.message.HttpCarbonMessage requestMsg, org.wso2.transport.http.netty.message.Http2PushPromise pushPromise)
requestMsg
- the request message associated to the push promisepushPromise
- the push promise messagepublic static void handleFailure(org.wso2.transport.http.netty.message.HttpCarbonMessage requestMessage, BallerinaConnectorException ex)
public static org.wso2.transport.http.netty.message.HttpCarbonMessage createErrorMessage(String payload, int statusCode)
public static BError getError(Context context, String errMsg)
context
- Represent ballerina contexterrMsg
- Error messagepublic static BError getError(Context context, Throwable throwable)
context
- Represent ballerina contextthrowable
- Throwable representing the error.public static org.wso2.transport.http.netty.message.HttpCarbonMessage getCarbonMsg(BMap<String,BValue> struct, org.wso2.transport.http.netty.message.HttpCarbonMessage defaultMsg)
public static org.wso2.transport.http.netty.message.Http2PushPromise getPushPromise(BMap<String,BValue> pushPromiseStruct, org.wso2.transport.http.netty.message.Http2PushPromise defaultPushPromise)
Http2PushPromise
represented by the PushPromise struct.pushPromiseStruct
- the push promise structdefaultPushPromise
- the Http2PushPromise to use if the struct does not have native data of a push promiseHttp2PushPromise
represented by the PushPromise structpublic static void populatePushPromiseStruct(BMap<String,BValue> pushPromiseStruct, org.wso2.transport.http.netty.message.Http2PushPromise pushPromise)
Http2PushPromise
.pushPromiseStruct
- the push promise structpushPromise
- the native Http2PushPromisepublic static org.wso2.transport.http.netty.message.Http2PushPromise createHttpPushPromise(BMap<String,BValue> struct)
Http2PushPromise
from PushPromise struct.struct
- the PushPromise structHttp2PushPromise
public static void addCarbonMsg(BMap<String,BValue> struct, org.wso2.transport.http.netty.message.HttpCarbonMessage httpCarbonMessage)
public static void populateInboundRequest(BMap<String,BValue> inboundRequestStruct, BMap<String,BValue> entity, BMap<String,BValue> mediaType, org.wso2.transport.http.netty.message.HttpCarbonMessage inboundRequestMsg, ProgramFile programFile)
public static void enrichHttpCallerWithNativeData(BMap<String,BValue> caller, org.wso2.transport.http.netty.message.HttpCarbonMessage inboundMsg, Struct config)
caller
- Represents the HTTP callerinboundMsg
- Represents carbon messageconfig
- Represents service endpoint configurationpublic static void enrichHttpCallerWithConnectionInfo(BMap<String,BValue> httpCaller, org.wso2.transport.http.netty.message.HttpCarbonMessage inboundMsg, HttpResource httpResource, Struct config)
httpCaller
- Represents the HTTP callerinboundMsg
- Represents the carbon messagehttpResource
- Represents the Http Resourceconfig
- Represents the service endpoint configurationpublic static void populateInboundResponse(BMap<String,BValue> inboundResponse, BMap<String,BValue> entity, BMap<String,BValue> mediaType, ProgramFile programFile, org.wso2.transport.http.netty.message.HttpCarbonMessage inboundResponseMsg)
inboundResponse
- Ballerina struct to represent responseentity
- Entity of the responsemediaType
- Content type of the responseprogramFile
- Cache control struct which holds the cache control directives related to the
responseinboundResponseMsg
- Represent carbon message.public static void enrichOutboundMessage(org.wso2.transport.http.netty.message.HttpCarbonMessage outboundMsg, BMap<String,BValue> outboundStruct)
outboundMsg
- transport Http carbon message.outboundStruct
- req/resp struct.public static void checkEntityAvailability(Context context, BMap<String,BValue> struct)
context
- ballerina context.struct
- request/response struct.public static Boolean checkRequestBodySizeHeadersAvailability(org.wso2.transport.http.netty.message.HttpCarbonMessage message)
message
- transport messagepublic static boolean isEntityDataSourceAvailable(BMap<String,BValue> struct)
struct
- request/response struct.public static CompressionConfigState getCompressionState(String compressionState)
public static org.wso2.transport.http.netty.contract.config.ChunkConfig getChunkConfig(String chunkConfig)
public static org.wso2.transport.http.netty.contract.config.KeepAliveConfig getKeepAliveConfig(String keepAliveConfig)
public static org.wso2.transport.http.netty.contract.config.ForwardedExtensionConfig getForwardedExtensionConfig(String forwarded)
public static org.wso2.transport.http.netty.message.HttpCarbonMessage createHttpCarbonMessage(boolean isRequest)
public static void checkFunctionValidity(BMap<String,BValue> connectionStruct, org.wso2.transport.http.netty.message.HttpCarbonMessage reqMsg, org.wso2.transport.http.netty.message.HttpCarbonMessage outboundResponseMsg)
public static void serverConnectionStructCheck(org.wso2.transport.http.netty.message.HttpCarbonMessage reqMsg)
public static Annotation getServiceConfigAnnotation(Service service, String pkgPath)
public static Annotation getServiceConfigStruct(Service service, String pkgPath)
public static Annotation getResourceConfigAnnotation(Resource resource, String pkgPath)
public static Annotation getTransactionConfigAnnotation(Resource resource, String transactionPackagePath)
public static String getContentTypeFromTransportMessage(org.wso2.transport.http.netty.message.HttpCarbonMessage transportMessage)
public static String addBoundaryIfNotExist(org.wso2.transport.http.netty.message.HttpCarbonMessage transportMessage, String contentType)
transportMessage
- Represent transport messagecontentType
- Represent the Content-Type header valuepublic static org.wso2.transport.http.netty.contract.HttpWsConnectorFactory createHttpWsConnectionFactory()
public static void checkAndObserveHttpRequest(Context context, org.wso2.transport.http.netty.message.HttpCarbonMessage message)
public static void injectHeaders(org.wso2.transport.http.netty.message.HttpCarbonMessage msg, Map<String,String> headers)
public static BMap<String,BValue> createResponseStruct(Context context, org.wso2.transport.http.netty.message.HttpCarbonMessage httpCarbonMessage)
HttpCarbonMessage
.context
- ballerina contexthttpCarbonMessage
- the HttpCarbonMessagepublic static void populateSenderConfigurationOptions(org.wso2.transport.http.netty.contract.config.SenderConfiguration senderConfiguration, Struct clientEndpointConfig)
senderConfiguration
- sender configuration instance.clientEndpointConfig
- client endpoint configuration.public static void populateSSLConfiguration(org.wso2.transport.http.netty.contract.config.SslConfiguration sslConfiguration, Struct secureSocket)
sslConfiguration
- ssl configuration instance.secureSocket
- secure socket configuration.public static void setDefaultTrustStore(org.wso2.transport.http.netty.contract.config.SslConfiguration sslConfiguration)
public static void serializeDataSource(BValue outboundMessageSource, BMap<String,BValue> entity, OutputStream messageOutputStream) throws IOException
outboundMessageSource
- Represent the outbound message datasourceentity
- Represent the entity of the outbound messagemessageOutputStream
- Represent the output streamIOException
- In case an error occurs while writing to output streampublic static boolean checkConfigAnnotationAvailability(Annotation configAnnotation)
configAnnotation
- Represent the annotationpublic static org.wso2.transport.http.netty.contract.config.ListenerConfiguration getListenerConfig(long port, Struct endpointConfig)
port
- listener port.endpointConfig
- listener endpoint configuration.Copyright © 2019 WSO2. All rights reserved.