Restore task class in WSO2 ESB - class

When i use a task in WSO2 ESB it always returns the same error with every web service:
"Unable to handle request. The action '(mySoapAction)' was not recognized"
where (mySoapAction) is every SOAP action used, for EVERY action, for EVERY proxy service i use for task implementation.
What could i do in order to fix this error? I thought a task class error in org.apache.synapse.startup.tasks.MessageInjector.
Obvoiusly the task implementation is correct, because the same tasks some day ago were perfectly working. Suggestions?

Here come a sample with the weather webservice (http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL)
Proxy service :
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="TestSOF"
transports="https http"
startOnLoad="true"
trace="disable">
<target>
<endpoint>
<wsdl service="Weather"
port="WeatherSoap12"
uri="http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL"/>
</endpoint>
<outSequence>
<log level="full"/>
<property name="OUT_ONLY" value="true"/>
<property name="transport.vfs.ReplyFileName" value="weather.xml" scope="transport"/>
<send>
<endpoint>
<address uri="vfs:file:///E:/temp"/>
</endpoint>
</send>
</outSequence>
</target>
<publishWSDL uri="http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL"/>
</proxy>
Task :
<?xml version="1.0" encoding="UTF-8"?>
<task xmlns="http://ws.apache.org/ns/synapse"
name="TestSOFTask"
class="org.apache.synapse.startup.tasks.MessageInjector"
group="synapse.simple.quartz">
<trigger count="1" interval="1"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
name="proxyName"
value="TestSOF"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
name="soapAction"
value="http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks" name="message">
<weat:GetCityWeatherByZIP xmlns:weat="http://ws.cdyne.com/WeatherWS/">
<weat:ZIP>11010</weat:ZIP>
</weat:GetCityWeatherByZIP>
</property>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
name="format"
value="soap12"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
name="injectTo"
value="proxy"/>
</task>
Schedule the task and you will find the service response in a file name weather.xml
If you want to change from soap12 to soap11 :
Change the value of property "format" in the task def to : soap11
Change the endpoint def in the proxy service using port "WeatherSoap" rather than "WeatherSoap12"
Hope it will help you to find what is going wrong with your conf...

Related

Error when sending Email in WSO2 ESB

I send Mail with WSO2 ESB 5.0.0
1. I have uncommented the following line in Axis2.xml file
<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">lmphuong</parameter>
<parameter name="mail.smtp.password">password</parameter>
<parameter name="mail.smtp.from">lmphuong#gmail.com</parameter>
</transportSender>
<transportReceiver name="mailto" class="org.apache.axis2.transport.mail.MailTransportListener">
<!-- configure any optional POP3/IMAP properties
check com.sun.mail.pop3 and com.sun.mail.imap package documentation for more details-->
</transportReceiver>
2. Add content at messageFormatters in axis2.xml
<messageFormatter contentType="text/html" class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/>
3. I have create Proxy Service in WSO2 ESB
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="EmailSender"
transports="http https"
startOnLoad="true">
<description/>
<target>
<inSequence>
<log/>
<property name="messageType"
value="text/html"
scope="axis2"
type="STRING"/>
<property name="ContentType" value="text/html" scope="axis2"/>
<property name="Subject" value="Testing ESB" scope="transport"/>
<property name="OUT_ONLY" value="true"/>
<property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
<payloadFactory media-type="xml">
<format>
<ns:text xmlns:ns="http://ws.apache.org/commons/ns/payload">$1</ns:text>
</format>
<args>
<arg value="Hello WSO2 ESB.....!"/>
</args>
</payloadFactory>
<log level="full"/>
<send>
<endpoint>
<address uri="mailto:ledung123#gmail.com"/>
</endpoint>
</send>
</inSequence>
<outSequence/>
</target>
</proxy>
4. I recieved error
ERROR - MailTransportSender Error creating mail message or sending it to the configured server
javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:306)
...
[2017-09-15 08:04:05,945] ERROR - MailTransportSender Error generating mail message
...
Please help me out how to soved this error
Looks like thereĀ“s something wrong with your credentials (AuthenticationFailedException). Do you have any special chracters in your credentials? Or is there are proxy server between esb and gmail?
What you could do is start esb in debug/enable wire log to see the complete traffic. More info can be found here.
https://docs.wso2.com/display/ESB500/Debugging+Mediation#DebuggingMediation-Viewingwirelogs
Another option might be to use the GMail connector which can be found here.
https://docs.wso2.com/display/ESBCONNECTORS/Gmail+Connector
https://store.wso2.com/store/pages/top-assets?q=%22_default%22%3A%22gmail%22

WSO2 REST to SOAP passing operation parameters

Using WSO2 ESB 4.8.1, I have configured a WSDL proxy that I want to access over REST. the proxy points to the SOAP WSDL URI and has publish WSDL turned on. This seem to work fine and I can see the service and its various operations in the WSO2 admin UI. Likewise if I go to localhost:8280/services/
The questions is how do I pass operation specific parameters when accessing over HTTP REST?
Let's say my FooService OperationX expects a "p1" parameter, can I pass this directly when accessing localhost:8280/services/FooService/OperationX in a browser?
I tried for example localhost:8280/services/FooService/SomeOperation?p1=somevalue, but always get a validation error that the required parameter is missing:
cvc-complex-type.2.4.b: The content of element 'axis2ns15:OperationXRequest' is not complete. One of '{"somenamespace":p1}' is expected.
Can this be supported by a basic WSDL proxy? Or do I need to use the API?
I think the better option for your scenario is to use api to access over REST. Here I have created an api (I used http://jsonplaceholder.typicode.com/comments as my REST back end) which gets the query parameter(postId) which was sent in REST request (http://172.22.99.96:8290/test/comments?postId=1) and assign that value to a property called mypostId inside the api.
Then I am modifying the payload by adding the mypostId property using payload factory mediator which will match to the echo service request(I have used echo service as the SOAP backend).
Then I use enrich mediator to change my soap envelope to match the echo service request soap envelope by adding "xmlns:echo="http://echo.services.core.carbon.wso2.org"" name space. Finally I am sending my created request to echo service proxy.
<api xmlns="http://ws.apache.org/ns/synapse" name="test" context="/test">
<resource methods="GET" uri-template="/comments?postId={postId}">
<inSequence>
<log level="custom">
<property name="Message Flow" value="--- Order GET ---"></property>
</log>
<log level="custom">
<property name="postId" expression="$url:postId"></property>
</log>
<property name="mypostId" expression="$url:postId"></property>
<call>
<endpoint>
<http method="GET" uri-template="http://jsonplaceholder.typicode.com/comments?postId={uri.var.postId}"></http>
</endpoint>
</call>
<payloadFactory media-type="xml">
<format>
<echo:echoInt xmlns:echo="http://echo.services.core.carbon.wso2.org">
<in>$1</in>
</echo:echoInt>
</format>
<args>
<arg evaluator="xml" expression="get-property('mypostId')"></arg>
</args>
</payloadFactory>
<log level="full"></log>
<log level="custom">
<property name="Message Flow" value="--- After Palyload factory---"></property>
</log>
<property name="extarctedBody" expression="$body"></property>
<log level="custom">
<property name="MyextarctedBody" expression="get-property('extarctedBody')"></property>
</log>
<log level="full"></log>
<enrich>
<source type="inline" clone="true">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:echo="http://echo.services.core.carbon.wso2.org"></soapenv:Envelope>
</source>
<target type="envelope"></target>
</enrich>
<log level="custom">
<property name="Message Flow" value="--- Order GET2 ---"></property>
</log>
<log level="full"></log>
<enrich>
<source type="property" clone="true" property="extarctedBody"></source>
<target xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:echo="http://echo.services.core.carbon.wso2.org" action="child" xpath="//soapenv:Envelope"></target>
</enrich>
<log level="full"></log>
<send>
<endpoint>
<address uri="http://localhost:8290/services/echo"></address>
</endpoint>
</send>
</inSequence>
<outSequence>
<send></send>
</outSequence>
</resource>
</api>
Hope this may help you .

WSO2 ESB How to send an email from a JMS message to a custom email address?

I'm wondering if someone can help me with the following setup.
I want to send a message from my application via JMS to WSO2 ESB so the ESB can send it as en email. I'm using ActiveMQ as queue. Until now, when I send a message via the ActiveMQ interface to the queue, wso2 esb gets it. Then, wso2 esb send the message as email to a specific email address.
So I could configure ActiveMQ and WSO2 esb to send the JMS message to a specific email address (eg. specificaddress#test.com).
And here is my question. How can I modify the receiver address for the email? In the ESB sequence configuration, I currently use a specific address. But the address is dependant on the user that uses my application. So I have to change the "To" property, dependant on the user that has to receive the email.
So how can I pass the values for the properties "To", but also for "Subject", through a JMS message to WSO2 esb sequence?
That's the configuration of the sequence I have:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="sendMail">
<property name="messageType" value="text/html" scope="axis2" type="STRING"></property>
<property name="ContentType" value="text/html" scope="axis2"></property>
<property name="Subject" value="This is the subject." scope="transport"></property>
<property name="To" value="specificaddress#test.com" scope="transport"></property>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"></property>
<log level="full"></log>
<send>
<endpoint>
<address uri="mailto:"></address>
</endpoint>
</send>
</sequence>
And this is my proxy:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="sendToMailIn"
transports="jms"
statistics="disable"
trace="disable"
startOnLoad="true">
<target inSequence="sendMail"/>
<description/>
</proxy>
I hope someone has a clue.
UPDATE
I think I have the solution!!! Wow :-) Maybe, at first, I was stupid, but here it is ...
What you can do is sending a SOAP envelop through a JMS message to WSO2 ESB. And then, with an XPath expression, you can get the passed values. A little bit has to changed at the proxy and the sequence.
This is the new sequence:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="sendMail">
<property name="messageType" value="text/html" scope="axis2" type="STRING"></property>
<property name="ContentType" value="text/html" scope="axis2"></property>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Subject" expression="$body/subject" scope="transport"></property>
<property xmlns:ns="http://org.apache.synapse/xsd" name="To" expression="$body/to" scope="transport"></property>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"></property>
<log level="full"></log>
<send>
<endpoint>
<address uri="mailto:"></address>
</endpoint>
</send>
</sequence>
And this is the new proxy:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="sendToMailIn"
transports="jms"
statistics="disable"
trace="disable"
startOnLoad="true">
<target inSequence="sendMail"/>
<parameter name="transport.jms.ContentType">
<rules>
<jmsProperty>contentType</jmsProperty>
<default>text/xml</default>
</rules>
</parameter>
<description/>
</proxy>
And this was my SOAP Envelop that WSO2 ESB receives from my ActiMQ queue as JMS message:
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org /soap/envelope/">
<soapenv:Body>
<subject>Email subject comes here.</subject>
<to>address#test.com</to>
</soapenv:Body>
</soapenv:Envelope>
you have couple of options here.
you can use http headers and send the "to", "subject" values to ESB.
Send it as a payload value and extract using XPath expression
I solved it with using JSON in a JMS message. Here is my setup that works for me.
This is my JSON message:
{"to":"mail#test.com","subject":"TestSubject","mailbody":"Some body text ..."}
This is my proxy:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="sendToMailIn"
transports="jms"
statistics="disable"
trace="disable"
startOnLoad="true">
<target inSequence="sendMail"/>
<parameter name="transport.jms.ContentType">
<rules>
<jmsProperty>contentType</jmsProperty>
<default>application/json</default>
</rules>
</parameter>
<parameter name="transport.mail.ContentType">application/xml</parameter>
<description/>
</proxy>
And this is my sequence:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="sendMail">
<property name="messageType" value="text/plain" scope="axis2" type="STRING"></property>
<property name="ContentType" value="text/plain" scope="axis2"></property>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Subject" expression="json-eval($.subject)" scope="transport"></property>
<property xmlns:ns="http://org.apache.synapse/xsd" name="To" expression="json-eval($.to)" scope="transport"></property>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"></property>
<script language="js">
<![CDATA[var mailbody = mc.getPayloadJSON().mailbody.toString(); mc.setPayloadXML(
<ns:text xmlns:ns="http://ws.apache.org/commons/ns/payload">{mailbody}</ns:text>);]]>
</script>
<log level="full"></log>
<send>
<endpoint>
<address uri="mailto:"></address>
</endpoint>
</send>
</sequence>

WSO2 esb: how to proxy REST service with numeric operation name

We are trying to implement basic SOAP-to-REST proxy service on WSO2 ESB. Our 3rd-party REST service accepts the requests in the following format:
http://<MYURL>/simpleQuery/16783484?oslc.select=value1
The problem is that operation name has numeric only format - "16783484" in our case. payloadFactory mediator does not allow having <16783484> as XML element, since XML spec restricts numeric-only element names.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="CQProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<payloadFactory>
<format>
<16783484>
<oslc.select>$1</oslc.select>
</16783484>
</format>
<args>
<arg value="myvalue1"/>
</args>
</payloadFactory>
<send>
<endpoint>
<address uri="http://<MYURL>/simpleQuery" format="get"/>
</endpoint>
</send>
<drop/>
</inSequence>
<outSequence>
<log level="full"/>
<send/>
</outSequence>
</target>
</proxy>
How can this be overcome?
Appreciate your help!
WSO2 support team suggested the following solution. Thank you Sandapa!
In that case, you have to set endpoint format as 'rest'. And if it's a GET request you have to set 'HTTP_METHOD' as as GET. Please refer the example given below.
Example:
<proxy xmlns="http://ws.apache.org/ns/synapse" name="CQProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="REST_URL_POSTFIX" value="/getSimpleQuote?symbol=IBM" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
<send>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService/" format="rest"/>
</endpoint>
</send>
<drop/>
</inSequence>
<outSequence>
<log level="full"/>
<send/>
</outSequence>
</target>
<description></description>
</proxy>
Although this comment is not going to suggest you a solution, I can say that this is a bad idea :-) You can try using XSLT instead of PayloadFactory to transform, but again that might choke up the XML parser. Problem is a lot of open source projects/libs that WSO2 products use and you might bump into elsewhere will honour the spec. In the long run, complying to the spec will give you less headaches when you integrate with other external tools/systems. Is it possible to change your rest service so that the service name at least have an underscore in front?

