Sending an simple E-mail using WSO2 ESB - java

I am trying to send an e-mail to a specific address using WSO2 ESB.
I configured my axis2.xml by applying following settings to mailto transport sender.
<transportSender name="mailto" class="org.apache.axis2.transport.mail.MailTransportSender">
<parameter name="mail.smtp.host">smtp.gmail.com</parameter>
<parameter name="mail.smtp.port">587</parameter>
<parameter name="mail.smtp.starttls.enable">true</parameter>
<parameter name="mail.smtp.auth">true</parameter>
<parameter name="mail.smtp.user">myusername#gmail.com</parameter>
<parameter name="mail.smtp.password">mypassword</parameter>
<parameter name="mail.smtp.from">myusername#gmail.com</parameter>
</transportSender>
This is my fragment of the sequence which is responsible for sending mail.
<log level="custom">
<property name="Mail status" value="===============enter the mail============="/>
</log>
<property name="messageType" value="text/html" scope="axis2"/>
<property name="ContentType" value="text/html" scope="axis2"/>
<property name="Subject" value="File Received" scope="transport"/>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<log level="full"/>
<send>
<endpoint>
<address uri="mailto:myreciveemail#gmail.com"/>
</endpoint>
</send>
<log level="custom">
<property name="flag" value="=====After======="/>
</log>
I am pretty much sure that other parts of my proxy service are working just fine.
But the problem is when I triggered the proxy service, it is going through all parts of the sequence without throwing an error but not sending the mail
This is my console output relevant to the fragment of sequence I stated earlier.
[2013-01-29 17:07:15,552] INFO - LogMediator Mail status = ===============enter
the mail=============
[2013-01-29 17:07:15,552] INFO - LogMediator To: , WSAction: urn:mediate, SOAPA
ction: urn:mediate, MessageID: urn:uuid:a12fd64c-f5c5-4b22-b092-e15af960a3d2, Di
rection: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envel
ope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body>
<geo:getZipCode xmlns:geo="http://geo.wso2">
<geo:longitude>1</geo:longitude>
<geo:latitude>3</geo:latitude>
</geo:getZipCode>
</soapenv:Body></soapenv:Envelope>
[2013-01-29 17:07:15,567] INFO - LogMediator flag = =====After=======
Guys please any one knows what's the issue is????

Try to use
<parameter name="mail.smtp.user">myusername</parameter>
without #gmail.com

For those of you who are trying to send an email using the configuration stated in the question via wso2 esb, apart from all that you will need to include a axis2-transport-mail-1.0.0.jar under wso2esb-5.0.0\repository\axis2\client\lib. This jar contains the classes necessary for axis2 to send out an email. Hope this helps someone.

Related

How to get the file from service-activator Message object in listener class

I need to pass the file to service layer which i am receiving in SFTP path.
below is configuration and i am seeing the message receiving in my service-activator like
GenericMessage [payload=com.jcraft.jsch.ChannelSftp$2#322906a2,
headers={closableResource=org.springframework.integration.sftp.session.SftpSession#379662a7,
id=704c58e7-1d93-3bef-0330-233c0f9af55c, file_remoteDirectory=/tmp/charge/,
file_remoteFile=Charge.txt, timestamp=1594158522576}]
<bean id="sftpSessionFactory"
class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
<property name="host" value="hostname"/>
<property name="port" value="22"/>
<property name="user" value="vkp"/>
<property name="password" value="1234"/>
<property name="allowUnknownKeys" value="true"/>
</bean>
<int-sftp:inbound-streaming-channel-adapter id="sftpAdapterAutoCreate"
session-factory="sftpSessionFactory"
filename-pattern="*.txt"
channel="receiveChannel"
remote-directory="/tmp/charge/">
</int-sftp:inbound-streaming-channel-adapter>
<int:poller fixed-rate="25000" max-messages-per-poll="1" id="shippingChargePoller" default="true"/>
<int:channel id="receiveChannel">
<int:queue/>
</int:channel>
<int:stream-transformer id="withCharset" charset="UTF-8" input-
channel="receiveChannel" />
<int:service-activator id="FeedListener" input-channel="receiveChannel" method="onMessage">
<bean class="com.listener.ChargeFeedListener"/>
</int:service-activator>
public void onMessage(Message<?> message){
System.out.println(message.toString());
System.out.println( " Received File is "+message.getPayload());
}
But i am not receiving the file in my java class . What i need to do to get the file ?
Please, read documentation: https://docs.spring.io/spring-integration/docs/current/reference/html/sftp.html#sftp-streaming. The <int-sftp:inbound-streaming-channel-adapter> is not about files. It does open an InputStream for a remote entry (probably file on SFTP) and let you to do with this stream whatever you want. For example (also according that docs), there is a StreamTransformer which let's you to read that stream into a byte[] or string if you provide a charset. If you really want to deal with files, then you need to consider to switch to the <int-sftp:inbound-channel-adapter>. That one pull the remote entry and store its content into a local file. Then that java.io.File is sent to the channel for your consideration.
I think we had a chat with you on the matter in other your question: Spring SFTP Integration is not polling the file.
Please, let us know what is wrong with our docs that confuses you so you have to raise questions like this over here.

