mulemule4

Mule 4 SAX parse exception during custom policy deployment


After uploading the implementation for my custom policy, I am seeing two errors in logs when it attempts to deploy, here is the first error:

ERROR 2024-06-17 18:53:05,449 [agw-policy-set-deployment.01] [processor: ; event: ] com.mulesoft.mule.runtime.gw.policies.deployment.DefaultPolicyDeployer: Error deploying policy resource-common-secure-replyto-policy-impl-5402681 to application policy-cdnmvr-process
org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException: Error occured registering policy 'resource-common-secure-replyto-policy-impl-5402681 @ policy-cdnmvr-process-api-main'
    at org.mule.runtime.module.deployment.impl.internal.application.MuleApplicationPolicyProvider.addPolicy(MuleApplicationPolicyProvider.java:113) ~[mule-module-deployment-model-impl-4.4.0-20240520.jar:4.4.0-20240520]
    at com.mulesoft.mule.runtime.gw.model.ApiImplementation.addPolicy(ApiImplementation.java:87) ~[api-gateway-core-4.4.0-20240520.jar:4.4.0-20240520]
    at com.mulesoft.mule.runtime.gw.policies.deployment.DefaultPolicyDeployer.internalDeploy(DefaultPolicyDeployer.java:81) ~[mule-module-policies-4.4.0-20240520.jar:4.4.0-20240520]
    at com.mulesoft.mule.runtime.gw.policies.deployment.DefaultPolicyDeployer.deploy(DefaultPolicyDeployer.java:52) ~[mule-module-policies-4.4.0-20240520.jar:4.4.0-20240520]
    at com.mulesoft.mule.runtime.gw.policies.service.DefaultTransactionalPolicyDeploymentService.deploy(DefaultTransactionalPolicyDeploymentService.java:50) ~[mule-module-policies-4.4.0-20240520.jar:4.4.0-20240520]
    at com.mulesoft.mule.runtime.gw.policies.service.DefaultMultiplexingPolicyDeploymentService.lambda$newPolicy$0(DefaultMultiplexingPolicyDeploymentService.java:30) ~[mule-module-policies-4.4.0-20240520.jar:4.4.0-20240520]
    at java.util.Optional.ifPresent(Optional.java:159) ~[?:1.8.0_412]
    at com.mulesoft.mule.runtime.gw.policies.service.DefaultMultiplexingPolicyDeploymentService.lambda$forAllApis$5(DefaultMultiplexingPolicyDeploymentService.java:61) ~[mule-module-policies-4.4.0-20240520.jar:4.4.0-20240520]
    at java.util.Collections$SingletonList.forEach(Collections.java:4824) ~[?:1.8.0_412]
    at com.mulesoft.mule.runtime.gw.policies.service.DefaultMultiplexingPolicyDeploymentService.forAllApis(DefaultMultiplexingPolicyDeploymentService.java:60) ~[mule-module-policies-4.4.0-20240520.jar:4.4.0-20240520]
    at com.mulesoft.mule.runtime.gw.policies.service.DefaultMultiplexingPolicyDeploymentService.newPolicy(DefaultMultiplexingPolicyDeploymentService.java:30) ~[mule-module-policies-4.4.0-20240520.jar:4.4.0-20240520]
    at com.mulesoft.mule.runtime.gw.policies.service.detection.PolicyChangeProcessor.visit(PolicyChangeProcessor.java:49) ~[mule-module-policies-4.4.0-20240520.jar:4.4.0-20240520]
    at com.mulesoft.mule.runtime.gw.policies.service.detection.change.PolicyAdded.accept(PolicyAdded.java:21) ~[mule-module-policies-4.4.0-20240520.jar:4.4.0-20240520]
    at com.mulesoft.mule.runtime.gw.policies.service.detection.PolicyChangeProcessor.lambda$process$0(PolicyChangeProcessor.java:44) ~[mule-module-policies-4.4.0-20240520.jar:4.4.0-20240520]
    at java.lang.Iterable.forEach(Iterable.java:75) ~[?:1.8.0_412]
    at com.mulesoft.mule.runtime.gw.policies.service.detection.PolicyChangeProcessor.process(PolicyChangeProcessor.java:44) ~[mule-module-policies-4.4.0-20240520.jar:4.4.0-20240520]
    at com.mulesoft.mule.runtime.gw.policies.service.DefaultPolicySetDeploymentService.lambda$policiesForApi$0(DefaultPolicySetDeploymentService.java:78) ~[mule-module-policies-4.4.0-20240520.jar:4.4.0-20240520]
    at com.mulesoft.anypoint.retry.runnable.RetrierRunnable.execute(RetrierRunnable.java:40) [api-gateway-backoff-1.0.0.jar:1.0.0]
    at com.mulesoft.anypoint.backoff.scheduler.runnable.BackoffRunnable.run(BackoffRunnable.java:36) [api-gateway-backoff-1.0.0.jar:1.0.0]
    at com.mulesoft.anypoint.backoff.scheduler.runnable.FastRecovery.run(FastRecovery.java:32) [api-gateway-backoff-1.0.0.jar:1.0.0]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_412]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_412]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_412]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.8.0_412]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_412]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_412]
    at java.lang.Thread.run(Thread.java:750) [?:1.8.0_412]
