Re: [Carbon-dev] [Architecture] Status of JavaScript Appdev Project

2011-11-04 Thread Ruchira Wageesha

 OK so any code outside these functions will get run at the point the code
 is loaded. Do we give any guarantees about that - for example, how often do
 we load that code? Under what conditions do we unload etc.?

 Maybe for starters we should say that there must not be any code outside
 of these functions and if you put anything there and it does something that
 your problem/luck and that we do not guarantee how that will hold up in the
 future.


At the moment, it doesn't use Rhino's compiled scripts. What it does is
just load the script when a request needs to be served. So, for the best
performance, we have to use compiled scripts.

Currently, the problem of global variable access is there. We need to find
the best solution for it.

Anyway, a compiled script is executed on a given scope. i.e. We need to
pass a toplevel scope into the compiled script when we execute it. So, we
will have to keep a per *.jss scope object in the memory in order to keep
those globally defined variable values.

Again, scope objects in Rhino implement java.io.Serializable interface. So
we can serialize the per *.jss scope and load when ever needed.

regards,
Ruchira
___
Carbon-dev mailing list
Carbon-dev@wso2.org
http://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev


Re: [Carbon-dev] [Architecture] Status of JavaScript Appdev Project

2011-11-03 Thread Sanjiva Weerawarana
Excellent progress Ruchira.

We need to have a discussion on tooling .. can you please grab me for 5-10
mins today? Lets come up with a plan to build a plan :).

On the JSS model below, what happens to any code that's in the file outside
of any function definitions?

Also, should we consider placing JS files that execute on the server like
this in a separate location rather than use a different extension? That's
the model with servlets - and its useful and necessary when the server side
code starts importing other stuff to use. We could simply use WEB-INF too
as that special directory ..

Sanjiva.

On Thu, Nov 3, 2011 at 2:29 PM, Ruchira Wageesha ruch...@wso2.com wrote:

 Hi,

 I have added all existing hostobjects(except global System HO) of WSO2
 Mashup Server to the Appdev environment. Several hostobjects such as
 WSRequest, was modified to act independently of carbon environment. XHR
 hostobject was also added which allows you to call sync/async HTTP calls
 using httpcore-nio.

 For the *.jss stuff, JSON support was also implemented. In a *.jss, we can
 implement doGet, doPost etc. methods which corresponds to relevant HTTP
 methods. So, when an HTTP request comes to a *.jss file, then request will
 be dispatched to the relavant JavaScript method in the *.jss file. There,
 you have access to the *request*, *response* and *session* objects.

 If the request content type is json, then we can get content as a JSON by
 accessing *request.content* property. Further, you can get any
 parameters posted with the request by calling *request.getParameter()*method.

 When we returning from a *.jss, you can either return directly a JSON
 object which will be serialized and send to the client as a JSON content.
 If you want, you can set custom headers to the response object and put
 content using *response.write()* method. A sample *.jss content can be
 found at the bottom.

 Further, a new Rhino engine was created which allows to keep different top
 level scopes for different envirenments. i.e. now we can allow to plug, any
 product specific, tenant specific Hostobjects without affecting others.
 Later this will be integrated into javax.script API.

 In order to allow database calls, php-mysql api was proposed. But, it
 doesn't seem like it utilizes Object Orientation which can be effectively
 used in JavaScript in order to make it easier for the developer. php-mysql
 api has a functional programming model. Also, we need to allow users to do
 async database calls. i.e. register a function which will get executed once
 the database return the result set. So, it would be better to have an API
 as in XHR.

 I will send a separate mail with a proposed mysql api covering above
 requirements.

 Following is the current request, response, session object APIs which
 corresponds to relavant Java methods.

 *session object API*

 readonly property number created
 readonly property number lastAccessed
 readonly property isNew
 property maxInactive


 void put(string key, object value)
 object get(string key)
 void invalidate()

 *request object API*

 readonly property object content //this will return string content or json
 content depending on the content type
 readonly property string method
 readonly property string protocol
 readonly property string queryString
 readonly property string contentType
 readonly property number contentLength

 string getHeader(string name)
 string getParameter(string name)

 *response object API*

 property string content
 property string contentType
 property number status

 void addHeader(string name, string value)
 void getHeader(string name)
 void write(object content) // JSON objects will be serialized to strings
 void sendError(number code, string message)
 void sendRedirect(string url)


 *A Sample *.jss content*

 function *doGet*(request, response, session) {
 response.write(html);
 response.write(h2 + request.getHeader(User-Agent) + /h2);
 response.write(h2 + request.getParameter(lang) + /h2);
 response.write(/html);
 }

 function *doPost*(request, response, session) {
 var obj = {
 name : ruchira,
 age : 27,
 address : {
 number : 16,
 city : ahangama
 }
 };
 //if the request was JSON, then content property will return that JSON
 object
 //obj = request.content;
 session.put(myObj, obj);
 var o = session.get(myObj);
 return o;
 }


 regards,
 Ruchira
 --
 Ruchira Wageesha
 Software Engineer - WSO2 Inc. www.wso2.com

 Email: ruch...@wso2.com Blog: ruchirawagee...@blogspot.com
 Mobile: +94775493444

 Lean . Enterprise . Middleware

 ___
 Architecture mailing list
 architect...@wso2.org
 https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture




-- 
Sanjiva Weerawarana, Ph.D.
Founder, Chairman  CEO; WSO2, Inc.;  http://wso2.com/
email: sanj...@wso2.com; phone: +94 11 763 9614; cell: +94 77 787 6880 | +1
650 265 8311
blog: 

Re: [Carbon-dev] [Architecture] Status of JavaScript Appdev Project

2011-11-03 Thread Ruchira Wageesha


 On the JSS model below, what happens to any code that's in the file
 outside of any function definitions?


Any code or function which are outside of doGet, doPost...etc methods will
be executed on global scope and can be accessed within doGet(), doPost()...
methods.

i.e. The *.jss file is first loaded into Rhino engine, which adds all
toplevel variables/functions into the top level scope. Then, relevant
doXXX() function will be executed where we can access those toplevel
variables/functions.

Further, request, response, and session objects are passed as args to the
doXXX() function, so won't be available to the outside of the function.

regards,
Ruchira
___
Carbon-dev mailing list
Carbon-dev@wso2.org
http://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev


Re: [Carbon-dev] [Architecture] Status of JavaScript Appdev Project

2011-11-03 Thread Sanjiva Weerawarana
On Fri, Nov 4, 2011 at 8:31 AM, Ruchira Wageesha ruch...@wso2.com wrote:


 On the JSS model below, what happens to any code that's in the file
 outside of any function definitions?


 Any code or function which are outside of doGet, doPost...etc methods will
 be executed on global scope and can be accessed within doGet(), doPost()...
 methods.

 i.e. The *.jss file is first loaded into Rhino engine, which adds all
 toplevel variables/functions into the top level scope. Then, relevant
 doXXX() function will be executed where we can access those toplevel
 variables/functions.


OK so any code outside these functions will get run at the point the code
is loaded. Do we give any guarantees about that - for example, how often do
we load that code? Under what conditions do we unload etc.?

Maybe for starters we should say that there must not be any code outside of
these functions and if you put anything there and it does something that
your problem/luck and that we do not guarantee how that will hold up in the
future.

Further, request, response, and session objects are passed as args to the
 doXXX() function, so won't be available to the outside of the function.


Yes.

Sanjiva.
-- 
Sanjiva Weerawarana, Ph.D.
Founder, Chairman  CEO; WSO2, Inc.;  http://wso2.com/
email: sanj...@wso2.com; phone: +94 11 763 9614; cell: +94 77 787 6880 | +1
650 265 8311
blog: http://sanjiva.weerawarana.org/

Lean . Enterprise . Middleware
___
Carbon-dev mailing list
Carbon-dev@wso2.org
http://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev