Class HttpUtils
- java.lang.Object
-
- org.apache.synapse.transport.netty.util.HttpUtils
-
public class HttpUtils extends Object
Utility class providing HTTP utility methods.
-
-
Constructor Summary
Constructors Constructor Description HttpUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addTransportHeadersToTransportMessage(io.netty.handler.codec.http.HttpHeaders headers, org.apache.axis2.context.MessageContext msgCtx)
static void
closeMessageOutputStreamQuietly(OutputStream messageOutputStream)
static void
copyContentFromInboundHttpCarbonMessage(org.wso2.transport.http.netty.message.HttpCarbonMessage inboundMsg, org.wso2.transport.http.netty.message.HttpCarbonMessage outboundResponseMsg)
static org.wso2.transport.http.netty.contractimpl.sender.channel.pool.ConnectionManager
getConnectionManager()
static org.wso2.transport.http.netty.message.HttpMessageDataStreamer
getHttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpCarbonMessage outboundResponse)
Get the response data streamer that should be used for serializing data.static boolean
isCONNECTRequest(org.apache.axis2.context.MessageContext msgCtx)
static boolean
isFaultMessage(org.apache.axis2.context.MessageContext msgContext)
static boolean
isGETRequest(org.apache.axis2.context.MessageContext msgCtx)
static boolean
isHEADRequest(org.apache.axis2.context.MessageContext msgCtx)
static boolean
isNoEntityBodyRequest(org.apache.axis2.context.MessageContext msgCtx)
static void
populatePoolingConfig(org.wso2.transport.http.netty.contractimpl.sender.channel.pool.PoolConfiguration poolConfiguration)
static org.wso2.transport.http.netty.contract.HttpResponseFuture
pushPromise(org.wso2.transport.http.netty.message.Http2PushPromise pushPromise, org.wso2.transport.http.netty.message.HttpCarbonMessage requestMsg)
Send the server push promises to the client.static org.wso2.transport.http.netty.contract.HttpResponseFuture
pushResponse(org.wso2.transport.http.netty.message.Http2PushPromise http2PushPromise, org.wso2.transport.http.netty.message.HttpCarbonMessage outboundPushMsg, org.wso2.transport.http.netty.message.HttpCarbonMessage requestMsg)
Send the promised server push responses to the client.static void
removeUnwantedHeadersFromInternalTransportHeadersMap(org.apache.axis2.context.MessageContext msgContext, BaseConfiguration baseConfiguration)
RRemove unwanted headers from the http response of outgoing request.static boolean
requestHasEntityBody(org.wso2.transport.http.netty.message.HttpCarbonMessage httpCarbonMessage)
Checks if the given HttpCarbonMessage has an entity body.static boolean
sendFaultAsHTTP200(org.apache.axis2.context.MessageContext msgContext)
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)
InvokesHttpResponseFuture
respond method to send the response back to the client.static void
serializeBytes(OutputStream outputStream, byte[] bytes)
static void
serializeDataUsingMessageFormatter(org.apache.axis2.context.MessageContext msgContext, org.apache.axis2.transport.MessageFormatter messageFormatter, OutputStream outputStream)
static void
setHostHeader(String host, int port, io.netty.handler.codec.http.HttpHeaders headers, org.apache.axis2.context.MessageContext msgCtx, boolean isPreservedHeader)
static void
writeEmptyBody(OutputStream outputStream)
-
-
-
Method Detail
-
getConnectionManager
public static org.wso2.transport.http.netty.contractimpl.sender.channel.pool.ConnectionManager getConnectionManager()
-
populatePoolingConfig
public static void populatePoolingConfig(org.wso2.transport.http.netty.contractimpl.sender.channel.pool.PoolConfiguration poolConfiguration)
-
removeUnwantedHeadersFromInternalTransportHeadersMap
public static void removeUnwantedHeadersFromInternalTransportHeadersMap(org.apache.axis2.context.MessageContext msgContext, BaseConfiguration baseConfiguration)
RRemove unwanted headers from the http response of outgoing request. These are headers which should be dictated by the transport and not by the user. We remove these as these may get copied from the request messages.- Parameters:
msgContext
- axis2 message contextbaseConfiguration
- configuration that has all the preserved header details
-
isFaultMessage
public static boolean isFaultMessage(org.apache.axis2.context.MessageContext msgContext)
-
sendFaultAsHTTP200
public static boolean sendFaultAsHTTP200(org.apache.axis2.context.MessageContext msgContext)
-
requestHasEntityBody
public static boolean requestHasEntityBody(org.wso2.transport.http.netty.message.HttpCarbonMessage httpCarbonMessage)
Checks if the given HttpCarbonMessage has an entity body.- Parameters:
httpCarbonMessage
- HttpCarbonMessage in which we need to check if an entity body is present- Returns:
- true if the HttpCarbonMessage has an entity body enclosed
-
sendOutboundResponse
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) throws org.apache.axis2.AxisFault
InvokesHttpResponseFuture
respond method to send the response back to the client.- Parameters:
requestMsg
- Represent the request messageresponseMsg
- Represent the corresponding response- Returns:
- HttpResponseFuture that represent the future results
- Throws:
org.apache.axis2.AxisFault
-
pushPromise
public static org.wso2.transport.http.netty.contract.HttpResponseFuture pushPromise(org.wso2.transport.http.netty.message.Http2PushPromise pushPromise, org.wso2.transport.http.netty.message.HttpCarbonMessage requestMsg) throws org.apache.axis2.AxisFault
Send the server push promises to the client.- Parameters:
pushPromise
- Http2PushPromiserequestMsg
- HttpCarbonMessage- Returns:
- HttpResponseFuture
- Throws:
org.apache.axis2.AxisFault
- if error occurred while sending server pushes
-
pushResponse
public static org.wso2.transport.http.netty.contract.HttpResponseFuture pushResponse(org.wso2.transport.http.netty.message.Http2PushPromise http2PushPromise, org.wso2.transport.http.netty.message.HttpCarbonMessage outboundPushMsg, org.wso2.transport.http.netty.message.HttpCarbonMessage requestMsg) throws org.apache.axis2.AxisFault
Send the promised server push responses to the client.- Parameters:
http2PushPromise
- Http2PushPromiseoutboundPushMsg
- HttpCarbonMessagerequestMsg
- HttpCarbonMessage- Returns:
- HttpResponseFuture
- Throws:
org.apache.axis2.AxisFault
- if error occurred while sending the server push responses
-
getHttpMessageDataStreamer
public static org.wso2.transport.http.netty.message.HttpMessageDataStreamer getHttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpCarbonMessage outboundResponse)
Get the response data streamer that should be used for serializing data.- Parameters:
outboundResponse
- Represents native response- Returns:
- HttpMessageDataStreamer that should be used for serializing
-
serializeDataUsingMessageFormatter
public static void serializeDataUsingMessageFormatter(org.apache.axis2.context.MessageContext msgContext, org.apache.axis2.transport.MessageFormatter messageFormatter, OutputStream outputStream) throws org.apache.axis2.AxisFault
- Throws:
org.apache.axis2.AxisFault
-
serializeBytes
public static void serializeBytes(OutputStream outputStream, byte[] bytes) throws org.apache.axis2.AxisFault
- Throws:
org.apache.axis2.AxisFault
-
writeEmptyBody
public static void writeEmptyBody(OutputStream outputStream) throws org.apache.axis2.AxisFault
- Throws:
org.apache.axis2.AxisFault
-
copyContentFromInboundHttpCarbonMessage
public static void copyContentFromInboundHttpCarbonMessage(org.wso2.transport.http.netty.message.HttpCarbonMessage inboundMsg, org.wso2.transport.http.netty.message.HttpCarbonMessage outboundResponseMsg)
-
closeMessageOutputStreamQuietly
public static void closeMessageOutputStreamQuietly(OutputStream messageOutputStream)
-
isGETRequest
public static boolean isGETRequest(org.apache.axis2.context.MessageContext msgCtx)
-
isHEADRequest
public static boolean isHEADRequest(org.apache.axis2.context.MessageContext msgCtx)
-
isCONNECTRequest
public static boolean isCONNECTRequest(org.apache.axis2.context.MessageContext msgCtx)
-
isNoEntityBodyRequest
public static boolean isNoEntityBodyRequest(org.apache.axis2.context.MessageContext msgCtx)
-
addTransportHeadersToTransportMessage
public static void addTransportHeadersToTransportMessage(io.netty.handler.codec.http.HttpHeaders headers, org.apache.axis2.context.MessageContext msgCtx)
-
setHostHeader
public static void setHostHeader(String host, int port, io.netty.handler.codec.http.HttpHeaders headers, org.apache.axis2.context.MessageContext msgCtx, boolean isPreservedHeader)
-
-