Caused by: org.mule.runtime.api.lifecycle.InitialisationException: Cannot create artifact context for the policy instance
    at org.mule.runtime.module.deployment.impl.internal.policy.DefaultApplicationPolicyInstance.initPolicyContext(DefaultApplicationPolicyInstance.java:135) ~[mule-module-deployment-model-impl-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.module.deployment.impl.internal.policy.DefaultApplicationPolicyInstance.initialise(DefaultApplicationPolicyInstance.java:238) ~[mule-module-deployment-model-impl-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.module.deployment.impl.internal.application.MuleApplicationPolicyProvider.addPolicy(MuleApplicationPolicyProvider.java:105) ~[mule-module-deployment-model-impl-4.4.0-20240520.jar:4.4.0-20240520]
    ... 26 more
Caused by: org.mule.runtime.core.api.config.ConfigurationException: There was '1' error while parsing the given file '/mule/pcbc-cdn-v4-dev-aws1dmule002-440/policies/resource-common-secure-replyto-policy-impl-5402681/policy.xml'.
Full list:
org.xml.sax.SAXParseException; lineNumber: 16; columnNumber: 42; cvc-complex-type.2.4.a: Invalid content was found starting with element '{"http://www.mulesoft.org/schema/mule/core":sub-flow}'. One of '{"http://www.mulesoft.org/schema/mule/core":abstract-message-processor, "http://www.mulesoft.org/schema/mule/core":abstract-mixed-content-message-processor}' is expected.
    at org.mule.runtime.core.api.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:56) ~[mule-core-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.core.api.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:84) ~[mule-core-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.config.api.dsl.artifact.SpringArtifactConfigurationProcessor.createArtifactContext(SpringArtifactConfigurationProcessor.java:52) ~[mule-module-spring-config-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.module.deployment.impl.internal.artifact.ArtifactContextBuilder$1.configure(ArtifactContextBuilder.java:453) ~[mule-module-deployment-model-impl-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.core.api.context.DefaultMuleContextFactory.lambda$createMuleContext$0(DefaultMuleContextFactory.java:63) ~[mule-core-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.core.api.context.DefaultMuleContextFactory.doCreateMuleContext(DefaultMuleContextFactory.java:175) ~[mule-core-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.core.api.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:60) ~[mule-core-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.module.deployment.impl.internal.artifact.ArtifactContextBuilder.lambda$build$1(ArtifactContextBuilder.java:485) ~[mule-module-deployment-model-impl-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.core.api.util.ExceptionUtils.tryExpecting(ExceptionUtils.java:224) ~[mule-core-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader(ClassUtils.java:1075) ~[mule-core-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader(ClassUtils.java:993) ~[mule-core-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.module.deployment.impl.internal.artifact.ArtifactContextBuilder.build(ArtifactContextBuilder.java:397) ~[mule-module-deployment-model-impl-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.module.deployment.impl.internal.policy.DefaultApplicationPolicyInstance.initPolicyContext(DefaultApplicationPolicyInstance.java:131) ~[mule-module-deployment-model-impl-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.module.deployment.impl.internal.policy.DefaultApplicationPolicyInstance.initialise(DefaultApplicationPolicyInstance.java:238) ~[mule-module-deployment-model-impl-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.module.deployment.impl.internal.application.MuleApplicationPolicyProvider.addPolicy(MuleApplicationPolicyProvider.java:105) ~[mule-module-deployment-model-impl-4.4.0-20240520.jar:4.4.0-20240520]
    ... 26 more
Caused by: org.mule.runtime.api.exception.MuleRuntimeException: There was '1' error while parsing the given file '/mule/pcbc-cdn-v4-dev-aws1dmule002-440/policies/resource-common-secure-replyto-policy-impl-5402681/policy.xml'.
Full list:
org.xml.sax.SAXParseException; lineNumber: 16; columnNumber: 42; cvc-complex-type.2.4.a: Invalid content was found starting with element '{"http://www.mulesoft.org/schema/mule/core":sub-flow}'. One of '{"http://www.mulesoft.org/schema/mule/core":abstract-message-processor, "http://www.mulesoft.org/schema/mule/core":abstract-mixed-content-message-processor}' is expected.
    at org.mule.runtime.dsl.api.xml.parser.XmlConfigurationDocumentLoader.throwExceptionIfErrorsWereFound(XmlConfigurationDocumentLoader.java:185) ~[mule-module-dsl-api-1.4.0-20240520.jar:?]
    at org.mule.runtime.dsl.api.xml.parser.XmlConfigurationDocumentLoader.loadDocument(XmlConfigurationDocumentLoader.java:163) ~[mule-module-dsl-api-1.4.0-20240520.jar:?]
    at org.mule.runtime.ast.internal.xml.DefaultAstXmlParser.doParse(DefaultAstXmlParser.java:321) ~[mule-artifact-ast-xml-parser-1.0.0-20240520.jar:?]
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[?:1.8.0_412]
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1384) ~[?:1.8.0_412]
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) ~[?:1.8.0_412]
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) ~[?:1.8.0_412]
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[?:1.8.0_412]
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:1.8.0_412]
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566) ~[?:1.8.0_412]
    at org.mule.runtime.ast.internal.xml.DefaultAstXmlParser.parse(DefaultAstXmlParser.java:142) ~[mule-artifact-ast-xml-parser-1.0.0-20240520.jar:?]
    at org.mule.runtime.config.internal.SpringXmlConfigurationBuilder.createApplicationModel(SpringXmlConfigurationBuilder.java:253) ~[mule-module-spring-config-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.config.internal.SpringXmlConfigurationBuilder.doCreateApplicationContext(SpringXmlConfigurationBuilder.java:208) ~[mule-module-spring-config-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.config.internal.SpringXmlConfigurationBuilder.createApplicationContext(SpringXmlConfigurationBuilder.java:195) ~[mule-module-spring-config-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.config.internal.SpringXmlConfigurationBuilder.doConfigure(SpringXmlConfigurationBuilder.java:170) ~[mule-module-spring-config-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.core.api.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:53) ~[mule-core-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.core.api.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:84) ~[mule-core-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.config.api.dsl.artifact.SpringArtifactConfigurationProcessor.createArtifactContext(SpringArtifactConfigurationProcessor.java:52) ~[mule-module-spring-config-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.module.deployment.impl.internal.artifact.ArtifactContextBuilder$1.configure(ArtifactContextBuilder.java:453) ~[mule-module-deployment-model-impl-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.core.api.context.DefaultMuleContextFactory.lambda$createMuleContext$0(DefaultMuleContextFactory.java:63) ~[mule-core-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.core.api.context.DefaultMuleContextFactory.doCreateMuleContext(DefaultMuleContextFactory.java:175) ~[mule-core-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.core.api.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:60) ~[mule-core-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.module.deployment.impl.internal.artifact.ArtifactContextBuilder.lambda$build$1(ArtifactContextBuilder.java:485) ~[mule-module-deployment-model-impl-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.core.api.util.ExceptionUtils.tryExpecting(ExceptionUtils.java:224) ~[mule-core-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader(ClassUtils.java:1075) ~[mule-core-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader(ClassUtils.java:993) ~[mule-core-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.module.deployment.impl.internal.artifact.ArtifactContextBuilder.build(ArtifactContextBuilder.java:397) ~[mule-module-deployment-model-impl-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.module.deployment.impl.internal.policy.DefaultApplicationPolicyInstance.initPolicyContext(DefaultApplicationPolicyInstance.java:131) ~[mule-module-deployment-model-impl-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.module.deployment.impl.internal.policy.DefaultApplicationPolicyInstance.initialise(DefaultApplicationPolicyInstance.java:238) ~[mule-module-deployment-model-impl-4.4.0-20240520.jar:4.4.0-20240520]
    at org.mule.runtime.module.deployment.impl.internal.application.MuleApplicationPolicyProvider.addPolicy(MuleApplicationPolicyProvider.java:105) ~[mule-module-deployment-model-impl-4.4.0-20240520.jar:4.4.0-20240520]
    ... 26 more

Judging by other instances of this same error (SAX parse exception) I'm seeing online I'm thinking there's something in my template.xml code that may be causing this issue, however I am struggling to narrow it down. Here is the template code, this is my first attempt at implementing a custom policy, so let me know if anything stands out:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:http-policy="http://www.mulesoft.org/schema/mule/http-policy"
      xmlns:http-transform="http://www.mulesoft.org/schema/mule/http-policy-transform"
      xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
               http://www.mulesoft.org/schema/mule/http-policy http://www.mulesoft.org/schema/mule/http-policy/current/mule-http-policy.xsd
               http://www.mulesoft.org/schema/mule/http-policy-transform http://www.mulesoft.org/schema/mule/http-policy-transform/current/mule-http-policy-transform.xsd">


    <http-policy:proxy name="{{{policyId}}}">
        <http-policy:source>

            <http-policy:execute-next/>

            <sub-flow name="policy-main">
                <choice>
                    <when expression="#[attributes.headers['wmic_common_replyTo'] != null and (attributes.headers['wmic_common_replyTo'] contains 'wmic.ins' or attributes.headers['wmic_common_replyTo'] contains 'guidewire.net')]">
                        <logger message="Header 'wmic_common_replyTo' is valid: #[attributes.headers['wmic_common_replyTo']]" level="INFO"/>
                    </when>
                    <when expression="#[attributes.headers['wmic_common_replyTo'] == null]">
                        <logger message="Header 'wmic_common_replyTo' is not present, proceeding without validation" level="INFO"/>
                    </when>
                    <otherwise>
                        <set-variable variableName="policyErrorMessage" value="Invalid 'wmic_common_replyTo' header. Must contain 'wmic.ins' or 'guidewire.net'."/>
                        <raise-error type="POLICY:VALIDATION_ERROR" description="#[vars.policyErrorMessage]"/>
                    </otherwise>
                </choice>
            </sub-flow>

        </http-policy:source>
    </http-policy:proxy>
</mule>

Solution

  • The error is telling that the <sub-flow> element is invalid:

    Invalid content was found starting with element '{"http://www.mulesoft.org/schema/mule/core":sub-flow}'
    

    It that makes no sense to have it in the body of the policy. Remove it and its matching /<sub-flow> and leave just the <choice> router instead.

    Example:

    <http-policy:proxy name="{{{policyId}}}">
        <http-policy:source>
    
            <http-policy:execute-next/>
    
            <choice>
            ...
            </choice>
    
        </http-policy:source>
    </http-policy:proxy>