WSO2 EI - RelayUtils Error while building Passthrough stream

I'm using WSO2 EI 6.3.0 and i want to get data from specific webservice and push this data to an other webservice.
In the first time, i have to get the JWT Token from a first webservice to put it in the second call to get data.
So, i created several sequence to have reusable sequences.
I have the error when i want to inject bearer token header into my endpoint to get data.
STEP OF IN SEQUENCE
During the LogincheckSeq, i call the login_check api to get the JWT Token.
Then during the createBearerTokenSeq, i only create a property with the token recovered from LoginCheckSeq
Then we pass in the CreateBearerTokenSeq, to create a property with the token recovered before from the json response of the LoginCheckEP
Finally, we pass in the last sequence GetCustomerSeq to get customers informations from the webservice in json thanks to the jwt token given in the header (Authorization: Bearer token)
This is my CustomerAPI.xml :
<?xml version="1.0" encoding="UTF-8"?>
<api context="/customers" name="CustomersAPI"
xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST GET" uri-template="/">
<inSequence>
<log level="custom" separator="
">
<property name="API CUSTOMER" value="START"/>
</log>
<sequence key="LoginCheckSeq"/>
<sequence key="CreateBearerTokenSeq"/>
<sequence key="GetCustomersSeq"/>
</inSequence>
<outSequence>
<log>
<property expression="$axis2:HTTP_SC" name="Status Code" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
</outSequence>
<faultSequence>
<log level="full"/>
</faultSequence>
</resource>
</api>
LoginCheckSeq.xml
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="LoginCheckSeq" trace="disable"
xmlns="http://ws.apache.org/ns/synapse">
<log level="custom" separator="
">
<property name="Login SEQUENCE" value="START"/>
</log>
<property expression="json-eval($.username)" name="uri.var.username" scope="default" type="STRING"/>
<property expression="json-eval($.password)" name="uri.var.password" scope="default" type="STRING"/>
<log level="custom" separator=",">
<property expression="fn:concat('Username : ', get-property('uri.var.username'), ' / Password : ',get-property('uri.var.password')) " name="PARAMS"/>
</log>
<call>
<endpoint key="LoginCheckEP"/>
</call>
</sequence>
CreateBearerToken.xml
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="CreateBearerTokenSeq" trace="disable"
xmlns="http://ws.apache.org/ns/synapse">
<log level="custom" separator="
">
<property name="Create Bearer Token SEQUENCE" value="START"/>
</log>
<payloadFactory media-type="json">
<format>{"token":"$1"}</format>
<args>
<arg evaluator="json" expression="$.token"/>
</args>
</payloadFactory>
<property name="messageType" value="application/json" scope="axis2"/>
<property expression="json-eval($.token)" name="uri.var.jwt.token" scope="default" type="STRING"/>
</sequence>
GetCustomerSeq.xml
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="GetCustomersSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log description="" level="custom" separator="
">
<property name="Get Customer SEQUENCE" value="START"/>
</log>
<log description="" level="custom" separator="##">
<property expression="fn:concat('Bearer ', get-property('uri.var.jwt.token'))" name="JWT Token Created"/>
</log>
<header name="Authorization" expression="fn:concat('Bearer ', get-property('uri.var.jwt.token'))" scope="transport"/>
<send>
<endpoint key="GetCustomersEP"/>
</send>
</sequence>
I get well the JWT Token from LoginCechkSeq but i have an error in the getCustomerSeq.
This is the error :
[2018-08-14 15:14:07,510] [EI-Core] INFO - LogMediator API CUSTOMER = START
[2018-08-14 15:14:07,511] [EI-Core] INFO - LogMediator Login SEQUENCE = START
[2018-08-14 15:14:07,511] [EI-Core] INFO - LogMediator PARAMS = Username : test#test.fr / Password : Azerty123
[2018-08-14 15:14:08,586] [EI-Core] INFO - LogMediator Create Bearer Token SEQUENCE = START
[2018-08-14 15:14:08,591] [EI-Core] INFO - LogMediator Get Customer SEQUENCE = START
[2018-08-14 15:14:08,591] [EI-Core] INFO - LogMediator JWT Token Created = Bearer eyJhbGciOiJSUzI1NiJ9.eyJyb2xlcyI6WyJST0xFX1VTRVJfTUFUT09NQSIsIlJPTEVfVVNFUiJdLCJ1c2VybmFtZSI6InRlc3RAdGVzdC5mciIsImZpcnN0TmFtZSI6I kxvXHUwMGVmYyIsImxhc3ROYW1lIjoiQ2FyaW91IiwiaWQiOjIwLCJpYXQiOjE1MzQyNTI0NDgsImV4cCI6MTUzNDI2Njg0OH0.Gx_cSwXE0rm1EZSPeI64cbOdysjXcLwj2NYjtNE4eh_gtUSwbCE2EUPL6sB-Rt_ayQOeOEx-w07Bkbh-Rr6rUd-mqnKXHuUCe76pOXWWW5ejV7k8n_ Tf3gk4upbzn77VMsyNALWJYNBSO4S8dDCyp413SRvnRaKuhkF1GgvkbZx7aJNUwkDA_ZuxG3IfOKQdao7GgDhWH9pltH9zIjXtjagbjRPgBaekcZiB2bxglQLF7RUMky2MVG_WEbcLFms14LiIEooG3lXao73Z2foYXSMxReHHAmhGPfSipw_wA9ohMolB_X5Ck13O0tSDUvsqvqdZHPZ w8ITmn_4pKnJhTiCK6U58Ub_Nr6Royeiwf3_WN7ooqOczF0hbJr7ZFONo3BwKEhCj6gPv9gknK0ahSotnsRvQS56VsquWJm9ZwtXAI2D0J8tNjSmxMP9FWbmFMWap2wOayUEGpauYD3WA5W-CZexqulJTbLSPcMF92QWaKMoVtL5blgGt9vTb1YIVnQi4KALK9psJETgcvHCIbfsN E_IcYMlotIHRuO4RR-j0I7WAxQVko9YNkIRpuDUftpUq95TbIxn5NeTFhWL_NoC2F3jO4khGYR-Hk2P2ZudygrrdmDMfezn7d5yArV7mlukSB6chwq38T261ktzqx_G_rHt1pjt0jXVhz1DPsY4
[2018-08-14 15:14:10,087] [EI-Core] ERROR - RelayUtils Error while building Passthrough stream
org.apache.axiom.om.OMException: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '{' (code 123) in prolog; expected '<'
at [row,col {unknown-source}]: [1,1]
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:296)
at org.apache.axiom.om.impl.llom.OMDocumentImpl.getOMDocumentElement(OMDocumentImpl.java:109)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.getDocumentElement(StAXOMBuilder.java:570)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.getDocumentElement(StAXOMBuilder.java:566)
at org.apache.synapse.transport.passthru.util.DeferredMessageBuilder.getDocument(DeferredMessageBuilder.java:165)
at org.apache.synapse.transport.passthru.util.RelayUtils.builldMessage(RelayUtils.java:163)
at org.apache.synapse.transport.passthru.util.RelayUtils.buildMessage(RelayUtils.java:116)
at org.apache.synapse.mediators.AbstractListMediator.buildMessage(AbstractListMediator.java:145)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:94)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:70)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.rest.Resource.process(Resource.java:351)
at org.apache.synapse.rest.API.process(API.java:338)
at org.apache.synapse.rest.RESTRequestHandler.apiProcess(RESTRequestHandler.java:123)
at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:101)
at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:56)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:303)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:570)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:193)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:263)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '{' (code 123) in prolog; expected '<'
at [row,col {unknown-source}]: [1,1]
at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java:639)
at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2052)
at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1134)
at org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper.next(XMLStreamReaderWrapper.java:225)
at org.apache.axiom.util.stax.dialect.DisallowDoctypeDeclStreamReaderWrapper.next(DisallowDoctypeDeclStreamReaderWrapper.java:34)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.parserNext(StAXOMBuilder.java:681)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:214)
... 24 more
I tried several thing like add this line :
<messageBuilder contentType="application/json" class="org.wso2.carbon.integrator.core.json.JsonStreamBuilder"/>
Or add property with name "messageType" with value "application/json"
But nothing resolve my problem...
If someone has already encountered this problem, I'm taking the solution =)
I found the response.
The Content-Type of the server response is : application/ld+json.
So WSO2 didn't recognize the encoding.
I just added this line into the axis2.xml :
<messageFormatter contentType="application/ld+json" class="org.wso2.carbon.integrator.core.json.JsonStreamFormatter"/>
....
<messageBuilder contentType="application/ld+json"
class="org.wso2.carbon.integrator.core.json.JsonStreamBuilder"/>
And it's work fine ! =)

