Run servlets on Nashorn written in server-side JavaScript

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
26 messages Options
12
leo
Reply | Threaded
Open this post in threaded view
|

Run servlets on Nashorn written in server-side JavaScript

leo
Hi there

I am trying to find out how to process servlets written in server-side
JavaScript through Tomcat.

I looked through the Tomcat FAQ and How-To but couldn't find anything.
By googling I found a way to hook up Python through Jython's PyServlet
class. I tried this and it works great.

But I am looking for server-side JavaScript in Tomcat. I am aware of the
JavaScript engine Nashorn. Is there a way to hook up Nashorn with a
servlet class, so that Tomcat serves JavaScript servlets? Something like
a "JavaScript Server Page" for Tomcat would be fine too.

Many thanks for any pointers,
Leo

ps: I use Tomcat 8.5, but I could move to another Tomcat version for
this.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Run servlets on Nashorn written in server-side JavaScript

Rony G. Flatscher (Apache)
Hi Leo,

why would you want to do that if you could do the same with Java? What is the motivation, the use
case for you?

How urgent is this (I may have something for both, Java EE and Jakarta EE, but need a little bit of
time)?

—-rony



On 15.02.2021 07:29, leo wrote:

> Hi there
>
> I am trying to find out how to process servlets written in server-side JavaScript through Tomcat.
>
> I looked through the Tomcat FAQ and How-To but couldn't find anything. By googling I found a way
> to hook up Python through Jython's PyServlet class. I tried this and it works great.
>
> But I am looking for server-side JavaScript in Tomcat. I am aware of the JavaScript engine
> Nashorn. Is there a way to hook up Nashorn with a servlet class, so that Tomcat serves JavaScript
> servlets? Something like a "JavaScript Server Page" for Tomcat would be fine too.
>
> Many thanks for any pointers,
> Leo
>
> ps: I use Tomcat 8.5, but I could move to another Tomcat version for this.
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Run servlets on Nashorn written in server-side JavaScript

Christopher Schultz-2
Rony and Leo,

On 2/17/21 02:58, Rony G. Flatscher (Apache) wrote:

> Hi Leo,
>
> why would you want to do that if you could do the same with Java? What is the motivation, the use
> case for you?
>
> How urgent is this (I may have something for both, Java EE and Jakarta EE, but need a little bit of
> time)?
>
> —-rony
>
>
>
> On 15.02.2021 07:29, leo wrote:
>> Hi there
>>
>> I am trying to find out how to process servlets written in server-side JavaScript through Tomcat.
>>
>> I looked through the Tomcat FAQ and How-To but couldn't find anything. By googling I found a way
>> to hook up Python through Jython's PyServlet class. I tried this and it works great.
>>
>> But I am looking for server-side JavaScript in Tomcat. I am aware of the JavaScript engine
>> Nashorn. Is there a way to hook up Nashorn with a servlet class, so that Tomcat serves JavaScript
>> servlets? Something like a "JavaScript Server Page" for Tomcat would be fine too.
>>
>> Many thanks for any pointers,
>> Leo
>>
>> ps: I use Tomcat 8.5, but I could move to another Tomcat version for this.

Weird; I never saw the OP on the list, only Rony's reply.

Usually if you want to use server-side JavaScript, you use something
like Node.js instead of a servlet container. Why not use Node?

If you'd really like to use Tomcat, you will need to write a Servlet
that establishes a JavaScript environment (e.g. Nashhorn), provides all
the plumbing for the servlet-container provided resources (e.g. request,
response, streams, session, etc.) as well as error-handling, etc.

It's a big job.

I'd be surprised is nobody had built something like this before. Or
maybe everybody just uses Node.js.

-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Run servlets on Nashorn written in server-side JavaScript

André Warnier (tomcat/perl)
On 17.02.2021 14:59, Christopher Schultz wrote:

> Rony and Leo,
>
> On 2/17/21 02:58, Rony G. Flatscher (Apache) wrote:
>> Hi Leo,
>>
>> why would you want to do that if you could do the same with Java? What is the
>> motivation, the use
>> case for you?
>>
>> How urgent is this (I may have something for both, Java EE and Jakarta EE, but need a
>> little bit of
>> time)?
>>
>> —-rony
>>
>>
>>
>> On 15.02.2021 07:29, leo wrote:
>>> Hi there
>>>
>>> I am trying to find out how to process servlets written in server-side JavaScript
>>> through Tomcat.
>>>
>>> I looked through the Tomcat FAQ and How-To but couldn't find anything. By googling I
>>> found a way
>>> to hook up Python through Jython's PyServlet class. I tried this and it works great.
>>>
>>> But I am looking for server-side JavaScript in Tomcat. I am aware of the JavaScript engine
>>> Nashorn. Is there a way to hook up Nashorn with a servlet class, so that Tomcat serves
>>> JavaScript
>>> servlets? Something like a "JavaScript Server Page" for Tomcat would be fine too.
>>>
>>> Many thanks for any pointers,
>>> Leo
>>>
>>> ps: I use Tomcat 8.5, but I could move to another Tomcat version for this.
>
> Weird; I never saw the OP on the list, only Rony's reply.
>
> Usually if you want to use server-side JavaScript, you use something like Node.js instead
> of a servlet container. Why not use Node?
>
> If you'd really like to use Tomcat, you will need to write a Servlet that establishes a
> JavaScript environment (e.g. Nashhorn), provides all the plumbing for the
> servlet-container provided resources (e.g. request, response, streams, session, etc.) as
> well as error-handling, etc.
>
> It's a big job.
>
> I'd be surprised is nobody had built something like this before. Or maybe everybody just
> uses Node.js.
>

