Hi,
I tried the following to in order to implement a connector using Script
mediator.
*01 Calling java library from script mediator (Above Example)*
This worked. But the problem is this is not 100% javascript. just calling
java from script mediator.
*02 Use script mediator for the whole process*
<script language="JS">
var url = "https://api.twilio.com/2010-04-01/Accounts";
var representationOfDesiredState = "";
var client = new XMLHttpRequest();
client.open("GET", url, false);
client.setRequestHeader("Content-Type", "text/plain");
client.send(representationOfDesiredState);
</script>
Use of the above configuration failed. XMLHttpRequest cannot be used. I
guess script mediator has some limitations. We cannot use normal
javascripts here.
*03 Using call mediator to call the service directly. Checked with Twilio
and Twitter*
This calls api directly. We can set the message body from script mediator
as required.
On Fri, Aug 23, 2013 at 2:00 PM, Malaka Silva <[email protected]> wrote:
> Hi,
>
> Following sample demonstrates a way to write a connector using WSO2 Script
> mediator.
>
> Same can be done using class mediator. This is another way of doing it.
>
>
> <template name="getAccountsList" xmlns="http://ws.apache.org/ns/synapse">
> <parameter name="friendlyName"/>
> <parameter name="status"/>
> <sequence>
> <script language="js"><![CDATA[
>
>
> importPackage(Packages.org.wso2.carbon.mediation.library.connectors.core.util);
> importPackage(Packages.com.twilio.sdk);
> importPackage(Packages.java.util);
> var restClient = new
> TwilioRestClient(<Twilio_User>, <Twilio_Password>);
> var params = new HashMap();
> var frindlyName = ConnectorUtils.lookupTemplateParamater(mc,
> "friendlyName");
> var status = ConnectorUtils.lookupTemplateParamater(mc,
> "status");
> print(frindlyName);
> print(status);
> if(frindlyName != null && frindlyName != ''){
> params.put('FriendlyName',frindlyName);
> }
> if(status != null && status != ''){
> params.put('Status',status);
> }
> var response = restClient.request('
> https://api.twilio.com/2010-04-01/Accounts',"GET",params);
> var strResponse = response.getResponseText();
> mc.setPayloadXML(new XML(strResponse));
> ]]></script>
> </sequence>
> </template>
>
> --
> Best Regards,
>
> Malaka Silva
> Senior Tech Lead
> M: +94 777 219 791
> T: +1 408 754 7388
> LinkedIn : http://www.linkedin.com/pub/malaka-silva/6/33/77
> Blog : http://mrmalakasilva.blogspot.com/
>
> WSO2, Inc.
> lean . enterprise . middleware
> http://www.wso2.com/
>
--
Best Regards,
Malaka Silva
Senior Tech Lead
M: +94 777 219 791
Tel : 94 11 214 5345
Fax :94 11 2145300
LinkedIn : http://www.linkedin.com/pub/malaka-silva/6/33/77
Blog : http://mrmalakasilva.blogspot.com/
WSO2, Inc.
lean . enterprise . middleware
http://www.wso2.com/
_______________________________________________
Architecture mailing list
[email protected]
https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture