Re: Out of memory exception

2021-02-18 Thread Niranjan Rao

On 2/18/21 12:53 PM, Shawn Heisey wrote:

On 2/18/2021 12:11 PM, Niranjan Rao wrote:
Thank you the response. This is not a web application, but a 
standalone java program. Hence I said it's not a tomcat question, but 
a generic JVM question. I have been researching about this a lot and 
based on many mails on this list, lot of people here know about 
internal behavior of JVM and specs lot better than I do.


Apologies for getting that wrong.

Is it a custom app or something that you downloaded and installed?  
Talk to whoever wrote it.  They will hopefully know what information 
is needed to troubleshoot further.


Is Java 15 required for the application to function?  If you can 
successfully use Java 11 or even Java 8, you'll be dealing with a far 
more stable platform.  Major show-stopper bugs in Java are rare, but 
they do happen.  I will warn you that although I do recommend 
downgrading Java for stability purposes, I do not hold out a lot of 
hope that it will solve this problem.


Which garbage collector are you using?  I would recommend one of the 
really stable collectors, like G1.  I wrote this wiki page a long time 
ago that includes garbage collection information for Solr ... I think 
it would apply well to any application where latency is important than 
throughput:


https://cwiki.apache.org/confluence/display/SOLR/ShawnHeisey

Thanks,
Shawn

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

I tried talking to the author, myself - but not much luck. Anyways 
talking with self does not help with new ideas much ;)


We added lot of logging and wrote a simple throw away tool to analyze 
the logs. Even though task counts are similar, there were some time out 
errors that could be causing the leaks. Currently a patch is deployed 
and we are waiting to see if it has made any impact.


Interesting point was why is one machine getting brunt of bad things. 
May be we will drop the box and spawn another VM with the assumption 
that host could be heavily loaded or something similar not easily 
visible things going on.


Your blog entry is very informative. Thank you.


Regards,


Niranjan


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Out of memory exception

2021-02-18 Thread Shawn Heisey

On 2/18/2021 12:11 PM, Niranjan Rao wrote:
Thank you the response. This is not a web application, but a standalone 
java program. Hence I said it's not a tomcat question, but a generic JVM 
question. I have been researching about this a lot and based on many 
mails on this list, lot of people here know about internal behavior of 
JVM and specs lot better than I do.


Apologies for getting that wrong.

Is it a custom app or something that you downloaded and installed?  Talk 
to whoever wrote it.  They will hopefully know what information is 
needed to troubleshoot further.


Is Java 15 required for the application to function?  If you can 
successfully use Java 11 or even Java 8, you'll be dealing with a far 
more stable platform.  Major show-stopper bugs in Java are rare, but 
they do happen.  I will warn you that although I do recommend 
downgrading Java for stability purposes, I do not hold out a lot of hope 
that it will solve this problem.


Which garbage collector are you using?  I would recommend one of the 
really stable collectors, like G1.  I wrote this wiki page a long time 
ago that includes garbage collection information for Solr ... I think it 
would apply well to any application where latency is important than 
throughput:


https://cwiki.apache.org/confluence/display/SOLR/ShawnHeisey

Thanks,
Shawn

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



[ANN] Apache Tomcat Migration tool for Jakarta EE 0.2.0

2021-02-18 Thread Mark Thomas
The Apache Tomcat team announces the immediate availability of Apache
Tomcat Migration Tool for Jakarta EE 0.2.0

Apache Tomcat Migration Tool for Jakarta EE is an open source software
tool for migrating binary web applications (WAR files) and other binary
artefacts from Java EE 8 to Jakarta EE 9.

The notable changes since 0.1.0 include:

- Various fixes to the packages that are and are not converted

- A new option to process zip archives in memory to support zip files
  that use options that are incompatible with a streaming approach

- A new option to exclude files from transformation

Please refer to the change log for the complete list of changes:
https://github.com/apache/tomcat-jakartaee-migration/blob/master/CHANGES.md

Downloads:
http://tomcat.apache.org/download-migration.cgi

Enjoy!

- The Apache Tomcat team


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Out of memory exception

