wso2 / product-microgateway

Choreo Connect is a cloud-native, open-source, and developer-centric API gateway.
https://wso2.com/choreo/choreo-connect/
Apache License 2.0
293 stars 252 forks source link

MicroGateway ballerina filter getXmlPayload() removes the starting CRLF character from the first multipart boundary #3403

Closed sajith-madhusanka closed 1 year ago

sajith-madhusanka commented 1 year ago

Description

The CRLF characters at the beginning of the body are being removed when building the payload via the ballerina filter.

Steps to Reproduce

xmlns "http://****" as gdc14;

string CONFIG_SOAP_GDCXML_CONTEXT = "usr_soap_gdcxml_context"; string CONFIG_ENVIRONMENT = "usr_environment"; string CONFIG_ENVIRONMENT_ID = "usr_environment_id";

string REQUEST_CONTENT_TYPE = "requestContentType"; string GDC_REQUEST_MESSAGE_ID = "gdcRequestMessageId"; string GDC_REQUEST_HEADER = "gdcRequestHeader";

string ERROR_RESPONSE_CODE = "error_response_code";

// Filter for the Soap GDC XML API // public type SoapGdcFilter object {

public function filterRequest(http:Caller caller, http:Request request, http:FilterContext context) returns boolean {

    if (context.attributes.hasKey(gateway:SKIP_ALL_FILTERS) && <boolean>context.attributes[gateway:SKIP_ALL_FILTERS]) {
        return true;
    }   

    xml|error payload = request.getXmlPayload();

    return true;
}

public function filterResponse(http:Response response, http:FilterContext context) returns boolean {
    return true;
}

}; // SoapGdcFilter


- Add the below configuration to the deployment-config.toml residing under the /conf directory:

[[filters]] name = "SoapGdcFilter" position = 1



- Configure SOAP UI to send a post request with MTOM enabled.

- Invoke the API using the SOAP UI and you will be able to observe that the **CRLF** ("/r/n" ) character is being missed in the first multipart boundary when sending the request to the backend server. Check the backend server's log.
`"body": "------=_Part_32_1103335936.1688648631996\r\nContent-Transfer-Encoding: 8bit\r\ncontent-type:
`- It should include the CRLF character as below,
`"body": "\r\n------=_Part_32_1103335936.1688648631996\r\nContent-Transfer-Encoding: 8bit\r\ncontent-type:
`

### Affected Component

APIM

### Version

wso2am-micro-gw-3.2.0

### Environment Details (with versions)

_No response_

### Relevant Log Output

_No response_

### Related Issues

_No response_

### Suggested Labels

_No response_
npamudika commented 1 year ago

Fixed with https://github.com/wso2/product-microgateway/pull/3402