Migrating from service-mix file poller to apache camel file poller

I am new to apache camel. I want to migrate from service mix file poller to camel file poller. I am trying to do it, but currently I have nothing to test as I have to code this and give someone for testing. So can someone help me and check whether I am going in right way?
Service-mix File Poller code:
<sm:activationSpec componentName="abcFilePoller"
destinationService="b:destinationA"
service="b:abcFilePoller">
<sm:component>
<bean class="org.apache.servicemix.components.file.FilePoller">
<property name="file" value="file://D:/input" />
<property name="period" value="20000"/>
<property name="archive" value="file://D:/archive" />
<property name="filter" ref="abcFileFilter" />
<property name="marshaler">
<bean class="org.apache.servicemix.components.util.BinaryFileMarshaler" />
</property>
</bean>
</sm:component>
</sm:activationSpec>
<sm:activationSpec componentName="destinationA"
service="b:destinationA">
<sm:component>
<bean
class="com.abc.file.ABCReceiverComponent">
</bean>
</sm:component>
</sm:activationSpec>
<bean id="abcFileFilter" class="org.apache.commons.io.filefilter.WildcardFileFilter">
<constructor-arg value="A*.ID" />
Apache Camel File Poller
<camel:route id="abcFilePoller">
<camel:from
uri="timer://time?period=20000"/>
<camel:pollEnrich uri="file://D:/input"/>
<camel:filter ref="abcFileFilter"></camel:filter>
<camel:to uri="file://D:/archive" />
<camel:to uri="" />
</camel:route>
<bean id="abcFileFilter" class="org.apache.commons.io.filefilter.WildcardFileFilter">
<constructor-arg value="A*.ID" />
</bean>
I have not completed the camel coding. I have left with destination part. And I have no idea about the marshaler that is used in the service-mix part. How to implement that BinaryFileMarshaler using camel.
You can do this even easier in Apache Camel where you can configure the filtering in the file endpoint, so it just becomes
<route>
<from uri="file:D:/input?delay=20000&include=A.*ID"/>
<to uri="file:D:/archive"/>
</route>
Just mind that the include option uses a regular expression, so if you are not familiar with that it can take a bit tries to get the expression to work as expected. But its standard java regular expressions.
See more at: https://camel.apache.org/components/latest/file-component.html
And for new users to Apache Camel then see: http://java.dzone.com/articles/open-source-integration-apache