2021-02-18 Thread Brian Wolfe
You need to monitor the JVM through something like visual VM or JConsole.
Monitor the heap space. Your gonna have to modify your code to help you
understand where the memory leak is occurring. The stack trace should give
you an idea of where in your code it is trying to allocate memory.

On Thu, Feb 18, 2021 at 2:12 PM Niranjan Rao  wrote:

> Hi Shawn
>
> Thank you the response. This is not a web application, but a standalone
> java program. Hence I said it's not a tomcat question, but a generic JVM
> question. I have been researching about this a lot and based on many
> mails on this list, lot of people here know about internal behavior of
> JVM and specs lot better than I do.
>
> Both the boxes are spawned from same AWS image, we build the image.
> There is no other difference. Both receive tasks over MQ.  Tasks could
> be slightly different - like for different users, number of entities
> user holds etc, but they should not be too different or kind of should
> average out in the long run. We have examined the data for the tasks and
> nothing unusual has come out so far.
>
> Regards,
>
> Niranjan
> On 2/18/21 10:59 AM, Shawn Heisey wrote:
>
> Regards,
>
> Niranjan
>
> > On 2/18/2021 11:36 AM, Niranjan Rao wrote:
> >> First apologies for non tomcat question. I have seen that there is
> >> enough expertise here to provide hints and hints are what I am
> >> looking for to solve the problem and question is generic enough. I
> >> have tried researching problem to best of my abilities.
> >
> > I believe you're right to think this isn't a tomcat question. There
> > are a lot of things it could be.  Tomcat is a *possible* source,
> > though I think the chance of that is low.  Without a LOT of info that
> > I would probably be useless at interpreting or asking for, it's
> > impossible to say for sure.
> >
> > With problems like this, it is normally the application running inside
> > Tomcat that has a problem, not Tomcat itself.  You're likely to get a
> > lot more useful information if you go to the people responsible for
> > those applications.
> >
> >> We have a java program that regularly throws
> >> "java.lang.OutOfMemoryError: Java heap space" exception. Puzzling
> >> point is it happens only on one VM. We have a set of two VMs/boxes
> >> spawned from same AWS image. Machine class/region is exactly same and
> >> since they are from same image, they should be mostly identical
> >> except stuff like host name, ip address etc.
> >>
> >> Number of tasks performed by VMs are comparable and not a significant
> >> difference. Yet, one VM never runs of out of memory and other one
> >> does. Sometimes it's as soon as half an hour after restarting the
> >> process while on the other box process is running for days and no
> >> issues.
> >
> > "Comparable" isn't "identical".
> >
> > Are they running the same apps?  Which apps are involved?  Is the one
> > that's throwing OOME handling substantially similar requests when
> > compared to one that doesn't?  Is the request rate nearly the same, or
> > is the problematic one handling a lot more?  Another applicable
> > question, also off topic for this mailing list:  Are the apps in both
> > cases configured identically?
> >
> >> I took memory dumps from both VMs and they look similar. Program is
> >> started with -Xmx1g flag and we have taken regular memory dumps. In
> >> many cases eclipse MAT reports total memory usage was less than 100MB
> >> when program crashed with out of memory exception.
> >
> > That's extremely odd, unless the application requested a REALLY big
> > chunk of memory such that the 100MB existing plus the new allocation
> > would be larger than the max heap size of 1GB.
> >
> > Do you have enough free memory that you could increase the max heap to
> > 2GB or beyond and see what happens?
> >
> >> Has anyone seen anything similar to this? Identical bits of code
> >> behaving differently? What else should I be looking for?
> >
> > Earlier you said "comparable" and now you're saying "identical". So I
> > have to ask ... which is it?  Remember that differences in
> > configurations, types of requests, and request load can lead to very
> > different requirements, even if the apps running inside Tomcat are the
> > same.
> >
> > Most of my experience in the Java world comes from Solr.  Apache Solr
> > is a servlet application, and ships with Jetty.  Tomcat is not usually
> > involved.  I joined this mailing list because I was responsible for
> > Tomcat servers running apps developed in-house, and every once in a
> > while, I needed to ask something tomcat-specific.
> >
> > Thanks,
> > Shawn
> >
> > -
> > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> > For additional commands, e-mail: users-h...@tomcat.apache.org
> >
>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional 

