Hi Chanaka,

It seems like there has been some kind of caching issue OR I've made a
mistake in the process. The API is working as expected. Really sorry about
the noise.

Anyways, thought of documenting what I did for future reference.

First I created a LocalEntry in the ESB admin console by going to Main ->
Local Entries -> Add Local Entries -> "Add Source URL Entry"

Name: MyLocalJSEntry2
URL: 
file:repository/deployment/server/synapse-configs/default/script/MyLocalJS.js

*Note* - You need to have this file created at
<CARBON_HOME>/repository/deployment/server/synapse-configs/default/script/MyLocalJS.js
in this case *before* creating the Local Entry. Otherwise ESB wouldn't let
you create the entry.

Then create the API as follows;

<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse";
     name="MySampleAPI2"
     context="/MySampleAPI2">
   <resource methods="GET">
      <inSequence>
         <send>
            <endpoint>
               <address uri="http://demo3177833.mockable.io/students"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <property name="messageType" value="application/json"
scope="axis2"/>
         <script language="js" key="MyLocalJSEntry2"
function="executeMain"/>
         <send/>
      </outSequence>
   </resource>
</api>


Note that I'm referencing the LocalEntry in script mediator key attribute.

Also I observed that ESB is caching this LocalEntry, but I'm not sure about
the cache timeout or if that is permanent. Which means that if you make a
change in the JS file you need to refresh the cache by saving the Local
Entry again (Edit -> Save). This is something that can be improved I guess.

Thanks.

On Tue, Mar 31, 2015 at 1:27 AM, Chanaka Fernando <[email protected]> wrote:

> Hi Akila,
>
> What is the error you are getting? This sample should work without any
> issue. Simply, you need to create a localEntry key and then refer that key
> from the script mediator.
>
> Thanks,
> Chanaka
>
> On Tue, Mar 31, 2015 at 1:27 PM, Akila Ravihansa Perera <
> [email protected]> wrote:
>
>> Hi,
>>
>> I'm trying to develop an API which contains a JS based script mediator
>> and to have the JS file externally. But I don't want to keep it in the
>> registry.
>>
>> Can someone please share some synapse configuration samples if it is
>> possible to load a JS file from the local file-system? I came across [1]
>> that uses localEntry but couldn't make it work.
>>
>> [1]
>> https://docs.wso2.com/display/ESB480/Sample+353%3A+Using+Ruby+Scripts+for+Mediation
>>
>> Thanks.
>>
>> --
>> Akila Ravihansa Perera
>> Software Engineer, WSO2
>>
>> Blog: http://ravihansa3000.blogspot.com
>>
>
>
>
> --
> --
> Chanaka Fernando
> Technical Lead
> WSO2, Inc.; http://wso2.com
> lean.enterprise.middleware
>
> mobile: +94 773337238
> Blog : http://soatutorials.blogspot.com
> LinkedIn:http://www.linkedin.com/pub/chanaka-fernando/19/a20/5b0
> Twitter:https://twitter.com/chanakaudaya
> Wordpress:http://chanakaudaya.wordpress.com
>
>
>
>


-- 
Akila Ravihansa Perera
Software Engineer, WSO2

Blog: http://ravihansa3000.blogspot.com
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to