i am using HTTP component of mule to connect to a REST API which is having a basic Authentication with USERNAME and PASSWORD . I used "HTTP settings" tab of HTTP component to supply the authentication details , username and Password. but i think its not working .
Am i doing anything wrong ? is there any better way to call REST service which is having Basic authentication like.
You should set the Basic Authentication value as a Header Property in to the outgoing Mule Message when you are consuming a REST service via the Mule HTTP outbound endpoint.
<flow name="consume_rest">
.............
..........
<set-property propertyName="Authorization" value="Basic Authorization String combination of Username and password" />
<http:outbound-endpoint exchange-pattern="request-response" method="POST" responseTimeout="20000"
host="localhost" path="rest.path" port="Port number" />
.............
.............
</flow>
Hope this helps.
The following is an example of REST Service with Basic Authentication :-
<mule-ss:security-manager>
<mule-ss:delegate-security-provider name="memory-provider" delegate-ref="authenticationManager" />
</mule-ss:security-manager>
<spring:beans>
<ss:authentication-manager alias="authenticationManager">
<ss:authentication-provider>
<ss:user-service id="userService">
<ss:user name="your username" password="your password" authorities="ROLE_ADMIN" />
<ss:user name="your username2" password="your password2" authorities="ROLE_USER" />
</ss:user-service>
</ss:authentication-provider>
</ss:authentication-manager>
</spring:beans>
<flow name="MainService" doc:name="MainService">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP">
<mule-ss:http-security-filter realm="realm" />
<mule-ss:authorization-filter requiredAuthorities="ROLE_ADMIN"/> <!-- Restrict a particular group of users -->
</http:inbound-endpoint>
<jersey:resources doc:name="REST">
<component class="com.test.services.schema.maindata.v1.Impl.MainDataImpl"/>
</jersey:resources>
</flow>
And for connecting an existing external REST Service from Mule use:- http://username:password#host/yourpath in http outbound endpoint
HTTP outbound with basic authentication
Thanks everyone for replying !!
The username and password on the connector is for when you want to secure your inbound endpoint with HTTP basic authentication.
When calling a external services that is secured with basic auth you should use the uri method
Related
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 setup user authentication (verification of username and password) fro Mule ESB http inbound-endpoint?
This http inbound-endpoint will be used for REST service.
Thank you.
<spring:beans>
<security:authentication-manager alias="MyManager">
<security:authentication-provider>
<security:user-service id="UserService">
<security:user name="someusername" password="somepassword" authorities="ROLE_ADMIN"/>
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
</spring:beans>
<spring-security:security-manager>
<spring-security:delegate-security-provider delegate-ref="MyManager" name="InMemory"/>
</spring-security:security-manager>
<flow name="main">
<http:inbound-endpoint address="http://localhost:8000/secured">
<spring-security:http-security-filter realm="mule-realm" securityProviders="InMemory"/>
</http:inbound-endpoint>
...
Mule can be configured with Spring security to provide basic authentication with username and password. The spring security can also be configured to provide role based support where multiple users involve .
Some example you can refer here to get more ideas on it :- http://confluex.com/blog/http-inbound-endpoint-basic-authentication/
and
http://www.javaroots.com/2013/06/how-to-secure-rest-services-in-mule-3.html
also
https://developer.mulesoft.com/docs/display/current/Configuring+the+Spring+Security+Manager
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"
/>
I'm struggling to configure and deploy to CloudHub an app with multiple Global HTTP Connectors and a REST component.
My application has two flows: one polls an RSS feed for news and posts a json representation of that feed to an http inbound endpoint in the same app (endpoint resides on second flow). The second flow receives that post, does some magic, including persisting the item to storage, and then notifies via an http outbound endpoint an external node.js web app to push the item via web sockets to active clients.
I have tried what feels like dozens of different configurations involving a variety of HTTP Global Connectors and http in and outbound endpoints, but I can't get everything to work. I currently have:
A Polling HTTP Connector
An HTTP endpoint referencing above polling http connector to get RSS Feed
One Global Connector (we'll call HTTP_ONE) to receive messages at localhost:${http.port}
An http oubound endpoint configured referencing HTTP_ONE and configured to post an activity to /api/v1/activity
An http inbound endpoint configured to receive messages for /api/v1 and a Jersey controller sitting just behind this endpoint which takes /activity.
Another Global Connector (HTTP_TWO) with an external host set as the proxy host name (e.g. somehost.somewhere.com).
An http outbound endpoint configured to post messages to somehost.somewhere.com
On my localhost, I've had to use various properties to allow for all of this activity on multiple ports on my laptop.
On CloudHub, I'm using localhost and ${http.port} everywhere except in the oubound endpoint that calls to an external web service.
I can get one flow or the other working, but not both.... My problem seems to be with the posting a given news item from the RSS feed to the Inbound HTTP Endpoint. It is sending the post to http://localhost:80/api/v1/activity, but the connector says that no such path exists (it only lists /api/v1 as an option), which makes me think that the call is not getting as far as the Jersey Controller which sits behind the Global Connector and the http inbound endpoint for /api/v1/activity. Is this behavior an inherent flaw in using the REST Component and multiple global http connectors? Also, why do we have to reference a Global HTTP Connector when making an outbound call? Why can't we use the default HTTP Connector? (Maybe the last two questions should go in a subsequent post...)
Here's most of the relevant config for the two flows:
Global Connectors
<http:polling-connector name="PollingHttpConnector" pollingFrequency="60000" doc:name="HTTP Polling" clientSoTimeout="10000" cookieSpec="netscape" receiveBacklog="0" receiveBufferSize="0" sendBufferSize="0" serverSoTimeout="10000" socketSoLinger="0" validateConnections="true"/>
<http:connector name="EduStream_HTTP" cookieSpec="netscape" validateConnections="true" sendBufferSize="0" receiveBufferSize="0" receiveBacklog="0" clientSoTimeout="10000" serverSoTimeout="10000" socketSoLinger="0" proxyHostname="${edustream.host}" doc:name="HTTP\HTTPS" proxyPort="80"/>
<http:connector name="EduStreamESB_HTTP" cookieSpec="netscape" validateConnections="true" sendBufferSize="0" receiveBufferSize="0" receiveBacklog="0" clientSoTimeout="10000" serverSoTimeout="10000" socketSoLinger="0" proxyHostname="localhost" proxyPort="${http.port}" doc:name="HTTP\HTTPS"/>
News RSS Feed Flow
<flow name="ucdNewsConsumer" doc:name="ucdNewsConsumer">
<http:inbound-endpoint address="http://news.ucdavis.edu/xml/getnews.php/rss/category/General%20Interest"
connector-ref="PollingHttpConnector" doc:name="HTTP" exchange-pattern="one-way"/>
<rss:feed-splitter/>
<rss:entry-last-updated-filter/>
<component class="edu.ucdavis.edustream.esb.news.rss.EntryReceiver" doc:name="Java"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="${http.port}" path="api/v1/activity" doc:name="HTTP" mimeType="application/json" connector-ref="EduStreamESB_HTTP" />
<logger message="Payload is: #[payload] Inbound Headers: #[headers:INBOUND:*] Outbound Headers: #[headers:OUTBOUND:*] Exception is: #[exception]" level="INFO" doc:name="Logger"/>
</flow>
Activity Publication Service -- Core Flow
<flow name="edustreamesbFlow1" doc:name="edustreamesbFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="${http.port}" doc:name="HTTP" contentType="application/json" mimeType="application/json" path="api/v1" connector-ref="EduStreamESB_HTTP"/>
<jersey:resources doc:name="REST">
<component class="edu.ucdavis.edustream.esb.activity.restapi.ActivityController"/>
</jersey:resources>
<component class="edu.ucdavis.edustream.esb.activity.restapi.JerseyResponseTransformer" doc:name="JerseyRespTrans"/>
<flow-ref name="PublishActivity" doc:name="Publish Activity"/>
</flow>
<sub-flow name="PublishActivity" doc:name="PublishActivity">
<component doc:name="ActivityService">
<spring-object bean="activityService"/>
</component>
<logger message="#[payload] #[message]" level="INFO" doc:name="Logger"/>
<http:outbound-endpoint exchange-pattern="request-response" host="${edustream.host}" port="80" path="api/v1/activity" mimeType="application/json" contentType="application/json" doc:name="HTTP" connector-ref="EduStream_HTTP"/>
</sub-flow>
I do not get why proxyHostname and proxyPort are configured on both EduStream_HTTP and EduStreamESB_HTTP connectors while the HTTP endpoints from these connectors target the same host/port as their destination address. This doesn't make any sense to me.
Are you really sure you need to use proxies?
For EduStreamESB_HTTP the answer is clearly no: you're calling CloudHub from CloudHub, so no need for a proxy.
For EduStreamESB_HTTP, maybe... but that still seems very strange.
I have a flow where I receive request via webservice. I forward that request to a JMS queue using component binding. However, I would like to get async-reply from that queue and use it as response to the webservice. Do I need to use reply-to and async-reply-router in the flow? Or is there any other way to do that in Mule 3? Any pointers?
<flow name="mviService">
<http:inbound-endpoint address="http://localhost:62005/mvi"
exchange-pattern="request-response">
<cxf:jaxws-service serviceClass="com.xyz.services.mvi.MVIServicePortType" />
</http:inbound-endpoint>
<component class="com.pennmutual.services.mvi.MVIServiceImpl">
<binding interface="com.pennmutual.mvi.helper.XMLReqProcessorInterface"
method="process121Order">
<jms:outbound-endpoint queue="mviq.121.order" />
</binding>
</component>
<async-reply>
</async-reply>
</flow>
============ EDITED - SEE BELOW FOR RE-FRAMED QUESTION =================
I think I haven't done a good job in describing the scenario. Let me try again. Here's the scenario --
A client calls our service described in this flow "mviService". mviService gets XML request via HTTP/SOAP based inbound endpoint. Let's call this request as XML121Request.4
A component defined in MVI "com.xyz.services.mvi.MVIServiceImpl" makes some changes in XML121Request.
Forwards this XML121 to a JMS queue "mviq.121.order". It uses component binding for this.
The outbound endpoint to this JMS queue is a third party web service where this request is forwarded. The third party acknowledges the receipt of XML121 and the synchronous web service call returns.
The response from that third party service comes at a later point of time, which is generally couple of seconds. The response comes asynchronously. Third party invokes another webservice endpoint on MVI and sends the XML121Response.
MVI puts this response in a JMS queue named "mviq.async.service.reply".
The "mviService" flow needs to wait for this response and send this response (after some modification) to caller(in step 1).
I'm able to get the response from third party and this response is enqued in a queue named "mviq.async.service.reply". I would like to use/consume this message and return it as a response to first call to MVI.
I'm trying to use "request-reply".
<request-reply timeout="60000">
<vm:outbound-endpoint path="request" />
<jms:inbound-endpoint queue="mviq.async.service.reply"
exchange-pattern="one-way" />
</request-reply>
THe problem is that even though I don't want to have outbound-endpoint in this case, I still have to put one as this is required by request-reply tag. The flow waits for 60 seconds at that point of time but even if I put something in the queue "mviq.async.service.reply" the correlation ID doesn't match so the service timesout and returns an error.
flow is mentioned below.
<flow name="mviService">
<http:inbound-endpoint address="http://localhost:62005/mvi"
exchange-pattern="request-response">
<cxf:jaxws-service serviceClass="com.xyz.services.mvi.MVIServicePortType" />
</http:inbound-endpoint>
<component class="com.pennmutual.services.mvi.MVIServiceImpl">
<binding interface="com.xyz.mvi.helper.XMLReqProcessorInterface"
method="process121Order">
<jms:outbound-endpoint queue="mviq.121.order" />
</binding>
</component>
<!-- <logger message="XML Correlation ID 1 is #[mule:message.headers(all)]" /> -->
<request-reply timeout="60000">
<vm:outbound-endpoint path="request" /> <!-- we don't care about this -->
<jms:inbound-endpoint queue="mviq.async.service.reply"
exchange-pattern="one-way" />
</request-reply>
<!-- <component class="com.xyz.mvi.CreateMVIServiceResponse"/> -->
</flow>
===== FLow with REPLY TO =============
<flow name="mviService">
<http:inbound-endpoint address="http://localhost:62005/mvi"
exchange-pattern="request-response">
<cxf:jaxws-service serviceClass="com.xyz.services.mvi.MVIServicePortType" />
</http:inbound-endpoint>
<component class="com.xyz.services.mvi.MVIServiceImpl">
<binding interface="com.xyz.mvi.helper.XMLReqProcessorInterface"
method="process121Order">
<jms:outbound-endpoint queue="mviq.121.order" exchange-pattern="request-response">
<message-properties-transformer scope="outbound">
<add-message-property key="MULE_REPLYTO" value="mviq.async.service.reply" />
</message-properties-transformer>
</jms:outbound-endpoint>
</binding>
</component>
</flow>
I'd like to suggest you do not create a service component class and instead use cxf:proxy-service, which will give you direct access to the SOAP envelope and the opportunity to assemble the response the way you want at XML level.
This will free you from the constraint a service component class imposes on you, hence waive the need to use bindings and open the door to using request-response.
See this SO answer and check the (skinny) proxy service user guide for more information.