How to change WSDL and add input variables in Proxy Service? - wso2

I created proxy service in WSO EI 6.4.0, which send email. In the flow I use properties: AttachmentFile, transport.mail.bodyWhenAttached, senderAddress and Subject. How to create custom wsdl with input parameters sender_address, subject, mail_text, attachment_file. or what other solution can you use?
I want to call this proxy server via API and send the parameters.
<inSequence xmlns="http://ws.apache.org/ns/synapse">
<property name="transport.mail.Format" scope="axis2" type="STRING" value="Attachment"/>
<property name="AttachmentFile" scope="axis2" type="STRING" value="attachment.csv"/>
<property name="ContentType" scope="axis2" type="STRING" value="text/html"/>
<property name="messageType" scope="axis2" type="STRING" value="text/html"/>
<property expression="Some body text" name="transport.mail.bodyWhenAttached"
scope="axis2" type="STRING"/>
<property name="senderAddress" scope="default" type="STRING" value="test#test.com"/>
<property name="Subject" scope="transport" type="STRING" value="WSO Email Test"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<property name="FORCE_SC_ACCEPTED" scope="axis2" type="STRING" value="true"/>
<log level="full"/>
<header
expression="fn:concat('mailto:', get-property('senderAddress'))"
name="To" scope="default"/>
<call>
<endpoint>
<default/>
</endpoint>
</call>
</inSequence>

Save the below file with the name sendEmailProxy.xml under the location
//repository/deployment/server/synapse-configs/default/proxy-services
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="sendEmailProxy"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<property name="transport.mail.Format"
scope="axis2"
type="STRING"
value="Attachment"/>
<property name="AttachmentFile"
scope="axis2"
type="STRING"
value="attachment.csv"/>
<property name="ContentType"
scope="axis2"
type="STRING"
value="text/html"/>
<property name="messageType"
scope="axis2"
type="STRING"
value="text/html"/>
<property name="senderAddress"
scope="default"
type="STRING"
value="test#test.com"/>
<property name="Subject"
scope="transport"
type="STRING"
value="WSO Email Test"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<property name="FORCE_SC_ACCEPTED"
scope="axis2"
type="STRING"
value="true"/>
<log level="full"/>
<header expression="fn:concat('mailto:', get-property('senderAddress'))"
name="To"
scope="default"/>
<call>
<endpoint>
<default/>
</endpoint>
</call>
<respond/>
</inSequence>
</target>
<parameter name="useOriginalwsdl">true</parameter>
<description/>
</proxy>
Once it is saved start wso2 EI/ESB instance , log into the instance, then click on service which is on left hand side of screen below services you wil find the proxy, You will have two options wsdl1.1 wsdl2.0 click on which ever you prefer , this would provide the wsdl file for you proxy
If you are already having a custom wsdl and want wso2 to pick up that wsdl then you need to add the below parameter
<parameter name="useOriginalwsdl">true</parameter>
This would accept your custom wsdl and wso2 will not generate it's own wsdl

Related

WSO2 developer studio keeps removing square bracket from my json payload

I'm using wso2 integration studio (version 7.2). I'm trying to post a JSON payload factory to an endpoint. This JSON message has a JSON array with a square bracket but wso2 keeps removing that before sending it out. The receiver API doesn't accept it in this format.
See my code below:
<api context="/test" name="testAPi" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<property name="setCharacterEncoding" value="false" scope="axis2"/>
<payloadFactory media-type="json">
<format>{"field1": 5,"field2": 2022,"field3": "22","contacts": [{"id":1014,"surname": "N"}],"applicants": [{"nameId": 111111}]}
</format>
<args/>
</payloadFactory>
<header name="Content-Type" scope="transport" value="application/json"/>
<property name="contentType" scope="axis2" type="STRING" value="application/json"/>
<log level="full"/>
<header name="Accept" scope="transport" value="*/*"/>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<header name="Connection" scope="transport" value="keep-alive"/>
<header name="Accept-Encoding" scope="transport" value="gzip, deflate, br"/>
<property name="DISABLE_CHUNKING" scope="axis2" type="STRING" value="true"/>
<log level="full"/>
<call blocking="true">
<endpoint key="tcpmon"/>
</call>
<log level="full"/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
I used the tcpmon to see what is sending out. and I can see wso2 just remove the [] from the message and send it out.
Do you know how can I fix this?

No password supplied by the callback handler for the user [wso2]

