I have a Spring MVC Web application that performs CRUD operations on Tomcat Server. Can I use Mule ESB as a request handler before Tomcat. For example, users request to localhost:8181/user/create (Mule ESB Port) and Mule redirect request to localhost:8080/user/create (Tomcat Server Port) and sends response back over mule. I am using Mule ESB for webservices, but I don't understand how can I use Mule ESB for web application requests.
You can use the new HTTP module released in 3.6 and create a proxy using this flow:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<http:listener-config name="proxyConfig" host="localhost" port="${proxyPort}" />
<http:request-config name="requestConfig" host="localhost" port="${httpPort}" />
<flow name="proxyTemplate">
<http:listener config-ref="proxyConfig" path="/*" responseStreamingMode="AUTO" parseRequest="false" >
<http:response-builder statusCode="#[message.inboundProperties['http.status']]" reasonPhrase="#[message.inboundProperties['http.reason']]" />
</http:listener>
<copy-properties propertyName="*" />
<remove-property propertyName="http.*" />
<copy-attachments attachmentName="*" />
<set-property propertyName="X-Forwarded-For" value="#[message.inboundProperties['http.remote.address']]" />
<http:request config-ref="requestConfig" method="#[message.inboundProperties['http.method']]" path="#[message.inboundProperties['http.request.path']]" parseResponse="false" >
<http:request-builder>
<http:query-params expression="#[message.inboundProperties['http.query.params']]" />
</http:request-builder>
</http:request>
<copy-properties propertyName="*" />
<remove-property propertyName="http.*" />
<copy-attachments attachmentName="*" />
</flow>
</mule>
Related
I am writing a Functional Unit test case to test a Mule Flow containing an inbound and outbound HTTP connector. The flow contains the following components:
An inbound HTTP connector that listens to a rest service call say http://localhost:8080/restapi/id
A logger that displays the id in the logs
A web service consumer that sends the soap request to server2 at the wsdl : http://server2:8080/sample.wsdl
A java component that reads recieves the output from server2 and forms the response for client.
In the functional Unit test case, I am trying to mock the HTTP outbound connector calling the serevr2.
How can I do this?
The flow configuration file code is as below:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:ws="http://www.mulesoft.org/schema/mule/ws" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ws http://www.mulesoft.org/schema/mule/ws/current/mule-ws.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
<http:request-config name="HTTP_Request_Configuration" host="server2" port="8080" doc:name="HTTP Request Configuration"/>
<ws:consumer-config name="Web_Service_Consumer" wsdlLocation="http://server2:8080/sample.wsdl" service="sample" port="sample" serviceAddress="sample" doc:name="Web Service Consumer"/>
<flow name="samplehttpflowFlow">
<http:listener config-ref="bookmartmanager-httpListenerConfig" path="/restapi/id" allowedMethods="GET" doc:name="HTTP"/>
<logger message="REST request received at #[java.lang.System.currentTimeMillis()]" level="INFO" doc:name="Logger"/>
<ws:consumer config-ref="Web_Service_Consumer" doc:name="Web Service Consumer"/>
<json:xml-to-json-transformer doc:name="XML to JSON"/>
</flow>
</mule>
Everytime I try to send an email in AnyPoint Studio I get an error. I've tried sending it from other computers and it always works. It just doesn't seem to work in mine and I have no idea why.
This is my .xml:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<smtp:gmail-connector name="Gmail" validateConnections="true" doc:name="Gmail"/>
<flow name="attemptsendemailFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/sendemail" doc:name="HTTP"/>
<set-payload value="Hello" doc:name="Set Payload"/>
<smtp:outbound-endpoint host="smtp.gmail.com" user="myemail#gmail.com" password="mypwd" connector-ref="Gmail" to="myemail#gmail.com" from="myemail#gmail.com" subject="This is a test." responseTimeout="10000" doc:name="SMTP"/>
</flow>
</mule>
When I open the browser and type localhost:8081/sendemail, no email is sent and the browser prints this message.
Failed to route event via endpoint: DefaultOutboundEndpoint{endpointUri=smtp://myemail%40gmail.com:<password>#smtp.gmail.com, connector=GmailSmtpConnector
{
name=Gmail
lifecycle=start
this=17e9bc9e
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=true
connected=true
supportedProtocols=[smtp]
serviceOverrides=<none>
}
, name='endpoint.smtp.myemail.gmail.com', mep=ONE_WAY, properties={fromAddress=myemail#gmail.com, toAddresses=myemail#gmail.com, subject=This is a test.}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8, disableTransportTransformer=false}.
Funny thing is, I tested the exact same xml in other computers and it works.
I would first test if your computer has connectivity to the Gmail servers.
Try "telnet smtp.gmail.com 587" or the Mac equivalent.
I can't see the port "587" in your flow.You can try the following configuration:
<smtp:outbound-endpoint
connector-ref="emailConnector"
host="smtp.gmail.com"
port="587"
user="<account name>%40gmail.com"
password="<password>"
to="<email addresses>"
from="<account name>#gmail.com"
subject="Test email message"/>
Also check if you have access to call the smtp.gmail.com from your local network
I have a basic mule flow:
HTTP => SOAP => JAVA CLASS
<mule xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="test_dynamicsFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<cxf:jaxws-service doc:name="CXF"/>
<component doc:name="Java"/>
</flow>
</mule>
I would like to make a retrying connection to SOAP with timeout but I don't know if it possible.
I've been looking for error handling connectors:
Should I use these connectors to do that or how can I implement it?
You need to wrap your HTTP call with the until-successful scope.
Example:
<until-successful objectStore-ref="objectStore" maxRetries="5" secondsBetweenRetries="60" >
<http:request config-ref="HTTP_Request_Configuration" path="submit" method="POST" />
</until-successful>
Reference: https://developer.mulesoft.com/docs/display/current/Until+Successful+Scope
How am i supposed to disable the amqp-gen queues that creates automatically? in Mule ActiveMQ i got a "disableTemporaryReplyToDestinations" property, by setting that to 'true' and doing a one-way exchange-pattern, i'm able to implement async messaging.
Now with AMQP/RabbitMQ it's a different story, i do have the one-way exchange pattern but i dont have any property to set from the component side inside MuleStudio that tells me to disable those, i can't even disable it from the RabbitMQ Panel.
How do i disable those tempQueues (called amqp-gen in AMQP) which are not needed for an async implementation?
This is my test XML
<mule xmlns:amqp="http://www.mulesoft.org/schema/mule/amqp" xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/amqp http://www.mulesoft.org/schema/mule/amqp/current/mule-amqp.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd ">
<amqp:connector name="AMQP_Connector" validateConnections="true"
host="arbuzqorks"
port="1111"
fallbackAddresses="localhost:5672"
doc:name="AMQP Connector"/>
<flow name="rabbitmq_demoFlow1" doc:name="rabbitmq_demoFlow1">
<http:inbound-endpoint exchange-pattern="one-way" host="localhost" port="8081" path="rabbitmq" doc:name="HTTP"/>
<set-payload value="#['This is a test message that...']" doc:name="Setting payload"/>
<amqp:outbound-endpoint exchangeType="direct" responseTimeout="10000" doc:name="AMQP" connector-ref="AMQP_Connector" exchangeName="async-direct-test" exchangeDurable="true" queueDurable="true"/>
</flow>
<flow name="async-rabbitmqFlow1" doc:name="async-rabbitmqFlow1">
<amqp:inbound-endpoint exchange-pattern="one-way" exchangeName="async-direct-test" exchangeDurable="true" queueDurable="true" responseTimeout="10000" connector-ref="AMQP_Connector" doc:name="AMQP"/>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<set-payload value="#[payload + ' passed into the consumer flow']" doc:name="adding string to payload"/>
<amqp:outbound-endpoint exchange-pattern="one-way" routingKey="test_response" exchangeType="direct" exchangeDurable="true" queueDurable="true" responseTimeout="10000" connector-ref="AMQP_Connector" doc:name="AMQP" exchangeName="async-direct-test"/>
</flow>
<flow name="async-rabbitmqFlow2" doc:name="async-rabbitmqFlow2">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="asyncamqp" doc:name="HTTP"/>
<component class="com.web.esb.component.AsyncMessageRequestorComponent" doc:name="Request AMQP Message"/>
</flow>
</mule>
Your "issue" is not related to temporary queues and trying to disable them but in fact is a feature called "private queues" (see the doc for more information).
Basically, because you do not name the queues you declare in your AMQP inbound and outbound endpoints, RabbitMQ consider them as private to your connection and give them generated names.
Use the queueName attribute to configure queue names on your AMQP endpoints and things will work as you intend.
I am trying to get the basic http rest helloworld example working in Mule but I get this error
Could not find a transformer to transform "SimpleDataType{type=java.lang.String, mimeType='*/*'}" to "SimpleDataType{type=java.io.InputStream, mimeType='*/*'}". (org.mule.api.transformer.TransformerException). Message payload is of type: String
This is my config file:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.3/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/3.3/mule-http.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/3.3/mule-xml.xsd
http://www.mulesoft.org/schema/mule/jersey http://www.mulesoft.org/schema/mule/jersey/3.0/mule-jersey.xsd
http://jersey.apache.org/core http://jersey.apache.org/schemas/core.xsd">
<flow name="HelloWorld">
<inbound-endpoint address="http://localhost:8081/api"/>
<jersey:resources>
<component class="com.helloworld.AdminApi"/>
</jersey:resources>
</flow>
</mule>
And my jersey service class
#Path("version")
public class AdminApi {
#GET
#Produces("text/plain")
public String sayHelloWithUri() {
return "Version 999 " ;
}
}
I am trying to access the service using:
http://localhost:8081/api/version
which I believe should be the right url but no luck I always get the above exception message.
Anyone has an idea what this could be?
EDIT:
Root Exception stack trace:
org.mule.api.registry.ResolverException: There are two transformers that are an exact match for input: "class java.lang.String", output: "class java.io.InputStream". Transformers are: "_ObjectToInputStream(class org.mule.transformer.simple.ObjectToInputStream)" and "_ObjectToInputStream(class org.mule.transformer.simple.ObjectToInputStream)"
at org.mule.transformer.graph.GraphTransformerResolver.resolve(GraphTransformerResolver.java:65)
at org.mule.registry.TypeBasedTransformerResolver.resolve(TypeBasedTransformerResolver.java:93)
at org.mule.registry.MuleRegistryHelper.resolveTransformer(MuleRegistryHelper.java:265)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
Your configuration runs just fine with Mule 3.3.0 (tested outside of Tomcat, in Eclipse) so I suspect the problem comes from either missing or duplicated JARs on your web application classpath.
Check the JARs that get packaged in WEB-INF/lib and potential manually added JARs in Tomcat's /lib directory.
<flow name="HelloWorld">
<inbound-endpoint address="http://localhost:8081/api"/>
<jersey:resources>
<component class="com.helloworld.AdminApi"/>
</jersey:resources>
</flow>
and use this url. http://localhost:8081/api/version
result is -Version 999
If you are running with Mule Studio 3.3.0, you must put the mimeType.
Example:
<flow name="RestServiceFlow" doc:name="RestServiceFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8083" doc:name="HTTP" mimeType="application/json"/>
<jersey:resources doc:name="RESTUTCNotification">
<component class="example.esb.restApi"/>
</jersey:resources>
</flow>