Re: Out of memory exception

2021-02-18 Thread Robert Turner
Have you tried enabling heap dumps on OOM exceptions (
https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/clopts001.html
; HeapDumpOnOutOfMemoryError) and then looking at the heap dump? It should
help you identify where the allocated heap is going to, and give you some
ideas of where to look next.


On Thu, Feb 18, 2021 at 2:12 PM Niranjan Rao  wrote:

> Hi Shawn
>
> Thank you the response. This is not a web application, but a standalone
> java program. Hence I said it's not a tomcat question, but a generic JVM
> question. I have been researching about this a lot and based on many
> mails on this list, lot of people here know about internal behavior of
> JVM and specs lot better than I do.
>
> Both the boxes are spawned from same AWS image, we build the image.
> There is no other difference. Both receive tasks over MQ.  Tasks could
> be slightly different - like for different users, number of entities
> user holds etc, but they should not be too different or kind of should
> average out in the long run. We have examined the data for the tasks and
> nothing unusual has come out so far.
>
> Regards,
>
> Niranjan
> On 2/18/21 10:59 AM, Shawn Heisey wrote:
>
> Regards,
>
> Niranjan
>
> > On 2/18/2021 11:36 AM, Niranjan Rao wrote:
> >> First apologies for non tomcat question. I have seen that there is
> >> enough expertise here to provide hints and hints are what I am
> >> looking for to solve the problem and question is generic enough. I
> >> have tried researching problem to best of my abilities.
> >
> > I believe you're right to think this isn't a tomcat question. There
> > are a lot of things it could be.  Tomcat is a *possible* source,
> > though I think the chance of that is low.  Without a LOT of info that
> > I would probably be useless at interpreting or asking for, it's
> > impossible to say for sure.
> >
> > With problems like this, it is normally the application running inside
> > Tomcat that has a problem, not Tomcat itself.  You're likely to get a
> > lot more useful information if you go to the people responsible for
> > those applications.
> >
> >> We have a java program that regularly throws
> >> "java.lang.OutOfMemoryError: Java heap space" exception. Puzzling
> >> point is it happens only on one VM. We have a set of two VMs/boxes
> >> spawned from same AWS image. Machine class/region is exactly same and
> >> since they are from same image, they should be mostly identical
> >> except stuff like host name, ip address etc.
> >>
> >> Number of tasks performed by VMs are comparable and not a significant
> >> difference. Yet, one VM never runs of out of memory and other one
> >> does. Sometimes it's as soon as half an hour after restarting the
> >> process while on the other box process is running for days and no
> >> issues.
> >
> > "Comparable" isn't "identical".
> >
> > Are they running the same apps?  Which apps are involved?  Is the one
> > that's throwing OOME handling substantially similar requests when
> > compared to one that doesn't?  Is the request rate nearly the same, or
> > is the problematic one handling a lot more?  Another applicable
> > question, also off topic for this mailing list:  Are the apps in both
> > cases configured identically?
> >
> >> I took memory dumps from both VMs and they look similar. Program is
> >> started with -Xmx1g flag and we have taken regular memory dumps. In
> >> many cases eclipse MAT reports total memory usage was less than 100MB
> >> when program crashed with out of memory exception.
> >
> > That's extremely odd, unless the application requested a REALLY big
> > chunk of memory such that the 100MB existing plus the new allocation
> > would be larger than the max heap size of 1GB.
> >
> > Do you have enough free memory that you could increase the max heap to
> > 2GB or beyond and see what happens?
> >
> >> Has anyone seen anything similar to this? Identical bits of code
> >> behaving differently? What else should I be looking for?
> >
> > Earlier you said "comparable" and now you're saying "identical". So I
> > have to ask ... which is it?  Remember that differences in
> > configurations, types of requests, and request load can lead to very
> > different requirements, even if the apps running inside Tomcat are the
> > same.
> >
> > Most of my experience in the Java world comes from Solr.  Apache Solr
> > is a servlet application, and ships with Jetty.  Tomcat is not usually
> > involved.  I joined this mailing list because I was responsible for
> > Tomcat servers running apps developed in-house, and every once in a
> > while, I needed to ask something tomcat-specific.
> >
> > Thanks,
> > Shawn
> >
> > -
> > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> > For additional commands, e-mail: users-h...@tomcat.apache.org
> >
>
>
> -
> To unsubscribe, e-mail: 

