<commit_before><!--
 ~ Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 ~
 ~ WSO2 Inc. licenses this file to you under the Apache License,
 ~ Version 2.0 (the "License"); you may not use this file except
 ~ in compliance with the License.
 ~ You may obtain a copy of the License at
 ~
 ~    http://www.apache.org/licenses/LICENSE-2.0
 ~
 ~ Unless required by applicable law or agreed to in writing,
 ~ software distributed under the License is distributed on an
 ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 ~ KIND, either express or implied.  See the License for the
 ~ specific language governing permissions and limitations
 ~ under the License.
 -->
<api xmlns="http://ws.apache.org/ns/synapse" name="$!apiName" context="$!apiContext" version="$!apiVersion" version-type="context" binds-to="WebhookServer, SecureWebhookServer, default">
    <resource methods="POST" url-mapping="/webhooks_events_receiver_resource" binds-to="WebhookServer, SecureWebhookServer">
        <inSequence>
            #if($isSecurityEnabled)
            <property name="generated_signature" expression="fn:concat('$signingAlgorithm', hmac-generate($ctx:ORIGINAL_PAYLOAD, '$secret', '$hmacSignatureGenerationAlgorithm'))"/>
            <property name="received_signature" expression="$trp:$signatureHeader"/>
            <filter xpath="get-property('received_signature') = get-property('generated_signature')">
                <then>
            #end
                    <clone>
                        <target>
                            <sequence>
                                <property name="NO_ENTITY_BODY" value="true" scope="axis2" type="BOOLEAN" />
                                <respond/>
                            </sequence>
                        </target>
                        <target>
                            <sequence>
                                <class name="org.wso2.carbon.apimgt.gateway.mediators.webhooks.SubscribersLoader"/>
                                <clone iterations="{get-property('SUBSCRIBERS_COUNT')}" continueParent="true">
                                    <target>
                                        <sequence onError="webhooksFaultSequence">
                                            <class name="org.wso2.carbon.apimgt.gateway.mediators.webhooks.SubscriberInfoLoader"/>
                                            <property name="TRANSPORT_HEADERS" action="remove" scope="axis2"/>
                                            <property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
                                            <header name="To" expression="$ctx:SUBSCRIBER_CALLBACK"/>
                                            <filter source="boolean($ctx:SUBSCRIBER_SECRET)" regex="true">
                                                <then>
                                                    <property name="X-Hub-Signature"
                                                              expression="fn:concat('sha1=', hmac-generate($ctx:ORIGINAL_PAYLOAD, $ctx:SUBSCRIBER_SECRET))"
                                                              scope="transport"/>
                                                </then>
                                                <else/>
                                            </filter>
                                            <call blocking="true">
                                                <endpoint>
                                                    <default>
                                                        <timeout>
                                                            <duration>60000</duration>
                                                        </timeout>
                                                        <markForSuspension>
                                                            <errorCodes>101504, 101505, 101500</errorCodes>
                                                            <retriesBeforeSuspension>3</retriesBeforeSuspension>
                                                            <retryDelay>1</retryDelay>
                                                        </markForSuspension>
                                                        <suspendOnFailure>
                                                            <initialDuration>1000</initialDuration>
                                                            <progressionFactor>2</progressionFactor>
                                                            <maximumDuration>64000</maximumDuration>
                                                        </suspendOnFailure>
                                                    </default>
                                                </endpoint>
                                            </call>
                                            <class name="org.wso2.carbon.apimgt.gateway.mediators.webhooks.DeliveryStatusUpdater"/>
                                        </sequence>
                                    </target>
                                </clone>
                            </sequence>
                        </target>
                    </clone>
            #if($isSecurityEnabled)
                </then>
                <else>
                    <log level="custom">
                        <property name="ERROR" value="The signature validation failed"/>
                    </log>
                    <drop/>
                </else>
            </filter>
            #end
        </inSequence>
    </resource>
    <resource methods="POST" url-mapping="/*" binds-to="default">
        <inSequence>
            <property name="STOP_TARGET_EXECUTION_ON_FAILURE" value="true"/>
            <clone sequential="true">
                <target>
                    <sequence>
                        <class name="org.wso2.carbon.apimgt.gateway.mediators.webhooks.SubscribersPersistMediator"/>
                        <property name="NO_ENTITY_BODY" value="true" scope="axis2" type="BOOLEAN" />
                        <respond/>
                    </sequence>
                </target>
                <target>
                    <sequence onError="webhooksFaultSequence">
                        <filter source="$url:hub.mode" regex="subscribe">
                            <then>
                                <property name="SUBSCRIBER_CALLBACK" expression="$url:hub.callback"/>
                                <property name="SUBSCRIBER_TOPIC" expression="$url:hub.topic"/>
                                <property name="SUBSCRIBER_APPLICATION_ID" expression="$ctx:api.ut.application.id"/>
                                <header name="To" expression="$ctx:SUBSCRIBER_CALLBACK"/>
                                <call>
                                    <endpoint>
                                        <default/>
                                    </endpoint>
                                </call><commit_msg>Change xpath<commit_after><!--
 ~ Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 ~
 ~ WSO2 Inc. licenses this file to you under the Apache License,
 ~ Version 2.0 (the "License"); you may not use this file except
 ~ in compliance with the License.
 ~ You may obtain a copy of the License at
 ~
 ~    http://www.apache.org/licenses/LICENSE-2.0
 ~
 ~ Unless required by applicable law or agreed to in writing,
 ~ software distributed under the License is distributed on an
 ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 ~ KIND, either express or implied.  See the License for the
 ~ specific language governing permissions and limitations
 ~ under the License.
 -->