+1.
On the face of it, it looks much simpler to set up a local Nodejs server, and proxy the
corresponding requests from Tomcat to it.
Perhaps have a look at this ?
https://stackoverflow.com/questions/42057314/how-to-implement-an-application-proxy-in-java-on-tomcat
Or use an Apache httpd front-end to filter requests and do the proxying to Nodejs and Tomcat.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Run servlets on Nashorn written in server-side JavaScript

Christopher Schultz-2
André,

On 2/17/21 11:15, André Warnier (tomcat/perl) wrote:

> On 17.02.2021 14:59, Christopher Schultz wrote:
>> Rony and Leo,
>>
>> On 2/17/21 02:58, Rony G. Flatscher (Apache) wrote:
>>> Hi Leo,
>>>
>>> why would you want to do that if you could do the same with Java?
>>> What is the motivation, the use
>>> case for you?
>>>
>>> How urgent is this (I may have something for both, Java EE and
>>> Jakarta EE, but need a little bit of
>>> time)?
>>>
>>> —-rony
>>>
>>>
>>>
>>> On 15.02.2021 07:29, leo wrote:
>>>> Hi there
>>>>
>>>> I am trying to find out how to process servlets written in
>>>> server-side JavaScript through Tomcat.
>>>>
>>>> I looked through the Tomcat FAQ and How-To but couldn't find
>>>> anything. By googling I found a way
>>>> to hook up Python through Jython's PyServlet class. I tried this and
>>>> it works great.
>>>>
>>>> But I am looking for server-side JavaScript in Tomcat. I am aware of
>>>> the JavaScript engine
>>>> Nashorn. Is there a way to hook up Nashorn with a servlet class, so
>>>> that Tomcat serves JavaScript
>>>> servlets? Something like a "JavaScript Server Page" for Tomcat would
>>>> be fine too.
>>>>
>>>> Many thanks for any pointers,
>>>> Leo
>>>>
>>>> ps: I use Tomcat 8.5, but I could move to another Tomcat version for
>>>> this.
>>
>> Weird; I never saw the OP on the list, only Rony's reply.
>>
>> Usually if you want to use server-side JavaScript, you use something
>> like Node.js instead of a servlet container. Why not use Node?
>>
>> If you'd really like to use Tomcat, you will need to write a Servlet
>> that establishes a JavaScript environment (e.g. Nashhorn), provides
>> all the plumbing for the servlet-container provided resources (e.g.
>> request, response, streams, session, etc.) as well as error-handling,
>> etc.
>>
>> It's a big job.
>>
>> I'd be surprised is nobody had built something like this before. Or
>> maybe everybody just uses Node.js.
>>
>
> +1.
> On the face of it, it looks much simpler to set up a local Nodejs
> server, and proxy the corresponding requests from Tomcat to it.
> Perhaps have a look at this ?
> https://stackoverflow.com/questions/42057314/how-to-implement-an-application-proxy-in-java-on-tomcat 
>
> Or use an Apache httpd front-end to filter requests and do the proxying
> to Nodejs and Tomcat.

+1 to using a different proxy. I'm sure Tomcat can be made into a fine
proxy, but there are other products which exist solely to be proxies.
You will have better luck with Apache Traffic Server, Squid, haproxy,
Apache httpd, Nginx, etc. than you will using Tomcat as a proxy.

-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Run servlets on Nashorn written in server-side JavaScript

Woonsan Ko-3
In reply to this post by Christopher Schultz-2
On Wed, Feb 17, 2021 at 8:59 AM Christopher Schultz
<[hidden email]> wrote:

>
> Rony and Leo,
>
> On 2/17/21 02:58, Rony G. Flatscher (Apache) wrote:
> > Hi Leo,
> >
> > why would you want to do that if you could do the same with Java? What is the motivation, the use
> > case for you?
> >
> > How urgent is this (I may have something for both, Java EE and Jakarta EE, but need a little bit of
> > time)?
> >
> > —-rony
> >
> >
> >
> > On 15.02.2021 07:29, leo wrote:
> >> Hi there
> >>
> >> I am trying to find out how to process servlets written in server-side JavaScript through Tomcat.
> >>
> >> I looked through the Tomcat FAQ and How-To but couldn't find anything. By googling I found a way
> >> to hook up Python through Jython's PyServlet class. I tried this and it works great.
> >>
> >> But I am looking for server-side JavaScript in Tomcat. I am aware of the JavaScript engine
> >> Nashorn. Is there a way to hook up Nashorn with a servlet class, so that Tomcat serves JavaScript
> >> servlets? Something like a "JavaScript Server Page" for Tomcat would be fine too.
> >>
> >> Many thanks for any pointers,
> >> Leo
> >>
> >> ps: I use Tomcat 8.5, but I could move to another Tomcat version for this.
>
> Weird; I never saw the OP on the list, only Rony's reply.
>
> Usually if you want to use server-side JavaScript, you use something
> like Node.js instead of a servlet container. Why not use Node?
>
> If you'd really like to use Tomcat, you will need to write a Servlet
> that establishes a JavaScript environment (e.g. Nashhorn), provides all
> the plumbing for the servlet-container provided resources (e.g. request,
> response, streams, session, etc.) as well as error-handling, etc.
>
> It's a big job.
>
> I'd be surprised is nobody had built something like this before. Or
> maybe everybody just uses Node.js.

I found one example:
- https://stackoverflow.com/questions/27710407/reuse-nashorn-scriptengine-in-servlet

As a servlet implementation may embed a Jython engine to execute a
python script, it will end up embedding a JS engine in a servlet to
execute a .js like the example.
I guess JS engine in Java vs. Node.js depends on whether or not you
need to allow the .js scripts to use any existing Java libraries in
the same JVM.

Regards, Woonsan

>
> -chris
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Run servlets on Nashorn written in server-side JavaScript

Rony G. Flatscher (Apache)
In reply to this post by Christopher Schultz-2
Hi Chris,

On 17.02.2021 14:59, Christopher Schultz wrote:

> Rony and Leo,
>
> On 2/17/21 02:58, Rony G. Flatscher (Apache) wrote:
>> Hi Leo,
>>
>> why would you want to do that if you could do the same with Java? What is the motivation, the use
>> case for you?
>>
>> How urgent is this (I may have something for both, Java EE and Jakarta EE, but need a little bit of
>> time)?
>>
>> —-rony
>>
>>
>>
>> On 15.02.2021 07:29, leo wrote:
>>> Hi there
>>>
>>> I am trying to find out how to process servlets written in server-side JavaScript through Tomcat.
>>>
>>> I looked through the Tomcat FAQ and How-To but couldn't find anything. By googling I found a way
>>> to hook up Python through Jython's PyServlet class. I tried this and it works great.
>>>
>>> But I am looking for server-side JavaScript in Tomcat. I am aware of the JavaScript engine
>>> Nashorn. Is there a way to hook up Nashorn with a servlet class, so that Tomcat serves JavaScript
>>> servlets? Something like a "JavaScript Server Page" for Tomcat would be fine too.
>>>
>>> Many thanks for any pointers,
>>> Leo
>>>
>>> ps: I use Tomcat 8.5, but I could move to another Tomcat version for this.
>
> Weird; I never saw the OP on the list, only Rony's reply.

Yes, somehow it appeared later (Tuesday evening here, but the date and time in the post is Monday),
at least I recognized it Tuesday evening for the first time.


> Usually if you want to use server-side JavaScript, you use something like Node.js instead of a
> servlet container. Why not use Node?

This may be an option if you desire to write in JavaScript.
(But it may be the case that creating web applications under e.g. Tomcat may be even easier than
with Node, one would have to check it out though. ;) )


> If you'd really like to use Tomcat, you will need to write a Servlet that establishes a JavaScript
> environment (e.g. Nashhorn), provides all the plumbing for the servlet-container provided
> resources (e.g. request, response, streams, session, etc.) as well as error-handling, etc.
>
> It's a big job.
>
> I'd be surprised is nobody had built something like this before. Or maybe everybody just uses
> Node.js.

Well, I had a need to let Business Administration (BA) students who just learned programming in an
easy to learn, yet powerful programming language (ooRexx, a message based, dynamically typed
language, originating at IBM, but in open-source for a long time) create little web applications
with Tomcat. This way they experience what is basically involved when creating a web app in person
(even if they never will create fully fledged web apps on their own it will help them get a basic
understanding, better estimates for web app projects and the like).

For these BA students - even if they "experienced" - Java or JavaScript would be outside of their
scope, short of having enough learning and training time needed for mastering Java and JavaScript to
the extent that is needed to create fully-fledged web applications in Java (like a web-shop with
cart, e-mail-newsletter, uploading files, etc.). This has to do with the BA curriculum in question
that does not provide enough resources/time (in this particular case a four hours lecture with
homework assignments for the duration of one semester, i.e. appr. for four months) for learning a
programming language like Java or JavaScript to a professional extent, which would be possible e.g.
at a technical university or in specific IS/CIS studies.

My BA students on the other hand have a working knowledge and expierence with ooRexx (which they
learned in a four hour class during a semester and learned to apply it to interact with Windows, MS
Office, but also with Java - camouflaged as ooRexx - in an operating-system independent manner, i.e.
creating GUI, socket programs, OpenOffice/LibreOffice, exploiting JavaFX in an operating system
platform independent manner) such that ooRexx would have become feasible for them for using it to
learn and to experiment with creating  web apps, if they so desire. If only Tomcat et.al. would
allow for that somehow.

As having authored Apache BSF and JSR-223 (package javax.script introduced in Java 6) bindings for
ooRexx (using a combination of JNI, C++, Java, ooRexx) it would be feasible and desirable to create
a solution that not only supports a single scripting/programming language like ooRexx in this case,
but supports in general also any other programming language for which there is a bindings either for
Apache BSF and/or JSR-223 out of the box. As there is a JSR-223 bindings for Nashorn, one should be
able to apply Nashorn/JavaScript with this very same infrastructure.

Currently I am assessing the results (have yet to check-out and to grade two seminar papers and one
Bachelor thesis) and at first sight look quite promising, but this will take a little bit of time
until I get to them (planned for the end of next week), unless Leo has an urgent need. [In the
meantime, if there is interest, I could point to a little informal overview article where I
explained how one would create web apps in Java on Tomcat in general to the Rexx community and how
one would go about doing the same with deploying ooRexx web apps on Tomcat. Maybe this might be
helpful if you know of persons who are not coding or maybe not proficient enough in Java, but
like/are able to code in other programming/scripting languages and wish to create web apps in their
language of choice that get deployed with Tomcat.]

---rony



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Run servlets on Nashorn written in server-side JavaScript

Christopher Schultz-2
Rony,

On 2/18/21 09:26, Rony G. Flatscher (Apache) wrote:

> Hi Chris,
>
> On 17.02.2021 14:59, Christopher Schultz wrote:
>> Rony and Leo,
>>
>> On 2/17/21 02:58, Rony G. Flatscher (Apache) wrote:
>>> Hi Leo,
>>>
>>> why would you want to do that if you could do the same with Java? What is the motivation, the use
>>> case for you?
>>>
>>> How urgent is this (I may have something for both, Java EE and Jakarta EE, but need a little bit of
>>> time)?
>>>
>>> —-rony
>>>
>>>
>>>
>>> On 15.02.2021 07:29, leo wrote:
>>>> Hi there
>>>>
>>>> I am trying to find out how to process servlets written in server-side JavaScript through Tomcat.
>>>>
>>>> I looked through the Tomcat FAQ and How-To but couldn't find anything. By googling I found a way
>>>> to hook up Python through Jython's PyServlet class. I tried this and it works great.
>>>>
>>>> But I am looking for server-side JavaScript in Tomcat. I am aware of the JavaScript engine
>>>> Nashorn. Is there a way to hook up Nashorn with a servlet class, so that Tomcat serves JavaScript
>>>> servlets? Something like a "JavaScript Server Page" for Tomcat would be fine too.
>>>>
>>>> Many thanks for any pointers,
>>>> Leo
>>>>
>>>> ps: I use Tomcat 8.5, but I could move to another Tomcat version for this.
>>
>> Weird; I never saw the OP on the list, only Rony's reply.
>
> Yes, somehow it appeared later (Tuesday evening here, but the date and time in the post is Monday),
> at least I recognized it Tuesday evening for the first time.
>
>
>> Usually if you want to use server-side JavaScript, you use something like Node.js instead of a
>> servlet container. Why not use Node?
>
> This may be an option if you desire to write in JavaScript.
> (But it may be the case that creating web applications under e.g. Tomcat may be even easier than
> with Node, one would have to check it out though. ;) )
>
>
>> If you'd really like to use Tomcat, you will need to write a Servlet that establishes a JavaScript
>> environment (e.g. Nashhorn), provides all the plumbing for the servlet-container provided
>> resources (e.g. request, response, streams, session, etc.) as well as error-handling, etc.
>>
>> It's a big job.
>>
>> I'd be surprised is nobody had built something like this before. Or maybe everybody just uses
>> Node.js.
>
> Well, I had a need to let Business Administration (BA) students who just learned programming in an
> easy to learn, yet powerful programming language (ooRexx, a message based, dynamically typed
> language, originating at IBM, but in open-source for a long time) create little web applications
> with Tomcat. This way they experience what is basically involved when creating a web app in person
> (even if they never will create fully fledged web apps on their own it will help them get a basic
> understanding, better estimates for web app projects and the like).
>
> For these BA students - even if they "experienced" - Java or JavaScript would be outside of their
> scope, short of having enough learning and training time needed for mastering Java and JavaScript to
> the extent that is needed to create fully-fledged web applications in Java (like a web-shop with
> cart, e-mail-newsletter, uploading files, etc.). This has to do with the BA curriculum in question
> that does not provide enough resources/time (in this particular case a four hours lecture with
> homework assignments for the duration of one semester, i.e. appr. for four months) for learning a
> programming language like Java or JavaScript to a professional extent, which would be possible e.g.
> at a technical university or in specific IS/CIS studies.
>
> My BA students on the other hand have a working knowledge and expierence with ooRexx (which they
> learned in a four hour class during a semester and learned to apply it to interact with Windows, MS
> Office, but also with Java - camouflaged as ooRexx - in an operating-system independent manner, i.e.
> creating GUI, socket programs, OpenOffice/LibreOffice, exploiting JavaFX in an operating system
> platform independent manner) such that ooRexx would have become feasible for them for using it to
> learn and to experiment with creating  web apps, if they so desire. If only Tomcat et.al. would
> allow for that somehow.
>
> As having authored Apache BSF and JSR-223 (package javax.script introduced in Java 6) bindings for
> ooRexx (using a combination of JNI, C++, Java, ooRexx) it would be feasible and desirable to create
> a solution that not only supports a single scripting/programming language like ooRexx in this case,
> but supports in general also any other programming language for which there is a bindings either for
> Apache BSF and/or JSR-223 out of the box. As there is a JSR-223 bindings for Nashorn, one should be
> able to apply Nashorn/JavaScript with this very same infrastructure.
>
> Currently I am assessing the results (have yet to check-out and to grade two seminar papers and one
> Bachelor thesis) and at first sight look quite promising, but this will take a little bit of time
> until I get to them (planned for the end of next week), unless Leo has an urgent need. [In the
> meantime, if there is interest, I could point to a little informal overview article where I
> explained how one would create web apps in Java on Tomcat in general to the Rexx community and how
> one would go about doing the same with deploying ooRexx web apps on Tomcat. Maybe this might be
> helpful if you know of persons who are not coding or maybe not proficient enough in Java, but
> like/are able to code in other programming/scripting languages and wish to create web apps in their
> language of choice that get deployed with Tomcat.]

A BSF / JSR-233 environment that is available for any servlet container
would certainly be an accomplishment, and probably very useful for some
shops (and students!).

I wonder if there is anything we can learn / steal from Apache Sling.

