I am getting error message from mobile app or somewhere any of front end.
I need keep that message in one single text file. That file could be stored in my local system.
How can I do this using WSO2ESB?
<proxy xmlns="http://ws.apache.org/ns/synapse" name="AppendFile" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence onError="fault">
<property name="error_TYPE" expression="//error/text()" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
<payloadFactory>
<format>
<error></error>
</format>
<args>
<arg expression="get-property('error')"/>
</args>
</payloadFactory>
<send>
<endpoint>
<address uri="//home/desktop/append.txt"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<property name="CONTENT_TYPE" value="application/json" scope="axis2"/>
<log level="full"/>
<send/>
</outSequence>
</target>
<description></description>
</proxy>
But its giving transport error.
How can we do this? Please suggest.
You can use VFS transport. Please refer.
http://achala11.blogspot.com/2012/08/vfs-transport-wso2-esb-using-file.html
http://docs.wso2.org/wiki/display/ESB460/VFS+Transport
http://docs.wso2.org/wiki/pages/viewpage.action?pageId=16846489
what is the error you got?
Anyway the endpoint you gave looks wrong. It should start with the transport protocol as vfs://
eg: vfs:file:///home/desktop/append.txt
Related
I have a service which send the email from WSo2 server. But i am getting the message content as attachment and not in body of the email.
You can define the message content for the email body using payload factory mediator as below.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="mailtest"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<send>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<payloadFactory media-type="xml">
<format>
<test xmlns="">$1</test>
</format>
<args>
<arg xmlns:ax21="http://services.samples/xsd"
xmlns:ns="http://services.samples"
evaluator="xml"
expression="//ns:getQuoteResponse/ns:return/ax21:name"/>
</args>
</payloadFactory>
<property name="Subject" scope="transport" value="Sample Mail"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<property name="messageType"
scope="axis2"
type="STRING"
value="text/plain"/>
<property name="OUT_ONLY" value="true"/>
<send>
<endpoint>
<address uri="mailto:yourmail#gmail.com"/>
</endpoint>
</send>
</outSequence>
</target>
<description/>
</proxy>
If you want to define a message body with the email attachment, use "transport.mail.bodyWhenAttached" property.
I have an API of the form
<api xmlns="http://ws.apache.org/ns/synapse" name="MyRestApi" context="/practice">
<resource methods="GET" uri-template="/{someValue}">
<inSequence>
<header name="Action" value="urn:sayHello"/>
<payloadFactory media-type="xml">
<format>
<p:sayHello xmlns:p="http://practice">
<p:inputString>$1</p:inputString>
</p:sayHello>
</format>
<args>
<arg evaluator="xml" expression="$ctx:uri.var.someValue"/>
</args>
</payloadFactory>
<log level="full"/>
<call>
<endpoint>
<address uri="http://192.168.0.105:9763/services/Practice/sayHello" format="soap12"/>
</endpoint>
</call>
<enrich>
<source type="body" clone="true"/>
<target type="property" action="child" property="body_of_first_call"/>
</enrich>
<property xmlns:ns="http://practice" name="response" expression="//ns:return" scope="default" type="STRING"/>
<property xmlns:ns="http://practice" name="response2" expression="//ns:sayHelloResponse" scope="default" type="STRING"/>
<log>
<property name="myValue" expression="$ctx:response"/>
<property name="myValue2" expression="$ctx:response2"/>
<property name="myValue3" expression="$ctx:body_of_first_call"/>
</log>
<payloadFactory media-type="xml">
<format>
<result>
<sentValue>$1</sentValue>
<returnedValue>$2</returnedValue>
</result>
</format>
<args>
<arg evaluator="xml" expression="$ctx:uri.var.someValue"/>
<arg evaluator="xml" expression="$ctx:response"/>
</args>
</payloadFactory>
<property name="messageType" value="application/xml" scope="axis2" type="STRING"/>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
Based almost entirely on a guide found here
It's at this point just an attempt to grasp the concepts of connectors and APIs so I can apply it to what I'm doing at work, but I've hit a snag. Any attempts to communicate with an outside SOAP service, which my ESB will need to do, either fails to find the endpoint or fails to pass on the values in the SOAP envelope.
As written above the code will find the endpoint, but the input value inputString in the request is always null. It's essentially identical to putting that address into your browser which completely omits the SOAP envelope, however logging the call prints the envelope as expected to the console so the envelope is being generated but not making its way to the application server.
Things I have also tried:
1) Changing the endpoint address to be the service endpoint, rather than the specific operation. This causes an error from the AS claiming the operation cannot be found. This endpoint and operation work as expected in SoapUI.
2) Using a WSDL endpoint instead of address. Result is the same as in 1.
3) Adding/removing the header tag. All three endpoints have been tried with/without the header tag. Their results do not change.
At this point I've exhausted my admittedly poor understanding of ESBs.
To invoke my service I set up my mediator this way.
<call blocking="true">
<endpoint>
<address uri="http://169.254.193.10:9769/services/ServicePharmacy" format="soap11"/>
</endpoint>
</call>
the blocking property in true is to do synchronous messaging
<call blocking="true">
</call>
this is my API
<api xmlns="http://ws.apache.org/ns/synapse" name="showByIdCallMediator" context="/getByIdCall">
<resource methods="GET" uri-template="/{Id}">
<inSequence>
<property name="getId" expression="get-property('uri.var.Id')" scope="default" type="STRING"/>
<log>
<property name="ID" expression="get-property('getId')"/>
</log>
<payloadFactory media-type="xml">
<format>
<p:searchPharmacy xmlns:p="http://pharmacy.arce.org">
<ax22:pharmacy xmlns:ax22="http://pharmacy.arce.org">
<xs:id xmlns:xs="http://pharmacy.arce.org/xsd">$1</xs:id>
</ax22:pharmacy>
</p:searchPharmacy>
</format>
<args>
<arg evaluator="xml" expression="get-property('getId')"/>
</args>
</payloadFactory>
<header name="Action" scope="default" value="urn:searchPharmacy"/>
<call blocking="true">
<endpoint>
<address uri="http://169.254.193.10:9769/services/ServicePharmacy" format="soap11"/>
</endpoint>
</call>
<log>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Status" expression="get-property('axis2','HTTP_SC')"/>
</log>
<log level="full"/>
<enrich>
<source type="body" clone="true"/>
<target type="property" property="Ouput_Respose_Service"/>
</enrich>
<log level="custom" separator=",">
<property name="Service_Response" expression="get-property('Ouput_Respose_Service')"/>
</log>
<respond description=""/>
</inSequence>
<outSequence>
<log level="full"/>
<send/>
</outSequence>
<faultSequence>
<sequence key="{faultSEQ}"/>
</faultSequence>
</resource>
</api>
I have a soap service that I want to turn around and post a message to an external server.
I was able to do this via curl like so:
curl --data-urlencode "filename=data.txt" --data-urlencode "filedir=/home/myfile/in"
--data-urlencode "busproc=MyBP" --data-urlencode "serverip=192.168.1.4"
--data-urlencode"uid=myuserid" --data-urlencode "pwd=mypwd"
http://somelocation.com:8833/webservice/inbound/here
But I can't quite get it working correctly. Here's my proxy service:
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="ExampleHTTPPostWithFormData"
transports="http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<log/>
<property name="messageType"
value="application/x-www-form-urlencoded"
scope="axis2"
type="STRING"/>
<property name="HTTP_METHOD" value="post" scope="axis2" type="STRING"/>
<send>
<endpoint>
<address uri="http://somelocation.com:8833/webservice/inbound/here"
format="pox"/>
<property name="uid" value="user"/>
<property name="pwd" value="password"/>
<property name="filedir" value="/home/myfile/in"/>
<property name="busproc" value="myBP"/>
<property name="serverip" value="192.168.1.4"/>
<property name="filename" value="data.txt"/>
</endpoint>
</send>
<log level="full"/>
</inSequence>
</target>
<description/>
</proxy>
The end service seems to only see me posting to the URL (but not the passed in data properties).
Properties are not the way to build the message content. The best way I've found to do it is with a payloadFactory. The message you need to build has a root XML element with one child per form field, and then it seems that Axis2 handles the messageType of application/x-www-form-urlencoded by serialising in the appropriate format. So a minimal change to your proxy would be:
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="ExampleHTTPPostWithFormData"
transports="http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<log/>
<property name="messageType"
value="application/x-www-form-urlencoded"
scope="axis2"
type="STRING"/>
<payloadFactory media-type="xml">
<format>
<params xmlns="">
<uid>user</uid>
<pwd>password</pwd>
<filedir>/home/myfile/in</filedir>
<busproc>myBP</busproc>
<serverip>192.168.1.4</serverip>
<filename>data.txt</filename>
</params>
</format>
</payloadFactory>
<send>
<endpoint>
<address uri="http://somelocation.com:8833/webservice/inbound/here"
format="rest"/>
</endpoint>
</send>
<log level="full"/>
</inSequence>
</target>
<description/>
</proxy>
It may also be convenient to add <property name="FORCE_HTTP_1.0" value="true" scope="axis2" type="STRING"/> depending on whether your REST service handles HTTP/1.1.
If you need parameters then you can pass in arguments to the payloadFactory, using the XPath extensions. E.g.
<payloadFactory media-type="xml">
<format>
<params xmlns="">
<uid>user</uid>
<pwd>password</pwd>
<filedir>/home/myfile/in</filedir>
<busproc>myBP</busproc>
<serverip>192.168.1.4</serverip>
<filename>$1</filename>
</params>
</format>
<args>
<arg evaluator="xml" expression="$ctx:filename"/>
</args>
</payloadFactory>
If your sending the SOAP payload in a file you would need to use the VFS transport. Please refer to the following sample on how to use the VFS transport to solve your issue
http://docs.wso2.org/pages/viewpage.action?pageId=26838852
Alternatively you can use SOAPUI or any SOAP client to send the payload directly to the ESB proxy endpoint
i wish to send a e-mail to my client using Header mediator .
Is it possible with that or not
My proxy like this
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="Mail"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<log/>
<property name="workpartybranchid"
expression="//workpartybranchid/text()"
scope="default"
type="STRING"/>
<payloadFactory>
<format>
<p:SelectMail_Op xmlns:p="http://ws.wso2.org/dataservice">
<p:workpartybranchid>$1</p:workpartybranchid>
</p:SelectMail_Op>
</format>
<args>
<arg expression="get-property('workpartybranchid')"/>
</args>
</payloadFactory>
<send receive="Mailseq">
<endpoint>
<address uri="http://192.168.1.4:9773/services/muser_DataService/"
format="soap11"/>
</endpoint>
</send>
</inSequence>
</target>
</proxy
and corresponding sequence is
<sequence xmlns="http://ws.apache.org/ns/synapse" name="Mailseq" onError="fault">
<property name="CONTENT_TYPE"
value="application/json"
scope="axis2"
type="STRING"/>
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
xmlns:s="http://ws.wso2.org/dataservice"
name="primarymail"
expression="//s:primarymail/text()"
scope="axis2"
type="STRING"/>
<log>
<property xmlns:ns="http://org.apache.synapse/xsd"
xmlns:s="http://ws.wso2.org/dataservice"
name="primarymail"
expression="//s:primarymail/text()"
scope="axis2"
type="STRING"/>
</log>
<header name="To" expression="fn:concat('mailto:', get-property('primarymail'))"/>
<send/>
<log>
<property name="mail" value="ts working"/></log>
</sequence>
can we send a email like this i have got reference from this
http://docs.wso2.org/wiki/display/ESB460/Sample+256%3A+Proxy+Services+with+the+Mail+Transport
i am posted my requirement in another way also please refer this
Can we send Multiple Mail in wso2esb in same sequence or dynamically set a mail
Just follow the step in below URL ( but rather than header part, use endpoint for this as below.. this worked for me)
http://docs.wso2.org/wiki/display/ESB460/Sample+256%3A+Proxy+Services+with+the+Mail+Transport
Add Send for mail as below...( no need header mediator)
<send> <endpoint>
<address uri="mailto:yourmailaddr#gmail.com" />
</endpoint>
</send>
i am doing filter based on the URL so i wish to know the FROM which service i am getting request .Means i wish to know the URL of Client
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Emp" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="username" expression="//username/text()" scope="default" type="STRING"/>
<property name="password" expression="//password/text()" scope="default" type="STRING"/>
<payloadFactory>
<format>
<send xmlns="">
<username>$1</username>
<password>$2</password>
</send>
</format>
<args>
<arg expression="get-property('username')"/>
<arg expression="get-property('password')"/>
</args>
</payloadFactory>
<send receive="Emp_Seq">
<endpoint>
<address uri="http://192.168.1.65:8282/services/Login"/>
</endpoint>
</send>
</inSequence>
<outSequence/>
</target>
<description></description>
</proxy>
URL of above Proxy is http://192.168.1.65:8282/services/Emp
my second proxy is which will do some logic based on first proxy
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Login" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="client_ip_address" expression="get-property('axis2','REMOTE_ADDR')" scope="default" type="STRING"/>
<property name="username" expression="//username/text()" scope="default" type="STRING"/>
<property name="password" expression="//password/text()" scope="default" type="STRING"/>
<property name="From" expression="get-property('From')"/>
<property name="Address" expression="get-property('To')"/>
<filter xmlns:ns="http://org.apache.synapse/xsd" xpath="get-property('From')='/services/Emp'">
<then>
<payloadFactory>
<format>
<ResponseJSON xmlns="">
<Status>404</Status>
<Exception>Not Found</Exception>
<Total>0</Total>
</ResponseJSON>
</format>
</payloadFactory>
<send/>
</then>
<else>
<payloadFactory>
<format>
<p:login xmlns:p="http://authentication.services.core.carbon.wso2.org">
<p:username>$1</p:username>
<p:password>$2</p:password>
<p:remoteAddress>$3</p:remoteAddress>
</p:login>
</format>
<args>
<arg expression="//username/text()"/>
<arg expression="//password/text()"/>
<arg expression="get-property('client_ip_address')"/>
</args>
</payloadFactory>
<header name="Action" value="urn:login"/>
<log level="full"/>
<send receive="Login_Seq">
<endpoint>
<address uri="https://192.168.1.65:9443/services/AuthenticationAdmin" format="soap11"/>
</endpoint>
</send>
</filter>
</inSequence>
<outSequence>
<log level="full"/>
</outSequence>
</target>
<description></description>
</proxy>
The issue is get-property('To') is giving Address=/services/Login where as get-property('From') is giving senderAddress=null
How can i manage this i trie d with lot of propertys even though its not working
like
<property name="senderAddress" expression="get-property('transport', 'From')"/>
<property name="Sender Address" expression="$url:From"/>
<header name="From" expression="get-property( 'From')"/>
<property name="PRESERVE_WS_ADDRESSING" value="true"/>
<property xmlns:wsa="http://www.w3.org/2005/08/addressing" name="$header" expression="$header/wsa:From"/>
This propertys also not working we don't have any option in wso2 esb If you know this please edit my proxy roughly ..its simple depanding logic but it is not working in WSO2
thanks in advance
You should be able to get the client's address with the REMOTE_HOST or REMOTE_ADDR properties. Please refer http://wso2.org/project/esb/java/4.0.3/docs/properties_guide.html#http