SOAP KeyInfo failed to recognise by IIS Server and client is java

I am getting following error while consuming .Net Web Service from java Spring
Web Service uses Certificate based authentication.
I tried java(Server) to java(Client) working locally using HTTPS and without https
Even .Net Side Server and client working.
org.springframework.ws.soap.client.SoapFaultClientException: Referenced security token could not be retrieved --->
WSE590: Failed to resolve the following Key Info
<KeyInfo Id="KI-A65A1CE3CB2EB7AE6114286591136763" xmlns="http://www.w3.org/2000/09/xmldsig#">
<wsse:SecurityTokenReference xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<ds:X509Data xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:X509IssuerSerial>
<ds:X509IssuerName>CN=VXX,OU=NXX,O=iXXX,L=Cty,ST=MH,C=IN</ds:X509IssuerName>
<ds:X509SerialNumber>1711043036</ds:X509SerialNumber>
</ds:X509IssuerSerial>
</ds:X509Data>
</wsse:SecurityTokenReference>
</KeyInfo>.
I am using org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor
to intercept request and response.
I don't understand whats happening at .Net side as its developed by other team.
But .Net Team told request is not reached to applcation, IIS server itself not able to process this.
Please find .Net client calling code snippet.
// TODO: Replace with a valid path to your certificate
string certPath = #"C:\mypath\certClient1.cer";
Secured.TSRService objsecserv = new Secured.TSRService();
objsecserv.Url = #"https://xyz/service.asmx";
//objsecserv.Url = #"http://xyz:97/service.asmx";
objsecserv.ClientCertificates.Add(X509Certificate.CreateFromCertFile(certPath));
objsecserv.Timeout = Timeout.Infinite;
string strresult1 = objsecserv.GetCertDetails();
rtxtresult.Text = strresult1;
And Here is my java side code snippet
<bean id="countryWsClSecInterId" class="org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor">
<property name="securementActions" value="Timestamp Signature" /> <!-- Encrypt -->
<!-- Key alias for signature -->
<property name="securementUsername" value="client" />
<property name="securementPassword" value="mypasswd" />
<property name="securementSignatureCrypto" ref="countryCrypto"/>
<property name="securementEncryptionCrypto" ref="countryCrypto"/>
<!-- Key alias for encryption -->
<property name="securementEncryptionUser" value="server"/>
<!-- Validation config -->
<property name="validationActions" value="Signature" />
<property name="validationSignatureCrypto" ref="countryCrypto"/>
</bean>
Please guide me , I searched a lot and made changes according but nothing worked.

