When I connect to:
http://legacy.cafebonappetit.com/api/2/menus?cafe=261
I get back JSON as I should. However, I'm unable to do this with the Mulesoft HTTP Connector. When I try, I get back 500. Here is my XML:
<flow name="GetDiningInfo">
<http:listener config-ref="HTTP_Listener_Configuration" path="/dining" doc:name="HTTP"/>
<http:request config-ref="HTTP_Request_Configuration" path="/api/2/menus" method="GET" doc:name="GET announcement from dining server" followRedirects="true" host="legacy.cafebonappetit.com" port="80">
<http:request-builder>
<http:query-param paramName="cafe" value="261"/>
</http:request-builder>
</http:request>
<logger level="INFO" doc:name="Logger"/>
</flow>
The connector global config is:
<http:request-config name="HTTPReqConfigforCafeBonAppetit.com" host="legacy.cafebonappetit.com" port="80" basePath="/api/2" doc:name="HTTP Request Configuration"/>
What am I doing wrong?
Thanks...
UPDATE: Still no joy. I'm still getting back a 500 internal server failure through Mule.
Here is the latest code that does not duplicate the path:
<http:request-config name="HTTPReqConfigforCafeBonAppetit" host="legacy.cafebonappetit.com" port="80" basePath="/api/2/" doc:name="HTTP Request Configuration" usePersistentConnections="false"/>
<flow name="GetDiningInfo">
<http:listener config-ref="HTTP_Listener_Configuration" path="/dining" doc:name="HTTP"/>
<http:request config-ref="HTTPReqConfigforCafeBonAppetit" path="menus" method="GET" doc:name="GET menu" followRedirects="true" parseResponse="false">
<http:request-builder>
<http:query-param paramName="cafe" value="261"/>
</http:request-builder>
</http:request>
<logger level="INFO" doc:name="Logger"/>
</flow>
Have you evaluated the URL request result? By referring that configuration it should be http://legacy.cafebonappetit.com/api/2/api/2/menus?cafe=261
That's why you unable to get the expected result. Therefore replace the path of http:request with /menus, without the base path /api/2. Because it's already defined in http:request-config
The server for legacy.cafebonappetit.com cannot handle the header Host including the port (which is valid). The HTTP connector sends Host: legacy.cafebonappetit.com:80 by default causing the server to reject the request, so you need to explicitly add the Host header, as in the example below.
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration" host="legacy.cafebonappetit.com" port="80" basePath="/api/2" doc:name="HTTP Request Configuration"/>
<flow name="so-testFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/dining" doc:name="HTTP"/>
<http:request config-ref="HTTP_Request_Configuration" path="menus" method="GET" doc:name="HTTP">
<http:request-builder>
<http:query-param paramName="cafe" value="261"/>
<http:header headerName="Host" value="legacy.cafebonappetit.com"/>
</http:request-builder>
<http:success-status-code-validator values="100..599"/>
</http:request>
</flow>
The example also includes a status code validator for all codes which allows you to see the exact error the server sends when the explicit Host header is removed.
Well the trouble here is when you send a request to the server by the 80 port. The server rejects the request immediately. To resolve this you got to add the header, so this way the server understand and process the request.
To do that just add the following line: $<http:header headerName="Host" value="the_host"/>.
The following XML got the solution:
<http:listener-config name="localhost" port="8085" doc:name="HTTP Listener Configuration" host="0.0.0.0"/>
<http:request-config name="HTTP_Request_Configuration" host="legacy.cafebonappetit.com" port="80" doc:name="HTTP Request Configuration" basePath="/api/2"/>
<flow name="GetDiningInfo">
<http:listener config-ref="localhost" path="/dining" doc:name="HTTP"/>
<http:request config-ref="HTTP_Request_Configuration" path="/menus" method="GET" doc:name="HTTP">
<http:request-builder>
<http:query-param paramName="cafe" value="261"/>
<http:header headerName="Host" value="legacy.cafebonappetit.com"/>
</http:request-builder>
<http:success-status-code-validator values="100..599"/>
</http:request>
<logger level="INFO" doc:name="Logger" message="#[payload]"/>
</flow>
The only way to resolve this issue is to make the server process the request.
Add this line in the xml,
<http:header headerName="Host" value="the_host"/>
You have to delete base path from global configuration of delete path in your xml because it generates url like : http://legacy.cafebonappetit.com/api/2/api/2/menus?cafe=261
here in url api/2/api/2 generated twice so thats why error occured
The server for legacy.cafebonappetit.com cannot handle the header Host including the port (which is valid).
The HTTP connector sends Host: legacy.cafebonappetit.com:80 by default causing the server to reject the request, so you need to explicitly add the Host header, as in the example below.
enter image description here
you can use the code like this
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0"
port="8081" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration"
host="legacy.cafebonappetit.com" port="80" basePath="/api/2" doc:name="HTTP
Request Configuration"/>
<flow name="so-testFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/dining"
doc:name="HTTP"/>
<http:request config-ref="HTTP_Request_Configuration" path="menus"
method="GET" doc:name="HTTP">
<http:request-builder>
<http:query-param paramName="cafe" value="261"/>
<http:header headerName="Host" value="legacy.cafebonappetit.com"/>
</http:request-builder>
<http:success-status-code-validator values="100..599"/>
</http:request>
</flow>
Use this below code for your issue...
<http:request config-ref="HTTP_Request_Configuration" path="/menus" method="GET" doc:name="HTTP">
<http:request-builder>
<http:query-param paramName="cafe" value="261"/>
<http:header headerName="Host" value="the_host"/>
</http:request-builder>
<http:success-status-code-validator values="100..599"/>
</http:request>
http:request-builder
try to add a header
The below code seems to work.
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8084" doc:name="HTTP Listener Configuration"/>
<http:endpoint exchange-pattern="request-response" method="POST" name="HTTP" address="http://legacy.cafebonappetit.com/api/2/menus?cafe=261" doc:name="HTTP"/>
<flow name="GetDiningInfo">
<http:listener config-ref="HTTP_Listener_Configuration" path="/dining" doc:name="HTTP"/>
<logger level="INFO" doc:name="Logger"/>
Related
I have this mule flow , where its polling the source folder to read the text file which I am adding as a attachment and sending through REST call , the same attachment I am trying to read in the different flow but inbound attachment is coming as null , please have a look into the code and help me on this.
<flow name="createAttachment" doc:description="Reading file and sending as attachment.">
<file:inbound-endpoint path="src/test/resources/in/attachment/" responseTimeout="10000" doc:name="File"/>
<file:file-to-byte-array-transformer doc:name="File to Byte Array"/>
<!-- <set-attachment attachmentName="#[originalFilename]" value="#[payload]" contentType="multipart/form-data" doc:name="Attachment"/> -->
<set-attachment attachmentName="#[originalFilename]" value="#[payload]" contentType="multipart/form-data" doc:name="Attachment" />
<http:request config-ref="HTTP_Request_Configuration" path="attachment/excel" method="POST" doc:name="HTTP"/>
</flow>
<flow name="readAttachment">
<http:listener config-ref="HTTP_Listener_Configuration" path="attachment/excel" allowedMethods="POST" parseRequest="false" />
<set-payload value="#[message.inboundAttachments['myattachment.txt']]" doc:name="Retrieve Attachments"/>
<set-payload value="#[payload.getInputStream() ]" doc:name="Get Inputstream from Payload"/>
<file:outbound-endpoint path="src/test/resources/out/attachment" responseTimeout="10000" doc:name="File" outputPattern="#[server.dateTime.toString()].pdf"/>
</flow>
I used the following:
<flow name="readAttachment">
<http:listener config-ref="HTTP_Listener_Configuration"
path="/" allowedMethods="POST" parseRequest="false" doc:name="HTTP" />
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<logger message="#[payload]" level="INFO" doc:name="Logger" /><file:outbound-endpoint path="src/test/resources" connector-ref="File" responseTimeout="10000" doc:name="File"/>
</flow>
When the attachment was received it was automatically parsed to be the payload, so it was just a case of turning the byte array to string.
I hope this helps
I'm sending a https request to a third party api and getting back a response of 403. How do I log to the console the request? I want to verify what I'm sending since it works when I curl it. Using Mule 3.7.0
<flow name="EmailFlow" >
<jms:inbound-endpoint queue="outbound.queue" doc:name="email outbound communicationQ" connector-ref="Active_MQ" >
</jms:inbound-endpoint>
<json:object-to-json-transformer doc:name="Object to JSON"/>
<logger message="msg is: #[payload]" level="INFO" doc:name="Logger"/>
<http:request config-ref="https_request_config" path="/api/v1/transmissions" method="POST" doc:name="HTTP">
<http:request-builder>
<http:header headerName="Authorization" value="somekey"/>
<http:header headerName="Content-Type" value="application/json"/>
</http:request-builder>
<http:success-status-code-validator values="403"/>
</http:request>
<logger level="INFO" doc:name="Logger"/>
</flow>
In 3.7 + You can add the following to your log4j2.xml which performs HTTP wire logging:
<AsyncLogger name="org.mule.module.http.internal.HttpMessageLogger" level="DEBUG" />
<AsyncLogger name="com.ning.http" level="DEBUG" />
I'm trying same host, port, mailid from java program , it send mail successfully.
below is my mule smtp flow
<smtp:connector name="smtpConnector" doc:name="SMTP"/>
<flow name="sendmail" >
<http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="8089" doc:name="HTTP" path="sendMail"/>
<smtp:outbound-endpoint host="15.456.128.61" port="587" user="test"
password="test123" to="xxxxx#xxx.com" from="xxxxx#xxx.com" subject="test mule"
responseTimeout="10000" connector-ref="smtpConnector" doc:name="Smtp"/>
<logger message="send mail suceesfully........ " level="INFO" doc:name="mailsend"/>
</flow>
http://localhost:8089/sendMail
using mule smtp i got below execption
Root Exception stack trace: javax.mail.AuthenticationFailedException:
535 5.7.3 Authentication unsuccessful
i tested smtp connector and it is working fine in mule flow , below is my code.
but here i used SMTPS
<http:listener-config name="HTTP_Listener_Configuration"
host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration" />
<flow name="yahooemailFlow">
<http:listener config-ref="HTTP_Listener_Configuration"
path="/" doc:name="HTTP" />
<set-payload value="#['Test Message ']" doc:name="Set Payload" />
<smtps:outbound-endpoint host="${smtp_host_ip}"
responseTimeout="10000" doc:name="SMTP" from="fromemail#yahoo.com"
mimeType="text/html" password="password" subject="subject"
to="toemail#yahoo.com" user="fromemail%40yahoo.com" />
<logger message="Mail Sent #[payload]" level="INFO" doc:name="Logger" />
</flow>
mule code
<flow name="getDetails">
<http:inbound-endpoint doc:description="This endpoint receives an HTTP message." doc:name="HTTP" exchange-pattern="request-response" host="localhost" port="8081" path="getDetails"/>
<json:xml-to-json-transformer doc:name="XML to JSON" mimeType="text/json" ignoreBadInput="true"/>
<logger message="xml to json output #[message.payload]" level="INFO" doc:name="Logger"/>
<logger message=" custom header username ... #[message.outboundProperties.get('http.headers.username')]" level="INFO" />
<logger message=" custom header username ... #[message.inboundProperties.get('http.headers.username')]" level="INFO" />
<http:outbound-endpoint exchange-pattern="request-response" address="http://localhost:8081/callReservation" method="POST" contentType="application/json" doc:name="HTTP"/>
</flow>
Here i give input as employee xml in the body
and in header i give username=user1 password=pwd1 in postman rest client
<?xml version="1.0" encoding="UTF-8"?>
<employee>
<name>abc</name>
<address>add1</address>
<phone>1212</phone>
</employee>
I got like error like below
com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '{' (code 123) in prolog; expected '<'
at [row,col {unknown-source}]: [1,1] (javax.xml.transform.TransformerException) (org.mule.api.transformer.TransformerException). Message payload is of type: String
using header and xmlto json conversion is mandatory for me.
can anyone help me out
Following code works fine for me. HTH.
<flow name="getDetails" doc:name="getDetails">
<http:inbound-endpoint doc:description="This endpoint receives an HTTP message."
doc:name="HTTP" exchange-pattern="request-response" host="localhost"
port="1000" path="getDetails" />
<json:xml-to-json-transformer doc:name="XML to JSON"
mimeType="text/json" ignoreBadInput="true" />
<logger message="xml to json output #[message.payload]" level="INFO"
doc:name="Logger" />
<logger
message=" custom header username ... #[message.inboundProperties.'http.headers'.username]"
level="INFO" doc:name="Logger"/>
<http:outbound-endpoint exchange-pattern="request-response"
address="http://localhost:1001/callReservation" method="POST"
contentType="application/json" doc:name="HTTP" />
</flow>
<flow name="testFlow1" doc:name="testFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="1001" path="callReservation" doc:name="HTTP"/>
<json:json-to-xml-transformer doc:name="JSON to XML"/>
<logger message="Data received : #[payload]" level="INFO" doc:name="Logger"/>
</flow>
I am getting the value using following :-
<logger message=" custom header username ... #[message.inboundProperties['username']]"
level="INFO" doc:name="Logger"/>
You need to pass the XML in the body of postman
UPDATE
I am getting the value as below :-
Use the data mapper after the http:outBound to convert to json response.
I have a ServiceFlow and a FileFlow. As soon as the ServiceFlow (Flow1) is triggered, FileFlow (Flow2) should take all the files and process them.
Making the initial state as stopped in Flow2 works only for the first time until Mule server started i.e., for the first triggered execution. Once the flow reaches the first trigger, if I try to keep some files in file:inbound-endpoint it starts processing the files.
But my scenario is based on each trigger only, so the second file has to pick the file. Please help me how to control this in Flow2.
I'm using the below code
<flow name="serviceFlow" doc:name="Flow1">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="8081" doc:name="HTTP" contentType="text/xml"
mimeType="text/xml" />
<set-payload value="'Started Processing'" doc:name="Set Payload" />
<async doc:name="Async">
<expression-component doc:name="Expression">
app.registry.FileFlow.start();
</expression-component>
</async>
</flow>
<flow name="FileFlow" doc:name="Flow2" initialState="stopped" >
<file:inbound-endpoint responseTimeout="10000" doc:name="File" path="C:\Users\Desktop\IN"/>
<batch:execute name="businessBatch1" doc:name="Batch Execute"/>
</flow>
Using Mule version: 3.5.1
What I can suggest you is to put a <expression-component doc:name="Expression">app.registry.FileFlow.stop();</expression-component> at the end of second flow so after the second flow is executed it will again make it's initial state "stopped" so that you can trigger the first flow again without fear since the flow2 is stopped.
<flow name="serviceFlow" doc:name="Flow1">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="8081" doc:name="HTTP" contentType="text/xml"
mimeType="text/xml" />
<set-payload value="'Started Processing'" doc:name="Set Payload" />
<async doc:name="Async">
<expression-component doc:name="Expression">
app.registry.FileFlow.start();
</expression-component>
</async>
</flow>
<flow name="FileFlow" doc:name="Flow2" initialState="stopped" >
<file:inbound-endpoint responseTimeout="10000" doc:name="File" path="C:\Users\Desktop\IN"/>
<batch:execute name="businessBatch1" doc:name="Batch Execute"/>
<expression-component doc:name="Expression">
app.registry.FileFlow.stop();
</expression-component>
</flow>