Re: Out of memory exception

2021-02-18 Thread Niranjan Rao

Hi Shawn

Thank you the response. This is not a web application, but a standalone 
java program. Hence I said it's not a tomcat question, but a generic JVM 
question. I have been researching about this a lot and based on many 
mails on this list, lot of people here know about internal behavior of 
JVM and specs lot better than I do.


Both the boxes are spawned from same AWS image, we build the image. 
There is no other difference. Both receive tasks over MQ.  Tasks could 
be slightly different - like for different users, number of entities 
user holds etc, but they should not be too different or kind of should 
average out in the long run. We have examined the data for the tasks and 
nothing unusual has come out so far.


Regards,

Niranjan
On 2/18/21 10:59 AM, Shawn Heisey wrote:

Regards,

Niranjan


On 2/18/2021 11:36 AM, Niranjan Rao wrote:
First apologies for non tomcat question. I have seen that there is 
enough expertise here to provide hints and hints are what I am 
looking for to solve the problem and question is generic enough. I 
have tried researching problem to best of my abilities.


I believe you're right to think this isn't a tomcat question. There 
are a lot of things it could be.  Tomcat is a *possible* source, 
though I think the chance of that is low.  Without a LOT of info that 
I would probably be useless at interpreting or asking for, it's 
impossible to say for sure.


With problems like this, it is normally the application running inside 
Tomcat that has a problem, not Tomcat itself.  You're likely to get a 
lot more useful information if you go to the people responsible for 
those applications.


We have a java program that regularly throws 
"java.lang.OutOfMemoryError: Java heap space" exception. Puzzling 
point is it happens only on one VM. We have a set of two VMs/boxes 
spawned from same AWS image. Machine class/region is exactly same and 
since they are from same image, they should be mostly identical 
except stuff like host name, ip address etc.


Number of tasks performed by VMs are comparable and not a significant 
difference. Yet, one VM never runs of out of memory and other one 
does. Sometimes it's as soon as half an hour after restarting the 
process while on the other box process is running for days and no 
issues.


"Comparable" isn't "identical".

Are they running the same apps?  Which apps are involved?  Is the one 
that's throwing OOME handling substantially similar requests when 
compared to one that doesn't?  Is the request rate nearly the same, or 
is the problematic one handling a lot more?  Another applicable 
question, also off topic for this mailing list:  Are the apps in both 
cases configured identically?


I took memory dumps from both VMs and they look similar. Program is 
started with -Xmx1g flag and we have taken regular memory dumps. In 
many cases eclipse MAT reports total memory usage was less than 100MB 
when program crashed with out of memory exception.


That's extremely odd, unless the application requested a REALLY big 
chunk of memory such that the 100MB existing plus the new allocation 
would be larger than the max heap size of 1GB.


Do you have enough free memory that you could increase the max heap to 
2GB or beyond and see what happens?


Has anyone seen anything similar to this? Identical bits of code 
behaving differently? What else should I be looking for?


Earlier you said "comparable" and now you're saying "identical". So I 
have to ask ... which is it?  Remember that differences in 
configurations, types of requests, and request load can lead to very 
different requirements, even if the apps running inside Tomcat are the 
same.


Most of my experience in the Java world comes from Solr.  Apache Solr 
is a servlet application, and ships with Jetty.  Tomcat is not usually 
involved.  I joined this mailing list because I was responsible for 
Tomcat servers running apps developed in-house, and every once in a 
while, I needed to ask something tomcat-specific.


Thanks,
Shawn

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org




-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Out of memory exception

2021-02-18 Thread Shawn Heisey

On 2/18/2021 11:36 AM, Niranjan Rao wrote:
First apologies for non tomcat question. I have seen that there is 
enough expertise here to provide hints and hints are what I am looking 
for to solve the problem and question is generic enough. I have tried 
researching problem to best of my abilities.