How to configure JBoss/JMS message rate limit / flow control

I've got a fast producer ESB (converts CSV to XML) and a slow consumer ESB (performing zip/base64/SOAP wrapping of the XML). The ESBs communicate via a JMS topic. This design is legacy and cannot be changed. When a large CSV file is processed, JBoss AS (5.2) grinds to a halt as the producer is flooding out the consumer, this is even with a heap-size of 4096M. Forgive me I'm new to JBoss/JMS and finding it all bewildering.
Producer sending config
<action class="com.example.FooAction" name="ProcessFoo">
<property name="springJndiLocation" value="FooEsbSpring" />
<property name="exceptionMethod" value="exceptionHandler" />
<property name="okMethod" value="processSuccess" />
<property name="jndiName" value="topic/FooTopic" />
<property name="connection-factory" value="ConnectionFactory" />
<property name="unwrap" value="true" />
<property name="security-principal" value="guest" />
<property name="security-credential" value="guest" />
</action>
Producer sending code:
Message msg = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
msg.getBody().add(foo); // foo is the business specific message
new JMSRouter(config).process(msg);
Consumer receiving config:
<jms-jca-provider connection-factory="ConnectionFactory" name="FooMessaging">
<jms-bus busid="fooChannel">
<jms-message-filter dest-name="topic/FooTopic"
dest-type="TOPIC" transacted="false" />
</jms-bus>
<activation-config>
<property name="dLQMaxResent" value="1" />
</activation-config>
</jms-jca-provider>
Topic config
<server>
<mbean code="org.jboss.jms.server.destination.TopicService"
name="jboss.esb.quickstart.destination:service=Topic,name=FooTopic"
xmbean-dd="xmdesc/Queue-xmbean.xml">
<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer
</depends>
<depends>jboss.messaging:service=PostOffice</depends>
</mbean>
</server>
Things I've tried so far.
Run the publisher ESB without the consumer ESB - as expected no problems.
Lots of googling, looking for existing questions on stackoverflow
Found some references to rate limiting but I can't see how to fit these into my config.
I've tried to find an API to discover how many messages are already on the topic unprocessed (with the hope I can implement my own back-off strategy).
Looked at this documentation.
Look at this section 6.3.17.2. org.jboss.mq.server.jmx.Topic and use the 'Depth' related attributes using JMX.
It might help you build the back-off strategy you're looking for

Categories

Resources