Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read an XML file in Mule Anypoint Studio after invoking an HTTP endpoint?

I am new to Anypoint Studio and I am trying to create a flow that will have an HTTP connector and an endpoint and when a user invokes the http endpoint then the application will load the contents of an XML file, will convert then to JSON and will return the JSON back in the HTTP Response.

My flow configuration looks like this

<flow name="test-flow">
        <http:listener config-ref="HttpListenerConfiguration" path="/read" allowedMethods="POST" doc:name="HTTP">
            <http:response-builder statusCode="200">
                <http:header headerName="Content-Type" value="application/json"/>
            </http:response-builder>
        </http:listener>
        <file:inbound-endpoint path="xml/test.xml" responseTimeout="10000" doc:name="File"/>
        <mulexml:xml-to-object-transformer returnClass="org.mule.examples.Catalog" doc:name="XML to Object"/>
        <json:object-to-json-transformer sourceClass="org.mule.examples.Catalog" doc:name="Object to JSON"/>
    </flow>

Of course it doesn't work. I get a

SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'file:inbound-endpoint'. One of '{"http://www.mulesoft.org/schema/mule/core":abstract-message-processor, "http://www.mulesoft.org/schema/mule/core":abstract-outbound-endpoint, "http://www.mulesoft.org/schema/mule/core":abstract-mixed-content-message-processor, "http://www.mulesoft.org/schema/mule/core":response}' is expected.

which I assume is coming from the fact that <file:inbound-endpoint...> needs to be as a source in the flow.

Any suggestions on how can I read a file after an HTTP endpoint is invoked?

Thanks

like image 208
NikosDim Avatar asked Dec 11 '25 01:12

NikosDim


1 Answers

As you correctly assumed, file:inbound-endpoint can only act as a message source. Thus to achieve what you want you can use the mule module requester. HTH.

like image 166
clare Avatar answered Dec 15 '25 13:12

clare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!