I believe you're right to think this isn't a tomcat question.  There are 
a lot of things it could be.  Tomcat is a *possible* source, though I 
think the chance of that is low.  Without a LOT of info that I would 
probably be useless at interpreting or asking for, it's impossible to 
say for sure.


With problems like this, it is normally the application running inside 
Tomcat that has a problem, not Tomcat itself.  You're likely to get a 
lot more useful information if you go to the people responsible for 
those applications.


We have a java program that regularly throws 
"java.lang.OutOfMemoryError: Java heap space" exception. Puzzling point 
is it happens only on one VM. We have a set of two VMs/boxes spawned 
from same AWS image. Machine class/region is exactly same and since they 
are from same image, they should be mostly identical except stuff like 
host name, ip address etc.


Number of tasks performed by VMs are comparable and not a significant 
difference. Yet, one VM never runs of out of memory and other one does. 
Sometimes it's as soon as half an hour after restarting the process 
while on the other box process is running for days and no issues.


"Comparable" isn't "identical".

Are they running the same apps?  Which apps are involved?  Is the one 
that's throwing OOME handling substantially similar requests when 
compared to one that doesn't?  Is the request rate nearly the same, or 
is the problematic one handling a lot more?  Another applicable 
question, also off topic for this mailing list:  Are the apps in both 
cases configured identically?


I took memory dumps from both VMs and they look similar. Program is 
started with -Xmx1g flag and we have taken regular memory dumps. In many 
cases eclipse MAT reports total memory usage was less than 100MB when 
program crashed with out of memory exception.


That's extremely odd, unless the application requested a REALLY big 
chunk of memory such that the 100MB existing plus the new allocation 
would be larger than the max heap size of 1GB.


Do you have enough free memory that you could increase the max heap to 
2GB or beyond and see what happens?


Has anyone seen anything similar to this? Identical bits of code 
behaving differently? What else should I be looking for?


Earlier you said "comparable" and now you're saying "identical".  So I 
have to ask ... which is it?  Remember that differences in 
configurations, types of requests, and request load can lead to very 
different requirements, even if the apps running inside Tomcat are the same.


Most of my experience in the Java world comes from Solr.  Apache Solr is 
a servlet application, and ships with Jetty.  Tomcat is not usually 
involved.  I joined this mailing list because I was responsible for 
Tomcat servers running apps developed in-house, and every once in a 
while, I needed to ask something tomcat-specific.


Thanks,
Shawn

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Out of memory exception

2021-02-18 Thread Niranjan Rao

Greetings,


First apologies for non tomcat question. I have seen that there is 
enough expertise here to provide hints and hints are what I am looking 
for to solve the problem and question is generic enough. I have tried 
researching problem to best of my abilities.


It all happens on Ubuntu 20.04 and JDK 15

We have a java program that regularly throws 
"java.lang.OutOfMemoryError: Java heap space" exception. Puzzling point 
is it happens only on one VM. We have a set of two VMs/boxes spawned 
from same AWS image. Machine class/region is exactly same and since they 
are from same image, they should be mostly identical except stuff like 
host name, ip address etc.


Number of tasks performed by VMs are comparable and not a significant 
difference. Yet, one VM never runs of out of memory and other one does. 
Sometimes it's as soon as half an hour after restarting the process 
while on the other box process is running for days and no issues.


I took memory dumps from both VMs and they look similar. Program is 
started with -Xmx1g flag and we have taken regular memory dumps. In many 
cases eclipse MAT reports total memory usage was less than 100MB when 
program crashed with out of memory exception.



Has anyone seen anything similar to this? Identical bits of code 
behaving differently? What else should I be looking for?



Regards,


Niranjan


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



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

2021-02-18 Thread Woonsan Ko
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)
 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:
> 
> [2] Java's Scripting Framework (Since Java 6):
> 
> [3] JCP JSR-223: 
> [4] Apache BSF: 
>
>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



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

2021-02-18 Thread 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:

[2] Java's Scripting Framework (Since Java 6):

[3] JCP JSR-223: 
[4] Apache BSF: 