WSO2 ESB mediate SOAP services

I am struggling to make work my message flow in the wso2 esb so I would need some help to implement a basic communication:
Service1 wants to receive an integer number
Service2 Generates random numbers
Service1 has InSequence: log, send (to addresspoint specified). OutSequence: log, send
this looks like:
<proxy name="ClientAskNumber" transports="https http" startOnLoad="true"
trace="disable">
<target faultSequence="fault">
<inSequence>
<log level="full">
<property name="Insequence" value="***" />
</log>
<send>
<endpoint>
<address uri="http://localhost:8280/services/RandomNumbers" />
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full">
<property name="Outsequence" value="***" />
</log>
<send />
</outSequence>
</target>
</proxy>
I have this response: <faultstring>System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: urn:mediate. at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()....etc
What it means? Am I missing something else? Please help. Thank you
EDIT:
I am studying the Wso2 ESB and I just need to understand how to make work a message communication, after it I will try to add different kind of mediation. I am just breaking down the problem, because I am new to this technology and as you can see I am really struggling to make it work...
EDIT2:*
<proxy xmlns="http://ws.apache.org/ns/synapse" name="ClientAskNumber" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target endpoint="RandomNumbers">
<inSequence>
<log>
<property name="CLIENTASKS" value="******C_ASKS" />
</log>
<send>
<endpoint key="RandomNumbers" />
</send>
</inSequence>
<outSequence>
<log>
<property name="CLIENTRECEIVES" value="*******C_RECEIVES" />
</log>
</outSequence>
</target>
</proxy>
In the case this helps someone else: the problem with "Server did not recognize the value of HTTP Header SOAPAction: urn:mediate..." is that I needed to add an Header mediator in order to call my webservice method "getNumbers", into my InSequence as follows:
<inSequence>
<log>
<property name="CLIENTASKS" value="******C_ASKS" />
</log>
<header name="Action" value="http://tempuri.org/getNumbers" />
<send>
<endpoint key="RandomNumbers" />
</send>
</inSequence>
and send this request via soapUI:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Numbers xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope>
I hope this can be useful to other persons who are using .Net Solutions with WSO2ESB (unfortunately there are not many examples out there...)
P.S. thanks to Ratha for his help
This is the flow i can tell you..
You have to point your 2nd service as the endpoint of your fist service..In the above configuration
http://localhost:8280/services/RandomNumbers --->2nd service url
ClientAskNumber -->1st service..
Now you can send the request which is needed to execute the 2nd service(ie:to retrive the random number)
So the proxy will forwrad to that endpoint and return the response to the outsequence..You should see that in the console/log since you used a log mediator.
In the error response you are getting i hope you are getting that from your second service. Check whether you are sending correct request to your endpoint