I have a proxy service inlclued a sequence.
I process for authentication for proxy service with tag
<policy key="gov:/testPolicy"/>
<enableSec/>
In this sequence contain iterate mediator.
When call proxy service with authentication by soapUI then not reponse for client and have a error Unexpected error sending message back {org.apache.synapse.core.axis2.Axis2Sender} org.apache.axis2.AxisFault: No password supplied by the callback handler for the user : "wso2carbon"
If have not iterate mediator then have not error
This sequence
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="SendReceiveQueue" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="get-property('Edxml_Organ_Id')" name="senderUnitId" scope="default" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
<property expression="get-property('Edxml_Type')" name="applicationType" scope="default" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
<property expression="get-property('Edxml_Record_Code')" name="recordCode" scope="default" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
<property expression="$ctx:data_original" name="messagePl" scope="default" type="STRING" xmlns:edXML="http://www.mic.gov.vn/TBT/QCVN_102_2016" xmlns:ns="http://org.apache.synapse/xsd"/>
<property expression="$body" name="messagePlBody" scope="default" type="STRING" xmlns:edXML="http://www.mic.gov.vn/TBT/QCVN_102_2016" xmlns:ns="http://org.apache.synapse/xsd"/>
<property name="QUEUE_ACTION_TYPE" scope="default" type="STRING" value="SENDER"/>
<log level="custom">
<property expression="get-property('messagePl')" name="messagePllogging" xmlns:ns="http://org.apache.synapse/xsd"/>
<property expression="get-property('messagePlBody')" name="messagePlloggingBody" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
<iterate expression="$ctx:abc//edXML:To" id="abc" sequential="true" xmlns:edXML="http://www.mic.gov.vn/TBT/QCVN_102_2016" xmlns:ns="http://org.apache.synapse/xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<target>
<sequence>
<log level="custom">
<property name="goi DSS" value="-------------------------------------------"/>
<property expression="//edXML:To/edXML:OrganId/text()" name="queue name"/>
</log>
<payloadFactory media-type="xml">
<format>
<p:getQueueId xmlns:p="http://ws.wso2.org/dataservice">
<xs:in_unitId xmlns:xs="http://ws.wso2.org/dataservice">$1</xs:in_unitId>
<xs:in_b2bType xmlns:xs="http://ws.wso2.org/dataservice">$2</xs:in_b2bType>
</p:getQueueId>
</format>
<args>
<arg evaluator="xml" expression="//edXML:To/edXML:OrganId/text()"/>
<arg evaluator="xml" expression="syn:get-property('Edxml_Type')"/>
</args>
</payloadFactory>
<call blocking="true">
<endpoint>
<address uri="http://cqdt-app3:8280/services/validateData"/>
</endpoint>
</call>
<property expression="//x:returnCode/x:MessageQueueId/text()" name="queue_name" scope="default" type="STRING" xmlns:x="http://ws.wso2.org/dataservice"/>
<log level="custom">
<property name="lay xong tu dss" value="-------------------------------------------"/>
<property expression="$ctx:queue_name" name="ten queue lay ra"/>
</log>
<class name="com.vsc.ReceiveQueue">
<property name="password" value="admin"/>
<property name="queueName" value="testQueue1"/>
<property name="CF_NAME_PREFIX" value="connectionfactory."/>
<property name="CF_NAME" value="QueueConnectionFactory"/>
<property name="QPID_ICF" value="org.wso2.andes.jndi.PropertiesFileInitialContextFactory"/>
<property name="CARBON_DEFAULT_HOSTNAME" value="cqdt-app3"/>
<property name="QUEUE_NAME_PREFIX" value="queue."/>
<property name="userName" value="admin"/>
<property name="CARBON_CLIENT_ID" value="carbon"/>
<property name="CARBON_DEFAULT_PORT" value="5675"/>
<property name="CARBON_VIRTUAL_HOST_NAME" value="carbon"/>
</class>
<log level="custom">
<property name="put xong vao queue" value="-------------------------------------------"/>
<property expression="$ctx:queue_name" name="ten queue ban xong"/>
</log>
<payloadFactory media-type="xml">
<format>
<response>
<result>SUCCESS</result>
</response>
</format>
<args/>
</payloadFactory>
<property name="RESPONSE" scope="default" type="STRING" value="true"/>
<property name="messageType" scope="axis2" type="STRING" value="application/xml"/>
<property action="remove" name="NO_ENTITY_BODY" scope="axis2"/>
<header action="remove" name="To" scope="default"/>
<send/>
</sequence>
</target>
</iterate>
<property name="RESPONSE" scope="default" type="STRING" value="true"/>
<header action="remove" name="To" scope="default"/>
<log level="custom">
<property expression="get-property('messagePl')" name="1111555555555555555555555555551111111111111111111111111111111-------------------------------" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
</sequence>
Please help me!
Have you tried applying the policy on the endpoint directly?
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="TQBsEndpoint">
<address uri="http://cqdt-app3:8280/services/validateData" format="soap11">
<enableSec policy="gov:testPolicy"/>
</address>
</endpoint>

Sending to dynamic address endpoint