-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



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

2021-02-18 Thread Christopher Schultz

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 

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

2021-02-18 Thread Rony G. Flatscher (Apache)
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 

Re: Tomcat 9 jar containing @webservlet annotation not loaded if inside tomcat/lib

2021-02-18 Thread aghart...@gmail.com

Hi,

FYI, tomcat 9.0.43 have this problem too.

Best Regards,

Agharta


Il 18/02/21 12:51, aghart...@gmail.com ha scritto:

Hi Mark,

Good questions, my mistake, sorry.

So:

jar file name is testannotation.jar

package is "aaa." (very simple)

Standard vanilla tomcat (.zip) downloaded from ASF site, no package 
manager. Unzipped to my home directory.


org.apache.tomcat.util.scan.StandardJarScanner.level = FINE (enabled 
inside tomcat/conf/logging.properties)


Result:

catalina.2021-02-18.log:18-Feb-2021 12:45:03.703 BUONO [main] 
org.apache.tomcat.util.scan.StandardJarScanner.processURLs Scanning 
JAR [file:/home/agharta/apache-tomcat-9.0.41/lib/testannotation.jar] 
from classpath
catalina.2021-02-18.log:18-Feb-2021 12:45:06.178 BUONO 
[http-nio-8082-exec-1] 
org.apache.tomcat.util.scan.StandardJarScanner.processURLs Scanning 
JAR [file:/home/agharta/apache-tomcat-9.0.41/lib/testannotation.jar] 
from classpath


...no other messages involving testannotation.jar or TestServlet.


Many thanks,

Agharta




Il 18/02/21 12:24, Mark Thomas ha scritto:

On 18/02/2021 10:46, aghart...@gmail.com wrote:

Hi all,

A question, I can't solve that

Tested with Tomcat 9.0.41, java 8 x64, linux (Fedora 32).


I have a standard tomcat web.xml (3.0 or 3.1, no matter).

I have created an external simple servlet with @WebServlet annotation,
and packaged it to a jar file:

Name of the JAR file?

Package the Servlet has been placed in?

Standard Tomcat downloaded from the ASF or one provided by your package
manager?

Have you tried enabling debug logging for
org.apache.tomcat.util.scan.StandardJarScanner ?

Mark




@WebServlet(name = "TestServlet", urlPatterns = {"/TestServlet"},
loadOnStartup = 1)
public class TestServlet extends HttpServlet {

 private static final Logger log =
Logger.getLogger(TestServlet.class.getName());

 private static final long serialVersionUID = 1L;

 @Override
 public void init() throws ServletException {
 log.setLevel(Level.ALL);
 log.log(Level.WARNING, "TESTSERVLET INIT");
 super.init();
 }

 @Override
 public void destroy() {
 }

 @Override
 protected void doGet(HttpServletRequest req, HttpServletResponse
resp) throws ServletException, IOException {
 processRequest(req, resp);
 }

 protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
 throws ServletException, IOException {
 response.setContentType("text/html;charset=UTF-8");
 PrintWriter out = response.getWriter();

 try {
     out.println("");
 out.println("");
 out.println("");
 out.println("Servlet TestServlet");
 out.println("");
 out.println("");
 out.println("Servlet TestServlet at " +
request.getContextPath() + "");

 out.println("");
 out.println("");
 } finally {
 out.close();
 }
 }

}


So, if I copy the .jar file inside WEB-INF/lib folder of destination 
war

project the log message will appears and the servlet is reachable.

But, if I copy the .jar file inside tomcat/lib folder the annotation
won't be processed.


FYI, in tomcat 7 both cases (inside WEB-INF/lib and tomcat/lib) 
works well.



I searched on breaking changes between tomcat 7 and 8/8.5/9 but nope.
Seems related to jarscanner.but no luck!


Because my servlet is in common to all projects I want to put it inside
tomcat/lib folder and share it to all my projects


Somebody can help me?


Many thanks,

Agharta








-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Tomcat 9 jar containing @webservlet annotation not loaded if inside tomcat/lib

2021-02-18 Thread aghart...@gmail.com

Hi Mark,

Good questions, my mistake, sorry.

