chinmaya samantara created FINERACT-2931:
--------------------------------------------

             Summary:  Creating a Web hook fails with HTTP 500 unless the 
Payload URL ends with "/"
                 Key: FINERACT-2931
                 URL: https://issues.apache.org/jira/browse/FINERACT-2931
             Project: Apache Fineract
          Issue Type: Bug
            Reporter: chinmaya samantara
            Assignee: chinmaya samantara


Creating a hook with the *Web* template fails with HTTP 500 when the Payload 
URL doesn't end with a slash, which is the usual form of a webhook URL (e.g. 
https://example.com/hook).

*Steps to reproduce*
{code:json}
POST /fineract-provider/api/v1/hooks
{
  "name": "Web",
  "isActive": true,
  "displayName": "my hook",
  "events": [ { "actionName": "CREATE", "entityName": "CLIENT" } ],
  "config": { "Payload URL": "https://example.com/hook";, "Content Type": "json" 
}
}
{code}

*Actual result:* HTTP 500. The log shows:
{noformat}
java.lang.IllegalArgumentException: baseUrl must end in /: 
https://example.com/hook
  at 
org.apache.fineract.infrastructure.hooks.processor.ProcessorHelper.createWebHookService(ProcessorHelper.java:118)
  at 
org.apache.fineract.infrastructure.hooks.service.HookWritePlatformServiceImpl.validateHookRules(HookWritePlatformServiceImpl.java:242)
{noformat}
The same request with "https://example.com/hook/"; returns 200. A malformed URL 
(e.g. "abc") also gives HTTP 500 instead of a validation error.

*Expected result:* the hook is created and the events are sent to 
https://example.com/hook. A malformed URL is rejected with a 400 validation 
error (url.invalid).

*Cause*
WebHookService uses @POST(".") / @GET("."), so 
ProcessorHelper.createWebHookService(url) passes the Payload URL to Retrofit as 
the *base* URL, and Retrofit requires a base URL that ends with "/". 
validateHookRules() only catches IOException, so the IllegalArgumentException 
becomes a 500.

*Proposed fix*
Pass the hook URL to each request with Retrofit's @Url parameter and use only 
the scheme, host and port as the base URL. URLs that already end with "/" are 
sent to exactly the same address as before. Also treat IllegalArgumentException 
from the URL as url.invalid in validateHookRules(). This affects the Web, 
Elastic Search and SMS Bridge hook processors, which share WebHookService.

Checked on develop 6bb3c0c293 and 7ac780192.




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to