Hi Akila,

You can try following,

        <script language="js"><![CDATA[
             importPackage(Packages.org.......JSUtils);
             ......................
             var result = JSUtils.parseJSON(someJsonVar);
 ]]></script>


On Tue, Mar 31, 2015 at 3:31 PM, Akila Ravihansa Perera <raviha...@wso2.com>
wrote:

> Hi,
>
> Is it possible to do $subject? I've been playing around with wso2-synapse
> code base but couldn't find a way around without overriding ScriptMediator
> class which is something I'm trying to avoid.
>
> My requirement is that I've developed some Java Util methods which I would
> like to expose as JS native functions. I tried writing a class mediator and
> do the bindings but couldn't get it working.
>
> ScriptEngineManager manager = new ScriptEngineManager();
> manager.registerEngineExtension("jsEngine", new
> RhinoScriptEngineFactory());
> ScriptEngine scriptEngine = manager.getEngineByExtension("jsEngine");
>
> Bindings bindings = scriptEngine.createBindings();
> bindings.put("jsUtils", new JSUtils());
>
> JSUtils Java class has some string operations that should be accessible
> via JS. Inside JS script mediator I should be able to something like this;
>
> var result = jsUtils.parseJSON(someJsonVar);
>
>
> I know this can be done by purely using the class mediator to evaluate the
> whole JS source. But I'd much rather use built-in script mediator and only
> inject my custom Java classes onto it.
>
> I think this would be a cool feature to have, if it is not already
> supported.
>
> Thanks.
>
> --
> Akila Ravihansa Perera
> Software Engineer, WSO2
>
> Blog: http://ravihansa3000.blogspot.com
>



-- 

Best Regards,

Malaka Silva
Senior Tech Lead
M: +94 777 219 791
Tel : 94 11 214 5345
Fax :94 11 2145300
Skype : malaka.sampath.silva
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/
http://www.wso2.com/about/team/malaka-silva/
<http://wso2.com/about/team/malaka-silva/>

Save a tree -Conserve nature & Save the world for your future. Print this
email only if it is absolutely necessary.
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to