So:

jar file name is testannotation.jar

package is "aaa." (very simple)

Standard vanilla tomcat (.zip) downloaded from ASF site, no package 
manager. Unzipped to my home directory.


org.apache.tomcat.util.scan.StandardJarScanner.level = FINE (enabled 
inside tomcat/conf/logging.properties)


Result:

catalina.2021-02-18.log:18-Feb-2021 12:45:03.703 BUONO [main] 
org.apache.tomcat.util.scan.StandardJarScanner.processURLs Scanning JAR 
[file:/home/agharta/apache-tomcat-9.0.41/lib/testannotation.jar] from 
classpath
catalina.2021-02-18.log:18-Feb-2021 12:45:06.178 BUONO 
[http-nio-8082-exec-1] 
org.apache.tomcat.util.scan.StandardJarScanner.processURLs Scanning JAR 
[file:/home/agharta/apache-tomcat-9.0.41/lib/testannotation.jar] from 
classpath


...no other messages involving testannotation.jar or TestServlet.


Many thanks,

Agharta




Il 18/02/21 12:24, Mark Thomas ha scritto:

On 18/02/2021 10:46, aghart...@gmail.com wrote:

Hi all,

A question, I can't solve that

Tested with Tomcat 9.0.41, java 8 x64, linux (Fedora 32).


I have a standard tomcat web.xml (3.0 or 3.1, no matter).

I have created an external simple servlet with @WebServlet annotation,
and packaged it to a jar file:

Name of the JAR file?

Package the Servlet has been placed in?

Standard Tomcat downloaded from the ASF or one provided by your package
manager?

Have you tried enabling debug logging for
org.apache.tomcat.util.scan.StandardJarScanner ?

Mark




@WebServlet(name = "TestServlet", urlPatterns = {"/TestServlet"},
loadOnStartup = 1)
public class TestServlet extends HttpServlet {

     private static final Logger log =
Logger.getLogger(TestServlet.class.getName());

     private static final long serialVersionUID = 1L;

     @Override
     public void init() throws ServletException {
     log.setLevel(Level.ALL);
     log.log(Level.WARNING, "TESTSERVLET INIT");
     super.init();
     }

     @Override
     public void destroy() {
     }

     @Override
     protected void doGet(HttpServletRequest req, HttpServletResponse
resp) throws ServletException, IOException {
     processRequest(req, resp);
     }

     protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
     throws ServletException, IOException {
     response.setContentType("text/html;charset=UTF-8");
     PrintWriter out = response.getWriter();

     try {
     out.println("");
     out.println("");
     out.println("");
     out.println("Servlet TestServlet");
     out.println("");
     out.println("");
     out.println("Servlet TestServlet at " +
request.getContextPath() + "");

     out.println("");
     out.println("");
     } finally {
     out.close();
     }
     }

}


So, if I copy the .jar file inside WEB-INF/lib folder of destination war
project the log message will appears and the servlet is reachable.

But, if I copy the .jar file inside tomcat/lib folder the annotation
won't be processed.


FYI, in tomcat 7 both cases (inside WEB-INF/lib and tomcat/lib) works well.


I searched on breaking changes between tomcat 7 and 8/8.5/9 but nope.
Seems related to jarscanner.but no luck!


Because my servlet is in common to all projects I want to put it inside
tomcat/lib folder and share it to all my projects


Somebody can help me?


Many thanks,

Agharta








-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Tomcat 9 jar containing @webservlet annotation not loaded if inside tomcat/lib

2021-02-18 Thread Mark Thomas
On 18/02/2021 10:46, aghart...@gmail.com wrote:
> Hi all,
> 
> A question, I can't solve that
> 
> Tested with Tomcat 9.0.41, java 8 x64, linux (Fedora 32).
> 
> 
> I have a standard tomcat web.xml (3.0 or 3.1, no matter).
> 
> I have created an external simple servlet with @WebServlet annotation,
> and packaged it to a jar file:

Name of the JAR file?

Package the Servlet has been placed in?

Standard Tomcat downloaded from the ASF or one provided by your package
manager?

