I am trying a simple Mule 3.3.0 configuration which will download every email and pass it on to my custom processor class. Once the email is retrieved it should be deleted from the gmail inbox. But that doesn't seem to be working. Below is my mule-config.xml
<spring:beans>
<spring:import resource="classpath:spring/applicationContextServices-core.xml"/>
<spring:import resource="classpath:spring/applicationContextServices-configuration.xml"/>
<spring:bean id="emailSender" name="emailSender" class="com.test.EmailSender"/>
<spring:bean id="retrieveEmailProcessor" name="retrieveEmailProcessor" class="com.test.RetrieveEmailProcessor"/>
</spring:beans>
<jms:activemq-connector name="Active_MQ" specification="1.1" username="[username]" password="[password]" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ">
<reconnect/>
</jms:activemq-connector>
<pop3s:connector name="pop3Connector" checkFrequency="45600" deleteReadMessages="true"/>
<flow name="1_SendMessageToOwner" doc:name="1_SendMessageToOwner" doc:description="This is to confirm that your email was received successfully">
<jms:inbound-endpoint topic="PoolMessage" connector-ref="Active_MQ" doc:name="JMS"/>
<component doc:name="Build Email Message">
<spring-object bean="emailSender"/>
</component>
<smtps:outbound-endpoint host="smtp.gmail.com" port="465" user="[username]%40gmail.com" password="[password]" from="[username]#gmail.com" responseTimeout="50000" doc:name="SMTP"/>
</flow>
<flow name="2_ReceiveConfirmation" doc:name="2_ReceiveConfirmation" doc:description="Retrieving Email">
<pop3s:inbound-endpoint connector-ref="pop3Connector" host="pop.gmail.com" port="995" user="[username]%40gmail.com" password="[password]" responseTimeout="10000" doc:name="Pop3"/>
<component doc:name="Process Transaction - Confirmation Message" doc:description="Recieve confirmation from member.">
<spring-object bean="retrieveEmailProcessor"/>
</component>
</flow>
</mule>
and the RetrieveEmailProcessor class
package com.test;
import java.util.Map;
import org.mule.api.MuleEventContext;
import org.mule.api.lifecycle.Callable;
public class RetrieveEmailProcessor implements Callable {
public Object onCall(MuleEventContext eventContext)
throws Exception
{
System.out.println("########## Entering RetrieveEmailProcessor.OnCall ##########");
Map dataMapMessage = (Map)eventContext.getMessage().getPayload();
String subject = (String)dataMapMessage.get("subject");
String toAddressList = (String)dataMapMessage.get("toAddressList");
String fromAddress = (String)dataMapMessage.get("fromAddress");
eventContext.getMessage().setOutboundProperty(
"toAddresses",
toAddressList);
eventContext.getMessage().setOutboundProperty(
"subject",
subject);
eventContext.getMessage().setOutboundProperty(
"replyToAddresses",
fromAddress);
System.out.println("########## Exiting RetrieveEmailProcessor.OnCall ##########");
return dataMapMessage.get("mailBody");
}
}
Is there anything obvious that I am missing?
Thanks in advance
Your Mule configuration is fine.
You need to check your Gmail's configuration:
Settings -> Forwarding and POP/IMAP -> In POP Download: --> 2. When messages are accessed with POP
There you need to select "delete Gmail's copy" if you want your messages deleted or archived once they're read by the POP connector.
Related
I'm having a random problem with amqp components in Mule.
This is the scenario:
I set a global AMQP connector to be used for both Mule Flows
<amqp:connector
name="amqpLocalhostConnector"
host="${amqp.host}"
port="${amqp.port}"
fallbackAddresses="${amqp.fallbackAddresses}"
virtualHost="${amqp.virtualHost}"
username="${amqp.username}"
password="${amqp.password}"
ackMode="MANUAL"
prefetchCount="1" />
This flows sends a notification to RabbitMQ
<flow
name="notifyRabbitMQ"
doc:name="notifyRabbitMQ">
<!-- Set the payload with an ID from an element in a database -->
<set-payload
doc:name="Set Payload"
value="123abc"/>
<!-- Send the ID into an amqp message to RabbitMQ -->
<amqp:outbound-endpoint
exchangeName="exchange"
routingKey="file.id"
connector-ref="amqpLocalhostConnector">
</amqp:outbound-endpoint>
</flow>
This flow gets the notification from the RabbitMQ queue and then process it.
<flow
name="processNotification"
doc:name="processNotification"
processingStrategy="synchronous">
<amqp:inbound-endpoint
queueName="files"
connector-ref="amqpLocalhostConnector" />
<byte-array-to-string-transformer doc:name="Message to String (ID)"/>
<set-payload
value="#[app.registry.customFileService.findFile(payload)]"
doc:name="Get File" />
<logger message="SUCCESS!" level="INFO" doc:name="Logger"/>
<amqp:acknowledge-message />
</flow>
When I run the project, sometimes it works fine and sometimes it throws the following error:
ERROR 2015-07-17 12:37:47,620 [[rabbit_notification].amqpLocalhostConnector.receiver.01] org.mule.transport.amqp.AmqpMessageReceiver$AmqpMessageRouterWork: Impossible to route: org.mule.transport.amqp.AmqpMessage#43cac8[consumerTag=amq.ctag-jASX98hPWb7UUiIVHLOeEQ,envelope=Envelope(deliveryTag=2, redeliver=false, exchange=exchange, routingKey=file.id),body={53,53,97,57,50,49,52,98,50,50,50,57,101,56,56,51,55,101,98,54,102,100,56,53},properties=#contentHeader(content-type=null, content-encoding=UTF-8, headers={MULE_SESSION=rO0ABXNyACNvcmcubXVsZS5zZXNzaW9uLkRlZmF1bHRNdWxlU2Vzc2lvbi7rdtEW7GGKAwAEWgAFdmFsaWRMAA1mbG93Q29uc3RydWN0dAAmTG9yZy9tdWxlL2FwaS9jb25zdHJ1Y3QvRmxvd0NvbnN0cnVjdDtMAAJpZHQAEkxqYXZhL2xhbmcvU3RyaW5nO0wAD3NlY3VyaXR5Q29udGV4dHQAJ0xvcmcvbXVsZS9hcGkvc2VjdXJpdHkvU2VjdXJpdHlDb250ZXh0O3hwAXB0ACRjNjI4Zjc0Ny0yYzk5LTExZTUtYjI3YS1lMWM4ZmJjNTUzY2Fwc3IAJWphdmEudXRpbC5Db2xsZWN0aW9ucyRTeW5jaHJvbml6ZWRNYXAbc/kJS0s5ewMAAkwAAW10AA9MamF2YS91dGlsL01hcDtMAAVtdXRleHQAEkxqYXZhL2xhbmcvT2JqZWN0O3hwc3IAJG9yZy5tdWxlLnV0aWwuQ2FzZUluc2Vuc2l0aXZlSGFzaE1hcJ3R2e9nRc4AAwAAeHB3DD9AAAAAAAAQAAAAAHhxAH4ACXh4, MULE_ENCODING=UTF-8, MULE_ROOT_MESSAGE_ID=c628f745-2c99-11e5-b27a-e1c8fbc553ca, MULE_ENDPOINT=amqp://exchange}, delivery-mode=2, priority=0, correlation-id=null, reply-to=null, expiration=null, message-id=c628f745-2c99-11e5-b27a-e1c8fbc553ca, timestamp=Fri Jul 17 12:37:47 ART 2015, type=null, user-id=null, app-id=null, cluster-id=null)]
Does anyone knows why this could be happening?
Thanks in advance.
In a flow something like below:
<flow name="fileFlow">
<file:inbound-endpoint path="/inbound/ftp/sbc" pollingFrequency="30000" fileAge="30000" moveToDirectory="/inbound/ftp/sbc/archive">
<file:filename-wildcard-filter pattern="*.xml" caseSensitive="false"/>
</file:inbound-endpoint>
<logger message="Entering #[flow.name] flow" level="INFO"/>
<component class="com.abc.RequestFile"/>
<logger message="Payload after transformation is: #[payload] flow" level="INFO"/>
<vm:outbound-endpoint path="merge" />
<logger message="Exiting #[flow.name] flow" level="INFO"/>
</flow>
I get InputStream from file:inbound-endpoint which is passed to RequestFile component. This component is required to return a list of files of which one of this is the original one read and passed. I am seeking a solution other than manual copying InputStream to File in java component.
As explained in this answer https://stackoverflow.com/a/12397775/387927 you can get the java.io.File object instead of its content with this setting:
<file:connector name="fileConnector" streaming="false" autoDelete="false">
<service-overrides messageFactory="org.mule.transport.file.FileMuleMessageFactory" />
</file:connector>
Note that it is up to you to move / delete the file either before you start or once you've done processing it, otherwise Mule will poll it again and again.
I have a Mule flow, with a custom interceptor, which constructs an Object and forwards it to a JMS outboud endpoint. The JMS endpoint throws an exception trying to convert the Object to a JMS StreamMessage. What I want is for the endpoint to convert the Object to a JMS ObjectMessage, instead. How would that be done?
here's my flow;
<spring:beans>
<spring:bean id="connectionFactoryFactory" name="connectionFactoryFactory"
class="ConnectionFactoryFactory">
<spring:property name="properties">
<spring:props>
<spring:prop key="imqAddressList">mqtcp://localhost:30001/jms</spring:prop>
<spring:prop key="imqReconnectAttempts">-1</spring:prop>
</spring:props>
</spring:property>
</spring:bean>
<spring:bean id="connectionFactory" name="connectionFactory"
factory-bean="connectionFactoryFactory" factory-method="createConnectionFactory" />
</spring:beans>
<jms:connector name="JMSConnector" connectionFactory-ref="connectionFactory"
specification="1.1" doc:name="JMS" />
<flow name="Request" doc:name="Request">
<quartz:inbound-endpoint responseTimeout="10000"
doc:name="InfoRequest" jobName="InfoRequest" repeatInterval="5000">
<quartz:event-generator-job />
</quartz:inbound-endpoint>
<custom-interceptor class="StateRequest"/>
<jms:outbound-endpoint connector-ref="JMSConnector"
doc:name="JMS" topic="requests"/>
</flow>
I have also tried adding an Object to JMS Message Transformer;
<jms:object-to-jmsmessage-transformer returnClass="javax.jms.ObjectMessage" name="Object_to_JmsMessage" doc:name="Object to JmsMessage"/>
<jms:outbound-endpoint connector-ref="JMSConnector"
doc:name="JMS" topic="requests" transformer-refs="Object_to_JmsMessage"/>
Because Request extends LinkedList<RequestId> implements Serializable, Mule will automatically convert this type to a StreamMessage.
Unfortunately this behavior is in a static class so it's hard to swap with another one. Either create your own JMS ObjectMessage from code or subclass AbstractJmsTransformer to create your own flavor of ObjectToJMSMessage that would call JmsMessageUtils.serializableToMessage for payloads of type Request.
I'm using mule 3.2.0 and
I'm invoking muleclient.send method in java-class which sends soap-request to a mule flow(not present here), which sends it to the http endpoint which receives request, logs it to my db with proxy pattern and propagates it to "ServiceFlow" which has Dispatcher transformer - java class, which uses invocation of MuleClient.send(String url, Object payload, Map messageProperties) method to dispatch one object of the payload array to an endpoint.
Then it gets processed by cxf:jax-ws-client, logged to a db once again and transferred to another instance of Dispatcher (where incoming payload is again of type Object[]). There I have http endpoint which does the service invocation. This part works okay.
But trouble appears at the receiving of the response. I've put Test1(2,3,4) transformers to print the invocation chain in my flows (They just do the System.out.println()), and saw that they're invoked in a weird sequence: I have it like 1,3 then TestTransformer (which is also the sysouter) then I get the error "NullPayload" in the caller of the main flow "Service flow" and then I receive the Test 4 and Test 2 outs. The responseTransformer-refs in patterns "1Proxy" are ignored, so as in "ServiceProxy". I've been looking for the solution for like a week now, and can't find it. In debugging, I can see that transformer called "TestTransformer" in has expected payload (Object[]) but when I receive it in my class caller, it appears as "NullPayload". I can see now that one of my endpoints has the path element instead of ref, not sure if this cause any impact on flow, but will check it. Also tried to use the "response" block to ensure my flow runs as expected. Any suggestions appreciated. Thanks
Here is what my config looks like:
<http:endpoint name="httpService" address="${service.soap}" exchange-pattern="request-response" responseTimeout="${timeout}" />
<vm:endpoint name="vmService" path="vmService" exchange-pattern="request-response"/>
<pattern:web-service-proxy
name="ServiceProxy"
inboundEndpoint-ref="httpService"
transformer-refs="to-string logging"
responseTransformer-refs="to-string logging"
outboundEndpoint-ref="vmService" />
<flow name="ServiceFlow" >
<inbound-endpoint ref="vmService"/>
<cxf:jaxws-service serviceClass="pkg.ServiceImpl" wsdlLocation="${service.wsdl}" enableMuleSoapHeaders="false" validationEnabled="true"/>
<custom-transformer class="pkg.Dispatcher">
<spring:property name="vmFlowPath" value="vm.logService"/>
</custom-transformer>
<custom-transformer name="TestTransformer" class="pkg.TestTransformer"/>
</flow>
<vm:endpoint name="vm1In" path="vm1In" exchange-pattern="request-response"/>
<vm:endpoint name="vm1Out" path="vm1Out" exchange-pattern="request-response"/>
<custom-transformer name="arrayGenerator" class="pkg.ArrayGenerator"/>
<custom-transformer name="objectExtractor" class="pkg.ObjectExtractor"/>
<custom-transformer name="faultChecker" class="pkg.FaultChecker"/>
<custom-transformer name="objectLogging" class="pkg.ObjectLogger">
<pattern:web-service-proxy
name="1Proxy"
inboundEndpoint-ref="vm1In"
transformer-refs="arrayGenerator objectLogging"
responseTransformer-refs="objectLogging objectExtractor faultChecker"
outboundEndpoint-ref="vm1Out" />
<flow name="logService">
<vm:inbound-endpoint path="vm.logService exchange-pattern="request-response"/>
<custom-transformer class="Test1"/>
<vm:outbound-endpoint ref="vm1In">
<cxf:jaxws-client
serviceClass="pkg.ServiceImpl"
operation="import"
enableMuleSoapHeaders="false"/>
<object-to-string-transformer/>
</vm:outbound-endpoint>
<object-to-xml-transformer>
<xm:xml-to-object-transformer returnClass="pkg.WSResponseClass"/>
<custom-transformer class="Test2"/>
</flow>
<flow name="DispatcherToServiceFlow">
<custom-transformer class="Test3"/>
<vm:inbound-endpoint path="vm1.Out"/>
<custom-transformer class="pkg.Dispatcher">
<spring:property name="vmFlowPath" value="vm.import"/>
</custom-transformer>
</flow>
<flow name="import">
<vm:inbound-endpoint path="vm.import" exchange-pattern="request-response"/>
<http:outbound-endpoint address="${importService}" responseTimeout="${timeout}" exchange-pattern="request-response" />
<object-to-string-transformer/>
<custom-transformer class="Test4"/>
</flow>
well, my problem really was the "path" element instead of referring to an existing vm endpoint with "ref" element like
<inbound-endpoint ref="vm1Out"/>
I am relatively new to mule and trying to define a mule flow which takes request XML via soap-based Web service. The XML is based on a complex schema and I have generated classes using WSDL2Java
After receiving the request cxf:jaxws-service executes the method submitOrder(SubmitOrderRequest parameters). After this method's execution I would like to transform the request XML to a little bit different format. Then this XML needs to be forwarded to another web service. The problem is that the mule message that comes out of ServiceImpl contains SubmitOrderResponse whereas I still want to work on SubmitOrderRequest.
<flow name="testService">
<http:inbound-endpoint address="http://localhost:62005/test"
exchange-pattern="request-response">
<cxf:jaxws-service serviceClass="com.test.ServicePortType" />
</http:inbound-endpoint>
<component class="com.test.ServiceImpl" />
<!-- transformer ref="MVIRequestTransformer" / -->
<!-- xm:object-to-xml-transformer / -->
<!-- logger message="XML payload is #[payload]" level="INFO" / -->
<!-- SEND TRASNFORMED MESSAGE TO ANOTHER SERVICE -->
</flow>
#WebService(endpointInterface = "com.pennmutual.services.mvi.MVIServicePort")
public class ServiceImpl implements ServicePortType {
...
#Override
public SubmitOrderResponse submitOrder(SubmitOrderRequest parameters) {
...
}
...
}
What are my options are. I can think of the following –
1. Put the request object somewhere in the context and retreive it later on for processing.
2. Change the return type of submitOrder to Object and return SubmitOrderRequest instead of SubmitOrderResponse.
Please suggest the best possible way to handle this situation. I am using mule 3.2.
I think there are two elegant way to do that (excluding the one that involves changing the webservice interface)
Store the request into a session variable and restore it afterwards.
Here is how your flow would look like:
<flow name="testService">
<http:inbound-endpoint address="http://localhost:62005/test" exchange-pattern="request-response">
<cxf:jaxws-service serviceClass="com.test.ServicePortType" />
</http:inbound-endpoint>
<message-properties-transformer scope="session">
<add-message-property value="payload" key="originalPayload" />
</message-properties-transformer>
<component class="com.test.ServiceImpl" />
</flow>
Use the enricher around the component to store the returned value into a variable so that it won't become the payload of your flow. Following an example of how to achieve this
<flow name="Echo" doc:name="Echo">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="6090" path="echo" encoding="UTF-8" />
<cxf:jaxws-service serviceClass="org.mule.example.echo.Echo" />
<enricher target="#[variable:echo]">
<component class="org.mule.example.echo.Echo" />
</enricher>
<logger level="ERROR" message="#[variable:echo]"/>
</flow>
You can find more informations on the enricher here