HTTP Request Connector mule - mule

I have a web service provider and consumer flows both in same project since I am testing in local. In my consumer flow, I have a HTTP Request connector which is supposed to hit the provider flow but the problem is while debugging it shows timeout to hit the provider flow and if I step over again it hits the provider flow. Also after the provider flow is executed, the control doesnt come back to consumer flow.
Here is HTTP connector config:
<http:request-config name="HTTP_Request_Configuration" host="localhost" port="8081" basePath="/api" connectionIdleTimeout="10000000" doc:name="HTTP Request Configuration"/>
<http:request config-ref="HTTP_Request_Configuration" path="/PatientAdmission" method="POST" doc:name="HTTP"/>
Am I missing something?
Below is the provider HTTP listener config
<http:listener-config name="api-httpListenerConfig" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<http:listener config-ref="api-httpListenerConfig" path="/api/*" metadata:id="426556ee-3ad8-4231-8c4c-ce3922720e6a" doc:name="HTTP"/>

Could you please try using the below listener configuration and check whether it helps (and let the http request config be the same):
<http:listener-config name="api-httpListenerConfig" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration" basePath="api"/>
<http:listener config-ref="api-httpListenerConfig" path="*" doc:name="HTTP"/>
Thanks,
Shijil.R.K

After setting the response codes in the provider HTTP Listener config and consumer HTTP Request config, the response came back to consumer flow.

Related

Mule http request giving 404 mapped as failure

I am trying to pass the multiple URI params in the http request as follows:
<http:listener-config name="HTTP_Listener_Configuration"
host="localhost" port="8081" doc:name="HTTP Listener Configuration"
connectionIdleTimeout="40000" />
<http:request-config name="HTTP_Request_Configuration1" protocol="HTTPS" host="" port="443" doc:name="HTTP Request Configuration" connectionIdleTimeout="300000" responseTimeout="50000">
<http:basic-authentication username="user" password="123"/>
</http:request-config>
<flow name="testFlow">
<http:listener config-ref="HTTP_Listener_Configuration"
path="/paypal" allowedMethods="GET" doc:name="HTTP" />
<set-variable variableName="config" value="#[{'p1':'3054', 'p2':'child/Lines'}]" doc:name="Variable"/>
<http:request config-ref="HTTP_Request_Configuration1" path="/resources/shipment/{p1}/{p2}" method="GET" doc:name="HTTP">
<http:request-builder>
<http:uri-params expression="#[flowVars.config]"/>
</http:request-builder>
</http:request>
</flow>
But this is giving me error as below:
Response code 404 mapped as failure.
ERROR 2019-01-04 18:46:34,526
[[paypaltest].HTTP_Listener_Configuration.worker.01]
org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Response code 404 mapped as failure.
Payload : org.glassfish.grizzly.utils.BufferInputStream#b473ec2
Element : /testFlow/processors/1 # test:test.xml:29 (HTTP)
Element XML : <http:request config-ref="HTTP_Request_Configuration1" path="/resources/shipments/{p1}/{p2}" method="GET" doc:name="HTTP">
<http:request-builder>
<http:uri-params expression="#[flowVars.config]"></http:uri-params>
</http:request-builder>
</http:request>
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.module.http.internal.request.ResponseValidatorException: Response code 404 mapped as failure.
Please let me know if any help can be provide!
It means that the url doesn't exist. Try to hit the url directly in postman before implementing in Mule. Since you wiped out the host="", I'll pretend it's example.com. My guess is that it's having an issue with p2. If you'd like to send the actual string, you'll need to URL encode the "/", which is %2F
So to test hit https://www.example.com/resources/shipments/3054/child%2FLines, with the Basic Auth for Authorization.
Postman: https://www.getpostman.com/apps
The issue i faced was unique to me, i tried this REST api call from SOAPUI and there it gave me the same error i.e. 404 not found so i compared it with POSTMAN request and found that Authorization header was the missing piece for this.
After adding this to http header it worked perfectly.
Please refer
https://docs.mulesoft.com/connectors/http/http-authentication
here are two solutions :
1. Add preemptive="true" in basic authentication configuration
The pre-emptive option passes the user name and password without waiting for a prompt from the server.
Add Authorization in the http:header value ="Basic dXNlcjoxMjM="

Got 'Connection Refused' error when i tried to connect Third party services using Proxy in Mule Anypointstudio