<api xmlns="http://ws.apache.org/ns/synapse" name="$!apiName" context="$!apiContext" version="$!apiVersion" version-type="context" binds-to="WebhookServer, SecureWebhookServer, default">
    <resource methods="POST" url-mapping="/webhooks_events_receiver_resource" binds-to="WebhookServer, SecureWebhookServer">
        <inSequence>
            #if($isSecurityEnabled)
            <property name="generated_signature" expression="fn:concat('$signingAlgorithm', hmac-generate($ctx:ORIGINAL_PAYLOAD, '$secret', '$hmacSignatureGenerationAlgorithm'))"/>
            <property name="received_signature" expression="$trp:$signatureHeader"/>
            <filter xpath="get-property('received_signature') = get-property('generated_signature')">
                <then>
            #end
                    <clone>
                        <target>
                            <sequence>
                                <property name="NO_ENTITY_BODY" value="true" scope="axis2" type="BOOLEAN" />
                                <respond/>
                            </sequence>
                        </target>
                        <target>
                            <sequence>
                                <class name="org.wso2.carbon.apimgt.gateway.mediators.webhooks.SubscribersLoader"/>
                                <clone iterations="{get-property('SUBSCRIBERS_COUNT')}" continueParent="true">
                                    <target>
                                        <sequence onError="webhooksFaultSequence">
                                            <class name="org.wso2.carbon.apimgt.gateway.mediators.webhooks.SubscriberInfoLoader"/>
                                            <property name="TRANSPORT_HEADERS" action="remove" scope="axis2"/>
                                            <property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
                                            <header name="To" expression="$ctx:SUBSCRIBER_CALLBACK"/>
                                            <filter source="boolean($ctx:SUBSCRIBER_SECRET)" regex="true">
                                                <then>
                                                    <property name="X-Hub-Signature"
                                                              expression="fn:concat('sha1=', hmac-generate($ctx:ORIGINAL_PAYLOAD, $ctx:SUBSCRIBER_SECRET))"
                                                              scope="transport"/>
                                                </then>
                                                <else/>
                                            </filter>
                                            <call blocking="true">
                                                <endpoint>
                                                    <default>
                                                        <timeout>
                                                            <duration>60000</duration>
                                                        </timeout>
                                                        <markForSuspension>
                                                            <errorCodes>101504, 101505, 101500</errorCodes>
                                                            <retriesBeforeSuspension>3</retriesBeforeSuspension>
                                                            <retryDelay>1</retryDelay>
                                                        </markForSuspension>
                                                        <suspendOnFailure>
                                                            <initialDuration>1000</initialDuration>
                                                            <progressionFactor>2</progressionFactor>
                                                            <maximumDuration>64000</maximumDuration>
                                                        </suspendOnFailure>
                                                    </default>
                                                </endpoint>
                                            </call>
                                            <class name="org.wso2.carbon.apimgt.gateway.mediators.webhooks.DeliveryStatusUpdater"/>
                                        </sequence>
                                    </target>
                                </clone>
                            </sequence>
                        </target>
                    </clone>
            #if($isSecurityEnabled)
                </then>
                <else>
                    <log level="custom">
                        <property name="ERROR" value="The signature validation failed"/>
                    </log>
                    <drop/>
                </else>
            </filter>
            #end
        </inSequence>
    </resource>
    <resource methods="POST" url-mapping="/*" binds-to="default">
        <inSequence>
            <property name="STOP_TARGET_EXECUTION_ON_FAILURE" value="true"/>
            <clone sequential="true">
                <target>
                    <sequence>
                        <class name="org.wso2.carbon.apimgt.gateway.mediators.webhooks.SubscribersPersistMediator"/>
                        <property name="NO_ENTITY_BODY" value="true" scope="axis2" type="BOOLEAN" />
                        <respond/>
                    </sequence>
                </target>
                <target>
                    <sequence onError="webhooksFaultSequence">
                        <filter source="fn:lower-case($url:hub.mode)" regex="subscribe">
                            <then>
                                <property name="SUBSCRIBER_CALLBACK" expression="$url:hub.callback"/>
                                <property name="SUBSCRIBER_TOPIC" expression="$url:hub.topic"/>
                                <property name="SUBSCRIBER_APPLICATION_ID" expression="$ctx:api.ut.application.id"/>
                                <header name="To" expression="$ctx:SUBSCRIBER_CALLBACK"/>
                                <call>
                                    <endpoint>
                                        <default/>
                                    </endpoint>
                                </call>
{'fraction_non_alphanumeric': 0.09282337773957886, 'fraction_numerical': 0.007878527431600058, 'mean_word_length': 0.9887480415895171, 'pattern_counts': {'":': 0, '<': 199, '<?xml version=': 0, '>': 199, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 142, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3523497', 'n_tokens_mistral': 2868, 'n_tokens_neox': 2713, 'n_words': 530}