Package org.apache.synapse.transport.netty.util

## Class RequestResponseUtils

- java.lang.Object
- - org.apache.synapse.transport.netty.util.RequestResponseUtils

-     public class RequestResponseUtils
      extends Object

  `RequestResponseUtils` contains utilities used in request and response message flow.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `RequestResponseUtils()` |

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `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.
    `static org.apache.axis2.addressing.EndpointReference` | `getDestinationEPR​(org.apache.axis2.context.MessageContext msgContext)` | Get the EPR for the message passed in.
    `static String` | `getHostName​(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.ListenerConfiguration` | `getListenerConfig​(SourceConfiguration sourceConfiguration, boolean sslEnabled)` | Returns Listener configuration instance populated with source configuration.
    `static String` | `getListenerInterface​(String host, int port)` |
    `static String` | `getProtocolVersion​(SourceConfiguration sourceConfiguration)` |
    `static String` | `getRestUrlPostfix​(String uri, String servicePath)` | Generate the REST_URL_POSTFIX from the request URI.
    `static String` | `getValueOfElementWithLocalName​(org.apache.axiom.om.OMElement element, String localName)` |
    `static void` | `handleException​(String msg)` |
    `static void` | `handleException​(String s, Exception e)` |
    `static boolean` | `isHTTPAccessLoggerEnabled()` |
    `static boolean` | `isHttpCarbonMessagePresent​(org.apache.axis2.context.MessageContext msgContext)` | Check if the HTTP_CARBON_MESSAGE is present in the message context.
    `static boolean` | `isHTTPTraceLoggerEnabled()` |
    `static boolean` | `isMultipartContent​(String contentType)` | Check whether the content type is multipart or not.
    `static boolean` | `isRESTRequest​(org.apache.axis2.context.MessageContext msgContext, String contentType, int soapVersion, String soapActionHeader)` | Checks if the request should be considered as REST.
    `static boolean` | `isRESTSupportedMediaType​(String contentType)` | Checks if the HTTP request is REST based on the given Content-Type header.
    `static void` | `populateKeyStoreConfigs​(org.apache.axiom.om.OMElement keyStoreEl, org.wso2.transport.http.netty.contract.config.SslConfiguration sslConfiguration, org.wso2.securevault.SecretResolver secretResolver)` |
    `static int` | `populateSOAPVersion​(org.apache.axis2.context.MessageContext msgContext, String contentType)` | Populates the SOAP version based on the given Content-Type.
    `static void` | `populateTrustStoreConfigs​(org.apache.axiom.om.OMElement trustStoreEl, org.wso2.transport.http.netty.contract.config.SslConfiguration sslConfiguration, org.wso2.securevault.SecretResolver secretResolver)` |
    `static void` | `setInboundMgsSizeValidationConfig​(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.ListenerConfiguration` | `setSslConfig​(org.apache.axis2.description.TransportInDescription transportIn, org.wso2.transport.http.netty.contract.config.ListenerConfiguration listenerConfiguration, BaseConfiguration sourceConfiguration)` |
    `static boolean` | `shouldInvokeFormatterToWriteBody​(org.apache.axis2.context.MessageContext msgContext)` | Checks if the request/response body should be written using the appropriate message formatter.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### RequestResponseUtils

          public RequestResponseUtils()

  - ### Method Detail

    - #### 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 context
        `sourceConfiguration` - source configuration
      Returns:
        the Axis2 message context created

    - #### getHostName

          public static String getHostName​(InetAddress address)

      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 from `InetAddress.toString()`, which is documented to return a String of the form "hostname / literal IP address" with 'hostname' blank if not already computed & stored in `address`.

      If the hostname cannot be determined from InetAddress.toString(), the value of `InetAddress.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

          public static boolean isMultipartContent​(String contentType)

      Check whether the content type is multipart or not.
      Parameters:
        `contentType` - value of the content type
      Returns:
        true for multipart content types

    - #### getRestUrlPostfix

          public static String getRestUrlPostfix​(String uri,
                                                 String servicePath)

      Generate the REST_URL_POSTFIX from the request URI.
      Parameters:
        `uri` - the Request URI as a string
        `servicePath` - service path
      Returns:
        REST_URL_POSTFIX as a string

    - #### isRESTSupportedMediaType

          public static boolean isRESTSupportedMediaType​(String contentType)

      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 context
        `contentType` - 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 context
        `contentType` - content-type of the request
        `soapVersion` - SOAP version
        `soapActionHeader` - 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

          public static String getProtocolVersion​(SourceConfiguration sourceConfiguration)

    - #### 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

          public static String getValueOfElementWithLocalName​(org.apache.axiom.om.OMElement element,
                                                              String localName)

    - #### getListenerInterface

          public static String getListenerInterface​(String host,
                                                    int port)

    - #### handleException

          public static void handleException​(String s,
                                             Exception e)
                                      throws org.apache.axis2.AxisFault

      Throws:
        `org.apache.axis2.AxisFault`

    - #### handleException

          public static void handleException​(String msg)
                                      throws org.apache.axis2.AxisFault

      Throws:
        `org.apache.axis2.AxisFault`