Class RequestResponseUtils
java.lang.Object
org.apache.synapse.transport.netty.util.RequestResponseUtils
RequestResponseUtils contains utilities used in request and response message flow.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.axis2.context.MessageContextconvertCarbonMsgToAxis2MsgCtx(org.wso2.transport.http.netty.message.HttpCarbonMessage incomingCarbonMsg, SourceConfiguration sourceConfiguration) Create an Axis2 message context for the given HttpCarbonMessage.static org.apache.axis2.addressing.EndpointReferencegetDestinationEPR(org.apache.axis2.context.MessageContext msgContext) Get the EPR for the message passed in.static StringgetHostName(InetAddress address) This method tries to determine the hostname of the given InetAddress without triggering a reverse DNS lookup.static org.wso2.transport.http.netty.contract.config.ListenerConfigurationgetListenerConfig(SourceConfiguration sourceConfiguration, boolean sslEnabled) Returns Listener configuration instance populated with source configuration.static StringgetListenerInterface(String host, int port) static StringgetProtocolVersion(SourceConfiguration sourceConfiguration) static StringgetRestUrlPostfix(String uri, String servicePath) Generate the REST_URL_POSTFIX from the request URI.static StringgetValueOfElementWithLocalName(org.apache.axiom.om.OMElement element, String localName) static voidhandleException(String msg) static voidhandleException(String s, Exception e) static booleanstatic booleanisHttpCarbonMessagePresent(org.apache.axis2.context.MessageContext msgContext) Check if the HTTP_CARBON_MESSAGE is present in the message context.static booleanstatic booleanisMultipartContent(String contentType) Check whether the content type is multipart or not.static booleanisRESTRequest(org.apache.axis2.context.MessageContext msgContext, String contentType, int soapVersion, String soapActionHeader) Checks if the request should be considered as REST.static booleanisRESTSupportedMediaType(String contentType) Checks if the HTTP request is REST based on the given Content-Type header.static voidpopulateKeyStoreConfigs(org.apache.axiom.om.OMElement keyStoreEl, org.wso2.transport.http.netty.contract.config.SslConfiguration sslConfiguration, org.wso2.securevault.SecretResolver secretResolver) static intpopulateSOAPVersion(org.apache.axis2.context.MessageContext msgContext, String contentType) Populates the SOAP version based on the given Content-Type.static voidpopulateTrustStoreConfigs(org.apache.axiom.om.OMElement trustStoreEl, org.wso2.transport.http.netty.contract.config.SslConfiguration sslConfiguration, org.wso2.securevault.SecretResolver secretResolver) static voidsetInboundMgsSizeValidationConfig(int maxInitialLineLength, int maxHeaderSize, int maxEntityBodySize, org.wso2.transport.http.netty.contract.config.InboundMsgSizeValidationConfig sizeValidationConfig) Sets the configuration for the inbound request and response size validation.static org.wso2.transport.http.netty.contract.config.ListenerConfigurationsetSslConfig(org.apache.axis2.description.TransportInDescription transportIn, org.wso2.transport.http.netty.contract.config.ListenerConfiguration listenerConfiguration, BaseConfiguration sourceConfiguration) static booleanshouldInvokeFormatterToWriteBody(org.apache.axis2.context.MessageContext msgContext) Checks if the request/response body should be written using the appropriate message formatter.
-
Constructor Details
-
RequestResponseUtils
public RequestResponseUtils()
-
-
Method Details
-
convertCarbonMsgToAxis2MsgCtx
public static org.apache.axis2.context.MessageContext convertCarbonMsgToAxis2MsgCtx(org.wso2.transport.http.netty.message.HttpCarbonMessage incomingCarbonMsg, SourceConfiguration sourceConfiguration) Create an Axis2 message context for the given HttpCarbonMessage. The carbon message may be in the process of being streamed.- Parameters:
incomingCarbonMsg- the http carbon message to be used to create the corresponding Axis2 message contextsourceConfiguration- source configuration- Returns:
- the Axis2 message context created
-
getHostName
This method tries to determine the hostname of the given InetAddress without triggering a reverse DNS lookup.InetAddress.getHostName()triggers a reverse DNS lookup which can be very costly in cases where reverse DNS fails. Tries to parse a symbolic hostname fromInetAddress.toString(), which is documented to return a String of the form "hostname / literal IP address" with 'hostname' blank if not already computed invalid input: '&' stored inaddress. If the hostname cannot be determined from InetAddress.toString(), the value ofInetAddress.getHostAddress()is returned.- Parameters:
address- The InetAddress whose hostname has to be determined- Returns:
- hostsname, if it can be determined. hostaddress, if not.
-
isHttpCarbonMessagePresent
public static boolean isHttpCarbonMessagePresent(org.apache.axis2.context.MessageContext msgContext) Check if the HTTP_CARBON_MESSAGE is present in the message context.- Parameters:
msgContext- axis2 message context- Returns:
- true if HTTP_CARBON_MESSAGE is present in the message context, false otherwise
-
shouldInvokeFormatterToWriteBody
public static boolean shouldInvokeFormatterToWriteBody(org.apache.axis2.context.MessageContext msgContext) Checks if the request/response body should be written using the appropriate message formatter.- Parameters:
msgContext- axis2 message context- Returns:
- true if the request was initiated from a non-http client or if the message has been built. Otherwise, return false if this is pass-through.
-
isMultipartContent
Check whether the content type is multipart or not.- Parameters:
contentType- value of the content type- Returns:
- true for multipart content types
-
getRestUrlPostfix
Generate the REST_URL_POSTFIX from the request URI.- Parameters:
uri- the Request URI as a stringservicePath- service path- Returns:
- REST_URL_POSTFIX as a string
-
isRESTSupportedMediaType
Checks if the HTTP request is REST based on the given Content-Type header.- Parameters:
contentType- Content-Type header- Returns:
- whether the HTTP request is REST or not
-
populateSOAPVersion
public static int populateSOAPVersion(org.apache.axis2.context.MessageContext msgContext, String contentType) Populates the SOAP version based on the given Content-Type.- Parameters:
msgContext- axis2 message contextcontentType- Content type of the request.- Returns:
- 0 if the content type is null. return 2 if the content type is application/soap+xml. Otherwise 1
-
isRESTRequest
public static boolean isRESTRequest(org.apache.axis2.context.MessageContext msgContext, String contentType, int soapVersion, String soapActionHeader) Checks if the request should be considered as REST.- Parameters:
msgContext- axis2 message contextcontentType- content-type of the requestsoapVersion- SOAP versionsoapActionHeader- SOAPAction header- Returns:
- whether the request should be considered as REST
-
getDestinationEPR
public static org.apache.axis2.addressing.EndpointReference getDestinationEPR(org.apache.axis2.context.MessageContext msgContext) Get the EPR for the message passed in.- Parameters:
msgContext- the message context- Returns:
- the destination EPR
-
getListenerConfig
public static org.wso2.transport.http.netty.contract.config.ListenerConfiguration getListenerConfig(SourceConfiguration sourceConfiguration, boolean sslEnabled) throws org.apache.axis2.AxisFault Returns Listener configuration instance populated with source configuration.- Parameters:
sourceConfiguration- source configuration- Returns:
- transport listener configuration instance
- Throws:
org.apache.axis2.AxisFault
-
getProtocolVersion
-
isHTTPTraceLoggerEnabled
public static boolean isHTTPTraceLoggerEnabled() -
isHTTPAccessLoggerEnabled
public static boolean isHTTPAccessLoggerEnabled() -
setSslConfig
public static org.wso2.transport.http.netty.contract.config.ListenerConfiguration setSslConfig(org.apache.axis2.description.TransportInDescription transportIn, org.wso2.transport.http.netty.contract.config.ListenerConfiguration listenerConfiguration, BaseConfiguration sourceConfiguration) throws org.apache.axis2.AxisFault - Throws:
org.apache.axis2.AxisFault
-
populateKeyStoreConfigs
public static void populateKeyStoreConfigs(org.apache.axiom.om.OMElement keyStoreEl, org.wso2.transport.http.netty.contract.config.SslConfiguration sslConfiguration, org.wso2.securevault.SecretResolver secretResolver) throws org.apache.axis2.AxisFault - Throws:
org.apache.axis2.AxisFault
-
populateTrustStoreConfigs
public static void populateTrustStoreConfigs(org.apache.axiom.om.OMElement trustStoreEl, org.wso2.transport.http.netty.contract.config.SslConfiguration sslConfiguration, org.wso2.securevault.SecretResolver secretResolver) throws org.apache.axis2.AxisFault - Throws:
org.apache.axis2.AxisFault
-
setInboundMgsSizeValidationConfig
public static void setInboundMgsSizeValidationConfig(int maxInitialLineLength, int maxHeaderSize, int maxEntityBodySize, org.wso2.transport.http.netty.contract.config.InboundMsgSizeValidationConfig sizeValidationConfig) throws org.apache.axis2.AxisFault Sets the configuration for the inbound request and response size validation.- Parameters:
maxInitialLineLength- The maximum length of the initial line (e.g."GET / HTTP/1.0"or"HTTP/1.0 200 OK")maxHeaderSize- The maximum length of all headers.maxEntityBodySize- The maximum length of the content or each chunk.sizeValidationConfig- instance that represents the configuration for the inbound request and response size validation.- Throws:
org.apache.axis2.AxisFault- when the given values are invalid.
-
getValueOfElementWithLocalName
-
getListenerInterface
-
handleException
- Throws:
org.apache.axis2.AxisFault
-
handleException
- Throws:
org.apache.axis2.AxisFault
-