Trying to use Mule as http proxy - mule

I tried to use mule as simple http proxy but seeing cookies that are send from the actual endpoint server is not passed on to the the client. Mule response has only one cookie.
<flow name="HelloWorld" doc:name="HelloWorld">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8888" doc:name="Http Endpoint"/>
<http:outbound-endpoint
method="GET" exchange-pattern="request-response"
address="http://www.google.com"
contentType="text/html" doc:name="HTTP" />
</flow>

I think your problem is not passing the cookies to the client, but the fact that the cookies you receive will point to .google.com domain, so a basic web browser will probably reject them for security reasons when they come from localhost domain, and even if they were not rejected, they would not be sent along a subsequent call to localhost.
Now, the cookies come from the http outbound as a list that you can iterate and update with something like
#[foreach (cookie: message.inboundProperties['Set-Cookie']) {cookie.domain='localhost'}]
but you will also need to check for the existence of Set-Cookie property to not produce a null pointer exception when no cookies are set by the server.
for debugging your proxy app, you can/should also log the message you receive from the http outbound to see if cookies are present.
From the client/browser to the proxied server, I think the cookies should work just fine, as there is no domain data involved.

Related

how to implement load balancer in mule Http Endpoint

In simple http endpoint, how to implement load balancer using any point studio.
<flow name="testFlow">
<http:listener config-ref="HTTP_Listener_Configuration"/>
</flow>
In simple mule HTTP endpoint you cant achieve load balancing.
However there are other efficient solution for achieving load balancing in mule application.
https://docs.mulesoft.com/runtime-manager/dedicated-load-balancer-tutorial
http://www.slideshare.net/ramakrishnakapa/load-balancer-in-mule
Load balancing can not be in simple http endpoint, but you can deploy several instances of your application and balance your request among those instances in mule. Switching between those instances is matter of different algorithms.
In this post it is all described in detail.
https://blogs.mulesoft.com/dev/mule-dev/load-balancing-with-mule/

Mulesoft server configure/access web server

A beginner in Mule and Server deployment, so please help. I have my local apache http web server running and configured the web server settings in a third party application. And the third party application's web service POST HTTP data to web server which I can access in PHP file and view the data.
How to simulate the same in Mule? Is it possible to configure Mule Server as web server in that application? If not can I access the data available in apache web server through any connectors?
Mule comes with an HTTP Connector, so yes it can receive HTTP POST requests.
Reference: https://developer.mulesoft.com/docs/display/current/HTTP+Connector
Yes, Using HTTP connector you can send POST request to the server .
you also wont have to configure the server properties just the port at which you'll access your application.
<flow name="testFlow1" doc:name="testFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="Server_Address_e.g._localhost" port="Enter_Port_Here" path="Enter_your_path_here" doc:name="HTTP"/>
</flow>

Scatter Gather for One Way

Mule 3.5 has replaced All router with Scatter Gather. I have a need to send payload to more than one message routes . Its one way and no need to aggregate the response. How would that be possible? The documentation all seem to be about request/response and aggregating data.
You can simply add each one-way outbound endpoint in turn to your flow, like so:
<flow name="MyFlow">
<set-payload value="Important Message" />
<vm:outbound-endpoint path="vm.inbox" />
<jms:outbound-endpoint queue="jms.inbox" />
<jms:outbound-endpoint queue="jms.inbox2" />
</flow>
In this flow, the payload "Important Message" will be sent to one VM queue and two JMS queues, in parallel. The endpoints are one-way because VM and JMS transport are one-way by default.

Multiple Inboud Endpoints in Mule ESB Flow?

I need to support an operation both via SOAP and file dropping on a folder. Most of the logic will be he same. Is it possible to trigger the same flow with two message sources? I cant seem to find a way. Thanks
Use a composite message source:
<composite-source>
<file:inbound-endpoint ... />
<http:inbound-endpoint ... />
</composite-source>
If you use CXF, you'll have to stick the service element inside the HTTP inbound endpoint.

Setup Mule web server and REST to SOAP proxy

I'm new to Mule and am trying to setup a web server [in Mule] to "replace" an existing Java server - which simply proxies for a SOAP web service.
So:
Web client (js/html) requests a static resource
Mule Server must return the static resource
or
Web client uses Jquery Ajax (json) request with path starting with "api/"
Mule Server must forward the request to the Java server (to use the old API)
or
Web client uses Jquery Ajax request with path starting with "sapi/"
Mule Server must translate the request to XML and call the SOAP server (for new api calls)
I'm struggling to find a good starting point:
I've played with Ajax connectors (and end-points) and can get the static content served - but not sure where to go with the api calls (don't want to force the client app to use mule.js)
I've played with HTTP end points, and I can't get the static content served (implicit Content-Type issue)
Any help will be appreciated...
Use http:static-resource-handler to serve your static content: it should take care of the content types for you. See for more info: http://www.mulesoft.org/documentation/display/current/HTTP+Transport+Reference#HTTPTransportReference-ServingStaticContent%28sinceMule3.2%29
Forget about the Ajax connector, all you need is the HTTP connector. Bind one HTTP endpoint on api and the other on sapi.
When forwarding the request, be sure to propagate headers and, potentially, path extension after api/. See the example below to see how this is typically done.
<flow name="rawProxy">
<http:inbound-endpoint
address="http://localhost:${http.port}/rest-proxies/raw"
exchange-pattern="request-response" />
<copy-properties propertyName="*" />
<http:outbound-endpoint address="http://localhost:${http.port}/rest/#[message.inboundProperties['http.relative.path']]?#[message.inboundProperties['http.query.string']]"
exchange-pattern="request-response" />
<response>
<copy-properties propertyName="*" />
</response>
</flow>
If the SOAP API you're calling as a WSDL then generate a client for it and instead of transforming to XML, transform to the request object it expects.