1st ESB App: HTTP Inbound Endpoint(request-response) -> javaComponent1 -> http outbound endpoint(request-response) -> JavaComponent2.
2nd ESB app: HTTP Inbound Endpoint(request-response) -> javacomponent3
In my case HTTP Inbound Endpoint(request-response) of 2nd ESB app sends the response back to the http outbound endpoint(request-response) of 1st ESB App.
My problem and query: HTTP Inbound Endpoint(request-response) of 2nd ESB app should send a java object as payload of the request that is being sent back to the http outbound endpoint(request-response) of 1st ESB App. The JavaComponent2 should be able to read the object received by the http outbound endpoint(request-response) of 1st ESB App and process it further.
How should I send my Java object from the http endpoint of the second app to the http outbound endpoint of the first app? I cannot use serialization here.
You can use object to bytearray transformer before sending the object from the 2nd Mule app . Then you use bytearray to Object transformer after the http outbound endpoint in the 1st mule app, while you are receiving the response from the 2nd mule app
First App
<flow name="test_serializableFlow1" doc:name="test_serializableFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" method="POST" doc:name="HTTP"/>
<logger message="Before transformer #[payload]" level="INFO" doc:name="Logger"/>
<byte-array-to-object-transformer doc:name="Byte Array to Object"/>
<logger message="After transformer #[payload]" level="INFO" doc:name="Logger"/>
</flow>
Second app
<flow name="ssFlow1" doc:name="ssFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP"/>
<component class="Test" doc:name="Java"/>
<object-to-byte-array-transformer doc:name="Object to Byte Array"/>
</flow>
Related
Mule flow will receive multipart/form-data.
In the mule flow at runtime, I can see details of the multipart/form-data as attachments. When mule call the http request step in the flow to forward the multipart/form-data as is, mule seems to be not sending the incoming multipart/form-data.
In the log step prior to the http request,I can see all the attachments.
<flow name="impl-document:/upload">
<logger message="Received attachments: #[message.inboundAttachments.size()]"
level="INFO" doc:name="Attachments Qty" />
<foreach collection="#[message.inboundAttachments]" doc:name="For Each">
<logger
message="Attachment Key: #[key] -Key Value: #[message.payloadAs(java.lang.String)]"
level="INFO" doc:name="Logger" />
</foreach>
<set-payload value="#[null]" doc:name="Set Payload as null" />
<http:request config-ref="HTTP_Request_Configuration"
path="nodes/upload" method="POST" doc:name="call to upload document">
</http:request>
</flow>
When I enhanced the log levels to track the http details, I see the content-length as -1
Content-Length: -1
I tried a few options like setting the content-type as Multipart/form but does not seems to be working. Any thoughts what I am missing in my flow would be really great.
You need to copy the inbound attachments as outbound ones in order for the HTTP request to consider them and generate a multipart request. HTH
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.
I'm not sure how to apply logic to handle this issue.
I have a simple flow, Where I'm consuming the service in between the flow. I have tried until successful, but it required Max retries field( but I dont want to limit my retry by giving any number). To my scenario, I'm not sure when my consuming service is up, But need to retry until the service up and running ( not required retry exhausted). Could anyone suggest to handle the scenario.
<flow name="newFlow1" doc:name="newFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="ttt" doc:name="HTTP"/>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<logger message="**********test****#[payload]" level="INFO" doc:name="Logger"/>
<until-successful doc:name="Until Successful">
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8089" path="new" method="POST" doc:name="HTTP"/>
</until-successful>
<set-payload value="'Return Response'" doc:name="Set Payload"/>
</flow>
Also tried Max Retries in until successful as '-1'( to make as unlimited retry) but it is not accepting the negative value.
Tried using HTTP connector retry connection strategy(but it seems to be work for JMS or JDBC).
Could you please anyone suggest to handle this issue.
Thanks in advance.
Edited:
<http:connector name="HttpConnector" doc:name="HTTP-HTTPS">
<reconnect-forever />
</http:connector>
<flow name="new1Flow1" doc:name="new1Flow1">
<http:inbound-endpoint exchange-pattern="request-response" doc:name="HTTP" path="ttt" responseTimeout="30000" host="localhost" port="8081" />
<logger message="***entered***" level="INFO" doc:name="Logger"/>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8089" path="new" connector-ref="HttpConnector" method="POST" doc:name="HTTP"/>
<logger message="**Http StatusCode***#[message.inboundProperties['http.status']]" level="INFO" doc:name="Logger"/>
</flow>
It is not doing retry, since the service is down I could see the following error message in console for one time only.( But we should get multiple times the error message in console until service up)
Failed to route event via endpoint: DefaultOutboundEndpoint{endpointUri=http://localhost:8089/new, connector=HttpConnector
Please suggest.
You can first define a http Connector which will have a property of reconnecting forever
<http:connector name="HttpConnector" >
<reconnect-forever frequency="2000" />
</http:connector>
then you can have your inbound-or outbound endpoint use that connector reference
like this
<http:inbound-endpoint connector-ref="HttpConnector" .../>
or
<http:outbound-endpoint connector-ref="HttpConnector" .../>
Hope this helps!
Good luck!
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"
/>