<http:request-config name="HTTP_Request_Configuration" protocol="HTTPS" host="nww.neopost.sbs.nhs.uk" port="443" doc:name="HTTP Request Configuration" proxy-ref="Neopost_Global_Proxy_Configuration">
<http:basic-authentication username="46234F3D-192C-4118-9A79-948F6C2053BB" password="F25038E0-53D6-4C06-8DFE-FF25FA3C82CD"/>
<tls:context>
<tls:trust-store path="C:/Java/jdk1.7.0_80/jre/lib/security/cacerts" password="changeit"/>
</tls:context>
</http:request-config>
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8088" basePath="test" doc:name="HTTP Listener Configuration"/>
<flow name="xxxFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" allowedMethods="GET" doc:name="HTTP"/>
<http:request config-ref="HTTP_Request_Configuration" path="web_api_dev/documentservices.svc/Documents" method="GET" doc:name="HTTP">
<http:request-builder>
<http:query-param paramName="batchsize" value="100"/>
</http:request-builder>
</http:request>
<logger level="INFO" doc:name="Logger"/>
</flow>
When i tried to connect third party services using anypoint studio project, it gives me 'java.net.ConnectException: Connection refused: no further information' error. I have checked the proxy and added that host in proxy bypass also. But still am getting same error.
I am accessible third party url using browser, but not with "https request".
Help me to resolve this error. Thanks in advance.
Anypointstudio_proxy_settings
Browser_proxy_Settings
Browser_Response
Mule flows do not use the Anypoint Studio proxy configuration. Your http:request-config element has specified proxy-ref="Neopost_Global_Proxy_Configuration", you need to remove that if you want to connect to that host directly.
If you have multiple HTTP Requests, some that need to use the proxy and some that don't, you will need to have 2 different http:request-config elements.

Migrating to the New HTTP Connector

I've upgraded from Mule 3.3.x to 3.6.x and since the old http endpoint is deprecated in 3.6.x I wanted to migrate to the new HTTP connector.
Here is the original code for calling a webservice and healthcheck
Webservice
<http:outbound-endpoint connector-ref="NoSessionConnector"
address="${testmigrationapp.endpoint.url}"
responseTimeout="${testmigrationapp.endpoint.timeout}" keep-alive="true"
responseTransformer-refs="errorHandler">
<jms:transaction action="ALWAYS_JOIN"/>
Healthcheck
<http:inbound-endpoint exchange-pattern="request-response" address="${testmigrationapp.healthcheck.address}" doc:name="HTTP"/>
How would I implement this using the new HTTP connector?
Thanks
An HTTP outbound endpoint would translate to an HTTP request. You will need to define a request-config specifying the host, port and persistent connections (because of the keep-alive=true). Then you can replace the outbound endpoint with a request element specifying the URL path and the response timeout. For example:
<http:request-config name="persistentRequestConfig" usePersistentConnections="true" host="example.com" port="80" />
<flow name="persistent">
<http:request config-ref="persistentRequestConfig" path="/" responseTimeout="30" />
</flow>
An HTTP inbound endpoint would translate to an HTTP listener. You will need to define a listener-config specifying the host and port. Then you can replace the inbound endpoint for a listener element specifying the URL path. For example:
<http:listener-config name="listenerConfig" host="0.0.0.0" port="8081"/>
<flow name="testFlow">
<http:listener config-ref="listenerConfig" path="/"/>
<echo-component/>
</flow>
For more details you can checkout our docs regarding the migration.

How to send a json payload while consuming a rest api

I have an api developed and want to consume this api in a mule flow.
But when I test from chrome:postman I am getting the below error.
Message payload is of type: BufferInputStream
So I tried to log the message and below I got
org.glassfish.grizzly.utils.BufferInputStream#e2ed077
So basically my requirement is how can I pass json payload to my api. Below is my code snippet.
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8083" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration" host="localhost" port="8082" doc:name="HTTP Request Configuration">
<http:basic-authentication username="sa" password="sa"/>
</http:request-config>
<flow name="get-response-container-storeFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/testapi" doc:name="HTTP"/>
<logger message="******************Executed Test_Container_Store_API*******************#[payload]" level="INFO" doc:name="Logger"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<http:request config-ref="HTTP_Request_Configuration" path="/apie" method="POST" sendBodyMode="NEVER" doc:name="HTTP">
</http:request>
You can resolve the first "error" with the logger by addding a <object-to-string-transformer/> as the first message processor after your http:inbound (or more importantly, before your logger).
If you want to include the body in the request you should remove the sendBodyMode="NEVER" attribute from your request.
From the MuleSoft docs:
By default, the methods GET, HEAD and OPTIONS sends HTTP requests with an empty body, and the payload of the Mule message won’t be used at all. The rest of the methods sends the message payload as the body of the request. If you need to change this default behavior, you can specify the sendBodyMode attribute in the request, with one of the following possible values:
AUTO (default): The behavior depends on the method. Body is not sent for GET, OPTIONS and HEAD, and it is sent otherwise.
ALWAYS: The body is always sent.
NEVER: The body is never sent.
This means since you have this attribute set to never your payload will never be included as the request-body.

How to Intercept incoming call in Mule

Hi I am working with Mule Any Point platform i am using composite source which is listening from HTTP and JMS both. I want to identify the incoming call coming from HTTP or JMS and i want to print using the logger. How to do that ?
Try the following way of using logger inside your endpoints.
<composite-source doc:name="Composite Source">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP">
<logger message="Request coming from HTTP endpoint."></logger>
<set-variable value="HTTP" variableName="myVar"></set-variable>
</http:inbound-endpoint>
<jms:inbound-endpoint doc:name="JMS" queue="in">
<logger message="Request coming from JMS endpoint."></logger>
<set-variable value="JMS" variableName="myVar"></set-variable>
</jms:inbound-endpoint>
</composite-source>
In the flow when you have to chekc a condition, you can use the flow variable "myVar" to check whether the message came from HTTP or JMS endpoint.
Hope this helps.