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="
Related
If backend system(REST API) is not closed the connection when they send the response payload as response then how can we close the connection intentionally from mule side(http request) ?
actually we found that backend system is not closing the connection so that mule is throwing 'Remotely Closed' error.
Could anyone suggest how to close the connection in Mule side(HTTP Request connector) after JUST receiving response from backend ?
And below is the HTTP configuration :
<http:request-config name="HTTP_Request_configuration" doc:name="HTTP Request configuration" doc:id="bed9482f-2a7c-4db5-91b5-6410fac08f8e" >
<http:request-connection host="test.com" port="81" /> </http:request-config>
<http:request method="POST" doc:name="Request" doc:id="823ec599-3f8d-4ffa-ba03-72f33f0bc1b8" config-ref="HTTP_Request_configuration" path="/">
</http:request>
<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.
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.
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.
Why Mule http inbound endpoint is always GET request. I'm logging type of http method
and it always logs type is GET even I specified method type PUT in http inbound end
point.
<http:inbound-endpoint exchange-pattern="request-response"
path="testPath" doc:name="HTTP"
host="localhost" port="8083"
mimeType="application/json"
method="PUT"/>
<logger level="INFO" message="method type #[message.inboundProperties['http.method']]"
doc:name="Logger"/> <--- It always logs method is GET
It never go into following expression block:
<choice doc:name="Choice">
<when expression="#[message.inboundProperties['http.method']=='PUT']">
I would like to set http method as a "PUT" in http inbound endpoint
The method attribute on http:inbound-endpoint is ineffective: you can put any value there, it won't change anything.
As Ale suggested, it's up to the HTTP client to use whatever method you want to receive on Mule's side.