I am trying to implement Server Sent Events using the HTTP connector in Mule 4.4.0. I have a flow with an http listener that is accepting SSE client connections and responding to the SSE heartbeat
<flow name="SSE_Subscribe_Flow">
<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/events/subscribe" allowedMethods="GET" responseStreamingMode="ALWAYS">
<http:response statusCode="200" >
<http:headers><![CDATA[#[output application/java
---
{
"Content-Type" : "text/event-stream",
"Cache-Control" : "no-cache",
"Connection" : "keep-alive"
}]]]>
</http:headers>
</http:response>
</http:listener>
<logger level="INFO" message="#[message]"/>
</flow>
Is it possible to push messages to the open connection from other flows?
Mule currently doesn't support Server-Sent Events. As an alternative, if you can use Websockets instead note that Mule 4 has a Websockets connector.
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>
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 a Mule application that is calling an external API over HTTPS using the <http:request connector. When I build and deploy my application locally, the call works fine. When I make a Postman call to the same external API using the exact same payload my Mule app sends, the call works fine. However, when I deploy the Mule app to Cloudhub and make the request - I get a 400 response from the external API.
Here's my flow:
<http:request-config name="mambuRequestConfiguration" protocol="HTTPS" doc:name="HTTP Request Configuration">
<http:basic-authentication username="${mambu.username}" password="${mambu.password}" preemptive="true" />
<tls:context>
<tls:key-store type="jks" path="keystore.jks" alias="${keystore.alias}" keyPassword="${keystore.keypassword}" password="${keystore.password}" />
</tls:context>
</http:request-config>
<flow name="createClientDepositAccount">
<dw:transform-message metadata:id="412fd434-12bb-47a3-9605-9bfc1d9fec46" doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
savingsAccount: {
accountHolderKey: payload.clientKey,
accountHolderType: "CLIENT",
productTypeKey: payload.productKey,
name: payload.clientProductName,
accountType: payload.accountType,
accountState: payload.accountState,
interestRate: payload.interestRate
}
}]]></dw:set-payload>
</dw:transform-message>
<http:request config-ref="mambuRequestConfiguration" path="${mambu.deposit.path}" method="POST" host="${mambu.host}" port="${mambu.port}" doc:name="Mambu: Create Client Deposit Account">
<http:success-status-code-validator values="0..599"/>
</http:request>
<dw:transform-message metadata:id="49f1231f-485f-433c-82c4-3d83856ac442" doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
message: "Account created successfully",
key: payload.savingsAccount.encodedKey
}]]></dw:set-payload>
</dw:transform-message>
</flow>
The external service I'm calling is Mambu, a cloud banking platform. I have a number of other flows in my application all making GET requests to various other Mambu APIs - all work fine (all GET requests are also over HTTPS). The response I'm getting from Mambu is a 400 with the payload:
{"returnCode":3,"returnStatus":"INVALID_API_OPERATION"}
Relevant links to the Mambu documentation are here and here.
I'm unable to replicate the behaviour I'm seeing in Cloudhub on my local instance. The only thing that differs about this call to the others I'm making is that it's a POST request.
In most cases this error is related to the API auto-discovery being improperly configured or corrupt. If API auto-discovery is configured on the Mule application, the best solution is to remove the setting from the Mule application, check if the error is resolved by starting the process again, then reconfigure the auto-discovery.
Bizarrely, the resolution to this was "turn it off and on again" as suggested on a question I posted on the Mulesoft forum. I simply deleted the app from Cloudhub and redeployed it and everything worked as expected. Very strange issue within Cloudhub by the looks of things. Hopefully Mulesoft will resolve...
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.
i'm very new to mule studio.
This is the environements setup.
VM1 = Windows 7, Visual Studio 2012, IIS 7.
A .net 4.5 WCF webservice hosted in IIS7 that has an operation that accepts a string and returns a string.
VM2 = Ubuntu 13.4 OpenJDK 1.7.0_25 Mule Studio 3.5 Community Edition.
I created a JAXWS-Client with an outbound endpoint, I did this by clicking the generate from WSDL and entering the url of the .net WCF webservice hosted in IIS on VM1. That was fine.
I then created an inbound endpoint with a jaxws-Service in-between the inbound service and the outbound client there is a logger and an object to string.
If I setup a vanilla inbound endpoint (no soap) and use a simple html form to post it all works fine and I get a string back to the browser. But adding the Soap Component causes the dispatcherexception when the flow hits the Soap Component just prior to the outbound endpoint.
org.mule.api.transport.DispatchException: java.lang.reflect.Method
cannot be cast to java.lang.String. Failed to route event via
endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message
payload is of type: String
<flow name="testtwoFlow1" doc:name="testtwoFlow1">
<http:inbound-endpoint exchange-pattern="request-response" path="SimplePing" doc:name="HTTP" host="0.0.0.0" port="8081"/>
<cxf:jaxws-service serviceClass="TestTwo.IPing" doc:name="SOAP" />
<logger level="INFO" doc:name="Logger"/>
<object-to-string-transformer doc:name="Object to String"/>
<flow-ref name="testtwoFlow3" doc:name="Flow Reference"/>
</flow>
<sub-flow name="testtwoFlow3" doc:name="testtwoFlow3">
<cxf:jaxws-client operation="SimplePing" serviceClass="TestTwo.IPing" enableMuleSoapHeaders="true" doc:name="SOAP"/>
<logger level="INFO" doc:name="Logger"/>
<http:outbound-endpoint exchange-pattern="request-response" host="192.168.0.2" port="80" path="MuleExperiments/Ping.svc" method="POST" doc:name="HTTP" />
</sub-flow>
I Have googled extensively and I haven been much in the way if examples that show an inbound service interacting with an outbound client. Or descriptions of the exception thrown, what causes it and how to address it. I'm guessing pretty much its because the service and the client are generated from the same WSDL, but I wouldn't have thought that would be a real issue. Or that in my cxf:jaxws-service & cxf:jaxws-service the service class is the same.
What my goal is, at this juncture, is to have a simple in/out of a string
My client was wrongly configured. It should have been clientClass, not serviceClass, and the port needed to be set as well. Once I made these changes, I got it working.
<cxf:jaxws-client
operation="SimplePing"
enableMuleSoapHeaders="true"
doc:name="SOAP"
clientClass="TestTwo.PingService"
port="BasicHttpBinding_IPing"
/>