-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Ad Apache Sling scripting (Re: Run servlets on Nashorn written in server-side JavaScript

Rony G. Flatscher (Apache)
Chris,

On 18.02.2021 15:56, Christopher Schultz wrote:
... cut ...
> A BSF / JSR-233 environment that is available for any servlet container would certainly be an
> accomplishment, and probably very useful for some shops (and students!).
>
> I wonder if there is anything we can learn / steal from Apache Sling.

hmm, at first sight Apache Sling defines its own Scripting classes [1] and seems to not use JSR-223
[2, 3] (or BSF [4] for that matter). As a result it seems that each scripting language that you wish
to use in the Sling environment needs to get a proper SlingScript implementation otherwise you are
out of luck.

Personally I think one should adhere to the standard Java scripting framework [2] whenever possible
(and I would see no compelling reason at first sight why the Sling project created its own scripting
framework). The Java scripting framework allows non-Java programmers to create scripts that can be
deployed by the Java application and allow them to interact directly with explicitly supplied Java
objects of the Java application. Loading a scripting language for the Java application programmer is
as easy as using javax.script.ScriptEngineManager methods that start with getEngineBy...() supplying
the name of the scripting language (like "groovy", "javascript", "netrexx", "rexx" and the like),
one of its mime-types or one of its file-extensions and then (re-)using that engine to evaluate
script code.

The JSR-223 [3] implementation of Java 6 makes it also quite easy to create new bindings for new
programming languages (one merely needs to extend javax.script.AbstractScriptEngine, which
implements already most of the javax.script.ScriptEngine interface, and implement the
javax.script.ScriptFactory interface).

---rony

[1] Sling's Scripting Framework:
<https://sling.apache.org/apidocs/sling10/org/apache/sling/api/scripting/package-summary.html>
[2] Java's Scripting Framework (Since Java 6):
<https://docs.oracle.com/javase/8/docs/api/index.html?javax/script/package-summary.html>
[3] JCP JSR-223: <https://www.jcp.org/en/jsr/detail?id=223>
[4] Apache BSF: <https://commons.apache.org/proper/commons-bsf/>



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Ad Apache Sling scripting (Re: Run servlets on Nashorn written in server-side JavaScript

Woonsan Ko-3
You might want to take a look at this, too:
- http://portals.apache.org/bridges/bridges-script/index.html

Of course, there must be outdated dependencies, but the idea is the
same and it has working code: integrate with JSR-223 for jruby,
jython, bsh, js, etc.
The portlet api (e.g, PortletRequest, PortletResponse, PortletContext,
etc) should be converted to servlet-api though.

Regards,

Woonsan

On Thu, Feb 18, 2021 at 11:09 AM Rony G. Flatscher (Apache)
<[hidden email]> wrote:

>
> Chris,
>
> On 18.02.2021 15:56, Christopher Schultz wrote:
> ... cut ...
> > A BSF / JSR-233 environment that is available for any servlet container would certainly be an
> > accomplishment, and probably very useful for some shops (and students!).
> >
> > I wonder if there is anything we can learn / steal from Apache Sling.
>
> hmm, at first sight Apache Sling defines its own Scripting classes [1] and seems to not use JSR-223
> [2, 3] (or BSF [4] for that matter). As a result it seems that each scripting language that you wish
> to use in the Sling environment needs to get a proper SlingScript implementation otherwise you are
> out of luck.
>
> Personally I think one should adhere to the standard Java scripting framework [2] whenever possible
> (and I would see no compelling reason at first sight why the Sling project created its own scripting
> framework). The Java scripting framework allows non-Java programmers to create scripts that can be
> deployed by the Java application and allow them to interact directly with explicitly supplied Java
> objects of the Java application. Loading a scripting language for the Java application programmer is
> as easy as using javax.script.ScriptEngineManager methods that start with getEngineBy...() supplying
> the name of the scripting language (like "groovy", "javascript", "netrexx", "rexx" and the like),
> one of its mime-types or one of its file-extensions and then (re-)using that engine to evaluate
> script code.
>
> The JSR-223 [3] implementation of Java 6 makes it also quite easy to create new bindings for new
> programming languages (one merely needs to extend javax.script.AbstractScriptEngine, which
> implements already most of the javax.script.ScriptEngine interface, and implement the
> javax.script.ScriptFactory interface).
>
> ---rony
>
> [1] Sling's Scripting Framework:
> <https://sling.apache.org/apidocs/sling10/org/apache/sling/api/scripting/package-summary.html>
> [2] Java's Scripting Framework (Since Java 6):
> <https://docs.oracle.com/javase/8/docs/api/index.html?javax/script/package-summary.html>
> [3] JCP JSR-223: <https://www.jcp.org/en/jsr/detail?id=223>
> [4] Apache BSF: <https://commons.apache.org/proper/commons-bsf/>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Ad Apache Sling scripting (Re: Run servlets on Nashorn written in server-side JavaScript

Rony G. Flatscher (Apache)
Woonsan,

On 18.02.2021 18:02, Woonsan Ko wrote:

> You might want to take a look at this, too:
> - http://portals.apache.org/bridges/bridges-script/index.html
>
> Of course, there must be outdated dependencies, but the idea is the
> same and it has working code: integrate with JSR-223 for jruby,
> jython, bsh, js, etc.
> The portlet api (e.g, PortletRequest, PortletResponse, PortletContext,
> etc) should be converted to servlet-api though.

thank you very much for this pointer. The overview page [1] includes references to the Portlet
specifications [2,3] which allow to learn about the motivation and also about its devised features.
It was also interesting to skim over some bird-eye's-view comparisons between Portlets and Servlets
e.g. in [4, 5].

As I have an implementation already in place (with BA students trying it out who have been serving a
little bit as a very small subject group) that supports both BSF and JSR-223, I would make further
work dependent on my assessment of the student's work (and of course whatever feedback comes up
later). The goal was to keep it as simple as possible (KISS principle) such that it is easy to
understand/teach and easy to take advantage of, yet make it versatile for the script developers
(including demo script samples that will dump the request and response objects and query their
getter values such that the students get to see/learn what they convey to them at the point of
invocation; just skimming over this extensive information causes them to learn what is available and
over time get a "feeling" of what they can expect and do with each request).

---rony

[1] Apache Portals Bridges Homepage: <http://portals.apache.org/bridges/index.html>
[2] JSR-168, Portlet Specification: <http://www.jcp.org/en/jsr/detail?id=168>
[3] JRS-286, Portlet Specification 2.0: <http://www.jcp.org/en/jsr/detail?id=286>
[4] Nilang, Servlet vs Portlet: <https://www.opensource-techblog.com/2014/10/servlet-vs-portlet.html>
[5] Sarin A., Portlets vs. Servlets: Request Processing with Web Components:
<https://www.developer.com/java/web/article.php/3891786/Portlets-vs-Servlets-Request-Processing-with-Web-Components.htm>


> On Thu, Feb 18, 2021 at 11:09 AM Rony G. Flatscher (Apache)
> <[hidden email]> wrote:
>> Chris,
>>
>> On 18.02.2021 15:56, Christopher Schultz wrote:
>> ... cut ...
>>> A BSF / JSR-233 environment that is available for any servlet container would certainly be an
>>> accomplishment, and probably very useful for some shops (and students!).
>>>
>>> I wonder if there is anything we can learn / steal from Apache Sling.
>> hmm, at first sight Apache Sling defines its own Scripting classes [1] and seems to not use JSR-223
>> [2, 3] (or BSF [4] for that matter). As a result it seems that each scripting language that you wish
>> to use in the Sling environment needs to get a proper SlingScript implementation otherwise you are
>> out of luck.
>>
>> Personally I think one should adhere to the standard Java scripting framework [2] whenever possible
>> (and I would see no compelling reason at first sight why the Sling project created its own scripting
>> framework). The Java scripting framework allows non-Java programmers to create scripts that can be
>> deployed by the Java application and allow them to interact directly with explicitly supplied Java
>> objects of the Java application. Loading a scripting language for the Java application programmer is
>> as easy as using javax.script.ScriptEngineManager methods that start with getEngineBy...() supplying
>> the name of the scripting language (like "groovy", "javascript", "netrexx", "rexx" and the like),
>> one of its mime-types or one of its file-extensions and then (re-)using that engine to evaluate
>> script code.
>>
>> The JSR-223 [3] implementation of Java 6 makes it also quite easy to create new bindings for new
>> programming languages (one merely needs to extend javax.script.AbstractScriptEngine, which
>> implements already most of the javax.script.ScriptEngine interface, and implement the
>> javax.script.ScriptFactory interface).
>>
>> ---rony
>>
>> [1] Sling's Scripting Framework:
>> <https://sling.apache.org/apidocs/sling10/org/apache/sling/api/scripting/package-summary.html>
>> [2] Java's Scripting Framework (Since Java 6):
>> <https://docs.oracle.com/javase/8/docs/api/index.html?javax/script/package-summary.html>
>> [3] JCP JSR-223: <https://www.jcp.org/en/jsr/detail?id=223>
>> [4] Apache BSF: <https://commons.apache.org/proper/commons-bsf/>
>>
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: Ad Apache Sling scripting (Re: Run servlets on Nashorn written in server-side JavaScript

Woonsan Ko-3
On Fri, Feb 19, 2021 at 7:37 AM Rony G. Flatscher (Apache)
<[hidden email]> wrote:

>
> Woonsan,
>
> On 18.02.2021 18:02, Woonsan Ko wrote:
>
> > You might want to take a look at this, too:
> > - http://portals.apache.org/bridges/bridges-script/index.html
> >
> > Of course, there must be outdated dependencies, but the idea is the
> > same and it has working code: integrate with JSR-223 for jruby,
> > jython, bsh, js, etc.
> > The portlet api (e.g, PortletRequest, PortletResponse, PortletContext,
> > etc) should be converted to servlet-api though.
>
> thank you very much for this pointer. The overview page [1] includes references to the Portlet
> specifications [2,3] which allow to learn about the motivation and also about its devised features.
> It was also interesting to skim over some bird-eye's-view comparisons between Portlets and Servlets
> e.g. in [4, 5].
>
> As I have an implementation already in place (with BA students trying it out who have been serving a
> little bit as a very small subject group) that supports both BSF and JSR-223, I would make further
> work dependent on my assessment of the student's work (and of course whatever feedback comes up
> later). The goal was to keep it as simple as possible (KISS principle) such that it is easy to
> understand/teach and easy to take advantage of, yet make it versatile for the script developers
> (including demo script samples that will dump the request and response objects and query their
> getter values such that the students get to see/learn what they convey to them at the point of
> invocation; just skimming over this extensive information causes them to learn what is available and
> over time get a "feeling" of what they can expect and do with each request).

That makes sense. Thanks for sharing your views!

Cheers, woonsan

>
> ---rony
>
> [1] Apache Portals Bridges Homepage: <http://portals.apache.org/bridges/index.html>
> [2] JSR-168, Portlet Specification: <http://www.jcp.org/en/jsr/detail?id=168>
> [3] JRS-286, Portlet Specification 2.0: <http://www.jcp.org/en/jsr/detail?id=286>
> [4] Nilang, Servlet vs Portlet: <https://www.opensource-techblog.com/2014/10/servlet-vs-portlet.html>
> [5] Sarin A., Portlets vs. Servlets: Request Processing with Web Components:
> <https://www.developer.com/java/web/article.php/3891786/Portlets-vs-Servlets-Request-Processing-with-Web-Components.htm>
>
>
> > On Thu, Feb 18, 2021 at 11:09 AM Rony G. Flatscher (Apache)
> > <[hidden email]> wrote:
> >> Chris,
> >>
> >> On 18.02.2021 15:56, Christopher Schultz wrote:
> >> ... cut ...
> >>> A BSF / JSR-233 environment that is available for any servlet container would certainly be an
> >>> accomplishment, and probably very useful for some shops (and students!).
> >>>
> >>> I wonder if there is anything we can learn / steal from Apache Sling.
> >> hmm, at first sight Apache Sling defines its own Scripting classes [1] and seems to not use JSR-223
> >> [2, 3] (or BSF [4] for that matter). As a result it seems that each scripting language that you wish
> >> to use in the Sling environment needs to get a proper SlingScript implementation otherwise you are
> >> out of luck.
> >>
> >> Personally I think one should adhere to the standard Java scripting framework [2] whenever possible
> >> (and I would see no compelling reason at first sight why the Sling project created its own scripting
> >> framework). The Java scripting framework allows non-Java programmers to create scripts that can be
> >> deployed by the Java application and allow them to interact directly with explicitly supplied Java
> >> objects of the Java application. Loading a scripting language for the Java application programmer is
> >> as easy as using javax.script.ScriptEngineManager methods that start with getEngineBy...() supplying
> >> the name of the scripting language (like "groovy", "javascript", "netrexx", "rexx" and the like),
> >> one of its mime-types or one of its file-extensions and then (re-)using that engine to evaluate
> >> script code.
> >>
> >> The JSR-223 [3] implementation of Java 6 makes it also quite easy to create new bindings for new
> >> programming languages (one merely needs to extend javax.script.AbstractScriptEngine, which
> >> implements already most of the javax.script.ScriptEngine interface, and implement the
> >> javax.script.ScriptFactory interface).
> >>
> >> ---rony
> >>
> >> [1] Sling's Scripting Framework:
> >> <https://sling.apache.org/apidocs/sling10/org/apache/sling/api/scripting/package-summary.html>
> >> [2] Java's Scripting Framework (Since Java 6):
> >> <https://docs.oracle.com/javase/8/docs/api/index.html?javax/script/package-summary.html>
> >> [3] JCP JSR-223: <https://www.jcp.org/en/jsr/detail?id=223>
> >> [4] Apache BSF: <https://commons.apache.org/proper/commons-bsf/>
> >>
> >>
> >

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

leo
Reply | Threaded
Open this post in threaded view
|

Re: Run servlets on Nashorn written in server-side JavaScript

leo
In reply to this post by Rony G. Flatscher (Apache)
Hi there

First apologise that I reply so late and thank you all for chiming in!
:-)