How can one send an email to a dynamic address?
Address endpoint's URI seem to be static.
Is there a way to inject a property in a address endpoint ?
Here is what I have so far :
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="sendMail" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="//email" name="email" scope="default" type="STRING"/>
<log level="custom">
<property expression="fn:concat('Sending mail to - ',get-property('mail'))" name="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"/>
<send>
<endpoint name="mail2user">
<address uri="mailto:username#gmail.com"/>
</endpoint>
</send>
</sequence>
Thanks.
Define header "To" and use send without endpoint :
<header name="To"expression="fn:concat('mailto:', get-property('senderAddress'))"/>
<property name="OUT_ONLY" value="true"/>
<send/>
Don't forget to define transportSender "mailto" with class "org.apache.axis2.transport.mail.MailTransportSender" in axis2.xml
Here is the final code after jean-michel suggestion :
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="sendMail" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="//email" name="mailto" scope="default" type="STRING"/>
<log level="custom">
<property expression="fn:concat('Sending mail to - ',get-property('mailto'))" name="mail"/>
</log>
<property name="messageType" scope="axis2" type="STRING" value="text/html"/>
<property name="ContentType" scope="axis2" type="STRING" value="text/html"/>
<property name="Subject" scope="transport" type="STRING" value="File Received"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<header expression="fn:concat('mailto:', get-property('mailto'))" name="To" scope="default"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<send/>
</sequence>

Unable to use call mediator in APIM 2.0.0

I've tried this on 1.10.0 and 2.0.0
On 1.10.0, you can disable the JMS sender in repository/conf/axis2/axis2_blocking_client.xml and use the call mediator in blocking mode. This is described in this blog post: http://shenavid.blogspot.nl/2016/08/invoking-external-endpoints-using-call.html and works ok. However this method does not work in 2.0.0 even though the related issue is marked as resolved.
Has anyone else tested this on 2.0.0 already? Or found an other workaround?
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="opal_auth_and_send"
onError="gov:apimgt/customsequences/fault/json_fault.xml"
trace="enable" xmlns="http://ws.apache.org/ns/synapse">
<property description="ORG_PAYLOAD" expression="$body/child::node()"
name="ORG_PAYLOAD" scope="default" type="STRING"/>
<property description="URL_POSTFIX"
expression="get-property('axis2', 'REST_URL_POSTFIX')"
name="URL_POSTFIX" scope="default" type="STRING"/>
<property action="remove" description="Remove REST_URL_POSTFIX"
name="REST_URL_POSTFIX" scope="axis2"/>
<property action="remove" description="Remove transport headers"
name="TRANSPORT_HEADERS" scope="axis2"/>
<header name="Authorization" scope="transport" value="Basic xxxxxxxx"/>
<property description="set messageType" name="messageType"
scope="transport" type="STRING" value="application/json"/>
<call blocking="true" description="Get Auth token (blocking)">
<endpoint>
<http method="get" trace="enable" uri-template="https://opal-demo34.ortec-finance.com/auth/api/token"/>
</endpoint>
</call>
<property description="Get Token from Response"
expression="json-eval($.token)" name="TOKEN" scope="default" type="STRING"/>
<property action="remove" description="Remove transport headers"
name="TRANSPORT_HEADERS" scope="axis2"/>
<log description="Log auth result" level="full"/>
<property description="Restore REST_URL_POSTFIX"
expression="get-property('URL_POSTFIX')" name="REST_URL_POSTFIX"
scope="axis2" type="STRING"/>
<payloadFactory description="Restore Payload" media-type="json">
<format>$1</format>
<args>
<arg evaluator="xml" expression="get-property('ORG_PAYLOAD')"/>
</args>
</payloadFactory>
<header expression="get-property('TOKEN')" name="Authorization" scope="transport"/>
</sequence>
Thanks,
Danny

Can we Set a Send mediator with Xpath expression

i am trying to send a message to my email for that i am using send mediator as well i setup required configurations in AXIS2 file
is it work for below proxy
if not what is the way to give xpath to send mediator
<proxy xmlns="http://ws.apache.org/ns/synapse" name="mailCheck" transports="http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="Subject" value="Alert Message From WSO2 ESB - Service Down !!!" scope="transport" type="STRING"/>
<property name="messageType" value="text/html" scope="axis2" type="STRING"/>
<property name="ContentType" value="text/html" scope="axis2" type="STRING"/>
<property name="Mail" value="mailto:faisal.shaik#youtility.in" scope="default" type="STRING"/>
<log level="full">
<property name="Mail" value="mailto:faisal.shaik#youtility.in"/>
</log>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<send>
<endpoint key-expression="get-property('Mail')"/>
</send>
</inSequence>
<outSequence/>
</target>
<description></description>
</proxy>
if need any changes pls let me know
if you want to get the email address from a property value then use the header mediator to set value of "To" to "mailto:faisal.shaik#youtility.in".
You can do that adding the following before the send mediator
<header name="To" expression="fn:concat('mailto:', get-property('Mail'))"/>
You can use this:
<property name="To" expression="get-property('uri.var.to')" scope="transport"/>
<send>
<endpoint>
<address uri="mailto:"/>
</endpoint>
</send>
<send>
<address uri="mailto:xxx#yyy"/>
</send>
key-expression also can be used..