Error in sending email in Anypoint Studio (MuleSoft) - java

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

Related

How to mock Mule ESB HTTP outbound Connector in a Functional Unit Test Case?

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>

Mule - Retry connection with basic flow

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

Mule ESB + TOMCAT Web Application Integration

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>

Mule MSMQ flow gives connection refused error in Mule Studio

I'm trying to run the sample example from Mule blog for MSMQ.
When I setup MSMQ as global component "Test connection" says Successful, that means MSMQ is setup. Well and good till now..
Now using the following flow to test sending a message into queue:
<msmq:config name="MSMQ" serviceAddress="machinename/localhost:9000" accessToken="XZodtPym+v6NeZs+Sr4+GK9EGdA=" rootQueueName=".\private$\msmq-demo" doc:name="MSMQ" >
<msmq:connection-pooling-profile initialisationPolicy="INITIALISE_ONE" exhaustedAction="WHEN_EXHAUSTED_GROW"/>
</msmq:config>
<flow name="testingFlow1" doc:name="testingFlow1">
<http:inbound-endpoint exchange-pattern="one-way" host="localhost" port="8091" doc:name="HTTP"/>
<set-payload value="#[header:INBOUND:http.relative.path]" doc:name="Set Payload"/>
<logger message=" Sending message: #[payload]" level="INFO" doc:name="Logger"/>
<msmq:send config-ref="MSMQ" doc:name="MSMQ"/>
</flow>
When the flow hits MSMQ in console I see this error:
INFO 2014-08-07 18:00:41,299 [[testing].testingFlow1.stage1.02] org.mule.api.processor.LoggerMessageProcessor: Sending message: test
ERROR 2014-08-07 18:00:42,888 [[testing].testingFlow1.stage1.02] org.mule.retry.notifiers.ConnectNotifier: Failed to connect/reconnect: Work Descriptor. Root Exception was: Connection refused: connect. Type: class java.net.ConnectException
ERROR 2014-08-07 18:00:42,894 [[testing].testingFlow1.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Failed to invoke send. Message payload is of type: String
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Connection refused: connect (java.net.ConnectException)
java.net.DualStackPlainSocketImpl:-2 (null)
2. java.net.ConnectException: Connection refused: connect (com.sun.jersey.api.client.ClientHandlerException)
com.sun.jersey.client.urlconnection.URLConnectionClientHandler:148 (null)
3. Failed to invoke send. Message payload is of type: String (org.mule.api.MessagingException)
org.mule.modules.msmq.processors.SendMessageProcessor:198 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
Any help or directions is welcome!
msmq-config picture for clarity:
Test connection succeeds
The proof of the pudding is Mule not Studio: if Mule can't connect then Studio most probably can't either, but fails to report the issue.
So you need to fix the msmq:config element until it works.
At first glance, this serviceAddress="machinename/localhost:9000" looks highly suspicious. You should either use the actual machine name and port or localhost and port if running collocated with MSMQ.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:msmq="http://www.mulesoft.org/schema/mule/msmq" 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.2"
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/msmq http://www.mulesoft.org/schema/mule/msmq/current/mule-msmq.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<msmq:config name="MSMQ" serviceAddress="x.x.x.:9333" accessToken="wRuoma0PhX4ZHA1vQosdefff=" rootQueueName=".\private$\msmqdemo" ignoreSSLWarnings="true" doc:name="MSMQ"/>
<flow name="msmqreceiveFlow">
<set-payload value="Hello" doc:name="Set Payload"/>
<msmq:send config-ref="MSMQ__MSMQ_Connection" queueName="msmqdemo" doc:name="MSMQ"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
Try this example I think service address is wrong.This example for sending message to MSMQ queue

How to disable tempQueues in Async AMQP-RabbitMQ Implementation in Mule?

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.

Categories