Rony,

18:58, Rony G. Flatscher (Apache) wrote:

> why would you want to do that if you could do the same with Java? What
> is the motivation, the use
> case for you?

Use case is a project where I want to increase the JavaScript portion to
make the it more uniform.

> How urgent is this (I may have something for both, Java EE and Jakarta
> EE, but need a little bit of
> time)?

Well, for the moment we have the backend in Java EE Servlets, but any
time I could switch to more JavaSCript in the backend I would try it
out!

Cheers,
Leo

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

leo
Reply | Threaded
Open this post in threaded view
|

Re: Run servlets on Nashorn written in server-side JavaScript

leo
In reply to this post by Christopher Schultz-2
Chris,

On 18 Feb 2021, at 0:59, Christopher Schultz wrote:

> Weird; I never saw the OP on the list, only Rony's reply.

Weird indeed. I just posted to [hidden email], but maybe
because it was my first post it was held back for a while?

> Usually if you want to use server-side JavaScript, you use something
> like Node.js instead of a servlet container. Why not use Node?
>
> If you'd really like to use Tomcat, you will need to write a Servlet
> that establishes a JavaScript environment (e.g. Nashhorn), provides
> all the plumbing for the servlet-container provided resources (e.g.
> request, response, streams, session, etc.) as well as error-handling,
> etc.
>
> It's a big job.

