Hi Thilini,

Try appending file:/// to your file path. I tried the below code and it
works fine for me.
Note : I'm trying to read test.txt file which resides in my CARBON_HOME
directory.

<%

var file = new File
('file:///data/packs/ds/wso2ds-2.1.0-SNAPSHOT/test.txt');
file.open("r");
var message = "";
message = file.readAll();
print(message);
file.close()

%>

Thanks,
Tanya

On Mon, Jun 13, 2016 at 9:31 AM, Thilini Cooray <thili...@wso2.com> wrote:

> Hi all,
>
> I want to read a file from API Manager publisher jaggery app which is
> located outside of that jaggery app.
> The reason for the requirement is that this particular file is a sample
> documentation which we plan to distribute with API Manager and should be
> stored in a location which users can easily access instead of inside
> jaggery apps.
>
> When jaggery FileHostObject gets created, it seems to be appending
> absolute path of the calling jaggery app to whenever path we are provided.
> I provided the absolute Path of the file. Therefore the real path provided
> by jaggery FileHostObject = absolute path of Jaggery app + absolute path of
> the file to be read.
>
> Since that path is wrong, when this file is accessed using
>  APIProviderHostObject.java it throws a file not found exception.
>
> I tried following approaches without any luck [1].
>
> Appreciate your feedback on any possible approach or would like to know
> whether it is not possible via jaggery.
>
> Thanks.
>
> [1]
>
>    1. Provided the path of the reading file relative to the jaggery app.
>    HostObject is not capable of understanding relative paths. - throws
>    FileNotFound Exception
>    2. Provided original file path using ~ (Home) - throws FileNotFound
>    Exception
>    3. Read the file on jaggery side using Packages.java.io.File - throws
>    ClassCastException: org.mozilla.javascript.NativeJavaObject cannot be cast
>    to org.jaggeryjs.hostobjects.file.FileHostObject
>
>
> --
> Best Regards,
>
> *Thilini Cooray*
> Software Engineer
> Mobile : +94 (0) 774 570 112 <%2B94%20%280%29%20773%20451194>
> E-mail : thili...@wso2.com
>
> WSO2 Inc. www.wso2.com
> lean.enterprise.middleware
>
> _______________________________________________
> Dev mailing list
> Dev@wso2.org
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>


-- 
Tanya Madurapperuma

Senior Software Engineer,
WSO2 Inc. : wso2.com
Mobile : +94718184439
Blog : http://tanyamadurapperuma.blogspot.com
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to