Loading

Encoding Special Characters in URI Params Request path contains special characters not encoded

Veröffentlichungsdatum: Aug 1, 2025
Aufgabe

GOAL

The APIkit Router element allows you to define an API. It helps developers generate whole code from the API specification (RAML file) itself. But apart from generating flows from the API specification, it also helps in routing the incoming requests to specific flows of the API. 

If you are using APIkit Router in application to generate flows and while calling an API endpoint if you see the mentioned error in logs. The error log suggests that, URL is a malformed URL (half encoded) and API kit can neither resolve nor accept it.
 
********************************************************************************
Message : Request path contains special characters not encoded
Element : encode-api-test-main/processors/0 @ encode-uri-test:encode-api-test.xml:17
Element DSL : <apikit:router config-ref="encode-api-test-config"></apikit:router>
Error type : APIKIT:BAD_REQUEST
FlowStack : at encode-api-test-main(encode-api-test-main/processors/0 @ encode-uri-test:encode-api-test.xml:17)

(set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************


Examples:

Here are few samples of malformed URL which will not be accepted by APIkit router.

1. http://localhost:8081/api/employee details
2. http://localhost:8081/api/employee (ID)
3. http://localhost:8081/api/employee & department
4. http://localhost:8081/api/employee (hello)

The above URL contains an URI params as ( /employee details , /employee (ID) , /employee & department ). All given URL's are malformed URL and partially encoded (Half-encoded). It has been found that half encoded URL are not accepted by APIkit and will throw highlighted error in mule_ee logs.

As API KIT module is not accepting half-encoded content, or you encode it all or none, but half-encoding is incorrect neither accepted by the module (Not supported).

Accepted & Not Accepted URL's :

The URL can not contain spaces and need to be encoded - Allowed
Half encoded including space - Not allowed
Completely encoded - Allowed
Unencoded URL- Allowed
Schritte
Let's take an example of RAML below, it has space (/employee:details) and APIkit will throw an error "NOT_IMPLEMENTED" in this case.
#%RAML 1.0
title: URI-encode-app

/employee:details:
  get:
    responses:
      200:
        body:
          application/json:
            example: 
                {
                      "message":"Employee Details retrieved Successfully"
                }
To execute it successfully, we need to make some changes in "configuration XML". Browse to flow generated by APIkit and enter the encoded value from [/employee details] to [/employee%3Adetails] and flow will run without any errors.

Note: Here we do not have to make changes manually. APIkit encodes the URL while generating the flows and adds %3A instead of colon (:)

After making a call (http://localhost:8081/api/employee:details) it will return 200 OK response.

Configuration XML will look like this:
<flow name="get:\employee%3Adetails:uri-encode-app-config">
        <ee:transform>
            <ee:message>
                <ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
  message: "Employee Details reterived Successfully"
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>

SOLUTION

1. Add the custom logic in your application to handle unescaped characters which can be resolved. You can make a use of Groovy script to handle special characters.
Attached a sample application which makes use of Groovy script to handle special characters in URL and return success.
2. You can make use of online tools for encoding URL's. URL can also be encoded using Java method URLEncoder.encode()
3. It is recommended to use latest version of Mulesoft connectors [ APIkit, HTTP, Sockets, Scripting, Database] Latest version contains some improvements. 
Nummer des Knowledge-Artikels

001115363

 
Laden
Salesforce Help | Article