Well, that’s why I asked whether somebody has ‘done’ it for
Nashorn/JavaSCript in the same way as it is done for Jython/Python
(https://jython.readthedocs.io/en/latest/SimpleWebApps/).

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

leo
Reply | Threaded
Open this post in threaded view
|

Re: Run servlets on Nashorn written in server-side JavaScript

leo
In reply to this post by André Warnier (tomcat/perl)
On 18 Feb 2021, at 3:15, André Warnier wrote:

> On 17.02.2021 14:59, Christopher Schultz wrote:
>
> […] On the face of it, it looks much simpler to set up a local
> Nodejs server, and proxy the corresponding requests from Tomcat to it.


Regarding why a servlet _in_ Tomcat and not a proxy: The production
environment is very restricted. We can add wars and jars to Tomcat, but
we can't install new separate OS native applications.

That’s why I thought Nashorn could be a way to deal with this
restriction - it even is built into Java 8!

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

leo
Reply | Threaded
Open this post in threaded view
|

Re: Run servlets on Nashorn written in server-side JavaScript

leo
In reply to this post by Woonsan Ko-3
On 18 Feb 2021, at 5:50, Woonsan Ko wrote:

> [...]
> I found one example:
>
> https://stackoverflow.com/questions/27710407/reuse-nashorn-scriptengine-in-servlet
>
> As a servlet implementation may embed a Jython engine to execute a
> python script, it will end up embedding a JS engine in a servlet to
> execute a .js like the example.

Thanks! I certainly will look at this!

> I guess JS engine in Java vs. Node.js depends on whether or not you
> need to allow the .js scripts to use any existing Java libraries in
> the same JVM.

Well, the JavaScript code has to be able to use java.sql... to access a
Oracle database. I would think this is possible with Nashorn.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Run servlets on Nashorn written in server-side JavaScript

Rony G. Flatscher (Apache)
In reply to this post by leo
On 23.02.2021 04:21, leo wrote:

> On 18 Feb 2021, at 3:15, André Warnier wrote:
>
>> On 17.02.2021 14:59, Christopher Schultz wrote:
>>
>> […] On the face of it, it looks much simpler to set up a local Nodejs server, and proxy the
>> corresponding requests from Tomcat to it.
>
>
> Regarding why a servlet _in_ Tomcat and not a proxy: The production environment is very
> restricted. We can add wars and jars to Tomcat, but we can't install new separate OS native
> applications.
>
> That’s why I thought Nashorn could be a way to deal with this restriction - it even is built into
> Java 8!
Note, Nashorn got removed from the standard JDK 15, but got resurrected as its own proper OpenJDK
module such that one can continue to use Nashorn on JDK 15 or later. [1]

---rony

[1] <https://github.com/openjdk/nashorn>

P.S.: Have tested my implementation with Nashorn on Java 8 and it works out of the box! Still, you
would need to test the implementation thoroughly yourself (stability, performance, resources) and
would be asked to come back with feedback on each of these qualities. So stay tuned, will publish a
link to the implementation with a proper Nashorn/JavaScript sample war in this mail thread in a few
days.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

leo
Reply | Threaded
Open this post in threaded view
|

Re: Run servlets on Nashorn written in server-side JavaScript

leo
Rony,

On 25 Feb 2021, at 2:47, Rony G. Flatscher (Apache) wrote:

> P.S.: Have tested my implementation with Nashorn on Java 8 and it
> works out of the box! Still, you
> would need to test the implementation thoroughly yourself (stability,
> performance, resources) and
> would be asked to come back with feedback on each of these qualities.
> So stay tuned, will publish a
> link to the implementation with a proper Nashorn/JavaScript sample war
> in this mail thread in a few
> days.

How cool is this! Let me know when you it ready, please. Thanks a lot!

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Run servlets on Nashorn written in server-side JavaScript

Rony G. Flatscher (Apache)
Leo,

On 26.02.2021 01:52, leo wrote:
> On 25 Feb 2021, at 2:47, Rony G. Flatscher (Apache) wrote:
>
>> P.S.: Have tested my implementation with Nashorn on Java 8 and it works out of the box! Still, you
>> would need to test the implementation thoroughly yourself (stability, performance, resources) and
>> would be asked to come back with feedback on each of these qualities. So stay tuned, will publish a
>> link to the implementation with a proper Nashorn/JavaScript sample war in this mail thread in a few
>> days.
>
> How cool is this! Let me know when you it ready, please. Thanks a lot!

O.K., had a few things I could finalize. Created two war files, "demoJavaScript.war" and
"demoRhino.war". The first got tested against Nashorn, the second - you guessed it ;) - against
Rhino (7.1.13). They are meant as little proof-of-concepts that should help you to get up and
running with them.