Have you tried enabling debug logging for
org.apache.tomcat.util.scan.StandardJarScanner ?

Mark


> 
> 
> @WebServlet(name = "TestServlet", urlPatterns = {"/TestServlet"},
> loadOnStartup = 1)
> public class TestServlet extends HttpServlet {
> 
>     private static final Logger log =
> Logger.getLogger(TestServlet.class.getName());
> 
>     private static final long serialVersionUID = 1L;
> 
>     @Override
>     public void init() throws ServletException {
>     log.setLevel(Level.ALL);
>     log.log(Level.WARNING, "TESTSERVLET INIT");
>     super.init();
>     }
> 
>     @Override
>     public void destroy() {
>     }
> 
>     @Override
>     protected void doGet(HttpServletRequest req, HttpServletResponse
> resp) throws ServletException, IOException {
>     processRequest(req, resp);
>     }
> 
>     protected void processRequest(HttpServletRequest request,
> HttpServletResponse response)
>     throws ServletException, IOException {
>     response.setContentType("text/html;charset=UTF-8");
>     PrintWriter out = response.getWriter();
> 
>     try {
>     out.println("");
>     out.println("");
>     out.println("");
>     out.println("Servlet TestServlet");
>     out.println("");
>     out.println("");
>     out.println("Servlet TestServlet at " +
> request.getContextPath() + "");
> 
>     out.println("");
>     out.println("");
>     } finally {
>     out.close();
>     }
>     }
> 
> }
> 
> 
> So, if I copy the .jar file inside WEB-INF/lib folder of destination war
> project the log message will appears and the servlet is reachable.
> 
> But, if I copy the .jar file inside tomcat/lib folder the annotation
> won't be processed.
> 
> 
> FYI, in tomcat 7 both cases (inside WEB-INF/lib and tomcat/lib) works well.
> 
> 
> I searched on breaking changes between tomcat 7 and 8/8.5/9 but nope.
> Seems related to jarscanner.but no luck!
> 
> 
> Because my servlet is in common to all projects I want to put it inside
> tomcat/lib folder and share it to all my projects
> 
> 
> Somebody can help me?
> 
> 
> Many thanks,
> 
> Agharta
> 
> 
> 
> 
> 
> 


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Tomcat 9 jar containing @webservlet annotation not loaded if inside tomcat/lib

2021-02-18 Thread aghart...@gmail.com

Hi all,

A question, I can't solve that

Tested with Tomcat 9.0.41, java 8 x64, linux (Fedora 32).


I have a standard tomcat web.xml (3.0 or 3.1, no matter).

I have created an external simple servlet with @WebServlet annotation, 
and packaged it to a jar file:



@WebServlet(name = "TestServlet", urlPatterns = {"/TestServlet"}, loadOnStartup 
= 1)
public class TestServlet extends HttpServlet {

    private static final Logger log = 
Logger.getLogger(TestServlet.class.getName());

    private static final long serialVersionUID = 1L;

    @Override
    public void init() throws ServletException {
    log.setLevel(Level.ALL);
    log.log(Level.WARNING, "TESTSERVLET INIT");
    super.init();
    }

    @Override
    public void destroy() {
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
throws ServletException, IOException {
    processRequest(req, resp);
    }

    protected void processRequest(HttpServletRequest request, 
HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    try {
    out.println("");
    out.println("");
    out.println("");
    out.println("Servlet TestServlet");
    out.println("");
    out.println("");
    out.println("Servlet TestServlet at " + request.getContextPath() + 
"");

    out.println("");
    out.println("");
    } finally {
    out.close();
    }
    }

}


So, if I copy the .jar file inside WEB-INF/lib folder of destination war 
project the log message will appears and the servlet is reachable.


But, if I copy the .jar file inside tomcat/lib folder the annotation 
won't be processed.



FYI, in tomcat 7 both cases (inside WEB-INF/lib and tomcat/lib) works well.


I searched on breaking changes between tomcat 7 and 8/8.5/9 but nope. 
Seems related to jarscanner.but no luck!



Because my servlet is in common to all projects I want to put it inside 
tomcat/lib folder and share it to all my projects



Somebody can help me?


Many thanks,

Agharta