Please note that the libraries are beta, though appear to be stable. Yet, there may be
errors/problems in them or there may be changes coming up.

If you have feedback of any sorts, please come forward (stability, usability, performance,
resources, etc.).

Basically you just need to go to [1] and get the two war-files (copy to $CATALINA_HOME/webapps) plus
either javax.ScriptTagLibs.jar (for Tomcat 9 or earlier) or jakarta.ScriptTagLibs.jar (for Tomcat
10) which you should copy to the shared directory at $CATALINA_HOME/lib and restart Tomcat to get
them recognized. If you want to test with Rhino you should follow the directions at [1] and copy the
mentioned two rhino jar files to the shared library directory as well.

In general you should take the time and look over that page at [1], I tried to remain as brief as
possible. :)

Also please do not forget that the target audience of [1] has been so far the Rexx community and my
BA students who learned programming using ooRexx in a semester and with that knowledge should now
become able to create little web sites for their own purposes and maybe with some experience for
small businesses/organizations given the information at [1] as a starting point.

Of course, if there are any questions please do not hesitate and please ask them!

HTH,

---rony

[1] Homepage of the ScriptTagLibs libraries:
<https://sourceforge.net/projects/bsf4oorexx/files/Sandbox/rgf/taglibs/beta/>



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Run servlets on Nashorn written in server-side JavaScript

Christopher Schultz-2
Rony,

On 2/28/21 11:33, Rony G. Flatscher (Apache) wrote:

> Leo,
>
> On 26.02.2021 01:52, leo wrote:
>> On 25 Feb 2021, at 2:47, Rony G. Flatscher (Apache) wrote:
>>
>>> P.S.: Have tested my implementation with Nashorn on Java 8 and it works out of the box! Still, you
>>> would need to test the implementation thoroughly yourself (stability, performance, resources) and
>>> would be asked to come back with feedback on each of these qualities. So stay tuned, will publish a
>>> link to the implementation with a proper Nashorn/JavaScript sample war in this mail thread in a few
>>> days.
>>
>> How cool is this! Let me know when you it ready, please. Thanks a lot!
>
> O.K., had a few things I could finalize. Created two war files, "demoJavaScript.war" and
> "demoRhino.war". The first got tested against Nashorn, the second - you guessed it ;) - against
> Rhino (7.1.13). They are meant as little proof-of-concepts that should help you to get up and
> running with them.
>
> Please note that the libraries are beta, though appear to be stable. Yet, there may be
> errors/problems in them or there may be changes coming up.
>
> If you have feedback of any sorts, please come forward (stability, usability, performance,
> resources, etc.).
>
> Basically you just need to go to [1] and get the two war-files (copy to $CATALINA_HOME/webapps) plus
> either javax.ScriptTagLibs.jar (for Tomcat 9 or earlier) or jakarta.ScriptTagLibs.jar (for Tomcat
> 10) which you should copy to the shared directory at $CATALINA_HOME/lib and restart Tomcat to get
> them recognized. If you want to test with Rhino you should follow the directions at [1] and copy the
> mentioned two rhino jar files to the shared library directory as well.
>
> In general you should take the time and look over that page at [1], I tried to remain as brief as
> possible. :)
>
> Also please do not forget that the target audience of [1] has been so far the Rexx community and my
> BA students who learned programming using ooRexx in a semester and with that knowledge should now
> become able to create little web sites for their own purposes and maybe with some experience for
> small businesses/organizations given the information at [1] as a starting point.
>
> Of course, if there are any questions please do not hesitate and please ask them!

Any source available?

-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

12